window.onscroll = winscroll;
var surveyIntervalId = "";

function winscroll()
{
 lightbox = document.getElementById('surveyshow');
 overlay = document.getElementById('surveyhide');
 //shad = document.getElementById('shadow');

 if (navigator.appName != 'Netscape' && lightbox.style.display == "inline")
 {
	surveylbRender();
 }
 
}

function openSurveyLB()
{ 
 createCookie("surveydone","yes","30");
 document.getElementById('surexturl').href = "javascript:openNewSurWin('http://www.surveymonkey.com/s/3FF6BPK')";

 lightbox = document.getElementById('surveyshow');
 overlay = document.getElementById('surveyhide');
 //shad = document.getElementById('shadow');
 surveylbRender(); 
} 

function openNewSurWin(url)
{
 closeSurveyLB();
 window.open(url,"Survey","location=1,status=1,scrollbars=1,width=800,height=600");
 /*
 if (navigator.appName != 'Netscape')
 {
  window.opener="self";
  window.open('','_parent','');
  window.close();
 }
 else{
 self.close();
 }
 */
}

function surveylbRender()
{
 if (navigator.appName == 'Netscape')
 {
	lightbox.style.position = "fixed";
	lightbox.style.top = "30%";
	lightbox.style.left = "30%";
	lightbox.style.display = "block";
	lightbox.style.width = "500";
	lightbox.style.height = "335";

	overlay.style.position = "fixed";
	overlay.style.top = "0";
	overlay.style.left = "0";
 }
 else
 {	
	lightbox.style.position = "absolute";
	lightbox.style.top = lightbox.offsetParent.scrollTop + lightbox.offsetParent.offsetHeight - 570;
	lightbox.style.left = "380";
	lightbox.style.styleFloat="left";
	lightbox.style.display = "inline";
	lightbox.style.width = "500";
	lightbox.style.height = "275";

	overlay.style.position = "absolute";	
	overlay.style.top = overlay.offsetParent.scrollTop;
	overlay.style.left = overlay.offsetParent.scrollLeft;

 } 

 lightbox.style.background = "#FFFFFF";
 lightbox.style.zIndex = "70007";
 lightbox.style.border="1px solid #cccccc";

 overlay.style.width = "100%";
 overlay.style.height = "100%"; 
 overlay.style.background = "#dedede"; 
 overlay.style.filter = "alpha(opacity=70)";
 overlay.style.opacity = "0.7";
 overlay.style.mozOpacity = "0.7"; 
 overlay.style.display = 'inline';
 overlay.style.styleFloat="left";
 overlay.style.zIndex = "70006";
 document.getElementsByTagName("body")[0].appendChild(overlay);
}

function closeSurveyLB()
{
 document.getElementById('surveyshow').style.display = 'none';
 document.getElementById('surveyhide').style.display='none';
// document.getElementById('shadow').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);
}



function createTimeCookie(name,value,days)
{
    if (days)
    {
		var date = new Date();
		date.setTime(date.getTime()+(days*60*1000));
		var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function timestamp_class(this_current_time, this_start_time, this_end_time, this_time_difference)
{ 
		this.this_current_time = this_current_time;
		this.this_start_time = this_start_time;
		this.this_end_time = this_end_time;
		this.this_time_difference = this_time_difference;
		this.GetCurrentTime = GetCurrentTime;
		this.StartTiming = StartTiming;
		this.EndTiming = EndTiming;
}

//Get current time from date timestamp
function GetCurrentTime()
{
	var my_current_timestamp;
	my_current_timestamp = new Date();		//stamp current date & time
	return my_current_timestamp.getTime();
}

//Stamp current time as start time and reset display textbox
function StartTiming()
{
	this.this_start_time = GetCurrentTime();	//stamp current time
        if (readCookie("sessionStartTime") == null)
            {
                createTimeCookie("sessionStartTime",this.this_start_time,"3");
                //document.TimeDisplayForm.TimeDisplayBox.value = 0;	//init textbox display to zero
            }
}

//Stamp current time as stop time, compute elapsed time difference and display in textbox
function EndTiming()
{
	this.this_end_time = GetCurrentTime();		//stamp current time
	//this.this_time_difference = (this.this_end_time - this.this_start_time) / 1000;	//compute elapsed time
        this.this_time_difference = (this.this_end_time - readCookie("sessionStartTime")) / 1000;	//compute elapsed time
        
        if (this.this_time_difference > 120)
        {
            openSurveyLB();
	     clearInterval(surveyIntervalId);	
        }
        //alert("Time Diff" + this.this_time_difference);
	//document.TimeDisplayForm.TimeDisplayBox.value = this.this_time_difference;	//set elapsed time in display box
}

var time_object = new timestamp_class(0, 0, 0, 0);	//create new time object and initialize it

