//--------------- [ Menus contraidos ]

  function jsCambiaCapaDisplay(eleId){
    var cual = document.getElementById(eleId);
    cual.style.display = (cual.style.display == "none") ? ("block") : ("none");
    return false;
  }

  function jsZonasNullMenu() {
    for (var i=0; i<100; i++) {
      var cual = 'zon_' + i;
      if (document.getElementById(cual))
         document.getElementById(cual).style.display = "none";
    }
  }
  function jsZonasCambiarMenu(menuId){
    var cual = 'zon_' + menuId;
    if (document.getElementById(cual).style.display == "none") {
       jsZonasNullMenu();
       document.getElementById(cual).style.display = "block";
    } else
       jsZonasNullMenu();
  }
 
  function jsSeccionNullMenu() {
    for (var i=0; i<100; i++) {
      var cual = 'sec_' + i;
      if (document.getElementById(cual))
         document.getElementById(cual).style.display = "none";
    }
  }
  function jsSeccionCambiarMenu(menuId){
    var cual = 'sec_' + menuId;
    if (document.getElementById(cual).style.display == "none") {
       jsSeccionNullMenu();
       document.getElementById(cual).style.display = "block";
    } else
       jsSeccionNullMenu();
  }

  function jsProduZonasNullMenu() {
    for (var i=0; i<100; i++) {
      var cual = 'pro_zon_' + i;
      if (document.getElementById(cual))
         document.getElementById(cual).style.display = "none";
    }
  }
  function jsProduZonasCambiarMenu(menuId){
    var cual = 'pro_zon_' + menuId;
    if (document.getElementById(cual).style.display == "none") {
       jsProduZonasNullMenu();
       document.getElementById(cual).style.display = "block";
    } else
       jsProduZonasNullMenu();
  }

  function jsProduAyuntNullMenu() {
    for (var i=0; i<100; i++) {
      var cual = 'pro_ayu_' + i;
      if (document.getElementById(cual))
         document.getElementById(cual).style.display = "none";
    }
  }
  function jsProduAyuntCambiarMenu(menuId){
    var cual = 'pro_ayu_' + menuId;
    if (document.getElementById(cual).style.display == "none") {
       jsProduAyuntNullMenu();
       document.getElementById(cual).style.display = "block";
    } else
       jsProduAyuntNullMenu();
  }
  function jsJumpMenu(selObj) {
    eval("parent.location='" + selObj.options[selObj.selectedIndex].value + "'");
  }

//--------------- [ Contenidos dinamicos ]

  function jsModifDinamico(tip){
    var txt = document.getElementById('txt_' + tip).value;
    var cod = document.getElementById('cod_' + tip).value;
    var idi = document.getElementById('idi_' + tip).value;

    axModifDinamico(tip, cod, txt, idi);
    return false;
  }

  function jsModifDinamicoAyunt(){
    var txt = document.getElementById('txt_wal').value;
    var cod = document.getElementById('cod_wal').value;

    axModifDinamicoAyunt(cod, txt);
    return false;
  }

