var USItimerID = '';
var properClickThrough = false;
var USIdone = false;
var onPage = 0;

function testYPos(e) {
	
	Y_pos = document.all? event.clientY: e.pageY - document.body.scrollTop - document.documentElement.scrollTop;
	
	if (Y_pos < 20 && onPage == 1) {
		onPage = 0
	}
	if (Y_pos > 20 && onPage == 0) {
		onPage = 1;
	}
}

if (document.attachEvent) {
	document.attachEvent("onmousemove", testYPos);
}

if (document.addEventListener) {
	document.addEventListener("mousemove", testYPos,  true);
}

window.onbeforeunload = function() {

	USIdone = true;
	
	if (USItimerID != '') clearTimeout(USItimerID);

	var yBasedSuppress = false;

	if (onPage == 1) yBasedSuppress = true;
		
	if (!properClickThrough && !yBasedSuppress)
	{
		window.onbeforeunload = null;
		
		/* sets the cookie expiration to one day */
		today = new Date();
		today.setTime( today.getTime() );

		expires = 1;
		expires = expires * 1000 * 60 * 60 * 24;
		expires_date = new Date( today.getTime() + (expires) );

		document.cookie = "vovici_survey=true; expires="+expires_date.toGMTString()+"; path=/; domain=.carpartswholesale.com";
		/* end - set cookie expiration */

		window.open('https://vovici.com/wsb.dll/s/15241g38f95');
	}
	
}

function TestClick() {

	if (USItimerID != '') clearTimeout(USItimerID);
	
	properClickThrough = true;
	USItimerID  = setTimeout("usiInterval();", 1000);
	
}

function usiInterval() {

	if(!USIdone){
		properClickThrough = false;
	}
	
	USItimerID = '';
}

document.documentElement.onmousedown = TestClick;
document.documentElement.onclick = TestClick;
document.documentElement.onkeypress = TestClick;
