//Last updated: Jan 15th, 06'
function createAjaxObj(){
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
		}
		else if (window.ActiveXObject){ // if IE
			try {
				httprequest=new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					httprequest=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		return httprequest
	}

	var ajaxpack=new Object()
	ajaxpack.basedomain="http://"+window.location.hostname
	//ajaxpack.basedomain="http://localhost/bcfone_fones"
	ajaxpack.ajaxobj=createAjaxObj()
	ajaxpack.filetype="txt"
	ajaxpack.addrandomnumber=0 //Set to 1 or 0. See documentation.
	
	ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype , ident){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
		if (this.ajaxobj){
			this.filetype=filetype
			this.ident=ident
			this.ajaxobj.onreadystatechange=callbackfunc
			this.ajaxobj.open('GET', url+"?"+parameters, true)
			this.ajaxobj.send(null)
		}
	}
	
	ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype, ident){
	ajaxpack.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (this.ajaxobj){
		this.filetype=filetype
		this.ident=ident
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}

function createAjaxObj2(){
	setTimeout('',1000);
	var httprequest=false
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml')
		}
		else if (window.ActiveXObject){ // if IE
			try {
				httprequest=new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					httprequest=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){}
			}
		}
		return httprequest
	}

	var ajaxpack2=new Object()
	ajaxpack2.basedomain="http://"+window.location.hostname
	//ajaxpack.basedomain="http://localhost/bcfone_fones"
	ajaxpack2.ajaxobj=createAjaxObj()
	ajaxpack2.filetype="txt"
	ajaxpack2.addrandomnumber=0 //Set to 1 or 0. See documentation.
	
	ajaxpack2.getAjaxRequest=function(url, parameters, callbackfunc, filetype , ident){
	ajaxpack2.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (ajaxpack2.addrandomnumber==1) //Further defeat caching problem in IE?
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime()
		if (this.ajaxobj){
			this.filetype=filetype
			this.ident=ident
			this.ajaxobj.onreadystatechange=callbackfunc
			this.ajaxobj.open('GET', url+"?"+parameters, true)
			this.ajaxobj.send(null)
		}
	}
	
	ajaxpack2.postAjaxRequest=function(url, parameters, callbackfunc, filetype){
	ajaxpack2.ajaxobj=createAjaxObj() //recreate ajax object to defeat cache problem in IE
	if (this.ajaxobj){
		this.filetype=filetype
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}

ajaxVar = new Array();

function processGet(){
	document.getElementById(ajaxpack.ident).innerHTML = "<div class='carregando'>&nbsp;</div>";
	var myajax=ajaxpack.ajaxobj;
	var myfiletype=ajaxpack.filetype;

	if (myajax.readyState == 4) {
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			if (myfiletype=="txt") {
				document.getElementById(ajaxpack.ident).innerHTML = myajax.responseText;
				extraiScript(myajax.responseText);
			} else {
				alert(myajax.responseXML);
			}
		}
	}
}

function processGetVar(){
	var myajax=ajaxpack.ajaxobj;
	var myfiletype=ajaxpack.filetype;
	if (myajax.readyState == 4) {
		if (myajax.status==200 || window.location.href.indexOf("http")==-1){
			if (myfiletype=="txt") {
				//document.getElementById(ajaxpack.ident).innerHTML = myajax.responseText;
				ajaxVar[ajaxpack.ident] = myajax.responseText;
			} else {
				//alert(myajax.responseXML);
			}
		}
	}
}

function processGetPost(){
	document.getElementById(ajaxpack.ident).innerHTML = "<div class='carregando'>&nbsp;</div>";
	var myajax=ajaxpack.ajaxobj;
	var myfiletype=ajaxpack.filetype;

	if (myajax.readyState == 4) { 
		if (myajax.status==200 || window.location.href.indexOf("http")==-1) {
			if (myfiletype=="txt") {
				document.getElementById(ajaxpack.ident).innerHTML = myajax.responseText;
				extraiScript(myajax.responseText);
			} else {
				alert(myajax.responseXML);
			}
		}
	}
}