  /* 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);
	}
*/

var isNS = document.layers; 
layerRef = (isNS) ? "document" : "document.all";
styleRef = (isNS) ? "" : ".style";

// =====================================================
function showHelp(HelpTopic,bid) {
// =====================================================
	window.open('LightCalcResHelp.asp?bid=' + bid + '&topic=' + HelpTopic, 'help', 'height=200,width=400,resizable=yes,scrollbars=yes');
	}


// =====================================================
function updateMode(tVal) {
// =====================================================
	  var tForm = document.testform;
	  var str = new String(tVal);   
	  //alert(tVal);   
	   // dropdown   
	   if (str.length > 0)
		tStyle = parseInt(str.substr(str.length-1));   
	   else
		tStyle = -1;	
		tForm.oldcmode.value = tForm.cmode.value;
		tForm.cmode.value = tStyle;
		//alert("old=" + tForm.oldcmode.value + " new=" + tForm.cmode.value);

}

// =====================================================
function showTips(bid, ApplianceType) {
// =====================================================
		window.open('tips.asp?bid=' + bid +'&appliancetype=' + ApplianceType, 'Tips', 'height=500,width=500,resizable=yes,scrollbars=yes,screenX=100,screenY=100,top=100,left=100');
}
	
	
// =====================================================
function formCheckSubmit(bUpdate) { 
// =====================================================			
		var tForm = document.testform;
		
	// first do check from submit button
	if (1==bUpdate) {
	  if (tForm.calc_zipcode) {
			if (IsValidZipPostal(tForm.calc_zipcode)){ 
				if (verifyForm() == true) {
					if (bUpdate)
						tForm.bRedirect.value = true;
					tForm.submit();	
					}
				}
			else {
			    alert('Please enter valid ZIP Code.');
				  tForm.calc_zipcode.focus();
				 }		
	    }	
	    else
			if (verifyForm() == true) {
				if (bUpdate)
					tForm.bRedirect.value = true;
				tForm.submit();	
				}
			else {
				// do nothing
				}
	} // end bupdate=1
	
	// do check if hit from mode type
	if (0==bUpdate) {
/*	  if (tForm.calc_zipcode) {
			if (IsValidZipCode(tForm.calc_zipcode)){ 
					tForm.submit();	
				}
			else
				{ alert("Please enter your 5 digit ZIP Code.");
				  tForm.calc_zipcode.focus();
				 }		
	    }	
	    else
*/	    
			tForm.submit();				
	} // end bupdate=1
	
					
} // end function
// =============================================================
	
		function IsValidZipCode(ZipCodeInput)
	{	// function checks to be sure zip code has numeric values and is 5 digits
/*	alert(ZipCodeInput.length);
	alert(ZipCode.value.length);
	alert(ZipCode.value);
*/	
	if  (numericInputPassed(ZipCodeInput.value) && (ZipCodeInput.value.length==5))
		return true;
	else
		{
		ZipCodeInput.select();
	   	return false; 
	  }
			
}
// =====================================================
function upZindex()
// =====================================================
// Changes z index of question layers so appropriate layers displays
    {
    // fix for bug 692 where event is not defined in firefox
    if (event)
        {
        event.srcElement.style.zIndex=4;
        }
    }

