// JavaScript Document
var browserType;
browserType = "ie"

if (document.layers) {browserType = "nn4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
   browserType= "gecko"
}
if (document.all) {browserType = "ie"}
   
   //----- cross-browser compatible version of "jumptofield" function. Andrew 2007-06-25
   function JumpToField3(itemName, strNextField, intMaxLength)
   {
	  if (browserType == "gecko" )
		 myVar = document.getElementById(itemName);
	  else if (browserType == "ie")
		 eval("myVar = document.all."+itemName);
	  else
		 myVar = document.layers[itemName];
		 
	  if (browserType == "gecko" )
		 objNextField = document.getElementById(strNextField);
	  else if (browserType == "ie")
		 eval("objNextField = document.all."+strNextField);
	  else
		 objNextField = document.layers[strNextField];
			
   	if (myVar.value.length == intMaxLength)
   	{
	  try { objNextField.setAttribute('autocomplete','off');  myVar.setAttribute('autocomplete','off'); }
	  catch (e) {a=1; }
	  
	  try { objNextField.focus();  }
	  catch (e) {a=1; }
   	  
    }
   }   
   
   //----- cross-browser compatible version of "jumptofield" function. GV 10/17/06 
   function JumpToField2(strNextField, intMaxLength, event)
   {
    var objTarget = event.target || event.srcElement;
    var objNextField = eval("objTarget.form." + strNextField);
   	if (objTarget.value.length == intMaxLength)
   	{
   	  objNextField.focus();
    }
   }   

