var timer;
var midX;
var midY;
var ghwcontent;
var ghalpha=0;

function f_clientWidth() {
	return biggest (window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0);
}
function f_clientHeight() {
	return smallest (window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0);
}
function f_scrollLeft() {
	return smallest (window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0);
}
function f_scrollTop() {
	return smallest (window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0);
}
function biggest(v1, v2, v3) { // return largest number
	var v4 = v1 > v2 ? v1 : v2;
	var v5 = v4 > v3 ? v4 : v3;
	return v5;
}

function smallest(n_win, n_docel, n_body) { // return smallest number
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function ghwgrow(sector)
{
	ghwid=document.getElementById(sector);
	theheight=parseInt(ghwid.offsetHeight);
     if (ghalpha < 100) {
     	ghwid.style.height = (ghalpha*3)+'px';
     	ghwid.style.top = parseInt(midY-(theheight/2))+'px';
		setOpacity(ghwid,ghalpha/100);
		ghalpha = ghalpha+5;
	 	}
	 else {
		setOpacity(ghwid,1);
        clearInterval(timer);
      }
}
function setOpacity(element,level) {
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
}
function setOpacityIE7(element,level) {
  element.style.opacity = level;
  element.style.MozOpacity = level;
  element.style.KhtmlOpacity = level;
  element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}
function ghwshrink(sector)
{
	ghwid=document.getElementById(sector);
	theheight=parseInt(ghwid.offsetHeight);
	
     if (ghalpha >= 5) {
		setOpacity(ghwid,ghalpha/100);
		ghalpha = ghalpha-5;
	 	}
	 else {
		ghwid.style.visibility="hidden";
        clearInterval(timer);
      }
}

function ghw(func,id) {

	midX=f_scrollLeft()+(f_clientWidth()/2);
	midY=f_scrollTop()+(f_clientHeight()/2);
	
	ghwid=document.getElementById('ghwbox');
	ghwid.style.visibility="hidden";
	ghwid.style.left=midX-250+'px';
	setOpacity(ghwid,0);
	ghwid.style.visibility="visible";
	ghwid.innerHTML="";

    timer = setInterval("ghwgrow('ghwbox')", 20);
	document.getElementById('ghwbox').innerHTML="<a href=\"javascript:ghwclose();\"><img style='float:right' src=\"/imgs/close.gif\"></a>Loading...";
	doAjax(func,id,'ghwbox');
}

function ghwclose()
{
      timer = setInterval("ghwshrink('ghwbox')",3);
}

// Generic AJAX functions below this line --------------------------------------------------

function getInData(func,id) {
    var urlparams = "";
	myRand=parseInt(Math.random()*99999999);
	urlparams = urlparams+"func=" + encodeURIComponent(func);
	urlparams = urlparams+"&id=" + encodeURIComponent(id);
	urlparams = urlparams+"&uniq=" + encodeURIComponent(myRand);
	return urlparams;
}

function actOnResult(responseHTML,responsediv) {
	document.getElementById(responsediv).innerHTML=responseHTML;
}

function createRequestObject(url, callback,divname) {

    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      if (req.readyState == 4) { // readyState of 4 signifies request is complete
        if (req.status == 200) { // status of 200 signifies sucessful HTTP call
          if (callback) callback(req.responseText,divname);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
}

function doAjax(func,id,divname){
	var url = '/ajax.php?' + getInData(func,id);
    var ajax = new createRequestObject(url, actOnResult,divname); 
    ajax.doGet();
}



