// JavaScript Document
function NewWin(theSource,theTitle)
{
	var winl = (screen.width - 280) / 2;
	var wint = (screen.height - 200) / 2;
	winprops = 'height=200,width=280,top='+wint+',left='+winl+',scrollbars=no,resizable=no'
	win = window.open("http://www.radiomaria.org/media/start.asp?SOURCE="+theSource+"&TITLE="+theTitle, "WinAudio", winprops)
}

function versellowsb(mypage, myname, w, h, scroll) {
  winl = (screen.width - w) / 2;
  wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function abreventzoom(fuente, ancho, alto) {
  ancho = ancho+20
  alto = alto+30
  x = screen.width/2-ancho/2
  y = screen.height/2-alto/2
  v=window.open(fuente, '', 'top=' + y + ', left=' + x + ', width='+ancho+', height=' + alto +'')
}

function tieneDatos(Valor) {
 if (Valor=='') return false;
  
 for (var i=0; i<Valor.length; i++) { 
   if ((" \t\n\r").indexOf(Valor.charAt(i))==-1) return true; 
   } 
 return false; 
}

function ValidarEmail(email){
    if( email.indexOf('@',0) <= 0  || email.indexOf(';',0) != -1
     || email.indexOf(' ',0) != -1 || email.indexOf('/',0) != -1
     || email.indexOf(';',0) != -1 || email.indexOf('<',0) != -1
     || email.indexOf('>',0) != -1 || email.indexOf('*',0) != -1
     || email.indexOf('|',0) != -1 || email.indexOf('`',0) != -1
     || email.indexOf('&',0) != -1 || email.indexOf('$',0) != -1
     || email.indexOf('!',0) != -1 || email.indexOf('"',0) != -1
     || email.indexOf(':',0) != -1 )
       { return false; }
    else return true;
}

function ValidaURL(Web) {
    if (Web == "") return false;
    else {
      if( (Web.substring(0, 7) != 'http://') || (Web.indexOf('.') < 0)) {
        return false;
      }
      else return true;
		}
}

function horaValida(hora) {

  if (!tieneDatos(hora)) return false;
  
	// Si no se especificó la hora pero se puso los :
	if (hora.indexOf(':')<=0) return false;

  horas = hora.split(':');
	
	var h = parseInt(horas[0]);
	var m = parseInt(horas[1]);
	
	if (isNaN(h) || isNaN(m)) return false;

	if ((h < 0) || (h>24) || (m < 0) || (m > 59)) return false;
	else return true;
}

function ValidarFecha(fecha)  {
    var Dia, Mes, Anyo, Dia_Mes_Mal = false;
    var fechaseparada= fecha.split("/");
		
    Dia = fechaseparada[0]; Mes = fechaseparada[1]; Anyo = fechaseparada[2];

    if( Dia == "" || Mes == "" || Anyo == "" ) return false;
    else {	    	
			while (Dia.substring(0,1)=="0") Dia = Dia.substring(1);
			if (Dia=="") return false;
      Dia = parseInt(Dia);
			
			while (Mes.substring(0,1)=="0") Mes = Mes.substring(1);
			if (Mes=="") return false;
      Mes = parseInt(Mes);

			while (Anyo.substring(0,1)=="0") Anyo = Anyo.substring(1);
			if (Anyo=="") return false;			
      Anyo = parseInt(Anyo);

      if( !isNaN(Dia) && !isNaN(Mes) && !isNaN(Anyo) && (Dia >= 1 && Mes >= 1 && Anyo >= 1900))  {
        /* Los meses de Enero, Marzo, Mayo, Julio, Agosto, Octubre y Diciembre tienen 31 días */
        if((Mes == 1 || Mes == 3 || Mes == 5 || Mes == 7 || Mes == 8 || Mes == 10 || Mes == 12) && (Dia > 31)) 
				  Dia_Mes_Mal = true;
					
        /* Los meses de Mayo, Junio, Septiembre y Noviembre tienen 30 días */
        if((Mes == 4 || Mes == 6 || Mes == 9 || Mes == 11) && (Dia > 30)) 
					Dia_Mes_Mal = true;
					
    		/* Febrero tiene 28 ó 29 días, dependiendo de si es bisiesto o no. Un año es bisiesto si es múltiplo de 4 pero no de
       		 100 salvo que sea múltiplo de 400. Por ejemplo, 12 y 400 son bisiestos, pero 100 y 700 no. */
        if( Mes == 2 && ( Dia > 29 || ( Dia == 29 && ( (Anyo % 400 != 0) && ((Anyo % 4 != 0) || (Anyo % 100 == 0)))))) 
				  Dia_Mes_Mal = true;

        if(Dia_Mes_Mal) {return false;}
        else return true;
      }   /* Si la fecha está fuera del rango razonable... */
      else {return false;}
    }
}

function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function ctrlinicio() {
  document.formdireccion.url.value = Trim(document.formdireccion.url.value);
	document.formdireccion.email.value = Trim(document.formdireccion.email.value);
	
	if (!tieneDatos(document.formdireccion.url.value)){
		 alert('Debe insertar la dirección de su web para que podamos realizar el Análisis Básico de Accesibilidad Web.');
		 return(false);
	}
  if (!tieneDatos(document.formdireccion.email.value)){
		 alert('Debe insertar una dirección de correo electrónico a la que debemos enviarle el Análisis Básico de Accesibilidad Web solicitado.');
		 return(false);
	}
  if (!ValidarEmail(document.formdireccion.email.value)){
 		 alert('Por favor, inserte una dirección de correo electrónico válida.');
 		 return(false);
 	}
	return(true);
}

function controlcontacto() {
	if(!tieneDatos(document.FormContacto.nombre.value)){
		alert('Para un contacto personalizado le rogamos que introduzca su nombre');
		document.FormContacto.nombre.focus(); 
		return (false);
	} 
	
	if(!tieneDatos(document.FormContacto.email.value)){
		alert('Si no dispone de correo electrónico,\n indíquenos su dirección y/o teléfono \nen el campo EMAIL');
		document.FormContacto.email.focus(); 
		return (false);
	} 
	
	if(!tieneDatos(document.FormContacto.asunto.value)){
	  alert('Para tramitar su contacto con mayor rapidez le rogamos que introduzca un texto en el campo ASUNTO');
		document.FormContacto.asunto.focus(); 
		return (false);
	} 
	
	if(!tieneDatos(document.FormContacto.mensaje.value)){
	  alert('Debe introducir el texto de su sugerencia en el campo MENSAJE');
		document.FormContacto.mensaje.focus(); 
		return (false);
  } 
	
	if(!tieneDatos(document.FormContacto.empresa.value)){
	  document.FormContacto.empresa.value='PARTICULAR';
		return(true);
	}
	
	if (document.FormContacto.nombre.value==document.FormContacto.email.value)
	{
	 alert('Debe rellenar los campos con datos reales. Gracias'); 
	 return (false);
	}
	if (document.FormContacto.nombre.value==document.FormContacto.asunto.value) 
	{
	 alert('Debe rellenar los campos con datos reales. Gracias'); 
	 return (false);
	}

	 
}
