// JavaScript Document
function $(id){return document.getElementById(id);}
function isIE() { // Private method 
  return navigator.userAgent.indexOf("MSIE") > -1;
}
function deftDomReady(onLoad)
{
	if (document.addEventListener)
		document.addEventListener("DOMContentLoaded", onLoad, false);
	else
		onLoad();
}
deftDomReady(function()
{
	//setTimeout("PrepareRolloverImages();",250);
});

function recurs(p1) {
  p1--;
  if (p1 < 0) return // exit condition
  setTimeout("recurs("+p1+")",10000);
  //window.status='recurs function running \t \t p1 = ' + p1 + ' \t \t Get_Cookie("Sv_Exp") == "1" = ' + (Get_Cookie("Sv_Exp") == "1");
  //alert('p1=' + p1)
  if ((p1 == 0) && (!Get_Cookie("Sv_Exp") == "1"))  {decline('N');} // do condition
}

function createDiv() {
  var pageloads = Get_Cookie('pageloads'); 
  if (pageloads) pageloads = parseInt(pageloads) + 1; 
  else pageloads = 1;
  var showsurvey = new Boolean();
  showsurvey = !((Get_Cookie("Sv_Exp") == "1") || (pageloads < 4))
  var winW = 630
	if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") { winW = window.innerWidth; }
		 if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth; }
		}
		var divTag = document.createElement("div");
		divTag.id = "pbcontainer";
		document.body.appendChild(divTag);
		if (!showsurvey) {
			document.getElementById("pbcontainer").style.visibility="hidden";
			}
		var divTag2 = document.getElementById("pb");
		divTag2.style.left = (winW/2)-260 +"px";
		if (!showsurvey) { 
			document.getElementById("pb").style.visibility="hidden"; }
		else { document.getElementById("pb").style.visibility="visible";
		}
  /*
  var debugmsg = '---------------------------- Debug Message ----------------------------\r';
  debugmsg = debugmsg + '\r' + 'pageloads\t \t \t \t = \t' + pageloads ;
  debugmsg = debugmsg + '\rpageloads < 4\t \t \t  \t = \t' + (pageloads < 4);
  debugmsg = debugmsg + '\rGet_Cookie("Sv_Exp") == "1"\t  \t \t = \t' + (Get_Cookie("Sv_Exp") == "1");
  debugmsg = debugmsg + '\rGet_Cookie("Sv_Exp") == "1" && pageloads < 4 \t = \t' + ((Get_Cookie("Sv_Exp") == "1") && (pageloads < 4));
  debugmsg = debugmsg + '\rGet_Cookie("Sv_Exp") == "1" || pageloads < 4 \t = \t' + ((Get_Cookie("Sv_Exp") == "1") || (pageloads < 4));
  debugmsg = debugmsg + '\rshowsurvey (Boolean) \t \t \t = \t' + showsurvey;
  alert(debugmsg); 
  */
  Set_Cookie('pageloads', pageloads);
  recurs(4);
  }
function decline(choice,nummin) {
if (choice == "Y") {
	Set_Cookie_By_Min("Sv_Exp","1",nummin,"/");
	document.getElementById("pbcontainer").style.visibility="hidden";
	document.getElementById("pb").style.visibility="hidden";
	}
else if (choice == "N") {
	document.getElementById("pbcontainer").style.visibility="visible";
	document.getElementById("pb").style.visibility="visible";
	}
}
function Set_Cookie_By_Min( name, value, expires, path, domain, secure ) {
var today = new Date();
today.setTime( today.getTime() );
	if ( expires ) { expires = expires * 1000 * 60; }
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" ); }
function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	for ( i = 0; i < a_all_cookies.length; i++ )
	{ a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ) { cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') ); }
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) { return null; }
}
