//function showHideChildrenAge(formName){
//         var nrChildren = window.document.forms[formName].childs.options[window.document.forms[formName].childs.selectedIndex].value;
//         var nrMaxChildren = <?= $maxChildren?>;
 //        for (var i=1; i <= nrChildren; i++){
 //           window.document.getElementById("childAgeTable" + i).className = "classshown";
 //        }
 //        nrChildren ++;
 //        for (var j= nrChildren ; j <= nrMaxChildren; j++){
 //           window.document.getElementById("childAgeTable" + j).className = "classhidden";
 //        }
 //     }

          function setDateS(data,nform){
              var a = data.split("/");
              document.forms[nform].monthsS.options[a[1]-1].selected=true;
              document.forms[nform].daysS.options[a[0]-1].selected=true;
              for(var i=0;i< document.forms[nform].yearS.options.length;i++){
                if(document.forms[nform].yearS.options[i].value==a[2]){
                  document.forms[nform].yearS.options[i].selected=true;
                }
              }
       }

          function setDateI(data,nform){
              var a = data.split("/");
              document.forms[nform].monthsI.options[a[1]-1].selected=true;
              document.forms[nform].daysI.options[a[0]-1].selected=true;
              for(var i=0;i< document.forms[nform].yearI.options.length;i++){
                if(document.forms[nform].yearI.options[i].value==a[2]){
                  document.forms[nform].yearI.options[i].selected=true;
                }
              }
       }

          function openW(frm,nform) {
             window.open('calendar.php?frm=' + frm + '&nform=' + nform + '&ln=<?= $ln?>','in','scrollbars=yes,status=no,width=265,height=270,top=200,left=550,menubar=no');
             return false;
       }

          function verifica() {
             var data1,data2,d,dat1,dat2;
             data1 = new Date();
             data2 = new Date();
             if (window.document.checka.yearI.options[window.document.checka.yearI.selectedIndex].value == "0" ||
                 window.document.checka.monthsI.options[window.document.checka.monthsI.selectedIndex].value == "0" ||
                 window.document.checka.daysI.options[window.document.checka.daysI.selectedIndex] == "0" ||
                 window.document.checka.yearS.options[window.document.checka.yearS.selectedIndex] == "0" ||
                 window.document.checka.monthsS.options[window.document.checka.monthsS.selectedIndex] == "0" ||
                 window.document.checka.daysS.options[window.document.checka.daysS.selectedIndex] == "0")
             {
                 alert ("<?= $msg2?>");
                 return false;
             }
        d = new Date();
        dc = new Date(d.getFullYear(),d.getMonth(), d.getDate());
        dataC = Date.parse(dc.toUTCString());
        dat1 = new Date(window.document.checka.yearI.options[window.document.checka.yearI.selectedIndex].value, parseInt(window.document.checka.monthsI.options[window.document.checka.monthsI.selectedIndex].value) -1 ,window.document.checka.daysI.options[window.document.checka.daysI.selectedIndex].value);
        dat2 = new Date(window.document.checka.yearS.options[window.document.checka.yearS.selectedIndex].value, parseInt(window.document.checka.monthsS.options[window.document.checka.monthsS.selectedIndex].value) -1 ,window.document.checka.daysS.options[window.document.checka.daysS.selectedIndex].value);
        data1 = Date.parse(dat1.toUTCString());
        data2 = Date.parse(dat2.toUTCString());

             if(dataC > data1){
               alert("<?= $msg3?>");
               return false;
             }
             if (data1 >= data2){
                 alert ("<?= $msg4?>");
                 return false;
             }
             return true;
          }
  
       function openAC(roomid){
          width=550;
          height=210;
          selectedMonth =  window.document.checka.monthsI.options[window.document.checka.monthsI.selectedIndex].value;
          selectedYear =  window.document.checka.yearI.options[window.document.checka.yearI.selectedIndex].value;
          xPos = (screen.Width - width) / 2;
          yPos = (screen.Height - height) / 2;
          if (roomid==0){
              window.open('availabilitycalendar.php?id=<?= $id?>&month=' + selectedMonth + '&year=' + selectedYear + '&ln=<?= $ln?>','availabilitycalendar','scrollbars=yes,status=no,width=' + width + ',height=' + height + ',top=' + yPos + ',left=' + xPos + ',menubar=no');
          }else{
             window.open('availabilitycalendar.php?id=<?= $id?>&roomid=' + roomid + '&month=' + selectedMonth + '&year=' + selectedYear + '&ln=<?= $ln?>','availabilitycalendar','scrollbars=yes,status=no,width=' + width + ',height=' + height + ',top=' + yPos + ',left=' + xPos + ',menubar=no');
          }             
          return false;
       }
  
   
   
      function closeWinNew(){
         if (typeof(winNew) == "object" && winNew != null ){
            winNew.close();
         }
      }

      function hideLoadingPage() {
         if (document.getElementById) {  // DOM3 = IE5, NS6
            document.getElementById('hidepage').style.visibility = 'hidden';
         }else {
            if (document.layers) {  // Netscape 4
               document.hidepage.visibility = 'hidden';
            }
            else {  // IE 4
               document.all.hidepage.style.visibility = 'hidden';
            }
         }
      }

      function openImg(param,wImg,hImg){
         xPos = (screen.Width - wImg) / 2;
         yPos = (screen.Height - hImg) / 2;
         winNew = window.open('systemadmin/room_photo.php?photo=' + param,'photo','scrollbars=no,status=no,width=' + wImg + ',height=' + hImg + ',top=' + yPos + ',left=' + xPos + ',menubar=no');
      }

      function roundTo2Decimals(param){
         var roundedNr = new Number(Math.round(param*100)/100);
         return roundedNr.toFixed(2);
      }

      function roundTo0Decimals(param){
         var roundedNr = new Number(Math.round(param*100)/100);
         var retVal = roundedNr.toFixed(0);
         var retRoundedNr = new Number(retVal);
         return retRoundedNr.toFixed(2);
      }
      
      function setTaxes(stayCost,paramTotalRes,objForm,roomID,formName,noRooms){
         var tmpTotalRes = roundTo2Decimals(parseFloat(paramTotalRes));
         var tmpTotalResWithTaxes = roundTo2Decimals(parseFloat(paramTotalRes));
         var i,taxVal;
         var objTaxeData;
         var arrTaxes = new Array();
         var haveGrandTotal;
         
         eval('arrTaxes = arrTaxes_' + roomID + ';');
         
         haveGrandTotal = false;         
         for (i = 0; i < arrTaxes.length; i++){
            taxVal = 0;
            objTaxeData = arrTaxes[i];
            switch (objTaxeData.type){
               case "percentage":
                  taxVal = calculateTaxe(stayCost,objTaxeData,formName,noRooms);
                  break;
               case "flat":
                  taxVal = roundTo2Decimals(parseFloat(objTaxeData.value * noRooms));
                  break;
            }
            
            if(taxVal > 0) {
               haveGrandTotal = true;
               window.document.getElementById("trTaxe_" + roomID + "_" + objTaxeData.id).className = "classshown";
            }
            else {
               window.document.getElementById("trTaxe_" + roomID + "_" + objTaxeData.id).className = "classhidden";
            }
            eval("objForm.taxes" + objTaxeData.id + ".value = taxVal;");
            
            tmpTotalResWithTaxes = roundTo2Decimals(parseFloat(tmpTotalResWithTaxes) + parseFloat(taxVal));
         }
         
         if(haveGrandTotal) {
            window.document.getElementById("trGrandTotalSpace_" + roomID).className = "classshown";
            window.document.getElementById("trGrandTotal_" + roomID).className = "classshown";
         }
         else {
            if(window.document.getElementById("trGrandTotalSpace_" + roomID) != null) {
               window.document.getElementById("trGrandTotalSpace_" + roomID).className = "classhidden";
               window.document.getElementById("trGrandTotal_" + roomID).className = "classhidden";
            }
         }
         objForm.grandTotal.value = roundTo2Decimals(parseFloat(tmpTotalResWithTaxes));
   }


    function calculateTaxe(totalForTheStay,objTaxeData,formName,noRooms){
         var retVal = 0;
         var valTheTaxeAppliesTo = 0;
         var aservCost = 0;
         
         if(objTaxeData.applicable.stay.istrue) {
            valTheTaxeAppliesTo += totalForTheStay;
         }
      
         if(objTaxeData.applicable.aservices.istrue) {
            for(i=0;i<objTaxeData.applicable.aservices.ids.length;i++) {
               eval("aservCost = document.forms['" + formName + "'].aservCS" + objTaxeData.applicable.aservices.ids[i] + ".value;");
               valTheTaxeAppliesTo += parseFloat(aservCost * noRooms);
            }
         }
      
         if(objTaxeData.applicable.taxes.istrue) {
            for(i=0;i<objTaxeData.applicable.taxes.ids.length;i++) {
               eval("taxeToApplyToCost = document.forms['" + formName + "'].taxes" + objTaxeData.applicable.taxes.ids[i] + ".value;");
               valTheTaxeAppliesTo += parseFloat(taxeToApplyToCost);
            }
         }
         
         retVal = roundTo2Decimals(parseFloat((objTaxeData.value/100) * valTheTaxeAppliesTo));

         return retVal;
      }

      function updateDataToTransport(paramFormName) {
      
         document.forms[paramFormName].submit_1.disabled = true;
         document.forms[paramFormName].submit_2.disabled = true;
      
         var dataToSend = document.forms[paramFormName].datatotransport.value;
      
         window.frames['helper_onchangecontrols'].prepareData(dataToSend, paramFormName);
      }

      function setDataToTransport(paramFormName, paramDataToTransport) {
      
         document.forms[paramFormName].datatotransport.value = paramDataToTransport;
         document.forms[paramFormName].submit_1.disabled = false;
         document.forms[paramFormName].submit_2.disabled = false;
      }

      function setCostService(sel,aservID,aservCost,stayTotal,noRooms,formName,currEnfInt,depositType,roomID){
         var deposit,serviceCharge,grandTotal;
         
         document.forms[formName].aservTotalRoom.value = parseFloat(document.forms[formName].aservTotalRoom.value) - parseFloat(eval("document.forms[formName].aservCS" + aservID + ".value"));
         eval("document.forms['" + formName + "'].aservCS" + aservID + ".value = roundTo2Decimals(document.forms['" + formName + "']." + sel + ".options[document.forms['" + formName + "']." + sel + ".selectedIndex].value * aservCost);");
         document.forms[formName].aservTotalRoom.value = roundTo2Decimals(parseFloat(document.forms[formName].aservTotalRoom.value) + parseFloat(eval("document.forms['" + formName + "'].aservCS" + aservID + ".value")));
         document.forms[formName].aservTotal.value = roundTo2Decimals(parseFloat(document.forms[formName].aservTotalRoom.value) * parseFloat(noRooms));
         document.forms[formName].staysaervTotal.value = roundTo2Decimals(parseFloat(document.forms[formName].aservTotal.value) + parseFloat(stayTotal));
         
         setTaxes(stayTotal,document.forms[formName].staysaervTotal.value,document.forms[formName],roomID,formName,noRooms);
   
         if (depositType == "percent"){
            if(document.forms[formName].deposit){
               if(document.forms[formName].grandTotal){
                  deposit = parseFloat(document.forms[formName].depositPercentage.value) *  parseFloat(document.forms[formName].grandTotal.value ) / parseFloat(100);
               }else{
                  deposit = parseFloat(document.forms[formName].depositPercentage.value) * parseFloat(document.forms[formName].staysaervTotal.value) / parseFloat(100);
               }
            }else{
               if(document.forms[formName].grandTotal){
                  deposit = parseFloat(document.forms[formName].grandTotal.value);
               }else{
                  deposit = parseFloat(document.forms[formName].staysaervTotal.value);
               }
            }
            if(currEnfInt.toUpperCase() == 'Y'){
               deposit = roundTo0Decimals(parseFloat(deposit));
            }else{
               deposit = roundTo2Decimals(parseFloat(deposit));
            }
      
            if(document.forms[formName].deposit){
               document.forms[formName].deposit.value = deposit;
            }
         
            if(document.forms[formName].serviceCharge){
               serviceCharge = document.forms[formName].serviceCharge.value;
            }else{
               serviceCharge = 0;
            }
      
            if(document.forms[formName].totalPayableNow){
               document.forms[formName].totalPayableNow.value = roundTo2Decimals(parseFloat(deposit) + parseFloat(serviceCharge));
            }
         }
   
         updateDataToTransport(formName);
   }
      
      
   function sendRequest(forma){
      var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
      if(!regex.test(forma.email.value)){
         alert("<?=$a1?>");
         forma.email.focus();
         return false;
      }
   }
   
   function unhideTaxes(roomID) {
   
      var arrTaxes = new Array();
      /*
      eval('arrTaxes = arrTaxes_' + roomID + ';');
      
      for (i = 0; i < arrTaxes.length; i++){
         window.document.getElementById("trTaxe_" + roomID + "_" + arrTaxes[i].id).className = "classshown";
      }
      */
      return true;
   }