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];
		detail_tabs[i] = tab;
		if(tab != act_tab) {
			$('link_' + tab).className = "tabboxtab";
			$(tab).style.display = "none";
		}
	}
}
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";
			$(feld).style.display = "none";
		}
		$('link_' + id).className = "tabboxtabAktiv";
		$(id).style.display = "block";
		//new Effect.toggle(id, 'appear', {duration:0.5});
		act_tab = id;
	}
}

//
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(),
													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"];
																			}
													}
 } );
																		
													//
									DatePickerExtended.addMethods({
										_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;
													     }
													    }
													   }
													  }
													  /* 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"]);
													    if ( this._disablePastDate || this._disableFutureDate ) {
													     if ( this._disablePastDate ) {
													      var _res	= ( _curDate >= this._todayDate ) ? true : false;
													      this._bindCellOnClick( td, true, _res, h_ij["c"] );
													     }
													     if ( this._disableFutureDate ) {
													      var _res	= ( this._todayDate.getTime() + this._oneDayInMs > _curDate.getTime() ) ? true : false;
													      this._bindCellOnClick( td, true, _res,  h_ij["c"] );
													     }	 
													    } else {														
													     //this._bindCellOnClick( 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_list[tempDateKey] ) {	 
															this._bindCellOnClick( td, false );
														 } else {
															this._bindCellOnClick( td, true );
														 }
														 //<
													    }
													    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;
	}
													 //
												  } );
	//


