<!--

function clean(frmObj) {
	var obj = eval('document.' + frmObj);
	obj.value = "";
}


function cleanLogin()
{
    document.getElementById('loginUser').value = '';
    document.getElementById('loginPass').value = '';
}

function showLogout(user)
{
    document.getElementById('logoutEntity').innerHTML = user;
    document.getElementById('logoutLink').style.display = 'inline';
    document.getElementById('authLink').style.display = 'none';
}

function showLogin()
{
    document.getElementById('logoutLink').style.display = 'none';
    document.getElementById('authLink').style.display = 'inline';
}

// Evita escrever letras na duraÃ§Ã£o
function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

/* abre um canal e fecha os outros*/
function eXpand2(obj,id){
	//Compatible IE 6, Mozilla 1.4.1 , Firebird 0.6.1+
	for (i=1;i <= 4; i++){
		if(document.getElementById(obj+i) != null){
			var img = eval('document.stp'+i);
			if(i==id){
				img.src="/img/" +  JS_LANG.toUpperCase() + "/step"+i+"_1.gif";
				document.getElementById("step"+i).style.display = 'inline';
			} else {
				img.src="/img/" + JS_LANG.toUpperCase() +"/step"+i+"_0.gif";
				document.getElementById("step"+i).style.display = 'none';
			}
		} else
			break;
	}
}


function setStepNumber(numStep)
{
   var i=1;
   for (i=1; i<=4; i++)
   {
      var img = eval('document.stp' + i);
      if(i == numStep)
          img.src="/img/" +  JS_LANG.toUpperCase() + "/step"+i+"_1.gif";
      else
          img.src="/img/" +  JS_LANG.toUpperCase() + "/step"+i+"_0.gif";
   }
}

function doAutentication()
{
    var f = document.frmLogin;
	f.action = "xlets/iReservasWorker.jsp?action=autenticate";
	f.submit();
}


function eXpand(obj){
	//Compatible IE 6, Mozilla 1.4.1 , Firebird 0.6.1+
	var aux = document.getElementById(obj);

	if (document.all) {
		aux.style.display = (aux.style.display == "none" ) ? "inline" : "none";
	} else {
		aux.style.display = (aux.style.display == "none" ) ? "table-row" : "none";
	}
}

function calcula() {
	var numQuartos = document.frmFullReservas.numQuartos.value;
	var numTotal = 0;

	var i;

	numTotal += parseInt(document.getElementById('numAdultos1').value) + parseInt(document.getElementById('numCriancas1').value);


	var noites = numNoites(document.frmFullReservas.txtDataCI.value,document.frmFullReservas.txtDataCO.value);

	calculaString(numTotal, noites, numQuartos);
	calculaPrecoTotal();
}

var step;

function goNextInput(i) {
	input = eval('document.frmFullReservas.numCartao'+i);
	inputNext = eval('document.frmFullReservas.numCartao'+parseInt(i+1));

	if (input.value.length==4){
		inputNext.focus();
	}
}

function submitForm() {
	var f = document.frmReservas;

	if (f.hotelDest.selectedIndex == 0) {
		alert(JS_MSG_SELECTHOTEL);
		f.hotelDest.focus();
		return;
	}

	if (f.txtDataCI.value == "") {
		alert(JS_MSG_INSERTCHECKIN);
		return;
	}

	if (f.txtDataCO.value == "") {
		alert(JS_MSG_INSERTCHECKOUT);
		return;
	}

	//verifica se data check-in maior que data actual
	var di=f.txtDataCI.value.split("/");
	var s=new Date(di[1]+'/'+di[0]+'/'+di[2])
	var e=new Date()

	if (checkDateDiff(s,e) > 0){
		alert(JS_MSG_CHECKINDATEINF);
		return;
	}

	//verifica se data check-in menor que data check-out
	var di=f.txtDataCI.value.split("/");
	var df=f.txtDataCO.value.split("/");
	var s=new Date(di[1]+'/'+di[0]+'/'+di[2] + ' GMT+0000');
	var e=new Date(df[1]+'/'+df[0]+'/'+df[2] + ' GMT+0000');

	if (checkDateDiff(s,e) < 0){
		alert(JS_MSG_CHECKINMOREHIGHOUT);
		return;
	}
	else if (checkDateDiff(s,e) == 0){
		alert(JS_MSG_CHECKINEQUALOUT);
		return;
	 }

	f.submit();
}

