/*
	ServiceSuite Live Chat Module v5.0	Copyright(C) 2007 Grail Networks Inc
	All Rights Reserved
	Unauthorized Duplication Prohibited
*/

var ss5_img = new Image();
ss5_img.onload=ss5_checkImage;
var ss5_ver='5.0';
var ss5_server='http://on.grailnetworks.com';
var ss5_reportcount=1; var ssgid = '4d8ae3a33b23ffa81041973588e47ef3dfdeb7c1';
var xenreport_server='http://on.grailnetworks.com';
var ss5_chatStatus = 0;

function Neptide_callUser(userid)
{
	ss5_chatStatus++;
	if (userid!="tm") 
		window.open("http://on.grailnetworks.com/instanton/servicesuite/livehelp/chatframe.on?requestedid="+userid+"&cookies="+navigator.cookieEnabled,"ServiceSuite_"+userid,"width=544,height=290,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
	else {
		window.open("http://on.grailnetworks.com/instanton/servicesuite/livehelp/operator_textmessage.on?clientid=20667&gid=4d8ae3a33b23ffa81041973588e47ef3dfdeb7c1&action=c&cookies="+navigator.cookieEnabled,"ServiceSuite_"+userid,"width=544,height=290,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
		}
}

function Neptide_callOperator()
{
	ss5_chatStatus++;
	window.open("http://on.grailnetworks.com/instanton/servicesuite/livehelp/chatframe.on?clientid=20667&deptid=1&cookies="+navigator.cookieEnabled,"ServiceSuite_20667","width=544,height=290,scrollbars=no,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
}

var neptide_title=document.title;
var neptide_url=document.URL;
var neptide_refer=document.referrer;

function ss5_setPage(newurl, newtitle)
{
	neptide_url=newurl;
	neptide_title=newtitle;
}

var xenurl="";

function ss5_report()
{
	ss5_img = new Image();
	ss5_img.onload = ss5_checkImage;
	var ss5_d = new Date();
	if (ss5_reportcount==1) {
		xenurl = xenreport_server+'/instanton/servicesuite/livehelp/sitescripts/vrecorder.on?rc='+ss5_reportcount+'&ver='+escape(ss5_ver)+'&stamp='+ss5_d.getTime()+'&cid=20667&url='+escape(neptide_url)+'&title='+escape(neptide_title)+'&refer='+escape(neptide_refer)+'&deptid=1&localtime='+escape(ss5_d.toLocaleString())+'&cookies='+navigator.cookieEnabled+'&tz='+ss5_d.getTimezoneOffset()+'&gid=4d8ae3a33b23ffa81041973588e47ef3dfdeb7c1';
	} else {
		xenurl = xenreport_server+'/instanton/servicesuite/livehelp/sitescripts/vrecorder.on?cid=20667&rc='+ss5_reportcount+'&gid=4d8ae3a33b23ffa81041973588e47ef3dfdeb7c1';
	}
	if (navigator.userAgent.indexOf('MSIE')>-1) xenurl+="&isie=1";
	ss5_img.src= xenurl;
	if (ss5_reportcount<432) {
	setTimeout("ss5_report()",25000);
	ss5_reportcount++;
	}
}

function ss5_checkImage() {
	
	if (ss5_img.width>1 && ss5_img.width!=16) {
		ssTrig_displayTextMessage();
	}
}

ss5_report();
//browser metrics

var ss_IEreported=false;
var flashVersion=0,ssmetric_string="";

function getMetrics() {
ssmetric_string="";
sstzone = (new Date()).toString();
ssmiddletz="";
var ssre=null;
if (navigator.userAgent.indexOf('MSIE')>-1 && Number(ScriptEngineMajorVersion()+ "."+ScriptEngineMinorVersion())>=5.5) 
	ssre = /[A-Z]{3,}/;
else if (navigator.userAgent.indexOf('Mozilla')>-1) 
	ssre = /\(.*?\)/;
else if (navigator.userAgent.indexOf('Opera')>-1)
	ssre = /[A-Z]{3,}-\d*/;
if (ssre!=null) {
	var ssm = ssre.exec(sstzone);
	if (ssm!=null)
		ssmiddletz=ssm;
}
ssmetric_string+="Browser: "+navigator.userAgent+"\n";
ssmetric_string+="Timezone: "+ssmiddletz+" "+((new Date()).getTimezoneOffset()/-60)+"\n";
ssmetric_string+="Browser Name: "+navigator.appName+"\n";
ssmetric_string+="Browser Code Name: "+navigator.appCodeName+"\n";
ssmetric_string+="Browser Version: "+navigator.appVersion+"\n";
if (window.screen) 
{
	ssmetric_string+="Screen Colors: "+window.screen.colorDepth+"bit\n";
	ssmetric_string+="Screen Resolution: "+window.screen.width+"x"+window.screen.height+"\n";
	ssmetric_string+="Available Resolution: "+window.screen.availWidth+"x"+window.screen.availHeight+"\n";
}
ssmetric_string+="Platform: "+navigator.platform+"\n";
if (navigator.javaEnabled() < 1) ssmetric_string+="Java: No\n";
if (navigator.javaEnabled() == 1) ssmetric_string+="Java: Yes\n";
if (navigator.cookieEnabled) ssmetric_string+="Cookies: Yes\n"; else ssmetric_string+="Cookies: No\n";

}

function getFlashVersion() {
	var dontKnow = false;
	var flashVersion = 0;
	agent = navigator.userAgent.toLowerCase();
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('6.') != -1) flashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) flashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) flashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) flashVersion = 3;
		}
	}

	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
		document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('if IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")) then flashVersion = 6 \n');
		document.write('if flashVersion < 6 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")) then flashVersion = 5 \n');
		document.write('if flashVersion < 5 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")) then flashVersion = 4 \n');
		document.write('if flashVersion < 4 and IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")) then flashVersion = 3 \n');
		document.write('neptide_IEreport_fv(flashVersion)');
		document.write('</scr' + 'ipt\> \n'); 
	}
		
	else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

	else if (agent.indexOf("webtv") != -1) flashVersion = 2;

	else {
		flashVersion = flashVersion_DONTKNOW;
		dontKnow = true;
	}

	return flashVersion;
}

