csuid=8575;
var ap=0;
var img_oper_online="http://www.gosimpleweb.net/images/chatimage.gif";
var img_oper_offline="http://www.gosimpleweb.net/images/bg.gif";
var img_operator_status="http://www.gosimpleweb.net/images/chatimage.gif";

var popup_template="<div id='cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;'><table cellpadding='5' cellspacing='0' width='375' height='275' style='background-image: url(https://iface.chatstat.com/system/images/chatInv_bg1.gif); 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://chat.chatstat.com/chatframe.aspx?csuid=8575&action=3');csHide('cs_messagealert');\"><img src='https://iface.chatstat.com/system/images/chatInv_yes1.gif' border='0'></a><br><br><a href=\"javascript:noThanks();\"><img src='https://iface.chatstat.com/system/images/chatInv_no1.gif' 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;'><table cellpadding='5' cellspacing='0' width='375' height='275' style='background-image: url(https://iface.chatstat.com/system/images/chatInv_bg1.gif); 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://chat.chatstat.com/chatframe.aspx?csuid=8575&action=2');csHide('auto_cs_messagealert');\"><img src='https://iface.chatstat.com/system/images/chatInv_yes1.gif' border='0'></a><br><br><a href=\"javascript:csHide('auto_cs_messagealert');\"><img src='https://iface.chatstat.com/system/images/chatInv_no1.gif' 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;

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=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.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 : 
		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 = 100;
		popDiv.id = 'cs_messagealert';
		

		myBody.appendChild(popDiv);	
		popDiv.innerHTML = popup_template.toString().replace(
			"<div id='cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;'>", "");


		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 = 100;
			popDiv2.id = 'auto_cs_messagealert';
		

			myBody2.appendChild(popDiv2);	
			popDiv2.innerHTML = auto_popup_template.toString().replace(
				"<div id='auto_cs_messagealert' style='position:absolute;display:none;visibility:hidden;z-index:1000;'>", "");
			
			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 = 100;
		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;'>", "");
	
		html = html.toString().replace(
			"<a href=\"javascript:pu('https://chat.chatstat.com/chatframe.aspx?csuid=" + csuid + "&action=3');csHide('cs_messagealert');\">", 
			"<a href=\"javascript:parent." + IframeID + ".pu('https://chat.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();\">");

		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)
	{
		divs = document.getElementsByTagName('div');
		if (divs[id].style.visibility == 'hidden')
		{
			divs[id].style.visibility = 'visible';
			divs[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)
	{
		divs = document.getElementsByTagName('div');
		if (divs[id].style.visibility == 'visible')
		{
			divs[id].style.visibility = 'hidden';
			divs[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)
	{
		divs = document.getElementsByTagName('div');
		if (divs[id].style.visibility == 'visible')
		{
			divs[id].style.visibility = 'hidden';
			divs[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=500,height=310,left = 200,top = 200');");
	chatwin.focus();
}

function noThanks() 
{
    csHide_Timeout("cs_messagealert");


    if(!isIframe)
    {
    	var vm_nothanks = 'https://iface.chatstat.com/image_nothanks.aspx?csuid=' + csuid + '&updTime=' + (new Date()).getTime();
	document.nothanks.src = vm_nothanks;
	document.nothanks.onLoad = handlePopupNoThanks();
    }
    else
    {
	var vm_nothanks = 'https://iface.chatstat.com/image_nothanks.aspx?csuid=' + csuid + '&updTime=' + (new Date()).getTime();
	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)
	{
	      divs = document.getElementsByTagName('div');
	      if (divs[id].style.visibility == 'visible')
	      {
        	    divs[id].style.visibility = 'hidden';
	            divs[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 img_tag = "<a href='javascript:pu(\"https://chat.chatstat.com/chatframe.aspx?csuid=" + csuid + "\",0);'/><i" + "mg border='0' " + "src='" + img_operator_status + "' name='imgcs2' /></a>";
		document.write(img_tag);
	}
    }
    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://iface.chatstat.com/image_chatchecker.aspx?csinit=1&csuid=" + csuid + "&url=" + uurl + "&ref=" + uref + "&updTime=" + (new Date()).getTime();
	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://iface.chatstat.com/image_chatchecker.aspx?csuid=' + csuid + '&url=' + uurl + '&updTime=' + (new Date()).getTime();",  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(newStatus==2)
		{
			if(InviteSent==false)
			{
				 cs_showEngagedPopup();
                    			setTimeout('handlePopupdisplayed();', 9000);   						
			}
		}

		switch(newWStatus)
			{
				case 2: //offline
					if(csChatCheckImg.src != img_oper_offline)
						csChatCheckImg.src = img_oper_offline;
					break;

				default: //online or unknown
					if(csChatCheckImg.src !=  img_oper_online)
						csChatCheckImg.src =  img_oper_online;
					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);
    }
}



write_ad();