// JavaScript Document

//sets cookie code 
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}
//end set cookie code 


// pass / no pass cookie set 
// URL to pass throught should be placed here as well
function passCookie(){
	ageVerification=getCookie('ageVerification');
	ageVerification=("pass");
	setCookie('ageVerification',ageVerification,365);
	window.location = "home.html"
	//alert ("You clicked pass"); 
	
}

function noPassCookie(){
	ageVerification=getCookie('ageVerification');
	ageVerification=("nopass");
	setCookie('ageVerification',ageVerification,365);
	window.location = "nopass.html"
	//alert ("You clicked nopass"); 
	
}
// end pass / no pass cookie set 




// redirect with cookie
// first one is used on index
function checkCookie()
{
ageVerification=getCookie('ageVerification');
if (ageVerification == "pass")
  {
  	window.location = "home.html"
  	//alert('pass');
  }
if (ageVerification == "nopass")
  {
  	window.location = "nopass.html"
  	//alert('no pass');
  }
else {
	//alert('nothing has happened');
  }
}


// used on protected pages
function checkCookieProtect()
{
ageVerification=getCookie('ageVerification');
if (ageVerification == "nopass")
  {
  	window.location = "nopass.html"
  	//alert('no pass2');
  }
if (ageVerification == "") {
	window.location = "index.html"
	//alert('No Cookie Data; go to ageVerification');
  }
else {
	//alert('stay on page');
  } 
}


// used to QA; deletes local cookies with this function
function deleteAllCookies()
{
	if (document.cookie)
	{
		var today=new Date;
		today.setYear(today.getYear()-10);
	
		var cookies=document.cookie.split(";");
		var i=0;
		for (i=0; i<cookies.length; i++)
		{
			document.cookie=cookies[i]+" ;expires="+today.toGMTString();
		}
		alert("removing "+i+" cookies");
	}
}