// =====================================================
function cleanQuestionLayers(tVal){   
// =====================================================
//hides all question layers   

       var tStyle;   
       var str = new String(tVal);   
       
       // always reset redirect to false
       document.testform.bRedirect.value = false;
       
          if (str.length == 0)
			// if rts mode, parse value stored in string if there
			if (document.testform.NXQBLIGHT_BULBTYPE_RTS){
				
				str = new String(document.testform.NXQBLIGHT_BULBTYPE_RTS.value);   
			}	
			// if cwt mode, parse value stored in string if there
			if (document.testform.NXQBLIGHT_BULBTYPE_CWT){
			    str = new String(document.testform.NXQBLIGHT_BULBTYPE_CWT.value);
			}    
			
	
	  //alert(tVal);   
	   // dropdown   
	   if (str.length > 0)
		tStyle = parseInt(str.substr(str.length-1));   
	   else
		tStyle = -1;	
	   
	   //alert('Tval parsed=' + tStyle); 
	   // if nothing passed in on load of page, change to default incandescent question
	   // only do this for rtw, and cwt mode
	   if ((document.testform.cmode.value == 0) || (document.testform.cmode.value == 1))
	   {  	   
		// compact flourescent
		if ((0==tStyle)&& (!ns4)) {  
			 switchDiv('C_Compact_Fluorescent_a', 1);
			 switchDiv('C_Compact_Fluorescent_b', 1); 
			 switchDiv('C_Standard_Fluorescent_a', 0);
			 switchDiv('C_Standard_Fluorescent_b', 0);  
			 switchDiv('C_Incandescent_a',0);    
			 switchDiv('C_Incandescent_b',0);
			 switchDiv('C_Halogen_a',0);
			 switchDiv('C_Halogen_b',0);
			 return true;
		}	
		// standard flourescent
		if ((1==tStyle)&&(!ns4)) {  
			  switchDiv('C_Standard_Fluorescent_a', 1);
			  switchDiv('C_Standard_Fluorescent_b', 1);      
			  switchDiv('C_Compact_Fluorescent_a', 0);
			  switchDiv('C_Compact_Fluorescent_b', 0);      
			  switchDiv('C_Incandescent_a',0);    
			  switchDiv('C_Incandescent_b',0);
			  switchDiv('C_Halogen_a',0);
			  switchDiv('C_Halogen_b',0);
			  return true;
		}	
	   
		// incandescent
		if (((2==tStyle)||(-1==tStyle))&&(!ns4)) {  
			  switchDiv('C_Standard_Fluorescent_a', 0);
			  switchDiv('C_Standard_Fluorescent_b', 0);      
			  switchDiv('C_Compact_Fluorescent_a', 0);
			  switchDiv('C_Compact_Fluorescent_b', 0);      
			  switchDiv('C_Incandescent_a',1);    
			  switchDiv('C_Incandescent_b',1);
			  switchDiv('C_Halogen_a',0);
			  switchDiv('C_Halogen_b',0);
			  return true;
		}	
	   
		// Halogen
		if ((3==tStyle)&&(!ns4)) {  
			  switchDiv('C_Standard_Fluorescent_a', 0);
			  switchDiv('C_Standard_Fluorescent_b', 0);      
			  switchDiv('C_Compact_Fluorescent_a', 0);
			  switchDiv('C_Compact_Fluorescent_b', 0);      
			  switchDiv('C_Incandescent_a',0);    
			  switchDiv('C_Incandescent_b',0);
			  switchDiv('C_Halogen_a',1);
			  switchDiv('C_Halogen_b',1);
			  return true;
		}	
	   }
	   if (ns4)
		{
		  alert("sorry, this only works in browsers that do Dynamic HTML");
		  return false;
		}
	   
	/* 
	   eval(layerRef + '.C_Compact_Fluorescent_a' +  styleRef + '.visibility = "visible"');
	   eval(layerRef + '.C_Compact_Fluorescent_b' +  styleRef + '.visibility = "visible"');
	*/   
  }   
  // =====================================================
  function switchDiv(div_id, visibility)
  // =====================================================
		{
			var style_sheet = getStyleObject(div_id);
			
			if (style_sheet)
			{
				if (visibility == 0)
					changeObjectVisibility(div_id, "hidden");
				else
					changeObjectVisibility(div_id, "visible");
			}
			else 
			{
				alert("sorry, this only works in browsers that do Dynamic HTML");
				return false;
			}
		}
// =====================================================
	function getStyleObject(objectId) 
// =====================================================
	{
		// checkW3C DOM, then MSIE 4, then NN 4.
		//
		if(document.getElementById && document.getElementById(objectId)) {
			return document.getElementById(objectId).style;
		}
		else if (document.all && document.all(objectId)) {  
			return document.all(objectId).style;
		} 
		else if (document.layers && document.layers[objectId]) { 
			return document.layers[objectId];
		} else {
			return false;
		}
	}
// =====================================================
	function changeObjectVisibility(objectId, newVisibility)
// =====================================================
	{
		// first get the object's stylesheet
		var styleObject = getStyleObject(objectId);

		// then if we find a stylesheet, set its visibility
		// as requested
		//
		if (styleObject) 
		{
			styleObject.visibility = newVisibility;
			return true;
		}
		else
		{
			return false;
		}
	}	
