function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->

<!-- START SoftVisions code -->
      function closeWinNew(){
         if (typeof(winNew) == "object" && winNew != null ){
            winNew.close();
         }
      }
      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;
            }
         }
         //resetCheckInOut("checkout");
      }


      function openW(frm,nform) {
         var roomID,i;

         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") && (frm == "end")){
            alert("ERROR: Please select the 'Check-in' date first !");
            return false;
         }


         var checkin = new Date();
         checkin.setDate(checkin.getDate()+1);

         var selectedDay = 1;
         if (window.document.checka.daysI.options[window.document.checka.daysI.selectedIndex].value != "0"){
            selectedDay =  window.document.checka.daysI.options[window.document.checka.daysI.selectedIndex].value;
         }
         var selectedMonth = checkin.getMonth()+1;
         if (window.document.checka.monthsI.options[window.document.checka.monthsI.selectedIndex].value != "0"){
            selectedMonth =  window.document.checka.monthsI.options[window.document.checka.monthsI.selectedIndex].value;
         }
         var selectedYear = checkin.getYear();
         if (window.document.checka.yearI.options[window.document.checka.yearI.selectedIndex].value != "0"){
            selectedYear =  window.document.checka.yearI.options[window.document.checka.yearI.selectedIndex].value;
         }
         roomID = window.document.checka.typeRoom.value;
         window.open('http://www.housesinvenice.com/booking/obm22/availabilitycalendarsmall.php?frm=' + frm + '&nform=' + nform + '&ln=es&id=1&roomid=' + roomID + '&day=' + selectedDay + '&month=' + selectedMonth + '&year=' + selectedYear,'in','scrollbars=yes,status=no,width=400,height=230,top=200,left=550,menubar=no');
         return false;
      }

      /*
      function openW(frm,nform) {
         window.open('calendar.php?frm=' + frm + '&nform=' + nform + '&ln=en','in','scrollbars=yes,status=no,width=265,height=270,top=200,left=550,menubar=no');
         return false;
      }


      function resetCheckInOut(param){
         if ((param == "checkin") || (param == "both")){
            window.document.checka.daysI.options[0].selected = true;
            window.document.checka.monthsI.options[0].selected = true;
            window.document.checka.yearI.options[0].selected = true;
         }
         if ((param == "checkout") || (param == "both")){
            window.document.checka.daysS.options[0].selected = true;
            window.document.checka.monthsS.options[0].selected = true;
            window.document.checka.yearS.options[0].selected = true;
         }
      }
      */

      function verifica() {
         var data1,data2,d,dat1,dat2;
         data1 = new Date();
         data2 = new Date();
         if (typeof(document.forms['checka'].typeRoom) == "undefined"){
            alert("Seleccionar otro apartamento. Este apartamento no está disponible")
            return false;
         }
         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 ("Fecha no válida, le rogamos de controlar");
            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("'La fecha de llegada non puede anticipar la fecha de hoy");
            return false;
         }
         if (data1 >= data2){
            alert ("La fecha de llegada no puede ser después la fecha de hoy");
            return false;
         }
         /*
         window.document.checka.yearI.disabled = false;
         window.document.checka.monthsI.disabled = false;
         window.document.checka.daysI.disabled = false;
         window.document.checka.yearS.disabled = false;
         window.document.checka.monthsS.disabled = false;
         window.document.checka.daysS.disabled = false;
         */
         return true;
      }
      function setCurrentDate(){
         checkin = new Date();
         checkout = new Date();
         checkin.setDate(checkin.getDate()+1);
         checkout.setDate(checkout.getDate()+4);
         selectElement(window.document.checka.daysI,checkin.getDate());
         selectElement(window.document.checka.monthsI,checkin.getMonth()+1);
         selectElement(window.document.checka.yearI,checkin.getFullYear());
         selectElement(window.document.checka.daysS,checkout.getDate());
         selectElement(window.document.checka.monthsS,checkout.getMonth()+1);
         selectElement(window.document.checka.yearS,checkout.getFullYear());
      }
      function selectElement(param,testValue){
         for (var i = 0; i < param.length; i++) {
            if (param.options[i].value == testValue) {
               param.options[i].selected = true;
            }
         }
      }
     function adjustDate( monthObj, dayObj, yearObj ) {
       var value = 0;
       var mthIdx = monthObj.options.selectedIndex - 1;
       var Dt = dayObj;
       var theYear = yearObj.options[yearObj.options.selectedIndex].value;
       var numDays = getDaysInMonth( mthIdx, theYear );

       if( mthIdx == 1 ) {
         if( Dt.options.selectedIndex + 3 < numDays ) {
           return 0;
         } else {
           if( Dt.options.selectedIndex > numDays) {
             Dt.options.selectedIndex = numDays;

           }
           if( (Dt.options.selectedIndex) == numDays ) {
             return 1;
           } else {
             return 4;
           }
         }
       }
       if( Dt.options.selectedIndex + 1 < numDays ) {
         value = 0;
       } else {
         if ( Dt.options.selectedIndex > numDays ) {
           Dt.options.selectedIndex--;
           value = 3;
         } else if ( Dt.options.selectedIndex == numDays ) {
           value = 2;
         } else {
           value = 4;
         }
       }
       return value;
     }
      function getDaysInMonth( mthIdx, YrStr ) {
        // all the rest have 31
        var maxDays = 31
        // expect Feb. (of course)
        if( mthIdx == 1 ) {
            if( isLeapYear( YrStr ) ) {
                maxDays=29;
            } else {
                maxDays=28;
            }
        }

        // thirty days hath...
        if( mthIdx == 3 || mthIdx == 5 || mthIdx == 8 || mthIdx == 10 ) {
            maxDays=30;
        }
        return maxDays;
      }
  function isLeapYear( yrStr ) {
    var leapYear = false;
    var year = parseInt( yrStr, 10 );
    if ( year % 4 == 0 ) {
      leapYear = true;
      if( year % 100 == 0 ) {
        leapYear = false;
        if( year % 400 == 0 ) {
          leapYear=true;
        }
      }
    }
    return leapYear;
  }

