var millisec=700;
var constid = 2006;
var cp_dur = 180000;
var selarr;
var host = window.location.host;
var clarity_timeout;

function import_click2call(){
  document.write("<div id=\"clarity\">"
  +"<div id=\"callmeouter\"></div>"
  +"<img id=\"callmeimage\" src=\"/click2call/im/bg.png\" alt=\"\"/>"
  +"<div id=\"callme\">"
  +"<div id=\"callmeclose\"><a href=\"javascript:void(0)\" onClick=\"layerClose()\">close</a></div>"
  +"<iframe ALLOWTRANSPARENCY=true id=\"callframe\" frameborder='0' src=\"/click2call/callme.html?id="+constid+"\"></iframe></div></div>");
  selarr = document.getElementsByTagName('select');
}

function import_virtualshopassistant(timer){
  var delay = timer*1000;
  clarity_timeout = setTimeout('VirtualShopAssistant();', delay);
}

function import_catchtheprospect(message){
  if (message) {
   set_session_cookie(message); }
  else {
   set_session_cookie('catch'); }
}

function Click2Call(){
  clearTimeout(clarity_timeout);
  scrollTo(0,0);
  document.getElementById('callmeouter').style.height = getPageHeight()+"px";
  opacity('callmeouter',0,40,1);
  setTimeout("setVisibility('callme','visible');setVisibility('callmeimage','visible');",200);
  for (i=0;i<selarr.length;i++) {
	selarr[i].style.visibility = 'hidden';
    }
  }

function CatchTheProspect(){
  document.getElementById('callframe').src="/click2call/catchtheprospect.html?id="+constid;
  Click2Call();
  }

function VirtualShopAssistant(){
  document.getElementById('callframe').src="/click2call/virtualshopassistant.html?id="+constid;
  Click2Call();
  }

function layerClose(){
  opacity('callmeouter',40,0,20);
  setTimeout("document.getElementById('callmeouter').style.height = 0;",30);
  setVisibility('callme','hidden');
  setVisibility('callmeimage','hidden');
  document.getElementById('callframe').src="/click2call/callme.html?id="+constid;
  for (i=0;i<selarr.length;i++) {
	selarr[i].style.visibility = 'visible';
    }
}


function setVisibility(objectID,state) {
	var obj = document.getElementById(objectID);
	obj.style.visibility = state;
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
			opacity(id, 0, 100, millisec);
	} else {
			opacity(id, 100, 0, millisec);
	}
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
					setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
					timer++;
			}
	} else if(opacStart < opacEnd) {
			document.getElementById(id).style.visibility= 'visible';
			for(i = opacStart; i <= opacEnd; i++)
					{
					setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
					timer++;
			}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function getPageHeight(){

	var yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}

	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	return pageHeight;
}

// CTP COOKIE MANIPULATION //

function set_session_cookie(message){
	var monicor="DontLeaveUs";
	var result=get_cookie(monicor);
	if (result==null){
		document.cookie=monicor + "=" + message;
	}
	else{
		if (result=="set" && message!="set"){
	    CatchTheProspect();
		document.cookie="DontLeaveUs=catch";
		}
		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;
}