document.returnValue = true;
var loadtimerId =0;
var checktimerId = 0;
var time = new Date();
var realloc = document.URL;
var chop = realloc.indexOf("/",7);
var loc = realloc.slice(chop);
var accname = "ACKSTORM";
var email = "http://www.clickchatsold.com/cgi-bin/noop.cgi?to=atencion.cliente@ackstorm.es";
var requestmsg = "Puedo%20ayudale%3F";
var cookiepiece = document.cookie.split("; "); 
var today = new Date();
var expiry = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000); 
var sitecid = Math.round(Math.random() * 999999 + time.getSeconds() * Math.random() * 999999 + time.getMinutes()* Math.random() * 999999);
var j = Math.round(sitecid+Math.random()*999999*Math.random());
var i = 0;
var tempWinHandle;
var ccs_Page;
var refid = 0;
var firstcheck = true;
var repeat = false;

var refloc = document.referrer;
var relchop = refloc.indexOf("/",7);
var refdomain = refloc.slice(7,relchop);
var curdomain = realloc.slice(7,chop);

if ( refloc == "" ) {
	refloc = getCookie(accname+"refloc",refloc);
}

if ( getCookie(accname+"sitecid") != null ) {
	sitecid =  getCookie(accname+"sitecid");
	repeat = true;
} else {
	setCookie(accname+"sitecid",sitecid);
}

function getCookie(name) { 
    cookiepiece = document.cookie.split("; "); 
    for (var i=0; i < cookiepiece.length; i++) {
      next = cookiepiece[i].split("="); 
      if (next[0] == name) 
        return unescape(next[1]); 
    }
    return null;
}

function setCookie(name, value) { 
    if (value != null && value != "")
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();    
}

var msg;
var tmpimg;
var send_refid = 0;
function ccs_checkstatus() {		
	clearTimeout(checktimerId);		
	if ( firstcheck ) {
	     refid = getCookie(accname+"refid");
	     if ( refid == null ) {
	     	refid = 0;
	     } else {
	     	refid ++;
	     }
	     setCookie(accname+"refid",refid+"");	     	      
	     firstcheck = false;	
	     send_refid = setTimeout('send_ref()',2000);    	     
	}	
	
	if ( refid == getCookie(accname+"refid") ) {	
		
		document.ccsimg.src = "http://trial1.clickchatsold.com/D0/"+accname+"."+sitecid+"."+loc+"."+j;		
		
		checktimerId = setTimeout('ccs_checkstatus()',10000);
		j++;
	} 
		
       

}

function send_ref() {
	clearTimeout(send_refid);
	tmpimg = new Image();
	 if ( refdomain != curdomain ) {
	     	msg = escape("Referrer : "+ refloc +"\nRepeat : "+repeat);
	     	tmpimg.src = "http://trial1.clickchatsold.com/Da/"+accname+"."+sitecid+"."+msg+"."+j;	
	     	if ( refloc != null ) {	
	     		setCookie(accname+"refloc",refloc);
	     	}
	 }	
	         
}
function ccs_doAction() {	
	clearTimeout(checktimerId);	
	ccs_requestchat();
	checktimerId = setTimeout('ccs_checkstatus()',10000);
}

function popChatWin() {
	// check what to 'pop'

	ccs_Page = "http://trial1.clickchatsold.com/D5/"+accname+"."+sitecid+"."+email+"."+j;
	tempWinHandle = window.open(ccs_Page, accname,'width=430,height=350,directories=no,location=no,menubar=no,scrollbars=no, status=no,toolbar=no,resizable=no');						 		
	tempWinHandle.focus();
	j++;
}

function ccs_requestchat(){
	ccs_Page = "http://trial1.clickchatsold.com/D9/"+accname+"."+sitecid+"."+requestmsg+".html";
	tempWinHandle = window.open(ccs_Page, accname+"show",'width=280,height=165,directories=no,location=no,menubar=no,scrollbars=no, status=no,toolbar=no,resizable=no');						 		
	tempWinHandle.focus();
}

function startup() {
	clearTimeout(checktimerId);	
	if (document.ccsimg != null ) {
		
		ccs_checkstatus();
	} else {
		
		checktimerId = setTimeout('startup()',1000);
	}	
}


startup();