
function ajax_submit(fId,divId,url) {

	new Ajax.Updater(divId,url, {
		method:'post',
		parameters: $(fId).serialize(true),
		evalScripts:true
	});
	return false;
}

function enableFormButtons(fId) {
		
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}


function setAdminUnitSelect(html_id,parent_id)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}

	var url="ajax.php"
	url=url+"?type=admin_units"
	url=url+"&parent_id="+parent_id
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			select_innerHTML(document.getElementById(html_id),xmlHttp.responseText);
			//document.getElementById(html_id).innerHTML=xmlHttp.responseText
			
		}
	}
	xmlHttp.send(null)


}

function setBankAdmins(html_id,parent_id)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}

	var url="ajax.php"
	url=url+"?type=bank_admins"
	url=url+"&parent_id="+parent_id
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			select_innerHTML(document.getElementById(html_id),xmlHttp.responseText);
			//document.getElementById(html_id).innerHTML=xmlHttp.responseText
			
		}
	}
	xmlHttp.send(null)


}

function setLoanTypeSelect(html_id,parent_id,empty)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}

	var url="ajax.php"
	url=url+"?type=loan_types"
	url=url+"&parent_id="+parent_id
	url=url+"&html_id="+html_id
	if (empty==1) url=url+"&e=1"
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			select_innerHTML(document.getElementById(html_id),xmlHttp.responseText);
			//document.getElementById(html_id).innerHTML=xmlHttp.responseText
			//setReqEntryText()
		}
	}
	xmlHttp.send(null)


}

function setReqEntryText()
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}

	var url="ajax.php"
	url=url+"?type=req_entrytext"
	if (document.getElementById("loantype")) url=url+"&f1="+document.getElementById("loantype").value
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			if (document.getElementById("req_entrytext")) document.getElementById("req_entrytext").innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send(null)


}

function runAjaxComm(comm,html_id,value)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}
	
	var url="ajax.php"
	url=url+"?type="+comm
	url=url+"&value="+value
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			document.getElementById(html_id).innerHTML=xmlHttp.responseText
			//setReqEntryText()
		}
	}
	xmlHttp.send(null)


}

function runAjaxCommSelect(comm,html_id,value)
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}
	
	var url="ajax.php"
	url=url+"?type="+comm
	url=url+"&value="+value
	url=url+"&sid="+Math.random()
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			select_innerHTML(document.getElementById(html_id),xmlHttp.responseText);
			
			//setReqEntryText()
		}
	}
	xmlHttp.send(null)


}



function select_innerHTML(objeto,innerHTML){
/******
* select_innerHTML - innerHTML to add option(s) to select(s)
* Problem: http://support.microsoft.com/default.aspx?scid=kb;en-us;276228
* Creative Commons license
* Versão: 1.0 - 06/04/2006
* Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br - elmicoxcodes.blogspot.com
* Parametros:
* objeto(tipo object): the select
* innerHTML(tipo string): the new innerHTML
*******/
    objeto.innerHTML = ""
    //creating phantom element to receive temp innerHTML
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    
    if(innerHTML.toLowerCase().indexOf("<option")<0){//if not option, convert do option
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
    //alert(innerHTML)
    //transfering childs of phantom element to options
    for(var i=0;i<selTemp.childNodes.length;i++){
        if(selTemp.childNodes[i].tagName){
            opt = document.createElement("OPTION")
            for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
                opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true))
            }
            opt.value = selTemp.childNodes[i].getAttribute("value")
            opt.text = selTemp.childNodes[i].innerHTML
            if(document.all){ //IEca
                objeto.add(opt)
            }else{
                objeto.appendChild(opt)
            }                    
        }    
    }
    //clear phantom
    document.body.removeChild(selTemp)
    selTemp = null
}

var sUrl="?";
	

function refreshSession()
{
	var xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support the XMLHttpRequest object.")
		return
	}

	var url="touch.php"
	xmlHttp.open("GET", url,true);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4) {
			document.getElementById("sessinfo").innerHTML=xmlHttp.responseText;
			
			if (xmlHttp.responseText=='logout') {
				clearInterval(sessInterval);
				window.location.href=sUrl;
			}
			
		}
	}
	xmlHttp.send(null)


}


