function checkDuration(frm) {
  var dur = parseInt(frm.value);
  if (dur > 50) {
    frm.focus();
    frm.select();
    alert("Bitte Urlaubsdauer < 50 eingeben");
    return false;
  }
  return true;
}

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.options[frm.ed_D.selectedIndex].value);
  var emon = frm.ed_M.options[frm.ed_M.selectedIndex].value;
  var eyea = parseInt(frm.ed_Y.options[frm.ed_Y.selectedIndex].value);
  if (!compareDate(sday, smon, syea, eday, emon, eyea, 1)) {
    frm.ed_D.focus();
    alert("Das angegebene Enddatum liegt vor dem Anreisedatum.");
    return false;
  }
  return true;
}

function checkValueRange(entry, min, max) {
  var value=parseFloat(convertLocaleSpecificNumberToFloat(entry.value));
  if (value>parseFloat(max)) {
    alert("Größte erlaubte Eingabe: " + max );
    entry.focus();
    return false;
  } else if (value<parseFloat(min)) {
    alert("Kleinste erlaubte Eingabe: " + min );
    entry.focus();
    return false;
  } else {
    return true;
  }
}

function setOnChangeDur(frm) {
  if (frm.d.value < 1) {
    frm.d.focus();
    frm.d.select();
    alert("Die Dauer muss größer als 0 sein.");
    return false;
  }
  return true;
}
function checkNumber(entry) {
  var val = entry.value + "";         
  var 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("Bitte nur Zahlen eingeben!");
      return false;
    }
    if ((decimalPoint==true)&&(letter!="-")) { decimalPlaces++; }
    if (decimalPlaces>maxDecimalPlaces && letter!="0") {
      entry.focus();
      entry.select();
      alert("Maximal erlaubte Dezimalstellen: " +maxDecimalPlaces);
      return false;
    }
    if ((letter=="-") && i!=0) {
      entry.focus();
      entry.select();
      alert("Ungültige Zahl");
      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("Ungültige Zahl");
    entry.focus();
    entry.select();
    return false;
  }
  return true;
}

function leapTo(url) {
  this.location.href=url;
}
function checkText(entry) {
  var val = entry.value + "";
  if (val.length > 0)  { return true; }
  entry.focus();
  entry.select();
  alert("Dieses Feld darf nicht leer sein.");
  return false;
}

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.className!="mbody") {
    menuBody = menuBody.nextSibling;
  }
  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 = "125px";
  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 = "125px";
  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 menuBody = event.srcElement.firstChild.nextSibling;
  while(menuBody.className!="mbody") {
    menuBody = menuBody.nextSibling;
  }
  if(menuBody.style.display=="none") {
    fnUnHighlightMenuHead(event.srcElement);
  }
  return true;
}

function fnUnHighlightMenuHead(menuHead) {  
  var bgcol = menuHead.getAttribute("hbgcol");
  if(bgcol==null) {
    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 doCheckFormscout(frm) {
if(!checkDuration(frm.d)) { return false; }
if(!checkNumber(frm.d)) { return false; }
if(!checkValueRange(frm.d, "-999999.0", "999999.0")) { return false; }
if(!checkNumber(frm.r0)) { return false; }
if(!checkValueRange(frm.r0, "-999999.0", "999999.0")) { return false; }
if(!checkNumber(frm.a0)) { return false; }
if(!checkValueRange(frm.a0, "-999999.0", "999999.0")) { return false; }
if(!checkStartDate(frm)) { return false; }
if(!setOnChangeDur(frm)) { return false; }
if(!roomCheck(frm)) { return false; }

return true;
}

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;
}
var disableMenu = false;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;
}
function doCheckFormcurrency(frm) {

return true;
}

function roomCheck(frm) {

  if (parseInt(frm.r0.value) == 0) {
    alert("Geben Sie bitte die Anzahl der Zimmer ein!");
    frm.r0.focus();
    return false;
  }
  return true;
}
function doCheckFormsearchCMP(frm) {

return true;
}

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);
  today = new Date();
  var daynow = today.getDate();
  var monthnow = today.getMonth();
  var yearnow = today.getYear();
  if (!compareDate(daynow, monthnow, yearnow, day, mon, yea, 1)) {
    frm.sd_D.focus();
    alert("Das angegebene Anreisedatum liegt in der Vergangenheit.");
    return false;
  }
  return true;
}

var ads="http://ads.in.adcenter.net";

function aa_banner(w,h,id,orgatag){
	now = new Date();
	var transID = now.getTime();
	document.write('<NOLAYER>');
	document.write('<iframe name="aa_banner" width="'+w+'" vspace="0" hspace="0" marginheight="0" marginwidth="0" sr'+'c="'+ads+'/html.ng/TransactionID='+transID+id+'&'+orgatag+'?" height="'+h+'" frameborder="0" scrolling="no">');
	document.write('<a href="'+ads+'/click.ng/TransactionID='+transID+id+'&'+orgatag+'?" target="_blank"><img sr'+'c="'+ads+'/image.ng/TransactionID='+transID+id+'&'+orgatag+'?" width="'+w+'" height="'+h+'" border="0" alt=""></a>');
	document.write('</iframe>');
	document.write('</NOLAYER>');
	document.write('<ilayer visibility="show" width="'+w+'" height="'+h+'" id="id'+id+'"></ilayer>');
}

function aa_footer(w,h,id,orgatag){
	now = new Date();
	var transID = now.getTime();
	document.write('<layer name="aa_banner" sr'+'c="'+ads+'/html.ng/TransactionID='+transID+id+'&'+orgatag+'" visibility="hide" clip="0,0,'+w+','+h+'" onlo'+'ad="moveToAbsolute(id'+id+'.pageX, id'+id+'.pageY);visibility=\'show\';"></layer>');
	}
  
function doOnLoad() {

  if(navigator.userAgent.indexOf("MSIE 4")!=-1) {
    if(!disableMenu) { disableMenu = true; }
  }
  if(document.all) {
    if(!disableMenu) {
      document.attachEvent("onclick", evlHideVisibleMenuBody);
    }
  }
        
  if(navigator.userAgent.indexOf("MSIE 4")!=-1) {
    if(!disableMenu) { disableMenu = true; }
  }
  if(document.all) {
    if(!disableMenu) {
      document.attachEvent("onclick", evlHideVisibleMenuBody);
    }
  }
        
return true;
}

function doOnUnLoad() {

return true;
}
