function send(obj_name)
{
	var frm = document.forms[obj_name];
	var el = document.getElementsByName("sch_tipo_alojamiento");
	var task;
	var do_submit = true;
	var frm_action;
	
	/*for (var i = 0; i < el.length; i++)
	{
		if (el[i].checked == true)
		{
			task = el[i].value;
		}
	}*/
	
	/*switch (task){
		case "1":
			frm_action = "index.php?mod=buscador&task=camping";
			break;
		case "2":
			frm_action = "index.php?mod=buscador&task=bungalo";
			break;
		default :
			frm_action = "index.php?mod=buscador&task=camping";
	}*/
	frm_action = "index.php?mod=buscador&task=camping";
	if (do_submit)
	{
		frm.action = frm_action;
		frm.submit();
	}
}

function SubmitReservationCheck()
{
	document.forms["frm_reservations"].submit();
	document.forms["frm_reservations"].reset();
}
function SubmitIntranet()
{
	
	document.forms["frm_intranet"].submit();
	document.forms["frm_intranet"].reset();
}

//fillObject(comunidades,provincias,this,'<?= STR_SCH_PROVINCE ?>')
function fillObject(arr1,arr2,obj,dest_name)
{
	var sel1 = obj;
	var sel2 = document.getElementById(dest_name);
	var i;
	var loc;
	
	for (i = 0; i < arr1.length; i++)
	{
		if (arr1[i] == sel1.options[sel1.selectedIndex].value)
		{
			loc = i;
			break;
		}
	}
		
	for (i = 1; i <= sel2.length; i++)
	{
		sel2.remove(i);
	}
	
	sel2.selectedIndex=0;
	sel2.length=1;
	
	var j = 1;
	if (loc != null && loc > 0)
	{
		for (i = 0; i < arr2[loc].length; i++)
		{
			if (arr2[loc][i] != "undefined" && arr2[loc][i] != null)
			{
		    var option = document.createElement('option');
		    option.appendChild(document.createTextNode(arr2[loc][i]));
		    option.setAttribute('value', arr2[loc][i]);
		    
		    sel2.appendChild(option);
	    
		    j++;
			
			}
			sel2.length = j;
		}
	}
}

function fillObjectWithValue(arr1,arr2,value,dest_name)
{
	var sel1 = value;
	var sel2 = document.getElementById(dest_name);
	var i;
	var loc;
	
	for (i = 0; i < arr1.length; i++)
	{
		if (arr1[i] == sel1)
		{
			loc = i;
			break;
		}
	}
	
	for (i = 1; i <= sel2.length; i++)
	{
		sel2.remove(i);
	}
	
	var j = 1;
	
	if (loc != null)
	{
		for (i = 0; i < arr2[loc].length; i++)
		{
			if (arr2[loc][i] != "undefined" && arr2[loc][i] != null)
			{
		    var option = document.createElement('option');
		    option.appendChild(document.createTextNode(arr2[loc][i]));
		    option.setAttribute('value', arr2[loc][i]);
		    
		    sel2.appendChild(option);
	    
		    j++;
			
			}
			sel2.length = j;
		}
	}
}

function selectValue(obj_name,value)
{
	var sel = document.getElementById(obj_name);
	
	if (sel.length > 1 && value != "-1")
	{
		for (var i = 1; i <= sel.length; i++)
		{
			if (sel.options[i].value == value)
			{
				sel.selectedIndex = i;
				break;
			}
		}
	}
}

//Calcula el nº de noches a partir de la fecha de entrada y de salida.
function getNights(obj_name_day_ini, obj_name_month_ini, obj_name_day_end, obj_name_month_end, obj_name_nights)
{
	var obj_day_ini = document.getElementById(obj_name_day_ini);
	var obj_month_ini = document.getElementById(obj_name_month_ini);
	var obj_day_end = document.getElementById(obj_name_day_end);
	var obj_month_end = document.getElementById(obj_name_month_end);
	
	var obj_nights = document.getElementById(obj_name_nights);
	
	var cond1 = obj_day_ini.value != "" && obj_month_ini.value != "";
	var cond2 = obj_day_end.value != "" && obj_month_end.value != "";
	
	var init_date, end_date;
	var curr_date = new Date();
	if (cond1 && cond2)
	{
		//año, mes-1, dia
		init_date = new Date (curr_date.getYear(), obj_month_ini.value, obj_day_ini.value);
		end_date = new Date (curr_date.getYear(), obj_month_end.value, obj_day_end.value);

		var diff_date = new Date(end_date-init_date);
		obj_nights.value = diff_date/(24*60*60*1000);
	}
}

