// GuideChat  - ver. 2.0
// Work with cookies
// Copyright(c) 2008 WaveAccess, http://wave-access.com

var sLiveHelpCookie = 'LiveHelpCookie';
var iMaxClicks = 2;

function clickCounter(){
	var iCookie = readCookie(sLiveHelpCookie);	
	if (!iCookie){
	    iCookie = 0;
	    setCookie(0);
	}
	if(iCookie && iCookie!='-1'){
		iCookie++;
		setCookie(iCookie);
	}
	if (iCookie > iMaxClicks - 1)
	    embedObject();
}


function setSupportJID()
{
     openDIV();
}

function openDIV()
{
	try{
	    if (readCookie(sLiveHelpCookie)!= '-1')
		{
		    var chatDIV = document.createElement('DIV');
		    chatDIV.id='chatDIV';
		    chatDIV.style.cssText = 'width:264px;height:133px;background:url(i/chatdivbg.png);position:absolute;z-index:98854;top:0px;left:0px;text-align:center';
		    chatDIV.innerHTML = '<img src="i/wa_close.gif" onClick="CloseChatDiv()" title="Close" style="cursor:pointer;float:right;margin:10px 10px 10px 0;clear:both"><div style="text-align:left;padding-right:15px;margin:20px 15px 20px 15px;">Welcome to SalesCentric online chat. If you have any questions please don\'t hesitate to ask them. Our managers will be happy to help you.</div><img src="i/btnchat.gif" alt="Enter Chat" title="Enter Chat" onClick="Chat()" style="float:none;margin:0 auto 0 auto;cursor:pointer">';
		    document.body.appendChild(chatDIV);
		    document.getElementById('chatDIV').style.top = (document.body.offsetHeight - document.getElementById('chatDIV').offsetHeight)/2 + "px";
		    document.getElementById('chatDIV').style.left = (document.body.offsetWidth - document.getElementById('chatDIV').offsetWidth)/2 + "px";
		    setCookie(-1);
		}
	}
	catch(err){}
}

function embedObject(){
    var sResult = '';
    try{
	    sResult  = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="rosterConnector" width="0" height="0" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">\n';
        sResult += '<param name="movie" value="gcfolder/rosterConnector.swf" />\n';
        sResult += '<param name="quality" value="high" />\n';
        sResult += '<param name="bgcolor" value="#ffffff" />\n';
        sResult += '<param name="allowScriptAccess" value="always" />\n';
        sResult += '<param name="flashVars" value="jabber_server=salescentric.com&guest_jid=guest"/>\n';
        sResult += '<embed src="gcfolder/rosterConnector.swf" quality="high" bgcolor="#ffffff" width="0" height="0" name="GuideChat" align="middle" play="true" loop="false" quality="high" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" flashVars="jabber_server=salescentric.com&guest_jid=guest">\n';
        sResult += '</embed>\n';
        sResult += '</object>';
        
        /*var swfGuideChatDIV = document.createElement('DIV');
	swfGuideChatDIV.id='swfGuideChatDIV';
	swfGuideChatDIV.style.cssText = "position:absolute;top:-10px;left:-10px;z-index:98853width:1px;height:1px";
	swfGuideChatDIV.innerHTML = sResult;		
	document.body.appendChild(swfGuideChatDIV);*/

	document.getElementById('swfGuideChatDIV').style.cssText = "position:absolute;top:-10px;left:-10px;z-index:98853width:1px;height:1px";
	document.getElementById('swfGuideChatDIV').innerHTML = sResult;
    }
    catch(err){}
}
function CloseChatDiv()
{
	try{
		setCookie(-1);
		if( document.getElementById('chatDIV') != null )
			document.getElementById('chatDIV').style.display = "none";
	}
	catch(err){}
}

function Chat(){
	try{
		setCookie(-1);
		CloseChatDiv();
		window.open('gcfolder/gc.html','new','width=425,height=450,toolbar=0, left=300,top=400');
	}
 	catch(err){}
}

function readCookie(name){
    try{    
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++){
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	    }
	}
	catch(err){}
	
	return null;
}

function setCookie(number){
    try{
        document.cookie = sLiveHelpCookie + '=' + number + ';path=/';
    }
    catch(err){} 
}

clickCounter();