function presetDate(frm, elem, mstart, intv) {
	var Today = new Date();
	var myDate = new Date(Today.getTime()+intv*24*60*60*1000);
	elem_d = elem + "_D";
	elem_m = elem + "_M";
	elem_y = elem + "_Y";
	if (navigator.appName.indexOf("Microsoft")== -1) {
		var day = myDate.getDate() - 1;
		var month = myDate.getMonth();
		var year = myDate.getYear() + 1900;
		var year_idx;
	   	for (var i=0; i < document[frm][elem_y].options.length; i++) {
			if (document[frm][elem_y].options[i].value == year) {
				year_idx = i;
			}
		}
		document[frm][elem_d].options[day].selected = true;
		document[frm][elem_m].options[month].selected = true;
		document[frm][elem_y].options[year_idx].selected = true;

		
	}
	else {
		var day = myDate.getDate();
		var month = myDate.getMonth();
		if (mstart == 1) { month = month + 1; }
		var year = myDate.getYear();
		document[frm][elem_d].value = day;
		document[frm][elem_m].value = month;
		document[frm][elem_y].value = year;
	}
}

function presetDate1(frm, elem, mstart, intv) {

		nmonth = parseInt(document.scout.sd_M.value, 10);
		nyear =  parseInt(document.scout.sd_Y.value, 10);
		nday =  parseInt(document.scout.sd_D.value, 10);		
		nmonth = nmonth + 1;
		if (nmonth == 12) {
		 nmonth = 0;
		 nyear = nyear + 1;
		}
		document[frm][elem_d].value = nday;
		document[frm][elem_m].value = nmonth;
		document[frm][elem_y].value = nyear;
}


function roomCheck(frm) {

  if (parseInt(frm.r0.value) == 0) {
    alert("Please enter the Number of Rooms!");
    frm.r0.focus();
    return false;
  }
  return true;
}

function checkDateed(frm) {
  var day = parseInt(frm.ed_D.value, 10);
  var mon = parseInt(frm.ed_M.value, 10);
  var yea = parseInt(frm.ed_Y.value, 10);
  if (!validDate(day, mon, yea)) {
    frm.ed_D.focus();
    alert("Please check the Date you have entered");
    return false;
  }
  return true;
}

function applyDateChange(id) {
  var frm = document.getElementById("hpCritForm");
  var sday = parseInt(frm.sd_D.options[frm.sd_D.selectedIndex].value);
  var smon = parseInt(frm.sd_M.options[frm.sd_M.selectedIndex].value);
  var syea = parseInt(frm.sd_Y.options[frm.sd_Y.selectedIndex].value);
  var sDat = new Date(syea, smon, sday);
  var eday = parseInt(frm.ed_D.value);
  var emon = parseInt(frm.ed_M.value);
  var eyea = parseInt(frm.ed_Y.value);
  var eDat = new Date(eyea, emon, eday);
  var duration = parseInt(frm.d.value);
  var todayDat = new Date();
  if (id == 1) {
	  if (!validDate(sday, smon, syea)) {
	  	alert("Please chose a valid Date.");
		return false;
	  }
	  if (!checkStartDate(frm)) {
	  	return false;
	  }
  }
  if (id == 2) {
	  if (!validDate(eday, emon, eyea)) {
	  	alert("Please chose a valid Date.");
  		return false;
	  }
  }
  var one_day=1000*60*60*24
  var daysDiff = Math.ceil((eDat.getTime()-(sDat.getTime()+duration*one_day))/(one_day));
  if (daysDiff  <= 0) {
	if (id==1 || id==3) {
		var newEDat = new Date();
		newEDat.setTime(sDat.getTime()+(duration+1)*one_day);
		setNewDateValue(frm, id, newEDat);
	}
	if (id==2) {
		var newSDat = new Date();
		newSDat.setTime(eDat.getTime()-(duration+1)*one_day);
		if (newSDat>=todayDat) {
			setNewDateValue(frm, id, newSDat);
		}

	}
  }
  return true;
}
var disableMenu = false;
function checkDateRange(frm) {
  var sday = parseInt(frm.sd_D.options[frm.sd_D.selectedIndex].value);
  var smon = frm.sd_M.options[frm.sd_M.selectedIndex].value;
  var syea = parseInt(frm.sd_Y.options[frm.sd_Y.selectedIndex].value);
  var eday = parseInt(frm.ed_D.value);
  var emon = frm.ed_M.value;
  var eyea = parseInt(frm.ed_Y.value);
  if (!compareDate(sday, smon, syea, eday, emon, eyea, 0)) {
    frm.ed_D.focus();
    alert("End date cannot be earlier than initial date");
    return false;
  }
  return true;
}

