var mMessage = "Este Campo es Obligatorio rellenarlo."
var mPrecio = "El precio no es correcto.\nEjemplo en Euros: 35,67"
var mCat = "Debe seleccionar la Familia a la que pertenece el Producto."
var mCantidad = "El Nº de Plazas no es correcto.\nIntroduzca un Número Entero Positivo como Nº de Plazas.\nEjemplo: 8 ó 0 si quiere que aparezcan todos."
var defaultEmptyOK = false

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function statBar (s)

{   window.status = s
}

function warnEmpty (theField)
{   theField.focus()
    alert(mMessage)
    statBar(mMessage)
    return false
}

function warnPrecio (theField)
{ 	theField.focus()
    alert(mPrecio)
    statBar(mPrecio)
    return false
}

function warnCantidad (theField)
{ 	theField.focus()
    alert(mCantidad)
    statBar(mCantidad)
    return false
}

function warnCategoria (theField)
{ 	theField.focus()
    alert(mCat)
    statBar(mCat)
    return false
}	

function mensaje(msg) {
	window.status =  ""+ msg +""
}

function isDigit (c){  
	return ((c >= "0") && (c <= "9"))
}

function isNumber (s) /*Numeros Decimales sin Signo Ej. 35,56 */

{   var i;
    var dotAppeared;
    dotAppeared = false;
    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.arguments[1] == true);  
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if ( (c == ".")||(c == ",") ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } else     
                if (!isDigit(c)) return false;
        } else { 
            if ( (c == ".")||(c == ",") ) {
                if( !dotAppeared )
                    dotAppeared = true;
                else
                    return false;
            } 
        }
    }

    return true;

}

function EsNumeroPositivo(Dato,Campo) /*Numeros enteros sin Signo Ej. 35 */
{
  var CadenaNumeros="0123456789";
  var EsteCaracter;
  var Contador=0;
  
  if (isEmpty(Dato)==false) 
  {  
  
	  for (i=0;i<Dato.length;i++)
		{
		  EsteCaracter=Dato.substring(i,i+1);
		  if (CadenaNumeros.indexOf(EsteCaracter)!=-1)
				Contador++;
		}
	  if (Contador==Dato.length)
		{
			return(true);
		}
	  else
		{
		  /*alert("Introduzca un Número Entero Positivo como Cantidad.");
		  Campo.focus();*/
		  return(false);
		}
  }
  else
  {
  	return(false);
  }
}

function isNumero (s) /* Numeros Enteros sin signo Ej. 23 */
{   var i;
    if (isEmpty(s)) 
       if (isNumero.arguments.length == 1) return defaultEmptyOK;
       else return (isNumero.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if( i != 0 ) {
            if (!isDigit(c)) return false;
        } else { 
            if (!isDigit(c)) return false;
        }
    }
    return true;
}

function VerificarTodo()  {
	if(isEmpty(document.frm_buscador_avanzado.txtClave.value))	
	{
		//El Nº de Plazas. Entero Positivo.
		if(!isEmpty(document.frm_buscador_avanzado.plazas.value))	
			{				
			if (!EsNumeroPositivo(document.frm_buscador_avanzado.plazas.value,document.frm_buscador_avanzado.plazas))
				{
					warnCantidad (document.frm_buscador_avanzado.plazas)			
					return false;
				}		
			}
		else {
				warnCantidad (document.frm_buscador_avanzado.plazas)			
				return false;					
		}

		/* Las Fechas: 
			1º Si una se rellena la otra es obligatoria
			2º La Fecha de Inicio debe ser menor que la Fecha de Fin
			3º Las Fechas deben ser igual o mayor que la Fecha de Hoy.
		*/
		
	if (!isEmpty(document.frm_buscador_avanzado.fecha_desde.value)&&!isEmpty(document.frm_buscador_avanzado.fecha_hasta.value))
	  {
	    //Formato de fecha de hoy dd/mm/yy
	   	
		var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate();
        var FechaHoy =(dayNr+"/"+(now.getMonth()+1)+"/"+now.getYear());

	    if (document.frm_buscador_avanzado.fecha_desde.value>=document.frm_buscador_avanzado.fecha_hasta.value)
			{
				alert("La Fecha Inicial debe ser menor que la Fecha Final.");
				document.frm_buscador_avanzado.fecha_desde.focus();
				return false;				
			}
			
		/*
	    if (document.frm_buscador_avanzado.fecha_desde.value<FechaHoy)
			{
				alert("La Fecha Inicial debe ser mayor o igual que la Fecha de Hoy: "+FechaHoy+" .");
				document.frm_buscador_avanzado.fecha_desde.focus();
				return false;				
			}			
			
	    if (document.frm_buscador_avanzado.fecha_desde.fecha_hasta<=FechaHoy)
			{
				alert("La Fecha Final debe ser mayor que la Fecha de Hoy: "+FechaHoy+" .");
				document.frm_buscador_avanzado.fecha_hasta.focus();
				return false;				
			}
		*/
		
	  }/*De si no están vacias las fechas*/
	  else {
		if (!isEmpty(document.frm_buscador_avanzado.fecha_desde.value)&&isEmpty(document.frm_buscador_avanzado.fecha_hasta.value))
		  {
			  	alert("Si desea filtrar por fechas de indicar la Fecha Final.");
				document.frm_buscador_avanzado.fecha_desde.focus();
				return false;	
		  }
		if (isEmpty(document.frm_buscador_avanzado.fecha_desde.value)&&!isEmpty(document.frm_buscador_avanzado.fecha_hasta.value))		  
		  {
			  	alert("Si desea filtrar por fechas de indicar la Fecha Inicial.");
				document.frm_buscador_avanzado.fecha_hasta.focus();
				return false;				  
		  }		  
		}
		
		//Verificar que al menos se pone: prov. o tipo o fechas
		if (isEmpty(document.frm_buscador_avanzado.fecha_desde.value)&&document.frm_buscador_avanzado.provincia.value==0&&document.frm_buscador_avanzado.tipo.value==0)
			{
			  	alert("Debe indicar al menos alguno de estos criterios de búsqueda: Provincia, Tipo Alojamiento ó Fechas.");
				return false;				  
			}
	}
	else { // Al menos 3 caracteres

		if(document.frm_buscador_avanzado.txtClave.value.length<4)
		{
			alert("La Palabra Clave a buscar por el Nombre del Alojamiento Rural, debe ser al menos de 4 caracteres.");
			return false;				  
		}
		
	} // de si esta vacio el txtClave

	//Si llego aquí. Todo Ok.
	return true;
}


