sfHover = function() {
	var oNav = document.getElementById("nav");
	if (oNav != null) {
		var sfEls = oNav.getElementsByTagName("LI");
		if (null != sfEls)
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					this.className+=" sfhover";
				}
				sfEls[i].onmouseout=function() {
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}	
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

function show() {   
	which = document.getElementById("small");
	which2 = document.getElementById("big");
	which.style.display = 'none';
	which2.style.display = 'block';
}

function hide() {   
	which = document.getElementById("small");
	which2 = document.getElementById("big");
	which.style.display = 'block';
	which2.style.display = 'none';
}

function hideMetaFields(aLink) {
	var oEl = $("metaFields");
	oEl.style.display = (oEl.style.display == "") ? "none" : "";			
	aLink.innerText = (oEl.style.display == "") ? "Hide" : "Show";
	return false;
}
	
function tagPopups() {
	if (!document.getElementsByTagName) return false;

	var links=document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("popup")) {

			links[i].onclick=function(event) {

				if (null != event) {
					event.target.href = event.target.href.replace("%26", "&");
				}

				var anchor = (null != event) ? event.target : window.event.srcElement;
				
				if (anchor.tagName != 'A') {						// access the anchor around this element tag.
					anchor = anchor.parentElement;
				}

				if (anchor.href.indexOf('&features') == -1 && anchor.href.indexOf('?features') == -1) {
					window.open(anchor.href, "", "top=40,left=40,width=600,height=600");
				}
				else {
					var fIndex = anchor.href.indexOf('&features');
					if (fIndex == -1)
						fIndex = anchor.href.indexOf('?features');
						
					var url = anchor.href.substring(0, fIndex );
					
					var params = anchor.href.substr(anchor.href.indexOf('top=', anchor.href.indexOf('?features')));
					window.open(url, "", params);
				}
			    return false;
			}
		}
		else if (links[i].className.match("back")) {
			links[i].onclick=function() {
				history.go(-1);
				return false;
			}
		}
	}
}

function tagTermsAndConditions() {
	if (!document.getElementsByTagName) return false; 
	var links = document.getElementsByTagName("span");
	for (var i=0 ; i<links.length ; i++) {
		if (links[i].className.match("hide")) {
			links[i].onmouseover=function() {
				which = document.getElementById("small");
				which2 = document.getElementById("big");
				which.style.display = 'none';
				which2.style.display = 'block';
			}
		}
		else if (links[i].className.match("show")) {
			links[i].onmouseout=function() {
				which = document.getElementById("small");
				which2 = document.getElementById("big");
				which.style.display = 'block';
				which2.style.display = 'none';
			}
		}
	}
}

function onMasterLoad() {
	toggleLayer('zipBox');
	tagPopups();
	tagTermsAndConditions();
	
	var cookieName = "CookieName";		
	var cookie = getCookie(cookieName);

	if (null == cookie || cookie.indexOf("Lang_Code") < 0)
		cookie = "Business=&Lang_Code=&Region=";
		
	var expr = new Date();
	expr.setTime(expr.getTime() + 30 * 24 * 60 * 60 * 1000);

	var lang = getLangFromUrl();
	if (lang.length > 0)
		cookie = setValueInCookie(cookie, "Lang_Code", lang);

	var type = getTypeFromUrl();
	cookie = setValueInCookie(cookie, "Business", type);

	var region = getRegionFromUrl();
	cookie = setValueInCookie(cookie, "Region", region);

	setCookie(cookieName, cookie, expr, "/");
}

