pageOpen = new Date();


function format_digit(var1){
	
	var lent= var1.length;
	if(lent==1){ final_format = "0"+var1; }else{  final_format = var1;  }
	return final_format; 
}

function bye() {
pageClose = new Date();
var time;
hours = (pageClose.getHours() - pageOpen.getHours());
minutes = (pageClose.getMinutes() - pageOpen.getMinutes());
seconds = (pageClose.getSeconds() - pageOpen.getSeconds());
//times = (seconds + (minutes * 60));

fhours=format_digit(hours+'');
fminutes=format_digit(minutes+'');
fseconds=format_digit(seconds+'');


if(seconds>0){
time=(fhours + ":" + fminutes+ ":" + fseconds);
}
/*
if (times == 1) {
time = (seconds + " second minutes "+ seconds );
}
else {
time = (time + " seconds");
   }
   
   */
//alert('It has been ' + time + '.  Please stay longer next time!');

return time;
} 


//Browser Support Code
function processPageView(page_name){
	var view_duration=bye();
	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.time.value = ajaxRequest.responseText;
	//document.getElementById('message').innerHTML = ajaxRequest.responseText;
		}
	}
	/*var age = document.getElementById('age').value;
	var wpm = document.getElementById('wpm').value;
	var sex = document.getElementById('sex').value;
	*/
	//var queryString = "?age=" + age + "&wpm=" + wpm + "&sex=" + sex +"time_spane="+time_span;

	var queryString = "?view_duration="+view_duration +"&page_name=" + page_name;
	//ajaxRequest.open("POST", "../time.php.htm" + queryString, true);
	

	ajaxRequest.open("GET", "../save_page.php.htm"+queryString, true);
	ajaxRequest.send(null); 
}