// Global Section
if (!ImagePathDef) var ImagePathDef = '/images/';

if (!ExpandedMenuBGColor) var ExpandedMenuBGColor = '#FFFFFF';
if (!bShowCoBranding) var bShowCoBranding = 'Y';
if (!bHomePage) var bHomePage = 'N';
if (!ShowB2CCookiePhoneNo) var ShowB2CCookiePhoneNo = 'Y';

if  (!SelChildItemImg) var SelChildItemImg = 'hl_green_dot.gif';	
if (!aRollImagesOnDef) {
	var aRollImagesOnDef = new Array();
	var iCnt = 0;
			
	aRollImagesOnDef[iCnt++] = "hl_top_nav_pur_ro.gif";
	aRollImagesOnDef[iCnt++] = "hl_top_nav_ref_ro.gif";
	aRollImagesOnDef[iCnt++] = "hl_top_nav_heq_ro.gif";
	aRollImagesOnDef[iCnt++] = "hl_top_nav_tr_ro.gif";
	aRollImagesOnDef[iCnt++] = "hl_top_nav_cs_ro.gif";
	aRollImagesOnDef[iCnt++] = "hl_top_nav_mp_ro.gif";
}

if (!aRollImagesOffDef) {
	var aRollImagesOffDef = new Array();
	var iCnt = 0;
			
	aRollImagesOffDef[iCnt++] = "hl_top_nav_pur_off.gif";
	aRollImagesOffDef[iCnt++] = "hl_top_nav_ref_off.gif";
	aRollImagesOffDef[iCnt++] = "hl_top_nav_heq_off.gif";
	aRollImagesOffDef[iCnt++] = "hl_top_nav_tr_off.gif";
	aRollImagesOffDef[iCnt++] = "hl_top_nav_cs_off.gif";
	aRollImagesOffDef[iCnt++] = "hl_top_nav_mp_off.gif";
}
var IE4 = (document.all) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var NS6 = (document.getElementById && !IE4) ? 1 : 0;
var ver4 = (NS4 || IE4 || NS6) ? 1 : 0;
var isLoggedIn = GetCookie('CCN')!=null;
var hideLogInLinks = false;
var selectParent = null;
var selectChild = null;

if (document.images) {
	// Active Images
	iCnt = 0;
    roll1_on = new Image();          
    roll1_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
    roll2_on = new Image();          
    roll2_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
    roll3_on = new Image();          
    roll3_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
    roll4_on = new Image();          
    roll4_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
	roll5_on = new Image();          
    roll5_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
	roll6_on = new Image();          
    roll6_on.src = ImagePathDef + aRollImagesOnDef[iCnt++];
    // Inactive Images
    iCnt = 0;
    roll1_off = new Image();         
    roll1_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];     
    roll2_off = new Image();          
    roll2_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];
    roll3_off = new Image();          
    roll3_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];
    roll4_off = new Image();          
    roll4_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];
	roll5_off = new Image();          
    roll5_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];
	roll6_off = new Image();          
    roll6_off.src = ImagePathDef + aRollImagesOffDef[iCnt++];
}
		        
function ratewatch()
{
	OpenWindow=window.open("/ratewatch/entry.asp","Rate_Watch","height=735,width=780,toolbar=yes,resizable=1,menubar=yes,scrollbars=yes,location=no,status=no");
} 			
function launch(newURL, newName, newFeatures, orgName) 
{
	var remote = open(newURL, newName, newFeatures);  
	if (remote.opener == null)
		remote.opener = window;
	remote.opener.name = orgName;
	return remote;
}
function POP_IT(WindowName,WindowTitle,WindowLink,WindowFeatures, PopUnder) {
	var win;
	win = launch('/popup/popup.asp?TARGETPAGE=' + WindowName + '&PAGETITLE=' + WindowTitle + '&TARGETLINK=' + WindowLink,'POPUPWINDOW',WindowFeatures,'Original');
	if(PopUnder==true){win.opener.focus();}
}

// Function to 'activate' images.
function imgOn(imgName) {
	if (!ver4) return;
	if (NS4) {
		document.MainBodyDiv.document[imgName].src = eval(imgName + "_on.src");
	}
	else {
		document[imgName].src = eval(imgName + "_on.src");
	}
		
}

// Function to 'deactivate' images.
function imgOff(imgName) {
	if (!ver4) return;
	if (NS4) {
		document.MainBodyDiv.document[imgName].src = eval(imgName + "_off.src");
	}
	else {
		document[imgName].src = eval(imgName + "_off.src");
	}
}
	
// Function to 'activate' pop-up layers.
function popUpShow(whichDiv) {
	if (!ver4) return;
	if (NS4) {
		eval ("document." + whichDiv + ".visibility = 'visible'");
	}
	else {
		eval (whichDiv + ".style.visibility = 'visible'");
	}
		
}

// Function to 'deactivate' pop-up layers.
function popUpHide(whichDiv) {
	if (!ver4) return;
	if (NS4) {
		eval ("document." + whichDiv + ".visibility = 'hidden'");
	}
	else {
		eval (whichDiv + ".style.visibility = 'hidden'");
	}
		
}
	
