var bNotRefresh = false;

function setFocus(elementID) {
        oElement = document.getElementById(elementID);

        oElement.focus();
}//end function

function changeClass(oElement, sClassName) {
  oElement.className = sClassName;
} // end...function

function showSubMenuItem(sID) {
  if (bNotRefresh == true) {
    bNotRefresh == false;
  }
  oElement = document.getElementById(sID);
  if (oElement) {
    if (oElement.className == 'sidesubmenu-item') {
      oElement.className = "sidesubmenu-item-hidden";
    } else {
      oElements = document.getElementsByTagName('div');
      if (oElements) {
        for (i = 0; i < oElements.length; i++) {
                  if (oElements.item(i).name == 'sidemenuitem') {
            oElements.item(i).className = 'sidesubmenu-item-hidden';
                  }
        }
      }
      oElement.className = "sidesubmenu-item";
    }
  }
} // end...function

function hideSubMenuItem(sID) {
  oElement = document.getElementById(sID);
  if (oElement) {
//    oElements = getElementByTagName("div");
//    if (oElements) {
//      for (i = 0; i < oElements.length; i++) {
//        oElements.item(i).className = "sidesubmenu-item-hidden";
//      }
//    }
    oElement.className = "sidesubmenu-item-hidden";
  }
} // end...function

function gotoPage(sLocation) {
//  var ns4 = document.all;
  window.top.location.assign(sLocation);
//  if (!ns4) {
//    window.top.location.replace(sLocation);
//  } else {
//    window.top.location.reload(sLocation);
//  }
//  return false;
} // end...function

function submitForm(location) {
  oForm = document.getElementById('submitform');

  if (oForm) {
    if (location.length > 0) { oForm.action = location; }
    oForm.submit();
  }
} // end...function

function strToDate(dateStr) {
  var bits = dateStr.split(".");
  return new Date(bits[2],bits[1]-1,bits[0]);
}

function strToBits(dateStr) {
  return dateStr.split(".");
}

function checkdates(from, to, reservations, frombiggerthanto, reservatinshavebeenmade, redirection) {
  var fd = strToDate(from.value);
  var td = strToDate(to.value);
  var year = fd.getYear();

  if (fd > td) {
    alert(frombiggerthanto);
    return false;
  }

  for(i=0;i<reservations.length;i++) {
    var rfrom = new Date(year,reservations[i][1]-1,reservations[i][0]);
    var rto = new Date(year,reservations[i][3]-1,reservations[i][2]);

    if((fd >= rfrom)&&(fd<=rto)) {
      alert(reservatinshavebeenmade);
            return false;
    }

    if((td>=rfrom)&&(td<=rto)) {
      alert(reservatinshavebeenmade);
            return false;
    }

    if(((fd<=rfrom)&&(td>=rto))||((fd<=rfrom)&&(td>=rfrom)&&(td>=rto))) {
      alert(reservatinshavebeenmade);
            return false;
    }
  } // end...for
  submitForm(redirection);
}

function checkiffirstdateislower(from, to, frombiggerthanto, redirection) {
  var fd = strToDate(from.value);
  var td = strToDate(to.value);

  if (fd > td) {
    alert(frombiggerthanto);
    return false;
  }
  submitForm(redirection);
}

function checkcheckboxes(redirection, errormsg) {
  oForm = document.getElementById("submitform");

  oElements = oForm.getElementsByTagName("input");

  j = 0;
  for(i=0;i<oElements.length;i++){
    oItem = oElements.item(i);
        if(oItem.type == 'checkbox') {
          if(oItem.checked == true){ j++; }
        }
  }

  if(j==0){ alert(errormsg); return false; }

  submitForm(redirection);
}

function checkinputfields(redirection, errormsg) {
  oForm = document.getElementById("submitform");

  oElements = oForm.getElementsByTagName("input");

  for(i=0;i<oElements.length;i++){
    oItem = oElements.item(i);
        if(oItem.type == "text") {
          if(oItem.value.length == 0){
                alert(errormsg);
                return false;
          }
        }
  }

  submitForm(redirection);
}