//Copyright 2006 Adobe Systems, Inc. All rights reserved.
//
//This is the base class for implementing an Active Content extension -- a piece of code that knows how to rewrite OBJECT tags so that they comply to the Eolas patent without making the browser display the "Press OK to continue loading the content of this page" message box.
//
// When the user hovers the mouse over an ActiveX control in Internet Explorer 6 updated with (April 2006) Cumulative Security Update (912812) or Internet Explorer 7, the following message is displayed:
// “Press Spacebar or Enter to activate and use this control.”
// The user can now click the mouse anywhere inside the ActiveX control area, or press the Spacebar or Enter key to activate the control.
// The standard.js file has been introduced to retain the earlier behavior where the control remains interactive from the first click to the last.


function setTValue(target, val) {     
 	target.value =val;      
}

function thideunhideRefTxt(dropdown, txt, divname, val) {

    var myindex  = document.getElementById(dropdown).selectedIndex;
    var SelValue = document.getElementById(dropdown).options[myindex].value;
    
    if ( (SelValue != "" && SelValue == val) || 
    		(document.getElementById(txt) != null && document.getElementById(txt).value != 'Please Explain'))
    {
    	document.getElementById(divname).style.display="block";
    }
  else
  	{
	  document.getElementById(divname).style.display="none";
  	}
}

function thideunhide(dropdown, divname, val) {

    var myindex  = dropdown.selectedIndex;
    var SelValue = dropdown.options[myindex].value;
    
    if (SelValue == val)
    {
    	document.getElementById(divname).style.display="block";
    }
  else
  	{
	  document.getElementById(divname).style.display="none";
  	}
}

function OnChangeHideShowDropDwnTxt(dropdown, value, txtReferral)
{
    var myindex  = dropdown.selectedIndex;
    var SelValue = dropdown.options[myindex].value;
    
    if (SelValue == value)
    {
    	dropdown.style.visibility = 'hidden';
    	txtReferral.style.visibility = 'visible';
    }
    return true;
}

function ShowHideDiv(src)
{
  for(i=0;i<src.options.length;i++)
    document.getElementById(src.options[i].value).style.display="none";
  document.getElementById(src.options[src.selecteIndex].value).style.display="block";  
}

function writeDocument(s){document.write(s);}

document.write("<link rel=\"shortcut icon\" href=\"favicon.ico\" type=\"image/x-icon\" />");

// Menu functions 
 
var navImgSuffix = "jpg";
var navImgPrefix = "images/nav/";
	
function navSetImg(navGroup, thisItem)	{
	var elem = $("nav" + navGroup + thisItem); // menu item div container		
	var activeItem = eval("navActive_" + navGroup);
	var navPanel;

	if(elem != null){
		if(thisItem == activeItem){
			elem.down(1).src = navImgPrefix + "nav" + navGroup + thisItem + "_on." + navImgSuffix;

			// switch background color of navbar container if you need it to 
			// show through transparent region of buttons when any of them is active

			navPanel = $("nav" + navGroup + "Panel");
			if(navPanel){				
				navPanel.setStyle({ backgroundColor: '' });
			}

			// Remove hyperlink tag in menu item div when it is active
			// so the mouse pointer does not swap to a pointing finger
			//var innerFinal = elem.down(0).innerHTML;
			//elem.down(0).replace(innerFinal);

		}else{
			elem.down(1).src = navImgPrefix + "nav" + navGroup + thisItem + "_off." + navImgSuffix;
		}
	}
}

function over(navGroup, thisItem) 		{
	var elem = $("nav" + navGroup + thisItem);
	var activeItem = eval("navActive_" + navGroup);
	if(elem != null){
		if(thisItem != activeItem){
			elem.down(1).src = navImgPrefix + "nav" + navGroup + thisItem + "_over." + navImgSuffix;
		}
	}
}

function out(navGroup, thisItem) {
	var elem = $("nav" + navGroup + thisItem);
	var activeItem = eval("navActive_" + navGroup);
	if(elem != null){
		if(thisItem != activeItem){
			elem.down(1).src = navImgPrefix + "nav" + navGroup + thisItem + "_off." + navImgSuffix;
		}
	}
}

function hideDiv(divName)
{
     var div = document.getElementById(divName);

	if(div != null)
	{
		div.style.display = "none";							
	}
}
      
function showDiv(divName)
{
     var div = document.getElementById(divName);

	if(div != null)
	{
		div.style.display = "";							
	}
}

function submitForm(formID, redirectTo)
{
    var frm;
    frm = $(formID);
    frm.action=redirectTo;
    frm.submit();
}