flashVersion_DONTKNOW = -1;
function ss_detect() 
{
	neptided = new Date();
	getMetrics();
	flashVersion = getFlashVersion();
	if (flashVersion != flashVersion_DONTKNOW) ssmetric_string+="Flash Version: "+flashVersion+"\n";
	ss_report_metrics();
}

function ss_IEreport_fv(fv)
{
	flashVersion=fv;
	if (flashVersion != flashVersion_DONTKNOW) {
		ssmetric_string+="Flash Version: "+flashVersion+"\n";
		ss_report_metrics();
		ss_IEreported=true;
	}
}

function ss_report_metrics() 
{
	if (ss_IEreported) return;
	reportimg = new Image();
	reportimg.src="http://on.grailnetworks.com/instanton/servicesuite/livehelp/sitescripts/vrecorder.on?cid=20667&gid="+ssgid+"&metrics="+escape(ssmetric_string);
}

ss_detect(); //no start load time generated

function ssTrig_InviteClose(tid) {
	var target;
	if (document.getElementById) {
		target = document.getElementById("catrig"+tid).style;
	} else if (document.all) {
		target = eval("document.all.catrig"+tid+".style");
	} else if (document.layers) {
		target = eval("document.catrig"+tid);
	}
	if (target) {
		target.visibility = "hidden";	
		target.top=-100;
	}
}

function ssTrig_acceptInvite() {
	ss_oCA(gn_deptid);
	ssTrig_InviteClose(0);
}

function ssTrig_closeTextMsg() {
	ssTrig_InviteClose(0);
}

function ssTrig_replyTextMsg() {
	ssTrig_InviteClose(0);
	Neptide_callUser("tm");
}