function checkDateDiff(di, df) {
    var iOut = 0;
    var bufferA = Date.parse(di) ;
    var bufferB = Date.parse(df) ;
    var number = bufferB-bufferA ;
	iOut = parseInt(number / 86400000) ;
    return iOut ;
}

function submitFullForm(next) {

	//alert("antes f.step.value="+document.frmFullReservas.step.value);
 
	var f = document.frmFullReservas;
	step = parseInt(f.step.value);
	var next = parseInt(next);

	//f.generateRooms.value= "false";

	// Se o próximo passo é o pagamento redirecciona para a página segura.
	if(step==2 && next==1)
	{
		
		if(document.getElementById('selectedRooms').style.display == "none")
		{
			alert(JS_MSG_NOSELECTEDROOMS);
			return false;
		}
		
		f.target = '';
		f.action = document.getElementById('pagamentoURL').value;
		f.submit();
		return false;
	}
	
	if (isNaN(step) || step==null || step=="" || step > 7){
		step=1;
		document.frmFullReservas.step.value=1;
		eXpand2("step",1);
	}

	if (step==1){
	 if (f.hotelDest.selectedIndex == 0) {
		alert(JS_MSG_SELECTHOTEL);
		f.hotelDest.focus();
		return;
	 }
	}

	if(step==1 && next==1){
		document.getElementById('searchResults').innerHTML = "";
		document.getElementById('selectedRooms').style.display = "none";
		document.getElementById('noRooms').style.display = "none";
		document.getElementById('searchTable').style.display = "none";

		f.step.value = 2;
		defineNav(2);
		f.action = "xlets/iReservasWorker.jsp?action=startSession";
		f.submit();
	}
	if(step==2 && next==-1)
	{
		document.getElementById('autenticacao').style.display = "inline";
		changeHotel(); 
		defineNav(1);
		
		f.step.value = 1;
		f.action = "xlets/iReservasWorker.jsp?action=startSession";
		f.submit();
  
	}
	
	step+=next;
	f.step.value=step;
	
	eXpand2("step",step);

}

function defineNav(step) {
	if (step<=1) {
		document.getElementById("rsrvBack").style.display="none";
		document.getElementById("rsrvGo").style.display="inline";
	} else if (step>=4){
		document.getElementById("rsrvBack").style.display="inline";
		document.getElementById("rsrvGo").style.display="none";
	}
	else {
		document.getElementById("rsrvBack").style.display="inline";
		document.getElementById("rsrvGo").style.display="inline";
	}
}

function confirmReservation()
{
    var f = document.frmFullReservas;
    f.action = "xlets/iReservasWorker.jsp?action=confirmReservation";
	f.submit();
}

// Envia o pedido de pesquisa de quartos ao servidor
function submitSearchFields(){
     var f = document.frmFullReservas;

     if (f.txtDataCI.value == "") {
		alert(JS_MSG_INSERTCHECKIN);
		return;
	 }

	 if (f.txtDataCO.value == "") {
		alert(JS_MSG_INSERTCHECKOUT);
		return;
	 }

	 //verifica se data check-in maior que data actual
	 var di=f.txtDataCI.value.split("/");
	 var s=new Date(di[1]+'/'+di[0]+'/'+di[2])
	 var e=new Date()

	 if (checkDateDiff(s,e) > 0){
		alert(JS_MSG_CHECKINDATEINF );
		return;
	 }

	 //verifica se data check-in menor que data check-out
	 var di=f.txtDataCI.value.split("/");
	 var df=f.txtDataCO.value.split("/");
	 var s=new Date(di[1]+'/'+di[0]+'/'+di[2] + ' GMT+0000');
	 var e=new Date(df[1]+'/'+df[0]+'/'+df[2] + ' GMT+0000');

	 if (checkDateDiff(s,e) < 0){
		alert(JS_MSG_CHECKINMOREHIGHOUT);
		return;
	 }
	 else if (checkDateDiff(s,e) == 0){
		alert(JS_MSG_CHECKINEQUALOUT );
		return;
	 }

	// Mostrar a div de loading
    var loadDiv = document.getElementById('loadingResults');
    loadDiv.style.display = "inline";
    var searchResults = parent.document.getElementById('searchResults');
    searchResults.innerHTML = loadDiv.innerHTML;

	// Apagar os resultados antigos...
	var searchTableRows = document.getElementById('searchResultsList');
	document.getElementById('searchTable').style.display = "none";
	
	for(var i = searchTableRows.rows.length-1; i >= 0; i--)
		if(searchTableRows.rows[i].className != "fixed") searchTableRows.deleteRow(searchTableRows.rows[i].rowIndex);

	
	var searchResults = document.getElementById('noRooms');
	searchResults.style.display = "none";
	
	f.action = "xlets/iReservasWorker.jsp?action=search";
	f.submit();
}

