
function GetElementById(fldId){
	if(document.layers){ //thisbrowser="NN4";
		return document.layers[fldId];
	}
	if(document.all){ //thisbrowser="ie"
		return document.all[fldId];
	}
	if(!document.all && document.getElementById){ //thisbrowser="NN6";
		return document.getElementById(fldId);
	}
}

function GetFieldValue(fldId){
	var fldinput = GetElementById(fldId);
	if(!fldinput) return;
	var type = fldinput.type;
	if (type=="checkbox" || type=="radio") {
		///// this doesn't work, need to loop through and get the checked one
		return fldinput.checked;
	} else if (type=="hidden" || type=="password" || type=="text" || type=="textarea") {
		return (fldinput.value);
	} else if (type=="select-one" || type=="select-multiple") {
		for (var j=0;j<fldinput.options.length;j++) {
			if (fldinput.options[j].selected){
				return (fldinput.options[j].value);
			}
		}
	}
	return false;
}

function IsOnlyChars(sText,sChars){
	var ValidChars = "0123456789.";
	var Char;
	for (i = 0; i < sText.length; i++){ 
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1){ return false; }
	}
	return true;
}
function IsNumeric(sval){
	return !isNaN(parseFloat(sval)) && isFinite(sval);
}


function FocusOnFldId(fldId){
  var fld = GetElementById(fldId);
  if(fld!=null) fld.focus();
}

function SetDivLocation(divFld, relativeFld, x, y){
  if(divFld == null || relativeFld == null) return;
  if(document.layers){ //thisbrowser="NN4";
    divFld.top = parseInt(relativeFld.top);
    divFld.left = parseInt(relativeFld.left);
  }
  if(document.all || document.getElementById){ //thisbrowser="ie" OR NN6
    var top = y;
    if(divFld.style.top){ top += parseInt(divFld.style.top); }
    top -= getElementTop(divFld);
    top += getElementTop(relativeFld);
    divFld.style.top = top + "px";
    
    var left = x;
    if(divFld.style.left){ left += parseInt(divFld.style.left); }
    left -= getElementLeft(divFld);
    left += getElementLeft(relativeFld);
    divFld.style.left = left + "px";
  }
}
function getElementLeft(fld) {
	if(document.layers){ //thisbrowser="NN4";
		return fld.pageX;
	} else { // id or NN6
		var xPos; var tempE1;
		xPos = fld.offsetLeft;
		tempEl = fld.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	}
}
function getElementTop(fld) {
	if(document.layers){ //thisbrowser="NN4";
		return fld.pageY;
	} else { // id or NN6
		var yPos; var tempE1;
		yPos = fld.offsetTop;
		tempEl = fld.offsetParent;
  		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}
}

function SetDivIdContent(divId, content){
	divFld = GetElementById(divId);
	if(!divFld) return;
	SetDivContent(divFld, content);
}
function SetDivContent(divFld, content){
  if(divFld == null || content == null) return;
  if(document.layers){ //thisbrowser="NN4";
    divFld.document.open();
    divFld.document.write(content);
    divFld.document.close();
  }
  if(document.all){ //thisbrowser="ie"
    divFld.innerHTML = content;
  }
  if(!document.all && document.getElementById){ //thisbrowser="NN6";
    divFld.innerHTML = content;
  }
}

function SetDivIdVisibility(divId, on){
	divFld = GetElementById(divId);
	if(!divFld) return;
	SetDivVisibility(divFld, on);
}
function SetDivVisibility(divFld, on){
  if(divFld == null) return;
  if(document.layers){ //thisbrowser="NN4";
    divFld.visibility = (on ? "show" : "hide");
  }
  if(document.all){ //thisbrowser="ie"
    divFld.style.visibility = (on ? "visible" : "hidden");
    divFld.style.zIndex = (on ? 100 : 0);
  }
  if(!document.all && document.getElementById){ //thisbrowser="NN6";
    divFld.style.visibility = (on ? "visible" : "hidden");
    divFld.style.zIndex = (on ? 100 : 0);
  }
}

function SetDivIdDisplay(divId, on){
	divFld = GetElementById(divId);
	if(!divFld) return;
	SetDivDisplay(divFld, on);
}
function SetDivDisplay(divFld, on){
  if(!divFld) return;
  if(document.layers){ //thisbrowser="NN4";
    divFld.visibility = (on ? "show" : "hide");
  }
  if(document.all){ //thisbrowser="ie"
    divFld.style.display = (on ? "block" : "none");
  }
  if(!document.all && document.getElementById){ //thisbrowser="NN6";
    divFld.style.display = (on ? "block" : "none");
  }
}

function createCookie(name, value, days, hours, minutes) {
	if (days || hours || minutes) {
		var date = new Date();
		var dateinc = 0;
		if(days){ dateinc += days*24*60*60*1000; }
		if(hours){ dateinc += hours*60*60*1000; }
		if(minutes){ dateinc += minutes*60*1000; }
		date.setTime(date.getTime()+dateinc);
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}