function delCheckSubInterest(startIdx, endIdx) {
	while (startIdx < endIdx) {
	  if (document.getElementsByName('subint') != null && document.getElementsByName('subint')[startIdx] != null) {
			document.getElementsByName('subint')[startIdx].checked = false;
  		document.getElementsByName('subint')[startIdx].disabled = false;
  	}
		startIdx++;
	}
}

function checkSingleAge(entry) {
 num = parseInt(entry.value);
 if (isNaN(num) || num<1) {
   alert("Please specify Age of Child(ren)");
   entry.focus();
   entry.select();
   return false;
 }
 return true;
}

  function checkMinChar(entry) {
	 if (entry.value.length < 2) {
	 	alert("Your entry must contain at least 2 characters");
	 	entry.focus();
	 	return false;
	 }
	 return true;
  }

function changedStartDate() {
  applyDateChange(1);
  presetDate1('scout', 'ed', 0, 14);
}

        
var visibleMenuBody = null;


function evlHideVisibleMenuBody(event) {
  var toElem = event.toElement;
  while((toElem!=null)&&(toElem.className!="mhead")&&(toElem.className!="mbody")) {
    toElem = toElem.parentNode;
  }
  if(toElem!=null) {
    event.cancelBubble = true;
    return false;
  }
  if(visibleMenuBody!=null) {
    visibleMenuBody.style.display = "none";
    fnUnHighlightMenuHead(visibleMenuBody.parentNode);
  }
}

function showMenuBody(event) {
  if(!document.all) {
    return false;
  }
  if(disableMenu) {
    return false;
  }
  if(visibleMenuBody!=null) {
    visibleMenuBody.style.display = "none";
    fnUnHighlightMenuHead(visibleMenuBody.parentNode);
  }
  var currentTarget = event.srcElement;
  while(currentTarget.className!="mhead") {
    currentTarget = currentTarget.parentNode;
  }
  currentTarget.attachEvent("onmouseout", evlHideVisibleMenuBody);
  var menuBody = currentTarget.firstChild.nextSibling;
  while((menuBody!=null) && (menuBody.className!="mbody")) {
    menuBody = menuBody.nextSibling;
  }
  if(menuBody!=null) {
    if(menuBody.getAttribute("done")==null) {
      menuBody.setAttribute("done", "true");
      menuBody.attachEvent("onmouseover", evlCancelEvent);
      menuBody.attachEvent("onmouseout", evlHideVisibleMenuBody);
      var entries = menuBody.childNodes;
      var i=0;
      for(i=0;i<entries.length;i++) {
        var menuEntry = entries[i];
        if(menuEntry.tagName=="A") {
          menuEntry.attachEvent("onmouseover", evlHighlightMenuEntry);
          menuEntry.attachEvent("onmouseout", evlUnHighlightMenuEntry);
          setMenuEntryStyles(currentTarget, menuEntry);
        }
      }
    }

    visibleMenuBody = menuBody;
    menuBody.style.display = "block";
    var boundingBox = currentTarget.getBoundingClientRect();
    menuBody.style.left = (boundingBox.left-2) + document.body.scrollLeft + "px";
    menuBody.style.top = (boundingBox.bottom-2) + document.body.scrollTop + "px";
  }
  fnHighlightMenuHead(currentTarget);
  return true;
}