function toggleLayer(whichLayer)
{
	if (document.getElementById) {
		// this is the way the standards work
		if (document.getElementById(whichLayer) == null) 
			return;
		
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	} else if (document.all) {
		if (document.all[whichLayer] == null)
			return;
	
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	} else if (document.layers) {
		if (document.layers[whichLayer] == null)
			return;
			
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function toggleOnOff(toggleOn,toggleOff) {
	//toggleOn
	toggleLayer(toggleOn);
	if (document.getElementById) {
		// this is the way the standards work
		var style2 = document.getElementById(toggleOff).style;
		style2.display = "";

		var styleLinkOffName=toggleOff+"Link";
		var styleLinkOffElem = document.getElementById(styleLinkOffName);
		if(styleLinkOffElem != 'undefined' && styleLinkOffElem != null)
		{
            var styleLinkOff=styleLinkOffElem.style;
            styleLinkOff.display = "none";
        }
        
        var styleLinkOnName=toggleOn+"Link";
		var styleLinkOnElem = document.getElementById(styleLinkOnName);
		if(styleLinkOnElem != 'undefined' && styleLinkOnElem != null)
		{
            var styleLinkOn=styleLinkOnElem.style;
            styleLinkOn.display = "block";
        }
	} else if (document.all) {
		// this is the way old msie versions work
		var style2 = document.all[toggleOff].style;
		style2.display = "";
		
		var styleLinkOffName=toggleOff+"Link";
		var styleLinkOffElem = document.all[styleLinkOffName];
		if(styleLinkOffElem != 'undefined' && styleLinkOffElem != null)
		{
            var styleLinkOff=styleLinkOffElem.style;
            styleLinkOff.display = "none";
        }
        
        var styleLinkOnName=toggleOn+"Link";
		var styleLinkOnElem = document.all[styleLinkOnName];
		if(styleLinkOnElem != 'undefined' && styleLinkOnElem != null)
		{
            var styleLinkOn=styleLinkOnElem.style;
            styleLinkOn.display = "block";
        }
	} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[toggleOff].style;
		style2.display = "";
		
		var styleLinkOffName=toggleOff+"Link";
		var styleLinkOffElem = document.layers[styleLinkOffName];
		if(styleLinkOffElem != 'undefined' && styleLinkOffElem != null)
		{
            var styleLinkOff=styleLinkOffElem.style;
            styleLinkOff.display = "none";
        }
        
        var styleLinkOnName=toggleOn+"Link";
		var styleLinkOnElem = document.layers[styleLinkOnName];
		if(styleLinkOnElem != 'undefined' && styleLinkOnElem != null)
		{
            var styleLinkOn=styleLinkOnElem.style;
            styleLinkOn.display = "block";
        }
	}
}

function hpTrack(tabState) {
	var whatLang = getLangFromUrl();
	var ucLang = whatLang.toLowerCase();
	var isEnglish = "en";
	var isSpanish = "es";
	//alert(ucLang);
	//alert(tabState);
	if (ucLang == isEnglish) {
		switch(tabState) {
			case 'tabResON':
			//alert(tabState + " " + "dcsMultiTrack('WT.ac', 'HP_RES_MENU_BAR_ON', 'WT.cg_n', 'HP_RES_BAR', 'WT.cg_s', 'HP_RES_BAR GREENBAR');");
			dcsMultiTrack('WT.ac', 'HP_RES_MENU_BAR_ON', 'WT.cg_n', 'HP_RES_BAR', 'WT.cg_s', 'HP_RES_BAR GREENBAR');
			break;
			case 'tabBusON':
			//alert(tabState + " " + "dcsMultiTrack('WT.ac', 'HP_BUS_MENU_BAR_ON', 'WT.cg_n', 'HP_BUS_BAR', 'WT.cg_s', 'HP_BUS_BAR ORANGEBAR');");
			dcsMultiTrack('WT.ac', 'HP_BUS_MENU_BAR_ON', 'WT.cg_n', 'HP_BUS_BAR', 'WT.cg_s', 'HP_BUS_BAR ORANGEBAR');
			break;
			case 'tabNone':
			//alert(tabState);
			break;
		}
	} else if (ucLang == isSpanish) {
			switch(tabState) {
			case 'tabResON':
			//alert(tabState);
			//dcsMultiTrack('WT.ac', 'HP_RES_MENU_BAR_ON', 'WT.cg_n', 'HP_RES_BAR', 'WT.cg_s', 'HP_RES_BAR GREENBAR');
			break;
			case 'tabBusOFF':
			//alert(tabState);
			//dcsMultiTrack('WT.ac', 'HP_BUS_MENU_BAR_ON', 'WT.cg_n', 'HP_BUS_BAR', 'WT.cg_s', 'HP_BUS_BAR ORANGEBAR');
			break;
			break;
			case 'tabNone':
			//alert(tabState);
			break;
			}
	}
}

function toggleNewOnOff(toggleState,toggleOn,toggleOff,toggleInit, wtState) {
	var sameTracker="tabSame";
	var diffTracker="tabDiff";
	var initTracker="tabStart";
	//toggleOn
	//toggleNewLayer(toggleOn);
	if (document.getElementById) {
		// this is the way the standards work
		if (toggleState==initTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";

				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";

				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";
				//alert("1");
			} else if (toggleState==sameTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="none";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="block";
			} else if (toggleState==diffTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";	
			}
	
	} else if (document.all) {
		// this is the way old msie versions work
		if (toggleState==initTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";

				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";

				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";
				//alert("1");
			} else if (toggleState==sameTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="none";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="block";
			} else if (toggleState==diffTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";	
			}
		
	} else if (document.layers) {
		// this is the way nn4 works
		if (toggleState==initTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";

				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";

				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";
				//alert("1");
			} else if (toggleState==sameTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="none";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="block";
			} else if (toggleState==diffTracker) {
				var style5 = document.getElementById(toggleOn).style;
				style5.display ="block";
				
				var style2 = document.getElementById(toggleOff).style;
				style2.display = "none";
		
				var style3 = document.getElementById(toggleInit).style;
				style3.display ="none";	
			}
	} hpTrack(wtState);
}

function getCookie(name) {

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);

  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
    var end = document.cookie.indexOf(";", begin);     

    if (end == -1)
    	end = dc.length;

  return unescape(dc.substring(begin + prefix.length, end));
}   

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	  ((expires) ? "; expires=" + expires.toGMTString() : "") +
	  ((path) ? "; path=" + path : "") +
	  ((domain) ? "; domain=" + domain : "") +
	  ((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function getValueFromCookie(cookie, keyToFind) {

	var cookie_pieces = cookie.split('&');
	for(var i=0; i<cookie_pieces.length; i++){

		var piece = trim(cookie_pieces[i]);

		var a = piece.indexOf('=');
		if (a == -1) {
			var key = piece;
			var value = '';
		} else { 
			var key = piece.substr(0,a);
			var value = piece.substr(a+1);
		}

		if (key == keyToFind)
			return value;
	}
	
	return "";
}

function setValueInCookie(cookie, keyToFind, valueToReplace) {

	var cookie_pieces = cookie.split('&');
	for(var i=0; i<cookie_pieces.length; i++){

		var piece = trim(cookie_pieces[i]);

		var a = piece.indexOf('=');
		if (a == -1) {
			var key = piece;
			var value = '';
		} else { 
			var key = piece.substr(0,a);
			var value = piece.substr(a+1);
		}

		if (key == keyToFind) {
			cookie = cookie.replace(key + "=" + value, key + "=" + valueToReplace);		
			return cookie;
		}
	}
	
	cookie = cookie + "&" + keyToFind + "=" + valueToReplace;
	return cookie;
}

function getLangFromUrl() {

	var url = document.location.toString();
	var pathAndQuery = url.substr(7);
	pathAndQuery = pathAndQuery.substr(pathAndQuery.indexOf("/"));
	
	if (pathAndQuery.length > 3)
		return pathAndQuery.substr(1, 2);

	return "";
}

function getTypeFromUrl() {
	var url = document.location.toString();

	if (url.indexOf("/MMC/") > 0)
		return "SBC";
	else if (url.indexOf("/DEBS/") > 0)
		return "ENT";
	else if (url.indexOf("/RES/") > 0)
		return "RES";
	
	return "";
}

function getRegionFromUrl() {
	var url = document.location.toString();
	var lang = getLangFromUrl();
	
	if (lang.length > 0) {
		var t = url.substr(url.indexOf("/" + lang + "/") + 4);
		var region = t.substr(0, t.indexOf("/"));
		
		if (region != "Pages" && region != getTypeFromUrl())
			return region;
	}
	
	return "";
}

function trim(str){
		
	while (str.charAt(0) == ' ')
		str = str.substring(1);
	
	while (str.charAt(str.length-1) == ' ')
		str = str.substring(0,str.length-1);

	return str;
}

String._typeName = 'String';
String.format = function(format) {

    var result = "";
    
    for (var i=0;;) {
                var next = format.indexOf("{", i);
        if (next < 0) {
            result += format.slice(i);
            break;
        }
        
        result += format.slice(i, next);
        i = next+1;
        
        if (format.charAt(i) == '{') {
            result += '{';
            i++;
            continue;
        }
        
        var next = format.indexOf("}", i);
        var brace = format.slice(i, next).split(':');
        
        var argNumber = Number.parse(brace[0])+1;
        var arg = arguments[argNumber];
        if (arg == null) {
            arg = '';
        }

        if (arg.toFormattedString)
            result += arg.toFormattedString(brace[1] ? brace[1] : '');
        else
            result += arg.toString();
        
        i = next+1;
    }
    
    return result;
}

Number.parse = function(value) {
    if (!value || (value.length == 0)) {
        return 0;
    }
    return parseFloat(value);
}
 
function clearTextBox(id) {
	var textbox = document.getElementById(id);
	textbox.value = '';
}

/* This function ensures that we do a postback only for valid State or Province name selection. 
*  We have some DDL values that do not require a postback, like State and Province header names.
*  Return true indicates not to do postback and false indicates to do a postback. 
*  See C# file PostalSoftWebPart.cs where we add a call to this function
*/
function VerifyRegionSelection(regionId)
{
    var region = document.getElementById(regionId);
    var myindex  = region.selectedIndex;
    var selVal = region.options[myindex].value;
    if(selVal == 'undefined' || selVal == '')
    {
        return true;
    }
    else
    {
        return false;
    }
}

/*BEGIN: Code for new Zip/Postal Code Layer*/

    function hidePostalLayer()
    {
      document.getElementById("postalLayer").style.visibility='hidden';
    }

    var wtac = "WT.ac";
    var wtcgn = "WT.cg_n";
    var wtcgs = "WT.cg_s";
    var webtrend1 = "";
    var webtrend2 = "";
    var webtrend3 = "";
    // This function calculates the click location and shows the pop-up layer close to the 
    // click location. It also stores the Web Trend params into a temporary storage until 
    // they are used when the Submit button is clicked
    function showPostalLayer(bizType, commType, elementId, wt1, wt2, wt3 )
    {
      //alert("bizType = " + bizType);
      //alert("commType = " + commType);
	webtrend1 = wt1;
	webtrend2 = wt2;
	webtrend3 = wt3;
        var bizTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_bizType');
        bizTypeHiddenField.value = bizType;
        var commodityTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_commodityType');
        commodityTypeHiddenField.value = commType;

        // Layer positioning by finding the clicked link's position
        var yVal = 0;
        var xVal = 0;
        var element = document.getElementById(elementId);
        while( element != null )
        {
            //alert("In While : " + element.id);
            yVal += element.offsetTop;
            xVal += element.offsetLeft;
            element = element.offsetParent;
        }
        //alert("yVal = " + yVal);
        //alert("xVal = " + xVal);

        document.getElementById("postalLayer").style.top = yVal + "px";
        document.getElementById("postalLayer").style.left = xVal + "px";
        document.getElementById("postalLayer").style.visibility='visible';
        
        //On MouseDown event call 'MouseDownEvent' function 
        document.onmousedown = MouseDownEvent;
    }

    function placePostalLayer(x, y)
    {
        document.getElementById("postalLayer").style.top = x + "px";
        document.getElementById("postalLayer").style.left = y + "px";
    }
    
    function ValidateZip(zip)
    {
        if (zip.match(/^[0-9]{5}$/)) {
            return true;
        }
        zip=zip.toUpperCase();
        if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
            return true;
        }
        if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
            return true;
        }
        document.getElementById("postalLayerError").style.display='block';
        return false;
    }
    
    function InLineSubmitButtonClicked()
    {
        var inLinePostalTxtBox = document.getElementById(placeHolderClientId + '_inLineZipcode');
        var validZip = ValidateZip(inLinePostalTxtBox.value);
        if (!validZip)
        {
            return validZip;
        }
        document.getElementById("postalLayerError").style.display='none';
    
        var bizTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_bizType');
        //alert("Biz Type = " + bizTypeHiddenField.value);
        var commodityTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_commodityType');
        //alert("Commodity Type = " + commodityTypeHiddenField.value);
        //alert("Calling dcsMultiTrack with wtac = '" + wtac + "', webtrend1 = '" + webtrend1 + "', wtcgn = '" + wtcgn + "', webtrend2 = '" + webtrend2 + "', wtcgs = '" + wtcgs + "', webtrend3 = '" +  webtrend3 + "'");
	dcsMultiTrack(wtac, webtrend1, wtcgn, webtrend2, wtcgs, webtrend3);
	webtrend1 = "";
	webtrend2 = "";
	webtrend3 = "";
        return true;
    }
    
    function InLineZipcodeEntered(myfield,e)
    {
        var keycode;
        if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
        else return true;

        if (keycode == 13)
            {
                if (InLineSubmitButtonClicked())
                {
                    var submitBtn = document.getElementById(placeHolderClientId + '_inLineSubmitButton');
                    submitBtn.click();
                }
                return false;
            }
        else
           return true;
    }

    function MouseDownEvent(e)
    {
        //alert('In MouseDownEvent');
        var submitBtn = document.getElementById(placeHolderClientId + '_inLineSubmitButton');
        var inLinePostalTxtBox = document.getElementById(placeHolderClientId + '_inLineZipcode');
        var srcEventId;
        if(e == null)
        {
            srcEventId = event.srcElement.id;
        }
        else
        {
            srcEventId = e.target.id;
        }
        //alert('MouseDownEvent - ' + srcEventId);
        if(srcEventId == submitBtn.id)
        {
            document.onmousedown = null;
            submitBtn.click();
        }
        else if(srcEventId == inLinePostalTxtBox.id || srcEventId == 'postalLayerText')
        {
            // do nothing
        }
        else
        {
            document.onmousedown = null;
            hidePostalLayer();
        }
    }
    
    function handleResMouseOut(e)
    {
        // This is the source element that mouse is getting away from
	    var tg = e.srcElement;
	    //alert("tg ID = " + tg.id);
	    
	    // This is the target element where the mouse moved to
        var reltg = e.toElement;
        //alert("reltg Id = " + reltg.id);
        while (reltg != null && reltg != 'undefined' && reltg.id != 'tabResidential')
        {
            reltg= reltg.parentNode;
            //alert("In While, new reltg ID = " + reltg.id);
            // Special condition : If the mouse moved over the Business Tab, we do not want to close yet
            if(reltg != null && reltg != 'undefined' && reltg.id == 'tabResidentialBusLink')
                break;
        }
        //if(reltg != null && reltg != 'undefined')
            //alert("After While reltg Id is : " + reltg.id);
            
        if (reltg != null && reltg != 'undefined' && reltg.id == 'tabResidential')
        {
            return;
        }
        else
        {
            //alert("call toggleNewOnOff ");
            toggleNewOnOff('tabSame', 'tabBusiness', 'tabResidential', 'tabInit')
        }
    }

    function handleBizMouseOut(e)
    {
        // This is the source element that mouse is getting away from
	    var tg = e.srcElement;
	    //alert("tg ID = " + tg.id);

	    // This is the target element where the mouse moved to
        var reltg = e.toElement;
        //alert("reltg Id = " + reltg.id);
        while (reltg != null && reltg != 'undefined' && reltg.id != 'tabBusiness')
        {
            reltg= reltg.parentNode;
            //alert("In While, new reltg ID = " + reltg.id);
            // Special condition : If the mouse moved over the Residential Tab, we do not want to close yet
            if(reltg != null && reltg != 'undefined' && reltg.id == 'tabBusinessResLink')
                break;
        }
        //if(reltg != null && reltg != 'undefined')
            //alert("After While reltg Id is : " + reltg.id);
            
        if (reltg != null && reltg != 'undefined' && reltg.id == 'tabBusiness')
        {
            return;
        }
        else
        {
            //alert("call toggleNewOnOff ");
            toggleNewOnOff('tabSame', 'tabResidential', 'tabBusiness', 'tabInit')
        }
    }

    function showSection(sec1,sec2,sec3)
    {
        //section one will always show
        //alert("show section called" + sec1);
    	document.getElementById(sec1).style.display="block";
       	document.getElementById(sec2).style.display="none";
 	   	document.getElementById(sec3).style.display="none";
    	
    }

    function showRegionalLayer(bizType, commType, elementId, wt1, wt2, wt3, region)
    {
                    
      //alert("bizType = " + bizType);
      //alert("commType = " + commType);
	    webtrend1 = wt1;
	    webtrend2 = wt2;
	    webtrend3 = wt3;
        var bizTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_bizType');
        bizTypeHiddenField.value = bizType;
        var commodityTypeHiddenField = document.getElementById(placeHolderClientId + '_DE_commodityType');
        commodityTypeHiddenField.value = commType;

        if(region == null)
        {
            // Layer positioning by finding the clicked link's position
            var yVal = 0;
            var xVal = 0;
            var element = document.getElementById(elementId);
            while( element != null )
            {
                //alert("In While : " + element.id);
                yVal += element.offsetTop;
                xVal += element.offsetLeft;
                element = element.offsetParent;
            }
            //alert("yVal = " + yVal);
            //alert("xVal = " + xVal);

            //Keeping postal layer as the same so that we can reuse the styles
            document.getElementById("postalLayer").style.top = yVal + "px";
            document.getElementById("postalLayer").style.left = xVal + "px";
            document.getElementById("postalLayer").style.visibility='visible';
            
            //On MouseDown event call 'RegionalMouseDownEvent' function 
            document.onmousedown = RegionalMouseDownEvent;
        }
        else
        {
            var regionHiddenField = document.getElementById(placeHolderClientId + '_DE_region');
            regionHiddenField.value = region;
            //Setting the Web Trends Info
            //InLineSubmitButtonClicked();
        
            UpdateRegionalWebTrendsKeys(region);
            
            var submitBtn = document.getElementById(placeHolderClientId + '_inLineSubmitButton');
            submitBtn.click();
        }
    }
    
    function RegionalMouseDownEvent(e)
    {
        //alert('In MouseDownEvent');
        var submitBtn = document.getElementById(placeHolderClientId + '_inLineSubmitButton');
        var inLineRegion = document.getElementById(regionDropDownId);
        var srcEventId;
        
        if(e == null)
        {
            srcEventId = event.srcElement.id;
        }
        else
        {
            srcEventId = e.target.id;
        }
        //alert('MouseDownEvent - ' + srcEventId);
        if(srcEventId == submitBtn.id)
        {
            webtrend1 = webtrend1.replace(/__REG__/i, GetStateCodeUsingValue(inLineRegion.value));
            webtrend2 = webtrend2.replace(/__REG__/i, GetStateCodeUsingValue(inLineRegion.value));
            webtrend3 = webtrend3.replace(/__REG__/i, GetStateCodeUsingValue(inLineRegion.value));
            
            document.onmousedown = null;
            submitBtn.click();
        }
        else if(srcEventId == inLineRegion.id || srcEventId == 'postalLayerText')
        {
            // do nothing
        }
        else
        {
            document.onmousedown = null;
            hidePostalLayer();
        }
    }

    function UpdateRegionalWebTrendsKeys(region)
    {
        var val;
        var inLineRegion = document.getElementById(regionDropDownId);
        for(var i=0; i<inLineRegion.options.length; i++)
            if(inLineRegion.options[i].text  == region)
                val =inLineRegion.options[i].value;
        
        webtrend1 = webtrend1.replace(/__REG__/i, GetStateCodeUsingValue(val));
        webtrend2 = webtrend2.replace(/__REG__/i, GetStateCodeUsingValue(val));
        webtrend3 = webtrend3.replace(/__REG__/i, GetStateCodeUsingValue(val));
    }


    //Webtrends requires that the postal abbreviation be used in the key
    function GetStateCodeUsingValue(regionCode)
    {
        var stateMapping = [];
        stateMapping["Z1Z1Z1"] = "AB";
        stateMapping["Z1Z1Z4"] = "BC";
        stateMapping["Z1Z1Z3"] = "MB";
        stateMapping["Z1Z1Z8"] = "NB";
        stateMapping["Z1Z1Z5"] = "NL";
        stateMapping["Z1Z2Z2"] = "NT";
        stateMapping["Z1Z1Z6"] = "NS";
        stateMapping["Z1Z2Z4"] = "NU";
        stateMapping["Z1Z1Z2"] = "ON";
        stateMapping["Z1Z1Z7"] = "PE";
        stateMapping["Z1Z1Z9"] = "QC";
        stateMapping["Z1Z2Z1"] = "SK";
        stateMapping["Z1Z2Z3"] = "YT";
        
        stateMapping["99994"] = "CT";
        stateMapping["99988"] = "DE";
        stateMapping["99987"] = "IL";
        stateMapping["99986"] = "ME";
        stateMapping["99995"] = "MD";
        stateMapping["99993"] = "MA";
        stateMapping["99992"] = "MI";
        stateMapping["99991"] = "NJ";
        stateMapping["99999"] = "NY";
        stateMapping["99998"] = "OH";
        stateMapping["99997"] = "PA";
        stateMapping["99990"] = "RI";
        stateMapping["99996"] = "TX";
        stateMapping["99989"] = "WA"; 
        
        return stateMapping[regionCode];
    }

