<!--

//===================================Manipula Lista de Eventos==================================

//Adiciona eventos e function a elementos
function addEvent(o, e, f, s){
	var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
	r[r.length] = [f, s || o], o[e] = function(e){
		try{
			(e = e || event).preventDefault || (e.preventDefault = function(){e.returnValue = false;});
			e.stopPropagation || (e.stopPropagation = function(){e.cancelBubble = true;});
			e.target || (e.target = e.srcElement || null);
			e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
		}catch(f){}
		for(d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
		return e = null, !!d;
    }
};

//=======================================Funções uteis=========================================

//Retorna id de um ou mais elementos
function $id() {
  var elements = new Array();
  var totArgs = arguments.length;
  for (var i = 0; i < totArgs; i++) {
    if (typeof arguments[i] == 'string') arguments[i] = document.getElementById(arguments[i]);
    if (arguments.length == 1) return arguments[i];
    elements.push(arguments[i]);
  }
  return elements;
}

//Retorna um array de elementos de todo o documento ou de um elemento
function $tag(t,id){
	if(id) return id.getElementsByTagName(t);
	else return document.getElementsByTagName(t);
}
//==========================================MENU DROPDOWN=================================

function horizontal() {
 
   var navItems = document.getElementById("menu_dropdown").getElementsByTagName("li");
    
   for (var i=0; i< navItems.length; i++) {
      if(navItems[i].className == "submenu")
      {
         if(navItems[i].getElementsByTagName('ul')[0] != null)
         {
            navItems[i].onmouseover=function() {this.getElementsByTagName('ul')[0].style.display="block";this.style.backgroundColor = "#FFFFFF";}
            navItems[i].onmouseout=function() {this.getElementsByTagName('ul')[0].style.display="none";this.style.backgroundColor = "#FFFFFF";}
         }
      }
   }
 
}
//====================================Manipula elementos======================================
var $obj = {
	//Cria um novo elemento
	create: function(type, id, parentObj, atributos, formType){
		this.newObj = document.createElement(type);
		if(id) this.newObj.setAttribute('id',id);
		if(atributos){
			var Arr = atributos.split('|');
			for(var i=0;i<Arr.length;i++) this.newObj.setAttribute(Arr[i].split('!!')[0],Arr[i].split('!!')[1]);
		}
		if(formType) this.newObj.type=formType;
		if(type=="form" || type=="iframe" || formType) if(id) this.newObj.setAttribute('name',id);
		
		parentObj.appendChild(this.newObj);
	},
	//Clona um objeto existente no documento
	clone: function(orObj,cloneObj,cloneType){
		this.dimension = Array();
		this.position = Array();
		this.dimension = this.getDimension(orObj);
		this.position = this.getPos(orObj);
		$obj.create(cloneType,cloneObj,$tag("body").item(0));
		$id(cloneObj).style.position='absolute';
		$id(cloneObj).style.left=this.position[0]+"px";
		$id(cloneObj).style.top=this.position[1]+"px";
		$id(cloneObj).style.width=this.dimension[0]+"px";
		$id(cloneObj).style.height=this.dimension[1]+"px";
		$id(cloneObj).style.zIndex=999;
	},
	//Atribui transparencia a um elemento
	opacity: function(obj,value){
		obj = obj.style;
		obj.filter = "alpha(opacity=" + value + ")"; 
		obj.opacity=(value/101);
		obj.MozOpacity=(value/101);
		obj.KhtmlOpacity=(value/101);
	},
	//Retorna a posição de um elemento
	getPos: function(obj){
		if($id(obj)){
			obj = $id(obj);
			var top=obj.offsetTop;
			objY=obj;
			while((objY=objY.offsetParent) != null) top+=objY.offsetTop;
			var left=obj.offsetLeft;
			objX=obj;
			while((objX=objX.offsetParent)!=null) left+=objX.offsetLeft;
			var position=Array(left,top);
			return position;
		} else return Array("ERRO:","Objeto '"+obj+"' não foi encontrado!");
	},
	//Retorna as dimensões de um elemento
	getDimension: function(obj){
		if($id(obj)){
			obj = $id(obj);
			var width=obj.offsetWidth;
			var height=obj.offsetHeight;
			var dimension=Array(width,height);
			return dimension;
		} else return Array("ERRO:","Objeto '"+obj+"' não foi encontrado!");
	}
}

//==========================================Funções AJAX=================================

//Cria uma nova instancia
function getAjax(url, retorno, info, method, formID, script, func){
	var requestContent = new ajax(url, retorno, info, method, formID, script, func);
	requestContent.connect();
}

//Atribui os parametros aos objetos
function ajax(url, retorno, info, method, formID, script, func){
	this.url = url; // URL a ser carregada
	this.retorno = retorno; // Elemento que recebera o conteudo da URL
	this.info = (info) ? info : 'loading'; // Enquanto URL é carregada default "loading"
	this.method = (method== 'GET'|| method=='POST') ? method : 'GET'; // method GET ou POST, default GET
	this.formID = formID; // form ID é obrigatoria apenas para method POST
	this.script = (script==0 || script==1) ? script : 1;
	this.func = func;
}

ajax.prototype = {
	//Cria o objeto XMLHttpRequest
    connect: function(){
		if(!this.url) return;
		if(this.func!=null) if(!eval(this.func)) return;
        this.xmlHttp = null;
		if( window.XMLHttpRequest ) this.xmlHttp = new XMLHttpRequest(); // Para todos os browsers
		else if( window.ActiveXObject){ // Para IE
			try{ this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
				catch(e){
					try{this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
						catch(e){}
				}
		}
		if(this.xmlHttp != null && this.xmlHttp != 'undefined' ){
			var object = this;
			this.xmlHttp.onreadystatechange = function(){ object.getState.call(object); }
			if(this.method=="GET") this.executeGET(); // Envia dados por GET
			else if(this.method=="POST") this.executePOST(); // Envia dados por POST
			else{alert('ERRO: FORM Method inválido!'); return;}
		}
		else alert('Seu browser não suporta requisições por AJAX.');
	},
	//Capitura o status da pagina a ser carregada
	getState: function(){
		if(this.xmlHttp.readyState == 4 ){
			this.result(this.xmlHttp.responseText);
			if(this.script) this.executeScripts(this.xmlHttp.responseText);
		} else this.loading();
	},
	//Executa method GET
	executeGET: function(){
		this.xmlHttp.open(this.method,this.url, true);
		this.xmlHttp.send(null);
		
	},
	//Executa method POST
	executePOST: function(){
		var fields = "";
		if(!this.formID) alert("Erro: ID do FORM não encontrado")
		for(i=0;i<$id(this.formID).length;i++){
			fields+=$id(this.formID)[i].name+"="+$id(this.formID)[i].value+"&";
		}
		this.xmlHttp.open(this.method,this.url, true);
		this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlHttp.setRequestHeader('Content-Type',"application/x-www-form-urlencoded; charset=iso-8859-1");
		this.xmlHttp.send(fields);
	},
	//Capitura javascript
	executeScripts: function(text){
		var ini = 0;
		while (ini!=-1){
			ini = text.indexOf('<script', ini);
			if (ini >=0){
			    var src = '',srctemp = text.substring(ini,text.indexOf('>', ini));
			    if(srctemp.indexOf('src')){
			        src = srctemp.substring(srctemp.indexOf('src="')+5,text.indexOf('>', ini));
			        src = src.substring(0,src.length-1);
			    }
				ini = text.indexOf('>', ini) + 1;
				var fim = text.indexOf('</script>', ini);
				codigo = text.substring(ini,fim);
				var novo = document.createElement("script");
				novo.setAttribute('type','text/javascript');
				if(src!='') novo.setAttribute('src',src);
				src = '';
				novo.text = codigo;
				document.body.appendChild(novo);
			}
		}
	},
	//Capitura o que vai ser exibido antes de concluir a URL
    loading: function(){ if(this.info!='')this.result(this.info); },
	//Insere retorno da URL carregada
	result: function(r){
		if($id(this.retorno)){
			if($id(this.retorno).tagName.toLowerCase()=="input") $id(this.retorno).value = unescape(escape(r).replace(/\%0D\%0A/g,"").replace(/\%09/g,""));
			else if($id(this.retorno).tagName.toLowerCase()=="textarea") $id(this.retorno).value = unescape(escape(r).replace(/\%09/g,""));
			else if($id(this.retorno).tagName.toLowerCase()=="select") this.preenche_select($id(this.retorno),r);
			else if($id(this.retorno).tagName) $id(this.retorno).innerHTML = r;
		}
		else if((typeof(this.retorno)).toLowerCase()=="string"){ //se for o nome da string
            if(r!="Falha no carregamento"){ 
                eval(this.retorno + '= unescape("' + escape(r) + '")')
            }
        }  
	},
	//Insere retorno da URL carregada em elementos select
	preenche_select: function(elem,r){
	    var opt;
		elem.innerHTML = '';
		$obj.create('temp','temp1',$tag('body')[0]);
		var temp = $id('temp1');
		temp.style.display = 'none';
		if(r.toLowerCase().indexOf("<option")<0) r = "<option>" + r + "</option>";
		r = r.replace(/<option/gi,"<span").replace(/<\/option/gi,"</span");
		temp.innerHTML = r;
	    for(var i=0;i<temp.childNodes.length;i++){
	        if(temp.childNodes[i].tagName){
				opt = document.createElement("OPTION");
	            for(var j=0;j<temp.childNodes[i].attributes.length;j++) opt.setAttributeNode(temp.childNodes[i].attributes[j].cloneNode(true));
            	opt.value = temp.childNodes[i].getAttribute("value");
	            opt.text = temp.childNodes[i].innerHTML;
				if(document.all) elem.add(opt);
				else elem.appendChild(opt);
			}
		}
	    $tag('body')[0].removeChild(temp);
		temp = null;
	}
}

-->
