//added js functions from the old Sigma-Aldrich site

function OpenWin(URL, windowattributes) {
	//help=window.open(URL,"Help",'window attributes');
	help=window.open(URL,"Help",windowattributes);
	help.focus();
}

function changeParentURL(url){
	window.opener.location = url;
}

function OpenWindow(URL, windowattributes) {
	    help=window.open(URL,"Help",windowattributes);
	    help.focus();
	}

//SCRIPT FOR A JUMP-TO BOX
      function MM_jumpMenu(targ,selObj,restore){ //v3.0
      eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
      if (restore) selObj.selectedIndex=0;
 }     

//**added for CoreMetrics**//

function getMemberId() {
	var hasWCUserActivityCookie  = document.cookie.indexOf("WC_USERACTIVITY_");
	if (hasWCUserActivityCookie != -1 ){ 
		var startcount2 = hasWCUserActivityCookie + 16;// Start cookie value 
		var endcount2 = document.cookie.indexOf("=", startcount2); // End cookie value 
		if (endcount2 == -1) endcount = document.cookie.length; 
			var MemberID = document.cookie.substring(startcount2, endcount2); //Extract value 
	} 
	else 
	{ 
		MemberID = "Unknown"; 
	}

	if(MemberID == "-1002"){MemberID = "Unknown";}
	return MemberID;
}

function getClientId() {
	var ClientID = "Unknown";
	var userCookie = document.cookie;
 	var hasAnonymousClientIdCookie = userCookie.indexOf("AnonymousClientId="); 
	if (hasAnonymousClientIdCookie != -1 )
		{userCookie = userCookie.substring(hasAnonymousClientIdCookie + 21, userCookie.length);} 
 	var hasClientIdCookie = userCookie.indexOf("ClientId=");
	if (hasClientIdCookie != -1 ){
		var startcount = hasClientIdCookie + 9;
		var endcount = userCookie.indexOf(";", startcount);
			if (endcount == -1) endcount = userCookie.length; 
			{ClientID = userCookie.substring(startcount, endcount);}
	}
	return ClientID;
}

function getSiteId() {
	var Site = "SA";
	if (document.location.href.indexOf("safcglobal.com") != -1 ){
	Site = "SAFC";
	} 
	return Site;
}


//**added for Bookmark**//

var addthis_pub = "sigmaaldrich";

function writeSocialBookmark() {

}

//*For configurator CD 9006958*//
function overlayPopup(vis, options, extra, flag,  message,buttonLabel1) {
var rEmail;
var rItem;

  options = options || {};
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  var frame = document.getElementById('ifrm');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
  	tbody.appendChild(tnode); 
	dark=document.getElementById('darkenScreenObject');
//bw-10-00169, BW-10-00056 ad iframe to fix ie6 issue.
	var ifram = document.createElement('iframe');
		ifram.setAttribute('id','ifrm');
		ifram.setAttribute('src','');
		ifram.setAttribute('frameBorder','0');
		ifram.setAttribute('scrolling','no');		
		dark.appendChild(ifram);
		frame = document.getElementById('ifrm');
        var msgnode = document.createElement('div');           // Create the box layer.
                msgnode.style.position='absolute';                 // Position fixed
        msgnode.style.display='none';                      // Start out Hidden
        msgnode.id='box';                                                   // Name it so we can find it later
// DS 11/10 - CD 9004781 - changed width of box from 350px to 375px
                // give it a size and align it to center
				msgnode.style.width = "375px";
                msgnode.style.height = "300px";
                msgnode.style.marginleft= "-150px";
                msgnode.style.margintop= "-150px";
                msgnode.style.textAlign = 'center';
                msgnode.style.top= "35%";                           // In the top - works for Mozilla not for IE
                msgnode.style.left= "35%";                          // Left corner of the page - works for Mozilla not for IE
        tbody.appendChild(msgnode);                            // Add it to the grey screen 
  }
  if (vis) {
    // Calculate the page width and height
       var pageWidth='100%';
       var pageHeight1 = parseInt(document.documentElement.scrollHeight)+ parseInt(document.documentElement.offsetHeight)+parseInt(document.body.scrollHeight);
       var pageHeight = pageHeight1+'px';    
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;
    dark.style.MozOpacity=opaque;
    dark.style.filter='alpha(opacity='+opacity+')';
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';
  	frame.style.width=pageWidth;
	frame.style.height=pageHeight;
	frame.style.opacity=.5; 
	frame.style.MozOpacity=.5; 
	frame.style.filter='alpha(opacity=.5)'; 
	frame.style.zIndex=dark.style.zIndex - 1;
	frame.style.display="inline";
        if(extra == 'Y')
                document.body.style.overflow =  'hidden';
        document.getElementById("box").style.zIndex = zindex+10;
        document.getElementById("box").style.border = "#000 solid 1px";
        document.getElementById("box").style.display = "block";
		document.getElementById("box").style.height = "auto";
        document.getElementById("box").style.backgroundColor="#FFF";
 	//AL-10-00169 and AL-10-00056 : removed the original code for AL-10-00032, used iframe solution instead. 
     //Start: getting the message populated from shoppingcart.jsp and displayed here with format inplace.
		if(flag=='Alert')
	  	{
			var overlayContent = "<HTML><HEAD>"+
	        	" </HEAD><BODY><br><br><b>"+
		        message+
	        	"</b><br><br>"+
	        	"<center>"+
	        	"<input class=\"button02\" type=\"button\" id=\"closediv\" name=\"closediv\" value=\""+
	        	buttonLabel1+
	        	"\""+
	        	"onClick=\"overlay();\"> <\/input>"+
	        	"</center><BR><BR><BR></BODY></HTML>";
	  	}
        document.getElementById("box").innerHTML = overlayContent;
	} 
	else{
    	dark.style.display='none';
    	frame.style.display='none';
  }
}