// =====================================================	
function layerWrite(tLayerName, text) {
// =====================================================
// writes text to layer
	if (ns4) {
	
	   alert('test=' + tLayerName);
		var layerObj = eval(layerRef + 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 CheckData() {
// This function checks to ensure wattage questions are
// answered for appropriate mode
// =====================================================
var tMode = document.testForm.cmode.value;
var bNoWattAnswer = false;

if (2==tMode) {
// skip watt verification and just call verify form
  return verifyForm();
}
else
{
   if (!dropDownPassed(document.testform.NXQBLIGHT_BULBTYPE_RTS)) {
		bNoWattAnswer = true;
	}

	if (!dropDownPassed(document.testform.NXQBLIGHT_CURRENTWATTS_CF_RTS)) {
		alert("Please select the wattage for this bulb type.");
		return false;
	}

	if (!dropDownPassed(document.testform.NXQBLIGHT_CURRENTWATTS_SF_RTS)) {
		alert("Please select the wattage for this bulb type.");
		return false;
	}

	if (!dropDownPassed(document.testform.NXQBLIGHT_CURRENTWATTS_I_RTS)) {
		alert("Please select the wattage for this bulb type.");
		return false;
	}

	if (!dropDownPassed(document.testform.NXQBLIGHT_CURRENTWATTS_H_RTS)) {

	}

	if (bNoWattAnswer) {
		alert("Please select the wattage for this bulb type.");
		return false;
	}
	else
		return verifyForm();
	}
}

function verifyForm() {

if (document.testform.NXQBLIGHT_CALC_MODE)
	if (!dropDownPassed(document.testform.NXQBLIGHT_CALC_MODE)) {
		document.testform.NXQBLIGHT_CALC_MODE.focus();
		alert("Please choose a style of light to analyze.");
		return false;
	}
// ====== RTS MODE ==========
if (document.testform.NXQBLIGHT_CF_RTS)
	if (!dropDownPassed(document.testform.NXQBLIGHT_CF_RTS)) {
		document.testform.NXQBLIGHT_CF_RTS.focus();
		alert("Please indicate how many lights you have.");
		return false;
	}

if (document.testform.NXQBLIGHT_BULBTYPE_RTS)
	if (!dropDownPassed(document.testform.NXQBLIGHT_BULBTYPE_RTS)) {
		document.testform.NXQBLIGHT_BULBTYPE_RTS.focus();
		alert("Please select a bulb type.");
		return false;
	}
	
if (document.testform.NXQBLIGHT_HRS_RTS)
	if (!dropDownPassed(document.testform.NXQBLIGHT_HRS_RTS)) {
		document.testform.NXQBLIGHT_HRS_RTS.focus();
		alert("Please indicate how many hours you use these lights.");
		return false;
	}
// ====== CWT MODE ==========
if (document.testform.NXQBLIGHT_CF_CWT)
	if (!dropDownPassed(document.testform.NXQBLIGHT_CF_CWT)) {
		document.testform.NXQBLIGHT_CF_CWT.focus();
		alert("Please indicate how many lights you have.");
		return false;
	}

if (document.testform.NXQBLIGHT_BULBTYPE_CWT)
	if (!dropDownPassed(document.testform.NXQBLIGHT_BULBTYPE_CWT)) {
		document.testform.NXQBLIGHT_BULBTYPE_CWT.focus();
		alert("Please select a bulb type.");
		return false;
	}

if (document.testform.NXQBLIGHT_HRS_CWT)
	if (!dropDownPassed(document.testform.NXQBLIGHT_HRS_CWT)) {
		document.testform.NXQBLIGHT_HRS_CWT.focus();
		alert("Please indicate how many hours you use these lights.");
		return false;
	}
// ====== HALOGEN MODE ==========	
if (document.testform.NXQBLIGHT_H_H)	
	if (!dropDownPassed(document.testform.NXQBLIGHT_H_H)) {
		document.testform.NXQBLIGHT_H_H.focus();
		alert("Please indicate how many lights you have.");
		return false;
	}

if (document.testform.NXQBLIGHT_CURRENTWATTS_H_H)
	if (!dropDownPassed(document.testform.NXQBLIGHT_CURRENTWATTS_H_H)) {
		document.testform.NXQBLIGHT_CURRENTWATTS_H_H.focus();
		alert("Please select the wattage for this bulb type.");
		return false;
	}

if (document.testform.NXQBLIGHT_HRS_H)
	if (!dropDownPassed(document.testform.NXQBLIGHT_HRS_H)) {
		document.testform.NXQBLIGHT_HRS_H.focus();
		alert("Please indicate how many hours you use these lights.");
		return false;
	}
	
	
////if we get to here, everything passed:
return true;
}


