var UserObject = {
  Browser: {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
  },
  BrowserFeatures: {
    XPath: !!document.evaluate,
    ElementExtensions: !!window.HTMLElement,
    SpecificElementExtensions:
      (document.createElement('div').__proto__ !==
       document.createElement('form').__proto__)
  }
}
UserObject.Browser.IE6=UserObject.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
UserObject.Browser.IE7=UserObject.Browser.IE && !UserObject.Browser.IE6;

//@todo: add hash-table
var detail_tabs = Array();
var act_tab = 0;
function register_content_tabs() {

	args = register_content_tabs.arguments;
	act_tab = args[0];
	for(i=0;i<args.length;i++) {
		var tab = args[i];
		if($(tab)) {
			detail_tabs[i] = tab;
			if(tab != act_tab) {
				$('link_' + tab).className = "tabboxtab"; //protoype
				$(tab).style.display = "none"; //protoype
			}
		}
	}
}
function show_content_tab(id) {

	if(id != act_tab) {
		var queue = Effect.Queue;
		queue.each(function(e) { e.cancel() });
		for(i=0;i<detail_tabs.length;i++) {
			feld = detail_tabs[i];
			$('link_' + feld).className = "tabboxtab";//protoype
			$(feld).style.display = "none";//protoype
		}
		$('link_' + id).className = "tabboxtabAktiv";//protoype
		$(id).style.display = "block";//protoype
		//new Effect.toggle(id, 'appear', {duration:0.5});
		act_tab = id;
	}
}

// //sf// muß anders gelöst werden
//var detail_pics = 1;
//var act_pic = 0;
//function set_detail_pics(anzahl) {
//	detail_pics = anzahl;
//	for(i=1; i<=anzahl;i++) {
//		$('link_Pic' + i).className = "";
//		$('Pic' + i).style.display = "none";
//	}
//	$('link_Pic1').className = "PicAktiv";
//	$('Pic1').style.display = "block";
//	act_pic = 1;
//}
//function switch_pic(id) {
//	if(id != act_pic) {
//		var queue = Effect.Queue;
//		queue.each(function(e) { e.cancel() });
//		for(i=1; i<=detail_pics;i++) {
//			$('link_Pic' + i).className = "";
//			$('Pic' + i).style.display = "none";
//		}
//		$('link_Pic' + id).className = "PicAktiv";
//		$('Pic' + id).style.display = 'block';
//		//new Effect.toggle('Pic' + id, 'appear', {duration:0.2});
//		act_pic = id;
//	}
//}
//



function deleteOptions(elementId) {
	while(document.getElementById(elementId).options.length > 0) {
		document.getElementById(elementId).options[0] = null;
	}
}
function addOption(elementId, txt, val) {
	var objOption = new Option(txt, val);
	document.getElementById(elementId).options.add(objOption);
}





/**************************************************************************************************************
*	Extended Date-Picker
*	last modified: 2008-02-17 (hk)
*
*************************************************************************************************************/
var DatePickerExtended = Class.create(DatePicker, {
						_departure_date_list: new Hash(),
						_departure_date_object: new Hash(),
						initialize: function ( $super, h_p ) { 
												$super(h_p); 
												if (!Object.isUndefined(h_p["departure_date_list"])) {
													this._departure_date_list	= h_p["departure_date_list"];
												}
												if (!Object.isUndefined(h_p["departure_date_object"])) {
													this._departure_date_object	= h_p["departure_date_object"];
												}
						}
 } );
																		
													//