function overlay(){
	document.getElementById("box").style.display = "none";
	document.getElementById('darkenScreenObject').style.display="none";
	document.getElementById('ifrm').style.display="none";
	document.body.style.overflow = 'auto';
}

//**added for popup countryselect**//
//For IE 8 popup conflict with Doctype
	engine = null;
	if (window.navigator.appName == "Microsoft Internet Explorer")
	{
	   // This is an IE browser. What mode is the engine in?
	   if (document.documentMode) // IE8
	      engine = document.documentMode;
	   else // IE 5-7
	   {
	      engine = 5; // Assume quirks mode unless proven otherwise
	      if (document.compatMode)
	      {
	         if (document.compatMode == "CSS1Compat")
	            engine = 7; // standards mode
	      }
	   }
	   // the engine variable now contains the document compatibility mode.
	}

// so that the country selection pop up can be called outside of the cookie setting
function changeCountry() {
	  grayOut(true,{'opacity':'25'});
	  showPopUp('dialog');
		  load('/set-country-cookie-backcompat.htm','dialog');
  }

var checkSialLocaleDef = document.cookie.indexOf("SialLocaleDef="); 
if (checkSialLocaleDef != -1) { 
	//If SialLocaleDef exists, get it's value
      	var start = checkSialLocaleDef + 14;                      // Start of cookie value 
      	var end = document.cookie.indexOf(";", start);            // End of cookie value 
      	if (end == -1) end = document.cookie.length; 
      	var checkSialLocaleDef=unescape(document.cookie.substring(start, end)); 
}

