// JavaScript Document

//Creat cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		//date.setTime(date.getTime()+(days*24*60*60*1000));
		date.setYear(date.getFullYear());
		date.setDate(date.getDate()+days);
		date.setHours(23,59,59);
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}
//Search for cookie by name
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;
	
}
//Use read cookie to verify the cookie
function checkCookie(){
	//set default expiration in days
	var days = 3;
	
	//set today
	var today = new Date();
	today.setFullYear(today.getFullYear());
	today.setDate(today.getDate());
	
	//set final
	var final = new Date();
	final.setFullYear(2009,2,13);
	final.setHours(0,0,0);
	
	//set two days out
	var two = new Date();
	two.setFullYear(2009,2,11);
	two.setHours(0,0,0);
	
	//set one day out
	var one = new Date();
	one.setFullYear(2009,2,12);
	one.setHours(0,0,0);
	
	//check if popup should cease
	if(today.getTime() < final.getTime()){
		//check if two days
		if(today.getMonth() == two.getMonth() && today.getDate() == two.getDate()){
			var days = 2;
		}
		//check if one day
		if(today.getMonth() == one.getMonth() && today.getDate() == one.getDate()){
			var days = 1;
		}
		//Check for cookie
		var x = readCookie('popupcookie');
		if (!x) {
			//If cookie is not there pop window and createCookie
			show();
			createCookie('popupcookie','popup',days);
		}
	} else {
		eraseCookie('popupcookie');
	}
}
//Show lightbox function called if cookie is not there
function show(){
	tb_show("", "?TB_inline=true&inlineId=popContent&height=350&width=712&modal=false", null);
}
//Erase cookie
function eraseCookie(name) {
	createCookie(name,"",-1);
}