/*END: Code for new Zip/Postal Code Layer*/

var itemSuffix = new Array();
var delay = 5;
var speed = 10;

function handleMenuOnMouseOver(div) {

  for(i = 0; i < itemSuffix.length; i++) {
    
    var menuHeader = document.getElementById('naviMenuHeader'+itemSuffix[i]);    
    var menuItemDiv = document.getElementById('naviMenuItem'+itemSuffix[i]);    
    var imgArrow = document.getElementById('naviMenuArrow'+itemSuffix[i]);    
      
    clearInterval(menuItemDiv.intervalId);
 
    if(menuItemDiv.style.display == 'none' && menuHeader.id == div.id) 
    {      
      imgArrow.src = "/Style%20Library/en-us/images/select_leftnav_ul.gif";   
      menuItemDiv.side = 'up';  
      menuItemDiv.style.display = 'block';
      menuItemDiv.style.height = '1px';          
      menuItemDiv.intervalId = setInterval("animateMenu('" + menuItemDiv.id + "')", delay);
    } 
    else if(menuItemDiv.style.display == 'block') {
      imgArrow.src = "/Style%20Library/en-us/images/gradientBlue_tab.gif";     
      menuItemDiv.side = 'down';  
      menuItemDiv.intervalId = setInterval("animateMenu('" + menuItemDiv.id + "')", delay);
    }
    
    if (menuHeader.id == div.id)
        SetDivBGColor(menuHeader, '#C5D7F0');
  }
}

