// JavaScript Document

//Dictionary
var msg01 = "The dates you have chosen are incorrect";
var msg02 = "Select a type room";
var msg03 = "Nombre";
var msg04 = "Apellidos";
var msg05 = "E-mail";
var msg06 = "Pais";
var msg07 = "Tipo de Tarjeta";
var msg08 = "Titular de la tarjeta";
var msg09 = "Número de la Tarjeta";
var msg10 = "Fecha de caducidad de la Tarjeta";
var msg11 = "Faltan o son incorrectos los siguientes datos: \n";

//Fuctions
function checkSearch(){
	var checkinMY,checkinMonth,checkinYear,checkoutMY,checkoutMonth,checkoutYear,year,month,day;
	checkinMY = document.search.checkinMonth.value;
	checkinMonth = checkinMY.substr(0,2);	
	checkinYear = checkinMY.substr(3,4);
	checkoutMY = document.search.checkoutMonth.value;
	checkoutMonth = checkoutMY.substr(0,2);	
	checkoutYear = checkoutMY.substr(3,4);
	var today = new Date();
	
	year = today.getFullYear();
	month = today.getMonth();
	day = today.getDate();
	//alert("year: "+year+" month: "+month+" day: "+day+" year: "+checkinYear+" month: "+checkinMonth+" day: "+document.search.checkinDay.value);
	if ( (Date.UTC(checkinYear,checkinMonth-1,document.search.checkinDay.value,0,0,0,0) >= Date.UTC(checkoutYear,checkoutMonth-1,document.search.checkoutDay.value,0,0,0,0)) || 
		 ( Date.UTC(checkinYear,checkinMonth-1,document.search.checkinDay.value,0,0,0,0) < Date.UTC(year,month,day,0,0,0,0) )){
		
		alert(msg01);		
		return false;
	}
	if ( document.search.type.value == "" ){
		alert(msg02);
		return false;
	}
	return true;	
}

function checkBook(){
	var error,name,surname,email,country,type_card,owner,num1,num2,num3,num4,expiremonth,expireyear;
	error = "";
	if ( document.book.txt_name.value == "" )
		error = error+msg03+"\n";
	if ( document.book.txt_surname.value == "" )
		error = error+msg04+"\n";
		
	/*val = document.book.txt_email.value;
	p=val.indexOf('@');
	
    if (p<1 || p==(val.length-1)) error .= msg05+"\n";*/
	if ( document.book.lis_country.value == "" )
		error = error+msg06+"\n";
		
	for (i=0;i<document.book.rad_method_payment.length;i++){ 
   		if (document.book.rad_method_payment[i].checked) 
	  	break; 
    }
	if ( document.book.rad_method_payment[i].value == "card" ){	
		if ( document.book.cmb_type_card.value == "" )
			error = error+msg07+"\n";
		if ( document.book.txt_owner.value == "" )
			error = error+msg08+"\n";
		if ( document.book.txt_num1.value == "" || document.book.txt_num2.value == "" ||document.book.txt_num3.value == "" ||document.book.txt_num4.value == "" )
			error = error+msg09+"\n";
		if ( document.book.lbl_month.value == "" )
			error = error+msg10+"\n";
	}
	
	if ( error != "" ){
		alert(msg11+error);
		return false;
	}else{
		return true;
	}
}

function mostrar(nombreCapa){
	document.getElementById(nombreCapa).style.visibility="visible";
}

function ocultar(nombreCapa){
	document.getElementById(nombreCapa).style.visibility="hidden";
} 