function setMenuEntryStyles(menuHead, menuEntry) {
  var ebs = findAttribute(menuHead, "ebs");
  var ebc = findAttribute(menuHead, "ebc");
  var ebw = findAttribute(menuHead, "ebw");
  var ep = findAttribute(menuHead, "ep");
  var ebgcol = findAttribute(menuHead, "ebgcol");
  var ecol = findAttribute(menuHead, "ecol");
  var etd = findAttribute(menuHead, "etd");
  menuEntry.style.textDecoration = etd;
  menuEntry.style.backgroundColor = ebgcol;
  menuEntry.style.color = ecol;
  menuEntry.style.whiteSpace = "nowrap";
  //menuEntry.style.width = "100%";
  menuEntry.style.width = "129px";
  menuEntry.style.borderStyle = "none";
  menuEntry.style.borderBottomStyle = ebs;
  menuEntry.style.borderBottomColor = ebc;
  menuEntry.style.borderBottomWidth = ebw;
  menuEntry.style.padding = ep;
}

function setHighlightedMenuEntryStyles(menuHead, menuEntry) {
  var ebs = findAttribute(menuHead, "hebs");
  var ebc = findAttribute(menuHead, "hebc");
  var ebw = findAttribute(menuHead, "hebw");
  var ep = findAttribute(menuHead, "hep");
  var ebgcol = findAttribute(menuHead, "hebgcol");
  var ecol = findAttribute(menuHead, "hecol");
  var etd = findAttribute(menuHead, "hetd");
  menuEntry.style.textDecoration = etd;
  menuEntry.style.backgroundColor = ebgcol;
  menuEntry.style.color = ecol;
  menuEntry.style.whiteSpace = "nowrap";
  //menuEntry.style.width = "100%";
  menuEntry.style.width = "129px";
  menuEntry.style.borderStyle = "none";
  menuEntry.style.borderBottomStyle = ebs;
  menuEntry.style.borderBottomColor = ebc;
  menuEntry.style.borderBottomWidth = ebw;
  menuEntry.style.padding = ep;
}


function findAttribute(menuHead, attributeName) {
  var att = menuHead.getAttribute(attributeName);
  if(att==null) {
    att = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute(attributeName);
  }
  return att;
}

function evlCancelEvent(event) {
  event.cancelBubble = true;
}

function fnHighlightMenuHead(menuHead) {
  var bgcol = menuHead.getAttribute("hhbgcol");
  if(bgcol==null) {
    bgcol = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hhbgcol");
  }
  var col = menuHead.getAttribute("hhcol");
  if(col==null) {
    col = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hhcol");
  }
  var firstChild = menuHead.firstChild;
  menuHead.style.backgroundColor = bgcol;
  menuHead.style.color = col;
  if(firstChild.style) {
    firstChild.style.color = col;
    firstChild.style.backgroundColor = bgcol;
  }
}

function evlUnHighlightMenuHeader(event) {
  if(!document.all) {
    return false;
  }
  if(disableMenu) {
    return false;
  }

/*
  if(event.srcElement.className!="mhead") {
    return false;
  }
*/
  var firstChild = event.srcElement.firstChild;
  var menuBody = null;
  if(firstChild!=null) {
    menuBody = firstChild.nextSibling;
  }
  if(menuBody!=null) {
    while((menuBody!=null) && (menuBody.className!="mbody")) {
      menuBody = menuBody.nextSibling;
    }
    if(menuBody!=null) {
      if(menuBody.style.display=="none") {
        fnUnHighlightMenuHead(event.srcElement);
      }
    } else {
      //fnUnHighlightMenuHead(event.srcElement.parentNode);
    }
  } else {
    if(event.srcElement.className!="mhead") {
      fnUnHighlightMenuHead(event.srcElement.parentNode);
    }
  }
  return true;
}

var rc = 0;

function fnUnHighlightMenuHead(menuHead) {
  var bgcol = menuHead.getAttribute("hbgcol");
  if(bgcol==null) {
    if(menuHead.getAttribute("tmpl")==null) {
      return;
    }
    if(document.getElementById(menuHead.getAttribute("tmpl"))==null) {
      return;
    }
    bgcol = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hbgcol");
  }
  var col = menuHead.getAttribute("hcol");
  if(col==null) {
    col = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hcol");
  }
  var firstChild = menuHead.firstChild;
  menuHead.style.backgroundColor = bgcol;
  menuHead.style.color = col;
  if(firstChild.style) {
    firstChild.style.color = col;
    firstChild.style.backgroundColor = bgcol;
  }
}

