function saveCookie(name, value, expires, path, domain, secure){
  var strCookie = name + "=" + value;
  if (expires){
     var curTime = new Date();
     curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
     strCookie += "; expires=" + curTime.toGMTString();
  }
  strCookie +=  (path) ? "; path=" + path : ""; 
  strCookie +=  (domain) ? "; domain=" + domain : "";
  strCookie +=  (secure) ? "; secure" : "";
  document.cookie = strCookie;
}
function getCookie(name){
  var strCookies = document.cookie;
  var cookieName = name + "=";  
  var valueBegin, valueEnd, value;
  valueBegin = strCookies.indexOf(cookieName);
  if (valueBegin == -1) return null; 
  valueEnd = strCookies.indexOf(";", valueBegin);
  if (valueEnd == -1)
      valueEnd = strCookies.length; 
  value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
  return value;
}

function checkCookieExist(name){
  if (getCookie(name))
      return true;
  else
      return false;
}

function deleteCookie(name, path, domain){
  var strCookie;
  if (checkCookieExist(name)){
    strCookie = name + "="; 
    strCookie += (path) ? "; path=" + path : "";
    strCookie += (domain) ? "; domain=" + domain : "";
    strCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    document.cookie = strCookie;
  }
}


function printlogout()
{
        var  ck = document.cookie;
        var login = ck.indexOf("GSACCOUNTCookie=");
        if(login<0){
                login = ck.indexOf("GSCustomerID=");
        }
        if(login>0){
                document.getElementById('logoutlink').innerHTML= "<A href=https://www.genscript.com/ssl-bin/account/logout class=l1>Log Out</A>"
        }

	var access = getCookie("GSAccessSession");
	if(!access){
		Stamp = new Date();
		access = Stamp.getTime();
		var randomnumber=Math.floor(Math.random()*100001)
        	access = access.toString().concat(randomnumber.toString());
	}

	//alert(access);

	saveCookie("GSAccessSession", access, 3000, "/", "genscript.com"); 
	saveCookie("GSReferer", document.referrer, 1, "/", "genscript.com");	

	var referrer = document.referrer; 

	xmlHttp=GetXmlHttpObject()
	if(xmlHttp != null && access){
		var url="http://www.genscript.com/cgi-bin/promotion/accesslog";
 	       	xmlHttp.open("GET",url,true)
        	xmlHttp.send(null)
	}
}



//function GetXmlHttpObject()
//{
//	var objXMLHttp=null
//	if (window.XMLHttpRequest)
//	{
//		objXMLHttp=new XMLHttpRequest()
//	}
//	else if (window.ActiveXObject)
//	{
//		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
//	}
//	return objXMLHttp
//}

function GetXmlHttpObject()
{
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
		return objXMLHttp;
	}
	else if (window.ActiveXObject)
	{
		var axtype = ["Microsoft.XMLHTTP","Msxml2.XMLHTTP"];
		for(var i=0; i<axtype.length; i++)
		{
			try {
					objXMLHttp=new ActiveXObject(axtype[i]);
					return objXMLHttp;
			}catch(oError)
			{
				// nothing do;
			}
		}
	}
}

