// JavaScript Document

 var countCountries = 1;
       function updateRegions(formName,countrySelectName,regionSelectName,citySelectName) {
         eval("countriesSelObj = window.document." + formName + "." + countrySelectName + ";");
         eval("regionsSelObj = window.document." + formName + "." + regionSelectName + ";");
         if (countCountries > 1){
           var countryid = countriesSelObj[countriesSelObj.selectedIndex].value;
         }else{
           var countryid = countriesSelObj.value;
         }
         countriesSelObj.disabled = true;
         regionsSelObj.options[0].text = 'loading';
         regionsSelObj.disabled = true;
         window.frames['populate'].location.replace('obmp22/helper_get_regions.php?ln=<?= $ln?>' + '&iCountry=' + countryid + '&formname=' + formName + '&countryselectname=' + countrySelectName + '&regionselectname=' + regionSelectName + '&cityselectname=' + citySelectName);
      }
      function populateRegionsSelectObj(arrids,arrnames,formname,countryselectname,regionselectname,cityselectname) {
         eval("countriesSelObj = window.document." + formname + "." + countryselectname + ";");
         eval("regionsSelObj = window.document." + formname + "." + regionselectname + ";");
         eval("citiesSelObj = window.document." + formname + "." + cityselectname + ";");
         regionsSelObj.length = 0;
         for(var i=0;i<arrids.length;i++) {
            regionsSelObj[i] = new Option(arrnames[i],arrids[i]);
         }
         regionsSelObj[1].selected = true;
         updateCities(formname,countryselectname,regionselectname,cityselectname,'');
         countriesSelObj.disabled = false;
         regionsSelObj.disabled = false;
      }

     function updateCities(formName,countrySelectName,regionSelectName,citySelectName,dir) {
         eval("countriesSelObj = window.document." + formName + "." + countrySelectName + ";");
         eval("regionsSelObj = window.document." + formName + "." + regionSelectName + ";");
         eval("citiesSelObj = window.document." + formName + "." + citySelectName + ";");
         if (countCountries > 1){
           var countryid = countriesSelObj[countriesSelObj.selectedIndex].value;
         }else{
           var countryid = countriesSelObj.value;
         }
         var regionid = regionsSelObj[regionsSelObj.selectedIndex].value;
         countriesSelObj.disabled = true;
         regionsSelObj.disabled = true;
         citiesSelObj.options[0].text = 'loading';
         citiesSelObj.disabled = true;
         window.frames['populate'].location.replace('' + dir + 'helper_get_cities.php?ln=<?= $ln?>' + '&iCountry=' + countryid + '&iRegion=' + regionid  + '&formname=' + formName + '&countryselectname=' + countrySelectName + '&regionselectname=' + regionSelectName + '&cityselectname=' + citySelectName);
      }



      function populateCitiesSelectObj(arrids,arrnames,formname,countryselectname,regionselectname,cityselectname) {
         eval("countriesSelObj = window.document." + formname + "." + countryselectname + ";");
         eval("regionsSelObj = window.document." + formname + "." + regionselectname + ";");
         eval("citiesSelObj = window.document." + formname + "." + cityselectname + ";");
         citiesSelObj.length = 0;
         for(var i=0;i<arrids.length;i++) {
            citiesSelObj[i] = new Option(arrnames[i],arrids[i]);
         }
         citiesSelObj[0].selected = true;
         regionsSelObj.disabled = false;
         countriesSelObj.disabled = false;
         citiesSelObj.disabled = false;
      }

     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 openWR(){
          var width = screen.Width - 50;
          var height = screen.Height - 200;
          var str = 'height=' + height + ',innerHeight=' + height;
          str += ',width=' + width + ',innerWidth=' + width;
          if (window.screen) {
             var ah = screen.availHeight - 100;
             var aw = screen.availWidth - 10;
             var xc = (aw - width) / 2;
             var yc = (ah - height) / 2;
             str += ',left=' + xc + ',screenX=' + xc;
             str += ',top=' + yc + ',screenY=' + yc;
          }
          window.open('obmp22/cancel_res.php?page=portal&ln=<?= $ln?>','obmp22R','scrollbars=yes,status=yes,menubar=no,toolbar=yes,' + str);
          return false;
     }

     function openC(frm,nform) {
        window.open('obmp22/calendar.php?frm=' + frm + '&nform=' + nform + '&ln=<?= $ln?>','in','scrollbars=yes,status=yes,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;
     }