//
//Internal function to return the decoded value of cookie.
//
function getCookieVal(offset)
{	
	var endstr=document.cookie.indexOf(";",offset);
	if (endstr == -1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


//
//function to return the value of cookie specified by "name"
//
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 getQueryString(name);
}


//function to create or update a cookie.
//
//	name - String object containing the cookie name.
//	value - String object containing the cookie value. May contain any valid string characters.
//	[expires] - Date object containing the expiration date of the cookie. If ommitted or null, expires the cookie at the end of the current session.
//	[path] - String object indication the path for which the cookie is valie. If omitted or null uses the domain of the calling document.
//	[domain] - String object indication the domain for which the cookie is valie. If omitted or null uses the domain of the calling document.
//	[secure] - Boolean (true/false) value indication whether cookie transmission requires a secure channel (HTTPS).
//
//The first two parameters are required. The other, if supplied, must be passed in the order listed above.
//To omit unused optional field, use null as a place holder.
//For example, to call setCookie using name, value and path you would code:
//	setCookie ("myCookieName", "myCookieValue", null, "/");
//Note that trailing omitted prameters do not require a placeholder.
//
//To set a secure cookie for path "/myPath", that expires after the current session, you might code:
//	setCookie (myCookieVar, CookieValueVar, null, "/myPath", null, true);
//
function setCookie (name, value)
{	
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? agrv[3] : null;
	var domain = (argc > 4) ? agrv[4] : null;
	var secure = (argc > 5) ? agrv[5] : null;
	document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + toString(expires))) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}


//
//Function to delete a cookie.
//
function deleteCookie (name)
{	
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//
//Function to retrive query string value.
//
function getQueryString(vQryName)
{
	var vUrl = document.URL;
	var idxQryStrt = vUrl.indexOf("?",0);
	var urlLen = vUrl.length;
	var qryStr = vUrl.substring(idxQryStrt+1,urlLen);
	var vArg = vQryName + "=";
	var argLen = vArg.length;
	var vStartOffset = qryStr.indexOf(vArg,0);
	if (vStartOffset==-1) return null;
	var qVal = qryStr.substring(vStartOffset+argLen);
	var vSaparator = "&";
	if (qVal.substring(0,1)=="'") vSaparator="'";
	if (qVal.substring(0,1)=='"') vSaparator='"';
	if (qVal.substring(0,1)=="'") qVal=qVal.substring(1);
	if (qVal.substring(0,1)=='"') qVal=qVal.substring(1);
	var vEndOffset = qVal.indexOf(vSaparator,0);
	if (vEndOffset!=-1) qVal=qVal.substring(0,vEndOffset);
	return unescape(qVal);
}

//
//Function to write refresh tag.
//
function refreshX()
{
	if (getCookie("loggedIn")==null) document.write('<META HTTP-EQUIV="REFRESH" CONTENT="0">');
	return true;
}