﻿var csuid=6016;
var page_group='None';
var ap=0;
var popupWidth = 375;
var popupHeight = 275;
var popup_template="<div id='cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;width:375;height:275;'><table cellpadding='5' cellspacing='0' width='375' height='275' style='background-image: url(https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_bg1&cs_user_id=0); background-position: bottom left; background-repeat: no-repeat; background-color: #D6D6D6; border: 1px solid #999;'><tr><td colspan='3' valign='top' align='center'><font color='#000000' size='3' face='Verdana, Arial, Helvetica, sans-serif'><b>An operator would like to assist you with your visit...</b></font></td></tr><tr><td width='125'>&nbsp;</td><td colspan='2' valign='middle'><font color='#000000' size='2' face='Verdana, Arial, Helvetica, sans-serif'>Would you like to speak with the operator?</font></td></tr><tr><td width='125'>&nbsp;</td><td width='25'>&nbsp;</td><td align='center'><br><a href=\"javascript:pu('https://chat1.chatstat.com/chatframe.aspx?csuid=6016&action=3');csHide('cs_messagealert');\"><img src='https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_yes1&cs_user_id=0' border='0'></a><br><br><a href=\"javascript:noThanks();\"><img src='https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_no1&cs_user_id=0' border='0' name='nothanks' id='nothanks'></a></td></tr></table></div>";

var auto_popup_template="<div id='auto_cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;width:375;height:275;'><table cellpadding='5' cellspacing='0' width='375' height='275' style='background-image: url(https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_bg1&cs_user_id=0); background-position: bottom left; background-repeat: no-repeat; background-color: #D6D6D6; border: 1px solid #999;'><tr><td colspan='3' valign='top' align='center'><font color='#000000' size='3' face='Verdana, Arial, Helvetica, sans-serif'><b>An operator would like to assist you with your visit...</b></font></td></tr><tr><td width='125'>&nbsp;</td><td colspan='2' valign='middle'><font color='#000000' size='2' face='Verdana, Arial, Helvetica, sans-serif'>Would you like to speak with the operator?</font></td></tr><tr><td width='125'>&nbsp;</td><td width='25'>&nbsp;</td><td align='center'><br><a href=\"javascript:pu('https://chat1.chatstat.com/chatframe.aspx?csuid=6016&action=2');csHide('auto_cs_messagealert');\"><img src='https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_yes1&cs_user_id=0' border='0'></a><br><br><a href=\"javascript:csHide('auto_cs_messagealert');\"><img src='https://adsrvr1.chatstat.com/AppImages/PopupInviteImage.aspx?imgsetname=Default&imagename=chatInv_no1&cs_user_id=0' border='0' name='nothanks' id='nothanks'></a></td></tr></table></div>";
var chatwin = 0;
var uref = escape(document.referrer);
var uurl = escape(document.URL);
var udim = escape(screen.width + 'x' + screen.height)
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
var px = document.layers ? "" : "px";
var InviteSent=false;
var divCreated=false;
var isIframe = false;
var IframeID="";
var acCanceled=false;
var csChatCheckImg;
var chatWindowH = 310;
var chatWindowW = 510;
var adServerURL="https://adsrvr1.chatstat.com/image_presence.aspx?csuid=";
//var adChatCheckerURL="";
//var chatServerURL="https://chat.chatstat.com/chatframe.aspx?csuid=";


if (uref == '') 
	uref = '0';
if (uurl == '') 
	uurl = '0';


try
{
	window.addEventListener('load',function(e){WriteCSItems();}, false); 
} 
catch(e)
{
	window.attachEvent('onload',function(e){WriteCSItems();}); 
}


function WriteCSItems()
{
	CreateDiv();
	writeCSchatChecker();
}