// Adiciona um quarto à lista de quartos seleccionados na sessão
function addRoom(id)
{
    var elem = document.getElementById('nQ'+id);
    var quant = elem.options[elem.options.selectedIndex].value
    if(quant == 0)
    {
        alert(JS_MSG_SELECTQUANT);
    }
    else{
         var f = document.frmFullReservas;
	     f.action = "xlets/iReservasWorker.jsp?action=addRoom&roomIndex="+id+"&roomQtd="+quant;
	     f.submit();
	}
}


function showNoRoomsFound(){
	
	var loadDiv = document.getElementById('loadingResults');
    loadDiv.style.display = "none";
	
	var searchResults = document.getElementById('noRooms');
	searchResults.style.display = "inline";
}

function updateSelectedRoomList(allRooms)
{
	var roomsList = document.getElementById('selectedRoomList');
	for(var i = roomsList.rows.length-1; i >= 0; i--)
	{
		if(roomsList.rows[i].className != "fixed") roomsList.deleteRow(roomsList.rows[i].rowIndex);
	}
	
	if(allRooms.length > 0)
		document.getElementById('selectedRooms').style.display = "inline";
	else
		document.getElementById('selectedRooms').style.display = "none";
	
	var totalPrice = 0;
	for (var i=0; i < allRooms.length; i++){
	
		var row = document.getElementById('selectedRoomList').insertRow(2);
		var rowPriceDetails = document.getElementById('selectedRoomList').insertRow(3);
		var rowSpacer = document.getElementById('selectedRoomList').insertRow(4);
		
		row.id = 'selrQ' + allRooms[i]['RoomNumber'];
		
		var quant = row.insertCell(0);
		var desc = row.insertCell(1);
		var adults = row.insertCell(2);
		var childs = row.insertCell(3);
		var detail = row.insertCell(4);
		var price = row.insertCell(5);
		var addCol = row.insertCell(6);
		
		// Estilos das linhas
		quant.style.verticalAlign = "middle";
		quant.style.textAlign = "center";
		quant.className = "black";
		desc.style.verticalAlign = "top";
		desc.style.textAlign = "left";
		desc.className = "black";
		detail.style.verticalAlign = "middle";
		detail.style.textAlign = "center";
		detail.className = "black";
		price.style.verticalAlign = "top";
		price.style.textAlign = "right";
		price.className = "black";
		
		// Conteúdo das linhas
		addCol.innerHTML = "&nbsp;&nbsp;&nbsp;<a href='javascript:removeRoom(" + allRooms[i]['RoomNumber'] + ")'><img src='/img/ico_apagar.gif' style='border-style:none;'></a>";
		
		quant.innerHTML = "<span class='black'>" + allRooms[i]['Quantidade'] + "</span>";
		
		detail.innerHTML = '<img alt="' + JS_LABEL_DETAIL + '" style="cursor:pointer;" onclick="showSelectedRoomDetail(' + allRooms[i]['RoomNumber'] + ')" border=0 src="/img/ico_info.gif">&nbsp;';

		price.innerHTML = '<br>'+allRooms[i]['Price']+'&euro;';
		desc.innerHTML = '<br><span style="vertical-align:top;" class="black">' + allRooms[i]['Description'] + '</span><br><br>';
		adults.innerHTML = allRooms[i]['Adults'];
		childs.innerHTML = allRooms[i]['Childs'];
		
		var colSpacer = rowSpacer.insertCell(0);
		colSpacer.colSpan = "7";
		colSpacer.background = '/img/dot_black.gif';
		colSpacer.style.verticalAlign = "top";
		colSpacer.innerHTML = "<img src='/img/px_white.gif' width='1' height='1'>";
		colSpacer.id = 'selsQ' + allRooms[i]['RoomNumber'];
		//<tr id='sQ" + roomNumber + "'><td colspan='7' background='/img/dot_black.gif' valign='top'><img src='/img/px_white.gif' width='1' height='1'></td></tr>
		
		// DETAILS
		rowPriceDetails.insertCell(0);
		var colPricesDetails = rowPriceDetails.insertCell(1);
		colPricesDetails.colSpan = "3";
		colPricesDetails.style.textAlign = "left";
		colPricesDetails.style.verticalAlign = "top";
		
		var htmlPricesDetail = "<div id='roomDetailsel" + allRooms[i]['RoomNumber'] + "' style='display:none;'><table  class='txtTable' style='BORDER-LEFT: #AAAAAA 1px solid'>";
		
		for(var j = 0; j < allRooms[i]['ArrayPriceDetails'].length; j++){

			htmlPricesDetail += "<tr><td colspan='2' align='left'><b>"+ allRooms[i]['ArrayPriceDetails'][j]['Date'] + "</b></td></tr>";
			if(allRooms[i]['ArrayPriceDetails'][j]['TotalAllotment'] != "0")
				htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;" + JS_LABEL_ALLOTMENT + ": </td><td align='left'>"+ allRooms[i]['ArrayPriceDetails'][j]['TotalAllotment'] +"&euro;</td></tr>";
			if(allRooms[i]['ArrayPriceDetails'][j]['TotalFood'] != "0")
				htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;Total Food: </td><td align='left'>"+ allRooms[i]['ArrayPriceDetails'][j]['TotalFood'] +"&euro;</td></tr>";
			if(allRooms[i]['ArrayPriceDetails'][j]['TotalBreakfast'] != "0")
				htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;Total Breakfast: </td><td align='left'>"+ allRooms[i]['ArrayPriceDetails'][j]['TotalBreakfast'] +"&euro;</td></tr>";
		
		}
		
		htmlPricesDetail += "<tr><td colspan='2' align='left'><br><b>" + JS_LABEL_TOTALPRICE + ": " + allRooms[i]['TotalPrice'] +"&euro;</b></td></tr>";
		htmlPricesDetail += "</table><br>";
		htmlPricesDetail += "</div>";

		colPricesDetails.innerHTML = htmlPricesDetail;
		
		totalPrice += allRooms[i]['TotalPrice']*allRooms[i]['Quantidade'];
		
	}
	
	document.getElementById('selthTotalOld').innerHTML = totalPrice + "&nbsp;&euro;";
}

