function ajaxInit(){
	var xmlhttp ;
	try {
		xmlhttp = new XMLHttpRequest ( ) ;
	}catch (ee){
		try { 
			xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP") ;
		}catch( e ) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP" ) ;
			}catch(E) {
				xmlhttp= false ;
			}
		}
	}
	return xmlhttp ;
}
function busca(evt){
	var key_code = evt.keyCode  ? evt.keyCode  :
		evt.charCode ? evt.charCode :
			evt.which    ? evt.which    : void 0;
	if (key_code == 13){
		document.formBusca.action='/studiowebti/busca';
		document.formBusca.submit();
	}
}
function acessar(valor,teclapres){
	var tecla = 0;
	if(document.all){
		tecla = teclapres.keyCode;
	}
	else{
		tecla = teclapres.which;
		if(tecla==1){tecla=0}
	}
	if (tecla == 13 || tecla == 0){
		if(document.formLogin.txtCPF.value==''){
			alert('Digite seu CPF!');
			document.formLogin.txtCPF.focus();
		}
		else if(document.formLogin.txtSenha.value==''){
			alert('Digite sua senha!');
			document.formLogin.txtSenhaAcesso.focus();
		}
		else{
			document.formLogin.action='http://sol.sisnetti.com.br:8180/stdweb/acesso?ac=verificar_acesso';
			document.formLogin.submit();
		}
	} 
}

function mascara(o,f){
	v_obj=o
	v_fun=f
	setTimeout("execmascara()",1)
}
function execmascara(){
	v_obj.value=v_fun(v_obj.value)
}

function cpf(v){
	v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
	v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
	//de novo (para o segundo bloco de números)
	v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
	return v
}

function validarCPF(CPF){ 
	if (CPF != ''){ 
		if (!verificarCPF(CPF)){ 
			alert('CPF Inválido!'); 
			document.form.txtCPF.value=''; 
			document.form.txtCPF.focus(); 
		} 
	} 
}  

function verificarCPF(c){ 
	c = c.replace('.','');	
	c = c.replace('.','');	
	c = c.replace('-','');	
	var i;  
	s = c; 
	var c = s.substr(0,9);  
	var dv = s.substr(9,2);  
	var d1 = 0;  
	var v = false; 
	for (i = 0; i < 9; i++)  
	{  
		d1 += c.charAt(i)*(10-i);  
	}  
	if (d1 == 0){  
	v = true;  
	return false;  
	}  
	d1 = 11 - (d1 % 11);  
		if (d1 > 9) d1 = 0;  
			if (dv.charAt(0) != d1)  
			{  
		v = true; 
		return false;  
	}  
	d1 *= 2;  
	for (i = 0; i < 9; i++) {  
		d1 += c.charAt(i)*(11-i);  
	}  
	d1 = 11 - (d1 % 11);  
	if (d1 > 9) d1 = 0;  
		if (dv.charAt(1) != d1)  
	{  
	v = true; 
	return false;  
	}  
	if (!v) { 
	return true; 
	} 

	
}

//valida numero inteiro com mascara
function mascaraInteiro(){
	if (event.keyCode < 48 || event.keyCode > 57){
		event.returnValue = false;
		return false;
	}
	return true;
}

//formata de forma generica os campos
function formataCampo(campo, Mascara, evento) { 
	var boleanoMascara; 

	var Digitato = evento.keyCode;
	exp = /\-|\.|\/|\(|\)| /g
	campoSoNumeros = campo.value.toString().replace( exp, "" ); 

	var posicaoCampo = 0;    
	var NovoValorCampo="";
	var TamanhoMascara = campoSoNumeros.length;; 

	if (Digitato != 8) { // backspace 
		for(i=0; i<= TamanhoMascara; i++) { 
			boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".")
					|| (Mascara.charAt(i) == "/")) 
					boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") 
							|| (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " ")) 
							if (boleanoMascara) { 
								NovoValorCampo += Mascara.charAt(i); 
								TamanhoMascara++;
							}else { 
								NovoValorCampo += campoSoNumeros.charAt(posicaoCampo); 
								posicaoCampo++; 
							}              
		}      
		campo.value = NovoValorCampo;
		return true; 
	}else { 
		return true; 
	}
}

function validaEmail(Email){
	var filter = /^(([a-zA-Z0-9_-])+(([\.\])+([a-zA-Z0-9_-]{0,1})))+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 
	var arrayEmail = Email.split(";"); //Separa os email 
	for (var i=0;i < arrayEmail.length; i++){ //varre a lista de emails 
		if ( !filter.test(arrayEmail[i]) ){ 
			return false; //se tiver erro sai com false 
		}
		else{ 
			return true; // se nao achou erro retorrna verdadeiro 
		}
	}
}

function enviarEmail(){
	if(document.form.txtNome.value==''){
		alert('Informe um nome!');
		document.form.txtNome.focus();
	}
	else if(document.form.txtEmail.value==''){
		alert('Informe um e-mail!');
		document.form.txtEmail.focus();
	}
	else if(validaEmail(document.form.txtEmail.value)==false){
		alert('E-mail inválido');
		document.form.txtEmail.value = '';
	}
	else if(document.form.txtMsg.value==''){
		alert('Digite uma mensagem!');
		document.form.txtMsg.focus();
	}
	else{
		document.form.action='/studiowebti/contato';
		document.form.submit();
	}
}

function showService(id){
	var ajax=ajaxInit();
	document.getElementById("DivDescServ").innerHTML="<center><img src=\"imagens/carregando.gif\"></center>";
	document.getElementById("DivService1").setAttribute((document.all ? "className" : "class"), "DivService");
	document.getElementById("DivService2").setAttribute((document.all ? "className" : "class"), "DivService");
	document.getElementById("DivService3").setAttribute((document.all ? "className" : "class"), "DivService");
	document.getElementById("DivService4").setAttribute((document.all ? "className" : "class"), "DivService");
	document.getElementById("DivService5").setAttribute((document.all ? "className" : "class"), "DivService");
	document.getElementById("DivService"+id).setAttribute((document.all ? "className" : "class"), "DivServiceSel");
	if(ajax){
		ajax.open('GET','?ac=showService&id='+id,true);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				if(ajax.status==200){
					document.getElementById("DivDescServ").innerHTML = ajax.responseText;
				}
			}
		}
	}
	ajax.send(null);
}