function JSFX_FloatDiv(id, sx, sy)
{  
	var el;
	try
	{
		el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	}
	catch(e)
	{
		return JSFX_FloatDivOverIframe(id, sx, sy);
	}
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 1);
	}
	return el;    
}
function JSFX_FloatDivOverIframe(id, sx, sy)
{  
	var el=window.top.document.getElementById?window.top.document.getElementById(id):window.top.document.all?window.top.document.all[id]:window.top.document.layers[id];
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};
	el.flt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		window.top.document.documentElement && window.top.document.documentElement.clientWidth ? 
		window.top.document.documentElement.clientWidth : window.top.document.body.clientWidth;
		pY = ns ? pageYOffset : window.top.document.documentElement && window.top.document.documentElement.scrollTop ? 
		window.top.document.documentElement.scrollTop : window.top.document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : window.top.document.documentElement && window.top.document.documentElement.clientHeight ? 
		window.top.document.documentElement.clientHeight : window.top.document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.flt()", 1);
	}
	return el;

}

function CreateDiv()
{
	isIframe = getIframe();
	if(!divCreated && !isIframe)
	{
		var myBody = document.body;
		var popDiv = document.createElement("div");

		popDiv.style.visibility = "hidden";
		popDiv.style.display = "none";		
		popDiv.style.position = "absolute";
		popDiv.style.zIndex = 1000;
		popDiv.style.width = popupWidth +"px";
		popDiv.style.height = popupWidth +"px";
		popDiv.id = 'cs_messagealert';			
		
		var html = popup_template.toString().replace(
			"<div id='cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;width:"+popupWidth+";height:"+popupHeight+";'>", "");
		html = html.toString().replace("</div>", "");
		
		myBody.appendChild(popDiv);	
		popDiv.innerHTML = html;


		JSFX_FloatDiv("cs_messagealert", 250,100).flt();

		if(ap == 1)
		{
			var myBody2 = document.body;
			var popDiv2 = document.createElement("div");

			popDiv2.style.visibility = "hidden";
			popDiv2.style.display = "none";		
			popDiv2.style.position = "absolute";
			popDiv2.style.zIndex = 1000;
			popDiv2.style.width = popupWidth +"px";
		    popDiv2.style.height = popupWidth +"px";
			popDiv2.id = 'auto_cs_messagealert';
		

            var html = auto_popup_template.toString().replace(
				"<div id='auto_cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;width:"+popupWidth+";height:"+popupHeight+";'>", "");
		    html = html.toString().replace("</div>", "");		

			myBody2.appendChild(popDiv2);	
			popDiv2.innerHTML = html;
			
			JSFX_FloatDiv("auto_cs_messagealert", 250,100).flt();		
		}

		divCreated=true;
	}
	else if(!divCreated && isIframe)
	{	 	
		var myBody = window.top.document.body;
		var popDiv = window.top.document.createElement("div");

		
		popDiv.style.visibility = "hidden";
		popDiv.style.display = "none";	
		popDiv.style.position = "absolute";
		popDiv.style.zIndex = 1000;
		popDiv.style.width = popupWidth +"px";
		popDiv.style.height = popupWidth +"px";
		popDiv.id = "cs_messagealert";


		window.top.document.body.appendChild(popDiv);				
		
		var html = popup_template.toString().replace(
			"<div id='cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;width:"+popupWidth+";height:"+popupHeight+";'>", "");
	
		html = html.toString().replace(
			"<a href=\"javascript:pu('https://chat1.chatstat.com/chatframe.aspx?csuid=" + csuid + "&action=3');csHide('cs_messagealert');\">", 
			"<a href=\"javascript:parent." + IframeID + ".pu('https://chat1.chatstat.com/chatframe.aspx?csuid=" + csuid + "&action=3');parent." + IframeID + ".csHide('cs_messagealert');\">");
		
		html =	html.toString().replace(
			"<a href=\"javascript:noThanks();\">", "<a href=\"javascript:parent." + IframeID + ".noThanks();\">");

        html = html.toString().replace("</div>", "");	    
        
		popDiv.innerHTML = html;


		divCreated=true;
		JSFX_FloatDivOverIframe("cs_messagealert", 250,100).flt();	
	}
}
function getIframe()
{
   var isIframe=false;
   try
   {
	var myTop;
	if (window.frameElement) 	
		myTop = window.frameElement;
	else if (window.top) 
	{
		myTop = window.top;
		var myURL = location.href;
		var iFs = myTop.document.getElementsByTagName('iframe');
		var x, i = iFs.length;
		while ( i-- )
		{
			x = iFs[i];
			if (x.src && x.src == myURL)
			{
				myTop = x;
				break;
			}
		}
	}
	if (myTop)
	{
		var iframeid ='The iframe ' + ((myTop.id)?
		'has ID=' + myTop.id : 'is anonymous');

		if(iframeid.indexOf("anonymous") == -1)
		{
			isIframe=true;
			IframeID = myTop.id;
		}


	} 
	else 	
		isIframe=false;	
   }
   catch(e)
   {
	isIframe=false;
   }

   return isIframe;
}
function csShow(id) 
{
	try
	{
	    if(id=='auto_cs_messagealert')
	    {
		    if(InviteSent==true)
			    acCanceled=true;

		    if(acCanceled==true)
			    return;	
	    }

	    if(!isIframe)
	    {
            document.getElementById(id).style.visibility = 'visible';
            document.getElementById(id).style.display = 'block';                        
	    }
	    else
	    {
		    divs = window.top.document.getElementsByTagName('div');
		    if (divs[id].style.visibility == 'hidden')
		    {
			    divs[id].style.visibility = 'visible';
			    divs[id].style.display = 'block';
		    }
	    }
	}
	catch(e)
	{
	}
}
function csHideParent(id) 
{
	if(!isIframe)
	{	    
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display = 'none';            
	}
	else
	{
		divs = window.top.document.getElementsByTagName('div');
		if (divs[id].style.visibility == 'visible')
		{
			divs[id].style.visibility = 'hidden';
			divs[id].style.display = 'none';
		}
	}
}
function csHide(id) 
{
	try
	{
	    if(!isIframe)
	    {
            document.getElementById(id).style.visibility = 'hidden';
            document.getElementById(id).style.display = 'none';                        
	    }
	    else
	    {
		    divs = window.top.document.getElementsByTagName('div');
		    if (divs[id].style.visibility == 'visible')
		    {
			    divs[id].style.visibility = 'hidden';
			    divs[id].style.display = 'none';
		    }
	    }
	}
	catch(e)
	{

	}
}
function quoted(str) 
{
  return (str != null) ? '"' + str + '"' : '""';
}
function pu(URL,pop) 
{	
    //prevent auto-popup opening
	InviteSent=true;
    acCanceled=true;
    setTimeout('handlePopupdisplayed();', 10000);   

	day = new Date();
	id = day.getTime();
	eval("chatwin = window.open(URL, 'chatwin', 'toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=no,width=" + chatWindowW + ",height=" + chatWindowH + ",left = 200,top = 200');");
	chatwin.focus();
}