function addRoomToSearchResults(roomNumber, quantidade, description, roomPrice, priceArray, totalPrice)
{
	var row = document.getElementById('searchResultsList').insertRow(2);
	var rowPriceDetails = document.getElementById('searchResultsList').insertRow(3);
	var rowSpacer = document.getElementById('searchResultsList').insertRow(4);
	
	document.getElementById('searchTable').style.display = "inline";
	var searchResults = document.getElementById('noRooms');
	searchResults.style.display = "none";
	
	row.id = 'rQ' + roomNumber;
	
	var quant = row.insertCell(0);
	var desc = row.insertCell(1);
	var detail = row.insertCell(2);
	var price = row.insertCell(3);
	var addCol = row.insertCell(4);
	
	// Estilos das linhas
	quant.style.verticalAlign = "top";
	quant.style.textAlign = "left";
	quant.className = "black";
	desc.style.verticalAlign = "top";
	desc.style.textAlign = "left";
	desc.className = "black";
	detail.style.verticalAlign = "middle";
	detail.style.textAlign = "center";
	detail.className = "black";
	price.style.verticalAlign = "top";
	price.style.textAlign = "right";
	price.className = "black";
	
	// Conteúdo das linhas
	addCol.innerHTML = "&nbsp;&nbsp;&nbsp;<a href='javascript:parent.addRoom(" + roomNumber + ")'><img src='/img/ico_add.gif' style='border-style:none;'></a>";
	
	var i = 0, quantHtml = '';
	
	quantHtml = '<br><select id="nQ' + roomNumber + '" name="nQ' + roomNumber + '" class="black" onchange="calculaPrecoTotal();">';
	for (i; i <= quantidade; i++)
	{
		quantHtml += '<option value="'+i+'" ';
		if(i == 0)
			quantHtml+= 'selected';
		quantHtml += '>'+i+'</option>';
	}
	quantHtml += '</select>';
	quant.innerHTML = quantHtml;
	
	var JS_LABEL_DETAIL = "Detalhes";
	detail.innerHTML = '<img alt="' + JS_LABEL_DETAIL + '" style="cursor:pointer;" onclick="showRoomDetail(' + roomNumber + ')" border=0 src="/img/ico_info.gif">&nbsp;';

	price.innerHTML = '<br><span id="preco' + roomNumber + '" style="vertical-align=top;">'+roomPrice+'&euro;</span>';
	desc.innerHTML = '<br>' + description + '<br><br>';
	
	var colSpacer = rowSpacer.insertCell(0);
	colSpacer.colSpan = "5";
	colSpacer.background = '/img/dot_black.gif';
	colSpacer.style.verticalAlign = "top";
	colSpacer.innerHTML = "<img src='/img/px_white.gif' width='1' height='1'>";
	colSpacer.id = 'sQ' + roomNumber;
	//<tr id='sQ" + roomNumber + "'><td colspan='5' background='/img/dot_black.gif' valign='top'><img src='/img/px_white.gif' width='1' height='1'></td></tr>
	
	// DETAILS
	rowPriceDetails.insertCell(0);
	var colPricesDetails = rowPriceDetails.insertCell(1);
	colPricesDetails.colSpan = "3";
	colPricesDetails.style.textAlign = "left";
	colPricesDetails.style.verticalAlign = "top";
	
	var htmlPricesDetail = "<div id='roomDetail" + roomNumber + "' style='display:none;'><table  class='txtTable' style='BORDER-LEFT: #AAAAAA 1px solid'>";
	
	for(var i = 0; i < priceArray.length; i++){
		htmlPricesDetail += "<tr><td colspan='2' align='left'><b>"+ priceArray[i]['Date'] + "</b></td></tr>";
		if(priceArray[i]['TotalAllotment'] != "0")
			htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;" + JS_LABEL_ALLOTMENT + ": </td><td align='left'>"+ priceArray[i]['TotalAllotment'] +"&euro;</td></tr>";
		if(priceArray[i]['TotalFood'] != "0")
			htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;" + JS_LABEL_LUNCH + ": </td><td align='left'>"+ priceArray[i]['TotalFood'] +"&euro;</td></tr>";
		if(priceArray[i]['TotalBreakfast'] != "0")
			htmlPricesDetail += "<tr><td align='right'>&nbsp;&nbsp;" + JS_LABEL_BREAKFEST + ": </td><td align='left'>"+ priceArray[i]['TotalBreakfast'] +"&euro;</td></tr>";
	}
	
	htmlPricesDetail += "<tr><td colspan='2' align='left'><br><b>" + JS_LABEL_TOTALPRICE + ": " + totalPrice +"&euro;</b></td></tr>";
	htmlPricesDetail += "</table><br>";
	htmlPricesDetail += "</div>";

	colPricesDetails.innerHTML = htmlPricesDetail;
	
}


