function set_cookie( name, value, expires) 
{

var domain = ".zapak.com";
var today = new Date();
today.setTime( today.getTime() );

if (expires)
expires = expires * 1000 * 60 * 60 * 24;


var expires_date = new Date(today.getTime() + (expires));
document.cookie = name + "=" +escape( value ) +
((expires) ? ";expires=" + expires_date.toGMTString() : "")+
((domain) ? ";domain=" + domain : "") 
}

function get_cookie(name) 
{
var start = document.cookie.indexOf(name + "=");
var len = start + name.length + 1;
if ((!start) && (name != document.cookie.substring(0, name.length)))
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf(";", len);
if (end == -1) 
end = document.cookie.length;
return unescape( document.cookie.substring(len, end));
}

function delete_cookie(name) {
	var path = '/';
	var domain = ".zapak.com";
	if ( get_cookie( name ) ) document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function switch_www()
{
	if(get_cookie('zv')) 
		delete_cookie('zv');
	window.location.href = WWW_SERVER_URL;
}


function getXmlHttp_RequestObject() 
{	
	if (window.XMLHttpRequest) 
	{		
		return new XMLHttpRequest(); //Not IE	
	} 
	else if	(window.ActiveXObject) 
	{		
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE	
	} 
	else 
	{		
		//Display your error message here. 		
		//and inform the user they might want to upgrade		
		//their browser.		
		alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to Firefox.");	
	}
} 

function egoupdate()
{
	var receive_Request = getXmlHttp_RequestObject();

	if (receive_Request.readyState == 4 || receive_Request.readyState == 0) 
	{

		//True explicity sets the request to asyncronous (default).		
		receive_Request.open("POST", 'loginstatus.php', true);		
		receive_Request.onreadystatechange = handlelogin; 		

		//Make the actual request.		
		receive_Request.send(null);	
	}



	function handlelogin()
	{    
		if (receive_Request.readyState == 4) 
		{
			var uid = receive_Request.responseText;
			if(uid != ''){
				document.getElementById('login').innerHTML = '<strong>Hi '+uid+'!';
				document.getElementById('signinout').innerHTML = '<a href=\"http://'+ZPK_DOMAIN_PREFIX+'secure.zapak.com/zlogout.php?redirect='+LITE_SERVER_URL+'\">Signout</a></strong>';
			}else{
				document.getElementById('signinout').innerHTML = '<a href=\"http://'+ZPK_DOMAIN_PREFIX+'lite.zapak.com/login.php?redirect='+LITE_SERVER_URL+'\">Sign in</a></strong>';
			}
		}
	}			
}			


