online_mesg = '&nbsp;';
offline_mesg = '&nbsp;';

String.prototype.rot13 = function(){
    return this.replace(/[a-zA-Z]/g, function(c){
        return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
    });
};

function randomHash(length)
{
  chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  pass = "";
  for(x=0;x<length;x++)
  {
    i = Math.floor(Math.random() * 62);
    pass += chars.charAt(i);
  }
  return pass;
}

function setCookie(c_name,value,exdays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    
    var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
    var i,x,y,ARRcookies=document.cookie.split(";");
    for (i=0; i<ARRcookies.length; i++)
    {
        x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        x=x.replace(/^\s+|\s+$/g,"");
        if (x==c_name)
        {
            return unescape(y);
        }
    }
}

function hook_chat() {
    ses = getCookie('lchat');
    if(!ses)
    {
        ses = randomHash(4);
        setCookie('lchat', ses, 1);
    }
    
    document.write('<div id="ci'+ses+'" style="z-index:100;position:absolute"></div>');
    document.write('<div id="sc'+ses+'" style="display:inline;width:1px;height:1px;margin-top:-1000px;"></div>');
    document.write('<div id="sd'+ses+'" style="display:none"></div>');
    
    sript = document.createElement("script");
    sript.type="text/javascript";
    
    sript_location = (location.protocol.indexOf("https") == 0 ? "https" : "http" )+"://image.providesupport.com/js/customers-support/safe-textlink.js?ps_h="+ses+"&ps_t="+new Date().getTime()+"&online-link-html="+online_mesg+"&offline-link-html="+offline_mesg;
    
    setTimeout("sript.src = sript_location; document.getElementById('sd'+ses).appendChild(sript)",1);
    
    try{
        var x = document.getElementById('hdr-chat');
        x.onclick=function(){document.getElementById('sc'+ses).firstChild.onclick();}
    }catch(e){}
    
};