var agenttext=navigator.userAgent;
var agentlower=agenttext.toLowerCase();
var CountryCookie = document.cookie.indexOf("country=");
var SialLocale = document.cookie.indexOf("SialLocaleDef="); 
// see if browser has cookies enabled
document.cookie = "Cck=present; path=/";
if ((document.cookie.indexOf("present")) != -1) {
	// remove cookie created to check browser
	document.cookie = "Cck=present; path=/; expires=15/02/2003 00:00:00; ";
	if ((CountryCookie == -1) || (SialLocale == -1) || (checkSialLocaleDef.indexOf("CountryCode") == -1)) { 
		var xmlhttp=false;
		try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
		xmlhttp = false;
		}
		}
		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
			try {
				xmlhttp = new XMLHttpRequest(); 
			} catch (e) {
				xmlhttp=false;
			}
		}
		if (!xmlhttp && window.createRequest) {
			try {
				xmlhttp = window.createRequest();
			} catch (e) {
				xmlhttp=false;
			}
		}
		if (xmlhttp) {	
		xmlhttp.open("HEAD", location.href ,true);
		xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var geoInfo = xmlhttp.getResponseHeader('X-Akamai-Edgescape');
			//var geoInfo = "georegion=255,country_code=US,region_code=IL,";
			if (geoInfo == null) {
			geoInfo = ""
			}
			if ((geoInfo != "") && (geoInfo.indexOf("country_code") != -1) ) {
				geoInfo = geoInfo.split("country_code=");
				geoInfo = geoInfo[1].split(",");  
				var aCountry = geoInfo[0];
				aCountry = aCountry.replace(/[^a-zA-Z]+/g,"").replace("AQ","US").replace("BQ","AW").replace("CC","GC").replace("CD","ZR").replace("CW","AW").replace("EH","MA").replace("FO","XG").replace("FX","FR").replace("GG","GB").replace("GS","GB").replace("IM","GB").replace("IO","GB").replace("JE","GB").replace("PR","US").replace("PS","IL").replace("RS","SX").replace("SJ","NO").replace("TF","FR").replace("TL","TP").replace("UM","US");
				var sUSAX="SO,AW,AG,BS,BB,BZ,BM,BO,KY,CO,CR,CU,DM,DO,EC,SV,FK,GL,GD,GU,GT,GY,HT,HN,JM,MH,MS,AN,NI,PA,PE,KN,LC,VC,SR,TT,TC,VE,VG,VI";
				var sAST="AS,AU,CX,CK,FJ,HM,KI,FM,NR,NU,NF,MP,PW,PG,PN,SH,WS,SB,TK,TO,TV,VU";
				var sFRA="GF,PF,GP,MQ,YT,MC,NC,RE,PM,WF";
				var sSNG="BN,KH,TP,ID,LA,MM,PH,SG,TH,VN";
				var sLANG="GI,AD,SM,EE,SK,SI,ZA,SZ,HK,CZ,DK,IN,IE,IL,NL,NO,RU,SE,TW,GB,US,NZ";
					if ((sUSAX.indexOf(aCountry)) != -1){
							document.cookie = "country=USAX" +";path=/; expires=" + ged(num_days);
						} else if ((sAST.indexOf(aCountry)) != -1){
							document.cookie = "country=AST" +";path=/; expires=" + ged(num_days);
						} else if ((sFRA.indexOf(aCountry)) != -1){
						document.cookie = "country=FRA" +";path=/; expires=" + ged(num_days);
						} else if ((sSNG.indexOf(aCountry)) != -1){
							document.cookie = "country=SNG" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "MY")) {
							document.cookie = "country=MAL" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-1|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "GI") || ((aCountry) == "AD")) {
							document.cookie = "country=SPA" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "SM") || ((aCountry) == "EE")) {
							document.cookie = "country=FIN" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "VA") || ((aCountry) == "IT")) {
							document.cookie = "country=ITA" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-4|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						//} else if (((aCountry) == "BE") || ((aCountry) == "LU")) {
						} else if (((aCountry) == "LU")) {
							document.cookie = "country=BELF" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-2|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "AR") || ((aCountry) == "PY")) {
							document.cookie = "country=ARG" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-32|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "SK") || ((aCountry) == "SI")) {
							document.cookie = "country=SLO" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "ZA") || ((aCountry) == "SZ")) {
							document.cookie = "country=SAF" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "AT")) {
							document.cookie = "country=AUS" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-3|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "DE")) {
							document.cookie = "country=GER" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-3|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "BR")) {
							document.cookie = "country=BRZ" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-6|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						//} else if (((aCountry) == "CA")) {
						//	document.cookie = "country=CANE" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "CN")) {
							document.cookie = "country=CHIM" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-7|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "HK")) {
							document.cookie = "country=CHIT" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "CL")) {
							document.cookie = "country=CHL" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-32|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "CZ")) {
							document.cookie = "country=CZH" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "DK")) {
							document.cookie = "country=DEN" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "FI")) {
							document.cookie = "country=FIN" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-17|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "FR")) {
							document.cookie = "country=FRA" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-2|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "HU")) {
							document.cookie = "country=HUN" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-19|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "IN")) {
							document.cookie = "country=IND" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "IE")) {
							document.cookie = "country=IRE" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "IL")) {
							document.cookie = "country=ISR" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "JP")) {
							document.cookie = "country=JPN" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-10|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "KR")) {
							document.cookie = "country=KOR" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-9|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "MX")) {
							document.cookie = "country=MEX" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-32|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "NL")) {
							document.cookie = "country=NED" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "NO")) {
							document.cookie = "country=NOR" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "PL")) {
							document.cookie = "country=POL" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-24|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "PT")) {
							document.cookie = "country=POR" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-6|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "RU")) {
							document.cookie = "country=RUS" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "ES")) {
							document.cookie = "country=SPA" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-5|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						} else if (((aCountry) == "SE")) {
							document.cookie = "country=SWE" +";path=/; expires=" + ged(num_days);
						//} else if (((aCountry) == "CH")) {
						//	document.cookie = "country=SWISC" +";path=/; expires=" + ged(num_days);
						//	document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-3|" + ";path=/; expires=" + ged(num_days);
						//	window.location.reload(true);
						} else if (((aCountry) == "TW")) {
							document.cookie = "country=TWN" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "GB")) {
							document.cookie = "country=UK" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "US")) {
							document.cookie = "country=USA" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "NZ")) {
							document.cookie = "country=ZEA" +";path=/; expires=" + ged(num_days);
						} else if (((aCountry) == "EU")|| ((aCountry) == "CA") ||((aCountry) == "CH") || ((aCountry) == "BE")) {
							function start() {
							grayOut(true,{'opacity':'25'});
							showPopUp('dialog');
							load('/set-country-cookie-backcompat.htm','dialog');
							}
							if (window.attachEvent) {window.attachEvent('onload', start);}
							else if (window.addEventListener) {window.addEventListener('load', start, false);}
							else {document.addEventListener('load', start, false);}
						} else {
							document.cookie = "country=EURX" +";path=/; expires=" + ged(num_days);
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-1|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						}
						if  (((sUSAX.indexOf(aCountry)) != -1) || ((sAST.indexOf(aCountry)) != -1) || ((sFRA.indexOf(aCountry)) != -1) || ((sSNG.indexOf(aCountry)) != -1) || ((sLANG.indexOf(aCountry)) != -1)) {
							document.cookie = "SialLocaleDef=CountryCode~" + aCountry + "|WebLang~-1|" + ";path=/; expires=" + ged(num_days);
							window.location.reload(true);
						}	
				} else { 
					if ((document.location.href.indexOf("safcglobal.com") == -1) && (document.location.href.indexOf("/safc-") == -1) && (document.location.href.indexOf("/help") == -1) && (document.location.href.indexOf("/splash") == -1) && (document.location.href.indexOf("/sigma-aldrich/home") == -1) && (document.location.href.indexOf("/site-level") == -1) && (document.location.href.indexOf("/medialib") == -1) && (document.location.href.indexOf("/errorpage") == -1) && (agentlower.indexOf("google") == -1)) {
					function start() {
					grayOut(true,{'opacity':'25'});
					showPopUp('dialog');
					load('/set-country-cookie-backcompat.htm','dialog');
					}
					if (window.attachEvent) {window.attachEvent('onload', start);}
					else if (window.addEventListener) {window.addEventListener('load', start, false);}
					else {document.addEventListener('load', start, false);}
					}
				}
			}
		}  
		xmlhttp.send(null)
		} else 	{
			if ((document.location.href.indexOf("safcglobal.com") == -1) && (document.location.href.indexOf("/safc-") == -1) && (document.location.href.indexOf("/help") == -1) && (document.location.href.indexOf("/splash") == -1) && (document.location.href.indexOf("/sigma-aldrich/home") == -1) && (document.location.href.indexOf("/site-level") == -1) && (document.location.href.indexOf("/medialib") == -1) && (document.location.href.indexOf("/errorpage") == -1) && (agentlower.indexOf("google") == -1)) {
				function start() {
				grayOut(true,{'opacity':'25'});
				showPopUp('dialog');
					load('/set-country-cookie-backcompat.htm','dialog');
				}
				if (window.attachEvent) {window.attachEvent('onload', start);}
				else if (window.addEventListener) {window.addEventListener('load', start, false);}
				else {document.addEventListener('load', start, false);} 
			}
		}
	} 
} else {
if (document.location.href.indexOf("/site-level/user-cookies.html") == -1) {
	document.location.replace("/site-level/user-cookies.html");
	}
}

