//Relative Layer Hack (read my book on how much i hate netscape..)
isIE = (document.all ? true : false);
isDOM = (document.getElementById ? true : false);

function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent; }
 return iPos;}

function getDivStyle(divname) {
 var style;
 if (isDOM) { style = document.getElementById(divname).style; }
 else { style = isIE ? document.all[divname].style
                     : document.layers[divname]; } // NS4
 return style;}

function hideElement(divname) {
 getDivStyle(divname).visibility = 'hidden';}

function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;}

function toggleVisible(divname) {
 var divstyle = getDivStyle(divname);
 if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
   divstyle.visibility = 'hidden'; } else {
   fixPosition(divname);
   divstyle.visibility = 'visible'; }

 var allstyles = ['prof','arra','lag','cat','camping','hotel','charter','fewo'];
   for (var i in allstyles) {
    if(document.getElementById(allstyles[i]) == null) continue;
    if(allstyles[i] != divname) {
      divstyle = getDivStyle(allstyles[i]);
      divstyle.visibility = 'hidden';
    }
  }

}

function setPosition(elt,positionername,isPlacedUnder) {
 var positioner;
 if (isIE) {  positioner = document.all[positionername]; } else {
  if (isDOM) {    positioner = document.getElementById(positionername);  } else {
    positioner = document.images[positionername];  }
 }
 elt.left = getAbsX(positioner);
 elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
}


// fixPosition() attaches the element named eltname
// to an image named eltname+'Pos'
//
function fixPosition(divname) {
 divstyle = getDivStyle(divname);
 positionerImgName = divname + 'Pos';
 // hint: try setting isPlacedUnder to false
 isPlacedUnder = true;
 if (isPlacedUnder) {
  setPosition(divstyle,positionerImgName,true);
 } else {
  setPosition(divstyle,positionerImgName)
 }
}

// fixPositions() puts everything back in the right place after a resize.
function fixPositions()
{
 // add a fixPosition call here for every element
 // you think might get stranded in a resize/reflow.
 fixPosition('kal');
}

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// will work below 255 only
function ByteToHex(i) {
  return charToHex(i >> 4) +
         charToHex(i % 16);
}
function charToHex(i) {
  if   (i<10) { return String.fromCharCode(48+i); }
  else { return String.fromCharCode(55+i); }
}

function SubmitSQLSearch() {
  var from = document.forms['search'].from.value;
  var to   = document.forms['search'].to.value;
  var today= document.forms['search'].today.value;

  from = from.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  to   = to.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  today= today.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");

  if (new Date(from).valueOf() >= new Date(to).valueOf()) {
    alert ('Das Abreisedatum muß nach dem Anreisedatum liegen.');
    return false;
  }
  if (new Date(from).valueOf() < new Date(today).valueOf()) {
    alert ('Das Anreisedatum muß heute oder danach liegen.');
    return false;
	}

	// calculate profiling info
	var decode = 'abcdefghijklmnopqrstuvwxyz012345';
	var profile = '';
	for (var i in document.forms['search']) {
	  if (i.indexOf('pro_') == 0 && document.forms['search'][i].checked) {
	    profile += i.substring(4,i.length)+'a';
	  }
  }

  // copy current values to submit form (in order to prevent unused field submitting)
  document.forms['sub']['from'].value = document.forms['search']['from'].value;
  document.forms['sub']['to'  ].value = document.forms['search']['to'  ].value;
  document.forms['sub']['pro' ].value = profile;
	document.forms['sub'].submit();
}

