/* fun&ccedil;oes desenvolvidas.*/

//**********************************************************************//
// Desenvolvido por: Carlos Claro                                      	//
// Programador Web														//
// A serviço de: Visuality Comunicação 									//
// Não deve ser reproduzido sem autorização                            	//
// contato: carlos@carlosclaro.com.br                                  	//
// 																		//
//**********************************************************************//

// fun&ccedil;&atilde;o xmlhttp.
function getxmlhttp(){
	var  xmlhttp = false;
	
	try{
		xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");
	}catch(e){//catch try linha 6
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){// fecha try linha 9
			xmlhttp = false;
		}//fecha catch E
	}// fecha catch linha 8
	
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}// fecha function getxmlhttp

//fun&ccedil;&atilde;o  processa ajax
function processajax (obj, serverPage){
	var theimg;
	xmlhttp = getxmlhttp();
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			document.getElementById(obj).innerHTML = xmlhttp.responseText;
		}
	}//fecha function
	xmlhttp.send(null);
}// fecha func ajax

function doneloading(theframe, thefile){
	var theloc = "/showimg.php?thefile=" + thefile 
	theframe.processajax("showimg",theloc);
}//fecha doneloading

function uploadimg(theform){
	theform.submit();
	setStatus("Carregando... ","showimg");
}
function setStatus(theStatus, theObj){
	obj = document.getElementById(theObj);
	if(obj){
		obj.innerHTML = "<div class='bold'>"+theStatus+"</div>";
	}
}



// Vari&aacute;vel que receber&aacute; o objeto XMLHttpRequest
//var req;

/* function trim(){
	//verifica espa&ccedil;os e formato da string
	if(typeof inputString != "string") { return inputString; }
	var retValue = inputString;;
	var ch = retValue.substring(0, 1);
	while (ch == " "){
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
		}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " "){
		retValue = retValue.substring(0, retValue.length-1);
		ch - ret.Value.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf(" ") != -1){
		retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length);
		//tira espa&ccedil;os multiplos
	}
	return retValue;
}//fecha trim

function  validacampo(valor, campo){
	var nowcont = true;
	
	if (campo == "yourname"){
		if(trim(valor) == ""){
			document.getElementById("login").innerHTML = "Preenche o campo login.";
			document.getElementById("nome").yourname.focus();
			nowcont = false;
		}//fecha trim
	}//fecha if  campo
	if(nowcont == true){
		if(campo == "yourtask"){
			if(trim(valor)==""){
				document.getElementById("login").innerHTML = "Preencha o campo login";				
				document.getElementById("nome").yourtask.focus();
			}// fecha if trim
		}//fecha campo
	}//fecha if nowcont
	
}//fehca valida campo */

function validarDados(campo, valor) {
 
// Verificar o Browser
// Firefox, Google Chrome, Safari e outros
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
// Internet Explorer
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}
 
// Aqui vai o valor e o nome do campo que pediu a requisi&ccedil;&atilde;o.
var url = "../php/validacao.php?campo="+campo+"&valor="+valor;
 
// Chamada do m&eacute;todo open para processar a requisi&ccedil;&atilde;o
req.open("Get", url, true);
 
// Quando o objeto recebe o retorno, chamamos a seguinte fun&ccedil;&atilde;o;
req.onreadystatechange = function() {
 
	// Exibe a mensagem "Verificando" enquanto carrega
	if(req.readyState == 1) {
		document.getElementById('campo_'+campo+'').innerHTML = '<font color="gray">Verificando...</font>';
	}
 
	// Verifica se o Ajax realizou todas as opera&ccedil;ões corretamente (essencial)
	if(req.readyState == 4 && req.status == 200) {
	// Resposta retornada pelo validacao.php
	var resposta = req.responseText;
 
	// Abaixo colocamos a resposta na div do campo que fez a requisi&ccedil;&atilde;o
	document.getElementById('campo_'+campo+'').innerHTML = resposta;
	}
 
}
 
req.send(null);
 
}//fecha fund validaDados


//inicia validadadoscad
function validarDadoscad(campo, valor) {
 
// Verificar o Browser
// Firefox, Google Chrome, Safari e outros
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
// Internet Explorer
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}
 
// Aqui vai o valor e o nome do campo que pediu a requisi&ccedil;&atilde;o.
var url = "php/validacao.php?campo="+campo+"&valor="+valor;
 
// Chamada do m&eacute;todo open para processar a requisi&ccedil;&atilde;o
req.open("Get", url, true);
 
// Quando o objeto recebe o retorno, chamamos a seguinte fun&ccedil;&atilde;o;
req.onreadystatechange = function() {
 
	// Exibe a mensagem "Verificando" enquanto carrega
	if(req.readyState == 1) {
		document.getElementById('campo_'+campo+'').innerHTML = '<font color="gray">Verificando...</font>';
	}
 
	// Verifica se o Ajax realizou todas as opera&ccedil;ões corretamente (essencial)
	if(req.readyState == 4 && req.status == 200) {
	// Resposta retornada pelo validacao.php
	var resposta = req.responseText;
 
	// Abaixo colocamos a resposta na div do campo que fez a requisi&ccedil;&atilde;o
	document.getElementById('campo_'+campo+'').innerHTML = resposta;
	}
 
}
 
req.send(null);
 
}//fecha fund validaDadoscad





// validaDadosNome
function validarDadosNome(campo, valor, tipocad) {
 
// Verificar o Browser
// Firefox, Google Chrome, Safari e outros
if(window.XMLHttpRequest) {
   req = new XMLHttpRequest();
}
// Internet Explorer
else if(window.ActiveXObject) {
   req = new ActiveXObject("Microsoft.XMLHTTP");
}
 
// Aqui vai o valor e o nome do campo que pediu a requisi&ccedil;&atilde;o.
var url = "../php/validacao.php?campo="+campo+"&valor="+valor+"&tipo_cad="+tipocad;
 
// Chamada do m&eacute;todo open para processar a requisi&ccedil;&atilde;o
req.open("Get", url, true);
 
// Quando o objeto recebe o retorno, chamamos a seguinte fun&ccedil;&atilde;o;
req.onreadystatechange = function() {
 
	// Exibe a mensagem "Verificando" enquanto carrega
	if(req.readyState == 1) {
		document.getElementById('campo_'+campo+'').innerHTML = '<font color="gray">Verificando...</font>';
	}
 
	// Verifica se o Ajax realizou todas as opera&ccedil;ões corretamente (essencial)
	if(req.readyState == 4 && req.status == 200) {
	// Resposta retornada pelo validacao.php
	var resposta = req.responseText;
 
	// Abaixo colocamos a resposta na div do campo que fez a requisi&ccedil;&atilde;o
	document.getElementById('campo_'+campo+'').innerHTML = resposta;
	}
 
}
 
req.send(null);
 
}//fecha fund validaDadosNome