if (ver4) 
{
	with (document) 
	{
	    write("<STYLE TYPE='text/css'>\n");
	    if (NS4)
	    {
	        write(".parent {position:absolute; visibility:inherit}\n");
	        write(".child {position:absolute; visibility:inherit}\n");
	        write(".uniparent {position:absolute; visibility:inherit}\n");
	    }
	    else
	    {
	        write(".child {display:none}\n")
	    }
	    write("</STYLE>");
	}
}

isExpanded = false;

function getIndex(el) 
{
	ind = null;
	for (i=0; i<document.NavMenu.document.layers.length; i++) {
		whichEl = document.NavMenu.document.layers[i];
		if (whichEl.id == el) {
		    ind = i;
		    break;
		}
	}
	//alert("index" +ind)
	return ind;
}

function arrange() 
{	firstInd=0
	nextY = document.NavMenu.document.layers[firstInd].pageY + document.NavMenu.document.layers[firstInd].document.height;
	for (i=firstInd; i<document.NavMenu.document.layers.length; i++) 
	{
	    if (document.NavMenu.document.layers[i].name != "Content") 
	    {
		    whichEl = document.NavMenu.document.layers[i];
		    if (whichEl.visibility != "hide") 
		    {
		        whichEl.pageY = nextY;
			    whichEl.pageX = 0;
		        nextY += whichEl.document.height;
		    }
	    }
	}
}

function initIt()
{
	setLoggedInState();
	ReadGlobalPhoneCookie();
    hideEmptyMenus(document.getElementById("Content"));
    if (!ver4) return;
	if (NS4) 
	{
		for (i=0; i<document.NavMenu.document.layers.length; i++) 
		{
		    whichEl = document.NavMenu.document.layers[i];
		    if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
		}
		arrange();
		// make the menu visible after it finishes loading to prevent the flashing effect
		document.NavMenu.visibility = "visible";
	}
	else 
	{
		divColl = document.getElementsByTagName("DIV");
		for (i=0; i<divColl.length; i++) 
		{
		    whichEl = divColl[i];
		    if (whichEl.className == "child") whichEl.style.display = "none";
		}
	}
    moveFooter(document.getElementById("FooterTable"));	
}
function ReadGlobalPhoneCookie()
{	
	if (document.getElementById) 
	{
		var PHONE_NO_COOKIE='B2CPhoneNoCookie';
	
		var B2CPhoneNoCookie = GetCookie(PHONE_NO_COOKIE);
		if (B2CPhoneNoCookie) var B2CCookiePhoneNo = B2CPhoneNoCookie.split("=")[1];
	
		if(B2CCookiePhoneNo)
		{ 
			if(ShowB2CCookiePhoneNo=='Y')
			{	
				SetPhoneNumber(B2CCookiePhoneNo);
			}
		}
	}
}
function SetPhoneNumber(phoneNumber)
{
	if (document.getElementById) 
	{
		
		var PHONE_NO_ELEMENT_NAME='DynTollFreeNumElem';
		if(phoneNumber)
		{ 
			if(phoneNumber.length>10)
			{
				phoneNumber = phoneNumber.substring(0, 1) + '-' + phoneNumber.substring(1, 4) + '-' + phoneNumber.substring(4, 7) + '-' + phoneNumber.substring(7, 11); 
			}
			else
			{
				phoneNumber = phoneNumber.substring(0, 3) + '-' + phoneNumber.substring(3, 6) + '-' + phoneNumber.substring(6, 10); 
			}
			if(document.getElementById("TopMenuPhoneNo")) document.getElementById("TopMenuPhoneNo").innerHTML = phoneNumber;
			if(document.getElementById("InstantCallBackPhoneNo")) document.getElementById("InstantCallBackPhoneNo").innerHTML = phoneNumber;
			
			if (document.getElementsByName)
			{
				var collPhoneElements = document.getElementsByName(PHONE_NO_ELEMENT_NAME);
				for ( var cnt = 0; cnt < collPhoneElements.length; cnt++ )
				{
					collPhoneElements[cnt].innerHTML = phoneNumber;
				}
			}
			
		}
	}
}
function setLoggedInState()
{
	if (document.getElementById) 
	{
		var rootURL = 'http://' + location.hostname;
		var myURL = document.URL.toLowerCase();
		var isfirstimebuyer  = false;
		/*checking if it is firsttimebuyer we dont have secure certificate for first time buyer */
		if(rootURL.indexOf('firsttimebuyer')>=0)
		{
		    isfirstimebuyer = true;
		}
		rootURL = rootURL.replace('firsttimebuyer.','www.');
		rootURL = rootURL.replace('offices.','www.');
		rootURL = rootURL.replace('mobile.','www.');
		var poundSign = myURL.indexOf('#');
		if(poundSign > 0) myURL = myURL.substring(0,poundSign);
		var	loginHTML = "";
        if(isfirstimebuyer==true)
        {    
			loginHTML = '<a href="'+rootURL+'/director.aspx?action=EPASSCMDLOGIN&URI=' + escape(rootURL.replace('http://', 'https://') + '/director.aspx?LoginURL=' + myURL.replace('http://', 'http://')) + '">Log In</a>';
		}
		else
		{
		    loginHTML = '<a href="'+rootURL+'/director.aspx?action=EPASSCMDLOGIN&URI=' + escape(rootURL.replace('http://', 'https://') + '/director.aspx?LoginURL=' + myURL.replace('http://', 'https://')) + '">Log In</a>';
		}
		var	logoutHTML = '<a href="'+rootURL+'/director.aspx?action=EPASSLOGOUT&URI=' + escape(rootURL.replace('https://', 'http://') + '/director.aspx?LoginURL=' + myURL.replace('https://', 'http://')) + '">Log Out</a>';
		var	EnEspanolHTML = '<a href="' + rootURL + '/director.aspx?action=ENESPANOL">en espa&#241;ol</a> | ';
		if(document.getElementById("EnEspanol")!=null) 
		{
			document.getElementById("EnEspanol").innerHTML = EnEspanolHTML;
		} 
		if(document.getElementById("loggedInState")!=null) 
		{
			if (hideLogInLinks) 
            {
                document.getElementById("FooterLoginBar").innerHTML = '';
                document.getElementById("loggedInState").innerHTML = '';
                document.getElementById("topLoginDot").style.display = "none"
            }
			else if(isLoggedIn) document.getElementById("loggedInState").innerHTML = logoutHTML;
			else document.getElementById("loggedInState").innerHTML = loginHTML;
		}
		if(document.getElementById("topLoggedInState")!=null) 
		{
			if (hideLogInLinks)
            {
                document.getElementById("FooterLoginBar").innerHTML = '';
                document.getElementById("topLoggedInState").innerHTML = '';
                document.getElementById("topLoginDot").style.display = "none"
            }
			else if(isLoggedIn) document.getElementById("topLoggedInState").innerHTML = logoutHTML;
			else document.getElementById("topLoggedInState").innerHTML = loginHTML;
		}
	}
}
function CloseAll(Pos)
{
	if (IE4 || NS6 ) 
	{
		divColl = document.getElementsByTagName('DIV');
		for (i=0; i<divColl.length; i++) 
		{
			whichEl = divColl[i];
			if (whichEl.className == "child") whichEl.style.display = "none";
		}
	}
	else
	{
		for (i=0; i<document.NavMenu.document.layers.length; i++) 
		{
			whichEl = document.NavMenu.document.layers[i];
			if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
		}
		arrange();
	}	
}

