function loginorcart()
{
	var islog = getCookie('buyok_skuserid');
	if(islog == null){}
	else{
		var usrcn = getCookie('buyok_skusercn');
		document.getElementById("headlink").innerHTML = "<a href='/viewbasket.jsp'><img src='/img/basket.png' width='23' height='18' align='absmiddle' /><span class='title'>Checkout</span></a>&nbsp;<a href='/myaccount.jsp'><img src='/img/login.png' width='16' height='18' align='absmiddle' /><span class='title'>Account</span></a><a href='/logout.jsp'><span class='title'>Logout</span></a>";
		//document.getElementById("middleGap").innerHTML = "Welcome back, <a href='http://www.selleckchem.com/myaccount.jsp'>"+usrcn+"</a>";
	}
}

function getCookieVal(offset)
{
    var endstr = document.cookie.indexOf(";", offset);
    if(endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return document.cookie.substring(offset, endstr);
}

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 changeheadbar(cty){
	var selCty = getCookie('sk_selcountry');
	if(selCty == null){
		var Days = 360;
		var name = "sk_selcountry";
		var exp  = new Date();
		exp.setTime(exp.getTime() + Days*24*60*60*1000);
		document.cookie = name + "="+ escape (cty) + ";expires=" + exp.toGMTString();
	}
	
    //SetCookie("sk_selcountry",cty);
    
	var rd=new Date();
	var url="../changecty.jsp?ctycode="+cty+"&"+rd;
	var xmlhttp=null;	//new ActiveXObject("Microsoft.XMLHTTP");
	try {//Firefox, Chrome, Surfri, Opera+8
		xmlhttp = new XMLHttpRequest();
	} catch (ie) {
		try {//IE6+
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (ie) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlhttp.open("get",url,false);
	xmlhttp.send();
	//document.getElementById("timer").innerHTML = xmlhttp.responseText;
	if(xmlhttp.readyState==4)
	{
	  if(xmlhttp.status==200)
	    {
		  if(xmlhttp.responseText.indexOf("none-1")==-1)
		    {
			  //alert(xmlhttp.responseText);
			  var tmpArray=xmlhttp.responseText.split("|");
			  document.getElementById("ctytxt").innerHTML= tmpArray[5];
			  document.getElementById("ctyflag").src = '/img/'+tmpArray[4]+'.png';
			}
		}
	}
}

function setutrack(value) {
	if (value == "null" && value == "") {
		value = "null";
	}
	var date = new Date();
	date.setMonth(date.getMonth() + 1);
	var list = new Array();
	var cookies = document.cookie.split(';');
	var cookie = '';
	var c = '';
	for ( var i = 0; i < cookies.length; i++) {
		cookie = cookies[i].split('=');
		if (cookie[0].replace(/^\s+|\s+$/g, '') == "sk_usertracking") {
			c = cookie[0].replace(/^\s+|\s+$/g, '');
			break;
		}
	}
	if (c == "sk_usertracking") {
		var user = unescape(cookie[1].replace(/^\s+|\s+$/g, ''));
		var href = window.location.href;
		var href1 = window.location.href;
		var strarray = user.split(";");
		for ( var i = 0; i < strarray.length; i++) {
			var url = strarray[0];
			var a4 = strarray[3];
			var href1 = a4;
			var a3 = strarray[4];
			var str = a3.split("=")[1];
			if (str.indexOf(value) == -1) {
				if (value == "null" && str == "null") {
					var all = url + ";LastPage=" + href + ";Customer=userid"
							+ ";" + href1 + ";Product=" + value;
				}
				if (value == "null" && str != "null") {
					var all = url + ";LastPage=" + href + ";Customer=userid"
							+ ";" + href1 + ";" + a3;
				}
				if (value != "null" && str != "null") {
					var a4 = str + ",";
					var all = url + ";LastPage=" + href + ";Customer=userid"
							+ ";" + href1 + ";Product=" + a4.concat(value);
				}
				if (value != "null" && str == "null") {
					if (str == "null") {
						var all = url + ";LastPage=" + href
								+ ";Customer=userid" + ";" + href1
								+ ";Product=" + value;
					} else {
						var a4 = str;
						var all = url + ";LastPage=" + href
								+ ";Customer=userid" + ";" + href1
								+ ";Product=" + a4.concat(value);
					}
				}
				document.cookie = "sk_usertracking=" + escape(all) + ";expires="+ date.toGMTString()+";path=/";
			} else {
				var all = url + ";LastPage=" + href + ";Customer=userid" + ";"
						+ href1 + ";" + a3;
				document.cookie = "sk_usertracking=" + escape(all) + ";expires="+ date.toGMTString()+";path=/";
			}
		}
	} else {
		var url = document.referrer;
		if (url == "") {
			url = "null";
		}
		var href3 = window.location.href;
		var all = "referrer=" + url + ";LastPage=" + href3 + ";Customer=userid"
				+ ";StartPage=" + href3 + ";Product=" + value;
		document.cookie = "sk_usertracking=" + escape(all) + ";expires="+ date.toGMTString()+";path=/";
	}
}
