var xmlHttp;
var url;

function Ywindow()
{
	var scrollY = 0;
	
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop )
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}
	
	return scrollY;
}

function showgif()
{
	try
	{
		var divobj = document.getElementById('loading-layer');
	}
	catch(e)
	{
		return;
	}
	
	//----------------------------------
	// Figure width and height
	//----------------------------------
	
	var my_width  = 0;
	var my_height = 0;
	
	if ( typeof( window.innerWidth ) == 'number' )
	{
		my_width  = window.innerWidth;
		my_height = window.innerHeight;
	}
	else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		my_width  = document.documentElement.clientWidth;
		my_height = document.documentElement.clientHeight;
	}
	else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		my_width  = document.body.clientWidth;
		my_height = document.body.clientHeight;
	}
	
	divobj.style.position = 'absolute';
	divobj.style.display  = 'block';
	divobj.style.zIndex   = 99;
	
	var divheight = parseInt( divobj.style.Height );
	var divwidth  = parseInt( divobj.style.Width );
	
	divheight = divheight ? divheight : 55;
	divwidth  = divwidth  ? divwidth  : 54;
	
	var scrolly = Ywindow();
	
	var setX = ( my_width  - divwidth  ) / 2 + 100;
	var setY = ( my_height - divheight ) / 2 + scrolly;
	
	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;
	
	divobj.style.left = setX + "px";
	divobj.style.top  = setY + "px";
}

function hidegif()
{
	try
	{
		var divobj = document.getElementById('loading-layer');
	}
	catch(e)
	{
		return;
	}
	divobj.style.display  = 'none';
}

function sendRating(n, r, vps)
{ 
if (vps == null) 
{
 vps = 0;
}
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null)
 {
 alert ("Your browser does not support HTTP Request. Please, update your browser.");
 return;
 }
showgif();
if (vps == 0) { url = "/brokers/vote.php"; }
else { url = "/vps/vote_vps.php"; }
url = url + "?rate=" + n;
url = url + "&rat=" + r;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function stateChanged()
{ 
if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
 { 
 var temp = new Array();
 temp = xmlHttp.responseText.split('\n');
 hidegif();
 if (temp[1] != '-') 
 {
 try
  {
 var idEl = document.getElementById("brating"+temp[2]); 
 idEl.innerHTML = temp[1];
 idEl = document.getElementById("rating_tool"+temp[2]); 
 idEl.className = "closed";
  }
 catch (e)
  {
  }
 }
else 
{
 alert(temp[0]);
}
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp = new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}