//to change sitesitedef to session--this can be removed after a while
	var SialSiteDef = document.cookie.indexOf("SialSiteDef="); 
		if (SialSiteDef != -1) { 
			//If SialSiteDef exists, get it's value
        		var start = SialSiteDef + 12;                             // Start of cookie value 
        		var end = document.cookie.indexOf(";", start);            // End of cookie value 
        		if (end == -1) end = document.cookie.length; 
        		var SialSiteDef=unescape(document.cookie.substring(start, end)); 
		resetSialSiteDef = SialSiteDef;
		document.cookie = "SialSiteDef=" + resetSialSiteDef + ";path=/";
		}

// number of days cookie lives for
	num_days = 360;
	function ged(noDays){
		var today = new Date();
		var expr = new Date(today.getTime() + noDays*24*60*60*1000);
		return  expr.toGMTString();
	}

//This sets cookies when links are clicked on pop up country selector
function setCountryLink(CountryInfo) {
	selectedValue = CountryInfo;
	setCookie();
}
//This sets cookies when countries are selected from the dropdown 
function setCountryDrop() {
	var selectedValue2 = document.choosecountry.cscope.options[document.choosecountry.cscope.selectedIndex].value;
	if ((selectedValue2) != "" ) {
		selectedValue = selectedValue2
		setCookie();		
	} else {
		alert("Please Choose a Country or Region");
      }
}