function hideEmptyMenus(menu)
{
    if(document.getElementById("el1Parent")==null)
    {
        // If there is a menu and it's empty, clear it.
        if(menu!=null) menu.innerHTML="";
        var ICB = document.getElementById("DivInstantcallback");
        // If there is a call back section, move it up
        if(ICB!=null) ICB.style.paddingTop="0px";
    }
}
function moveFooter(footer)
{
    // If there is no menu, just return
    if(document.getElementById("NavMenu")==null||footer==null) return;
    var MenuY = document.getElementById("NavMenu").offsetTop;
    var NavMenuHeight = document.getElementById("NavMenu").clientHeight
    // Add the height of the "Menu" div to the height of the "NavMenu" div plus 10px for safety
    var menuBottom = (MenuY + NavMenuHeight + 10);
    var overlap = menuBottom - footer.offsetTop;
    var footerSpace = document.getElementById("footerSpacerImg");
    // if the menu is too close to the footer, push the footer down
    // else make sure there are at least 50px between the content and the footer
    if(footerSpace!=null)
    {
        if(overlap>0) footerSpace.height = overlap+10;    
        else footerSpace.height = 25;   
    }
}

function expandIt(el) 
{
    if (!ver4) return;
	if (IE4 || NS6) 
	{
	    whichEl = document.getElementById(el + "Child");
		if (whichEl.style.display == "none") whichEl.style.display = "block";
		else whichEl.style.display = "none";
	}
	else 
	{
	    whichEl = eval("document.NavMenu.document." + el + "Child");
		if (whichEl.visibility == "hide") whichEl.visibility = "show";
		else whichEl.visibility = "hide";
		arrange();
	}
    // Move the footer down if needed
    moveFooter(document.getElementById("FooterTable"));	
}