function noThanks() 
{
    csHide_Timeout("cs_messagealert");

    if(!isIframe)
    {
    	var vm_nothanks = 'https://adsrvr1.chatstat.com/image_nothanks.aspx?cs_user_id=' + csuid;
	    document.nothanks.src = vm_nothanks;
	    document.nothanks.onLoad = handlePopupNoThanks();
    }
    else
    {
	    var vm_nothanks = 'https://adsrvr1.chatstat.com/image_nothanks.aspx?cs_user_id=' + csuid;
	    window.top.document.nothanks.src = vm_nothanks;
	    window.top.document.nothanks.onLoad = handlePopupNoThanks();
    }
}

function handlePopupNoThanks()
{
    setTimeout('csHide("cs_messagealert");', 4000);
    setTimeout('handlePopupdisplayed();', 10000);    
}
function handlePopupdisplayed()
{
    InviteSent=false;
}

function csHide_Timeout(id)
{
	if(!isIframe)
	{
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display = 'none';                    
	}
	else
	{
		divs = window.top.document.getElementsByTagName('div');
		if (divs[id].style.visibility == 'visible')
      	{
    	    divs[id].style.visibility = 'hidden';
            divs[id].style.display = 'none';            
      	}
	}
}

function write_ad() 
{
    try
    {
	    if (chat == 1) 
	    {
            var scripts = document.getElementsByTagName("script"); 
            for (var i = 0; i < scripts.length; i++) 
            { 
                var sourceTemp = scripts[i].getAttribute("src"); 
                if (sourceTemp != null) 
                {
                    var source = sourceTemp.toLowerCase();
                    if (source.indexOf("jsbuilder.aspx") >= 1) 
                    { 
                        var element = null;
                        try 
                        {
                          element = document.createElement('<a id="ChatStat" href="javascript:pu(\'https://chat1.chatstat.com/chatframe.aspx?csuid=' + csuid + '\',0);">');
                        } 
                        catch (e) 
                        {
                        }
                        if (!element || element.nodeName != "A") 
                        {
                            element = document.createElement('a'); 
                            element.setAttribute("id", "ChatStat");
                            element.setAttribute("href", "javascript:pu('https://chat1.chatstat.com/chatframe.aspx?csuid=" + csuid + "',0);");
                        }
            				
                        element.innerHTML = '<i' + 'mg border="0" ' + 'src="' + adServerURL + csuid + '&page_group=' + page_group + '" name="imgcs2" />';
                        scripts[i].parentNode.insertBefore(element, scripts[i]);
                        break;
                    }
                }
            }
	    }
    }
    catch(err)
    {
      txt="There was an error on this page.\n\n";
      txt+="Error description: " + err.description + "\n\n";
      txt+="Click OK to continue.\n\n";
     // alert(txt);
    }
}



