  /* Global variables
   for browser sniffing */
var isNav, isIE, isDom, isOld
var coll = ""
var styleObj = ""
var layerRef = ""


var timerID = null;
var timerOn = false;
/*This sets how long the menu
  will linger on the screen after
  mousing out */
var timeDelay = 1200;

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
ns6 = (!document.all && document.getElementById) ? true : false;

/* var scrnx = window.screen.availWidth
   var scrny = window.screen.availHeight
   var calcx = scrnx * .80
   var calcy = scrny * .90
   if (!ns4) {
	   window.resizeTo(calcx,calcy);
	}
*/

function ZipCodeHandler() {  
   /* fired onload...
     sniff browser version and set
     up DOM variables, set button colors
     and set position of drop-down menus */
	if (document.layers) {
		// alert ("Running Netscape 4");
		layerRef="document.layers";
		styleObj="";
		visibleVar="show";
		isNav = true;
	}else if(document.all){
		// alert ("Running IE");
		coll = "all."
		layerRef="document.all";
		styleObj=".style";
		visibleVar="visible";
		isIE = true;
	}else if(document.getElementById){
		// alert ("Running Netscape 6");
		coll = "getElementByID."
		layerRef="document.getElementById";
		styleObj=".style";
		visibleVar="visible";
		isDom = true;
	}else{
		//alert("Older than 4.0 browser.");
		isOld = true;
	}
	cleanZipCodeLayers();
	
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
	var theObj
	
	if (typeof obj == "string") {
		//special code to handle ns6 or other dom "getelementbyID" browser
	  	if (isDom) {
	  		theObj = eval('document.getElementById("' + obj + '")' + styleObj)
	  	} else {
			theObj = "document.layers[" + obj + "]"
		}
	} else {
		theObj = obj
	}
	return theObj
}

// Setting the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "hidden"
}


function cleanZipCodeLayers(){
     //hides all zipcode layers
      
	hide('zipcodeerror');
	hide('zipcodebox');
	hide('calclayer');
	SetZipCodeLayer();

}
    
// Setting the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj)
	theObj.visibility = "visible"
}

function layerWrite(tLayerName, text) {
	if (ns4) {
		var layerObj = eval("document.layers[tLayerName].document.layers[tLayerName]")
	  	layerObj.document.open();
	  	layerObj.document.write(text);
	  	layerObj.document.close();
		layerObj.visibility = 'hidden';
		document.height < window.innerHeight ? window.innerHeight : document.height;
  		document.height = layerObj.pageY + layerObj.clip.height;
		layerObj.visibility = 'visible';
	}
	else if (ns6) {
		var divObj = document.getElementById(tLayerName)
		divObj.innerHTML = text;
	}
	else if (ie4)
		document.all[tLayerName].innerHTML = text;
}

function getElement(tForm, eName) {
	// loop through the elements in the form and get the element position with
	// the name passed in.
	var tLen;
	tLen = tForm.elements.length;
	for (var i = 0; i < tLen; ++i) {
		
		if (tForm.elements[i].name == eName) {
		  return i;
		}
	}
	return -1;
}

function labelWrite(tLayerName, text) {
	alert('want to write to:' + tLayerName + ' this:' + text);
	if (ns4) {
		var tIndex = getObject(tLayerName);
		tIndex.innerHTML = text	
	}
	
}
function format_number(pnumber,decimals){ 
// this function will format a number with and return number with
// appropriate number of decimal places

	if (isNaN(pnumber)) { return 0}; 
	if (pnumber=='') { return 0}; 

	var snum = new String(pnumber); 
	var sec = snum.split('.'); 
	var whole = parseFloat(sec[0]); 
	var result = ''; 

	if(sec.length > 1){ 
		var dec = new String(sec[1]); 
		dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals))); 
		dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals)); 
		var dot = dec.indexOf('.'); 
		if(dot == -1){ 
			dec += '.'; 
			dot = dec.indexOf('.'); 
		} 
		while(dec.length <= dot + decimals) { dec += '0'; } 
		result = dec; 
	} else{ 
		var dot; 
		var dec = new String(whole); 
		dec += '.'; 
		dot = dec.indexOf('.'); 
		while(dec.length <= dot + decimals) { dec += '0'; } 
		result = dec; 
	} 
	return result; 
} 

