// JavaScript Document
var url = document.location.href;
var xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);
var allElements = "";
var loadingZone = 1;

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	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 local(objectXY) {
	var hscroll=f_scrollLeft();
	var vscroll=f_scrollTop();
	document.getElementById(objectXY).style.left=hscroll+'px';
	document.getElementById(objectXY).style.top=vscroll+'px';
}

function ajax_do(url,func,name) {
        // Does URL begin with http?
		if (loadingZone==1) {
			document.getElementById('ajaxZoneLoading'+name).className='ajaxZoneLoadingVisible';
			var ajaxInterval=setInterval("local('ajaxZoneLoading"+name+"')",20);
		}

        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }
        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url+'?ajaxZoneFunction='+func+'&ajaxZoneName='+name+getAll();

		// Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);

}

function getAll() {
	elements=allElements.split(",");
	query="";
	for (i=0;i<elements.length;i++) {
		if ((document.getElementById(elements[i]).tagName.toLowerCase()=="input") || (document.getElementById(elements[i]).tagName.toLowerCase()=="select") || (document.getElementById(elements[i]).tagName.toLowerCase()=="textarea")) {
			if (document.getElementById(elements[i]).type.toLowerCase()!="image")
				query+="&"+elements[i]+"->value="+escape(document.getElementById(elements[i]).value);
			if ((document.getElementById(elements[i]).type.toLowerCase()=="checkbox") || (document.getElementById(elements[i]).type.toLowerCase()=="radio")) {
				if (document.getElementById(elements[i]).checked)
					tmp="true";
				else
					tmp="false";
				query+="&"+elements[i]+"->checked="+escape(tmp);
			}
		} else
			query+="&"+elements[i]+"->innerHTML="+escape(document.getElementById(elements[i]).innerHTML);
	}
	return query;
}

function innerHTML(id,text) {
	document.getElementById(id).innerHTML=text;
}

function value(id,text) {
	document.getElementById(id).value=text;
}

function addOption(id,text,value) {
	document.getElementById(id).options.add(new Option(text,value));
}

function clearOptions(id) {
	document.getElementById(id).options.length=0;
}

function delOption(id,index) {
	document.getElementById(id).options[index]=null;
}

function className(id,name) {
	document.getElementById(id).className=name;
}

function enabled(option) {
	document.getElementById(id).disabled=option;
}

function checked(id,yesno) {
	document.getElementById(id).checked=yesno;	
}

function setFocus(id) {
	document.getElementById(id).focus();
}

function createLoading(id,align,text) {
	div=document.createElement("div");
	div.id=id;
	div.align=align;
	div.innerHTML=text;
	div.className='ajaxZoneLoadingHide';
	document.body.appendChild(div);
}

function objScript(text) {
	jscript=document.createElement("SCRIPT");
    jscript.type='text/javascript';
	jscript.language='javascript';
	jscript.text=text;
	document.body.appendChild(jscript);
}

function executeJavaScript(text) {
	eval(text);
}
