// JavaScript Document

// this function opens pop-up window that the customer has requested; window sizes are width and height; window position is top and left dimensions.
function callme()
{
window.open('call2you/callme.htm','callme','width=500,height=500,top=250,left=300');
}
// end function


// this function opens pop-up window when the customer moves away from special pages. In the body tag place, onunload="return exit_popup();" , to capture customer moving away from page

function exit_popup()
{
window.open('call2you/callmesorry2.htm','callme','width=500,height=500,top=250,left=300');
}
// end function

// The next functions are used to check that cookies are accepted, place cookies for timed pop-over/pop-under event

function set_session_cookie(message){
	var monicor="DontLeaveUs";
	var result=get_cookie(monicor);
	if (result==null){
		document.cookie=monicor + "=" + message;
	}
	else{
		if (result=="goodbye"){
		timedVisibility2();
		//setPopUpSorryVisibility();
		document.cookie="DontLeaveUs=hello";
		}
		else if (result!=message){
			document.cookie=monicor + "=" + message;
		}
	}
}

//Get cookie routine by Shelley Powers 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

var clarity_timeout;
<!-- callme form visibilty -->
function timedVisibility(){
	<!-- changing the 'theDelay' variable will change pop-up timing. 1000 = 1second. eg 60,000 is 1 minute -->
	var theDelay = 30000;
	clarity_timeout = setTimeout('setPopUpHelpVisibility();', theDelay);
}

function setPopUpHelpVisibility(){
	setVisibility('callmeouterhelp','visible');
	// animation of the pop-up form across the page. first 2 numbers are final position, last number is speed of transverse.
	initAnimate('callmeouterhelp',120,50,99);
}

function setPopUpVisibility(){
	setVisibility('callmeouter','visible');
	setVisibility('callmeouterhelp','hidden');
	setVisibility('callmeoutersorry','hidden');
	// stop automatic pop-up of help version
	clearTimeout(clarity_timeout);
	// animation of the pop-up form across the page. first 2 numbers are final position, last number is speed of transverse.
	initAnimate('callmeouter',120,50,99);
}

function setPopUpClose(){
	setVisibility('callmeouter','hidden');
	setVisibility('callmeouterhelp','hidden');
	setVisibility('callmeoutersorry','hidden');
}

var clarity_timeout2;

function timedVisibility2(){
	var theDelay2 = 5000;
	clarity_timeout2 = setTimeout('setPopUpSorryVisibility();', theDelay2);
}

function halt_layer(){
	clearTimeout(clarity_timeout2);
}

function setPopUpSorryVisibility(){
	setVisibility('callmeoutersorry','visible');
	// stop automatic pop-up of help version
	clearTimeout(clarity_timeout);
	// animation of the pop-up form across the page. first 2 numbers are final position, last number is speed of transverse.
	initAnimate('callmeoutersorry',120,50,99);
}
function setVisibility(objectID,state) {
	var object = document.getElementById(objectID);
	object.style.visibility = state;
}

function toggleVisibility(objectID) {
	var object = document.getElementById(objectID);
	state = object.style.visibility;
	if (state == 'hidden')
		object.style.visibility = 'visible';
	else {
		if (state == 'visible')
			object.style.visibility = 'hidden';
		else object.style.visibility = 'visible';
	}
}

function callmeconnecting()
{
	var tmpProduct = "product=" + window.document.callform.product.value;
	var tmpPhone = "&phone=" + window.document.callform.phone.value;
	var tmpId = "&id=" + window.document.callform.id.value;
	var tmpName = "&name=" + window.document.callform.name.value;
	var tmpEmail = "&email=" + window.document.callform.email.value;
	var tmpWhen = "&when=" + window.document.callform.when.value;
		
	var tmpAll = tmpProduct + tmpPhone + tmpId + tmpName + tmpEmail + tmpWhen;
	
	window.location = "callmeconnect.htm?" + tmpAll;
}

