var cookieName				='popUpTracker';
var OPACITY_BACKGROUND_SHOWN=0.6;
var OPACITY_POPUP_SHOWN		=1.0;
if(debug=false){
	document.write('PopUp Debug Window:<BR>\nShow On: '+POPUP_SHOW_ON+'<BR>\nWhen: '+POPUP_WHEN+'<BR>\nFADE:'+POPUP_FADE);
}
	
function hideIt(){
	popupStatuses['UserPopUp']=0;
	if(POPUP_FADE==1){
		$("#backgroundPopup")	.fadeTo("slow",0);
		$("#popUpWindow")		.fadeTo("slow",0);
	}
	document.getElementById("popUpWindow").style.display='none';
	document.getElementById("backgroundPopup").style.display='none';
}
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=/";
}
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);
	alert('Deleted Cookie:\n\n'+name);
}
function showIt(){
	//alert('showIt');
	popupStatuses['UserPopUp']=1;
	var cookieContents = readCookie(cookieName);
	if (POPUP_WHEN=="everyTime"){
	//$("p:first","div.enterleave").text("We are now showing the Pop Up everytime");
	//POPUP DEBUGGING	
	}	
	var date = new Date();	
	var unixTime=(date.getTime()+(0*24*60*60*1000));
	//alert('showInt\n\nShow On: '+POPUP_SHOW_ON+'\nWhen: '+POPUP_WHEN+'\nCurrent Time: '+unixTime+'\n\nCookie Time: '+cookieContents+'\nFADE:'+POPUP_FADE);
	if((
		( (POPUP_WHEN=="everyTime") )||
		( (POPUP_WHEN=="onceDaily")		&& (cookieContents<unixTime)	)||
		( (POPUP_WHEN=="oncePerYear")	&&(cookieContents<unixTime)  		)
	)&&	(POPUP_SHOW_ON==='exit')	){
		//alert('showing Pop Up');
		if(POPUP_FADE==1){
			//alert('fading to show');
			$("#backgroundPopup")	.fadeTo("slow",OPACITY_BACKGROUND_SHOWN);
			$("#popUpWindow")		.fadeTo("slow",OPACITY_POPUP_SHOWN);
		}
		document.getElementById("backgroundPopup").style.display='block';				
		document.getElementById("popUpWindow").style.display='block'		;			

		if(POPUP_WHEN=="onceDaily"){			
			expireOn=unixTime+(1   *24*60*60*1000);			
			createCookie(cookieName,expireOn,1);		
		}else if(POPUP_WHEN=="oncePerYear"){
			expireOn=unixTime+(365*24*60*60*1000);
			createCookie(cookieName,expireOn,365);
		}	
	}else if (POPUP_WHEN!="everyTime"){
		var cookieDate = new Date();		
		cookieDate.setTime(cookieContents);		
		//$("p:first","div.enterleave").text("Found Cookie.  Will Not show Pop Up Until \n"+cookieDate.toGMTString());
		//POPUP DEBUGGING	
	}
}
function defaultPopUpLoad(){
	alert('defaultPopUpLoad');
	document.getElementById("backgroundPopup").style.opacity	=OPACITY_BACKGROUND_SHOWN;
	var cookieContents = readCookie(cookieName);
	var date = new Date();	
	var unixTime=(date.getTime()+(0*24*60*60*1000));
	//alert('defaultPopUpLoad\n\n'+'When: '+POPUP_WHEN+'\nShow On: '+POPUP_SHOW_ON+'\nCurrent Time: '+unixTime+'\n\nCookie Time: '+cookieContents+'\nFADE:'+POPUP_FADE);
	if(POPUP_SHOW_ON=='load'){
		//alert('default Page load\n'+'When: '+POPUP_WHEN+'\nShow On: '+POPUP_SHOW_ON+'\nCookie:'+cookieContents+'\nunixTime:'+unixTime);
		if( (cookieContents<unixTime)||(POPUP_WHEN=="onceDaily") ){
			//alert('Showing POp on Load ');
			if(POPUP_FADE==1){
				alert('defaultPopUpLoad fading');
				$("#backgroundPopup")	.fadeTo("slow",OPACITY_BACKGROUND_SHOWN);
				$("#popUpWindow")		.fadeTo("slow",OPACITY_POPUP_SHOWN);
			}
			document.getElementById("backgroundPopup").style.display='block';				
			document.getElementById("popUpWindow").style.display='block'		;	
		}
		if(POPUP_WHEN=="onceDaily"){			
			//alert('creating Daily Cookie ');
			expireOn=unixTime+(1   *24*60*60*1000);			
			createCookie(cookieName,expireOn,1);		
		}else if(POPUP_WHEN=="oncePerYear"){
			//alert('creating Yearly Cookie ');
			expireOn=unixTime+(365*24*60*60*1000);
			createCookie(cookieName,expireOn,365);
		}	
	}
}
function setAllOpacity(id,to){	
	//alert('setAllOpacity\n'+id+'\n'+to);	
	//document.getElementById(id).style.-moz-opacity	=to;	
	document.getElementById(id).style.filter=alpha(opacity=to);
	document.getElementById(id).style.opacity		=to;
}
