// JavaScript Document

var _ajax = { handler: {}, idCounter: 0 }; // a prop handler do obj permite várias conexões  simultaneas

function makeHttpRequest(url, send_n_load, params, meth){ 


	
	this.id = ++_ajax.idCounter;
	_ajax.handler[this.id] = this; //estancio o proprio objeto para handler com um id unico
	this.meth = meth ? meth : 'GET';	
	this.url = url;	
	this.params = this.meth == 'POST' ? params : null;
	this.paramsforGet = this.meth == 'GET' ? '?'+params : '';
	this.http_request = false;
	this.oReturn = send_n_load;

	this.init = function(){ // inicializa o objeto XMLHttpRequest
		if (window.XMLHttpRequest) { // Mozilla, Safari,... 
		this.http_request = new XMLHttpRequest(); 
				   //if (this.http_request.overrideMimeType) { 
					  // this.http_request.overrideMimeType('text/xml'); 
				   //} 
		} else if (window.ActiveXObject) { // IE 
			try { 
			this.http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
			} catch (e) { 
				try { 
				this.http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
				} catch (e) {} 
			} 
		} 
	}

this.init();
//alert(this.url);

   if (!this.http_request) { 
       alert('No browser support'); 
       return false; 
   } 
   
   this.http_request.onreadystatechange = new Function("_ajax.handler["+this.id+"].onChange();");   
   
   this.onChange = function() {
	// alert("here");
       if (this.http_request.readyState == 4) { 
           if (this.http_request.status == 200) {              
			  
			   new Function("_ajax.handler["+this.id+"].oReturn(_ajax.handler["+this.id+"].http_request.responseText);")();
			   //alert(this.http_request.responseText);                   
             
           } else { 
            alert('There was a problem with the request.(MCode: ' + this.http_request.status + ')'); 
			//if($GEBId("load"))$GEBId("load").style.display="none"; 
           } 
       } 
   } 
   
   
   this.http_request.open(this.meth, this.url+this.paramsforGet, true);
    if(this.meth == "POST"){
	   this.http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	this.http_request.send(this.params);
   }
} // fim classe makeHttpRequest


//intancia o objeto acima
function ajax(doc,retfunc,params,meth){
	//alert(doc+" - "+retfunc+" - "+params+" - "+meth)
myAjax = new makeHttpRequest(doc, retfunc, params, meth);
}

//cria a lista de parametros do form
function createparams(form){
//if($GEBId('userfile')) 
var str = "";
var tags = $GEBTn('input',form);
var tarea = $GEBTn('textarea',form);
var slect = $GEBTn('select',form);
	for(d=0;d < tags.length;d++){
	if(tags[d].type == 'hidden' || tags[d].type == 'text' || tags[d].id == 'foto' || tags[d].type == 'file'  || (tags[d].type == 'radio' && tags[d].checked)  || (tags[d].type == 'checkbox' && tags[d].checked)) str+=tags[d].id+"="+tags[d].value+"&"; 
	}
	
	for(d=0;d < tarea.length;d++){
	str+=tarea[d].id+"="+tarea[d].value+"&"; 
	}
	
	for(d=0;d < slect.length;d++){
	str+=slect[d].id+"="+slect[d].value+"&"; 
	}
	
	
	str = str.replace(/\&$/,"");
			
	//
form.params.value = str;
//alert("formParams: "+form.params.value);
}




function disonoff(oDiv){ // NAO UTILIZADA AQUI
	var theex = $GEBId(oDiv);
	if(theex.style.display == "none") theex.style.display = "";
	else theex.style.display = "none";
}

function offslash(){//caso haja, retira a barra do fim do endereço digitado // NAO UTILIZADA AQUI
	var thedir = $GEBId("dir_xml");
	c = thedir.value;
	var barra = c.charAt(c.length - 1);
		if(barra == "/"){		
		c = c.replace(/\//,"");	
		thedir.value = c;	
		}
}



function trimString (str) {
  return str.replace(/^s*/, '').replace(/s*$/, ''); 
} 


function foc(){
	document.form1.addr.focus();
}

function foclog(){
	document.f1.login.focus();
}

/*
function mk_importObj(formItem){
		myrssfeed_obj = new importXML(formItem);	//rssclass.js
		return true;
}


var firstTitle = 0;
function mkBold(){
var titels = $GEBTn('td');
$GEBId('imglink').innerHTML=myrssfeed_obj.theImgLink; // COLOCA A IMG DO CANAL NO TITULO
	for(h=0;h < titels.length; h++){
		if(titels[h].firstChild && (titels[h].firstChild.nodeValue == "Channel" || titels[h].firstChild && titels[h].firstChild.nodeValue == "Title")){
		firstTitle++;
			if(firstTitle == 1){
			titels[h].nextSibling.style.height="40px";
			titels[h].nextSibling.style.verticalAlign="top";
			titels[h].nextSibling.style.color="#f9f9f9";
			titels[h].nextSibling.style.backgroundColor="#006699";
			titels[h].nextSibling.style.fontWeight="bold";
			titels[h].nextSibling.style.fontSize="13px";
			}else{
			titels[h].nextSibling.style.fontWeight="bold";
			titels[h].nextSibling.style.fontSize="12px";
			}
		}
	}
	firstTitle = 0;
}


function setMkBold(){	// chama a func que set all titles bold and bigger
	setTimeout("mkBold()",100);
}
*/

function $GEBId(id,doc) { return (doc || document).getElementById(id); }

function $GEBTn(nome,doc) { return (doc || document).getElementsByTagName(nome); }