//Calcula el nº de noches a partir de la fecha de entrada y de salida.
function checkNights(obj_name_day_ini, obj_name_month_ini, obj_name_day_end, obj_name_month_end, obj_name_nights)
{
	var obj_day_ini = document.getElementById(obj_name_day_ini);
	var obj_month_ini = document.getElementById(obj_name_month_ini);
	var obj_day_end = document.getElementById(obj_name_day_end);
	var obj_month_end = document.getElementById(obj_name_month_end);
	
	var obj_nights = document.getElementById(obj_name_nights);
	
	var cond1 = obj_day_ini.value != "" && obj_month_ini.value != "";
	var cond2 = obj_day_end.value != "" && obj_month_end.value != "";
	
	var init_date, end_date;
	var curr_date = new Date();
	if (cond1 && cond2)
	{
		//año, mes-1, dia
		init_date = new Date (curr_date.getYear(), obj_month_ini.value, obj_day_ini.value);
		end_date = new Date (curr_date.getYear(), obj_month_end.value, obj_day_end.value);

		var diff_date = new Date(end_date-init_date);
		if (obj_nights.value > diff_date/(24*60*60*1000))
		{
			alert("El número de noches excede las fechas introducidas!\nSe va a modificar el valor de las noches a las que corresponden a las fechas.");
			obj_nights.value = diff_date/(24*60*60*1000);
		}
	}
}

//CardMainImage
function showImage(path,loader)
{
	var img = document.getElementById(loader);
	img.src = path;
}

function checkRegister()
{
	var frm = document.forms["frm_register"];
	
	var nm = frm.elements["txt_nombre"];
	var email = frm.elements["txt_email"];
	var user = frm.elements["txt_usuario"];
	var pass = frm.elements["txt_password"];
	var reppass = frm.elements["txt_password2"];
	var pais = frm.elements["slc_pais"];
	var prov = frm.elements["slc_provincia"];
	var gender = frm.elements["rad_sexo"];
	var birth = frm.elements["txt_fecha"];
	var occupation = frm.elements["txt_profesion"];

	if (nm.value == "")
	{
		alert("Debe introducir su nombre.");
		nm.focus();
		return false;
	}
	if (email.value == "")
	{
		alert("Debe introducir su e-mail.");
		email.focus();
		return false;
	} else {
		if ( !validarEmail(email.value) )
		{
			alert("El formato del e-mail no es correcto.");
			email.focus();
			return false;			
		}
	}
	if (user.value == "")
	{
		alert("Debe introducir su nombre de usuario.");
		user.focus();
		return false;
	}
	if (pass.value == "")
	{
		alert("Debe introducir una contraseña.");
		pass.focus();
		return false;
	}	
	
	if (reppass.value != pass.value)
	{
		alert("Las contraseñas deben de ser las mismas en la definición y en la confirmación.");
		pass.value = "";
		reppass.value = "";
		pass.focus();
		return false;
	}
	
	if (pais.selectedIndex == 0 || pais.options[pais.selectedIndex].value == "-1")
	{
		alert("Debe seleccionar un pais.");
		pais.focus();
		return false;		
	}	
	
	if (pais.options[pais.selectedIndex].value == "ES" && prov.selectedIndex == 0)
	{
		alert("Debe seleccionar una provincia.");
		prov.focus();
		return false;		
	}

	var isset_gender = false;
	for (var i = 0; i < gender.length; i++)
	{
		if(gender[i].checked == true)
		{
			isset_gender = true;
			break;
		}
	}
	if (!isset_gender)
	{
		alert("Debe indicar su sexo.");
		return false;	
	}	
	
	if (birth.value == "")
	{
		alert("Debe indicar su fecha de nacimiento.");
		birth.focus();
		return false;			
	} else {
		if ( !validarDate(birth.value) )
		{
		alert("El formato de su fecha de nacimiento es incorrecto.\nEl formato de la fecha debe ser 'dd/mm/aaaa'");
		birth.focus();
		return false;				
		}
	}
	
	if (occupation.value == "")
	{
		alert("Debe introducir su profesión.");
		occupation.focus();
		return false;
	}	
	
	return true;
}

