// JavaScript Document
function nuevoAjax(){var xmlhttp=false;try
{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e)
{try
{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(E){xmlhttp=false;}}
if(!xmlhttp&&typeof XMLHttpRequest!='undefined'){xmlhttp=new XMLHttpRequest();}
return xmlhttp;}

var  pontitulo=new Array();

function espere(div)
  {
  document.getElementById(div).innerHTML="<div align='center' style='text-align:center'><img src='images/espere.gif'></div>"  
  }

function rojo(ctrl)
  {
  var capa=document.getElementById(ctrl);
  capa.style.background="#FF0000";
  capa.style.color="#000000";
  capa.focus();
  }
function normal(ctrl)
  {
  ctrl.style.background="#FFCC00";
  }
  
var cadena="";
function controla_letras(div,max,muestra){
  if(!muestra)	
    muestra="numero_caracteres";
  maximo=max;
  var cad=document.getElementById(div).value;
  if(cad.length>max){
    document.getElementById(div).value=cadena;
	}
  else{
    cadena=cad;
	document.getElementById(muestra).innerHTML="(Act: <strong>" +cad.length +"</strong>)";
    }	
  }
  
function controla_envio()
  {
  var nombre=document.getElementById("nombre").value;
  if(nombre=="")
    {
	alert("Por favor, indíquenos su nombre");
	rojo("nombre");
	return false;
	}
  
  var mail=document.getElementById("mail").value;
  var mail2=document.getElementById("mail2").value;
  if(control_mail(mail))
    {
	alert("Mail incorrecto");
	rojo("mail");
	return false;
	}
  if(mail!=mail2)
    {
	alert("Los mails no coinciden");
	rojo("mail");
	return false;
	}
  if(document.getElementById("USER").value=="")
    {
	alert("Por favor, repita el código de control");
	rojo("USER");
	return false;
	}
  if(document.getElementById("REAL").value!=document.getElementById("USER").value)
    {
	alert("Código de control incorrecto");
	rojo("USER");
	return false;
	}
  }
 
 function contactar()
   {
   var capa=document.getElementById("frm_contacto");
   var nombre=document.getElementById("nombre").value;
   var mail=document.getElementById("mail").value;   
   var telefono=document.getElementById("telefono").value;   
   var comentarios=document.getElementById("comentarios").value;
   capa.style.background="#FFFFFF";
   capa.style.border="0px";
   espere("frm_contacto");
   ajax=nuevoAjax();
   ajax.open("POST","FUNCIONES/mail.php",true);
   ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   ajax.send("nombre="+nombre+"&mail="+mail+"&telefono="+telefono+"&comentarios="+comentarios+"&accion=envia_mail");
   ajax.onreadystatechange=function()
     {
	 if(ajax.readyState==4)
       {
	   capa.innerHTML=ajax.responseText;
	   }
	 }
   }

function control_mail(mail)
  {
  var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
  if(mail.length==0)
    {
	return true;
	}
  else
    {
	if(filter.test(mail))
	  {
	  return false;
	  }
    else
	  {
	  return true;
	  }
	}
  }

function NuevoCodigo(div,pagina)
  {
  var capa=document.getElementById(div);
  espere(div);
  var ajax=nuevoAjax();
  ajax.open("POST","FUNCIONES/codigo.php",true);
  ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  ajax.send("opcion=nuevo_codigo");
  ajax.onreadystatechange=function()
    {
	if(ajax.readyState==4)
      {
	  capa.innerHTML=ajax.responseText;
	  }
	}
  }  