var isMinNS4 = (document.layers) ? 1 : 0;

var isMinIE4 = (document.all)    ? 1 : 0;

var SITEURL = 'http://www.nickgregan.com/';	



function nick_rate(type, ncount, id_num, uip, units)

{	

	var theUL = document.getElementById('unit_ul'+type+id_num); // the UL	

	var RateURL=SITEURL+"rate.php?type="+type+"&j="+ncount+"&q="+id_num+"&t="+uip+"&c="+units;	

	theUL.innerHTML = '<div class="loading"></div>'; // Loading process

	http_nick.open("GET", RateURL , true);

	http_nick.onreadystatechange = handlehttpResponse;

	http_nick.send(null);

}

function handlehttpResponse() {

 	if (http_nick.readyState == 4) 

	{

    	if (http_nick.status == 200)

		{       	

			var response = http_nick.responseText;

			//alert(response);

			var update = new Array();

	

			if(response.indexOf('|') != -1) {

				update = response.split('|');			   				
			   	update[0]=replace(update[0],"\n","");
				update[0]=replace(update[0],"\r","");
				changeRate(trim(update[0]), trim(update[1]));

			}

		}		

  	}

}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function nick_desc(type, id_num, len, dstatus)

{	

	//var theUL = document.getElementById('desc'+type+id_num);

	//theUL.innerHTML = '<div class="loading"></div>'; // Loading process

	

	var DURL=SITEURL+"desc.php?t="+type+"&i="+id_num+"&l="+len+"&s="+dstatus;	

	http_nick.open("GET", DURL , true);

	http_nick.onreadystatechange = handlehttpResponse_Desc;

	http_nick.send(null);

}



function handlehttpResponse_Desc() {

 	if (http_nick.readyState == 4) 

	{

    	if (http_nick.status == 200)

		{       	

			var response = http_nick.responseText;

			//alert(response);

			var update = new Array();

	

			if(response.indexOf('^') != -1) {

				update = response.split('^');			   
				changeRate(ltrim(update[0]), ltrim(update[1]));

			}

		}		

  	}

}

function changeRate( div2show, text ) {  

	
    var IE = (document.all) ? 1 : 0;

    var DOM = 0; 

    if (parseInt(navigator.appVersion) >=5) {DOM=1};	

    if (DOM) {

        var viewer = document.getElementById(div2show);
		viewer.innerHTML="";
        viewer.innerHTML = text;

    }  else if(IE) {

        document.all[div2show].innerHTML = text;

    }

}

function mousepos(){		

	

	if (isMinNS4)

  	{

		bt="ns";

  	}

  	else if (isMinIE4)

  	{

		bt="ie";

  	}

  	else

  	{

		bt="ot";

  	}

	var x=document.nick_mouse.MouseX.value;

	var y=document.nick_mouse.MouseY.value;

	if(bt != "ie")

	{

		x=x+"px";

		y=y+"px";

	}

	var xyPos = x + ":" + y;

	return xyPos;

}

function getHTTPObject_rat()

{

  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

  try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }
  return xmlhttp;
}
var http_nick = getHTTPObject_rat(); // We create the HTTP Object
function replace(string,text,by) {
var strLength = string.length, txtLength = text.length;
if ((strLength == 0) || (txtLength == 0)) return string;
var i = string.indexOf(text);
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
var newstr = string.substring(0,i) + by;
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength),text,by);
return newstr;
}