// -- AJAX -------------------------------------------------------------------------------
function inc(url, destino, parametros){
    var req = null;
    if (!parametros) 
        parametros = '';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        requesita();
    }
    else 
        if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            requesita();
        }
    
    function requesita(){
        req.open("POST", url, true);
        req.onreadystatechange = processa_pagina;
        req.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=iso-8859-1");
        req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        req.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
        req.setRequestHeader("Pragma", "no-cache");
        req.setRequestHeader("expires", "0");
        req.send(parametros);
    }
    
    function processa_pagina(){
        document.getElementById(destino).innerHTML = "<div id=\"carregando\" class=\"doze\">Carregando...</div>";
        if (req.readyState == 4) {
            if (req.status == 200) {
                document.getElementById(destino).innerHTML = req.responseText;
                ScriptOnload(req.responseText);
            }
           /* else {
                alert("Houve um problema ao obter os dados:\n" + req.statusText + "\n" + url);
            }*/
        }
    }
}

function ScriptOnload(texto){
    var Emular = document.createElement('script');
    var encontrou = texto.indexOf('onload', "0");
    if (encontrou != -1) {
        dividir = texto.split('onload="');
        fim = dividir[1].split('"');
        Emular.setAttribute('language', 'Javascript');
        Emular.text = fim[0];
        document.body.appendChild(Emular);
    }
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


if(document.all) { 
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { 
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

    sValue = objeto.value;

    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) {
      if (sMask.charAt(i-1) == "9") {
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { 
        return true;
      } 
    }
    else {
      return true;
    }
  }
 function verificaCaracter(objnome){
  caracter = objnome.value;
  if (caracter.length == 0){
    return true;
  }
  return false;
}
function verificaEmail(objnome){
  invalid = Array("ç","~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?"," ");
  xemail = objnome.value;
  if (xemail.indexOf("@")==-1){
    return true;
  }else{
    partes=xemail.split("@");
    if(partes[0]=="" || partes[0].length < 2){
      return true;
    }else{
      for(i=0;i < invalid.length;i++){
        if(partes[0].indexOf(invalid[i])!=-1){ return true }
      }
    }
    if(partes[1]==""){
      return true;
    }else{
      if (partes[1].indexOf(".")==-1){
        return true;
      }else{
        ponto=partes[1].split(".")
        if(ponto[0]=="" || ponto[0].length < 2){
          return true;
        }else{
          for(i=0;i < invalid.length;i++){
            if(ponto[0].indexOf(invalid[i])!=-1){ return true }
          }
        }
        if(ponto[1]==""){ return true; }
      }
    }
  }
  return false
}
function SomenteNumeros(input){
	if ((event.keyCode<48)||(event.keyCode>57))
		event.returnValue = false;
}
function FormataValor(campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;
	var vr = 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 ; }
	 	tam = tam - 1;
	 	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 ) ;}
	}
}

function envia_contato(form){ //realiza a captura dos dados do post para o acesso
	var valor = 'destinatario='+form.destinatario.value+'&copia='+form.copia.value+'&assunto='+form.assunto.value+'&nome='+form.nome.value+'&email='+form.email.value+'&telefone='+form.telefone.value+'&mensagem='+form.mensagem.value+'&cidade='+form.cidade.value+'&uf='+form.uf.value;
	inc('contato_envia.php','formEnvia',valor);
	camposLimpa(form);
}

function camposLimpa(form){
	if(form.mensagem.value != '' && form.nome.value != '' && form.email.value != ''){
		form.mensagem.value = '';
		form.nome.value = '';
		form.email.value = '';
		form.assunto.value = '';
		form.telefone.value = '';
		form.cidade.value = '';
		form.uf.value = '';
		
		form.nome.focus();
	}
	return true;
}

$(document).ready(function() {
	$('#menu #portfolio')
	.css({backgroundPosition:"-14px -76px", color:"#FFF"})
    .hover(function(){
        $(this).stop().animate({backgroundPosition:"-14px -124px", color:"#EEE", fontSize:"18px"}, 200);
    }, function(){
        $(this).stop().animate({backgroundPosition:"-14px -76px", color:"#FFF", fontSize:"20px"}, 200);
    });
	
	$('#menu #clientes')
	.css({backgroundPosition:"-149px -76px", color:"#FFF"})
    .hover(function(){
        $(this).stop().animate({backgroundPosition:"-149px -124px", color:"#EEE", fontSize:"18px"}, 200);
    }, function(){
        $(this).stop().animate({backgroundPosition:"-149px -76px", color:"#FFF", fontSize:"20px"}, 200);
    });
	
	$('#menu #contato')
	.css({backgroundPosition:"-269px -76px", color:"#FFF"})
    .hover(function(){
        $(this).stop().animate({backgroundPosition:"-269px -124px", color:"#EEE", fontSize:"18px"}, 200);
    }, function(){
        $(this).stop().animate({backgroundPosition:"-269px -76px", color:"#FFF", fontSize:"20px"}, 200);
    });
	
	$('.caixa.caxinha').css({bottom: -135});
	$('.caixa')
	.hover(function(){
		$(".caxinha", this).stop().animate({bottom:'0px'}, 500);
	}, function() {
		$(".caxinha", this).stop().animate({bottom:'-135px'}, 500);
	});

});