//This gets called when "submit" is clicked.  It will set the cookie and close the window.
function setCookie() {
		//selectedValue = selectedValue.search.replace(/%28/,"(").replace(/%29/,")");
		selectedValue = selectedValue.replace(/[^a-zA-Z % + & =]+/g,'');
		sCode = selectedValue.substring(selectedValue.indexOf("Code=") + 5, selectedValue.indexOf("&Page"));
		sPage = selectedValue.substring(selectedValue.indexOf("Page=") + 5, selectedValue.indexOf("&SO"));
		sSO = selectedValue.substring(selectedValue.indexOf("SO=") + 3);
		document.cookie = "country=" + sCode + ";path=/; expires=" + ged(num_days);
		if ((sCode.indexOf("CANF") != -1) || (sCode.indexOf("BELF") != -1) || (sCode.indexOf("FRA") != -1) || (sCode.indexOf("SWISU") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-2|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("AUS") != -1) || (sCode.indexOf("GER") != -1) || (sCode.indexOf("SWISC") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-3|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("ARG") != -1) || (sCode.indexOf("CHL") != -1) || (sCode.indexOf("MEX") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-32|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("BRZ") != -1) || (sCode.indexOf("POR") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-6|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("CHIM") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-7|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("FIN") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-17|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("HUN") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-19|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("ITA") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-4|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("JPN") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-10|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("KOR") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-9|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("POL") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-24|" + ";path=/; expires=" + ged(num_days);
		} else if ((sCode.indexOf("SPA") != -1)) {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-5|" + ";path=/; expires=" + ged(num_days);
		} else {
			document.cookie = "SialLocaleDef=CountryCode~" + sSO + "|WebLang~-1|" + ";path=/; expires=" + ged(num_days);			
		}
		closePopUp('dialog');
		grayOut(false);
		var goHome="catalog,webapp,configurator,chemistry,analytical-chromatography,labware,life-science,programs,materials-science,technical-service-home,safety-center,site-level,sigma-aldrich,safc-,medialib";
		var reFresh="catalog,webapp,configurator,sigma-aldrich";
		var sUrl=document.location.href;
		sUrl = sUrl.split(document.location.hostname);
		sUrl = sUrl[1].split("/");
		sUrl = sUrl[1].split(".");
		sUrl = sUrl[0];
		if ((reFresh.indexOf(sUrl)) != -1) { 
		window.location.reload(true);
		} 
		if ((goHome.indexOf(sUrl)) == -1) { 
			document.location.replace("/sigma-aldrich/home.html");
		}	
}


function showPopUp(el) {
var dlg = document.getElementById(el)
dlg.style.display = "block"
}
function closePopUp(el) {
var dlg = document.getElementById(el)
dlg.style.display = "none"
}

function grayOut(vis, options) {
// Pass true to gray out screen, false to ungray
// options are optional. This is a JSON object with the following (optional) properties
// opacity:0-100 // Lower number = less grayout higher = more of a blackout 
// zindex: # // HTML elements with a higher zindex appear on top of the gray out
// bgcolor: (#xxxxxx) // Standard RGB Hex color code
// grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
// Because options is JSON opacity/zindex/bgcolor are all optional and can appear
// in any order. Pass only the properties you need to set.
var options = options || {}; 
var zindex = options.zindex || 50;
var opacity = options.opacity || 70;
var opaque = (opacity / 100);
var bgcolor = options.bgcolor || '#000000';
var dark=document.getElementById('darkenScreenObject');
if (!dark) {
// The dark layer doesn't exist, it's never been created. So we'll
// create it here and apply some basic styles.
// If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
var tbody = document.getElementsByTagName("body")[0];
var tnode = document.createElement('div'); // Create the layer.
var ifram = document.createElement('iframe'); //create an iframe to address ie6 shortcomings
ifram.setAttribute('id','ifrm');
ifram.setAttribute('src','');
ifram.setAttribute('frameBorder','0');
ifram.setAttribute('scrolling','no');
tnode.style.position='absolute'; // Position absolutely
tnode.style.top='0px'; // In the top
tnode.style.left='0px'; // Left corner of the page
tnode.style.overflow='hidden'; // Try to avoid making scroll bars 
tnode.style.display='none'; // Start out Hidden
tnode.id='darkenScreenObject'; // Name it so we can find it later
tbody.appendChild(ifram);
tbody.appendChild(tnode); // Add it to the web page
dark=document.getElementById('darkenScreenObject'); // Get the object.
dark.appendChild(ifram);
frame = document.getElementById('ifrm'); //get the iframe
}
if (vis) {
// Calculate the page width and height 
if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
var pageWidth = document.body.scrollWidth+'px';
var pageHeight = document.body.scrollHeight+'px';
} else if( document.body.offsetWidth ) {
var pageWidth = document.body.offsetWidth+'px';
var pageHeight = document.body.offsetHeight+'px';
} else {
var pageWidth='100%';
var pageHeight='100%';
} 
//set the shader to cover the entire page and make it visible.
dark.style.opacity=opaque; 
dark.style.MozOpacity=opaque; 
dark.style.filter='alpha(opacity='+opacity+')'; 
dark.style.zIndex=zindex; 
dark.style.backgroundColor=bgcolor; 
dark.style.width= pageWidth;
dark.style.height= pageHeight;
frame.style.width= pageWidth;
frame.style.height= pageHeight;
frame.style.opacity=opaque; 
frame.style.MozOpacity=opaque; 
frame.style.filter='alpha(opacity='+opacity+')';
frame.style.zIndex=dark.style.zIndex - 1;
frame.style.display="inline";
dark.style.display='block'; 
} else {
dark.style.display='none';
frame.style.display='none';
}
}

function ahah(url, target) {
  document.getElementById(target).innerHTML = ' Retrieving data...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function load(name, div) {
	ahah(name,div);
	return false;
}

document.write("<div id='dialog'></div>");

// ***search look ahead****
var linkList = new Array();
var myArray = new Array();
var sigma = {

	searchBar: {
		init: function(){

		}
	}
};
		