// Adiciona um quarto à lista de quartos seleccionados na sessão
function removeRoom(id)
{
    var f = document.frmFullReservas;
	f.action = "xlets/iReservasWorker.jsp?action=removeRoom&roomIndex="+id;
	f.submit();
}

function hideNav() {
	//document.getElementById("rsrvBack").style.display="none";
	//document.getElementById("rsrvGo").style.display="none";
	document.getElementById("navtab").style.display="none";
	document.getElementById("steps").style.display="none";
}

function getEpoca(){
	var epoca = -1;
	var f = document.frmFullReservas;

	var di=f.txtDataCI.value.split("/");
	var dtaIni=new Date(di[2]+'/'+di[1]+'/'+di[0])

	var curdate = new Date()

	//Definiï¿½ï¿½o das ï¿½pocas:
	var curMonth = curdate.getMonth();

	var yearPre;
	var year;

	//Depois de setembro
	if (curMonth > 8){
		var yearPre = curdate.getYear();
		var year = curdate.getYear() + 1;
	}else{
		var yearPre = curdate.getYear() - 1;
		var year = curdate.getYear();
	}

	epocaBaixa = new Date(year + "/11/01");
	epocaBaixaPre = new Date(yearPre + "/11/01");
	epocaMedia = new Date(year + "/04/01");

	epocaMediaEsp = new Date(year + "/10/01");
	epocaAlta = new Date(year + "/06/01");

	//Epoca Baixa
	if (checkDateDiff(dtaIni,epocaBaixaPre)<=0 && checkDateDiff(dtaIni,epocaMedia)>0 || checkDateDiff(dtaIni,epocaBaixa)<=0){
		epoca = 0;
	}

	//Epoca Media
	if (checkDateDiff(dtaIni, epocaBaixaPre) > 0 || (checkDateDiff(dtaIni, epocaMedia) <= 0 && checkDateDiff(dtaIni, epocaAlta) > 0) || (checkDateDiff(dtaIni, epocaMediaEsp) <= 0 && checkDateDiff(dtaIni,epocaBaixa) > 0)){
		epoca = 1;
	}

	//Epoca Alta
	if (checkDateDiff(dtaIni, epocaAlta) <= 0 && checkDateDiff(dtaIni, epocaMediaEsp) > 0){
		epoca = 2;
	}

	return epoca;
}