DatePickerExtended.addMethods({


myBindCellOnClick	: function ( td, wcompare, compareresult, myMode ) {
	var doBind	= false;
	if ( wcompare ) {
		if ( compareresult ) {
			doBind	= true;
		} else {
			if (myMode>9) {
				td.className = 'nclick_outbound';
			} else if (myMode>4) {
				td.className = 'bookedout';
			} else if (myMode>2) {
				td.className = 'extern';
			} else if (myMode>1) {
				td.className = 'free';
			} else {
				td.className = 'unknown';
			}
		}
	} else {
		doBind	= true;
	}
	if ( doBind ) {
		var _self	= this;
		td.className = 'bookable';
		td.onclick	= function () { 
			$(_self._relative).value = String($(this).readAttribute('id')).replace(_self._relative+'-','').replace(/-/g, _self._df.separator);
			/* if we have a cellCallback defined call it and pass it the cell */
			if (_self._cellCallback)
				_self._cellCallback(this);
				_self.close(); 
		};
	}
},

getLocaleClose	: function () {
	var myLegend = '<hr />';
	myLegend = myLegend+'<div class="legendBookable datePickerLegendBox">&nbsp;X&nbsp;</div>=Buchung&nbsp;möglich &nbsp; ';
	myLegend = myLegend+'<div class="legendFree datePickerLegendBox">&nbsp;X&nbsp;</div>=Frei &nbsp; ';
	myLegend = myLegend+'<div class="legendExtern datePickerLegendBox">&nbsp;X&nbsp;</div>=Buchung&nbsp;möglich&nbsp;aber&nbsp;nicht&nbsp;online &nbsp; ';
	myLegend = myLegend+'<div class="legendBookedout datePickerLegendBox">&nbsp;X&nbsp;</div>=Ausgebucht &nbsp; ';
	myLegend = myLegend+'<div class="legendUnkown datePickerLegendBox">&nbsp;X&nbsp;</div>=Geschlossen &nbsp; ';

	return	myLegend+'<hr />'+this._language_close.get(this._language);
},


_buildCalendar		: function () {
												  var _self	= this;
												  var tbody	= $(this._id_datepicker+'-tbody');
												  try {
												   while ( tbody.hasChildNodes() )
													tbody.removeChild(tbody.childNodes[0]);
												  } catch ( e ) {};
												  /* generate day headers */
												  var trDay	= new Element('tr');
												  this._language_day.get(this._language).each( function ( item ) {
												   var td	= new Element('td');
												   td.innerHTML	= item;
												   td.className	= 'wday';
												   trDay.appendChild( td );
												  });
												  tbody.appendChild( trDay );
												  /* generate the content of days */
												  
												  /* build-up days matrix */
												  var a_d	= [ [ 0, 0, 0, 0, 0, 0, 0 ] ,[ 0, 0, 0, 0, 0, 0, 0 ]
												   ,[ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0 ]
												   ,[ 0, 0, 0, 0, 0, 0, 0 ]
												  ];
												  /* set date at beginning of month to display */
												  var d		= new Date(this._current_year, this._current_mon, 1, 12);
												  /* start the day list on monday */
												  var startIndex	= ( !d.getDay() ) ? 6 : d.getDay() - 1;
												  var nbDaysInMonth	= this._getMonthDays(
													this._current_year, this._current_mon);
												  var daysIndex		= 1;
												  for ( var j = startIndex; j < 7; j++ ) {
												   a_d[0][j]	= { 
													 d : daysIndex
													,m : this._current_mon
													,y : this._current_year 
												   };
												   daysIndex++;
												  }
												  var a_prevMY	= this._prevMonthYear();
												  var nbDaysInMonthPrev	= this._getMonthDays(a_prevMY[1], a_prevMY[0]);
												  for ( var j = 0; j < startIndex; j++ ) {
												   a_d[0][j]	= { 
													 d : Number(nbDaysInMonthPrev - startIndex + j + 1) 
													,m : Number(a_prevMY[0])
													,y : a_prevMY[1]
													,c : 'outbound'
												   };
												  }
												  var switchNextMonth	= false;
												  var currentMonth	= this._current_mon;
												  var currentYear	= this._current_year;
												  for ( var i = 1; i < 6; i++ ) {
												   for ( var j = 0; j < 7; j++ ) {
													a_d[i][j]	= { 
													  d : daysIndex
													 ,m : currentMonth
													 ,y : currentYear
													 ,c : ( switchNextMonth ) ? 'outbound' : ( 
													  ((daysIndex == this._todayDate.getDate()) &&
														(this._current_mon  == this._todayDate.getMonth()) &&
														(this._current_year == this._todayDate.getFullYear())) ? 'today' : null)
													};
													daysIndex++;
													/* if at the end of the month : reset counter */
													if (daysIndex > nbDaysInMonth ) {
													 daysIndex	= 1;
													 switchNextMonth = true;
													 if (this._current_mon + 1 > 11 ) {
													  currentMonth = 0;
													  currentYear += 1;
													 } else {
													  currentMonth += 1;
													 }
													}
												   }
												  }
												  /* alert ("generate days for current date"); */
												  for ( var i = 0; i < 6; i++ ) {
												   var tr	= new Element('tr');
												   for ( var j = 0; j < 7; j++ ) {
													var h_ij	= a_d[i][j];
													var td	= new Element('td');
													/* id is : datepicker-day-mon-year or depending on language other way */
													/* don't forget to add 1 on month for proper formmatting */
													var id	= $A([
													 this._relative,
													 this._df.date_to_string(h_ij["y"], h_ij["m"]+1, h_ij["d"], '-')
													]).join('-');
													/* set id and classname for cell if exists */
													td.setAttribute('id', id);
													if (h_ij["c"])
													 td.className	= h_ij["c"];
													/* on onclick : rebuild date value from id of current cell */
													var _curDate	= new Date();
													_curDate.setFullYear(h_ij["y"], h_ij["m"], h_ij["d"]);

													/* alert ("curDate="+_curDate+" - todayDate="+this._todayDate); */

													if ( this._disablePastDate || this._disableFutureDate ) {
													 if ( this._disablePastDate ) {
													  var _res	= ( _curDate >= this._todayDate ) ? true : false;
													  this.myBindCellOnClick( td, true, _res, (h_ij["c"] ? 10 : 0) );
													 }
													 if ( this._disableFutureDate ) {
													  var _res	= ( this._todayDate.getTime() + this._oneDayInMs > _curDate.getTime() ) ? true : false;
													  this.myBindCellOnClick( td, true, _res,  (h_ij["c"] ? 10 : 0) );
													 }	 
													} else {														
													 //this.myBindCellOnClick( td, false );
													 //>
													 // check if date is selectable:
													 var tempMonth = h_ij["m"] + 1;
													 var tempDateKey = ((h_ij["d"] < 10) ? "0"+h_ij["d"]:h_ij["d"])+"."+((tempMonth < 10) ? "0"+tempMonth:tempMonth)+"."+h_ij["y"];
													 if(this._departure_date_object['dates'][tempDateKey]==1 ) {	
														 /* Hier war true gesetzt; return ist dann false! */
														 /* alert ("False: Date:"+tempDateKey+"="+this._departure_date_list[tempDateKey]+" - Object="+this._departure_date_object['dates'][tempDateKey]); */
														this.myBindCellOnClick( td, false, false, this._departure_date_object['dates'][tempDateKey] );
													 } else {
														 /* alert ("True: Date:"+tempDateKey+"="+this._departure_date_list[tempDateKey]+" - Object="+this._departure_date_object['dates'][tempDateKey]); */
														this.myBindCellOnClick( td, true, false,  this._departure_date_object['dates'][tempDateKey] );
													 }
													 //<
													}
													td.innerHTML= h_ij["d"];
													tr.appendChild( td );
												   }
												   tbody.appendChild( tr );
												  }
												  return	tbody;
												 },
					setDepartureDateListData: function(departure_date_list_data) {
						this._departure_date_list = new Hash();
						this._departure_date_list = departure_date_list_data;
					},
					setDepartureDateListObject: function(departure_date_list_object) {
						this._departure_date_object = new Hash();
						this._departure_date_object = departure_date_list_object;
					},
					setDepartureDateDebug: function(test) {
													 alert('test='+test+';');
					}
												 //
											  } );
//