function doSearch()
{
	var search;
	search = jQuery.trim(jQuery("#Query").val());

	var html = "<ul>";

	var url = "/catalog/SearchTypeahead.do?Query=" + encodeURI(search);
	for (var i = 0; i < myArray.length; i++) 
	{
		myArray[i].abort();
	    myArray.splice(i,1);
	}
	
	xhr = jQuery.ajax({
		     async: true,
		     url: url,
		     dataType: "json",
		     success: function(json) 
		     {
				var i=0;
				jQuery('#resultsLookAheadContent').html("");
				//jQuery('#searchTitle').hide();
				jQuery("#recentSearches").hide();
				var typeaheadList = "<ul class=\"lookaheadResultsContainer\">";
				
				for (i=0;i<json.lookaheadarray.length-1;i++)
				{
					var  theTextValue = (json.lookaheadarray[i].TextValue).replace(/-/g,' ');
					
					var theSearchTerm = (json.lookaheadarray[i].searchTerm).replace(/-/g,' ');
					var spotInResult = (theTextValue.toUpperCase()).indexOf((theSearchTerm).toUpperCase());

					//var spotInResult = ((json.lookaheadarray[i].TextValue).toUpperCase()).indexOf((json.lookaheadarray[i].searchTerm).toUpperCase());
					var lengthOfSearchTerm = (json.lookaheadarray[i].searchTerm).length;
					var translatedRoot = " " + json.lookaheadarray[i].TranslatedRefinement;
					var nontranslatedRoot = json.lookaheadarray[i].NonTranslatedRefinement;
					
					if (nontranslatedRoot.indexOf('LA_REF_PROD_NAM') >= 0)
						translatedRoot = "";
					var inTerm;
					if ((json.lookaheadarray[i].InTerm).length > 0)
						inTerm = json.lookaheadarray[i].InTerm+"-";
					else
						inTerm = "NA-";
					var coremetricsTag = "SearchLookAhead-"+json.lookaheadarray[i].searchInterface+"-"+inTerm+encodeURI(json.lookaheadarray[i].searchTerm)+"-"+encodeURI(cleanSearchTerm(json.lookaheadarray[i].TextValue));
					if (spotInResult < 0)
					{
						var term =  json.lookaheadarray[i].TextValue;
						linkList.push(buildSearchUrl(cleanSearchTerm(json.lookaheadarray[i].TextValue), json.lookaheadarray[i].searchInterface, json.lookaheadarray[i].Id));
  							typeaheadList = typeaheadList + "<li class=\"lookaheadResultsElement\"><a class=\"lookaheadText\" onclick=\"cmCreatePageElementTag(\'"+coremetricsTag+"\',\'SIAL-Header\')\" href=\"/catalog/Lookup.do?N5="+json.lookaheadarray[i].searchInterface+"&N3=mode+matchpartialmax&N4="+encodeURI(cleanSearchTerm(json.lookaheadarray[i].TextValue))+"&N1=S_ID&ST=RS&N25="+json.lookaheadarray[i].Id+"&F=PR\">" + term + "<span class=\"focusblue\">" + json.lookaheadarray[i].InTerm+ translatedRoot + "</span>" + "</a></li>";
					} 
					else if (spotInResult == 0)
					{
						var term =  "<span class=\"focusblue\">"+json.lookaheadarray[i].TextValue.substr(spotInResult,lengthOfSearchTerm) + "</span>" + json.lookaheadarray[i].TextValue.substr(lengthOfSearchTerm);
						linkList.push(buildSearchUrl(cleanSearchTerm(json.lookaheadarray[i].TextValue), json.lookaheadarray[i].searchInterface, json.lookaheadarray[i].Id));							
					    typeaheadList = typeaheadList + "<li class=\"lookaheadResultsElement\"><a class=\"lookaheadText\" onclick=\"cmCreatePageElementTag(\'"+coremetricsTag+"\',\'SIAL-Header\')\" href=\"/catalog/Lookup.do?N5="+json.lookaheadarray[i].searchInterface+"&N3=mode+matchpartialmax&N4="+encodeURI(cleanSearchTerm(json.lookaheadarray[i].TextValue))+"&N1=S_ID&ST=RS&N25="+json.lookaheadarray[i].Id+"&F=PR\">" + term + "<span class=\"focusblue\">" + json.lookaheadarray[i].InTerm+ translatedRoot + "</span>" + "</a></li>";
					}	
					else
					{
						var term =  json.lookaheadarray[i].TextValue.substr(0,spotInResult)+"<span class=\"focusblue\">"+json.lookaheadarray[i].TextValue.substr(spotInResult,lengthOfSearchTerm) + "</span>" + json.lookaheadarray[i].TextValue.substr(spotInResult+lengthOfSearchTerm);
						linkList.push(buildSearchUrl(cleanSearchTerm(json.lookaheadarray[i].TextValue), json.lookaheadarray[i].searchInterface, json.lookaheadarray[i].Id));	
						typeaheadList = typeaheadList + "<li class=\"lookaheadResultsElement\"><a class=\"lookaheadText\" onclick=\"cmCreatePageElementTag(\'"+coremetricsTag+"\',\'SIAL-Header\')\" href=\"/catalog/Lookup.do?N5="+json.lookaheadarray[i].searchInterface+"&N3=mode+matchpartialmax&N4="+encodeURI(cleanSearchTerm(json.lookaheadarray[i].TextValue))+"&N1=S_ID&ST=RS&N25="+json.lookaheadarray[i].Id+"&F=PR\">" + term + "<span class=\"focusblue\">" + json.lookaheadarray[i].InTerm+ translatedRoot + "</span>" + "</a></li>";
					}
			    	
				}
				i = json.lookaheadarray.length-1;
				var coremetricsTag = "SearchLookAhead-"+json.lookaheadarray[i].searchInterface+"-NA-"+encodeURI(json.lookaheadarray[i].searchTerm)+"-"+"ViewAll";
				var term =  json.lookaheadarray[i].TextValue.substr(0,spotInResult)+"<span class=\"focusblue\">"+json.lookaheadarray[i].TextValue.substr(spotInResult,lengthOfSearchTerm) + "</span>" + json.lookaheadarray[i].TextValue.substr(spotInResult+lengthOfSearchTerm);
				
				linkList.push(buildSearchUrl(json.lookaheadarray[i].searchTerm, json.lookaheadarray[i].searchInterface, "0"));
				typeaheadList = typeaheadList + "<li class=\"lookaheadResultsElement\"><a class=\"lookaheadText focusblue\" onclick=\"cmCreatePageElementTag(\'"+coremetricsTag+"\',\'SIAL-Header\')\" href=\"/catalog/Lookup.do?N5="+json.lookaheadarray[i].searchInterface+"&N3=mode+matchpartialmax&N4="+encodeURI(json.lookaheadarray[i].searchTerm)+"&N1=S_ID&ST=RS&N25=0&F=PR\">" + json.lookaheadarray[i].viewAll+"</a></li>";
				typeaheadList = typeaheadList + "</ul>";
				
				html = html + "</ul>";
				jQuery('#resultsLookAheadContent').append(typeaheadList);
				
				jQuery('#resultsLookAheadContent').show();	
			}
	
	});
	myArray.push(xhr);
	

}
		