/*
   -------- sends cursor to the specified field when specified number of 
   -------- characters are typed into the current field. GV 4/26/04 
   */	  	
   function JumpToField(strNextField, intMaxLength)
   {
 		JumpToField2(strNextField, intMaxLength, event)
   }
   
 // ------- if radio buttons have children, toggle visibility on or off. GV 6/24/04
 function ToggleRadioButtonChildren(strControlName)
 {
   return false;
   var intValue = ""
   var objDivReference = ""
   var objControlReference = eval("document.forms[0]." + strControlName)
   for (i = 0;i < objControlReference.length;i++)
   {
     intValue = objControlReference[i].value     
     objDivReference = "OutdoorUnitSub_" + intValue 
     ToggleDHTMLContent(objControlReference[i], objDivReference)  
       
   }       
  
  }
 
 
 /*
 -------- shows or hides DHTML content depending on whether or not the triggering radio button
 -------- or checkbox is checked. GV 6/24/04
 */
 
   ///**************************************************************************///
  ///  DONT USE THIS ONE. USE ONE BELOW BUT NOTE DIFFERENCE  Andrew 2007-06-25 ///
 ///**************************************************************************///
 function ToggleDHTMLContent(objControl, objDiv)
 {
   if (eval("document.all." + objDiv))
   {
     var objDivReference = eval("document.all." + objDiv)
     if (objControl.checked)
     {
       objDivReference.style.display = "block"
       //objDivReference.controls[0].focus()
     }
     else
     {
       objDivReference.style.display = "none"
     }
   }
 }   
 
  // Only pass form ids
 //----- cross-browser compatible version of "ToggleDHTMLContent" function. Andrew 2007-06-25
 function ToggleDHTMLContent2(objControl, objDiv) {
	 //get item
  if (browserType == "gecko" )
     myVar = document.getElementById(objDiv);
  else if (browserType == "ie")
     eval("myVar = document.all."+objDiv);
  else
     myVar = document.layers[objDiv];
	 
	 //get control
  if (browserType == "gecko" )
     obVar = document.getElementById(objControl);
  else if (browserType == "ie")
     eval("obVar = document.all."+objControl);
  else
     obVar = document.layers[objControl];
	 
	 //make change
     if (obVar.checked)
     {
	  try { myVar.style.display = "block"; }
	  catch (e) {a=1; }
     }
     else
     {
	  try { myVar.style.display = "none"; }
	  catch (e) {a=1; }
     }
}

 function ShowHideDiv(objControl, objDiv)
 {
	 // ---- code to execute if objControl is a checkbox. GV 2/4/08
	if (objControl.type == "checkbox")
	{
	 	if (objControl.checked)
	 	{
			objDiv.style.display = "block";
	 	}
	 	else
	 	{
			objDiv.style.display = "none"; 
	 	}
	}
	 // ---- code to execute if objControl is a button. GV 2/4/08
	else if (objControl.type == "button")
	{
		if (objDiv.style.display == "block")
		{
			objDiv.style.display = "none"; 
		}
		else
		{
			objDiv.style.display = "block"; 
		}
	}
 }
 /*
 -------- shows or hides DHTML content depending on whether or not the triggering radio button
 -------- or checkbox is checked. GV 6/24/04
 --------Add on for previous funtion. alerts user that unselecting a checkbox cancels their
 --------order for that selection AP 10/08/04
 */
 
   function ToggleDHTMLContentERR2(objControl, objDiv)
 	{
		
   strText = "Deselecting a check box means that you no do not wish to order offerings contained in that section. "
   strText = strText + "Click \"ok\" to continue and \"cancel\" if you wish to keep the current selection checked";
	 //get item
  if (browserType == "gecko" )
     myVar = document.getElementById(objDiv);
  else if (browserType == "ie")
     eval("myVar = document.all."+objDiv);
  else
     myVar = document.layers[objDiv];
	 
	 //get control
  if (browserType == "gecko" )
     obVar = document.getElementById(objControl);
  else if (browserType == "ie")
     eval("obVar = document.all."+objControl);
  else
     obVar = document.layers[objControl];
	 
	 //get SuppressAlert
  if (browserType == "gecko" )
     SuppressAlert = document.getElementById("SuppressAlert");
  else if (browserType == "ie")
     eval("SuppressAlert = document.all."+"SuppressAlert");
  else
     SuppressAlert = document.layers["SuppressAlert"];
	  
	 
	if (SuppressAlert)
		{
		
		if (SuppressAlert.value == '')
			{
			if (obVar.checked)
				{
				ToggleDHTMLContent2(objControl, objDiv);
				}
			else
				{  //user just unchecked the option
				var answer = confirm(strText);
				if (answer)
					{
					ToggleDHTMLContent2(objControl, objDiv);
					}
				else
					{
					alert("No changes made to your order");
					obVar.checked = true;
					}
				answer = confirm("Click 'OK' if you DON'T want to see the same message every time you deselect a checkbox.\n\nClick 'Cancel' if you DO want to see the same message every time you deselect a checkbox.");
				if (answer)
					{
					SuppressAlert.value = "yes";
					}
				}
			}
		else
			{
			ToggleDHTMLContent2(objControl, objDiv);
			}
		}
	else
		{
		alert("the hidden form field \"SuppressAlert\" must be created.");
		}
	}
	 
 // ------ added option to suppress future occcurences of this alert. GV 10/27/04
  function ToggleDHTMLContentERR(objControl, objDiv)
 {
   strText = "Deselecting a check box means that you no do not wish to order offerings contained in that section. Click \"ok\" to continue and \"cancel\" if you wish to keep the current selection checked";
   ToggleDHTMLContentWithAlert(objControl, objDiv, strText);
 }   
 
   function ToggleDHTMLContentWithAlert(objControl, objDiv, strText)
 {
   // checks for the existence of hidden form field needed to 
   if (document.forms[0].SuppressAlert)
   {
	   
	 if (document.forms[0].SuppressAlert.value == '')
	 {
       var objDivReference = eval("document.all." + objDiv)
       if (objControl.checked)
       {
         ToggleDHTMLContent(objControl, objDiv);
       }
       else
       {  //user just unchecked the option
	     var answer = confirm(strText);
	     if (answer)
	     {
	       ToggleDHTMLContent(objControl, objDiv);
	     }
	     else
	     {
	       alert("No changes made to your order");
	       objControl.checked = true;
	     }
	     answer = confirm("Click 'OK' if you DON'T want to see the same message every time you deselect a checkbox.\n\nClick 'Cancel' if you DO want to see the same message every time you deselect a checkbox.")
         if (answer)
	     {
	       document.forms[0].SuppressAlert.value = "yes"
	     }
	   }
     }
	 else
	 {
	   ToggleDHTMLContent(objControl, objDiv);
	 }
   }
   else
   {
     alert("the hidden form field \"SuppressAlert\" must be created.")
   }
 }  
 
 function ResetRadioGroup(strRadioButtonName)
 {
   var objRadioButtonReference = eval("document.forms[0]." + strRadioButtonName)
   for (i = 0;i < objRadioButtonReference.length;i++)
   {            
     objRadioButtonReference[i].checked = false         
   }
 }
 
  /*
   -------- Displays popup Help Message (uses script alert) 
   -------- AP 8/06/04   (could be changed to our own window format later)
   */	  	
	function ShowHelpMsg(strValue)
		{
		alert(strValue);
		}
		
		
  // ------ disallows form submission until page is printed. 9/20/04
   function AllowSubmit(form)
   {
     var f = form
     if (f.AllowSubmission.value != "1")
     {
       alert("You must print this screen before proceeding any further")
       return false
     }
     else
     {
       var blnSelected = false
       for (i = 0; i < f.Terms.length; i++)
       {
         if (f.Terms[i].checked)
         {
           blnSelected = true
         } 
       }
       if (blnSelected == false)
       {
         alert("You must check the box above to signify that you accept the terms and conditions.")
         f.Terms[0].focus()
         return false
       }
       else
       {        
         return true
       }
     }
   }

  function MaintainFormState(objForm)
  //------ maintains <DIV> content display across posts depending on checkbox state
  {
    var f = objForm
    //var objCheckBoxCollection = document.all.tags("input")
    for (var i = 0; i < f.length; i++)
    {
      if (f.elements[i].type == "checkbox")
      {
        if (f.elements[i].checked)
        {
          var strCheckBoxName = f.elements[i].name
          var strDivName = strCheckBoxName.replace(/CB/, "D")
          ToggleDHTMLContentERR2(strCheckBoxName, strDivName)
		  
        } 
      }
    }
  }
  
 function ResetForm(objForm, strTagType, strToplevelTagState)
  {
	//------ resets all form elements & collapses block-formatted DHTML containers.
    var f = objForm;
	var objAllTags = document.all.tags(strTagType)
	f.reset()
	for (i = 0;i < f.length; i++)
	{
	  if (f[i].type == "checkbox")
	  {
	    f[i].checked = 0
	  }
	}
	for (i = 0;i < objAllTags.length; i++)
	{
	 if (objAllTags[i].id != '')
	 {
	   if (objAllTags[i].id.indexOf("TOPLEVEL") != -1)
	   {
	     objAllTags[i].style.display = strToplevelTagState   
	   }
	   else
	   {
		   
		  // ------ exclude tags with explicit border width. GV 3/29/05
		  if (objAllTags[i].style.borderwidth == "2px")
		  {
			objAllTags[i].style.display = "block"  
		  }
		  //-------
		  
		  else
		  {
	        objAllTags[i].style.display = "none"
		  }
	   }
	 }
	}
	
  } 
  
 
  function ResetFormHttp(objForm, strTagType)
  {
	//------ resets all form elements & collapses block-formatted DHTML containers.
    var f = objForm;
	var objAllTags = document.all.tags(strTagType)
	f.reset()
	for (i = 0;i < f.length; i++)
	{
	  if (f[i].type == "checkbox")
	  {
	    f[i].checked = 0
	  }
	}
	for (i = 0;i < objAllTags.length; i++)
	{
	 if (objAllTags[i].id != '')
	 {
	   if (objAllTags[i].id.indexOf("TOPLEVEL") != -1)
	   {
	     objAllTags[i].innerHTML = ''   
	   }
	   else
	   {
		   
		  // ------ exclude tags with explicit border width. GV 3/29/05
		  if (objAllTags[i].style.borderwidth == "2px")
		  {
			objAllTags[i].style.display = "block"  
		  }
		  //-------
		  
		  else
		  {
	        objAllTags[i].style.display = "none"
		  }
	   }
	 }
	}
	
  } 
 
 
     //------ renders order text in red if not approved or green if approved. GV 2/11/04
     function ChangeTextColor(strOrder, objCheckBox)
     {

      //var strLink = document.links['test']
      if (objCheckBox.checked) { strColor = "green" } else { strColor = "red" } 
      
      
      for (var i = 0;i < allCells.length;i++)
      {
        if (allCells[i].id == "TC" + strOrder)
        {
          
          allCells[i].style.color =  strColor
        }
      }
      for (var i = 0;i < allLinks.length;i++)
      {
        if (allLinks[i].id == "L" + strOrder)
        {
          
          allLinks[i].style.color =  strColor
        }
      }      
    }
    
    
    //------ maintains text color if loaded from browser cache. GV 2/12/04
    function MaintainTextColor()
    {
	var f = document.forms[0]
      var CurrentElement = ""
      var CurrentOrder = ""
      for (var i = 0;i < f.length;i++)
      {

        if (f.elements[i].type == "checkbox")
        {
          CurrentElement = f.elements[i]
          CurrentOrder = f.elements[i].value
          ChangeTextColor(CurrentOrder, CurrentElement)
        }
      }
    }  
	