function highlight(parentNum,childItemNum) 
{
    if (!ver4) return;
	//mark this menu as selected
	var el = "el" + parentNum
	var nextNum = parentNum + 1
	selectParent = el
	//change its background color and its bullet image
	if (IE4 || NS6) 
	{
		if (document.getElementById(el + 'Parent'))
		{	
			whichElP = document.getElementById(el + "Parent");
			whichELink = document.getElementById('Link' + parentNum);
//			whichImP = document.images[el + 'imEx'];
			
			nextYelIm = document.images['Rule' + nextNum ];
		
			whichElP.style.backgroundColor = ExpandedMenuBGColor;
			if (whichElP)	whichElP.className = 'menuParentSelected';
			if (whichELink) whichELink .className = 'menuParentSelected';
			whichElP.style.backgroundColor = ExpandedMenuBGColor;
			whichElP.style.fontWeight = "bold";
			//turn off the yellow rule on the following item
			if (nextYelIm) nextYelIm.src = '/images/spacer.gif';
			//if the Parent has children expand it
            var elC = el + 'Child';
   			whichElC = document.getElementById(elC);
			if (whichElC) 
			{
				//if there is a child selected to highlight, change its color
				expandIt(el);
				var elCh = 'Child' + parentNum + '-' + childItemNum;
				whichElCh = document.getElementById(elCh);
				if (childItemNum != null && whichElCh!= null)
                {
    			    whichElCh.style.fontWeight = "bold";
                }
			}
//			//else just change it to yellow, but do not expand it
//			else 
//				whichImP.src = ImagePathDef + "mn_ylw_arrow_no.gif";
		}		
	}
	else 

	{
		whichElP = eval("document.NavMenu.document." + el + "Parent");
		whichElC = eval("document.NavMenu.document." + el + "Child");
		whichImP = eval("whichElP.document.images['"+ el + "imEx']");
		//alert(whichImP.src);
		if (eval("document.NavMenu.document." + el + "Parent"))
		{
			if (eval("document.NavMenu.document.el" + nextNum + "Parent")) 
			{
				nextYelIm = eval("document.NavMenu.document.el" + nextNum + "Parent.document.images['Rule" + nextNum + "']");
				whichElP.bgColor = ExpandedMenuBGColor;
				whichElP.className = 'menuParentSelected';
				whichElC.bgColor = ExpandedMenuBGColor;
				//turn off the yellow rule on the following item
				nextYelIm.src = ImagePathDef + "spacer.gif"
			}
			//if the image has an arrow, change it to yellow and expand it
			var imageSource = whichImP.src;
			if (imageSource.indexOf("mn_arrow_on.gif") != -1) 
			{
				whichImP.src = ImagePathDef + "hl_green_arrow.gif"
				//if there is a child selected to highlight, change its image to the checkbox
				if (childItemNum != null) eval ("whichElC.document.images['ChildImage" + parentNum + "-" + childItemNum + "'].src = ImagePathDef + 'hl_green_dot.gif'")
				expandIt(el);
			}
			//else just change it to yellow, but do not expand it
			else
				whichImP.src = ImagePathDef + "mn_ylw_arrow_no.gif";
		}
	}
}
	
//CSS window resize fix for NS 4.x
function reDo() 
{
    if (innerWidth != origWidth || innerHeight != origHeight)
	//location.reload(true);
	window.history.go(0);
}

if (NS4) 
{
	origWidth = innerWidth;
	origHeight = innerHeight;
	onresize = reDo;
}
		
//function that calls help popup		
function showHelp(sTerm, sMatch, sAppName, sTitle, sCont)
{
    var sMachine = location.host;
    var sProtocol = location.protocol + '//';
    var nDot = sMachine.search(/./);
    if ((sMachine != 'staging.countrywide.com') && (nDot > 0)) 
        sMachine = sProtocol + 'www.' + sMachine.substr(nDot + 1);
    else
        sMachine = sProtocol + sMachine;
	var sURL = sMachine + '/Help/PopupHelp.asp';
	var sTargetPage = '?TARGETPAGE=' + sMachine + '/help/showhelp.asp';
	var sTargetLink = '&TARGETLINK=' + sTerm;
	var sMatch = '&MATCH=' + sMatch;
	if ((showHelp.arguments.length > 2) && (showHelp.arguments[2].length > 0))
		var sApp = '&APPLICATION=' + sAppName;
	else
		var sApp = '';
	if ((showHelp.arguments.length > 3) && (showHelp.arguments[3].length > 0))
		var sPageTitle = '&PAGETITLE=' + sTitle;
	else
		var sPageTitle = '';
	if ((showHelp.arguments.length > 4) && (showHelp.arguments[4].length > 0))
		var sContext = '&CONTEXT=' + sCont;
	else
		var sContext = '';
	if (location.href.indexOf('#') > 0)
		var sCallingPage = 'CALLINGPAGE=' + location.href.substring(0, location.href.indexOf('#'));
	else
		var sCallingPage = 'CALLINGPAGE=' + location.href;
	sCallingPage = '&' + sCallingPage.replace(/&/g,"|");
	var sFeatures = 'toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,copyhistory=no,scrollbars=1,width=642,height=345, left=250, top=100';
	//open popup window
	launch(sURL + sTargetPage + sTargetLink + sMatch + sApp + sPageTitle + sContext + sCallingPage, 'POPUPWINDOW', sFeatures);
}

//hide a temporary Layer
function hideLayer() 
{
	if (NS4) 
		document.loadingLayer.visibility = "hidden";
	else 
		loadingLayer.style.visibility = "hidden";
}
		
var ITEM_DELIMITER = "|"
var EQUAL_DELIMITER = "~"	
var ARG_INCREMENT = 3;
var HIDE_DIV = 'H';
var SHOW_DIV = 'S';
var Hide, Show;