/**
	On DOM LOADED
*/
jQuery(function(){
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
	  return this.animate({opacity: 'toggle'}, speed, easing, callback); 
	};
	sigma.searchBar.init();
});

var secs = 0;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function StopTheClock()
{
    if(timerRunning) {
        clearTimeout(timerID);
	}
    timerRunning = false;
    alert('this took' + secs);
}

function StartTheTimer()
{
    self.status = secs;
    secs = secs + 1;
    timerRunning = true;
    timerID = self.setTimeout("StartTheTimer()", delay);
    
}


// changes for Chinese and Japanese
var lookaheadEnabled = true;
if(document.cookie.indexOf('CountryCode~JP') >= 0 || document.cookie.indexOf('CountryCode~CN') >= 0){
	lookaheadEnabled = false;
}
jQuery(document).ready(function(){

	/*
	if(true == lookaheadEnabled) {
		jQuery('#searchTrigger').click(function(e){
			jQuery('#searchBox').show();
			jQuery('#Query').focus();
			jQuery('#searchDropDown').fadeIn('fast');
			if(jQuery("ul.lookaheadResultsContainer").length == 0 ) {
				jQuery("#recentSearches").show(); 
			}
		});
	}
	*/

	jQuery("#Query").bind('keypress', function(e){
		var code = e.keyCode || e.which;
		if(code === 13) { // Enter key
			if(true == e.isPropagationStopped()){
				return;
			}
			if(selectedIndex < 0){
				formHandlerTwo();
			}
			else{
				window.location.href = jQuery("ul.lookaheadResultsContainer li.lookaheadResultsElement a.lookaheadText").eq(selectedIndex).attr("href");
			}
			e.stopPropagation();
			return false;
		}	
	
	});

	jQuery("#Query").bind('keyup', function(e){

        var code = e.keyCode || e.which;

		if (code === 40) { //Down arrow
			if(true == e.isPropagationStopped()){
				return;
			}
            if( jQuery("li.hovered").index() == jQuery("li.lookaheadResultsElement").length-1){
				return;
			}

            if (jQuery("ul.lookaheadResultsContainer li.hovered").size() == 0) { //if no li has the hovered class
                jQuery("ul.lookaheadResultsContainer li").first().addClass("hovered");
				selectedIndex = 0;
            } else {
				jQuery("li.hovered").removeClass("hovered").next().addClass("hovered");
				selectedIndex++;
            }
			e.stopPropagation();
			return false;
        }
        else if (code === 38) { //Up arrow
			if(true == e.isPropagationStopped()){
				return;
			}
            if(jQuery("li.hovered").index()==0) {
				return;
			}
            if (!jQuery("li.hovered")) { //if no li has the hovered class
                jQuery("li.hovered").eq(0).removeClass("hovered");
				selectedIndex = -1;
            } else {                 
				jQuery("li.hovered").eq(0).removeClass("hovered").prev().addClass("hovered");
				selectedIndex--;
            }
			e.stopPropagation();					
			return false;
        }
		else {
			linkList.length = 0;
			selectedIndex = -1;
			var search;
			search = jQuery("#Query").val();

			var dolookahead = false;
			if (((document.cookie).indexOf('CountryCode~JP') >= 0 || (document.cookie).indexOf('CountryCode~CN') >= 0) && search.length > 0)
			{
				// changes for Chinese and Japanese
				dolookahead = false;
			}
			if (((document.cookie).indexOf('CountryCode~JP') < 0 && (document.cookie).indexOf('CountryCode~CN') < 0) && search.length  > 2 ) 
		    {
		    	dolookahead = true;
		    }
		  
		    if (dolookahead)
		    {	
				clearTimeout(jQuery.data(this, 'timer'));
				var wait = setTimeout(doSearch, 200);
				jQuery(this).data('timer', wait);
			}
/*			else if (search.length > 2) 
			{
				clearTimeout(jQuery.data(this, 'timer'));
				var wait = setTimeout(doSearch, 200);
				jQuery(this).data('timer', wait);
			} 
*/
			else {
				clearTimeout(jQuery.data(this, 'timer'));
				jQuery("#recentSearches").show();
				jQuery("ul.lookaheadResultsContainer").remove();
				jQuery('#resultsLookAheadContent').hide();
			}
		}
	}); 

	jQuery("ul.lookaheadResultsContainer li").live('mouseover', function(evt){
		if(true == evt.isPropagationStopped()){
			return;
		}			
		jQuery("ul.lookaheadResultsContainer li").each(function(index, Elem){
			jQuery(this).removeClass("hovered");
		});
		
		jQuery(this).addClass("hovered");
		var index = jQuery(this).index();
		evt.stopPropagation();					
		return false;
	});
	jQuery("ul.lookaheadResultsContainer li").live('mouseout', function(evt){
		if(true == evt.isPropagationStopped()){
			return;
		}				
		jQuery(this).removeClass("hovered");
		evt.stopPropagation();					
		return false;
	});

	if(true == lookaheadEnabled) {
		jQuery("#Query").click(function(evt){
			clearDefaultandCSS(document.getElementById("Query"));
				jQuery("#searchBox").addClass("searchBoxExtended");
			jQuery("#Query").removeClass("Query").addClass("Query-extended");
			jQuery('#searchDropDown').fadeIn('fast');
			if(jQuery("ul.lookaheadResultsContainer").length == 0 ) {
				jQuery("#recentSearches").show(); 
			}
		});
	}

	jQuery("body").click(function(evt){
		if(jQuery('#searchDropDown').is(":visible") == false){
			return;
		}
		var sBoxHeight = jQuery('#searchBox').height();
		var sBoxWidth = jQuery('#searchBox').width();
		var sBoxOffset = jQuery('#searchBox').offset();
		var sBoxTop = sBoxOffset.top;
		var sBoxleft = sBoxOffset.left;


		var sDropDownHeight = jQuery('#searchDropDown').height();
		var sDropDownWidth = jQuery('#searchDropDown').width();
		var sDropDownOffset = jQuery('#searchDropDown').offset();
		var sDropDownTop = sDropDownOffset.top;
		var sDropDownLeft = sDropDownOffset.left;

		var mouseX = evt.pageX;
		var mouseY = evt.pageY;	

		if (mouseY < sBoxTop || mouseX > (sBoxleft + sBoxWidth) || mouseX < sBoxleft ||
			mouseY > (sDropDownTop + sDropDownHeight) || mouseX > (sDropDownLeft + sDropDownWidth) || mouseX < sDropDownLeft){
			jQuery("#searchDropDown").hide();
			jQuery("#searchBox").removeClass("searchBoxExtended");
			jQuery("#Query").removeClass("Query-extended").addClass("Query");
		}
	});
});

function buildSearchUrl(n4Val, n5Val, n25Val){
	return "/catalog/Lookup.do?N5=" + n5Val + "&N3=mode+matchpartialmax&N4=" + encodeURI(cleanSearchTerm(n4Val)) + "&N1=S_ID&ST=RS&N25=" + n25Val + "&F=PR";
}
function removeHTMLTags(toBeStripped){
 		var strInputCode = toBeStripped
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
 		return strTagStrippedText;
}
function removeForSecurity(originalTerm){
		var strTagStrippedText = originalTerm.replace(/\s([^&][^#]\S*);\s/g, " $1 ");		
 		return strTagStrippedText;
}
function cleanSearchTerm(originalTerm){
	return removeForSecurity(removeHTMLTags(originalTerm));
}
