// JavaScript Document compiled by Arisia ©2006
// not all functions are used in every website constructed for Clarity Callback
// any copyrights should be copied over if used in other js files.

// this function opens a normal pop-up window that the customer has requested; window sizes are width and height; window position is top and left dimensions. id number is customers claritycallback number.
function callme()
{
window.open('call2you/callme.htm?version=1','callme','width=420,height=420,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()
{
	var clarityWindow = window.open('scripts/call2you/callmesorry2.htm?version=3','callme','width=10,height=10,top=100,left=100','resizable=yes');
	self.focus();
	//clarityWindow.blur();
}
// end function
// this function sets the visibility of the layers, plus sets the position of the pop up when it appears.
function setPopUpVisibility(){
	Call2yousetVisibility('callmeouter','visible');
	document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callme.htm?version=1' height='460' width='410' 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',120,100,20);
	movelayer('callmeouter',120,120);// set up layer without animation	
}

// this function sets the visibility of the layers, plus sets the position of the pop up when it appears.
function setPopUpHelpVisibility(){
	Call2yousetVisibility('callmeouter','visible');
	document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callme.htm?version=2' height='460' width='410' 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',260,120,30);
	movelayer('callmeouter',120,120);// set up layer without animation
}

// this function sets the visibility of the layers, plus sets the position of the pop up when it appears.
function setPopUpSorryVisibility(){
	Call2yousetVisibility('callmeouter','visible');
		document.getElementById('callmeouter').innerHTML = "<iframe id='callmeiframe' src='call2you/callme.htm?version=3' height='460' width='410' 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',260,120,30);
    movelayer('callmeouter',120,120);// set up layer without animation
	// stop automatic pop-up of help version
	clearTimeout(clarity_timeout);
}

// timed delay for 'do you require help' layered pop up, in milliseconds
var clarity_timeout;

function timedVisibility(delay){
	<!-- changing the 'theDelay' variable will change pop-up timing. 1000 = 1second. eg 60,000 is 1 minute -->
	var theDelay = delay*1000;
	clarity_timeout = setTimeout('setPopUpHelpVisibility();', theDelay);
}

// timed delay for 'sorry to see your leaving' layered pop up, in milliseconds.
var clarity_timeout2;

function timedVisibility2(){
	<!-- changing the 'theDelay' variable will change pop-up timing. 1000 = 1second. eg 60,000 is 1 minute -->
	var theDelay2 = 1000;
	clarity_timeout2 = setTimeout('setPopUpSorryVisibility();', theDelay2);
}

// this function tries to stop the pop up layer appearing if the pop up window has been successful
function halt_layer(){
	clearTimeout(clarity_timeout2);
}

// closes a layered pop up window
function setPopUpClose(){
	Call2yousetVisibility('callmeouter','hidden');
	movelayer('callmeouter',-495,-495);
}

// function sets visibility of layer
function Call2yousetVisibility(objectID,state) {
	var object = document.getElementById(objectID);
	object.style.visibility = state;
}

// 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';

}

// The next functions are used to check that cookies are accepted, place cookies for timed pop-over/pop-under event
// changed by arisia 04/10/2006

function set_session_cookie(message){
	var monicor="DontLeaveUs";
	var result=get_cookie(monicor);
	if (result==null){
		document.cookie=monicor + "=" + message;
	}
	else{
		if (result=="goodbye"){
			if (message=="hello"){
				//timedVisibility2();
				setPopUpSorryVisibility();
				document.cookie="DontLeaveUs=" + message;
			}
		}
		else if (result!=message){
			if (message!="hold"){
				document.cookie=monicor + "=" + message;
			}else{
				document.cookie=monicor + "=goodbye";
			}
		}
	}
}
function set_session_cookie2(message){
	var monicor="local";
	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;
}

// 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;
}


// dragging pop-up layer
var object2 = null;
var ccX = null;
var ccY = null;

function initPage(x,y) {
	ccX=x;
	ccY=y;
	document.onmousedown = pickIt;
	document.onmousemove = dragIt;
	document.onmouseup = dropIt;
}

function pickIt(evt) {
	evt = (evt)?evt:((window.event)?event:null);
	//var objectID = (evt.target)?evt.target.id:((evt.srcElement)?evt.srcElement.id:null);
	//object2 = document.getElementById(objectID);
	object2 = document.getElementById('callmeouter');
	if (object2) {
		object2.style.zIndex = 9;
		ccX = evt.clientX - object2.offsetLeft;
		ccY = evt.clientY - object2.offsetTop;
		return;
		}
	else {
			object2 = null;
			return false;
	}
}

function dragIt(evt) {
	evt = (evt)?evt:((window.event)?event:null);
	if (object2) {
	object2.style.left = evt.clientX - ccX + 'px';
	object2.style.top = evt.clientY - ccY + 'px';
	return false;
	}
}

function dropIt() {
	if (object2) {
		object2.style.zIndex = 9;
		object2 = null;
		return false;
	}
}
//

// scripting to send data to clarity server to enable email facility

var IFrameObj; // our IFrame object
function callToServer(URL) {
  if (!document.createElement) {return true};
  var IFrameDoc;
    if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

// the following script is used to keep the pop-up window on the screen even if the viewer scrolls down .

/***********************************************
* 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=100 //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=100;
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


// 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 = "callme/callmehelp.htm";
var windowWidth  = 420; // cannot be less than 100
var windowHeight = 420; // 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('callme/callmehelp.htm','callme','width=420,height=420,top=250,left=300');
// uncomment the line below to cause window to pop-under
//	agilePopper.blur();
}

// standard functions dealing with checking the form before sending
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 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=='');
}
//-->

<!-- standard functions dealing with image swapping
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_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_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];}
}
//-->