function SubmitSearch() {
  var from = document.forms['search'].from.value;
  var to   = document.forms['search'].to.value;
  var today= document.forms['search'].today.value;

  from = from.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  to   = to.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  today= today.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");

  if (new Date(from).valueOf() >= new Date(to).valueOf()) {
    alert ('Das Abreisedatum muß nach dem Anreisedatum liegen.');
    return false;
  }
  if (new Date(from).valueOf() < new Date(today).valueOf()) {
    alert ('Das Anreisedatum muß heute oder danach liegen.');
    return false;
	}

	// calculate profiling info
	var decode = 'abcdefghijklmnopqrstuvwxyz012345';
	var profile = '';
	for (var i=0; i<100;i++) {
	  if (typeof (document.forms['search']['pro_'+i]) != 'undefined' &&
	      document.forms['search']['pro_'+i].checked) {
	    profile += ByteToHex(i);
	  }
  }

  // copy current values to submit form (in order to prevent unused field submitting)
  document.forms['sub']['from'].value = document.forms['search']['from'].value;
  document.forms['sub']['to'  ].value = document.forms['search']['to'  ].value;
  document.forms['sub']['pro' ].value = profile;
	document.forms['sub'].submit();
}

function SubmitSQLSearch() {
  var from = document.forms['search'].from.value;
  var to   = document.forms['search'].to.value;
  var today= document.forms['search'].today.value;

  from = from.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  to   = to.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");
  today= today.replace(/(\d*)\.(\d*)\.(\d*)/,"$2/$1/$3");

  if (new Date(from).valueOf() >= new Date(to).valueOf()) {
    alert ('Das Abreisedatum muß nach dem Anreisedatum liegen.');
    return false;
  }
  if (new Date(from).valueOf() < new Date(today).valueOf()) {
    alert ('Das Anreisedatum muß heute oder danach liegen.');
    return false;
	}

	// calculate profiling info
	var decode = 'abcdefghijklmnopqrstuvwxyz012345';
	var profile = '';
	for (var i in document.forms['search']) {
	  if (i.indexOf('pro_') == 0 && document.forms['search'][i].checked) {
	    profile += i.substring(4,i.length)+'a';
	  }
  }

  // copy current values to submit form (in order to prevent unused field submitting)
  document.forms['sub']['from'].value = document.forms['search']['from'].value;
  document.forms['sub']['to'  ].value = document.forms['search']['to'  ].value;
  document.forms['sub']['pro' ].value = profile;
	document.forms['sub'].submit();
}

/*****************************************************************************
 * ValidAddress
 * checks if given email has correct format
 *
 * address    email to check
 *
 * returns false on error
 ****************************************************************************/

function ValidAddress(address) {
  var expr=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  return expr.test(address);
}

/*****************************************************************************
 * SubmitBooking
 * checks input variables in search form and if they are ok continues to
 * result page
 *
 * no parameters
 *
 * returns false on error
 ****************************************************************************/

var bookurl='';
var submitted=0;
function SubmitBooking() {
  if (submitted) return;

  // check if current object was already booked
  if (bookurl!= '') {
    location = bookurl;
    return false;
  }
  // check if all fields are filled
  var fields = ['personen','vorname','nachname','strasse','land','plz',
                'ort','telefon','email'];
  var names  = ['Personen','Vorname','Nachname','Straße','Land','PLZ',
                'Ort','Telefon','eMail'];
  for (var i=0;i<fields.length;i++) {
    if (document.forms['book'][fields[i]].value=='') {
      alert ('Die Eingabe von "'+names[i]+'" ist erforderlich.');
      document.forms['book'][fields[i]].focus();
      return false;
    }
  }

  // check valid eMail format
  if (!ValidAddress(document.forms['book'].email.value)) {
    alert ('Bitte geben sie eine vollständige eMail Adresse ein');
    document.forms['book']['email'].focus();
    return false;
  }

  // check AGB
  if (!document.forms['book'].agb.checked) {
    alert ('Sie müssen bestätigen, daß Sie die Bedingungen gelesen und akzeptiert haben.');
    return false;
  }

  // disable submit button and ..
  /* for (var i=0; i<document.links.length; i++) {
  if (document.links[i].href.indexOf('#submit') > -1) {
	document.links[i].href = 'javascript:alert(\'Bitte warten Sie kurz, Ihre Anfrage wird bearbeitet.\');';
	document.links[i].onclick = '';
	}}
  */

  // submit if everything is ok
  submitted=1;
  document.forms['book'].submit();
}



