// JavaScript Document
function goPage(pag,div){
	$.ajax({
		type: "GET",
		url: pag,
		success: function(texto){
			$("#"+div).html(texto);
		}
	});
}

/*
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
									FUNÇÃO PARA ENVIAR CAMPOS
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
*/



function SubmitCampos(fpagina,fcampos,fdiv){
	
	if(fcampos!=''){
		
		var formCampoAntigo = ''
		spl = fcampos.split('/*/')
		tamanho = spl.length

		for(i=0;i<tamanho;i++){
				
			formCampo = spl[i]+"="+document.getElementById(spl[i]).value
			
			formCampoAntigo = formCampo+"&"+formCampoAntigo
		}

	}
				
	goPage(fpagina+'?tipo='+document.getElementById('tipo').checked+'&'+formCampoAntigo,fdiv)

}


function limparInner(idInner){
	document.getElementById(idInner).innerHTML = ''
}




function dialogcalculo(fpagina, fnome, fscroll, ftitle, fdiretories, flocation, fstatus, fmenubar, ftoolbar, fresizable, flargura, faltura){
	
		x=screen.width
		y=screen.height
		larg = flargura
		altu = faltura
		cima = (y-altu)/2
		lado = (x-larg)/2
		window.open(fpagina, fnome,"scrollbars="+fscroll+", title="+ftitle+", diretories="+fdiretories+", location="+flocation+", status="+fstatus+", menubar="+fmenubar+", toolbar="+ftoolbar+", resizable="+fresizable+", left="+lado+", top="+cima+", height="+altu+", width="+larg)
		
}




function Login(usuario,senha){
	var flag = true
	if(document.form.login.value==''){
		alert('Usuario não pode ser nulo!')
		document.form.login.focus()
		flag = false
	}
	else
	if(document.form.senha.value==''){
		alert('Senha não pode ser nula!')
		document.form.senha.focus()
		flag = false
	}
	else
	if(document.form.login.value!=usuario){
		alert('Usuario incorreto!')
		document.form.login.focus()
		flag = false
	}
	else
	if(document.form.senha.value!=senha){
		alert('Senha incorreta!')
		document.form.senha.focus()
		flag = false
	}
	
	if(flag == true){
		document.form.submit()	
	}	
}




function verificacontato(){
	
var nome = document.getElementById('nomeContato').value;
var email = document.getElementById('emailContato').value;
var telefone = document.getElementById('telefoneContato').value;
var mensagem = document.getElementById('mensagemContato').value;

	if(document.getElementById('nomeContato').value==''){
		
		document.getElementById('nomeContato').focus()
		alert('Nome não pode ser nulo!')
			
	}else
	
	if (document.getElementById('emailContato').value.indexOf("@")==-1||document.getElementById('emailContato').value.indexOf(".")==-1){
		
		document.getElementById('emailContato').focus();
		alert('Preencha o E-mail corretamente!');
		
	}else 
	if(document.getElementById('telefoneContato').value==''){
		
		document.getElementById('telefoneContato').focus()
		alert('Telefone não pode ser nulo!')
			
	}else
	
	if(document.getElementById('mensagemContato').value==''){
		
		document.getElementById('mensagemContato').focus()
		alert('Mensagem não pode ser nulo!')
			
	}else{  
			
		goPage('contato.php?nome='+nome+'&email='+email+'&telefone='+telefone+'&mensagem='+mensagem,'exibePaginas')

    }
}


function limpadiv(div){
	
	
	document.getElementById(div).innerHTML='';
	
	
}


function Enviarajax(fpagina,div){
	ajax = ajaxInit();

	if(ajax){
		ajax.open('GET',fpagina,true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1")
		ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax.setRequestHeader("Pragma", "no-cache");
		ajax.onreadystatechange = function(){
			if(ajax.readyState==1){
					document.getElementById(div).innerHTML="<div align='center'><img src='imagem/loading.gif'/></div>"
	 		}			
			if(ajax.readyState==2){
					document.getElementById(div).innerHTML="<div align='center'><img src='imagem/loading.gif'/></div>"
	 		}
			if(ajax.readyState==3){
					document.getElementById(div).innerHTML="<div align='center'><img src='imagem/loading.gif'/></div>"
	 		}			
			if(ajax.readyState==4){
				
                

				document.getElementById(div).innerHTML=ajax.responseText;
				
				if(ajax.responseText){
					 
					 document.contato.nome.value="";
					 document.contato.email.value="";
					 document.contato.telefone.value="";
					 document.contato.mensagem.value="";
					 
					setTimeout("limpadiv('enviar')",5000); 
					                       }
					
	 		}
	 	}
	 }
 ajax.send(fpagina)
}


/*
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
							FUNÇÃO DE FORMATAR VALOR EM REAIS
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
*/


function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	
	if(document.all) {tecla=event.keyCode;} else {tecla=teclapres.which;} 
	if (tecla > 57)
	{
		//tecla=0;tecla < 48 || 
		campo.focus(); 
		return false;
	}
	vr = new String(campo.value);
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if(tam < tammax && tecla != 8){
		tam = vr.length + 1;
	}

	if(tecla == 8 ){
		tam = tam - 1;
	}
	if(tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if(tam <= 2 ){ 
			campo.value = vr;
		}
		if((tam > 2) && (tam <= 5)){
			campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
		}
		if((tam >= 6) && (tam <= 8)){
			campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
		if((tam >= 9) && (tam <= 11)){
			campo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
		if((tam >= 12) && (tam <= 14)){
			campo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
		if((tam >= 15) && (tam <= 17) ){
			campo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );
		}
	}
}