function submitApplicantForm(formID, redirectTo)
{
    
		var frm;
		frm = $(formID);
		frm.action=redirectTo;
		frm.submit();
}

	// This code creates a centered pop-up window.
 function launchWindow(w,h,windowName,source,scrollbarsYN)
 {
     var xobj = null;
 
     var chasm = screen.availWidth;
     var mount = screen.availHeight;
 
     xobj = window.open(source,windowName,'width=' + w + ',height=' + h + ',left=' + ((chasm - w - 10) * .5) + ',top=' + ((mount - h - 30) * .5) + ',scrollbars=' + scrollbarsYN + ',resizable=yes,dependent=yes');
     xobj.focus();
 }
 
 // popup function
 function popup(source, windowName) {
     var xobj = null;
 
     xobj = launchWindow(754,520,windowName,source,'no');  
 }
 
function getElement(whichLayer)     {
     var elem;
 
 // this is the way the standards work
  if( document.getElementById )   {
    elem = document.getElementById( whichLayer );
                                  }
  // this is the way old msie versions work
  else if( document.all ) {
      elem = document.all[whichLayer];
                          }
  // this is the way nn4 works
  else if( document.layers )  {
      elem = document.layers[whichLayer];
                              }
  return elem;
                                    }
 
// Example:
// toggleColor("clarity", "rgb(108,156,178)", "rgb(255,0,0)");
// Never use spaces between the hex values when calling this function.
 
function toggleColor (whichLayer, hexcolor_1, hexcolor_2 ) {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
 
  // IE doesn't recognize RGB values with spaces and Firefox doesn't recognize 
  // them without spaces, so I'm instructing Netscape/Firefox to add
  // an extra space after each comma of the hex triplet.
  
  var hexcolor_1, hexcolor_2;
  if (navigator.appName == "Netscape")  {
    hexcolor_1 = hexcolor_1.replace(/,/g,", ");
    hexcolor_2 = hexcolor_2.replace(/,/g,", ");
                                        }
    
  if (vis.backgroundColor == "")      {
    vis.backgroundColor = hexcolor_1; 
                                      }                              
  
  if (vis.backgroundColor == hexcolor_1)          {
    vis.backgroundColor = hexcolor_2;
                                                  }
  else if (vis.backgroundColor == hexcolor_2) {
    vis.backgroundColor = hexcolor_1;
                                              }
                                                          }
 
function setColor (whichLayer, hexcolor) {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
  
  var hexcolor;
  if (navigator.appName == "Netscape")      {
    hexcolor = hexcolor.replace(/,/g,", ");
                                            }                                                            
  vis.backgroundColor = hexcolor;
                                          }
 
function toggleLayer( whichLayer )  {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
 
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&element.offsetWidth!=undefined&&element.offsetHeight!=undefined)
    vis.display = (element.offsetWidth!=0&&element.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
                                    }
 
function selectPanel(whichLayer)  {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
  
  // Each clickable section needs to be in this list.
  var element_list = ["clarity_panel", "natlight_panel", "curbappeal_panel", "strength_panel", "durability_panel", "custommade_panel", "easycare_panel" ];
  
  // Connectors are so named because they are the divs that connect the button
  // to the panel so it looks like one one contiguous region.
  
  var connectorname;
  var i;
  
  // Make every div except for the one specified as this function's argument
  // invisible and set every other connector to the page background color.
  for ( i in element_list ) {
    if (element_list[i] != whichLayer ) {
      document.getElementById(element_list[i]).style.display='none';
      connectorname = element_list[i].replace("_panel","");
      setColor(connectorname, "rgb(197,214,162)");
                                        }
                            }
    
  toggleLayer(whichLayer);
  connectorname = whichLayer.replace("_panel","");
  toggleColor(connectorname, "rgb(197,214,162)", "rgb(108,156,178)");
                                  
                                  }
                                  
function fadeLayer(whichLayer) {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
  vis.opacity = .50;
                                }
 
function unfadeLayer(whichLayer) {
  var vis, element;
  element=getElement(whichLayer);
  vis = element.style;
  vis.opacity = 1;
                                 }
 
 
 
var lastTerm = '';
 