function checkLogin()
{
	var frm = document.forms["frm_login"];
	
	var user = frm.elements["txt_user"];
	var pass = frm.elements["txt_pass"];

	if (user.value == "")
	{
		alert("Debe introducir su nombre de usuario.");
		user.focus();
		return false;
	}
	
	if (pass.value == "")
	{
		alert("Debe introducir su contraseña.");
		pass.focus();
		return false;
	}
	
	return true;
}

function checkAdvertise()
{
	var frm = document.forms["frm_new_adv"];
	
	var nm = frm.elements["txt_nombre"];
	var telefono = frm.elements["txt_telefono"];
	var prov = frm.elements["slc_provincia"];
	var precio = frm.elements["txt_precio"];
	var operacion = frm.elements["slc_operacion"];
	var categoria = frm.elements["slc_categoria"];
	var anio = frm.elements["txt_anio"];
	var descripcion = frm.elements["txt_descripcion"];
	
	if (nm.value == "")
	{
		alert("Debe introducir un nombre.");
		nm.focus();
		return false;
	}
	if (telefono.value == "")
	{
		alert("Debe introducir un telefono.");
		telefono.focus();
		return false;
	}
	if (precio.value == "")
	{
		alert("Debe introducir un precio.");
		precio.focus();
		return false;
	}
	if (anio.value == "")
	{
		alert("Debe introducir un año.");
		anio.focus();
		return false;
	}
	if (descripcion.value == "")
	{
		alert("Debe introducir una descripcion.");
		descripcion.focus();
		return false;
	}					

	if (prov.selectedIndex == 0 || prov.options[prov.selectedIndex].value == "-1")
	{
		alert("Debe seleccionar una provincia.");
		prov.focus();
		return false;		
	}	
	if (operacion.selectedIndex == 0 || operacion.options[operacion.selectedIndex].value == "-1")
	{
		alert("Debe seleccionar una opreación.");
		operacion.focus();
		return false;		
	}	
	if (categoria.selectedIndex == 0 || categoria.options[categoria.selectedIndex].value == "-1")
	{
		alert("Debe seleccionar una categoria.");
		categoria.focus();
		return false;		
	}				
		
	return true;
}

function checkContact()
{
	var frm = document.forms["frm_contact"];
	
	var nm = frm.elements["txt_nombre"];
	var email = frm.elements["txt_email"];
	var comentarios = frm.elements["txt_comentarios"];
	
	if (nm.value == "")
	{
		alert("Debe introducir un nombre.");
		nm.focus();
		return false;
	}
	
	if (email.value == "")
	{
		alert("Debe introducir su e-mail.");
		email.focus();
		return false;
	} else {
		if ( !validarEmail(email.value) )
		{
			alert("El formato del e-mail no es correcto.");
			email.focus();
			return false;			
		}
	}
	
	if (comentarios.value == "")
	{
		alert("Debe introducir sus comentarios.");
		comentarios.focus();
		return false;
	}		
	
	return true;
}
function validarEmail(valor) {
  var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  return regexp.test(valor);
}

function validarDate(Cadena) {
   var Fecha= new String(Cadena)
   var RealFecha= new Date()  
   var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
   var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
   var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

   if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
      return false
   }
   if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
      return false
   }
   if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
      return false
   }
   if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
      if (Mes==2 && Dia > 28 || Dia>30) {
         return false
      }
   }
  
   return true   
}

function showProvinces(valor_ref, id_obj, id_activo, id_inactivo, valor_activo)
{
	var obj_mostrar = document.getElementById(id_obj);
	
	if (valor_ref == valor_activo)
	{
		obj_mostrar.className = id_activo;
	}
	else
	{
		obj_mostrar.className = id_inactivo;		
	}
}

function AbrirPopUp(str_url, str_win, h,w)
{
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=yes,';
	settings +='resizable=no,';
	settings +='titlebar=no,';
	settings +='menubar=no,';
	settings +='status=no';
	win=window.open(str_url,str_win,settings);
	win.window.focus();
}

function checkDeletion()
{
	if (confirm("Esta seguro que desea eliminar el camping?\nToda la información relacionada con el mismo será eliminada del sistema!"))
	{
		document.forms["frm_Delete"].submit();
	}
}
