sLivePersonURL="https://server.iad.liveperson.net/hc/58947214/?cmd=mTagRepstate&site=58947214&buttonID=12&divID=lpButDivID-1283877766174&bt=1&c=1";

function flagError(err) {
	sError = ""
	for (var i in err) sError = sError + i + '=' + err[i] + '&';
	if (sDomain=="localhost") {
		/*alert("error on page");*/
		alert(sError);
	} else {
		sURL = sRootURL+'/500.php?Errortype=Javascript&error=' + escape(sError);
		var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
		request.open("GET", sURL, true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		request.send(null);
	}
}

function DisplayProducts(sCategory) {
	sObj=document.getElementById(sCategory);
	nHeight=sObj.offsetHeight;
	sObj.style.height="0px";
	sObj.style.visibility="visible";
	sObj.style.position="relative";
	document.getElementById(sCategory+"_switch").style.display="none";
	setTimeout("OpenCategory(sObj, "+nHeight+")",50);
}

function OpenCategory(sObj, nHeight) {
	
	if ((nHeight-sObj.offsetHeight) > 50) {
		sObj.style.height=(sObj.offsetHeight+50)+"px";
	} else {
		sObj.style.height=nHeight+"px";
	}
	if (sObj.offsetHeight<nHeight) {
		setTimeout("OpenCategory(sObj, "+nHeight+")",50);
	}
}


function loadjscssfile(filename, filetype){
	if (filetype=="js"){ //if filename is a external JavaScript file
		var fileref=document.createElement('script');
		fileref.setAttribute("type","text/javascript");;
		fileref.setAttribute("src", filename)
	}
	else if (filetype=="css"){ //if filename is an external CSS file
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
	}
	if (typeof fileref!="undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref);
}

function LoadLivePerson() {
	loadjscssfile(sLivePersonURL,'js');
	ChatTimeout=setTimeout("CheckChat()",2000);
	//loadjscssfile("http://cdn.icarkits.com/css/shadowbox-3.0.3/shadowbox.css",'css');
}


properClickThrough = false;

function regularChatDisplay(e) {
	if (!properClickThrough)  {
	window.onbeforeunload = null;
	ChatEnabled=true;
	alert("Wait! A live agent would like to talk to you about finding an adapter for your vehicle. Please hit 'Cancel' on the next window to remain on this page..."); 
	return "\n\nPress 'CANCEL' below to speak with a live representative.\n\n";
	}
}



var ChatEnabled=false;
var ChatTimeout=0;

function SetChat() {
	ChatEnabled=true;
}

function CheckChat() {
	if (ChatEnabled) { ShowChat(); return; }
	ChatTimeout=setTimeout("CheckChat()",5000);
}

function ShowChat() {
	var keys = [];
	for(var key in lpMTagStatic){
     keys.push(key);
   	}
	lpMTagStatic[keys[1]].Clicked();
	return;
}

function TestClick() {
	properClickThrough = true;
}

//window.onbeforeunload = regularChatDisplay;
//document.documentElement.onmousedown = TestClick;
//document.documentElement.onclick = TestClick;
//document.documentElement.onkeypress = TestClick;