// set hidden/visible vars for Netscape 4 & IE compatibility
if (NS4) 
{
	Hide = "hide";
	Show = "show";
} 
else 
{
	Hide = "hidden";
	Show = "visible";
}

function GetStyle(id) 
{
	// Checks the DOM strategy and return an object reference.
	if (IE4 || NS6) 
		return document.getElementById(id).style;
	else
		return document.layers[id];
}

function MoveLayer(LayerID, TopPos, LeftPos)
{
	var oLayer;
	
	oLayer = GetStyle(LayerID);
	if (NS4)
	{
		oLayer.left = LeftPos;
		oLayer.top = TopPos;
	}
	else
	{
		oLayer.pixelTop = TopPos;
		oLayer.pixelLeft = LeftPos;			
	}

}
function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break; 
	}
	return null;
}

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function ChangeVisibility() 
{
	var oLayer, nCnt;
	
	// run through the args (objects) and set the visibility of each
	for (nCnt=0; nCnt<arguments.length; nCnt+=ARG_INCREMENT) 
	{
	    // Get a reference to the Style object
	    oLayer = GetStyle(arguments[nCnt]);		      
	    if (arguments[nCnt+1] == HIDE_DIV) oLayer.visibility = Hide;		
	    else if (arguments[nCnt+1] == SHOW_DIV) oLayer.visibility = Show;		 
	    else	// toggle the object's visibility
	    {  
		    if (oLayer.visibility == Show) oLayer.visibility = Hide;
		    else oLayer.visibility = Show;
	    }
	    if (arguments[nCnt+2] != '') oLayer.position = arguments[nCnt+2];
	}
	window.scrollTo(0,0);
}

function IsVisible(Layer)
{
	var oLayer;
	oLayer = GetStyle(Layer);
	return (oLayer.visibility == Show); 
}

function WriteHiddens(LayerID, FormName, FormElement)
{
	var nLayer, nForm, nField, sData, oElement

	sData = "";
	// cycle through each layer's forms in NetScape
	if (NS4) 
	{
		for (nLayer=0; nLayer<document.layers.length; nLayer+=1)
		{	
			for (nForm=0; nForm<document.layers[nLayer].document.forms.length; nForm+=1) 
			{	
				for (nField=0; nField<document.layers[nLayer].document.forms[nForm].elements.length; nField+=1) 
				{
					oElement = document.layers[nLayer].document.forms[nForm].elements[nField];
					if (oElement.name != FormElement)
					{
						switch (oElement.type)
						{
							case "radio": case "checkbox":
								if (oElement.checked)
									sData = sData + oElement.name + EQUAL_DELIMITER + oElement.value + ITEM_DELIMITER;
								break;
							case "select-one":
								//alert(oElement.type + '   ' + oElement.name + '   ' + oElement[oElement.selectedIndex].value);
								sData = sData + oElement.name + EQUAL_DELIMITER + oElement[oElement.selectedIndex].value + ITEM_DELIMITER;
								break;
							default:									
								sData = sData + oElement.name + EQUAL_DELIMITER + oElement.value + ITEM_DELIMITER;
						}
					}
				}
			}			
		}
	}			
	
	// cycle through the top-level document's forms
	for (nForm=0; nForm<document.forms.length; nForm+=1)
	{
		for (nField=0; nField<document.forms[nForm].elements.length; nField+=1)
		{
			oElement = document.forms[nForm].elements[nField];
			if (oElement.name != FormElement)
			{
				if (oElement.type == "radio" || oElement.type == "checkbox")
				{
					if (oElement.checked)
						sData = sData + oElement.name + EQUAL_DELIMITER + oElement.value + ITEM_DELIMITER;
				}
				else
					sData = sData + oElement.name + EQUAL_DELIMITER + oElement.value + ITEM_DELIMITER;
			}
		}
	}

	if (IE4 || NS6)
		document.forms[FormName].elements[FormElement].value = sData;
	else
		document.layers[LayerID].document.forms[FormName].elements[FormElement].value = sData;

	return true;
}		

function SaveForms(LayerID, FormName, Action, FormElement) 
{
	var oForm;
	
	if (IE4 || NS6 || LayerID == '')
		oForm = document.forms[FormName];
	else
		oForm = document.layers[LayerID].document.forms[FormName];

	oForm.action = Action;
	WriteHiddens(LayerID, FormName, FormElement);
	oForm.submit();
	return true;
}

function ChangeImages() 
{		
	var oImage, nIndex, nCnt, ImageName, NewImageSource, LayerID;
	
	for (nCnt=0; nCnt<arguments.length; nCnt+=ARG_INCREMENT) 
	{		
		ImageName = arguments[nCnt];
		NewImageSource = arguments[nCnt+1];
		LayerID = arguments[nCnt+2];
				
		if (IE4)
		{
			nIndex = GetImageNum(ImageName);
			if (nIndex >= 0) oImage = document.images[nIndex];
		}
		else if (LayerID != '')	oImage = document.layers[LayerID].document.images[ImageName];
		else oImage = document.images[ImageName];
		if (oImage) oImage.src = NewImageSource;	
	}
	return true;
}

