//get & parse cookies for date init

var dummy, iata, gstdir, expDate = new Date();
expDate.setTime(expDate.getTime() + 365 * 24 * 60 * 60 * 1000); // one year

var errorMsg = "<font class='redcontentfont'>Unfortunately you appear to have Cookies blocked on your browser. This will perhibit you from entering our Adviser section. If you would like to gain access you will have to turn Cookies back <strong>on</strong> using your browser options. For further information on how to do this, please refer to www.aboutcookies.org</font>";


function setCookie(isName,isValue,dExpires){
	document.cookie = isName + "=" + isValue + ";expires=" + dExpires.toGMTString();
}

function getCookie(isName){
	var cookieStr, startSlice, endSlice, isData, isValue;
	cookieStr = document.cookie;
	startSlice = cookieStr.indexOf(isName + "=");
	if (startSlice == -1) {
	 return false;
	}
	endSlice = cookieStr.indexOf(";", startSlice+1);
	if (endSlice == -1) {
		endSlice = cookieStr.length; 
	}
	isData = cookieStr.substring(startSlice, endSlice);
	isValue = isData.substring(isData.indexOf("=") + 1, isData.length);
	return isValue;
}

function init(){
	setCookie('test', '1', expDate);
	if (!getCookie('test')){
		 document.getElementById('noCookie').style.display = '';
		 document.getElementById('noCookie').innerHTML = errorMsg;
	}
}

function parseCookies()  {
	var ArvSelM = 0, ArvSelD = 0, ArvSelY = 0, DepSelM = 0, DepSelD = 0, DepSelY = 0, adult = 0,
	child = 0, property = '', cartype = '1', unit_type = '', unitType = 0, iata = '', cookieName, cookieValue, thisCookie, cData;
	dummy = init;
	gstdir = '';  //do not use var in a function so this variable is global
	if (document.cookie != "") {
		thisCookie = document.cookie.split("; ");
		for (i=0; i < thisCookie.length; i++) {
			cData = thisCookie[i].split('=');
			cookieName = cData[0];
			cookieValue = cData[1] ? cData[1] : null;
			// cookieName = cookieName.toLowerCase();
// 			cookieValue = cookieValue.toLowerCase();
			if (cookieName=="ArvSelM") {
				 ArvSelM = parseInt(cookieValue) - 1;
				 }
			if (cookieName=="DepSelM") {
				 DepSelM = parseInt(cookieValue) - 1;
				 }
			if (cookieName=="ArvSelD") {
				 ArvSelD = parseInt(cookieValue) - 1;
				 }
			if (cookieName=="DepSelD") {
				 DepSelD = parseInt(cookieValue) - 1;
				 }
			if (cookieName=="ArvSelY") {
				 ArvSelY = parseInt(cookieValue);
				 }
			if (cookieName=="DepSelY") {
				 DepSelY = parseInt(cookieValue);
				 }
			if (cookieName=="adult") {
				 adult = parseInt(cookieValue) - 1;
				 }
			if (cookieName=="child") {
				 child = parseInt(cookieValue);
				 }
			if (cookieName=="unit_type") {
				 unit_type = cookieValue;
				 switch(unit_type)  {
					case "One Bedroom":
						unitType = 0;
						break;
					case "Two Bedroom":
						unitType = 1;
						break;
					case "Studio":
						unitType = 2;
						break;
					default:
						break;
					}
				 }
			if (cookieName=="cartype") {
				 cartype = parseInt(cookieValue);
				 }
			if (cookieName=="property") {
				 property = parseInt(cookieValue);
				 }
			if (cookieName=="iata") {
				 iata = cookieValue;
				 }
			if (cookieName=="gstdir") {
				 gstdir = cookieValue;
				 }
			}
	 }
}

