/**
 * This function was created by the agency that provided the flash introduction movie. 
 * It is called from the introduction video when you agree to the terms and conditions.
 * */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		// this was delivered by cossette as (days*24*60*60*1000), but we are modifing a 'day' to be 1 hour instead.
		date.setTime(date.getTime()+(days*1*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/**
 * This function was created by the agency that provided the flash introduction movie. 
 * It is called from the introduction video to know if it will display the warning page or just
 * go right into the animation.
 * 
 * The function has been commented out because legal decided that they want a user to agree to the conditions
 * every time they visit the site regardless of the cookie settings.
 * */
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;
}

/**
 * This function was created by the agency that provided the flash introduction movie. 
 * It is called from the introduction video.
 * */
function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
 * This function was created by the agency that provided the flash introduction movie. 
 * It is called from the introduction video at the end of the animation.
 * */
function proceed_to_page(url){
	window.location = url;
}


/**
 * This function was created by the Amour development team and it is a close match to the readCookie function above.
 * It is called from the checkForCookie function below to check if the amour cookie exists on a clients browser.
 * It is also called from the showPage.js to check if our cookie exists.
 * */
function siteCookieExists() {
	var nameEQ = "amour_cookie=";
	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 true;
		}
	}
	return false;
}

/**
 * This function was created by the Amour development team.
 * It is called from the checkForCookie function below to check if the clients browser has cookies enabled.
 * It will create a test cookie on the page and try to read it.  If it can't read the cookie it creates, it 
 * assumes cookies are disabled.
 * */
function areCookiesEnabled(){
	var cookieEnabled=(navigator.cookieEnabled)? true : false

	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="testcookie"
		cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
	}
	return cookieEnabled;
}


/**
 * This function was created by the Amour development team.
 * Check to see if cookies are enabled... if they are not, we hide the page contents and show a div that contains a message about needing cookies.
 * If they have cookies enabled, check for our cookie.  If our cookie does not exist, redirect the user back to the landing page, but pass in the 
 * menu id, extension id, and the asset (if it exists) of the page they are trying to view in the query string.  The introduction page will redirect them back
 * to where they were trying to go after the user agrees to the legal on on the landing page.
 * */
function checkForCookie(menuid, vgnextoid, assetuid){
	if (!areCookiesEnabled()) {
		document.getElementById('gridPortalPage').style.display = 'none';
		document.getElementById('gridPortalPageNoCookie').style.display = 'block';
	}else{
		if (!siteCookieExists()){
			window.location = "/portal/site/amour?menu=" +menuid+ "&vngextoid=" + vgnextoid + "&assetuid=" + assetuid;
		}
	}
	return false;
}