function EditState(stateVal)
{
if ((stateVal == "AL") || (stateVal == "AZ") || (stateVal == "FL") || (stateVal == "IL") || (stateVal == "NV") || (stateVal == "TX") || (stateVal == "SC") || (stateVal == "WA") || (stateVal == "NM") || (stateVal == "MN") || (stateVal == "VT")) {
     document.forms[0].SellPrice.disabled = false;
     //document.frmOrders3ndPage.SellPrice.focus(); // <-- have to enter zipcode first anyway
     }
  else{
     document.forms[0].SellPrice.value = "";
     document.forms[0].SellPrice.disabled = true;
    }
}	

function SelectDropdownOption(objDropDown,strValue)
{
	//var regex = /-/;
	//var strArg2 = strValue
	//var strArg2 = strValue.replace(regex, '');
	//alert(strArg2);
	for (var i=0;i<objDropDown.options.length;i++)
	{
		if (objDropDown.options[i].value == strValue)
		{
			objDropDown.selectedIndex = i;
			break;
		}
	}
}


/*=====================================================================
Hide DIV
======================================================================*/ 
function hide(itemName) {
  if (browserType == "gecko" )
     myVar = document.getElementById(itemName);
  else if (browserType == "ie")
     eval("myVar = document.all."+itemName);
  else
     myVar = document.layers[itemName];
  try { myVar.style.display = "none"; }
  catch (e) {a=1; }
}

