﻿function insert(prefix,suffix,tld) {
	document.write('<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;:' + prefix + '&#64;' + suffix + '.' + tld + '\">');
	document.write(prefix + '&#64;' + suffix + '.' + tld + '</a>');
}

function _(_id){
	if(document.getElementById && document.getElementById(_id)) return document.getElementById(_id);
	else return null;
}

var email_pattern=/^([A-Za-z0-9\-._]+)@([A-Za-z0-9\-._]+)\.([A-Za-z0-9]{2,3})$/;
var req;
var i;

function check_form(form){
	req=form.getElementsByTagName("*");
	for(i=0;i<req.length;i++){
		if(req[i].lang!="require") continue;
		if( (req[i].name=="arrival" || req[i].name=="departure") && req[i].value=="" ){
			alert("Bitte geben Sie sowohl Anreise- als auch Abreisedatum ein.");
			return false;
		}
		if(req[i].name=="arrival" && !check_date(req[i].value)){
			alert("Das Anreisedatum liegt vor dem heutigen Datum. Bitte korrigieren Sie das Anreisedatum.");
			return false;
		}
		if(req[i].name=="departure" && !check_date(form["arrival"].value, req[i].value)){
			alert("Zwischen Anreise- und Abreisedatum muss mindestens eine Nacht liegen.");
			return false;
		}
		if(req[i].value=="" || req[i].value==req[i].def_value){
			alert("Bitte überprüfen Sie Ihre Eingabe.");
			req[i].focus(); 
			return false;
		}
		if(req[i].name=="email" && !email_pattern.test(req[i].value)){
			alert("Bitte geben Sie eine gültige E-Mail Adresse ein.");
			req[i].focus(); 
			return false;
		}
	}
	return true;
}

function check_date(date1, date2){
	if(!date1) return false;
	var now=(new Date).getTime();
	var d1=getTimestamp(date1);
	if(now>d1) return false; //is in the past
	if(date2 && d1+24*60*60*1000>getTimestamp(date2)) return false; //one day before departure day
	return true;
}

function getTimestamp(date){ //transform date to integer ( 01.01.2012 => 15394232)
	if(!/\d{2}\.\d{2}\.\d{4}/.test(date)) return 0;
	var day=Number(date.substr(0,2));
	var mon=Number(date.substr(3,2))-1;
	var year=Number(date.substr(6,4));
	var now=(new Date);
	var date=new Date(year,mon,day,now.getHours(),now.getMinutes(),now.getSeconds());
	return date.getTime()+60*60*1000;
}

var so;
function load_flash(name){
	so = new SWFObject("imgs/"+name+".swf", "mymovie", "591", "446", "7", "#fff");
	//so.addParam("wmode", "opaque");
	so.useExpressInstall("js/expressinstall.swf");
	var version = deconcept.SWFObjectUtil.getPlayerVersion();
	if(version["major"] < 8) so.setAttribute('doExpressInstall', true);
	so.write('start_flash');
}

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 += '- Ein '+nm+' ist erforderlich.\n'; }
  } if (errors) alert('Bitte vervollständigen Sie Ihre Angaben:\n\n'+errors);
  document.MM_returnValue = (errors == '');
}


var BuchungsFenster = null;
function go() {
     if ( BuchungsFenster == null ) {
             BuchungsFenster = window.open("", "Buchungsanfrage", "toolbar=no,width=750,height=550,directories=no,status=yes,scrollbars=yes,resize=yes,menubar=no" );
     } else {
             if ( BuchungsFenster.closed )
                     BuchungsFenster = window.open("", "Buchungsanfrage", "toolbar=no,width=750,height=550,directories=no,status=yes,scrollbars=yes,resize=yes,menubar=no" );
             else
                     BuchungsFenster.focus();
     }

document.bkrequest.target="Buchungsanfrage";
document.bkrequest.action="http://www.hoteldaten.com/koop-apis/wdba/dorequest.php";
document.bkrequest.submit();                                                                           
}