function GetImageNum(ImageName)
{
	for (var nIndex=0; nIndex<document.images.length; nIndex++)
	{
		if (document.images[nIndex].name==ImageName) return nIndex;
	}		
	return -1;
}

function SubmitForm(DivLayerName, FormName, Action)
{	
	var oForm;
	
	if (IE4 || NS6 || DivLayerName == '') oForm = document.forms[FormName];
	else oForm = document.layers[DivLayerName].document.forms[FormName];

	oForm.action = Action;
	oForm.submit();
	return true;
}

function SetValueAndSubmitForm(DivLayerName, FormName, Action, Element, Value)
{	
	var oForm, oElement;
	
	if (IE4 || DivLayerName == '') oForm = document.forms[FormName];
	else oForm = document.layers[DivLayerName].document.forms[FormName];
	
	oElement = oForm.elements[Element];
	if (oElement) 
	{
		oElement.value = Value;
		oForm.action = Action;
		oForm.submit();
		return true;
	}
	else return false;			
}

function GetForm(FormName, LayerName) 
{
	if (IE4 || NS6) return document[FormName];
	else return document.layers[LayerName].document.forms[FormName];
}

function ClearForm(FormName, LayerName) 
{
	var oElements;
	var nCnt;
	
	if (IE4 || LayerName == '') oElements = document.forms[FormName].elements;
	else oElements = document.layers[LayerName].document.forms[FormName].elements;
		  		
	for (nCnt = 0; nCnt < oElements.length; nCnt++)
	{
	    if (oElements[nCnt].type == 'text' || oElements[nCnt].type == 'password') oElements[nCnt].value = '';
	}
}

function GetFormElement(ElementName, FormName, LayerName) 
{
	if (IE4 || NS6 || LayerName=='') return document.forms[FormName].elements[ElementName];
	else return document.layers[LayerName].document.forms[FormName].elements[ElementName];
}

function PrintFriendly(oStayVisible,xPos,yPos,ImageName,FriendlyImg,FriendlyAlt,NonImg,NonAlt,HighLightMenuItem)
{
    var oDIvar, imgnum, DIVs;
    if (IE4) oDIvar = document.all.tags('DIV');
    else oDIvar = document.layers;

	for (var nCnt=0; nCnt < oDIvar.length ; nCnt++) 
	{
	    var oDStyle = (IE4) ? oDIvar[nCnt].style : oDIvar[nCnt];
	    if (oDIvar[nCnt].document.layers)
	    {
	        for (var nCnt1=0; nCnt1 < oDIvar[nCnt].document.layers.length ; nCnt1++)
	        {
	            if (bPrintFriendly)
		            oDIvar[nCnt].document.layers[nCnt1].visibility = Show ;
		        else 
		            oDIvar[nCnt].document.layers[nCnt1].visibility = Hide ;
	        }
	    }
	    if (bPrintFriendly)
		    oDStyle.visibility = Show ;
		else 
		    oDStyle.visibility = Hide ;
	}
	popUpShow(oStayVisible);
    oDIvar = (NS4) ? document.layers['CalcResultsDiv'].document.images : document.images;
    oDIvar[ImageName].src = (bPrintFriendly) ? FriendlyImg : NonImg;
    oDIvar['PrintClick'].src = (bPrintFriendly) ? '/images/spacer.gif': '/images/PrintClick.gif' ;
    oDIvar[ImageName].alt = (bPrintFriendly) ? FriendlyAlt : NonAlt;
	if (!bPrintFriendly)
	{
		MoveLayer(oStayVisible,1,1);
        popUpShow('LegalParagraph');
	}
	else
	{
		MoveLayer(oStayVisible,xPos,yPos);
        popUpHide('LegalParagraph');
        CloseAll();
        if (HighLightMenuItem)	expandIt('el'+ HighLightMenuItem);
        else if ((typeof el4Child)!= 'undefined') expandIt('el4');
	}
	bPrintFriendly = !bPrintFriendly;
}
function LiveChatLink()
{
    var curDateTime = new Date();
    var curDay = curDateTime.getDay();
    var curHour = curDateTime.getHours();
    var centralTimeZoneOffset = 5
    var CentralTimeHour = curHour + ((curDateTime.getTimezoneOffset()/60) - centralTimeZoneOffset);
    if (curDay > 0 && curDay < 6)
        if (CentralTimeHour < 17 && CentralTimeHour > 7) 
	        return POP_IT('https://firepond.countrywide.com/converse/brightconverser.html','LiveChat','','toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=no,width=525,height=580');
	    else
		    return POP_IT('/global/OffHours.asp?scriptName=' + scriptName,'LiveChat','','toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=no,width=500,height=400');
    else
	    return POP_IT('/global/OffHours.asp?scriptName=' + scriptName,'LiveChat','','toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=no,width=500,height=400');
}
function termsSummary()
{
    OpenWindow=POP_IT('/HELOC_Summary.asp','Terms_Summary','','height=500,width=475,toolbar=no,resizable=0,menubar=yes,scrollbars=yes,location=no,status=no');
}
function GetOmnitureURL(action, products)
{	
	var querystring = '';
	var pagename = window.location.pathname.toLowerCase();
	if(action!=null&&action.length>0) querystring += '&Action=' + action
	if(products!=null&&products.length>0) querystring += '&Products=' + products
	if(querystring.length>0)pagename += '?' + querystring.substring(1,querystring.length)
	return pagename;
}
function TimeoutAlert()
{
	//var sHelpPrompt =' Attention ';
	var aMsgs = new Array();
	aMsgs[0] = 'As a security precaution, you have five minutes';
	aMsgs[1] = 'remaining before your current session times out.';
	aMsgs[2] = ' ';
	aMsgs[3] = 'Please select "Continue" to proceed.';
	showErrorLayer(aMsgs,' Attention ',true);
}