function evlHighlightMenuEntry(event) {
  var currentTarget = event.srcElement;
  /*
  while(currentTarget.tagName!="DIV") {
    currentTarget = currentTarget.parentNode;
  }
  */
  var menuHead = currentTarget.parentNode.parentNode;
  setHighlightedMenuEntryStyles(menuHead, currentTarget);
  event.cancelBubble = true;
}

function evlUnHighlightMenuEntry(event) {
  var currentTarget = event.srcElement;
  var menuHead = currentTarget.parentNode.parentNode;
  setMenuEntryStyles(menuHead, currentTarget);
  event.cancelBubble = true;

  var toElem = event.toElement;
  while((toElem!=null)&&(toElem.className!="mhead")&&(toElem.className!="mbody")) {
    toElem = toElem.parentNode;
  }
  if(toElem==null) {
    evlHideVisibleMenuBody(event);
  }
}

      
            function checkEmptySearchString(inputnavsearch) {
              if(inputnavsearch.value == "Suchbegriff") {
                alert("Enter your Search");
                return false;
              } else {
                return true;
              }
            }
          
function validDate(day, mon, year)   {
  mon = mon + "";
  year = year + "";
  mon = mon.toUpperCase();
  if ((day < 1)  || (day > 31))  { return 0;  }
  if ((year < 0)  || (year > 9999) || (year == "NaN") || (year == "---")) { return 0;  }
  if ((mon != "0") && (mon != "1") && (mon != "2") && (mon != "3") && (mon != "4") && (mon != "5") && (mon != "6") && (mon != "7") && (mon != "8") && (mon != "9") && (mon != "10") && (mon != "11"))  { return 0; }  if ((mon== "0") || (mon== "2") || (mon== "4") || (mon== "6") || (mon== "7") || (mon== "9") || (mon== "11")) { return 1;
  } else {
    if ((mon== "3") || (mon== "5") ||   (mon== "8") || (mon== "10")) {
      if (day <= 30)  {   return 1; }    }
    else {
      if (mon == "1")   {
        if (((year % 4) == 0) && ((year % 100) != 0))  {
          if (day <= 29) {  return 1;  }
        }
        if ((year % 400) == 0) {
          if (day <= 29)   {  return 1;    }
        }
        if (day <= 28) {  return 1;    }
      } else {
        return 0;
      }
    }
  }
  return 0;
}

function checkStartDate(frm) {
  var day = parseInt(frm.sd_D.options[frm.sd_D.selectedIndex].value);
  var mon = frm.sd_M.options[frm.sd_M.selectedIndex].value;
  var yea = parseInt(frm.sd_Y.options[frm.sd_Y.selectedIndex].value);
  var daynow = parseInt(frm.sd_DN.value);
  var monthnow = parseInt(frm.sd_MN.value);
  var yearnow = parseInt(frm.sd_YN.value);
  if (!compareDate(daynow, monthnow, yearnow, day, mon, yea, 1)) {
    frm.sd_D.focus();
    alert("Check In Date cannot be earlier than today");
    return false;
  }
  return true;
}
function doCheckFormscout(frm) {
if(!checkMinChar(frm.rls)) { return false; }
if(!checkDatesd(frm)) { return false; }
if(!checkStartDate(frm)) { return false; }
if(!checkDateed(frm)) { return false; }
if(!checkDateRange(frm)) { return false; }
if(!checkDuration(frm.d)) { return false; }
if(!checkNumber(frm.d)) { return false; }
if(!checkValueRange(frm.d, "-999999.0", "999999.0", "true")) { return false; }
if(!checkText(frm.r0)) { return false; }
if(!checkNumber(frm.r0)) { return false; }
if(!checkValueRange(frm.r0, "-999999.0", "999999.0", "false")) { return false; }
if(!checkText(frm.a0)) { return false; }
if(!checkNumber(frm.a0)) { return false; }
if(!checkValueRange(frm.a0, "-999999.0", "999999.0", "false")) { return false; }
if(!checkText(frm.c0)) { return false; }
if(!checkNumber(frm.c0)) { return false; }
if(!checkValueRange(frm.c0, "-999999.0", "999999.0", "false")) { return false; }
if(!checkNumber(frm.y00)) { return false; }
if(!checkValueRange(frm.y00, "-999999.0", "999999.0", "true")) { return false; }
if(!checkNumber(frm.y01)) { return false; }
if(!checkValueRange(frm.y01, "-999999.0", "999999.0", "true")) { return false; }
if(!checkNumber(frm.y02)) { return false; }
if(!checkValueRange(frm.y02, "-999999.0", "999999.0", "true")) { return false; }
if(!checkNumber(frm.y03)) { return false; }
if(!checkValueRange(frm.y03, "-999999.0", "999999.0", "true")) { return false; }
if(!checkChildAge(frm)) { return false; }
if(!roomCheck(frm)) { return false; }

return true;
}

