	//Ajax
/*
EXEMPLO DE UTILIZAÇÃO
 
	ResultadoListData = null;
	
	SendData('ajax.asp','RetornaListData','XML',undefined,false);
			
	alert(ResultadoListData);


FORMATO DO RETORNO XML 

	<RETORNO> ... conteúdo... </RETORNO>
 
 */

//-=-=-=-=- AJAX BY CL/CGB -=-=-=-=-

	var xmlhttp=false;
	var isFirefox=false;
	var agt = navigator.userAgent.toLowerCase(); 
	var is_opera = (agt.indexOf("opera") != -1); 			
	var sReturnTypeDefault = "XML";
	var sLoadFunctionDefault = "";
	var sASyncDefault = true;
	var iASync = 0;
		
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
		isFirefox = true;
	}

	//END - XMLHTTP
	
	function SetReturnType(value){
		sReturnTypeDefault = value;
	}

	function SetLoadFunction(value){
		sLoadFunctionDefault = value;
	}

	function SetASync(value){
		sASyncDefault = value;
	}
	
	function OnlySendDataASync(sURL){
		eval('var xmlhttp'+iASync+' = false;');
		if (!(isFirefox)){
			try {
				eval('xmlhttp'+iASync+' = new ActiveXObject("Msxml2.XMLHTTP");');
				
			} catch (e) {
				try {
					eval('xmlhttp'+iASync+' = new ActiveXObject("Microsoft.XMLHTTP");');
				} catch (e) {
				}
			}
		}else{
			if (typeof XMLHttpRequest!='undefined') {
				eval('xmlhttp'+iASync+' = new XMLHttpRequest();');
			}
		}
		try {
			eval('xmlhttp'+iASync+'.open("GET", sURL, true);');
			eval('xmlhttp'+iASync+'.send(null);');
			} catch (e) {

		}
		iASync += 1;
		return true;
	}

	function SendData(sURL,sWriteFunction,sReturnType,sLoadFunction,sASync){
		
		if (sURL == undefined)
		{
			alert("É necessário informar alguma URL para consulta");
			return false;
		}

		//se passar modo assíncrono utiliza a funçao do includeAjax.asp
		if( sASync && sWriteFunction != undefined && sReturnType!='XML' )
		{
			if( typeof sWriteFunction == 'string' )
				eval('sWriteFunction='+sWriteFunction);
			
			if( typeof sLoadFunction == 'string' )
				eval('sLoadFunction='+sLoadFunction);
				
			ajax.addRequest( sURL, sWriteFunction,undefined,undefined,undefined, sLoadFunction,undefined,"GET");
			return;
		}
		
		if (sWriteFunction == undefined)
		{
			//alert("É necessário informar alguma Funçao para retorno dos dados");
			OnlySendDataASync(sURL);
			return false;
		}
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlhttp = new XMLHttpRequest();
			}
		}

		if (sReturnType == undefined)
		{
			sReturnType = sReturnTypeDefault
		}

		if (sLoadFunction == undefined)
		{
			sLoadFunction = sLoadFunctionDefault;
		}

		if (sASync == undefined)
		{
			sASync = sASyncDefault;
		}
				
		if (sLoadFunction != "")
		{
			ShowLoading(sLoadFunction,true);
		}

		xmlhttp.open("GET", sURL, sASync);
		xmlhttp.onreadystatechange= function() {
			
			/* estado carregado */
			if (xmlhttp.readyState==4) 
			{
				eval(sWriteFunction + "(RequisitionResponse(sReturnType),sReturnType);");
				if (sLoadFunction != "")
				{
					ShowLoading(sLoadFunction,false);
				}
			}
		}		
		
		try{ 
			xmlhttp.send(null);
		}catch(e){ 
			//Se der erro de REDE vai retornar NULL e vai parar a execuçao, senao da erro de Objeto para o usuário
			//by Marcola Inc 26 oct 2006
			ResultadoListData = null;
			return false;
		}

		if (isFirefox && !(sASync))
		{
			if (xmlhttp.readyState==4) 
				{
					eval(sWriteFunction + "(RequisitionResponse(sReturnType),sReturnType);");
					if (sLoadFunction != "")
					{
						ShowLoading(sLoadFunction,false);
					}
				}
		}
	}
	
	function RequisitionResponse(sReturnType){
		if (sReturnType.toUpperCase() == 'TXT')
			return xmlhttp.responseText;
		if (sReturnType.toUpperCase() == 'XML')
			if (isFirefox){
				xmlhttp.responseXML.normalize();
			}
			return xmlhttp.responseXML;
	}

	function ShowLoading(tDiv,b){
		if (b){
			eval("document.getElementById('" + tDiv + "').style.visibility = ''");
		}else{
			eval("document.getElementById('" + tDiv + "').style.visibility = 'hidden'");
		}
	}

	function GetValueXML(doc){
		if (doc.getElementsByTagName('RETORNO').length != 0){
			var element = doc.getElementsByTagName('RETORNO').item(0);
			if (!(element.firstChild == null)){
				return element.firstChild.data.trim();//replace para spaco no ffx
			}else{
				return '';/*entra aqui qndo o retorno é vazio*/
			}
		}else{
			return null;/*entra aqui qndo der pau ou nao tiver*/
		}
	}

	function RetornaListData(resposta,type)
	{
		if (resposta != null){
			if (type == 'XML'){
				
				ResultadoListData = GetValueXML(resposta);
				if (!(isFirefox)){
					AlimentaResultadoListData(ResultadoListData);
				}
			}else{
				ResultadoListData = resposta; // qndo for txt(JSON) deve se testar 
				if (!(isFirefox)){
					AlimentaResultadoListData(ResultadoListData);
				}
			}
		}else{
			ResultadoListData = null;
			AlimentaResultadoListData(null);
		}
		return true;
	}	
	
	function GetValueRetornoXML(doc){//Aki varre o resultado para buscar..
		if (doc.length != 0){
			var element = doc.item(0);
			if (!(element.firstChild == null)){
				return element.firstChild.data.trim();//replace para spaco no ffx
			}else{
				return '';/*entra aqui qndo o retorno é vazio*/
			}
		}else{
			return null;/*entra aqui qndo der pau ou nao tiver*/
		}
	}	
	
	String.prototype.trim = function()
	{
		/*
		^  - busca do inicio da string
		\s - equivale a espaço em branco
		+  - equivale a buscar 1 ou mais ocorrencias
		|  - equivale a OR
		$  - busca do fim da string
		g  - busca por todas as ocorrencias
		*/
		
		return this.replace(/^\s+|\s+$/g , "" );
	}
	
	//-=-=-=-=- FIM AJAX -=-=-=-=-=-=-

	//valida login 
	function validaLogin() {
		//debugger;
				
		objFormulario = document.getElementById('formLogin');
		var User =  document.getElementById("username").value;
		/*----------verifica se o titulo foi preenchido----------*/	
				
		if(document.getElementById("username").value == "")
		{	 	
		  alert("Preencha o campo \"Usuario\"!!!"); 
		  document.getElementById("username").focus();     
		  return false;
		}
		/*----------verifica se a data foi preenchida-----------*/
 	 	var Senha =  document.getElementById("password").value;
		if (document.getElementById("password").value == "")
		{
			
			alert("Preencha o campo \"Senha\"!!!");
			document.getElementById("password").focus();
			return false;
		}	     	
		//alert("Formulário validado. Todos os campos estão ok;");
		
		var url = "validacao.asp?login=" + User + "&senha=" + Senha+""
		//window.open(url);	
		ResultadoListData = null;
			
		SendData(url,'RetornaListData','XML',undefined,false);
		
		if (ResultadoListData == "ok") 
		{
			//alert('Login OK, \n a pagina será submitada com os valores:\n\n\t' + 'Login: ' + User + '\n\tSenha: ' + Senha);
			objFormulario.submit();
			//document.getElementById("enviarAcao").type = 'submit';
			//document.getElementById("enviarAcao").click();
			return true;
		} 
		else 
		{
			alert("Login ou Senha incorretos");
			document.getElementById("username").focus(); 
			return false;
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	



	

	