
function II_checkRules()
{var retRuleID=0;var arrRules=II_getRules();var arrMatchHistory=II_getMatchHistory();if(arrMatchHistory.length==0)
return;for(var idx=0;idx<arrRules.length;idx++)
{var rule=arrRules[idx];var ruleid=II_gtRC("ri",rule);var pagematchtype=II_gtRC("pmt",rule);var pagematch=II_gtRC("pm",rule);var prevpagematchtype=II_gtRC("ppmt",rule);var prevpagematch=II_gtRC("ppm",rule);var ruletype=II_gtRC("rt",rule);var rulevalue1=II_gtRC("rv1",rule);var rulevalue2=II_gtRC("rv2",rule);var rulevalue3=II_gtRC("rv3",rule);var andruletype=II_gtRC("art",rule);var andrulevalue1=II_gtRC("arv1",rule);var andrulevalue2=II_gtRC("arv2",rule);var andrulevalue3=II_gtRC("arv3",rule);if(retRuleID>0)
break;var bPageMatched=false;var bPrevPageMatched=false;if(pagematchtype=='2')bPageMatched=true;if(prevpagematchtype=='0')bPrevPageMatched=true;if((pagematchtype=='0'||pagematchtype==1)&&pagematch.length>0)
{var match1=II_searchLastHistoryEntry(pagematch);if((pagematchtype=='0'&&match1>0)||(pagematchtype=='1'&&match1==0))
bPageMatched=true;}
if((prevpagematchtype=='1'||prevpagematchtype==2)&&prevpagematch.length>0)
{if(prevpagematchtype=='1'&&II_searchPrevHistoryEntry(prevpagematch)>0)
bPrevPageMatched=true;else if(prevpagematchtype=='2'&&document.referrer!=null&&document.referrer.indexOf(prevpagematch)!=-1)
bPrevPageMatched=true;}
if(bPageMatched==true&&bPrevPageMatched==true)
{if(II_checkRuleExceptions(rule)>0)
{switch(ruletype)
{case'100':if(pagematchtype=='0')
{var match1=II_searchAllHistory(pagematch);if(match1>=rulevalue1)
retRuleID=ruleid;}
else if(pagematchtype=='1')
{var match1=II_searchAllHistory(pagematch);if(arrMatchHistory.length-match1>=rulevalue1)
retRuleID=ruleid;}
else if(pagematchtype=='2')
{var match1=arrMatchHistory.length;if(match1>=rulevalue1)
retRuleID=ruleid;}
break;case'102':var cookieval=II_getCookie(rulevalue1);if(cookieval!=null&&cookieval.indexOf(rulevalue2)!=-1)
retRuleID=ruleid;break;case'103':eval("if (typeof(window."+rulevalue1+") != undefined && window."+rulevalue1+" == '"+rulevalue2+"') { retRuleID = ruleid; }");break;case'104':eval("if (typeof(document."+rulevalue1+") != undefined && document."+rulevalue1+".value == '"+rulevalue2+"') { retRuleID = ruleid; }");break;case'105':retRuleID=ruleid;break;default:}
if(retRuleID>0&&andruletype!='0')
{switch(andruletype)
{case'100':if(pagematchtype=='0')
{var match1=II_searchAllHistory(pagematch);if(match1<andrulevalue1)
retRuleID=0;}
else if(pagematchtype=='1')
{var match1=II_searchAllHistory(pagematch);if(arrMatchHistory.length-match1<andrulevalue1)
retRuleID=0;}
else if(pagematchtype=='2')
{var match1=arrMatchHistory.length;if(match1<andrulevalue1)
retRuleID=0;}
break;case'102':var cookieval=II_getCookie(andrulevalue1);if(cookieval==null||cookieval.indexOf(andrulevalue2)==-1)
retRuleID=0;break;case'103':eval("if (typeof(window."+andrulevalue1+") != undefined && window."+andrulevalue1+" == '"+andrulevalue2+"') { retRuleID = ruleid; } else { retRuleID = 0; }");break;case'104':eval("if (typeof(document."+andrulevalue1+") != undefined && document."+andrulevalue1+".value == '"+andrulevalue2+"') { retRuleID = ruleid; } else { retRuleID = 0; }");break;case'105':retRuleID=ruleid;break;default:}}}}}
return(retRuleID);}
function II_checkRuleExceptions(rule)
{var retRuleID=II_gtRC("ri",rule);var excprevoffercount=II_gtRC("epoc",rule);var excprevoffertime=II_gtRC("epot",rule);var excprevvisit=II_gtRC("epv",rule);var exconlyprevvisit=II_gtRC("eopv",rule);if(excprevoffercount.length>0)
{var pages=II_gtSV("PrevOfferCount");if(pages!=''&&pages>=excprevoffercount)
return(0);}
if(excprevoffertime.length>0)
{var ii_time=II_gtSV("PrevOfferTime");if(ii_time!='')
{var ii_curTime=new Date().getTime();ii_time=parseInt(ii_time)+(parseInt(excprevoffertime)*1000);if(ii_curTime<ii_time)
return(0);}}
if(excprevvisit.length>0)
{arrPrev=excprevvisit.split('^');if(arrPrev!=null&&arrPrev.length>0)
{for(var idx=0;idx<arrPrev.length;idx++)
{var match1=II_searchAllHistory(arrPrev[idx]);if(match1>0)
return(0);}}}
if(exconlyprevvisit.length>0)
{arrOnlyPrev=exconlyprevvisit.split('^');if(arrOnlyPrev!=null&&arrOnlyPrev.length>0)
{for(var idx=0;idx<arrOnlyPrev.length;idx++)
{var match1=II_searchAllHistory(arrOnlyPrev[idx]);if(match1==0)
return(0);}}}
return(retRuleID);}
function II_searchAllHistory(matchValue)
{var matchCount=0;var arrMatchHistory=II_getMatchHistory();if(arrMatchHistory.length>0)
{for(var idx=arrMatchHistory.length-1;idx>=0;idx--)
{var histEntryMatches=arrMatchHistory[idx].split('```');for(var idx2=0;idx2<histEntryMatches.length;idx2++)
{var singleRuleDetails=histEntryMatches[idx2].split('`');var search=singleRuleDetails[0];if(search==matchValue)
matchCount++;}}}
return(matchCount);}
function II_searchLastHistoryEntry(matchValue)
{var matchCount=0;var arrMatchHistory=II_getMatchHistory();if(arrMatchHistory.length>0)
{var histEntryMatches=arrMatchHistory[arrMatchHistory.length-1].split('```');for(var idx=0;idx<histEntryMatches.length;idx++)
{var singleRuleDetails=histEntryMatches[idx].split('`');var search=singleRuleDetails[0];if(search==matchValue)
{matchCount++;break;}}}
return(matchCount);}
function II_searchPrevHistoryEntry(matchValue)
{var matchCount=0;var arrMatchHistory=II_getMatchHistory();if(arrMatchHistory.length>1)
{var histEntryMatches=arrMatchHistory[arrMatchHistory.length-2].split('```');for(var idx=0;idx<histEntryMatches.length;idx++)
{var singleRuleDetails=histEntryMatches[idx].split('`');var search=singleRuleDetails[0];if(search==matchValue)
{matchCount++;break;}}}
return(matchCount);}
function II_doAvailCheck(ruleid)
{var rule=II_gtRS(ruleid);var deptid=II_gtRC("idi",rule);if(deptid=='-2')deptid='Default';var timestamp=(new Date()).getTime();II_gAvailableImage.src=II_gProtocol+'://admin.instantservice.com/resources/smartbutton/'+II_gAccountID+'/'+deptid+'/available.gif?ts='+timestamp;}
var II_gAvailableImage=null;if(II_gUsingIE||II_gUsingNS)
{if(navigator.appName.indexOf("Microsoft")!=-1&&navigator.platform.indexOf("Mac")!=-1)
II_gAvailableImage=document.createElement('IMG');else
II_gAvailableImage=new Image();}
II_gAvailableImage.onload=function(evt)
{II_gAgentsAvail=true;var timestamp=(new Date()).getTime();var ii_srcFile=(II_gUsingTestServers)?"/II_TestRules.js":"/II_Rules.js";callServer(II_gProtocol+'://admin.instantservice.com/resources/smartbutton/'+II_gAccountID+ii_srcFile+'?ts='+timestamp);}
II_gAvailableImage.onerror=function(evt)
{II_gAgentsAvail=false;if(II_gtRC("av",II_gtRS(II_gRuleID))=="0")
{var timestamp=(new Date()).getTime();var ii_srcFile=(II_gUsingTestServers)?"/II_TestRules.js":"/II_Rules.js";callServer(II_gProtocol+'://admin.instantservice.com/resources/smartbutton/'+II_gAccountID+ii_srcFile+'?ts='+timestamp);}}
NS6=false;IE4=(document.all);if(!IE4){NS6=(document.getElementById);}
NS4=(document.layers);function adjust(){if((NS4)||(NS6)){if(lastX==-1||delayspeed==0)
{lastX=window.pageXOffset+floatX;lastY=window.pageYOffset+floatY;}
else
{var dx=Math.abs(window.pageXOffset+floatX-lastX);var dy=Math.abs(window.pageYOffset+floatY-lastY);var d=Math.sqrt(dx*dx+dy*dy);var c=Math.round(d/10);if(window.pageXOffset+floatX>lastX){lastX=lastX+delayspeed+c;}
if(window.pageXOffset+floatX<lastX){lastX=lastX-delayspeed-c;}
if(window.pageYOffset+floatY>lastY){lastY=lastY+delayspeed+c;}
if(window.pageYOffset+floatY<lastY){lastY=lastY-delayspeed-c;}}
if(NS4){document.layers['floatlayer'].pageX=lastX;document.layers['floatlayer'].pageY=lastY;}
if(NS6){document.getElementById('floatlayer').style.left=lastX;document.getElementById('floatlayer').style.top=lastY;}}
else if(IE4){if(lastX==-1||delayspeed==0)
{lastX=document.body.scrollLeft+floatX;lastY=document.body.scrollTop+floatY;}
else
{var dx=Math.abs(document.body.scrollLeft+floatX-lastX);var dy=Math.abs(document.body.scrollTop+floatY-lastY);var d=Math.sqrt(dx*dx+dy*dy);var c=Math.round(d/10);if(document.body.scrollLeft+floatX>lastX){lastX=lastX+delayspeed+c;}
if(document.body.scrollLeft+floatX<lastX){lastX=lastX-delayspeed-c;}
if(document.body.scrollTop+floatY>lastY){lastY=lastY+delayspeed+c;}
if(document.body.scrollTop+floatY<lastY){lastY=lastY-delayspeed-c;}}
document.all['floatlayer'].style.posLeft=lastX;document.all['floatlayer'].style.posTop=lastY;}
setTimeout('adjust()',50);}
function define()
{if((NS4)||(NS6))
{if(halign=="left"){floatX=ifloatX};if(halign=="right"){floatX=window.innerWidth-ifloatX-layerwidth-20};if(halign=="center"){floatX=Math.round((window.innerWidth-20)/2)-Math.round(layerwidth/2)};if(valign=="top"){floatY=ifloatY};if(valign=="bottom"){floatY=window.innerHeight-ifloatY-layerheight};if(valign=="center"){floatY=Math.round((window.innerHeight-20)/2)-Math.round(layerheight/2)};}
if(IE4)
{if(halign=="left"){floatX=ifloatX};if(halign=="right"){floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
if(halign=="center"){floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
if(valign=="top"){floatY=ifloatY};if(valign=="bottom"){floatY=document.body.offsetHeight-ifloatY-layerheight}
if(valign=="center"){floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}}}
var II_ENABLED=true;var II_MAX_RULEMATCHLIST_SIZE=30;var II_COOKIE_EXPIRATION=new Date();var II_gRuleID=0;var II_gInvitationID=0;var II_gUsingTestServers=false;var II_gAgentsAvail=false;function ruleCheck()
{if(II_gtSV("RuleTriggered")!="true")
{II_gRuleID=II_checkRules();if(II_gRuleID>0)
{var ii_timesince=parseInt(II_gtSV('TimeSinceLastCheck'));var ii_wtl=parseInt(II_gtRC("wtl",II_gtRS(II_gRuleID)));if(ii_timesince>=ii_wtl||ii_wtl=='99999')
{II_upSV('RuleTriggered','true');II_gInvitationID=II_gtRC("ii",II_gtRS(II_gRuleID));II_doAvailCheck(II_gRuleID);}}
setTimeout("II_upSV('TimeSinceLastCheck', parseInt(II_gtSV('TimeSinceLastCheck')) + 5);ruleCheck()",5000);}}
if(II_gUsingIE||II_gUsingNS)
{II_COOKIE_EXPIRATION.setTime(II_COOKIE_EXPIRATION.getTime()+(182*30*24*60*60*1000));if(II_getCookie(II_gTSCookieName)==null)
II_createTestServersCookie();if(II_getUsingTestServers())
II_gUsingTestServers=true;if(II_getRules().length==0)
{if(II_gUsingTestServers)II_createRulesCookie("test");else II_createRulesCookie("live");}
if(II_updateMatchHistoryCookie())
{ruleCheck();}}