/* 
	AJAX & window library routines
	bx]l[ab 2007
*/

function xmlObj(){
	if (window.XMLHttpRequest){
		var obj = new XMLHttpRequest();
	} else {
		var obj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return obj;
}

function getEl(el){
	if (document.getElementById) {
		return document.getElementById(el);
	} else if (document.all) {
		return document.all[id];
	}
}

function setEl(el, content){
	if (document.getElementById) {
		var obj = document.getElementById(el);
		obj.innerHTML = content;
	} else if (document.all) {
		var obj = document.all[id];
		obj.innerHTML = content;
	}
}

function setFormEl(el, content){
	if (document.getElementById) {
		var obj = document.getElementById(el);
		obj.value = content;
	} else if (document.all) {
		var obj = document.all[id];
		obj.value = content;
	}
}

document.write('<span id=tooltip style="position: absolute; display: hidden; top:0px; left: 0px;"></span>');

function showTooltip(text){
	var obj=getEl("tooltip");
	obj.style.visibility="visible";
	setEl('tooltip',text);
}

function hideTooltip(){
	var obj=getEl("tooltip");
	obj.style.visibility="hidden";
}

function showWindow(title){
	var obj=getEl("window");
	obj.style.visibility="visible";
	setEl('title','<b>'+title+'</b>');
}

function hideWindow(){
	var obj=getEl("window");
	obj.style.visibility="hidden";
}
/*
	set element  
*/
function ajaxSetEl(url, el, call){
	var obj = xmlObj();
	setEl(el,"Loading...");
	obj.onreadystatechange=function(){
		if (obj.readyState==4) {
			if (obj.status==200) {
				//alert(" "+obj.status+"\r\nRequest: "+url);
				setEl(el,obj.responseText);
				if(call) call();
			} else {
				//alert("warning: ajax request returned "+obj.status+"\r\nRequest: "+url);
				setEl(el,"Error loading "+url);
			}

		} else {
			//alert(obj.status+url +  obj.readyState);
		}
	}
	obj.open("GET",url,true);
	obj.send(null);
//	ajaxBusy= false;
}

function ajaxGetJS(url, el){
	var obj = xmlObj();
	obj.onreadystatechange=function(){
		if (obj.readyState==4) {
			if (obj.status==200) {
				//alert(" "+obj.status+"\r\nRequest: "+url);
				eval(obj.responseText);
			} else {
				alert("warning: ajax request returned "+obj.status+"\r\nRequest: "+url);
			}
		}
	}
	obj.open("GET",url,true);
	obj.send(null);
}


function sizeElement(el,width, height, steps){
	var e=getEl(el);
	var x=parseInt(e.style.width);
	var y=parseInt(e.style.height);
	var newx=x + Math.round((width - x) / steps);
	var newy=y + Math.round((height - y) / steps);
	e.style.width=newx+'px';
	e.style.height=newy+'px';
	e.width=newx;
	e.height=newy;

	steps--;
	if (steps>0)
		setTimeout('sizeElement("'+el+'",'+width+','+height+','+steps+');',500);
}

function bounceEl(el,width, height, steps){
	var e=getEl(el);
	e.width=0;
	e.height=0;
	e.display='none';
	e.style.width='auto';
	e.style.height='auto';
	setTimeout('sizeElement("'+el+'",'+width+','+height+','+steps+');',500);
}

function ajaxGetDoc(url, callbackFunc){
	var obj = xmlObj();
	obj.onreadystatechange=function(){
		if (obj.readyState==4) {
			if (obj.status==200) {
				callbackFunc(obj.responseText);
				//setEl(el,obj.responseText);
			} else {
				alert("warning: ajax request returned "+obj.status+"\r\nRequest: "+url);
			}
		}
	}
	obj.open("GET",url,true);
	obj.send(null);
}

function ajaxSetFormEl(url, el){
	var obj = xmlObj();
	obj.onreadystatechange=function(){
		if (obj.readyState==4) {
			if (obj.status==200) {
				setFormEl(el,obj.responseText);
			} else {
				alert("warning: ajax request returned "+obj.status+"\r\nRequest: url");
			}
		}
	}
	obj.open("GET",url,true);
	obj.send(null);
}

function ajaxPostForm(url){
	var obj = xmlObj();
	obj.onreadystatechange=function(){
		if (obj.readyState==4) {
			if (obj.status==200) {
				//alert(obj.responseText+' element: '+ el);
			} else {
				alert("warning: ajax request returned "+obj.status+"\r\nRequest: "+url);
			}
		}
	}
	obj.open("POST",url,true);
	obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	obj.send(null);
}

function toggleDelBtns(formname){
	var form=eval('document.'+formname);
	var newstate=form.delbtn.checked;
	for(var i=0;i<form.elements.length;i++){
		var e=form.elements[i];
		if(e.type=='checkbox'){
			e.checked=newstate;
		}
	}
}

function ToggleDiv(id,visible){
	var el = getEl(id);
	if(el){
		el.style.display=(visible==true?"block;":"none;");
	}
}

function ToggleLang(level,index,max){
	for(var i=0;i<max;i++){
		var obj = getEl('form'+i+'_'+level);
		if(obj!=null){
			obj.style.display = (i==index)?'block':'none';
		}
	}
}

function ToggleLangAll(level,max){
	for(var i=0;i<max;i++){
		var obj = getEl('form'+i+'_'+level);
		if(obj!=null){
			obj.style.display = 'block';
		}
	}
}
