/**
 * JavaScript: Cookie handling scripts for TBXOnline. 
 * @version: 1.0
 * @author: Buddhika Nalin Fernando
 * Date created: 23/01/2007
 * Date modified: 23/01/2007
 * Copyright: Codegen International (Pvt) Ltd.
 */


/**
 * Extracts the values of a given Cookie.
 * This function searches to find a cookie with the given name. If exists it will be returned. 
 * Else, null will be returned.
 * @param   p_sName       	Name of the Cookie.<br>
 * @see         setCookie().
 */
function getCookie(p_sName)
{
	if (document.cookie.length>0)
	{
		iStartPos=document.cookie.indexOf(p_sName + "=")
		if (iStartPos!=-1)
		{ 
			iStartPos += (p_sName.length + 1 );
			iEndPos=document.cookie.indexOf(";",iStartPos)
			if (iEndPos==-1)
			{
				iEndPos=document.cookie.length
			}
			return unescape(document.cookie.substring(iStartPos,iEndPos))
		} 
	}
	return "";
}


/**
 * Creates or updates a Cookie.
 * This function searches to find a cookie with the given name. If exists it will be returned. 
 * Else, null will be returned.
 * @param   p_sName       	Name of the Cookie.<br>
 * @param   p_sValue       	Value of the Cookie.<br>
 * @param   p_iExpireDays  	No of days in which the Cookie is going to expire.
 							Can leave as null, if no need to expire<br>
 * @see         getCookie().
 */
function setCookie(p_sName,p_sValue,p_iExpireDays)
{
	var sExpiryDate="";
	if(p_iExpireDays!=null)
	{
		var oExpiryDate=new Date()
		oExpiryDate.setDate( oExpiryDate.getDate() + p_iExpireDays )
		sExpiryDate = ";expires="+oExpiryDate.toGMTString();
	}
	document.cookie=p_sName+ "=" +escape(p_sValue)+sExpiryDate;
}

 /**
 * Creates or updates a Cookie.
 * This function searches to find a cookie with the given name. If exists replace the cookie with the new value.
 * Else, creates new one.
 * @param   city            Value for the city.
 * @param   checkinDate     Value for the checkin date.
 * @param   nights          Number of nights.
 * @param   adultRooms      Number of adult rooms.
 * @param   childRooms      Number of child rooms.
 * @param   infantRooms     Number of infant rooms.
 * @param   childAges       Appended values for ages of the children.
 */
function setPageCookie( city, checkinDate, nights, adultRooms, childRooms, infantRooms, childAges, roomNumber )
{
    var searchCriteria = city + "," + checkinDate + "," + nights + "," + adultRooms + "," + childRooms + "," +infantRooms;
    setCookie("c_searchCriteria_" + roomNumber, searchCriteria, 31);
//    document.cookie="c_searchCriteria"+ "=" +escape(searchCriteria)+";expires=-1";
    setCookie("c_childAndInfantAges_" + roomNumber, childAges, 31);
}

function setMultyCenterCookies(city, checkinDate, nights, centerNo, hotelName)
{
    var criteria = city + "," + checkinDate + "," + nights + "," + hotelName;
    setCookie('centerCriteria' + centerNo, criteria, 31);
}

function setPassengerDetails(adultRooms, childRooms, infantRooms, childAges)
{
    var criteria = adultRooms + "@" + childRooms + "@" +infantRooms + "@" + childAges;
    setCookie('multyCenterAges' , criteria, 31);
}