function writeCSchatChecker()
{
    csChatCheckImg = document.createElement('IMG');
	csChatCheckImg.style.visibility = "hidden";
	csChatCheckImg.id = "cs_img_popup1";
	csChatCheckImg.name = "imgcs1";
	csChatCheckImg.src = "https://adsrvr1.chatstat.com/image_chatchecker.aspx?csinit=1&csuid=" + csuid + "&url=" + uurl + "&ref=" + uref + "&updTime=" + (new Date()).getTime() + '&page_group=' + page_group;
	document.body.appendChild(csChatCheckImg);

	try
	{
	   csChatCheckImg.addEventListener('load',function(e){cs_getVisitorCSStatus();}, false); 
	} 
	catch(e)
	{
	   csChatCheckImg.attachEvent('onload',function(e){cs_getVisitorCSStatus();}); 
	}
}


function cs_getVisitorCSStatus()
{
    try
    {
	    //Check Image Status
	    cs_getVisitorCSButtonHandler();
	    setTimeout("csChatCheckImg.src = 'https://adsrvr1.chatstat.com/image_chatchecker.aspx?csuid=' + csuid + '&url=' + uurl + '&updTime=' + (new Date()).getTime() + '&page_group=' + page_group;",  9000);
    }
    catch(err)
    {
      txt="There was an error on this page.\n\n";
      txt+="Error description: " + err.description + "\n\n";
      txt+="Click OK to continue.\n\n";
      //alert(txt);
    }	
}



function cs_showEngagedPopup()
{
    
	document.getElementById('cs_messagealert').style.visibility = 'visible';
	document.getElementById('cs_messagealert').style.display = 'block';   
	InviteSent=true;
	acCanceled=true;
}


function cs_getVisitorCSButtonHandler()
{
    try
    {
		newStatus =document.getElementById('cs_img_popup1').height;
		newWStatus =document.getElementById('cs_img_popup1').width;
		var vm_img_src = '';
               
   	    //Operator wants to chat with this user?
		if(newWStatus ==2)
		{
			if(InviteSent==false)
			{			    		    
				 cs_showEngagedPopup();
                 setTimeout('handlePopupdisplayed();', 9000);
			}
		}

		//OPERATORAWARE1000
	
	}
    catch(err)
    {
      txt="There was an error on this page.\n\n";
      txt+="Error description: " + err.description + "\n\n";
      txt+="Click OK to continue.\n\n";
      //alert(txt);
    }
}



write_ad();
