function setCookie(c_name,value,expiredays)
{var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

function checkCookie()
{
	lscode=getCookie('lscode');
	


	
	if (lscode == null || lscode == "")
	{
		var query = window.location.search.substring(1);
		
				
		if (query == null || query == '' || query.indexOf('lscheck') < 0)
		{
		//	alert("query is null or volusions");
			window.location = "http://www.labsphereonline.com/lscheck.php";
			return;
		}
				
		// came back from lscheck and unknown
		if (query.indexOf('lscheck=unknown') > -1)
		{
			//alert("the cookie failed and is set to invalid");
			setCookie('lscode','invalid', 1);	
			window.location = "http://www.labspherestore.com/v/unknown_ip.html";
			return;
		}
		
		// came back from lscheck:
		if (query.indexOf('lscheck=87532') > -1)
		{
			//alert("the cookie failed and is set to invalid");
			setCookie('lscode','invalid', 1);	
			window.location = "http://www.labspherestore.com/v/online.html";
			return;
		}
		
			
		//var pos = query.indexOf('=');
		//if (pos > 0) {
			//var key = query.substring(0,pos);
			//var val = query.substring(pos+1);
			
		
			
		//alert("key = [" + key + "] and val = [" + val + "]");
			//if (key == "a" && val == "97893") {
		setCookie('lscode','US97893', 1);
		window.location = "http://www.labspherestore.com/";
		//alert("the cookie is set to valid");
		return;
			//}
			//else
			//{
			//	setCookie('lscode','invalid', 1);	
			//	window.location = "http://www.labspherestore.com/v/online.html";
			//	return;
			//}
		
		
		// the cookie and URL were both null
	//	setCookie('lscode','invalid', 1);	
		//window.location = "http://www.labspherestore.com/v/online.html";
	//	return;

	}
	else
		if (lscode !="US97893")
			window.location = "http://www.labspherestore.com/v/online.html";
			
	
	return "ok";	
}