function toggleDefinition(term) {
 var termElem;
 var defElem;
 var imgElem;
 var srcURL;
 
 // hide last selected term
 if (lastTerm != '') {
  termElem = $(lastTerm);
  termElem.removeClassName('active_menu');
  defElem = $(lastTerm + 'Def');
  defElem.hide();
  // set last menu item img back to unSelected
  imgElem = $(lastTerm + 'Img');
  if(imgElem != null){
   srcURL = imgElem.src;
   imgElem.src = srcURL.replace('Sel','UnSel');
  }
 }
 
 // toggle selected term
 if (lastTerm != term) {
  termElem = $(term);
  termElem.addClassName('active_menu');
  defElem = $(term + 'Def');
  defElem.show();
  // set new menu item img to Selected
  imgElem = $(term + 'Img');
  
  if(imgElem != null){
   srcURL = imgElem.src;
   if(srcURL.search(/Over\.(jpg|gif)$/) != -1) {
    imgElem.src = srcURL.replace('Over','Sel');
              }
   else {
    imgElem.src = srcURL.replace('UnSel','Sel');
     }
  }
  
  lastTerm = term;
 }
 else {
  lastTerm = '';
 }
}
 
function overDefinition(term)  {
 //alert("over event fired.");
 var imgElem;
 imgElem = $(term + 'Img');
 
 if ( document.getElementById(term).className != "active_menu")  {
  imgElem.src = imgElem.src.replace('UnSel','Over');
                 }
        }
 
function offDefinition(term)  {
 //alert("off event fired.");
 var imgElem;
 imgElem = $(term + 'Img');
 
 if ( document.getElementById(term).className != "active_menu")  {
  imgElem.src = imgElem.src.replace('Over','UnSel'); 
                 }
 else  {
  imgElem.src = imgElem.src.replace('Over','Sel');
   }
        }        
         
 
var arrayStates = ["AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ", "NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"];
 
function addStateOptions(elem, selected){
 var ddState = '';
 var optn = '';
 
 ddState = $(elem);
 if(ddState != null){
  for(var i=0;i<arrayStates.length;i++){
   optn = document.createElement("OPTION");
   optn.text = arrayStates[i];
   optn.value = arrayStates[i];
   if(selected == arrayStates[i]){optn.selected = true;}
   ddState.options.add(optn);
  }
 }
}
 
function gotoProfMeasure()      {
      window.open("measuring_service.jsp", "top", true);
      self.close();    
}
 
function beforeAfter(feature, beforeafter) {
 var imgSrc;
 var imgElem = feature + "Img";
  var mapElem = feature + "Map";
  var mapParam = "Before";
  
  if(beforeafter == "Before"){
   mapParam = "After";
   mapHTML = '<area shape="rect" coords="329,156,376,175" href="javascript:beforeAfter(\'' 
    + feature + '\', \'' + mapParam + '\')" />';
  }else{
   mapParam = "Before";
   mapHTML = '<area shape="rect" coords="273,156,321,175" href="javascript:beforeAfter(\'' 
    + feature + '\', \'' + mapParam + '\')" />';  
  }
  
 imgSrc = "images/imgFeature" + feature + beforeafter + ".jpg";
         
                           
 $(imgElem).src = imgSrc;
 $(mapElem).innerHTML = mapHTML;
}
                             