function handleMenuOnMouseOut() {
  
  for(i = 0; i < itemSuffix.length; i++) {

    var head = document.getElementById('naviMenuHeader'+itemSuffix[i]);
    SetDivBGColor(head , '#FFFFFF');    
/*
    var head = document.getElementById('naviMenuHeader'+itemSuffix[i]);
    var cont = 'naviMenuItem'+itemSuffix[i];
    var menuItemDiv = document.getElementById(cont);
    var imgArrow = document.getElementById('naviMenuArrow'+itemSuffix[i]);
    
    clearInterval(menuItemDiv.intervalId);
    
    imgArrow.src = "/Style%20Library/en-us/images/gradientBlue_tab.gif";
    menuItemDiv.side = 'down';  
    menuItemDiv.intervalId = windows.setInterval("animateMenu('" + menuItemDiv.id + "')", delay);
*/
    
  }
}

function initMenuMain(mainDiv) {  
    
   
  var varMainDiv = document.getElementById(mainDiv);  
  
  if (varMainDiv != null)
  {
      divElements = varMainDiv.getElementsByTagName('div')

      for(i = 0; i < divElements.length; i++) {
        
        if(divElements[i].id.indexOf("naviMenuHeader") != -1) {
          divElements[i].onmouseover = new Function("handleMenuOnMouseOver(this)");
          divElements[i].onmouseout = new Function("handleMenuOnMouseOut()");
        } 
        else if(divElements[i].id.indexOf("naviMenuItem") != -1) {
            
            var menuItemSuffix = divElements[i].id.replace('naviMenuItem','');
            
            itemSuffix.push(menuItemSuffix);
            divElements[i].onmouseout = new Function("handleMenuOnMouseOut()");
            divElements[i].divHeight = divElements[i].offsetHeight;      
            
            if(divElements[i].style.display == 'block')
            {
            divElements[i].style.display = 'block';
            }
            else
            {
            divElements[i].style.display = 'none';        
            }
        } 
      }
  }

}