/*=====================================================================
Show DIV
======================================================================*/ 
function show(itemName) {
  if (browserType == "gecko" )
     myVar = document.getElementById(itemName);
  else if (browserType == "ie")
     eval("myVar = document.all."+itemName);
  else
     myVar = document.layers[itemName];
  try { myVar.style.display = "block"; }
  catch (e) {a=1; }
}
/*=====================================================================
Create Cross-browser DIV reference
======================================================================*/ 
  function CBDiv(name)
  {
	if (document.getElementById)
	{
		var objTempDiv = document.getElementById(name);
	}
	else if (document.all)
	{
		var objTempDiv = document.all[name];
	}
	else if (document.layers)
	{
		var objTempDiv = document.layers[name];
	}
	else
	{
		alert('Your browser does not support certain functionality on this screen. Call 800-886-9363 ext. 8169 for assistance.');  
	}
	return objTempDiv;
  }
  
  	//------ checks or unchecks all checkboxes in a form with the specified prefix. GV 8/14/07
	function CheckAllBoxes(oForm, sPrefix)
	{
		var f = oForm;
		var intCheckCount = 0;
		var intNoCheckCount = 0;
		var intPrefixLen = sPrefix.length;
			
		//---- determine mass check state if master control is not a checkbox. GV 8/14/07
		for (var i = 0;i < f.length;i++)
		{
			objCurrent = f.elements[i];
			if (objCurrent.type == "checkbox")
			{
				if (objCurrent.name.substring(0,intPrefixLen) == sPrefix)
				{					
					/* 
					if number of currently-checked items is greater that that of non-checked items set mass state to unchecked.
					Otherwise, set mass state to checked. GV 8.14/05 
					*/
					if (objCurrent.checked == true)
					{
						intCheckCount += 1;
					}
					else if (objCurrent.checked == false)
					{
						intNoCheckCount += 1;
					}
				}
			}
		}
		for (var i = 0;i < f.length;i++)
		{
			objCurrent = f.elements[i];
			if (objCurrent.name.substring(0,intPrefixLen) == sPrefix)
			//-- if the control that fired the event is a checkbox, use it's check state to determine mass-check state. GV 8/14/07
			{
				if (event.srcElement.type ==  "checkbox")
				{
					if (event.srcElement.checked)
					{
						objCurrent.checked = true;
					}
					else
					{
						objCurrent.checked = false;
					}
				}
				//-- if the control that fired the event is not a checkbox, use variables to determine mass-check state. GV 8/14/07
				else
				{
					// if checked elements outnumber non-checked, set mass-check state to unchecked and vice-versa.
					if (intCheckCount > intNoCheckCount) 
					{ 
						objCurrent.checked = false;
					}
					else
					{
						objCurrent.checked = true;
					}
				}
			}
		}
	}
	function GetRadioSelection(oRadio)
	{
		for (var i = 0;i < oRadio.length;i++)
		{
			if (oRadio[i].checked)
			{
				//break;
				return oRadio[i];
			}
		}
		return false;
	}
	function UnCheckAllBoxes(oForm,sPrefix)
	{
		var f = oForm;
		var intPrefixLen = sPrefix.length;
		for (var i = 0;i < f.length;i++)
		{
			objCurrent = f.elements[i];
			if (objCurrent.type == "checkbox")
			{
				
				if (objCurrent.name.substring(0,intPrefixLen) == sPrefix)
				{
					objCurrent.checked = false;
				}
			}
		}
	}
	
	function ChangeTagStylesByControl(oControl, sTag, sID, sStyleText)
	{
		var objElements = document.all.tags("TD")
		for (var i=0;i<objElements.length;i++)
		{
		 	if (objElements[i].id == sID)
			{
				objElements[i].style.cssText =  sStyleText;
				//objElements[i].style.color = "#ff0000";
			}
		}
	}	
function ShowSecurityAlert()
{
	var f = document.forms['SecurityAlertForm'];
	if (f.SecurityAlert.value == 'true') 
	{ 
		alert('ATTENTION!\n\nYou have filled out the registration form but have not submitted any password-retrieval information. This means that you will not be able to reset your login information if you forget it. \n\nYou will be prompted for this information again the first time you log in.');
	}
}	