function calcPrecos(){
	var epoca = 0;
	var iHotel = parseInt(document.frmFullReservas.hotelDest.selectedIndex)-1;
	var f = document.frmFullReservas;

	epoca = getEpoca();

}

// Mostra detalhes na listagem de quartos disponï¿½veis para reserva.
function showRoomDetail(id)
{
    var divDetail = document.getElementById("roomDetail"+id);

    if(divDetail.style.display == "none")
        divDetail.style.display = "inline";
    else
        divDetail.style.display = "none";
}

function showSelectedRoomDetail(id){ showRoomDetail('sel'+id); }


function changeHotel() {
	var oHotel = document.frmFullReservas.hotelDest;
	//var epoca = getEpoca();

	if (oHotel.selectedIndex>0) {

		iWorker.document.location.href = "xlets/iHotelInfo.jsp?H=" + oHotel.options[oHotel.selectedIndex].value;
	}
	else document.getElementById('divConteudo').innerHTML="";
}

function hideInfoQ(){
    var divSombra = document.getElementById("divSombra");
    var divInfoQuarto = document.getElementById("divInfoQuarto");
    var selects = document.getElementsByTagName('select');

    //mostrar caixas de select
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = 'visible';
	}

	//esconder divs
    divSombra.style.display = "none";
    divInfoQuarto.style.display = "none";
}

function showInfoQ(vista){

	if (document.frmFullReservas.hotelDest.selectedIndex>0) {
		iWorkerQ.document.location.href = "xlets/iQuartoInfo.jsp?H=" + document.frmFullReservas.hotelDest.options[document.frmFullReservas.hotelDest.selectedIndex].value + "&V=" + vista;

		var divSombra = document.getElementById("divSombra");
    	var divInfoQuarto = document.getElementById("divInfoQuarto");
    	var nLeft = (document.body.clientWidth/2)-(460/2);
		var nTop = (document.body.clientHeight/2)-(180/2);
		var selects = document.getElementsByTagName('select');

	    //calculate middle
		divInfoQuarto.style.top = nTop;
		divInfoQuarto.style.left = nLeft;

		//esconder caixas de select
		for (i=0; i<selects.length; i++) {
			selects[i].style.visibility = 'hidden';
		}

		//mostrar divs
		divSombra.style.top = 0;
		divSombra.style.left = 0;
	    //divSombra.style.width = document.body.clientWidth;
	    //divSombra.style.height = document.body.clientHeight;
		divSombra.style.width = screen.width;
	    divSombra.style.height = screen.height;
	    divSombra.style.display = "block";
	    divInfoQuarto.style.display = "block";
	}
}

//funcao para calcular o numero de noites entre duas datas
function numNoites(dti, dtf){

	var di=dti.split("/");
	var df=dtf.split("/");
	var s=new Date(di[1]+'/'+di[0]+'/'+di[2])
	var e=new Date(df[1]+'/'+df[0]+'/'+df[2])

	return checkDateDiff(s,e);
}

//funcao que vai escrever string dinï¿½mica no fim da tabela dos quartos
function calculaString(hospedes, noites, quartos){

	//document.getElementById("thInfo").innerHTML="<i>"+hospedes+JS_LABEL_HOSPDURANTE+noites+JS_LABEL_NOITESEM+quartos+JS_LABEL_QUARTOOUS+"</i>";
}

//funï¿½ï¿½o que calcula o total a pagar pela estadia no hotel
function calculaPrecoTotal(){
	var f = document.frmFullReservas;
	var iHotel = parseInt(document.frmFullReservas.hotelDest.selectedIndex)-1;

	var numQuartosDisp = (document.getElementById('searchResultsList').rows.length-3)/3;
	
	var precoTotal = 0;

	//preï¿½os dos quartos
	for (i = 1; i <= numQuartosDisp; i++){
		var det = eval("document.frmFullReservas.nQ" + i);
		numQuartos = parseInt(det.options[det.selectedIndex].value);

		var preco = document.getElementById("preco" + i);
		precoQuarto = parseFloat(preco.innerHTML);
		precoTotal += (numQuartos * precoQuarto);
	}

	var hasChilds = false;

	
	var noites = numNoites(document.frmFullReservas.txtDataCI.value,document.frmFullReservas.txtDataCO.value);
	var elem = document.getElementById("thTotal");
	if(elem != null)
		document.getElementById("thTotal").innerHTML = precoTotal*noites;

}