function URLencode(s){
 // Replace % first as it defines all encoding
 if(s != null){
  s = s.replace(/\%/g, "%25");
 
  s = s.replace(/\$/g, "%24");
  s = s.replace(/&/g, "%26");
  s = s.replace(/\+/g, "%2B"); // plus
  s = s.replace(/\x2C/g, "%2C"); // comma
  s = s.replace(/\x2F/g, "%2F"); // fwd slash
  s = s.replace(/:/g, "%3A");
  s = s.replace(/\x3B/g, "%3B"); // semi-colon
  s = s.replace(/=/g, "%3D");
  s = s.replace(/\?/g, "%3F");
  s = s.replace(/@/g, "%40");
 
  // Other
  s = s.replace(/ /g, "%20");
  s = s.replace(/\x22/g, "%22"); // double quote
  s = s.replace(/\x27/g, "%27"); // single quote
  s = s.replace(/\x91/g, "%91"); // left curly single quote
  s = s.replace(/\x92/g, "%92"); // right curly single quote
  s = s.replace(/\x93/g, "%93"); // left curly double quote
  s = s.replace(/\x94/g, "%94"); // right curly double quote
  s = s.replace(/</g, "%3C");
  s = s.replace(/>/g, "%3E");
  s = s.replace(/#/g, "%23");
  s = s.replace(/\{/g, "%7B");
  s = s.replace(/\}/g, "%7D");
  s = s.replace(/\|/g, "%7C");
  s = s.replace(/\\/g, "%5C");
  s = s.replace(/\^/g, "%5E");
  s = s.replace(/~/g, "%7E");
  s = s.replace(/\[/g, "%5B");
  s = s.replace(/\]/g, "%5D");
  s = s.replace(/`/g, "%60");
 }
 return s;
}
 

function URLdecode(s){
 if(s != null){ 
  s = s.replace(/\%24/g, "$");
  s = s.replace(/\%26/g, "&");
  s = s.replace(/\%2B/g, "+");
  s = s.replace(/\%2C/g, ",");
  s = s.replace(/\%2F/g, "/");
  s = s.replace(/\%3A/g, ":");
  s = s.replace(/\%3B/g, ";");
  s = s.replace(/\%3D/g, "=");
  s = s.replace(/\%3F/g, "?");
  s = s.replace(/\%40/g, "@");
 
  // Other
  s = s.replace(/\%20/g, " ");
  s = s.replace(/\%22/g, String.fromCharCode(34)); // double quote
  s = s.replace(/\%27/g, String.fromCharCode(39)); // single quote
  s = s.replace(/\%91/g, String.fromCharCode(145)); 
  s = s.replace(/\%92/g, String.fromCharCode(146)); 
  s = s.replace(/\%93/g, String.fromCharCode(147)); 
  s = s.replace(/\%94/g, String.fromCharCode(148)); 
  s = s.replace(/\%3C/g, "<");
  s = s.replace(/\%3E/g, ">");
  s = s.replace(/\%23/g, "#");
  s = s.replace(/\%7B/g, "{");
  s = s.replace(/\%7D/g, "}");
  s = s.replace(/\%7C/g, "|");
  s = s.replace(/\%5C/g, String.fromCharCode(92)); // backslash
  s = s.replace(/\%5E/g, "^");
  s = s.replace(/\%7E/g, "~");
  s = s.replace(/\%5B/g, "[");
  s = s.replace(/\%5D/g, "]");
  s = s.replace(/\%60/g, String.fromCharCode(96)); // accent grave
 
  s = s.replace(/\%25/g, "%");
 } 
 return s;
}
 						
function makeStateAjaxRequest() {

  var valueChosen = $('propertyState').getValue();

  if(valueChosen == "")
  	return;
  	 
  var url = "GenerateProductPricing";
  var argument = { componentId:"join", arguments:[ { name:"state", value:valueChosen }] };
  var postdata = "json=" + argument.toJSONString();
  var request = YAHOO.util.Connect.asyncRequest('POST',url, new callback(argument), postdata);
}


function makeScreeningStateRequest() {
	  
	  var valueChosen = $('screeningState').getValue();

	  if(valueChosen == "")
		  	return;
					  			  	  
	  var url = "GenerateApplicantProductPricing";
	  var argument = { componentId:"join", arguments:[ { name:"screeningState", value:valueChosen }] };
	  var postdata = "json=" + argument.toJSONString();
	  var request = YAHOO.util.Connect.asyncRequest('POST',url, new callback(argument), postdata);
}


var downStrokeField;
function autojump(fieldName,nextFieldName,fakeMaxLength)
{
	var myForm=document.forms[document.forms.length - 1];
	var myField=myForm.elements[fieldName];
	myField.nextField=myForm.elements[nextFieldName];
	
	if (myField.maxLength == null)
	   myField.maxLength=fakeMaxLength;
	
	myField.onkeydown=autojump_keyDown;
	myField.onkeyup=autojump_keyUp;
}

function autojump_keyDown()
{
	this.beforeLength=this.value.length;
	downStrokeField=this;
}

function autojump_keyUp()
{
	if (
	   (this == downStrokeField) && 
	   (this.value.length > this.beforeLength) && 
	   (this.value.length >= this.maxLength)
	   )
	   this.nextField.focus();
	downStrokeField=null;
}


function openModal(page, name, width, height, title) {
	if(title) {
		page += '&title=' + title;
	}
	
	if (window.showModalDialog ) { 
		window.showModalDialog(page, name,
		"dialogWidth:" + width + "px;dialogHeight:" + height + "px");
	} else {   	
		window.open(page, name,
				'height=' + height + ',width=' + width + ',toolbar=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,modal=no');
		
	}
} 

function wopen(url, name, title, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.

w += 32;
h += 96;
 var win = window.open(url,
  name, 
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=yes, title=' + title + ', ' +
  'status=no, toolbar=no, scrollbars=yes, resizable=no');
 
 win.resizeTo(w, h);
 win.focus();
}

//select dropdown by value
function setSelectedIndex(s, v) {
	for ( var i = 0; i < s.options.length; i++ ) {
		if ( s.options[i].value == v ) {
			s.options[i].selected = true;
			return;
		}
	}
}

function setExpDateToToday()
{
	var monthList = document.getElementById("ccExpMonth");
	var yearList = document.getElementById("ccExpYear");

	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1;//January is 0!
	var yyyy = today.getFullYear();
	if(dd<10){dd='0'+dd}
	if(mm<10){mm='0'+mm}

	setSelectedIndex(monthList, mm);
	setSelectedIndex(yearList, yyyy);
}
