// JavaScript Document
function validar_entrada(variable){
	var caracteres = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyzáéíóúÁÉÍÓÚ1234567890 "
  for (i = 0;  i < variable.length;  i++)  {
    ch = variable.charAt(i);
    if(caracteres.indexOf(ch) == -1) {return (false);}

    if(variable.substring(i,i + 6).toUpperCase() == "INSERT") {return (false);}
    if(variable.substring(i,i + 6).toUpperCase() == "SELECT") {return (false);}
    if(variable.substring(i,i + 6).toUpperCase() == "UPDATE") {return (false);}
    if(variable.substring(i,i + 6).toUpperCase() == "DELETE") {return (false);}
  }
}

function validar_formulario(theForm){
if (theForm.txtBuscar.value == "") {
	fmrBusqueda.txtBuscar.value="Introduzca Palabra";
	return (false);}
if (validar_entrada(theForm.txtBuscar.value) == false) {
  alert ('Ha introducido caracteres inválidos en el texto de búsqueda, elimínelos y vuelva a intentarlo');	
  theForm.txtBuscar.focus();
  return (false);}
 }

function BuscarCategoria(targ,selObj,restore) {
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  	if (restore) selObj.selectedIndex=0;
}

function hacer_busqueda() {
	valor = fmrBusqueda.txtBuscar.value;
	if (valor =="" || valor =="Introduzca Palabra" || valor =="Busca tu Master...") {
		fmrBusqueda.txtBuscar.value="Introduzca Palabra";
	} 
	else {
	if (validar_entrada(fmrBusqueda.txtBuscar.value) == false) {
	  	alert ('Ha introducido caracteres inválidos en el texto de búsqueda, elimínelos y vuelva a intentarlo');	
	  	fmrBusqueda.txtBuscar.focus();
  	}	else {
		fmrBusqueda.submit();
	}
	}
}
function vaciarBusqueda() {
	valor = fmrBusqueda.txtBuscar.value;
	if (valor =="" || valor =="Introduzca Palabra" || valor =="Buscador de Masters" || valor =="Busca tu Master...") {
		document.fmrBusqueda.txtBuscar.value="";
	} 
}

var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}

function selectmouse(e)
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
  while (fobj.tagName != topelement && fobj.className != "arrastrame")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className=="arrastrame")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}

document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");

	function MostrarCapa(capa){
	  if(document.layers)document.layers[capa].visibility='show'     // Si utilizamos NS
	  if(document.all)document.all(capa).style.visibility='visible'  // Si utilizamos IE
	}
	
	function OcultarCapa(capa,vDestino){
	  if(document.layers)document.layers[capa].visibility='hide'     // Si utilizamos NS
	  if(document.all)document.all(capa).style.visibility='hidden'   // Si utilizamos IE
	 
	}
	
function abrir_ventana(pagina){
window.open(pagina,'','toolbar=no,location=no,resizable=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=no,width=380,height=405,top=130,left=250');
}

function abrir_ventana_condiciones() {
window.open('http://www.aprendemas.com/legal/condiciones_f2body.asp','','toolbar=no,location=yes,resizable=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=yes,width=400,height=400');
}

function enviar_onclick() {
	if (document.frmEnviarAmigo.fmNombre.value=="" || document.frmEnviarAmigo.fmEmail.value=="" || document.frmEnviarAmigo.fmEmail2.value=="" ) { 
		alert("Rellene todos los campos requeridos");
		return false;
	}
	mascara = /^[_\w\d-]+(\.[_\w\d-]+)*@[\w\d-]+(\.[\w\d-]+)*(\.([\w]){2,4})$/;
	testMascara = mascara.test(document.frmEnviarAmigo.fmEmail.value);
	if (!testMascara) {  // Validamos el email
		alert("No es una dirección de email válida.");
		document.frmEnviarAmigo.fmEmail.focus();
		return false;
	}
	
//Validaciones del Mensaje
	var texto = frmEnviarAmigo.fmMensaje.value;
	
	if  (DPTelefono(texto) == true)
		{alert("No se permite la introdución de teléfonos en el contenido del Mensaje");
		 frmEnviarAmigo.fmMensaje.focus();
		 return false;}
	
	if  (DPVinculo2(texto) == true)
		{alert("No se permite la introdución de hipervínculos en el contenido del Mensaje");
		 frmEnviarAmigo.fmMensaje.focus();
		 return false;}
	
	if  (DPEmail(texto) == true)
		{alert("No se permite la introdución de direcciones de correo en el contenido del Mensaje");
		 frmEnviarAmigo.fmMensaje.focus();
		 return false;}
}

