// XML HTTP värk võetud lehelt http://www.jibbering.com/2002/4/httprequest.html

var xmlhttp=false;
var xmlEl;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

// IE IMEB RÄMEDALT, JUBE BRAUSER LIHTSALT! Mitte midagi ei suuda see asi standardide järgi teha!
// 3 tundi workaroundide otsimiseks ja külgepookimiseks, et teateaken valmis ehitada!
function isIE() {
 return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function hinnetxt(mis) {
 if (document.getElementById('teade2')) {
   document.getElementById('teadetxt').innerHTML = mis;
   if (isIE()) {
     document.getElementById('teade').style.width = document.documentElement.clientWidth+'px';
     document.getElementById('teade').style.height = document.documentElement.clientHeight+'px';
     window.onscroll = function() {
        document.getElementById('teade').style.top = document.documentElement.scrollTop+'px';
        document.getElementById('teade2').style.top = (document.documentElement.scrollTop+document.documentElement.clientHeight/2)+'px';
     };
     window.onscroll();
   }
   else {
     document.getElementById('teade').style.width = '100%';
     document.getElementById('teade').style.height = '100%';
     document.getElementById('teade').style.position = 'fixed';
     document.getElementById('teade2').style.position = 'fixed';
   }
   document.getElementById('teade').style.visibility = 'visible';
   document.getElementById('teade2').style.visibility = 'visible';
   document.getElementById('ok').focus();
 }
 else alert(mis);
}

function sulge() {
 document.getElementById('teade2').style.visibility = 'hidden';
 document.getElementById('teade').style.visibility = 'hidden';
 if (isIE()) {
   window.onscroll = '';
 }
 else {
 // Firefoxi aeglustumise vältimiseks taastame absolute.
   document.getElementById('teade').style.position = 'absolute';
   document.getElementById('teade2').style.position = 'absolute';
 }
 return false;
}

function xmlreq(mis,op,key) {
 if (xmlhttp.readyState != 4) xmlhttp.abort();
 xmlhttp.open("GET", "?mis=hinda2&id="+mis+"&op="+op+"&key="+key+'&GUINum='+Math.floor(Math.random()*99999999999999999),true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   tekst = xmlhttp.responseText;
   tekst = tekst.split('\n');
   if (tekst[1]) {
     document.getElementById('l'+mis).innerHTML = tekst[1];
	 hinnatud(xmlEl);
   }
   if (tekst[0] && tekst[0] != '-') hinnetxt(tekst[0]);
   else if (tekst[0] != '-') hinnetxt('Hindamisel tekkis viga, palun proovi uuesti.');
  }
 }
 xmlhttp.send(null)
}
function rate(mis,id,key,op1,op2) {
 if (xmlhttp) {
   xmlEl=mis;
   xmlreq(id,op1,key);
 }
 else {
   document.forms.vorm.mis.value = "hinda";
   document.forms.vorm.hinne.value = op2;
   document.forms.vorm.id.value = id;
   document.forms.vorm.key.value = key;
   document.forms.vorm.submit();
 }
 mis.blur();
 return false;
}
function pluss(mis,id,key) {
 return rate(mis,id,key,"p","+");
}
function miinus(mis,id,key) {
 return rate(mis,id,key,"m","-");
}
function hinnatud(mis) {
 mis=mis.parentNode;
 mis.removeChild(mis.childNodes[0]);
 mis.removeChild(mis.childNodes[mis.childNodes.length-1]);
}