function changedEndDate() {
  applyDateChange(2);
}

function setNewDateValue(frm, id, newDate) {
	var yearnow = parseInt(frm.sd_YN.value);
	var newDay = newDate.getDate();
	var newMon = newDate.getMonth();
	var newYear = newDate.getYear();
	if (newYear < 1000) { newYear+=1900; }

	if (id==1 || id==3) {
		frm.ed_D.selectedIndex = newDay-1;
		frm.ed_M.selectedIndex = newMon;
		frm.ed_Y.selectedIndex = newYear - yearnow
	}
	if (id==2) {
		frm.sd_D.selectedIndex = newDay-1;
		frm.sd_M.selectedIndex = newMon;
		frm.sd_Y.selectedIndex = newYear - yearnow
	}
}

function compareDate(dayf, monthf, yearf, dayt, montht, yeart, equal) {
  if (parseInt(yeart) < parseInt(yearf)) {  return 0; }
  if (parseInt(yeart) > parseInt(yearf)) {  return 1; }
  if (parseInt(montht) < parseInt(monthf)) {  return 0; }
  if (parseInt(montht) > parseInt(monthf)) { return 1; }
  if (equal)   {
    if (parseInt(dayt) < parseInt(dayf))   {  return 0; }
	} else {
		if (parseInt(dayt) <= parseInt(dayf))   {  return 0; }
  }
  return 1;
}
function convertLocaleSpecificNumberToFloat(val) {
  var tempVal = ""; 
  for (var i=0;i<val.length;i++)   {      
   letter=val.substring(i,i+1);          
   if (letter != ".") {
     if (letter == ",") {
       tempVal = tempVal + "."; 
     } else {
       tempVal = tempVal + letter; 
     }
    }
  }
  return tempVal*1;
}

function setBlur(frm) {
  var idx0 = parseInt(frm.c0.value);
  while (idx0<=4) {
    if (idx0==0) {
      frm.y00.value='';
    } else if (idx0==1) {
      frm.y01.value='';
    } else if (idx0==2) {
      frm.y02.value='';
    } else if (idx0==3) {
      frm.y03.value='';
    }
    idx0++;
  }
}


function replaceSpaceWithNbsp(strText) {
  if (strText == null) {
    return null;
  }
  var strBefore;
  var strAfter = strText;
  do {
    strBefore = strAfter;
    strAfter = strBefore.replace(" ", "&nbsp;");
  } while (strBefore != strAfter);
  return strAfter;
}
function doCheckFormsearchCMP(frm) {
if(!checkEmptySearchString(frm.scope)) { return false; }

return true;
}

function checkDuration(entry) {
  var dur = parseInt(entry.value);
  if (dur > 50) {
    alert("Length of Stay may not be more than 50 Days");
    entry.focus();
    return false;
  }
  return true;
}

function checkMainInterest(index) {
  document.getElementsByName('hpint')[index].checked = true;
}

