function createXMLHTTP(){	
	try{
		ajax = new ActiveXObject('Microsoft.XMLHTTP');
	}catch(e){
		try{
			ajax = new ActiveXObject('Msxml2.XMLHTTP');
		}catch(ex){
			try {
				ajax = new XMLHttpRequest();
			}catch(exc) {
				alert('Esse browser não tem recursos para uso do Ajax');
				ajax = null;
			}
		}

		return ajax;
	}

	var arrSignatures = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP',  'Microsoft.XMLHTTP'];
	for (var i=0; i < arrSignatures.length; i++) {
		try {
			var oRequest = new ActiveXObject(arrSignatures[i]);
			return oRequest;
		} catch (oError) {
		
		}
	}
	
	throw new Error('MSXML is not installed on your system.');
}

function EnviaForm(pagina, formulario, tagId){
	try{
		var parametro = '';
		var valor = '';
		for (i=0; i<document[formulario].length; i++){
			if (document[formulario][i].name!=undefined){
				valor = document[formulario][i].value;
				if ((document[formulario][i].name).substr(0,3)=='chk'){
					if (document[formulario][i].checked==true){
						parametro = document[formulario][i].name + '=' + (valor).replace('&', '|') +'&'+parametro;
					}
				}else{
					parametro = document[formulario][i].name + '=' + (valor).replace('&', '|') +'&'+parametro;
				}
			}
		}
		
		goAjax(pagina, tagId, encodeURI(parametro));
	
	} catch (oError) {
		//alert(oError.description);
	}	
}

function goAjax(pagina, tagRetorno, parametros) {
	document.getElementById(tagRetorno).innerHTML='<div align="center" class="carregando"><img src="http://www.jobsistemas.com.br/imagens/carregando.gif"><br />carregando...</div>'
	
	try{
		var xmlhttp = new ActiveXObject('MSXML2.XMLHTTP');
	}catch(e){
		var xmlhttp = new XMLHttpRequest();
	}

	try{

		xmlhttp.open('POST', pagina, true);
		
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
		xmlhttp.setRequestHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
		xmlhttp.setRequestHeader('Cache-Control', 'post-check=0, pre-check=0');
		xmlhttp.setRequestHeader('Pragma', 'no-cache');
		
		
		xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4) {
			if (xmlhttp.status==200){
				document.getElementById(tagRetorno).innerHTML=xmlhttp.responseText;
				texto=unescape(xmlhttp.responseText.replace(/\+/g," "));
				ExecutaScript(texto);
	
			}else{
				try{
					document.getElementById(tagRetorno).innerHTML='';
					}catch(e){
					//alert('Um erro na página não permitiu que ela fosse carregada\n'+xmlhttp.status+'-'+(e.description).replace("'","_")+'. ');
					return false;
					}
					document.getElementById(tagRetorno).innerHTML=xmlhttp.responseText;
					//alert('Um erro na página não permitiu que ela fosse carregada\n'+xmlhttp.status+'. ');	
				}
			}
		}

	}catch(e){
		alert('Erro!')
	}

	try{
		xmlhttp.send(parametros);
	}catch(e){
		alert(e.description);
	}
}

function ExecutaScript(texto){
    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini>=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);
            codigo = texto.substring(ini,fim);
            eval(codigo);
        }
    }
}