function confirmaCopia() {
	if (document.frmFullReservas.chkIgual.checked)
		copiaDadosContacto();
}

function changePaymentInput() {
	var f = document.frmFullReservas;
	if (f.opPagamento[0].checked) {
		//input=cartao
		document.getElementById("tblCCred").style.display = "";
		document.getElementById("tblConta").style.display = "none";
	} else {
		//input=conta
		document.getElementById("tblCCred").style.display = "none";
		document.getElementById("tblConta").style.display = "";
	}
}


/************************* Funcoes Mobile ************************************/

//formulario da home
function submitMobForm() {
	var f = document.frmMobReservas;

	if (f.hotelDest.selectedIndex == 0) {
		alert("Por favor, seleccione o hotel de destino.");
		f.hotelDest.focus();
		return;
	}

	if (f.diaCI.selectedIndex == 0 || f.mesCI.selectedIndex == 0 || f.anoCI.selectedIndex == 0) {
		alert("Por favor, introduza a data de Check-In.");
		return;
	}

	if (f.diaCO.selectedIndex == 0 || f.mesCO.selectedIndex == 0 || f.anoCO.selectedIndex == 0) {
		alert("Por favor, introduza a data de Check-Out.");
		return;
	}

	//verifica se data check-in maior que data actual
	var s=new Date(f.anoCI.value+'/'+f.mesCI.value+'/'+f.diaCI.value)
	var e=new Date()

	if (checkDateDiff(s,e) > 0){
		alert('ERRO: data de Check-In inferior ï¿½ data actual.');
		return;
	}

	//verifica se data check-in menor que data check-out
	var s=new Date(f.anoCI.value+'/'+f.mesCI.value+'/'+f.diaCI.value)
	var e=new Date(f.anoCO.value+'/'+f.mesCO.value+'/'+f.diaCO.value)

	if (checkDateDiff(s,e) < 0){
		alert('ERRO: data de Check-In superior ï¿½ data de Check-Out.');
		return;
	}
	else if (checkDateDiff(s,e) == 0){
		alert('ERRO: data de Check-Out igual ï¿½ data de Check-In.');
		return;
	}

	if (f.numQuartos.selectedIndex == 0) {
		alert("Por favor, introduza o nï¿½mero de quartos pretendidos.");
		f.numQuartos.focus();
		return;
	}

	if (f.numAdultos.selectedIndex == 0) {
		alert("Por favor, introduza o nï¿½mero de adultos/quarto.");
		f.numAdultos.focus();
		return;
	}

	f.submit();
}