function animateMenu(id) {

  var multiplier = 0;
  var variableHeight = 0;  
  var itemDiv = document.getElementById(id);
  var height = document.getElementById(id).offsetHeight;
  var originalHeight = itemDiv.divHeight;	
        
  if(itemDiv.side == 'up')
  {
  
    multiplier = 1;
  }
  else if(itemDiv.side == 'down') 
  {
    multiplier=-1;
  }
  
  if(multiplier == 1) {
    variableHeight = (Math.round((originalHeight - height) / speed));    
  } else {
    variableHeight = (Math.round(height / speed));
  }
  
  if(variableHeight <= 1) {
    variableHeight = 1;
  }

  var newHeight = height + (variableHeight * multiplier);
  
  if (newHeight <0)
  {
    newHeight = 0;
  }
  
  itemDiv.style.height = newHeight + 'px';  
  itemDiv.style.opacity = height / originalHeight;
  itemDiv.style.filter = 'alpha(opacity=' + (height * 100 / originalHeight) + ')';
  
  if(height <= 1 && multiplier != 1) 
  {
    itemDiv.style.display = 'none';
    clearInterval(itemDiv.intervalId);
  } 
  else if(height > (originalHeight - 2) && multiplier == 1) {
    clearInterval(itemDiv.intervalId);
  }  
}

