<!--
//
// Scripts zum Buchen
//

var RCode=new Array();
/*
= new Array(
  "",	 			 	 		 // calling URL
	"",							 // Options
	"", 						 //calling vendor
	"OFB", 					 // Reiseart
	"HAM",					 // Zielgebiet
	"13",						 // Zielort
	"26",						 // Zielhotel
	"",							 // Leistungsart
	"",  		   			 // ReiseDatum
	"" 				 			 // ReiseEndeDatum
);
*/
RCode.ANF="";
RCode.Reiseart="";
RCode.Zielgebiet="";
RCode.Zielort="";
RCode.Zielhotel="";
RCode.Vendor = "";


var day,month,year;

// Init
var today="050801";

if (self.opener) {
  today=self.opener.GetToday8(); //Datum heute YYMMDD
}
	
year=new Number(today.substring(0,2));
year+=2000;
month=new Number(today.substring(2,4));
day=new Number(today.substring(4,6));


function GetRCode() {
  return RCode;
}

function CreateDatePage(hWin) {
  hWin.location="/buchen/date.htm";
}

function getEndDate6(stDate,Days) {
  var begin= new Date("20"+stDate.substring(0,2), stDate.substring(2,4)-1, stDate.substring(4,6));
	var n=new Number(Math.round(begin) )+Days*24*60*60*1000;
	var end= new Date(n);
	var stYear=""+end.getFullYear();
	stYear=stYear.substring(2,4);
	var stMonth=end.getMonth()+1;
	stMonth=""+stMonth;
	if (stMonth.length<2)
	  stMonth="0"+stMonth;
	var stDate=""+end.getDate();
	if (stDate.length<2)
	  stDate="0"+stDate;
	return stYear+stMonth+stDate;
}

function AccessRemote(hWin,DateBegin) {

  var hWin=window.open("", "buchen",  "width=800,height=600,toolbar=0,directories=no,status=no,resizable=no,scrollbars=yes");
  var hDoc=hWin.document;
  OpenPage(hDoc);
	hDoc.write("Verbindungsaufbau... bitte warten...<br>");
	hDoc.write("<p></p>");
	ClosePage(hDoc);

	var DateEnd=getEndDate6(DateBegin,56);
	
  var RCode=System.RCode;
	
  var remoteURL=RemoteBuchenApp;
	remoteURL+="?"+"WSYD_EVENT=EVBCH&";
  if (top.opener && top.opener.GetOptions) {
    remoteURL+="OPTIONS="+top.opener.GetOptions()+"&";
	}
	//remoteURL+="VENDOR="+CallData[2]+"&";
	remoteURL+="VENDOR="+RCode.Vendor+"&";
	remoteURL+="REIART="+RCode.Reiseart+"&";
	remoteURL+="GEBIET="+RCode.Zielgebiet+"&";
	remoteURL+="ZORT="+RCode.Zielort+"&";
	remoteURL+="ZHOTEL="+RCode.Zielhotel+"&";
	remoteURL+="LEISAR="+RCode.ANF+"&";
  remoteURL+="REIDAT="+DateBegin+"&";
  remoteURL+="REIEND="+DateEnd+"&";		

  hWin.location=remoteURL;

}

