function openWindow(wName, wUrl){wName = window.open(wUrl, wName, 'width=660, height=600,scrollbars=YES');return false;}
function formAction(form, url){document.getElementById(form).setAttribute("action", url);}
$(document).ready(function(){
	$("#pais").bind("change", function(){
		var id = $("#pais").val();
		if (id != 0)
		{
			$.ajax({
				type: "POST", 
				url: "es/util/index/provincia/",
				data: "id="+id, 
				dataType: "script"
			});
		}
	});
	if ($("#adultos").val() != ""){showNinyosBebes();}
	$("#adultos").bind("change", showNinyosBebes);
	$("a.external").bind("click", function(){$(this).attr("target","_blank");});
	$("a.false").bind("click", function(){return false;});
	$('.flecha').bind('click', function(){$(this).next().toggle(300);$(this).next().next().toggle();if($(this).hasClass("close")){$(this).removeClass("close").addClass("open");}else {$(this).addClass("close").removeClass("open");}});
	$("#ninyosLi").bind("mouseenter", function(){$("#ninyosDiv").show(300);});
	$("#ninyosLi").bind("mouseleave", function(){$("#ninyosDiv").hide(300);});
	$("#bebesLi").bind("mouseenter", function(){$("#bebesDiv").show(300);});
	$("#bebesLi").bind("mouseleave", function(){$("#bebesDiv").hide(300);});
	$(".destacado, .nuevoAlojamiento").bind("click", function(){window.location = $(this).find("p.ubicacion a").attr("href");});
	$("#busquedaGeneralForm").bind("submit", function(){
		if ($("#pais").val() == 0){$("#pais").val(1);}
		if ($("#adultos").val() == ""){$("#adultos").val(2);}
	});
	$("#masinfoForm").validate({
		rules: {
			masNombre: {
				required: true,
				minlength: 3
			},
			masComentario: {
				required: true,
				minlength: 10
			}
		}
	});
	$("#accesoForm").validate({
		rules: {
			accesoEmail: {
				required: true,
				email: true
			},
			accesoPassword: {
				required: true,
				minlength: 3
			}
		}
	});
	$("#alquilerOpinionForm").validate({
		rules: {
			_titulo: {
				required: true,
				minlength: 3
			},
			_valoracion: {
				required: true
			},
			_opinion: {
				required: true,
				minlength: 10
			}
		}
	});
	/*
	$("#masinfoForm").validate({
		submitHandler: function(form){
			form.submit();
		}
	});
	*/
	$(".onlynumber").keydown(function(event) {
		// Allow only backspace and delete
		if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 190) {
			// let it happen, don't do anything
		}
		else {
			// Ensure that it is a number and stop the keypress
			if (event.keyCode < 48 || event.keyCode > 57 ) {
				event.preventDefault();	
			}	
		}
	});
	
});
function showNinyosBebes(){$("#ninyosContainer, #bebesContainer, #ninyosLi, #bebesLi").show(300);}
function deleteLista(id)
{
	$.ajax({
		type: "POST",
		url: "es/util/index/mylist/",
		data: "id="+id+"&checked=0",
		dataType: 'script'
	});
	if ($("#myAdd"+id)){$("#myAdd"+id).removeClass("checked");}
}
