var myActualCookie = ""

function readCookie(cookieName) {
   var ca = document.cookie.split(';');
   var nameEQ = cookieName + "=";
   for(var i=0; i < ca.length; i++) {
    	var c = ca[i];
      while (c.charAt(0)==' ') 
			    c = c.substring(1, c.length); //delete spaces
      if (c.indexOf(nameEQ) == 0) { 
					myActualCookie = c.substring(nameEQ.length, c.length);
					myActualCookie = myActualCookie.replace(/%2A/g, "*");
					myActualCookie = myActualCookie.replace(/%2C/g, ",");
					myActualCookie = myActualCookie.replace(/%28/g, "(");
					myActualCookie = myActualCookie.replace(/%29/g, ")");
			}
   }
}

function readDirectory() {
   var cookie = myActualCookie.split("*")	 
	 if (cookie.length > 0)
   		return cookie[0]
	 else 
	    return null;		
}

function readInternetID() {
   var cookie = myActualCookie.split("*")	 
	 if (cookie.length > 1)
   		return cookie[1].substring(1,cookie[1].length)
	 else 
	    return "";		
}

function readOldCookie() {
   var cookie = myActualCookie.split("*")	 
	 if (cookie.length > 1)
   		return cookie[2].substring(1,cookie[2].length)
	 else 
	    return "";		
}

function checkCookie() {
	readCookie("BookingDetails");
	var MyInternetID = readInternetID()
	var MyOldCookie = readOldCookie()
	var MyDirectory = readDirectory()
	if (MyOldCookie != "") {
	   // old cookie exists
		 window.location.href = "../Validation.php?CookieType=Old&MyInternetID="+MyDirectory
	} else if (MyDirectory != "") { 	 
	   // new cookie exists
		 window.location.href = "../Validation.php?CookieType=New&MyDirectory="+MyDirectory+"&MyInternetID="+MyInternetID
	}				

}