//simone 2.0

//cookie functions
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/;domain=bestpricecruises.com";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}


//Check for first visit and play first time audio if it is the first visit
function check_visit(){
	if (readCookie('BPCreturn') == 'true'){
		//check for updates
		checkUpdates();
		//update the last visit cookie
		newLastVis();
	}else{
		//alert("no cookie");
		sayAudio('welcome1');
		createCookie('BPCreturn','true',3650);
		//update the last visit cookie
		newLastVis();
	}
}

//tell us when the scene is loaded
function vh_sceneLoaded(sceneIndex){
	check_visit();
}

//check lastupdate.js against BCPlastvis
function checkUpdates(){
   //get last visit
   lastvis = readCookie('BPClastvis');
   if (lastvis == null){
   	lastvis = "01-01-1980";
  	}
   lastsplit = lastvis.split("-");
   lastvisit = Date.UTC(lastsplit[2],lastsplit[0],lastsplit[1]);
   
   //check top ten deals
   lastTTUp = lastTopTen.split("-");
   lastTTUpdate = Date.UTC(lastTTUp[2],lastTTUp[0],lastTTUp[1]);
   
   //if the top ten is newer tell the customer
   if (lastvisit < lastTTUpdate){
      sayAudio('newhotdeals01');
   }
     
}

//update BPClastvis with todays date
function newLastVis(){
	eraseCookie('BPClastvis');
	today = new Date();
	day = today.getDate();
	month = today.getMonth()+1;
	year = today.getFullYear();
	lastvis = month+"-"+day+"-"+year;
	createCookie("BPClastvis",lastvis,3650);
}