function ssTrig_createTextMessage() {
	var tid=0;
	if (document.getElementById) {
		if (document.getElementById('catrig0')==null) {
			document.write("<div style='z-index:300; top:-100; left:200; width:300; height:200; visibility: hidden; position: absolute;' id='catrig0' onMouseOut='ssTrig_pauseInvite("+tid+",false)' onMouseOver='ssTrig_pauseInvite("+tid+",true)'>");
			document.write('<img src="http://on.grailnetworks.com/instanton/servicesuite/livehelp/graphics/images/catextmessage_r1_c1.gif" width="300" height="31" border="0" usemap="#m_catextmessage_r1_c1" alt=""><br>');
			document.write('<iframe frameborder=0 scrolling=no allowtransparency="true" background-color="transparent" id="catrigtxtcontent" style="width:300px; height:145px;" src="http://on.grailnetworks.com/instanton/servicesuite/livehelp/operator_textmessage.on?action=g"></iframe><br>');
			document.write('<img src="http://on.grailnetworks.com/instanton/servicesuite/livehelp/graphics/images/catextmessage_r3_c1.gif" width="300" height="24" border="0" usemap="#m_catextmessage_r3_c1" alt="">');
			document.write('<map name="m_catextmessage_r3_c1"><area shape="poly" coords="165,1,295,1,295,19,165,19,165,1" href="javascript:ssTrig_replyTextMsg()" title="Reply to this text message" alt="Reply to this text message" ><area shape="rect" coords="20,7,140,15" href="http://www.grailnetworks.com" target="_blank" alt="" ></map>');
			document.write('<map name="m_catextmessage_r1_c1"><area shape="poly" coords="278,3,294,3,294,18,278,18,278,3" href="javascript:ssTrig_closeTextMsg()" title="Close this text message" alt="Close this text message" ></map>');			
			document.write('</div>');
		}
	}	
}

function ssTrig_createInvite() {
	if (document.getElementById) {
		if (document.getElementById('catriginvite')==null) {
			document.write("<div style='z-index:300; top:-100; left:200; visibility: hidden; position: absolute;' id='catriginvite' onMouseOut='ssTrig_pauseInvite(\"invite\",false)' onMouseOver='ssTrig_pauseInvite(\"invite\",true)'>");
			document.write("<a href='javascript:void(ssTrig_acceptInvite())'><img src='http://on.grailnetworks.com/instanton/servicesuite/livehelp/graphics/twopix.gif' name='gnofferurl' border=0></a><br><a href='javascript:void(ssTrig_InviteClose(\"invite\"))'><img src='http://on.grailnetworks.com/instanton/servicesuite/livehelp/graphics/twopix.gif' name='gncloseurl' border=0></a>");
			document.write("</div>");
		}
	}
}

function ssTrig_displayTextMessage() {
	if (document.getElementById) {
		catrign = new Date();
		now = catrign.getTime();
		document.getElementById('catrigtxtcontent').src = 'http://on.grailnetworks.com/instanton/servicesuite/livehelp/operator_textmessage.on?action=g&clientid=20667&gid='+ssgid+"&"+now;
		ssTrig_activateInvite(0);
	}
}

function ssTrig_pauseInvite(tid,pauseit) {
	ssTrig_pauseOn=pauseit;
}

function ssTrig_activateInvite(tid) {
	if ((!ssTrig_invited && tid!=0) || tid==0) {
		var gn_wl = (tid>0)?"invite":0;
		var ssaction="ssTrig_pauseInvite('"+gn_wl+"',false);ssTrig_AnimateDiv('"+gn_wl+"',100,200,50,true);focus();"
		if (tid>0) {
			ssTrig_populateTrigger(tid, ssaction);
		} else eval(ssaction);
	}
}