function RemoteBuchen(hWindow,RCode) {
  var fAdmin=false;
	
  if (top.opener && top.opener.GetUser) {
	  if (top.opener.GetUser()=="TEST") {
		  fBuchenDisabled=false;
		}
		if (top.opener.GetUser()=="ADMIN") {
		  fAdmin=true;
		  fBuchenDisabled=false;
		}
		
	}

  if (fBuchenDisabled) {
	  alert("Die Online-Buchung steht zur Zeit nicht zur Verfügung!\n"+
		      "Bitte versuchen Sie es später noch einmal!\n\n"+
					"Vielen Dank für ihr Verständnis!");
	  return;
	}

	
	System.RCode=RCode;
	if (!RCode.ANF ||
	    RCode.ANF=="" ||
	    RCode.Reiseart=="" ||
			RCode.Zielgebiet=="" ||
			RCode.Zielort=="" 
//			|| RCode.Zielhotel==""
	    ) {
	  if (!confirm("unvollständiger Zugriffscode\n"+
		      "ANF:       "+RCode.ANF+"\n"+
		      "Reiseart:  "+RCode.Reiseart+"\n"+
					"Zielgebiet:"+RCode.Zielgebiet+"\n"+
					"Zielort:   "+RCode.Zielort+"\n"+
					"Zielhotel: "+RCode.Zielhotel+"\n"+
					
					"möchten Sie fortfahren"))
			return;
	}

  //var hWin=window.open("", "",  "width=800,height=600,toolbar=0,directories=no,status=no,resizable=no,scrollbars=yes");
  
  //hWin.creator = self;
	
//	if (fAdmin) {
	  //CreateDatePage(hWin);
//	  return;
//	}
	
//  AccessRemote(hWin,GetToday8());	
	
}

function Buchen(hWindow, anf, gebiet, ort, hotel, reiseart, vendor) {
  	var RCode=new Array();
	RCode.ANF=anf;
  	RCode.Zielgebiet=gebiet;
  	RCode.Zielort=ort;
  	RCode.Zielhotel=hotel;
	RCode.Reiseart=reiseart;
   RCode.Vendor = vendor;
   
  	RemoteBuchen(hWindow,RCode);
}


function getSelectedDate(calID,x,y) {
  var c=Calendar[calID];
	var month=c.Month;
	var year=c.Year;
	var begin_day = new Date (year,month,1);
  begin_day_date = begin_day.getDay();
	if (begin_day_date!=0)
	   begin_day_date-=1;
	else
	   begin_day_date=6;
  var end_day = new Date (year,month+1,1);
  var count_day = (end_day - begin_day)/1000/60/60/24+0.5;
  if (count_day>31)
	   count_day=31;
	var daycount=new Number(y)*7+new Number(x)+1;
	var day=daycount-begin_day_date;
	if (day<1)
	  return -1;
	if (day>count_day)
	  return -1;
	//alert(begin_day_date+" " + count_day + " " + daycount);
	month++;
	if (day<10)
	  day="0"+day;
	if (month<10)
	  month="0"+month;
	return year+""+month+""+day;
}

function onDateSelected(calID,x,y) {
  var sel=getSelectedDate(calID,x,y);
	if (sel==-1) {
	  alert("Bitte wählen Sie ein gültiges Datum!");
		return;
	}
  if (self && self.AccessRemote) {
	  self.AccessRemote(self,sel.substring(2,8));	  
	}
	else
    	alert(sel.substring(2,8));
}

function rueckgabe(seldate) {  
	/* Folgende zeilen wieder rausnehemen wenn die buchung funktioniert !!*
		Johannes joh: 11.07.08 */
		/*
		alert('Die Onlinebuchung ist zur Zeit leider nicht verfügbar!\r\n'+
			  'Bitte wenden sie sich bei einem Buchungswunsch\r\n'+
			  'an die zentrale Telefonnummer: (0)2302-2000-0');
		return; */
	/*****/

  if (self && self.AccessRemote) {
	  self.AccessRemote(self, seldate);	  
	}
	else
    alert(seldate);
}


function Weiter() {

  day=document.DATEBEGIN.DAY.value;
	if (day<10)
	  day="0"+day;
  month=document.DATEBEGIN.MONTH.value;
	if (month<10)
	  month="0"+month;
	year=document.DATEBEGIN.YEAR.value;
	year=new Number(year.substring(2,4));
	if (year<10)
	  year="0"+year;
  DateBegin=year+""+month+""+day;
  if (self.opener && self.opener.AccessRemote) {
	  self.opener.AccessRemote(self,DateBegin);
		
	}
}

function InitPage() {
}
//-->

