function escapeURLonly(gURL){
	var returnURL = "";
	var headerIdx = gURL.indexOf("://");
	var headerPart = gURL.substring(0,headerIdx+3);
	var urlPart = gURL.substring(headerIdx+3,gURL.length);
	urlPart = escape(urlPart);
	returnURL = headerPart + urlPart;
	return returnURL;
}

document.returnValue = true;
var loadtimerId =0;
var checktimerId = 0;
var loc = document.URL;
loc = escapeURLonly(loc);
var accname = "navrealty";
var checksrv = "http://ultra2.clickchatsold.com";

function lib_bwcheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	plat = new String(navigator.platform);
	if ((plat.toUpperCase()).indexOf("MAC") != -1) { this.mac = true; } 	
	else { this.mac = false; }
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

var bw=new lib_bwcheck()

var cookiepiece = document.cookie.split("; "); 
var time = new Date();
var expiry = new Date(time.getTime() + 5 * 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 checktime = 0;

var lasttime = getCookie(accname+"lasttime");
var ref = getCookie(accname+"ref");

if ( ref == null || ref == "" || ref == "null" ) {
	ref = document.referrer;
	setCookie(accname+"ref",ref);
}

if ( lasttime == null || lasttime == "" || lasttime == "null" ) {
	lasttime = "Never";
}

var refloc = navigator.appName+" ("+navigator.userAgent+")"+"\n"+lasttime+"\n"+ ref;
var extrainfo = escape(refloc);

setCookie(accname+"lasttime",time.toGMTString());

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()+"; path=/;";    
}

var msg;
var tmpimg;

function ccs_checkstatus() {		
	clearTimeout(checktimerId);		
	if ( firstcheck ) {
	     refid = getCookie(accname+"refid");
	     if ( refid == null ) {
	     	refid = 0;
	     } else {
	     	refid ++;
	     }
	     setCookie(accname+"refid",refid+"");	     	      
	     firstcheck = false;	
		if ((bw.mac) && (bw.ie5)) {
			tmpimg = document.images["ccststImg2"];
		} else {
			tmpimg = new Image();								
		}    
			tmpimg.onload = trackresult;  
    	    tmpimg.src = checksrv+"/D0/"+accname+"."+sitecid+"."+extrainfo+"?"+loc+"."+j;	
    	     j++;
	     checktimerId = setTimeout('ccs_checkstatus()',15000);
	} else {	
		if ( refid == getCookie(accname+"refid") ) {			
			if ((bw.mac) && (bw.ie5)) {
				tmpimg = document.images["ccststImg2"];
			} else {
				tmpimg = new Image();								
			}   
			tmpimg.onload = trackresult; 
    	    tmpimg.src = checksrv+"/D0/"+accname+"."+sitecid+".?"+loc+"."+j;	
			if ( checktime <= 480 ) {
				checktimerId = setTimeout('ccs_checkstatus()',15000);
				checktime++;
			}
			j++;
		} 
	}
}

function trackresult(){
	var width = tmpimg.width; 
	if ( width == 2 ) {	
		ccs_doAction();
	}
}

function ccs_doAction() {	
	clearTimeout(checktimerId);	
	ccs_requestchat();
	checktimerId = setTimeout('ccs_checkstatus()',15000);
}

function popChatWin(groupint) {
	// check what to 'pop'
	if (!groupint) 
	 groupint = 0;	
	 	
	ccs_Page = "http://ultra2.clickchatsold.com/D5/"+accname+"."+sitecid+"."+groupint+"."+j;
	tempWinHandle = window.open(ccs_Page, accname,'width=430,height=370,directories=no,location=no,menubar=no,scrollbars=no, status=no,toolbar=no,resizable=no');						 		
	if (tempWinHandle != null && tempWinHandle != "") {
		tempWinHandle.focus();
	}
	j++;
	
}

function ccs_requestchat(){
	
	ccs_Page = "http://ultra2.clickchatsold.com/D9/"+accname+"."+sitecid+".NA.html."+j;
	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');						 		
	if (tempWinHandle != null && tempWinHandle != "") {
		tempWinHandle.focus();
	}
	j++;
	
}

function startup() {	
	clearTimeout(checktimerId);	
	ccs_checkstatus();		
}

function writeImg() {
	if ((bw.mac) && (bw.ie5)) {
		document.write("<img id='ccststImg2' name='ccststImg2' src='http://pic1.clickchatsold.com/images/dottran.gif'>");
	}
}

writeImg();
startup();