function ssTrig_AnimateDiv(tid,topOffset,toLeft,Speed,makeVisible) {
	var target=null,toTop;
	if (document.getElementById) {
		target = document.getElementById(("catrig"+tid)).style;
	} else if (document.all) {
		target = eval("document.all.catrig"+tid+".style");
	} else if (document.layers) {
		target = eval("document.catrig"+tid);
	}

	if (document.documentElement && document.documentElement.scrollTop) {
		ssTrig_doctop = document.documentElement.scrollTop-100;
		toTop = document.documentElement.scrollTop+topOffset;
	} else if (document.body) {
		ssTrig_doctop = document.body.scrollTop-100;
		toTop = document.body.scrollTop+topOffset;
	} else {
		ssTrig_doctop = -100;
		toTop = topOffset;
	}

	if (target) {
		var c=0; var nextSpeed = Speed,posy,posx,inc;
		if (makeVisible) {
				target.visibility = "visible";
		}
		if (target.visibility=="visible") {
			if (!ssTrig_pauseOn) {
				posy = parseInt(target.top);
				posx = parseInt(target.left);
				if (isNaN(posx)) posx=190;
				if (isNaN(posy)) posy=ssTrig_doctop;
				nextSpeed = Speed*(Math.abs(Math.min(posy/toTop,posx/toLeft)));
				if (Math.max(Math.abs(posy-toTop),Math.abs(posx-toLeft))>=30) inc=10; else inc=1;
				if (posy!=toTop) target.top=posy+((posy > toTop)? -inc : inc)+"px"; else c++;
				if (posx!=toLeft) target.left=posx+((posx > toLeft)? -inc : inc)+"px"; else c++;
			}
			if (c==2) nextSpeed=100;
			setTimeout("ssTrig_AnimateDiv('"+tid+"',"+topOffset+","+toLeft+","+Speed+")",nextSpeed);
		}
	}
}

		function ssTrig_populateTrigger(tid,ssaction) {
		var offerurl,closeurl;
		switch(tid) { case 13:offerurl = "www.serenitygroup.com/wp-content/themes/serenity/images/button_callout_support.png";closeurl = "www.serenitygroup.com/images/close-window.gif";gn_deptid =1;break; } document.gnofferurl.src = "http://"+offerurl; document.gncloseurl.src = "http://"+closeurl;		ssTrig_onLoadImages(ssaction);
	}
	
function ssTrig_onLoadImages(ssaction) {
	if (document.gnofferurl.complete && document.gncloseurl.complete) eval(ssaction); else setTimeout("ssTrig_onLoadImages('"+ssaction+"')",250);
}
	
function trim(s) 
{
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }
 while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}	

function ssTrig_checkTrigger(tid,sp,to,sek,asl,uvpg) {
	var gn_match,gn_matches,gn_kw,gn_seksg,gn_fk,gn_paths,gn_spa,gn_ci;
	if (to>0) {
		setTimeout("ssTrig_activateInvite("+tid+")",to*1000);
	}
	
	if (sek!="") {
		gn_kw = document.referrer.toLowerCase();
		if (asl==1) gn_q = 0; else gn_q = gn_kw.indexOf('?')+1; 
		if (gn_q>-1) {
		gn_seksg = sek.toLowerCase().split(',');
		for (gn_i=0;gn_i<gn_seksg.length;gn_i++) {
			gn_seks = trim(gn_seksg[gn_i]).split(' ');
			gn_fk=0;
			for (gn_i2=0;gn_i2<gn_seks.length;gn_i2++) {
				if (gn_kw.indexOf(gn_seks[gn_i2],gn_q)!=-1 && gn_seks[gn_i2]!="") gn_fk++;
			}
			if (gn_fk == gn_seks.length && gn_fk>0) {ssTrig_activateInvite(tid); return;}
		}
		}
	}
	
        if (sp!="") {
                gn_match = 0;
                gn_paths = "".toLowerCase().split('|');
                gn_spa = sp.toLowerCase().split('|');
                gn_matches = gn_spa.length;

				if (uvpg==true) {
				for(gn_ci=0;gn_ci<gn_spa.length;gn_ci++) {
					if (document.location.href.toLowerCase().indexOf(gn_spa[gn_ci])>-1) {
						ssTrig_activateInvite(tid);
						return;
					}
				}
				return;
				}
				
                if (gn_matches>1) {
                for(gn_ci=0;gn_ci<gn_paths.length;gn_ci++) {
                   if (gn_paths[gn_ci]!="") {
                        if (gn_paths[gn_ci].indexOf(gn_spa[gn_match])>-1) gn_match++;
						else {
                        	gn_match=0;
                            if (gn_paths[gn_ci].indexOf(gn_spa[gn_match])>-1) gn_match++;
                        }
                   }
                }
                if (gn_match==(gn_matches-1)) {
                        if (document.location.href.toLowerCase().indexOf(gn_spa[gn_match])>-1) {
                                ssTrig_activateInvite(tid);
                        }
                }
                } else {
                        if (document.location.href.toLowerCase().indexOf(gn_spa[0])>-1) {
                                ssTrig_activateInvite(tid);
                        }
                }
        }
}

	
function ssTrig_init() {
	ssTrig_createTextMessage();
	ssTrig_createInvite();}