function SetLeftNavStatusCookie(activeImage, activeDiv)
{ 
    document.cookie='leftNavStatusCookie ='+ escape(activeImage+ '-' +activeDiv)+ ';';     
}

function SetDivBGColor(activeDiv, bgColor) 
{
    activeDiv.style.backgroundColor = bgColor;
}

function IsInDesignMode()
{
   if(document.getElementById("MSOLayout_InDesignMode").value == '1') return true;
   if(document.getElementById("MSOTlPn_SelectedWpId").value != "") return true;
   return false;
}

function EnableLinks()
{
     if(!IsInDesignMode())
     {
           var cstIdentifier='id="DEonclick=';
           
           var Corp32 = 'http://torapp37:22264';
           var Biz32  = 'http://torapp37:22265';
           var Res32  = 'http://torapp37:22266';
           
           var Corp64 = 'http://torapp149:1010';
           var Biz64 =  'http://torapp149:1009';
           var Res64 =  'http://torapp149:1008';
     
           // Create an array to store all the anchor elements in the page.
           var anchors = document.getElementsByTagName("a");
     
           // Loop through the anchors array.
           for (var i=0; i<anchors.length; i++) 
           {
                // Check if this anchor element contain cstIdentifier text.
                if (anchors[i].outerHTML.indexOf(cstIdentifier) > 0)
                {
                     //alert(anchors[i].outerHTML);
                     
                     // Store the HTML for this anchor element.
                     oldText = anchors[i].outerHTML;
           
                     //rewrite the URL to remove our test text and add a target instead
                     newText = oldText.replace(cstIdentifier, 'onclick="');
           
                     // Write the HTML back to the browser.
                     anchors[i].outerHTML = newText;
                     
                }
                
                // corp
                if (anchors[i].outerHTML.indexOf(Corp32) > 0)
                {
                     // Store the HTML for this anchor element.
                     oldText = anchors[i].outerHTML;
           
                     //rewrite the URL to remove our test text and add a target instead
                     newText = oldText.replace(Corp32, Corp64);
           
                     // Write the HTML back to the browser.
                     anchors[i].outerHTML = newText;
                     
                }
                
                // biz
                if (anchors[i].outerHTML.indexOf(Biz32) > 0)
                {
                     // Store the HTML for this anchor element.
                     oldText = anchors[i].outerHTML;
           
                     //rewrite the URL to remove our test text and add a target instead
                     newText = oldText.replace(Biz32, Biz64);
           
                     // Write the HTML back to the browser.
                     anchors[i].outerHTML = newText;
                     
                }
                
                // res
                if (anchors[i].outerHTML.indexOf(Res32) > 0)
                {
                     // Store the HTML for this anchor element.
                     oldText = anchors[i].outerHTML;
           
                     //rewrite the URL to remove our test text and add a target instead
                     newText = oldText.replace(Res32, Res64);
           
                     // Write the HTML back to the browser.
                     anchors[i].outerHTML = newText;
                     
                }
                
                
           }
     }
}

function openPopUpWindow(url, width, height)
{
	var widthParam, heightParam, topParam, leftParam, options

	if (url != null)
	{
		if ((width != null) && (eval(width)))
		{
			leftParam = "left=" + (screen.width - width) / 2;
			widthParam = "width=" + width;
		}

		if ((height != null) && (eval(height)))
		{
			topParam = "top=" + (screen.height - height) / 2;
			heightParam = "height=" + height;
		}
		
		
		options = "toolbar=0,scrollbars=1,menubar=0,resizable=0,directories=0,status=0,location=0," + topParam + "," + leftParam + "," + widthParam + "," + heightParam;
		window.open(url, "", options );
	}

}


