web2js = {};


web2js.URL = window.location;


web2js.cookie = {};
// returns the value for the given cookie name
web2js.cookie.ONE_YEAR = 365;

web2js.cookie.read = function (strNme) 
{
	var objDoc = document.cookie; // get all the cookies associated with this document
	var iPosOfEquSgn = objDoc.indexOf(strNme + "="); 
	if( iPosOfEquSgn == -1) return null; // no cookie with that name found
	iPosOfValStart = iPosOfEquSgn +1; // eat the equal sign
	iPosOfValStart += strNme.length; // move the start position to the end of the cookie name
	var iPosOfValEnd = objDoc.indexOf(";",iPosOfValStart); // search for the end position starting at start index
	if( iPosOfValEnd != -1)
	{ 
		// return cookie value
		return objDoc.substring( iPosOfValStart , iPosOfValEnd ); 
	}
	else // the is the last cookie 
	{ 
		return  objDoc.substring( iPosOfValStart ); 
	}
}

web2js.cookie.make = function ( strNme , strVal , iDaysToLive , strPath , strDomain , strSecure) 
{
	if(strNme == null || strVal == null)
	{
		alert("Cookie name must be given");
		return; 
	}
	var strExpires = "" // by default expires is not set
	if(iDaysToLive)
	{// if iDay is not null
		var date = new 	Date();// create a new date
		var toDay = date.getTime(); // get todays date
		strExpires = toDay + (iDaysToLive * 24*60*60*1000); // add todays date to the number of days this cookie should die
		date.setTime(strExpires); // use the seTime method and pass it expire date
		strExpires = date.toUTCString(); // get the  correct cookie date represenation
		strExpires = ";expires=" + strExpires; // format the expire's name/value pair  and dimlinter it by a sec";"
	}
	
	strPath = (strPath != null) ? ";path=" + strPath : ";path=/" // format the path's name/value pair
	strDomain = (strDomain != null) ? ";domain=" + strDomain : "" // format domain's name/value pair
	strSecure = (strSecure != null) ?  ";secure=" + strSecure : "" // format secure' name/value pair
	document.cookie = strNme + "=" + strVal +";"+ strExpires + strPath	+ strDomain + strSecure // append this new cookie to the document.cooies property
}

//	remove the specified cookie from	the client's system
web2js.cookie.eat = function (strNme,strPath,strDomain)
{
	makeCookie(strNme,"",-1,strPath,strDomain) //Call the save cookie function and pass it -1 for the days parameter

}