// Función para comprobar si hay un nº de telefono en el editor de texto
function DPTelefono(texto) {
	//Patrones de Teléfonos
	
	//xxxxxxxxx /o/xxxxxxxxx/
	var exp1 = /([0-9]{9}\D)|([0-9]{9})/gi;
	var rem1 = texto.replace(exp1,"");
	
	//xxx xxx xxx /o/xxx xxx xxx/
	var exp2 = /([0-9]{3}\D)([0-9]{3}\D)([0-9]{3}\D)|([0-9]{3}\D)([0-9]{3}\D)([0-9]{3})/gi;
	var rem2 = texto.replace(exp2,"");
	
	//xx xxx xx xx /o/xx xxx xx xx/
	var exp3 = /(\d{2}\D\d{3}\D\d{2}\D\d{2}\D)|(\d{2}\D\d{3}\D\d{2}\D\d{2})/gi;
	var rem3 = texto.replace(exp3,"");
	
	//xx xxxxxxx /o/xx xxxxxxx/
	var exp4 = /(\d{2}\D\d{7}\D)|(\d{2}\D\d{7})/gi;
	var rem4 = texto.replace(exp4,"");
	
	if ((rem1.length != texto.length)|(rem2.length != texto.length)|(rem3.length != texto.length)|(rem4.length != texto.length))
		{	return true;	}
	else
		{	return false;	}
}
// Función para comprobar si hay un Hipervínculo en el editor de texto
function DPVinculo(texto) {
	//Patrones de Hipervínculos
	
	var exp1 = new RegExp("http://([a-z]*)", "gi");
	var rem1 = texto.replace(exp1," ");
	
	var exp2 = /(www[\.])/gi;
	var rem2 = texto.replace(exp2," ");
	
	if ((rem1.length != texto.length)|(rem2.length != texto.length))
		{	return true;	}
	else
		{	return false;	}
}
// Función para comprobar si hay un Email en el editor de texto
function DPEmail(texto) {
	//Patron de Email
	
	//xxxxx@zzzz.yyy
	var exp1 = /([a-z]*)@([a-z]*)[\.]([a-z]{2,3})/gi;
	var rem1 = texto.replace(exp1," ");
	
	if (rem1.length != texto.length)
		{	return true;	}
	else
		{	return false;	}
}

function DPVinculo2(texto) {
	//Patrones 2 de Hipervínculos
	
	var exp1 = new RegExp("www.([a-z]*).([a-z]{3})", "gi");
	var rem1 = texto.replace(exp1," ");
	
	var exp2 = new RegExp("www.([a-z]*).([a-z]{2})", "gi");
	var rem2 = texto.replace(exp2," ");
	
	var exp3 = new RegExp("http://", "gi");
	var rem3 = texto.replace(exp3," ");

	
	if ((rem1.length != texto.length)|(rem2.length != texto.length)|(rem3.length != texto.length))
		{	return true;	}
	else
		{	return false;	}
}

function Arroba(sString)
{
	var str = sString.value
	// Return false if e-mail field does not contain a '@' and '.' .   
	if (str.indexOf ('@',0) == -1 || str.indexOf ('.',0) == -1)
		{
		alert('Introduzca correctamente el E-mail')
		sString.focus()
		return false 
	}
	else
		{
		return true;      
		}
}

//Función Validación Campos de Alta ClubFOrmación.
// Validación campos requeridos en el 1º post
function ValidaAltaClubPost1(){
		if(frmAltaClub.fmNombre.value == ""){
		alert("Introduce tu Nombre.");
		frmAltaClub.fmNombre.focus();
		return false;
	}
	if(frmAltaClub.fmEmail.value == ""){
		alert("Introduce tu Email.");
		frmAltaClub.fmEmail.focus();
		return false;
	}
	if(frmAltaClub.fmEmail2.value == ""){
		alert("Repite tu Email para confirmarlo.");
		frmAltaClub.fmEmail2.focus();
		return false;
	}
	if(frmAltaClub.fmEmail2.value != frmAltaClub.fmEmail.value){
		alert("Los emails introducidos no coinciden.");
		frmAltaClub.fmEmail2.focus();
		return false;
	}		
	if(frmAltaClub.fmProvincia.value == ""){
	alert("Selecciona tu Provincia.");
	frmAltaClub.fmProvincia.focus();
	return false;
	}
	if(frmAltaClub.fmCategorias.value == ""){
	alert("Selecciona las Categorías que más te interesan.");
	frmAltaClub.fmCategorias.focus();
	return false;
	}
}
// Validación campos requeridos en el 2º post
function ValidaAltaClubPost2(){
	if(frmAltaClub.fmConocido.value == ""){
		alert("Selecciona una opción.");
		frmAltaClub.fmConocido.focus();
		return false;
	}
}

function AbrirVentanaLegal(){
	window.open('/Legal/IndexBody.asp','','toolbar=no,location=no,resizable=no,directories=no,status=no,menubar=no,copyhistory=no,scrollbars=yes,width=568,height=380');
}