//formulario reservas
function submitFullMobForm(next) {
	var f = document.frmFullMobReservas;
	var step = parseInt(f.step.value);
	var next = parseInt(next);

	if (step==1) {
	 if (f.hotelDest.selectedIndex == 0) {
		alert("Por favor, seleccione o hotel de destino.");
		f.hotelDest.focus();
		return;
	 }

	 if (f.diaCI.selectedIndex == 0 || f.mesCI.selectedIndex == 0 || f.anoCI.selectedIndex == 0) {
		alert("Por favor, introduza a data de Check-In.");
		return;
	 }

	 if (f.diaCO.selectedIndex == 0 || f.mesCO.selectedIndex == 0 || f.anoCO.selectedIndex == 0) {
		alert("Por favor, introduza a data de Check-Out.");
		return;
	 }

	 //verifica se data check-in maior que data actual
	 var s=new Date(f.anoCI.value+'/'+f.mesCI.value+'/'+f.diaCI.value)
	 var e=new Date()

	 if (checkDateDiff(s,e) > 0){
		alert('ERRO: data de Check-In inferior ï¿½ data actual.');
		return;
	 }

	 //verifica se data check-in menor que data check-out
	 var s=new Date(f.anoCI.value+'/'+f.mesCI.value+'/'+f.diaCI.value)
	 var e=new Date(f.anoCO.value+'/'+f.mesCO.value+'/'+f.diaCO.value)

	 if (checkDateDiff(s,e) < 0){
		alert('ERRO: data de Check-In superior ï¿½ data de Check-Out.');
		return;
	 }
	 else if (checkDateDiff(s,e) == 0){
		alert('ERRO: data de Check-Out igual ï¿½ data de Check-In.');
		return;
	 }

	 if (f.numQuartos.selectedIndex == 0) {
		alert("Por favor, introduza o nï¿½mero de quartos pretendidos.");
		f.numQuartos.focus();
		return;
	 }

	 if (f.numAdultos.selectedIndex == 0) {
		alert("Por favor, introduza o nï¿½mero de adultos/quarto.");
		f.numAdultos.focus();
		return;
	 }

	 //verifica hora prevista de chegada
	 if (f.horasVoo.value!="" && f.minsVoo.value!=""){
	  var horasVoo = parseInt(f.horasVoo.value);
	  var minsVoo = parseInt(f.minsVoo.value);
	  if (isNaN(f.horasVoo.value) || isNaN(f.minsVoo.value) || (horasVoo<0) || (horasVoo>23) || (minsVoo<0) || (minsVoo>59)) {
	 	alert("Hora Prevista de Chegada Invï¿½lida. Corrija, por favor.");
	 	return;
	  }
	 }
	 else {
	 	f.horasVoo.value="";
	 	f.minsVoo.value="";
	 }
	}

	if (step==3 && next==1) {
	 if (f.nome.value=="") {
	 	alert("Por favor, introduza o seu nome.");
	 	f.nome.focus();
	 	return;
	 }

	 if (f.morada.value=="") {
	 	alert("Por favor, introduza a sua morada.");
	 	f.morada.focus();
	 	return;
	 }

	 if (f.contribuinte.value=="") {
	 	alert("Por favor, introduza o seu nï¿½mero de contribuinte.");
	 	f.contribuinte.focus();
	 	return;
	 }

	 if (f.telefone.value=="") {
	 	alert("Por favor, introduza o seu telefone.");
	 	f.telefone.focus();
	 	return;
	 }

	 if (!f.chkIgual.checked){
	  if (f.nomef.value=="") {
	 	alert("Por favor, introduza nome do contacto de facturaï¿½ï¿½o.");
	 	f.nomef.focus();
	 	return;
	  }

	  if (f.moradaf.value=="") {
	 	alert("Por favor, introduza a morada do contacto de facturaï¿½ï¿½o.");
	 	f.moradaf.focus();
	 	return;
	  }

	  if (f.contribuintef.value=="") {
	 	alert("Por favor, introduza o nï¿½mero de contribuinte do contacto de facturaï¿½ï¿½o.");
	 	f.contribuintef.focus();
	 	return;
	 }

	  if (f.telefonef.value=="") {
	 	alert("Por favor, introduza o telefone do contacto de facturaï¿½ï¿½o.");
	 	f.telefonef.focus();
	 	return;
	  }
	 }
	 else confirmaCopiaPDA();

	}

	if (step==5 && next==1){
	 if (f.opPagamento.value=="ccred") {
	  	if (f.lstCartoes.selectedIndex==0){
	 		alert("Por favor, escolha o tipo de cartï¿½o.");
	 		return;
	 	}

	 	if (f.nomeCartao.value=="") {
	 		alert("Por favor, introduza o nome do titular do cartï¿½o.");
	 		return;
		}

		if (f.numCartao.value=="") {
	 		alert("Por favor, introduza o nï¿½mero do cartï¿½o.");
	 		return;
		}

	 	if (f.mesValidade.selectedIndex==0 || f.anoValidade.selectedIndex==0){
	 		alert("Por favor, introduza a validade do cartï¿½o.");
	 		return;
	 	}
	 }
	}

	f.step.value=step+next;
	f.submit();
}

//funcao que copia dados do contacto para o contacto facturacao
function copiaDadosContactoPDA(){

	var f = document.frmFullMobReservas;

	if (f.chkIgual.checked){
		f.nomef.value=f.nome.value;
		//f.nomef.readOnly=true;
		f.moradaf.value=f.morada.value;
		//f.moradaf.readOnly=true;
		f.contribuintef.value=f.contribuinte.value;
		//f.contribuintef.readOnly=true;
		f.telefonef.value=f.telefone.value;
		//f.telefonef.readOnly=true;
		f.emailf.value=f.email.value;
		//f.emailf.readOnly=true;
	}
	/*else {
		f.nomef.readOnly=false;
		f.moradaf.readOnly=false;
		f.contribuintef.readOnly=false;
		f.telefonef.readOnly=false;
		f.emailf.readOnly=false;
	}*/
}

function confirmaCopiaPDA() {
	if (document.frmFullMobReservas.chkIgual.checked)
		copiaDadosContactoPDA();
}

//-->