function requisicao()
{
  req = false;
	if(window.XMLHttpRequest)
	{
		try
		{
			req = new XMLHttpRequest();
		}
		catch(e)
		{
			req = false;
		}
	}
	else if(window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				req = false;
			}
		}
	}
	return req;
}



function atualiza(url,nome_div){
   document.getElementById(nome_div).innerHTML = "<font color='#FFFFFF' style='font-family:verdana;font-size:10px;'><b>CARREGANDO...</b></font>";
   req = requisicao();
   req.open("GET", url, true);
   req.onreadystatechange = function(){
       if(req.readyState == 4){
           if(req.status == 200){
            var texto = req.responseText
 
            document.getElementById(nome_div).innerHTML = texto;
            
            $(function() {
            $('#foto_ampliada a').lightBox();
             });
           }
       }
   }
   req.send(null);
}

function carregarUrl(url,target,carregando)
{ 
  
  if( typeof carregando == 'undefined')
	{
		carregando = '<font color="#983327" style="font-family:verdana;font-size:10px;"><b>carregando...</b></font>';
	}
	else
	{	 
		carregando = carregando;				
	}
	document.getElementById(target).innerHTML = carregando;
	req = requisicao();
	req.open("GET", url, true);
	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				var texto = req.responseText
				document.getElementById(target).innerHTML = texto;
					
          $(function() {
             $('#foto_ampliada a').lightBox();
          });
        
        if(url == "contato.php"){
            $(document).ready(function(){
            $('#formStatus').hide();
            $('#enviado').hide();
            $("#telefone").mask("(99) 9999-9999");
          
               
            $('#btnEnviar').click(function(){
          
            $("#formContato").validate({
              rules: {
                  nome: {
                      required: true,
                      minlength: 5
                    },
                  email: {
                      required: true,
                      minlength: 7,
                      email: true
                    },
                  assunto: {
                      required: true,
                      minlength: 4
                    },
                  mensagem: {
                      required: true,
                      minlength: 4
                    }
              },
              submitHandler: function() { 
              
               $("#formStatus").fadeIn("fast");
               $('#enviado').show();
            
              $.post('PHP/enviar.php', 
              {
                nome: $('#nome').val(),
                assunto: $('#assunto').val(),
                telefone: $('#telefone').val(),
                email: $('#email').val(),
                mensagem: document.getElementById("mensagem").value
              }, function(response){
                 $('#enviado').hide();
                 $('#formStatus').html(response);
                 $('#nome').val('');
                 $('#assunto').val('');
                 $('#telefone').val('');
                 $('#email').val('');
                 document.getElementById("mensagem").value = ' ';
                 })
            return false;
            }
             });
            });  
          
          });   
        } 
			}
		}
	}
	req.send(null);
	

}