//--------------- [ Formularios ]
  //News
  function jsEnviarNews(){
    var mai = document.getElementById('newmai').value;
    var sit = document.getElementById('newsit').value;
    var zon = document.getElementById('newzon').value;
    var idi = document.getElementById('newidi').value;	
	var pag = window.location.href;
	
	//Validar el email
	if(mailValido(document.getElementById('newmai'), document.getElementById('newidi').value))
		axEnviarNews(mai, sit, idi, zon, pag);
	return false;
  }
  //Preguntas
  function jsEnviarPregu(){
    var mai = document.getElementById('premai').value;
    var pre = document.getElementById('prepre').value;
    var sit = document.getElementById('presit').value;
    var zon = document.getElementById('prezon').value;
    var idi = document.getElementById('preidi').value;
    var pro = '';
	var pag = window.location.href;
	
	if(mailValido(document.getElementById('premai'),document.getElementById('preidi').value))
		axEnviarPregu(mai, pre, sit, idi, pro, zon, pag);
	return false;
  }
  //Reservas
  function jsEnviarReser(){
  	var objForm = document.forms['reserva'];    
    var pag = window.location.href;
	
	if(objForm['nom'].value=='')
    {
      alert("Debe indicar el nombre del producto");
      return false;
    }
      
    if(mailValido(objForm['resmai'], objForm['residi'].value))
	 	   axEnviarReser(objForm,pag);		
	  return false;
  }
  function jsEnviarContacto(){
  	var objForm = document.forms['contacto'];    
    var pag = window.location.href;
	      
    if(mailValido(objForm['conmai'],objForm['conidi'].value))
		axEnviarContacto(objForm,pag);		
	return false;  	
  }
  function jsEnviarAlta(){
  	var objForm = document.forms['alta'];    
    var pag = window.location.href;
	      
    if(!mailValido(objForm['altmai'],objForm['altidi'].value))
		return false;
	if(objForm['altnop'].value=='')
	{	
		alert('Debe rellenar el nombre del producto');
		objForm['altnop'].select();
		return false;
	}
	
	axEnviarAlta(objForm,pag);		
	return false;  	
  }  
  
  // Buscador
  function jsBuscar(){
    var txt = document.getElementById('txt_bus').value;
    var sit = document.getElementById('sit_bus').value;
    var idi = document.getElementById('idi_bus').value;
    axEnviarBusqueda(txt, sit, idi);
    return false;
  }
  
  // Ofertas
  function jsBuscarOfertas(pUrl){
  	var objForm = document.forms['frmBuscador'];  
  	
//alert(pUrl);
	if(validaciones())
		axEnviarBuscadorOfertas(pUrl,objForm);
	return false;
  }
  
  
  
//--------------- [ Funciones de Validacion]
//El array "DaysInMonth" contiene los dias que tiene cada mes
var DaysInMonth = new Array()
DaysInMonth[0] = 31 //Los dias de Enero
DaysInMonth[1] = 0 //Los dias de Febrero se calculan mas adelante por si el año es bisiesto
DaysInMonth[2] = 31 //Los dias de Marzo
DaysInMonth[3] = 30 //Los dias de Abril
DaysInMonth[4] = 31 //Los dias de Mayo
DaysInMonth[5] = 30 //Los dias de Junio
DaysInMonth[6] = 31 //Los dias de Julio
DaysInMonth[7] = 31 //Los dias de Agosto
DaysInMonth[8] = 30 //Los dias de Septiembre
DaysInMonth[9] = 31 //Los dias de Octubre
DaysInMonth[10] = 30 //Los dias de Noviembre
DaysInMonth[11] = 31 //Los dias de Diciembre

//la funcion IsInteger(Chain) chequea si "Chain" es un numero entero sin signo valido
//La variable "Chain" es una cadena de caracteres
function IsInteger(Chain)
{
	var Template = /^\d+$/ //Formato de numero entero sin signo
	return Template.test(Chain) //Compara "Chain" con el formato "Template"
}

//La funcion "IsDay(Day, Month)" chequea si "Day" es un numero de dia valido para el mes "Month"
//Las variables "Day" y "Month" son cadenas de caracteres
function IsDay(Day, Month)
{
	if (IsInteger(Day) && IsMonth(Month)) //Si "Day" es un numero entero valido y "Month" es un numero de mes valido
	{
		return (parseInt(Day,10)>0 && parseInt(Day,10)<=DaysInMonth[Month - 1]) ? 1 : 0 //Si "Day" esta entre 1 y los dias que tiene el mes "Month" devuelve verdadero si no devuelve falso
	}
	else return 0 //Si "Day" no es un numero entero valido o "Month" no es un numero de mes valido devuelve falso
}

//La funcion "IsMonth(Month)" chequea si "Month" es un numero de mes valido
//La variable "Month" es una cadena de caracteres
function IsMonth(Month)
{	
	if (IsInteger(Month)) //Si "Month" es un número entero valido
	{		
		return (parseInt(Month,10)>0 && parseInt(Month,10)<=12) ? 1 : 0 //Si "Month" esta entre 1 y 12 devuelve verdadero si no devuelve falso
	}
	else return 0 //Si "Month" no es un numero entero valido devuelve falso
}

//La funcion "IsYear(Year)" chequea si "Year" es un numero de año valido
//La variable "Year" es una cadena de caracteres
function IsYear(Year)
{
	if (IsInteger(Year)) //Si "Year" es un numero entero valido
	{
		return (Year.length == 4) ? 1 : 0 //Si "Year" tiene cuatro digitos devuelve verdadero si no devuelve falso
	}
	else return 0 //Si "Year" no es un numero entero valido devuelve falso
}

