var f = false;

var p_b = '0';
var p_bot = '0';
var p_os = '0';
var p_sr = screen.width+'x'+screen.height;
var p_cd = screen.colorDepth; // -bit

var ua = navigator.userAgent.toLowerCase();

if(ua.indexOf('america online browser') != -1){p_b = '3';} 
else if(ua.indexOf('konqueror') != -1){p_b = '5';}
else if(ua.indexOf('minimo') != -1){p_b = '6';}
else if(ua.indexOf('seamonkey') != -1){p_b = '7';}
else if(ua.indexOf('netpositive') != -1){p_b = '9';}
else if(ua.indexOf('omniweb') != -1){p_b = '10';}
else if(ua.indexOf('playstation') != -1){p_b = '12';}
else if(ua.indexOf('safari') != -1){p_b = '13';}
else if(ua.indexOf('camino') != -1){p_b = '14';}
else if(ua.indexOf('offbyone') != -1){p_b = '15';}
else if(ua.indexOf('opera') != -1){p_b = '11';} 
else if(ua.indexOf('avantbrowser') != -1){p_b = '4';} 
else if(ua.indexOf('firefox') != -1){p_b = '2';} 
else if(ua.indexOf('bonecho') != -1){p_b = '16';} 
else if(ua.indexOf('msie') != -1){p_b = '1';} 
else if(ua.indexOf('netscape') != -1){p_b = '8';} 
else {p_b = '0';}

if(ua.indexOf('linux') != -1){p_os = '2';} 
else if(ua.indexOf('x11') != -1){p_os = '3';} 
else if(ua.indexOf('mac') != -1){p_os = '4';} 
else if(ua.indexOf('win') != -1){p_os = '1';} 
else {p_os = '0';}

// if(ua.indexOf('ia_archiver') != -1){p_bot = '4';} 
// else if(ua.indexOf('jeeves') != -1){p_bot = '5';} 
// else if(ua.indexOf('gigabot') != -1){p_bot = '6';} 
// else if(ua.indexOf('grub-client') != -1){p_bot = '11';}
// else if(ua.indexOf('baiduspider') != -1){p_bot = '8';}
// else if(ua.indexOf('gamespy') != -1){p_bot = '9';} 
// else if(ua.indexOf('msnbot') != -1){p_bot = '7';} 
// else if(ua.indexOf('scooter') != -1){p_bot = '10';} 
// else if(ua.indexOf('yahoo-mmcrawler') != -1 || ua.indexOf('yahoo! slurp') != -1 || ua.indexOf('.yahoo.') != -1 || ua.indexOf('.inktomi.') != -1){p_bot = '3';} 
// else if(ua.indexOf('googlebot-image') != -1){p_bot = '2';} 
// else if(ua.indexOf('googlebot') != -1){p_bot = '1';} 
// else{p_bot = '0';}

if(p_sr=='1024x768'){p_sr='1';}
else if(p_sr=='800x600'){p_sr='2';}
else if(p_sr=='1280x1024'){p_sr='3';}
else if(p_sr=='1152x864'){p_sr='4';}
else if(p_sr=='1280x800'){p_sr='5';}
else if(p_sr=='1280x960'){p_sr='6';}
else if(p_sr=='1400x1050'){p_sr='7';}
else if(p_sr=='1600x1200'){p_sr='8';}
else if(p_sr=='1280x768'){p_sr='9';}
else if(p_sr=='1680x1050'){p_sr='10';}
else if(p_sr=='1440x900'){p_sr='11';}
else if(p_sr=='1280x720'){p_sr='12';}
else if(p_sr=='640x480'){p_sr='13';}
else if(p_sr=='960x600'){p_sr='14';}
else{p_sr='0';}

if(p_cd=='32'){p_cd='1';}
else if(p_cd=='16'){p_cd='2';}
else if(p_cd=='24'){p_cd='3';}
else if(p_cd=='8'){p_cd='4';}
else{p_cd='0';}

// ASYNCHRONOUS REQUEST SENDING
function RequestObject() {
	var ro;
    if (window.XMLHttpRequest) {
		ro = new XMLHttpRequest();
		if (ro.overrideMimeType) {
			ro.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) {
	    try {
            ro = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ro = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
	}
    return ro;
}

var http = RequestObject();

function Response() {
	if (http.readyState == 4) {
		if(http.status == 200){
			results = http.responseText; // http.responseXML;
			f = false; // re-activate the AJAX function
		}
	}
}

function hitThisPage(cid, page, ip) {
	if (!f && http) {
		var sendf = "cid="+cid+"&p_sr="+p_sr+"&p_cd="+p_cd+"&p_b="+p_b+"&p_os="+p_os+"&page="+page+"&ip="+ip;
		if(p_bot != '0'){
			sendf += '&p_bot='+p_bot;
		}
		http.open("POST", "/hit", true);
		http.onreadystatechange = Response;
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.send(sendf);
		f = true;
	}
}