function openCalendar(reqUrl) {
  window.open(reqUrl, "calendarWindow", "menubar=no,toolbar=no,width=305,height=340,screenX=400,screenY=400,resizable=no").focus();
}
function checkNumber(entry) {
  var val = entry.value + "";         
  var maxDecimalPlaces; 
  if (entry.form[entry.name+"_decimalPlaces"] == null) { 
    maxDecimalPlaces = 0; 
  } else { 
    maxDecimalPlaces = parseInt(eval(entry.form[entry.name+"_decimalPlaces"].value));
  }
  var newVal = ""; 
  var decimalPoint=false;
  var decimalPlaces=0;
  var thousandFoundIndex = -1;
  var dotFoundIndex = -1;
  var invalidNumber = false;
  if (val.length == 1 && val.substring(0,1) =="-") {      
    invalidNumber = true;
  }
  for (var i=0;i<val.length;i++)   {      
    letter=val.substring(i,i+1);          
    if ( ((letter<"0" || "9"<letter)&&(letter!=",")&&(letter!="-") && (letter!="."))
         || ((letter==",")&&(decimalPoint==true)) ) {
      entry.focus();
      entry.select();
      alert("You must enter Numbers only");
      return false;
    }
    if ((decimalPoint==true)&&(letter!="-")) { decimalPlaces++; }
    if (decimalPlaces>maxDecimalPlaces && letter!="0") {
      entry.focus();
      entry.select();
      alert("Maximum decimal places permitted: " +maxDecimalPlaces);
      return false;
    }
    if ((letter=="-") && i!=0) {
      entry.focus();
      entry.select();
      alert("Invalid Number");
      return false;
    }
    if (letter==",") { decimalPoint=true; }
    if (letter==".") {
      if (dotFoundIndex >= 0) {
        invalidNumber = true;
      } else {
        thousandFoundIndex = i;
      }
    }
    if (letter==",") {
      dotFoundIndex = i;
    }
    if (dotFoundIndex == i && i == (val.length - 1))  {
      invalidNumber = true;
    }
    if (thousandFoundIndex >= 0 && dotFoundIndex == i && ((dotFoundIndex - thousandFoundIndex) != 4))  {
      invalidNumber = true;
    }
    if (thousandFoundIndex >= 0 && dotFoundIndex < 0 && (i == val.length - 1) && (i - thousandFoundIndex != 3 )){
      invalidNumber = true;
    }
    newVal = newVal + letter;
  }
  entry.value = newVal;
  if (invalidNumber) {
    alert("Invalid Number");
    entry.focus();
    entry.select();
    return false;
  }
  return true;
}

function checkValueRange(entry, min, max, empty) {
  if (entry.value.length==0 && empty) { return true; }
  var value=parseFloat(convertLocaleSpecificNumberToFloat(entry.value));
  if (value>parseFloat(max)) {
    alert("Maximum entry permitted: " + max );
    entry.focus();
    return false;
  } else if (value<parseFloat(min)) {
    alert("Minimum entry permitted: " + min );
    entry.focus();
    return false;
  } else {
    return true;
  }
}

function checkChildAge(frm) {
  var i0 = parseInt(frm.c0.value);
  var idx0=1;
  var passedCheck=true;
  while (idx0<=i0) {
    if (idx0==1) {
      passedCheck = checkSingleAge(frm.y00);
    } else if (idx0==2) {
      passedCheck = checkSingleAge(frm.y01);
    } else if (idx0==3) {
      passedCheck = checkSingleAge(frm.y02);
    } else if (idx0==4) {
      passedCheck = checkSingleAge(frm.y03);
    }
    if (!passedCheck) { return false; }
    idx0++;
  }
  return true;
}

function changedDuration() {
  applyDateChange(3);
}
function checkText(entry) {
  var val = entry.value + "";
  val = val.replace(/ */, "");
  if (val.length > 0)  { return true; }
  entry.focus();
  entry.select();
  alert("Required field");
  return false;
}

function checkDatesd(frm) {
  var day = parseInt(frm.sd_D.options[frm.sd_D.selectedIndex].value, 10);
  var mon = parseInt(frm.sd_M.options[frm.sd_M.selectedIndex].value, 10);
  var yea = parseInt(frm.sd_Y.options[frm.sd_Y.selectedIndex].value, 10);
  if (!validDate(day, mon, yea)) {
    frm.sd_D.focus();
    alert("Please check the Date  you have entered");
    return false;
  }
  return true;
}

function doOnLoad() {

var loadingImage = document.getElementById("loadingImg");
if (loadingImage != null) {
  loadingImage.src = "/at/layoutimg/0.gif";
}

  if(navigator.userAgent.indexOf("MSIE 4")!=-1) {
    if(!disableMenu) { disableMenu = true; }
  }
  if(document.all) {
    if(!disableMenu) {
      if(document.attachEvent) {
        document.attachEvent("onclick", evlHideVisibleMenuBody);
      } else {
        disableMenu = true;
      }
    }
  }
      
return true;
}

function doOnUnLoad() {

return true;
}