var xmlHttp,xmlHttps;

function getXMLHTTPObject() {
	var XMLHttpFactories = [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlHttp = XMLHttpFactories[i]();
			xmlHttps = XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlHttp;
}

function ready(){
	xmlHttp = getXMLHTTPObject();
}

function askConfirm(){
	return confirm("Are You Sure?");
}

var temp;

var header = new Array("fjb","komal","bioskop","kurs");

var spot = new Array();

function change(parentId, status, exts)
{

    //if (document.getElementById(parentId)){
	 //imgicon = document.getElementById(parentId);
	 imgicon = parentId;
	 
	 temp = parentId;
	
	 var off = true;

	 if (status == 1){
	  	imgicon.src = 'http://skin.ngobrolaja.com/v1-9/img/'+imgicon.name+'_on.'+exts;
	 }
	 else if (status == 0){
		var spottemp = getType(parentId.id);
		if (spot[spottemp[0]] == spottemp[1] && spot[spottemp[0]] != null){
			off = false;
		}
		if (off)
			imgicon.src = 'http://skin.ngobrolaja.com/v1-9/img/'+imgicon.name+'_off.'+exts;
	 }
    //}
}

function setPosition(){
	var spottemp = getType(temp.id);
	if (spot[spottemp[0]] != null && spot[spottemp[0]] != spottemp[1]){
		var imgoff = document.getElementById('icon_' + spottemp[0] + '_' + spot[spottemp[0]]);
		imgoff.src = 'http://skin.ngobrolaja.com/v1-9/img/'+imgoff.name+'_off.' + imgoff.src.substr(imgoff.src.length-3);
		spot[spottemp[0]] = null;
	}
	spot[spottemp[0]] = spottemp[1];
}

function getType(spot){
	spot = spot.replace("icon_","");
	spot = spot.split("_");
	return spot;
}

function showingsimpleajax(url,elementid,verspace,horspace){
	ready();
	document.getElementById(elementid).innerHTML = "<IMG src = 'http://skin.ngobrolaja.com/v2-0/img/default/icon_loading.gif' vspace='"+verspace+"' hspace='"+horspace+"'>";
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			document.getElementById(elementid).innerHTML = xmlHttp.responseText;
			document.getElementById("txtshout").focus();
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showingajax(url,loadingid,elementid,verspace,horspace,width,height){
	ready();
	if (url == 'toptab.php'){
		if (spot['fjb'] != null){
			var imgoff = document.getElementById('icon_fjb_' + spot['fjb']);
			imgoff.src = 'http://skin.ngobrolaja.com/v1-9/img/'+imgoff.name+'_off.' + imgoff.src.substr(imgoff.src.length-3);
			spot['fjb'] = null;
		}
	}
	else
		setPosition();
	if (document.getElementById(loadingid))
		document.getElementById(loadingid).innerHTML = "<IMG src = 'http://skin.ngobrolaja.com/v1-9/img/loading.gif' width='" + width + "' height='" + height + "' vspace='"+verspace+"' hspace='"+horspace+"'>";
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			document.getElementById(elementid).innerHTML = xmlHttp.responseText;
			if (document.getElementById(loadingid))
				document.getElementById(loadingid).innerHTML = "";
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showeditshout(shoutid,page){
	var urlsh = "getshout.php?sid="+shoutid+"&pagenow="+page;
	showingsimpleajax(urlsh,"edits",0,0);
}

function xstooltip_findPosX(obj)
{
  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
	{
	    curleft += obj.offsetLeft
	    obj = obj.offsetParent;
	}
    }
    else if (obj.x)
	curleft += obj.x;
    return curleft;
}
function xstooltip_findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
	while (obj.offsetParent)
	{
	    curtop += obj.offsetTop
	    obj = obj.offsetParent;
	}
    }
    else if (obj.y)
	curtop += obj.y;
    return curtop;
}
function xstooltip_show(tooltipId, parentId, posX, posY)
{
    it = document.getElementById(tooltipId);

    imgpic = document.getElementById(parentId);

    if ((it.style.top == '' || it.style.top == 0)
	&& (it.style.left == '' || it.style.left == 0))
    {
	// need to fixate default size (MSIE problem)
	it.style.width = it.offsetWidth + 'px';
	it.style.height = it.offsetHeight + 'px';

	// if tooltip is too wide, shift left to be within parent
	//if (posX + it.offsetWidth > img.offsetWidth) posX = img.offsetWidth - it.offsetWidth;
	//if (posX < 0 ) posX = 0;

	x = xstooltip_findPosX(imgpic) + posX;
	y = xstooltip_findPosY(imgpic) + posY; 

	//get_mouse_pointer_coordinates();

	//x = posx;
	//y = posy+20;

	it.style.top = y + 'px';
	it.style.left = x + 'px';

    }

    it.style.visibility = 'visible';

    /*if (parentId != 'container' && parentId.indexOf('movie') == -1){
	//alert(img.name);
	img.src = 'img/'+img.name+'_on.gif';
    }*/
}
function xstooltip_hide(id,parentId)
{
    it = document.getElementById(id);
    it.style.visibility = 'hidden';
    /*img = document.getElementById(parentId);
    if (parentId != 'container' && parentId.indexOf('movie') == -1){
	img.src = 'img/'+img.name+'_off.gif';
    }*/
}