function ChangeCalcPhoneNoInMenus()
{
	var changephonenoinmenus = document.getElementById('txtCalcPhoneNo').getAttribute('changephonenoinmenus');
    var oldphoneno = document.getElementById('txtCalcPhoneNo').getAttribute('oldphoneno');
    var newphoneno = document.getElementById('txtCalcPhoneNo').getAttribute('newphoneno');
    var topMenuPhoneNoClientId = document.getElementById('TopMenuPhoneNo');
    var leftMenuPhoneNoClientId = document.getElementById('InstantCallBackPhoneNo');
    var contactUsNumberLeftId = document.getElementById('ContactUsNumberLeft');
    var otherOptionLeftId = document.getElementById('ContactUsNumberLeft2');
	var topMenuContactUsPhoneNo = document.getElementById('ContactUsNumber');
   
    if(changephonenoinmenus == 'true')
    {
		if(topMenuPhoneNoClientId != null)  //topmenu phone no
			topMenuPhoneNoClientId.innerHTML = newphoneno;
		if(leftMenuPhoneNoClientId != null) //leftmenu phone no
			leftMenuPhoneNoClientId.innerHTML = newphoneno;
		if(contactUsNumberLeftId != null)
		{
			var strInnerHTML = contactUsNumberLeftId.innerHTML;
			contactUsNumberLeftId.innerHTML = strInnerHTML.replace("tollfreenumber=" + oldphoneno,"tollfreenumber=" + newphoneno);
		}
		if(otherOptionLeftId!= null)
		{
			var strInnerHTML = otherOptionLeftId.innerHTML;
			otherOptionLeftId.innerHTML = strInnerHTML.replace("tollfreenumber=" + oldphoneno,"tollfreenumber=" + newphoneno);
		}
		if(topMenuContactUsPhoneNo!= null)
		{
		    var contactHREF = topMenuContactUsPhoneNo.innerHTML;
		    var num = contactHREF.indexOf('tollfreenumber=')+15
		    if(num!=0)
		    {
			    var firstPart = contactHREF.substring(0,num); 
			    var lastPart = contactHREF.substring(num + 14); 
			    topMenuContactUsPhoneNo.innerHTML = firstPart + newphoneno + lastPart; 
		    }
		}
	}
}
function ShowDownPage()
{
    var showDownPage = false;
  
    

    
    return showDownPage;
}

function GetSubCampaignCode(sChannel)
{
	var subCampaignCode
	subCampaignCode = "";
	
	switch(sChannel)
	{
		case "cmd:homeprod":
			subCampaignCode = "81101 Chat_HomePages";
			break;
		case "cmd:homegen":
			subCampaignCode = "81105 Chat_GenHomePage";
			break;
		case "cmd:rates":
			subCampaignCode = "68827 Chat_TodaysRates";
			break;
		case "cmd:purch":
			subCampaignCode = "81096 Chat_EdPurch";
			break;
		case "cmd:gen":
			subCampaignCode = "81097 Chat_EdGen";
			break;
		case "cmd:calc":
			subCampaignCode = "81103 Chat_Calc";
			break;
		case "cmd:equity":
			subCampaignCode = "81104 Chat_EdEquity";
			break;
		case "cmd:refi":
			subCampaignCode = "81099 Chat_EdRefi";
			break;
		case "cmd:ratewatch":
			subCampaignCode = "81098 Chat_RateWatch";
			break;
		case "cmd:advisor":
			subCampaignCode = "81100 Chat_LoanAdvsr";
			break;
		case "cmd:fthb":
			subCampaignCode = "81095 Chat_FTHB";
			break;
		case "cmd:apply":
			subCampaignCode = "83511 Chat_ApplyNow";
			break;
		case "cmd:lp":
			subCampaignCode = "83512 Chat_Landing_Pages";
			break;
		case "cmd:loan_advisor":
			subCampaignCode = "81100 Chat_LoanAdvsr";
			break;
		default:
			break;
	}

	return subCampaignCode;
}