var ssTrig_pauseOn=false,ssTrig_doctop=0,ssTrig_textMessageOperatorID=0,gn_deptid=0,ssTrig_invited=false;
ssTrig_init();
setTimeout("ssTrig_checkTrigger(13,'',10,'',0,false)",0);
var ss5_cA=0;

function ss_oCA(x) {
	var e,w,h,s;
	switch(x) {case 1:e=false;w=544;h=290;s=0;break;default:x=1;e=false;w=544;h=290;s=0;break;}
	if (x>0) ss_oC(s,x,false,e,w,h); else ss_oC(s,false,-x,e,w,h);
}
function ss_oC(secure,did,uid,ss5e,w,h) {
ss5_cA++;
var ss5_d = new Date(),ss5_bU,sswhi;
ss5_bU=((secure!=null && secure>0)?"https://on.grailnetworks.com/instanton/servicesuite/livehelp/":"http://on.grailnetworks.com/instanton/servicesuite/livehelp/");
if (did>0) sswhi="&deptid="+did; else sswhi="&userid="+uid;
	if (!ss5e) {
		window.open(ss5_bU+"chatframe.on?clientid=20667"+sswhi+"&currentpage="+escape(document.URL)+"&ua="+escape(navigator.userAgent)+"","ServiceSuite_20667","width="+w+",height="+h+",scrollbars=auto,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes");
	} else {
		document.location.href=ss5_bU+"embeddedchat.on?clientid=20667"+sswhi+"&pos="+w+"&l="+h+"";
	}
}
function Neptide_openChat(secure,deptid)
{
	ss_oC(secure,deptid,false,false,544,290);
}
function ss5vis(ss5tg,ss5n) {
	var ss5t=document.getElementById(ss5tg);
	if (ss5t!=null) ss5t.style.visibility=(ss5n)?"visible":"hidden"; 
}
function ss5_aI(ss5_cs,ss5d,ss5ig) {
	var ss5i=document.getElementById('ssChatIconImg'+ss5d);
	switch(ss5_cs) {
		case 0: ss5vis('ssChatIconUnAvail'+ss5d,true);if (ss5i) {if (ss5ig[0].indexOf('http')==-1) ss5ig[0]="http://on.grailnetworks.com"+ss5ig[0];ss5i.src=ss5ig[0];}break;
		case 1: ss5vis('ssChatIconAvail'+ss5d,true);if (ss5i) {if (ss5ig[1].indexOf('http')==-1) ss5ig[1]="http://on.grailnetworks.com"+ss5ig[1];ss5i.src=ss5ig[1];}break;
	}
}
ss5_aI(1,'',new Array('http://www.serenitygroup.com/wp-content/themes/serenity/images/button_callout_support_offline.png','http://www.serenitygroup.com/wp-content/themes/serenity/images/button_callout_support.png'));//copyright(c) 2010 Grail Networks, Inc.