var sfHover = function() {
	var ieULs = document.getElementById('nav').getElementsByTagName('ul');

	/** IE script to cover <select> elements with <iframe>s **/
	for (j=0; j<ieULs.length; j++) {
	ieULs[j].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + ieULs[j].innerHTML);
	var ieMat = ieULs[j].firstChild;
		ieMat.style.width=ieULs[j].offsetWidth+"px"; 
		ieMat.style.height=ieULs[j].offsetHeight+"px";	
		ieULs[j].style.zIndex="0";
	}
	/** IE script to change class on mouseover **/

	var ieLIs = document.getElementById('nav').getElementsByTagName('li');
	for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
		 ieLIs[i].onmouseover=function() {this.className+=" sfhover";} 
		 ieLIs[i].onmouseout=function() {this.className=this.className.replace(' sfhover', '');}
	}
};

if (window.attachEvent) { window.attachEvent('onload', sfHover); }

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openAWindow(pageToLoad, winName, width, height, center) 
{
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," 
    + "height=" + height + "," 
    + "location=0," 
    + "menubar=0,"
    + "resizable=0,"
    + "scrollbars=0,"
    + "status=0," 
    + "titlebar=0,"
    + "toolbar=0,"
    + "hotkeys=0,"
    + "screenx=" + xposition + ","  //NN Only
    + "screeny=" + yposition + ","  //NN Only
    + "left=" + xposition + ","     //IE Only
    + "top=" + yposition;           //IE Only

    if (pageToLoad != '/emailafriend/sendemail.aspx')
    {
		pageToLoad = pageToLoad + "&r="+window.location;
	}
	else
	{
		pageToLoad = pageToLoad + "?r="+window.location;
	}
    window.open( pageToLoad,winName,args );
}


// ------------------------------------------------------------------------------
// ----------   PPC Cookie stuff --------------------------------------------


var CookieLifeTime = 1800;  // Cookie life time is 1800 seconds / 30 minutes


function setCookie(cookieName,cookieValue,lifeTime,path,domain,isSecure)
{
     var d = new Date();
     var time = d.getDate();

     document.cookie=escape( cookieName ) + "=" + escape( cookieValue ) +
		( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
		( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") + 
		( isSecure ? ";secure" : "");     
}

function getCookie(name)
{
  var nameEQ = name + "=";
	var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);   
		if (c.indexOf(nameEQ) == 0) {
            var cookieValue = c.substring(nameEQ.length,c.length);
            return c.substring(nameEQ.length,c.length);
        }
	}
	return null;
}

function extendCookie(name,value,lifetime)
{
    setCookie(name,value,lifetime);
}


function deleteCookie(name)
{
    setCookie(name,"",-10);  
}

function getKey(key) {
    var ss = window.location.search;
    if (ss.charAt(0)=='?') ss = ss.substring(1,ss.length);
    var keys = ss.split('&');   
    var key = key + "=";	
    for(var i=0;i<keys.length;i++) {
        var c = keys[i];
        if (c.indexOf(key) == 0) { 
          return c.substring(key.length,c.length); 
        }
	}
	return false;
}

var SEHost = escape(window.location.hostname);

if (getKey("WT.srch") && getKey("srch")) {

    if (!getCookie("srch")) {
        var CookieValue = getKey("srch");
        setCookie("srch",CookieValue,CookieLifeTime,"/");  
    }
	
    if (!getCookie("SEHost")) {
        var CookieValue = SEHost;
        setCookie("SEHost",CookieValue,CookieLifeTime,"/"); 
    }
	
    if (!getCookie("WT.srch")) {
        var CookieValue = getKey("WT.srch");
        setCookie("WT.srch",CookieValue,CookieLifeTime,"/"); 
    }
    if (!getCookie(SEHost)) {
        var CookieValue = "WT.srch=" + getKey("WT.srch") + ";srch=" + getKey("srch") + ";SEHost=" + SEHost + ";";
        setCookie(SEHost,CookieValue,CookieLifeTime,"/"); 
    }
    
}

var addPPC = function () {
  var anchors;
  var srch = getCookie("srch");
  var wtsrch = getCookie("WT.srch");
  
  if (srch && wtsrch) {
  
    anchors = document.getElementsByTagName("A");
    for ( a0 in anchors ) {
      if ( anchors[a0].href && anchors[a0].href.lastIndexOf(window.location.hostname) < 0) {
        if ( anchors[a0].href.lastIndexOf("http://") == 0 || anchors[a0].href.lastIndexOf("https://") == 0) {
          if ( anchors[a0].href.lastIndexOf("?") > 0) {
              anchors[a0].href = anchors[a0].href + "&WT.srch="+wtsrch+"&srch="+srch;
          } else {
              anchors[a0].href = anchors[a0].href + "?WT.srch="+wtsrch+"&srch="+srch;
          }
        }
      }
    }
  }
};


var init = function() {
  addPPC();
};

if(window.addEventListener) {
  window.addEventListener("onload", init, false);
} else {
  window.attachEvent("onload", init);
}
