//JavaScript Document
//load css
document.write('<style type="text/css"><!-- #callmeouter {height: 450px; width: 450px; position: absolute; z-index: 99; top: -450px; left: -450px; border: none; visibility: hidden;}--></style>');

//keep on screen code
document.write('<style type="text/css">.dockclass{position:relative;}</style>');

/***********************************************
* Dock Content script- Created by and © Dynamicdrive.com
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full script
***********************************************/

var offsetfromedge=-400     //offset from window edge when content is "docked". Change if desired.
var dockarray=new Array() //array to cache dockit instances
var dkclear=new Array()   //array to cache corresponding clearinterval pointers

function dockit(el, duration){
this.source=document.all? document.all[el] : document.getElementById(el);
this.source.height=this.source.offsetHeight;
this.docheight=truebody().clientHeight;
this.duration=duration;
this.pagetop=0;
this.elementoffset=this.getOffsetY();
dockarray[dockarray.length]=this;
var pointer=eval(dockarray.length-1);
var dynexpress='dkclear['+pointer+']=setInterval("dockornot(dockarray['+pointer+'])",100);';
dynexpress=(this.duration>0)? dynexpress+'setTimeout("clearInterval(dkclear['+pointer+']); dockarray['+pointer+'].source.style.top=0", duration*1000)' : dynexpress;
eval(dynexpress);
}

dockit.prototype.getOffsetY=function(){
var totaloffset=parseInt(this.source.offsetTop);
var parentEl=this.source.offsetParent;
while (parentEl!=null){
totaloffset+=parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function dockornot(obj){
obj.pagetop=truebody().scrollTop;
if (obj.pagetop>obj.elementoffset) //detect upper offset
obj.source.style.top=obj.pagetop-obj.elementoffset+offsetfromedge+"px";
else if (obj.pagetop+obj.docheight<obj.elementoffset+parseInt(obj.source.height)) //lower offset
obj.source.style.top=obj.pagetop+obj.docheight-obj.source.height-obj.elementoffset-offsetfromedge+"px";
else
obj.source.style.top=0;
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body

}


// 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=460,height=460,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=460,height=460,top=250,left=300');
}
// end function

// Flash cookie set
<!--
function setCookie(name, value)
{
  document.cookie = name+"="+value;
}
//-->


// 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(delay){
// Change the var 'delay' on page script as marked
	var theDelay = delay *1000;
	clarity_timeout = setTimeout('setPopUpHelpVisibility();', theDelay);
}

function setPopUpHelpVisibility(){
	setVisibility('callmeouter','visible');
	document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callmehelp.htm' height='500' width='500' frameborder='0' allowtransparency='true' scrolling='no'></iframe>";
	// animation of the pop-up form across the page. first 2 numbers are final position, last number is speed of transverse.
	// initAnimate('callmeouter',140,20,30);
	movelayer('callmeouter',10,5);// set up layer without animation
}

function setPopUpVisibility(){
	setVisibility('callmeouter','visible');
	document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callme.htm' height='500' width='500' frameborder='0' allowtransparency='true' scrolling='no'></iframe>";
	// 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',140,20,30);
	movelayer('callmeouter',10,5);// set up layer without animation	
}

function setPopUpClose(){
//	initAnimate('callmeouter',10,-500,40);
//	setVisibility('callmeouter','hidden');
    movelayer('callmeouter',-450,-450);
}

var clarity_timeout2;

function timedVisibility2(){
	var theDelay2 = 0;
	clarity_timeout2 = setTimeout('setPopUpSorryVisibility();', theDelay2);
}

function halt_layer(){
	clearTimeout(clarity_timeout2);
}

function setPopUpSorryVisibility(){
	setVisibility('callmeouter','visible');
		document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callmesorry.htm' height='500' width='500' frameborder='0' allowtransparency='true' scrolling='no'></iframe>";
	// animation of the pop-up form across the page. first 2 numbers are final position, last number is speed of transverse.
	//	initAnimate('callmeouter',140,40,30);
    movelayer('callmeouter',10,5);// set up layer without animation
	// stop automatic pop-up of help version
	clearTimeout(clarity_timeout);

}
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';
	}
}
// sets the layer off screen for Netscape browsers which don't fully support invisable layers  19/9/06
function movelayer(objectID,x,y){
object = document.getElementById(objectID);
		object.style.left=x+'px';
		object.style.top=x+'px';

}

// 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;
}

// 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  = 460; // cannot be less than 100
var windowHeight = 460; // 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=420,height=420,top=250,left=300');
// uncomment the line below to cause window to pop-under
//	agilePopper.blur();
}
