/*********************************************************
   JS Utilities used for this site 
   By Sasa Jovanovic
**********************************************************/

/* Returns elemnt position */
function getElementPos(el) {
    if(typeof(el.offsetParent) == "undefined")
        return [70, 4000];
	var a = new Array(0,0);
	while(el)
	{
		a[0] += el.offsetLeft || 0;
		a[1] += el.offsetTop || 0;
		el = el.offsetParent || null;
	}
	return a;
}

/* sets opacity of element */
function setOpacity(ID,v) {
	var t=document.getElementById(ID)
	t.style['opacity'] = v / 100;
	t.style['-moz-opacity'] = v / 100;
	if(t.filters) t.filters.alpha['opacity'] = v;
}

/* Ajax utils */
function xmlhttpGet() {

   this.xmlhttpGet = function (strURL, qstr, ID,fncToExec) {
      var xmlHttpReq = false;
      var self = this;
      // Mozilla/Safari
      if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
      }
      // IE
      else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      self.xmlHttpReq.open('GET', strURL, true);
      self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      self.xmlHttpReq.onreadystatechange = function() {
         if (self.xmlHttpReq.readyState == 4) {
             updatepage(self.xmlHttpReq.responseText,ID,fncToExec)
         } //else {
            //document.getElementById(ID).innerHTML = self.xmlHttpReq.responseText;
		 //}
			
      }
      self.xmlHttpReq.send(qstr);
   }

   function updatepage(str,ID,fncToExec){
       document.getElementById("ajaxContent").style.backgroundImage="url(images/spacer.gif)"  
	   if (str.indexOf("Error")>0 && str.indexOf("404")>0) {
		 document.getElementById(ID).innerHTML="Server Error: File not found. "
	   } else { 
         document.getElementById(ID).innerHTML = str;
	   }
	   if (fncToExec!=undefined) {
		   setTimeout(fncToExec,100);
	   }
   }
}

/* Other stuff */
function gotoHomePage() {
	document.location.href="index.html"
}