// animating the pop-up layer
var animateSpeed = null;
var fX = null;
var fY = null;
var cX = null;
var cY = null;
var dX = null;
var dY = null;
var stepX = null;
var stepX = null;
var stepY = null;

function initAnimate(objectID,x,y,animate){

	object = document.getElementById(objectID);
	fX = x;
	fY = y;
	animateSpeed = animate;
	
	cX = object.offsetLeft;
	cY = object.offsetTop;
	dX = Math.abs(fX-cX);
	dY = Math.abs(fY-cY);
	if((dX==0)||(dY==0)){slope=0;}
	else {slope=dY/dX;
		if(dX>=dY){
			if(cX<fX){stepX=animateSpeed;}
			else if(cX>fX){stepX=-animateSpeed;}
			if(cY<fY){stepY=animateSpeed*slope;}
			else if(cY>fY){stepY=-animateSpeed*slope;}
		}
		else if(dX<dY){
			if(cY<fY){stepY=animateSpeed;}
			else if(cY>fY){stepY=-animateSpeed;}
			if(cX<fX){stepX=animateSpeed/slope;}
			else if(cX>fX){stepX=-animateSpeed/slope;}
		}
	}
	animateObject();
}
function animateObject(){
	if((dX>0)||(dY>0)){
		object.style.left=Math.round(cX)+'px';
		object.style.top=Math.round(cY)+'px';
		cX=cX+stepX;
		cY=cY+stepY;
		dX=dX-Math.abs(stepX);
		dY=dY-Math.abs(stepY);
		setTimeout('animateObject()',0);
	}
	else{
		object.style.left=fX+'px';
		object.style.top=fY+'px';
	}
	return;
}


<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
<!--
function YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}
//-->


// The next functions are used to check that cookies are accepted, place cookies for timed pop-over/pop-under event

// check if cookies are excepted
function chk()
{
	testing = document.cookie;
	//alert (testing);
	test=testing.split(";");
	if (testing.indexOf('popunder') == -1 && testing.indexOf('timechk') == -1)
	{
		Set_Cookie('popunder','pop','5');
		SetCookie('timechk','checktime');
		showpop();
	}
	if (testing.indexOf('popunder') == -1)
	{
		if (testing.indexOf('timechk') > -1 && testing.indexOf('shown') == -1)
		{
			doAgilePopup();
		}
	}
}

// get named cookie
function GetCookie (name) {  
	var arg = name + "=";
	//alert (arg);
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
			if (i == 0) break;   
		}  
	return null;
}

// set named cookie
function SetCookie (name, value) {  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}


function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	var today = new Date();
	today.setTime( today.getTime() );
		expires = expires * 1000;
	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" : "" );
}

// delete named cookie
function DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (exp*24*60*60*1000));

function amt(){
	var count = GetCookie('count')
	if(count == null) {
		SetCookie('count','1')
		return 1
	}
	else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('count')
		SetCookie('count',newcount,exp)
		return count
	}
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

// set time for pop-up, 1000ms = 1 sec
function checkCount() {
	var count = GetCookie('count');
	if (count == null) {
		count=1;
		//alert (count);
		setTimeout('this.doAgilePopup()',30000);
	}else {
		count++;
		SetCookie('count', count, exp);
   }
}

function showpop() {
		checkCount();
		return true;
}

var theURL = "call2you/callmehelp.htm";
var windowWidth  = 450; // cannot be less than 100
var windowHeight = 450; // cannot be less than 100
var windowX = 600;
var windowY = 650;
//var autoclose = true;
var s="width="+windowWidth+",height="+windowHeight;
var beIE=document.all?true:false;
var done=new Object("no");

function doAgilePopup(){
	SetCookie('shown', 'showw');
	agilePopper = window.open('call2you/callmehelp.htm','callme','width=450,height=450,top=250,left=300');
// uncomment the line below to cause window to pop-under
//	agilePopper.blur();
}
