//==============================================================================================================================================//
function onMenu(indice)
{
	var item = document.getElementById('item' + indice);
	item.style.backgroundColor='#FFFFFF';
	var enlace = document.getElementById('enlace' + indice);
	enlace.style.color='#9e360c';
}


function offMenu(indice)
{
	var item = document.getElementById('item' + indice);
	item.style.backgroundColor='';
	var enlace = document.getElementById('enlace' + indice);
	enlace.style.color='#000000';
}//============================================================================================================================================================================================//
function esLongitud(valor, size)
{
	if (valor.length == size)
		return true;
	else
		return false;
}
//============================================================================================================================================================================================//
function esBlanco(texto)
{
	if (texto.length==0 || texto=='')
		return true;
	else
		return false;
}
//============================================================================================================================================================================================//
function isNumber(str)
{
  var ValidChars = "0123456789";
   var res=true;
   var Char;

   for (i = 0; i < str.length && res == true; i++) 
      { 
      Char = str.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         res = false;
         }
      }
   return res;
}
//============================================================================================================================================================================================//
function valInMinMax(value,min,max)
{
	if (value>= min && value <= max)
		return true;
	else
		return false;
}
//============================================================================================================================================================
function isDateTime(datetime)
{
	date = datetime.substring(0,10);
	//alert ("isDateTime --> date:-" + date + "-");
	time = datetime.substring(11);
	//alert ("isDateTime --> time:-" + time + "-");
	if (!isDate(date, "ddmmyyyy" , "/") || !isTime(time, ":"))
		return false
	else
		return true;
}

//============================================================================================================================================================
function isTime(time, schar)
{
	var hour, minute, second;
	tokens = time.split(schar);
	hour =tokens[0];
	minute = tokens[1];
	second = tokens[2];
	//alert("isTime --> hour: " + hour);
	//alert("isTime --> minute: " + minute);
	//alert("isTime --> second: " + second);

	if (!(valInMinMax(hour,0,23)))
	{ 
		return false;
	}
	if (!(valInMinMax(minute,0,59)))
	{ 
		return false;
	}
	if (!(valInMinMax(second,0,59)))
	{ 
		return false;
	}	
	return true;
}
//============================================================================================================================================================================================//
function isDate(date, mask, schar)
{
	var day, month, year;
	switch (mask){
		case "ddmmyyyy":
			tokens = date.split(schar);
			day =tokens[0];
			month = tokens[1];
			year = tokens[2];
			break;
		case "mmddyyyy":
			day = date.split(schar)[1];
			month = date.split(schar)[0];
			year = date.split(schar)[2];
			break;
		case "yyyyddmm":
			day = date.split(schar)[2];
			month = date.split(schar)[0];
			year = date.split(schar)[1];
			break;
		default :
			return false;
	}

	if (!(valInMinMax(year,1900,2080)))
	{ 
		return false;
	}
	if (!(valInMinMax(month,1,12)))
	{ 
		return false;
	}
	if ((month==4) || (month==6) || (month==9) || (month==11))
	{
		if (!(valInMinMax(day,1,30))){ return false;}
	}	
	if ((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12))
	{
		if (!(valInMinMax(day,1,31))){ return false;}
	}
	if (month==2)
	{
		if (!(new Date(year,1,29).getDate()==29))
		{
			if (!(valInMinMax(day,1,28))){ return false;}
		} 
		else 
		{
			if (!(valInMinMax(day,1,29))){ return false;}
		}
	}
	return true;
}

//============================================================================================================================================================================================//
function handleErrorBlanco(campo, name)
{
	alert(name + ' no puede estar vacío ');
	campo.focus();
}
//============================================================================================================================================================================================//
function handleErrorAllBlancos()
{
	alert('Debes rellenar al menos un campo');
}
//============================================================================================================================================================================================//
function handleErrorFormato(campo, nombre, mascara)
{
	alert('Formato incorrecto en  ' + nombre + ". Introduce " + mascara);
	campo.focus();
}
//============================================================================================================================================================================================//
function validaDatosPersonales(formulario)
{
	if (esBlanco(formulario.name.value))
	{
		handleErrorBlanco(formulario.name, "Nombre");
		return false;
	}
	if (esBlanco(formulario.surname.value))
	{
		handleErrorBlanco(formulario.surname, "Apellidos");
		return false;
	}
	if (!isDate(formulario.birthDate.value, "ddmmyyyy", "/"))
	{
		handleErrorFormato(formulario.birthDate, "Fecha Nac", "dd/mm/aaaa");
		return false;
	}
	if (esBlanco(formulario.street.value))
	{
		handleErrorBlanco(formulario.street, "Calle");
		return false;
	}
	if (esBlanco(formulario.number.value))
	{
		handleErrorBlanco(formulario.number, "Número");
		return false;
	}
	if (esBlanco(formulario.city.value))
	{
		handleErrorBlanco(formulario.city, "Ciudad");
		return false;
	}
	if (esBlanco(formulario.postalCode.value))
	{
		handleErrorBlanco(formulario.postalCode, "Código Postal");
		return false;
	}
	if (esBlanco(formulario.province.value))
	{
		handleErrorBlanco(formulario.province, "Provincia");
		return false;
	}
	if (esBlanco(formulario.country.value))
	{
		handleErrorBlanco(formulario.country, "País");
		return false;
	}
	if (esBlanco(formulario.nationality.value))
	{
		handleErrorBlanco(formulario.nationality, "Nacionalidad");
		return false;
	}			
	if (esBlanco(formulario.nif.value))
	{
		handleErrorBlanco(formulario.nif, "NIF/T.R");
		return false;
	}
	if (esBlanco(formulario.tlf.value))
	{
		handleErrorBlanco(formulario.tlf, "Teléfono");
		return false;
	}
	if (esBlanco(formulario.email.value))
	{
		handleErrorBlanco(formulario.email, "Correo electrónico");
		return false;
	}
	return true;
}