//La funcion IsLeapYear(Year) chequea si "Year" es un año es bisiesto
//La variable "Year" es una cadena de caracteres
function IsLeapYear(Year)
{
	if (IsInteger(Year)) //Si "Year" es un numero entero valido
	{
		return ((Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0)) ? 1 : 0// Si "Year" es un año es bisiesto devuelve verdadero si no devuelve falso
	}
	else return 0 //Si "Year" no es un numero entero valido devuelve falso
}

//La funcion IsDate(YourDate, YourDateSeparator) chequea si "YourDate" es una fecha valida con el separador de fecha "YourDateSeparator"
//Las variables "YourDate" y "YourDateSeparator" son cadenas de caracteres
function IsDate(YourDate, YourDateSeparator)
{
	var IsAllOK = 1 //Variable iniciada como verdadera para saber si todas las validaciones fueron correctas
	var YourDateParts = new Array() //Variable donde se almacenaran las partes de la fecha (dia, mes y año) tras haber eliminado el separador de la fecha
	YourDateParts = YourDate.split(YourDateSeparator) //Se crean las partes de la fecha (dia, mes y año) eliminando el separador de la fecha
	var Day = YourDateParts[0] //El dia corresponde al primer elemento del array
	var Month = YourDateParts[1] //El mes corresponde al segundo elemento del array
	var Year = YourDateParts[2] //El año corresponde al tercer elemento del array
	if (IsYear(Year) && !IsLeapYear(Year)) //Si "Year" es un numero de año valido y no es bisiesto
	{
		DaysInMonth[1] = 28 //Como "Year" no es bisiesto Febrero tiene entonces 28 dias
	}
	else if (IsYear(Year) && IsLeapYear(Year)) //Si "Year" es un numero de año valido y es bisiesto
	{
		DaysInMonth[1] = 29 //Como "Year" es bisiesto Febrero tiene entonces 29 dias
	}
	else IsAllOK = 0 //Si "Year" no es un numero de año valido la variable pasa a ser falsa
	IsAllOK = (IsMonth(Month)) ? IsAllOK : 0 //Si "Month" es un numero de mes valido la variable se queda como esta si no pasa a ser falsa
	IsAllOK = (IsDay(Day, Month)) ? IsAllOK : 0 //Si "Day" es un numero de dia valido para el mes "Month" la variable se queda como esta si no pasa a ser falsa
	return IsAllOK //Finalmente se devuelve el valor de la variable como verdadero o falso
}
function validarFecha(objFecha)
{
	if(objFecha.value!="")
	{
		if(!IsDate(objFecha.value, "-"))
		{				
			return false;
		}
	}	
	return true;		
}

function validaciones()
{
	if (!validarFecha(document.getElementById('txtFechaIni')))
	{ 
		alert("La fecha de Inicio introducida es incorrecta.\n\r(El formato debe ser dd-mm-aaaa)");
		document.getElementById('txtFechaIni').focus();
		return false;
	}
	if (!validarFecha(document.getElementById('txtFechaFin')))
	{
		alert("La fecha de Fin introducida es incorrecta.\n\r(El formato debe ser dd-mm-aaaa)");
		document.getElementById('txtFechaFin').focus();
		return false;		
	}
	return true;
}

//Validacion del  email
function mailValido(obj,idi)
{
	var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var returnval = emailfilter.test(obj.value);
	var msg = '';
	if (returnval==false)
	{		
		switch(idi)
		{
			case 'es':
				msg = 'Por favor, introduzca su e-mail:';
				break;
			case 'en':
				msg = 'Please, enter your e-mail address:';
				break;
			case 'fr':
				msg = 'Veuillez saisir votre adresse email:';
				break;
			case 'de':
				msg = 'Bitte geben Sie Ihre E-Mail Adresse ein:';
				break;				
			case 'pt':
				msg = 'Por favor, digite o seu endereço de e-mail:';
				break;
			case 'nl':
				msg = 'Tevreden, ga uw e-mailadres in:';
				break;
			case 'it':
				msg = 'Inserisci il tuo indirizzo e-mail:';
				break;				
		}
		alert(msg + obj.value);
		obj.select();
	}
	return returnval;	
}


