function open_win (url,type){
	if (type=="tour") { 
		var parameters="resizable=yes,scrollbars=yes,menubar=no,location=no,directories=no,toolbar=no,status=no";
		parameters+=",width=600,height=530,top=1,left=1";
		window.open(url,"TOUR",parameters);
	} else if (type=="ficha") { 
		var parameters="resizable=yes,scrollbars=yes,menubar=no,location=no,directories=no,toolbar=no,status=no";
		parameters+=",width=720,height=600,top=1,left=1";
		window.open(url,"FICHA",parameters);
	} else if (type=="foto") { 
		var parameters="resizable=yes,scrollbars=yes,menubar=no,location=no,directories=no,toolbar=no,status=no";
		parameters+=",width=620,height=530,top=1,left=1";
		window.open(url,"FOTO",parameters);
	}
}

function checkArgumentsDisp (f, msg_error1, msg_error2, msg_error3, msg_error4) {
	rc = checkArgumentsDate (f, msg_error1, msg_error2, msg_error3);
	if (rc == false) return false;
	return checkArgumentsGeneral (f, msg_error4);
}

function checkArgumentsGeneral (f, msg_error1) {
	if ( (f.type.value == '') && (f.mode.value == '') && (f.price.value == '') && (f.rooms.value == '') &&
      	     (f.places.value == '') && (f.zone.value == '') ) {
		alert (msg_error1);
		return false;
	}
	return true;
}

function checkArgumentsDate (f, msg_error1, msg_error2, msg_error3) {
	rc = validateDate (f.dayin.value, f.fecha.value);
	if (rc == -1) {
		alert (msg_error1);
		return false;
	} else if (rc == -2) {
		alert (msg_error3);
		return false;
	}

	if ( (f.nights.value>0) && (f.nights.value<=20) ) return true;
	alert (msg_error2);
	f.nights.focus();
	return false;
}

function validateDate (day, fecha) {
	if ( (fecha == '') ||(day == '') ) return -1;
	var aux = fecha.split("-");
	var year = aux[0];
	var month = aux[1];
	//alert (day +"-"+month+"-"+year);
	if ( (day<=0) || (day>31) ) return false;
	if ( ( (month==4) || (month==6) || (month==9) ||(month==11) ) &&
	     (day>30) ) return -1;
	if ( (month==2) && (leapyear(year)) && (day>29) ) return -1;
	if ( (month==2) && (!leapyear(year)) && (day>28) ) return -1;

	// Sacamos la fecha de hoy
	todaysdate = new Date();
	day_hoy  = todaysdate.getDate();
	month_hoy = todaysdate.getMonth() + 1;
	yy = todaysdate.getYear();
	year_hoy = (yy < 1000) ? yy + 1900 : yy;

	if (year_hoy > year) return -2;
	if (year_hoy == year) {
		if (month_hoy > month) return -2;
		if (month_hoy == month) {
			if (day_hoy > day) return -2;
		}
	}

	return true;	
}

function leapyear (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? true : false );
}

function setTodayDate (f, lista) {
	todaysdate = new Date();
	month = todaysdate.getMonth() + 1;
	yy = todaysdate.getYear();
	year = (yy < 1000) ? yy + 1900 : yy;

	n=0; flag=0; cont=0;

	aux = lista.split("|");
        while (cont<aux.length) {
		if (n+1 == month) {
			textaux=aux[n]+" - "+year;
			textvalue=year+"-"+(n+1);
			f.fecha.options[cont+2] = new Option (textaux,textvalue);
			flag=1;
			cont++;
		} else if (flag==1) {
			textaux=aux[n]+" - "+year;
			textvalue=year+"-"+(n+1);
			f.fecha.options[cont+2] = new Option (textaux,textvalue);
			cont++;
		}

		if (n>=aux.length-1) {
			n=0;
			year++;
		} else n++;
	}
	return true;
}

// Funcion para cambiar de idioma una url
function change_lang (window, lang) { 
	var window_url = window.location;
	window_url = '' + window_url
	re = /^(.+)language=(\d+)(.*)$/;
  	var newurl = window_url.replace(re, "$1language=" + lang + "$3");
//	alert("nuev: " + newurl);
	window.location = newurl
}

