﻿var needToConfirm = true;

var d = new Date();
var start_time = d.getTime();
var jcount = 0;

function record_time(time) {

  php_f = "php/record.php?msec=" + time + "&ref=" + document.referrer + "&rept=" + jcount;
  xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.open("GET", php_f, true);
  xmlhttp.send(null);
}

function rec_exit (){
  var e = new Date();

  time_in = e.getTime() - start_time;
  e.setMonth(e.getMonth()+3);
/*  jcount = eval(cookieVal("Counter"));*/
  jcount = cookieVal("Counter");
  
  jcount++;
  document.cookie = "Counter="+jcount+";expires=" + e.toGMTString();
  if ((time_in < 30000) & needToConfirm & (jcount == 1)) { 
	  record_time(-time_in);
      return "WOW - quit so fast! Is this web site so bad?\n\nMay be try to visit the Products page?\n\nOr, please stay and send me feedback with remarks about what you did not like on this site?\n\n ";
  }
  record_time(time_in);
  
}
window.onbeforeunload=rec_exit;

function cookieVal(cookieName) {
  thisCookie = document.cookie.split("; ");
  for (i=0; i<thisCookie.length; i++) {
	if (cookieName == thisCookie[i].split("=")[0]){
		return thisCookie[i].split("=")[1];
	}
  }
  return 0;
}

var	tip_on = false;

function div_on	(txt) {
	var el = document.getElementById('gmap_txt');
	if (txt) {
		el.innerHTML = txt;
		tip_on = 2;
	} else {
		el.style.display = "none";
		tip_on = false;
	}	
}		

var offsetfromcursorY=21; //Customize y offset of tooltip
 
var ie=document.all;
var ns6=document.getElementById && !document.all;

function positiontip (e) {
	if (tip_on) {
		var el = document.getElementById('gmap_txt');
		var curX=(ns6)?e.pageX : event.clientX;
		var curY=(ns6)?e.pageY : event.clientY;
 
		el.style.left=curX - el.offsetWidth/2 + "px";
 
		el.style.top=curY + offsetfromcursorY + "px";
	}
	if (tip_on > 1) {
		el.style.display = "block";
		tip_on = 1;	
	}
}

document.onmousemove=positiontip;

