// JavaScript Document
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function otros_fun(){
	if (document.getElementById('idconocio').value=="Otros") {
	document.getElementById('idotros').disabled="";
	document.getElementById('idotros').style.borderColor="#F7931E";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}	
	else
	{
	document.getElementById('idotros').disabled="disabled";
	document.getElementById('idotros').style.borderColor="#CCCCCC";
	document.getElementById('idotros').style.borderStyle="solid";
	document.getElementById('idotros').style.borderWidth="1";
	}
}

function PonerRojo(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="#00547B";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
if (NombreCampo=="Email"){
  if (!nombre.value) alert("El campo "+NombreCampo+" esta vacio");
  else alert("Direccion de Email invalida");
} else if (NombreCampo=="Sexo" || NombreCampo=="Pais") {
  alert("Debe elegir una opcion del campo de seleccion "+NombreCampo);
} else {
  alert("El campo "+NombreCampo+" esta vacio");
}
nombre.focus();
}

function PonerRojoNOJS(iD, NombreCampo){
var nombre = document.getElementById(iD);
nombre.style.borderColor="#00547B";
nombre.style.borderStyle="solid";
nombre.style.borderWidth="1";
nombre.focus();
}

function Normalizar(iD){
// var nombre = document.getElementById(iD);
// var nombre = iD;
iD.style.borderColor="";
iD.style.borderStyle="";
iD.style.borderWidth="";
}

// Validador de la consulta
function Validar_consulta(){
  var nombre = document.getElementById("idnombre");
  var email = document.getElementById("idemail");
  var comentarios = document.getElementById("idcomentarios");

Normalizar(nombre);
Normalizar(email);
Normalizar(comentarios);
  if (!nombre.value){
    PonerRojo('idnombre','Nombre');
    return false;
  }
  if (!isEmail(email.value)) {
    PonerRojo('idemail','email');
    return false;
  }
  if (!comentarios.value){
    PonerRojo('idcomentarios','Intereses');
    return false;
  }
document.consulta.submit();
}