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;
}

function enviarMail(){
	c = document.getElementById("resultado_mensaje");
	ID = document.enviar_email.IDA.value;
	DD = document.enviar_email.DD.value;

	nombre= document.enviar_email.nombre.value;
	de	  = document.enviar_email.email.value;
	para  = document.enviar_email.para.value;

	men	  = document.enviar_email.mensaje.value;
	cap	  = document.enviar_email.captcha.value;
	
	ajax=nuevoAjax();
	c.innerHTML = '<p style="text-align:center;"><img src="http://www.psicologia-online.com/araceli/articulos/imagenes/esperando.gif"/></p>'; 
	ajax.open("POST", "../includeGUI/js/formulario/envia_mail.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			c.innerHTML = ajax.responseText
			if(c.innerHTML == '1'){
				//envio el email
				c.innerHTML = "Gracias por enviar su consulta...<br/><a href='#' onClick='volver(2);'>Volver a la tabla de información</a>";	
				borrarCampos();
				document.getElementById('VisFrm').style.display="none";
			}
			if(c.innerHTML == '2'){
				//Email no valido
				c.innerHTML = "La direcci&oacute;n de email es incorrecta<br/><a href='#' onClick='volver(2);'>Volver a la tabla de información</a";
			}
			if(c.innerHTML == '3'){
				//Codigo Erroneo
				c.innerHTML ="El texto de la imagen es incorrecto<br/><a href='#' onClick='volver(2);'>Volver a la tabla de información</a";
			}
			
			c.innerHTML="<div style=\"font-size:12px; color: #000000	; font-weight:bold;	 border:3px solid #FFCC00; line-height:1.8em; padding:10px 15px 10px 10px; margin:10px 10px 10px 10px;\">"+c.innerHTML+"</div>";
		}
		
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("ID="+ID+"&DD="+DD+"&nombre="+nombre+"&emailPARA="+para+"&emailDE="+de+"&mensaje="+men+"&captcha="+cap)
}

function borrarCampos(){
	document.enviar_email.nombre.value="";
	document.enviar_email.email.value="";
	document.enviar_email.para.value="";
	document.enviar_email.mensaje.value="";
	document.enviar_email.captcha.value="";
}

/*--------------------------*/
function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' Ingrese un E-mail valido.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' son requeridos.\n'; }
    } if (errors) alert('Error(es) ocurridos:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function volver(Opc, email, id, deDonde){
	var inf1Aux=document.getElementById('Inf1');
	var inf2Aux=document.getElementById('Inf2');
	if(Opc==2){ 
		document.getElementById("Inf1").style.display="block"; 
		document.getElementById("Inf2").style.display="none"; 
		document.enviar_email.imgCod.src="../includeGUI/js/formulario/captcha.jpg"; }
		
	else{ 
		document.getElementById("Inf2").style.display="block"; 
		document.getElementById("Inf1").style.display="none";
		
		document.getElementById('VisFrm').style.display="block";
		
		document.enviar_email.para.value=email;
		document.enviar_email.IDA.value=id;
		document.enviar_email.DD.value=deDonde;
		document.enviar_email.imgCod.src="../includeGUI/js/formulario/Cap_Img.php";
		
		document.getElementById("resultado_mensaje").innerHTML="<div style=\"font-size:12px; color: #000000	; font-weight:bold;	 border:3px solid #FFCC00; line-height:1.8em; padding:10px 15px 10px 10px; margin:10px 10px 10px 10px;\"><a href='#' onClick='volver(2);'>Volver a la tabla de información</a></div>";
	}
}
