var millisec=700;
var clarity_timeout;
var constid = 2178;
var ctp = 0;
var vsa = 0;
var c2c = 0;

function import_click2call(){
document.write("<div id=\"callmeouter\"></div><div id=\"callme\">"
+"<div id=\"callmeclose\"><a href=\"javascript:void(0)\" onClick=\"layerClose()\">"
+"<img src=\"/click2call/im/close.png\" alt=\"\" /></a></div>"
+"<iframe ALLOWTRANSPARENCY=true id=\"c2c_frame\" frameborder='0' src='/click2call/callme.html?id="+constid+"'></iframe></div>");
}

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 getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


 function setTags(name,state){
  var tags = document.getElementsByTagName(name);
  for (var i = 0; i < tags.length; i++) {
    tags[i].style.visibility = state;
  }
 }

function Click2Call(){
  if (vsa  | ctp){ layerClose(); }
  c2c = 1;
  clearTimeout(clarity_timeout);
  document.getElementById('callmeouter').style.height = getPageHeight()+"px";
  setVisibility('callme','visible');
  setVisibility('callmeouter','visible');
  setTags('select','hidden');
  }

function layerClose(){
  c2c=0; vsa=0; ctp=0;
  clearTimeout(clarity_timeout);
  document.getElementById('callmeouter').style.height = 0;
  setVisibility('callme','hidden');
  setVisibility('callmeouter','hidden');
  document.getElementById('c2c_frame').src='/click2call/callme.html?id='+constid;
  setTags('select','visible');
}

function VirtualShopAssistant(){
  document.getElementById('c2c_frame').src='/click2call/virtualshopassistant.html?id='+constid;
  vsa = 1;
  clearTimeout(clarity_timeout);
  setVisibility('callme','visible');
  setDisplay('c2c_frame','block');
  setDisplay('callmeclose','block');
  setTimeout("grow('c2c_frame',0,230,100)",millisec*1.5);
  setTimeout("opacity('callme',0,99, millisec);",100);
  }

function CatchTheProspect(){
  if (c2c | vsa){ layerClose(); }
  document.getElementById('c2c_frame').src='/click2call/catchtheprospect.html?id='+constid;
  ctp = 1;
  clearTimeout(clarity_timeout);
  opacity('callmeouter',0,45, 200);
  setVisibility('callme','visible');
  setVisibility('callmeouter','visible');
  setDisplay('c2c_frame','block');
  setDisplay('callmeclose','block');
  setTimeout("grow('c2c_frame',0,230,100)",millisec*1.5);
  setTimeout("opacity('callme',0,99, millisec);",100);
  }

// 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=="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;
}


var clarity_timeout2;

function timedVisibility2(){
	var theDelay2 = 1;
	clarity_timeout2 = setTimeout('CatchTheProspect();', theDelay2);
}

function halt_layer(){
	clearTimeout(clarity_timeout2);
}

function setVisibility(objectID,state) {
	var obj = document.getElementById(objectID);
	obj.style.visibility = state;
}


function setDisplay(objectID,state) {
	var obj = document.getElementById(objectID);
	obj.style.display = state;
}

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

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 grow(id, heightStart, heightEnd, 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(heightStart > heightEnd) {
        for(i = heightStart; i >= heightEnd; i--) {
            setTimeout("changeHeight(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(heightStart < heightEnd) {
        for(i = heightStart; i <= heightEnd; i++)
            {
            setTimeout("changeHeight(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeHeight(h, id) {
	fram = document.getElementById(id);
	if (fram.contentDocument){
	   var framedoc = fram.contentDocument;
	 } else {
	   var framedoc = document.frames[id].document;
       }
    var main = framedoc.getElementById("main");
    main.style.height  = h+"px";
}

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;
}