function SetLoanadvisorPhoneNumber()
{
    var oldphoneno
    if( document.getElementById('TopMenuPhoneNo')) oldphoneno = document.getElementById('TopMenuPhoneNo').innerHTML;
    var newphoneno = '1.800.763.0715';
    
    var contactUsNumberLeftId = document.getElementById('ContactUsNumberLeft');
	var topMenuContactUsPhoneNo = document.getElementById('ContactUsNumber');
	
	if(contactUsNumberLeftId != null)
	{
		var strInnerHTML = contactUsNumberLeftId.innerHTML;
		contactUsNumberLeftId.innerHTML = strInnerHTML.replace("tollfreenumber=" + oldphoneno,"tollfreenumber=" + newphoneno);
	}
		
	if(topMenuContactUsPhoneNo!= null)
	{
		var contactHREF = topMenuContactUsPhoneNo.innerHTML;
		var num = contactHREF.indexOf('tollfreenumber=')+15
		if(num!=0)
		{
			var firstPart = contactHREF.substring(0,num); 
			var lastPart = contactHREF.substring(num + 14); 
			topMenuContactUsPhoneNo.innerHTML = firstPart + newphoneno + lastPart; 
		}
	}
		
	if(document.getElementById("TopMenuPhoneNo")) document.getElementById("TopMenuPhoneNo").innerHTML = newphoneno;
	if(document.getElementById("InstantCallBackPhoneNo")) document.getElementById("InstantCallBackPhoneNo").innerHTML = newphoneno;
}

function relocationhighlight(parentNum,childItemNum) 
{
    if (!ver4) return;
	//mark this menu as selected
	parentNum = parentNum-1;//Temp Fix, since 1st menu Item is removed,Praentnum hard coded in pages sends incorrect parentNum, It's fixed here
	var el = "el" + parentNum
	var nextNum = parentNum + 1
	var RelocationImagePathDef = '/images/Relocation'
	var RelocationExpandedMenuBGColor = '#EFEFD6';
	selectParent = el
	//change its background color and its bullet image
	if (IE4 || NS6) 
	{
		if (document.getElementById(el + 'Parent'))
		{	
			whichElP = document.getElementById(el + "Parent");
			whichElC = document.getElementById(el + "Child");
			
			whichELink = document.getElementById('Link' + parentNum);
//			whichImP = document.images[el + 'imEx'];
			
			nextYelIm = document.images['Rule' + nextNum ];
		
			whichElP.style.backgroundColor = RelocationExpandedMenuBGColor;
			if (whichElP)	whichElP.className = 'menuParentSelected';
			if (whichELink) whichELink .className = 'menuParentSelected';
			whichElC.style.backgroundColor = RelocationExpandedMenuBGColor;
			whichElC.style.fontWeight = "bold";
			//turn off the yellow rule on the following item
			if (nextYelIm) nextYelIm.src = '/images/spacer.gif';
			expandIt(el); 
			
			//if the image has an arrow, change it to yellow and expand it
//			var imageSource = whichImP.src;
//			if (imageSource.indexOf("mn_arrow_on.gif") != -1) 
//			{
//				whichImP.src = ImagePathDef + "hl_green_arrow.gif"
//				//if there is a child selected to highlight, change its image to the checkbox
//				if (childItemNum != null) document.images['ChildImage' + parentNum + '-' + childItemNum ].src = ImagePathDef + 'hl_green_dot.gif';
//				expandIt(el);
//			}
//			//else just change it to yellow, but do not expand it
//			else 
//				whichImP.src = ImagePathDef + "mn_ylw_arrow_no.gif";
		}		
	}
	else 

	{
		whichElP = eval("document.NavMenu.document." + el + "Parent");
		whichElC = eval("document.NavMenu.document." + el + "Child");
		whichImP = eval("whichElP.document.images['"+ el + "imEx']");
		//alert(whichImP.src);
		if (eval("document.NavMenu.document." + el + "Parent"))
		{
			if (eval("document.NavMenu.document.el" + nextNum + "Parent")) 
			{
				nextYelIm = eval("document.NavMenu.document.el" + nextNum + "Parent.document.images['Rule" + nextNum + "']");
				whichElP.bgColor = RelocationExpandedMenuBGColor;
				whichElP.className = 'menuParentSelected';
				whichElC.bgColor = RelocationExpandedMenuBGColor;
				//turn off the yellow rule on the following item
				nextYelIm.src = RelocationImagePathDef + "spacer.gif"
			}
			//if the image has an arrow, change it to yellow and expand it
			var imageSource = whichImP.src;
			if (imageSource.indexOf("mn_arrow_on.gif") != -1) 
			{
				whichImP.src = RelocationImagePathDef + "hl_green_arrow.gif"
				//if there is a child selected to highlight, change its image to the checkbox
				if (childItemNum != null) eval ("whichElC.document.images['ChildImage" + parentNum + "-" + childItemNum + "'].src = RelocationImagePathDef + 'hl_green_dot.gif'")
				expandIt(el);
			}
			//else just change it to yellow, but do not expand it
			else
				whichImP.src = RelocationImagePathDef + "mn_ylw_arrow_no.gif";
		}
	}
}