/**
 * dmcSBtabs()
 * RollOver and Active Effects for Searchbox Menu Buttons
 * Set display style to content divs
 * @return void
 **/
function dmcSBtabs(_dmcObj,_dmcOpt){
	/* obj		=>	Object */
	/* opt 'n'	=> normal */
	/* opt 'r'	=> rollover */
	/* opt 'a'	=> active */

	/* Variables */
	var i = 0;

	var _dmcImgPath = '/reisehero_de/250x125/';
	var _dmcObjName = _dmcObj.id + '_' + _dmcOpt;
	var _dmcNewPath = _dmcImgPath + _dmcObj.id + '_' + _dmcOpt + '.gif';

	var _dmcActiveName = _dmcObj.id + '_' + 'a';
	var _dmcActualName = _dmcObj.src.substr(_dmcObj.src.lastIndexOf('.') - _dmcObjName.length,
									(_dmcObj.src.length - _dmcObj.src.lastIndexOf('/')) - (_dmcObj.src.length - _dmcObj.src.lastIndexOf('.') + 1));

	/* if button active, return false */
	if(_dmcActualName==_dmcActiveName) {
		return false;
	} else {

		/* if is click event , then set all other Elements hidden or normal */
		if(_dmcOpt=='a') {
			for(i=1;i<=3;i++) {

				if(_dmcObj.id != document.getElementById('dmc250_tab_' + i).id) {
					document.getElementById('dmc250_tab_' + i).src = _dmcImgPath + document.getElementById('dmc250_tab_' + i).id + '_' + 'n' + '.gif';
					document.getElementById('dmc250_tab_' + i + '-content').style.display = 'none';
				} else {
					document.getElementById('dmc250_tab_' + i + '-content').style.display = '';
				}
			}
		}
//alert(_dmcNewPath);
		/* Set new ImagePath */
		_dmcObj.src = _dmcNewPath;
	}
} /* end: function dmcSBtabs */

/**
* dmcAddOptionsList()
* Generate a list of days or months for a select box
* @param	opt			string		'days' or 'month'
* @param	id			string		ID of HTML Object
* @param	givenMonth	string		Value of selected Month
* @param	provider	string		'lm' for last-minute
* @param	firstCall	boolean		true or false
* @param	addDays		int			Count of Days to add
* @return 	void
**/
function dmcAddOptionsList(_dmcOpt,_dmcId,_dmcGivenMonth,_dmcProvider,_dmcFirstCall,_dmcAddDays){

	/* Switch between days and months */
	switch(_dmcOpt) {

		case 'days':

			/* Counter i for loop */
			var _dmci;

			/* Index of selected Day by changing month */
			var _dmcOldDayIndex			= document.getElementById(_dmcId).selectedIndex;

			/* Date Object */
			var _dmcActualDate 			= new Date();

			/* Actually Month */
			var _dmcActualMonth			= _dmcActualDate.getMonth();

			/* If givenMonth is set, get Month from String */
			if(_dmcGivenMonth) {

				switch(_dmcProvider) {
					case 'lm':
						var _dmcMonthToSet = _dmcGivenMonth.substr(0,2);
						if(_dmcMonthToSet.substr(0,1)=='0') {
							_dmcMonthToSet = _dmcMonthToSet.substr(1,1);
						}
						break;

					default:
						var _dmcMonthToSet = _dmcGivenMonth.substr(_dmcGivenMonth.length-2,_dmcGivenMonth.length);
						if(_dmcMonthToSet.substr(0,1)=='-') {
							_dmcMonthToSet = _dmcMonthToSet.substr(1,1);
						}
						break;
				} /* end: switch */

				_dmcActualDate.setMonth(_dmcMonthToSet-1);
			}

			/* count of days in actual month */
			var _dmcDaysOfActualMonth 	= _dmcActualDate.daysInMonth();

			/* if addDays not defined, set addDays = 0 */
			if(_dmcAddDays <= 0) { _dmcAddDays = 0; }

			/* Day to set selected */
			var _dmcSelectDay = (_dmcActualDate.getDate()+_dmcAddDays);

			if(_dmcDaysOfActualMonth < (_dmcActualDate.getDate()+_dmcAddDays)) {
				_dmcSelectDay = (_dmcActualDate.getDate()+_dmcAddDays)-_dmcDaysOfActualMonth;

				_dmcActualDate.setMonth(_dmcActualMonth+1);
				_dmcDaysOfActualMonth 	= _dmcActualDate.daysInMonth();

				var _dmcSelectNextMonth = true;
			}

			/* Delete all option Tags inside of given id - object */
			document.getElementById(_dmcId).innerHTML = '';

			/* Loop from day 1 to 'daysOfActualMonth' */
			for(_dmci=1; _dmci<=_dmcDaysOfActualMonth; _dmci++) {

				if(_dmcFirstCall==true && _dmcSelectDay == _dmci) {
					dmcMakeOption(_dmcId,_dmci-1,_dmci,_dmci,true);
					if(_dmcSelectNextMonth==true) {
						var _dmcMonthID = _dmcId.substr(0,_dmcId.length-3)+ 'month';
						document.getElementById(_dmcMonthID)[1].selected='selected';
					}
				} else if((_dmci-1) == _dmcOldDayIndex) {
					dmcMakeOption(_dmcId,_dmci-1,_dmci,_dmci,true);
				} else {
					dmcMakeOption(_dmcId,_dmci-1,_dmci,_dmci,false);
				} /* end: if */

			} /* end: for */

			break;

		case 'months':

			/* Counter i for loop */
			var _dmci;

			/* Max-Count j for loop */
			var _dmcj=12;

			/* Date Object DateForMonth */
			var _dmcDateForMonth 	= new Date();

			/* Actually Month actualMonth */
			var _dmcActualMonth 	= _dmcDateForMonth.getMonth();

			/* Counter for makeOptions function */
			var _dmcCount;

			/* 'offset' is needed to calculate 'count' for makeOptions function */
			var _dmcOffset;

			/* Delete all option Tags inside of given id - object */
			document.getElementById(_dmcId).innerHTML = '';

			/*
			Loop from actually month (ex. 2 March) to end (11 December) and
			then begin from 0 (January) to offset (February)

			offset = 2 [0 (January) - 2 (March)]
			*/
			for(_dmci=0; _dmci<_dmcj; _dmci++) {

				/*
				If actualMonth not 0 (January) AND counter i ==
				j-actualMonth (needed Months in actually year), then
				set Year + 1 (next year), offset = i (count of consumed
				months) and reset counter for loop
				*/
				if( _dmcActualMonth > 0 && _dmci == (_dmcj-_dmcActualMonth) ) {

					_dmcDateForMonth.setFullYear(_dmcDateForMonth.getFullYear()+1);

					_dmcOffset = _dmci;
					_dmci = 0;
					_dmcj = _dmcActualMonth;
				}

				/* Set count for makeOptions function */
				_dmcCount = _dmci;

				/* Set month */
				_dmcDateForMonth.setMonth(_dmci+_dmcActualMonth);

				/*
				If Max-Count == actualMonth (next Year), then
				we need to set count WITH offset and Month WITHOUT
				actualMonth (seems to be the same as offset)
				*/
				if(_dmcj == _dmcActualMonth && _dmci < _dmcActualMonth) {
					_dmcCount = _dmci + _dmcOffset;
					_dmcDateForMonth.setMonth(_dmci);
				}

				/* Month for next Option (Part of Value) */
				var _dmcOptMonth 	= _dmcDateForMonth.getMonthName();

				/* Year for next Option (Part of Value) */
				var _dmcOptYear 	= _dmcDateForMonth.getFullYear().toString();

				/* Label for next Option */
				var _dmcOptLabel 	= _dmcOptMonth + ' ' + _dmcOptYear.substr(_dmcOptYear.length-2,_dmcOptYear.length);

				/*
				If provider is set, look for other formatting
				options (Value)
				*/
				switch(_dmcProvider) {
					/* other date formatting for last-minute (lm) */
					case 'lm':
						var _dmcOptValue = (_dmcDateForMonth.getMonth()+1<10) ? '0' : '';
							_dmcOptValue += (_dmcDateForMonth.getMonth()+1) + '.' + _dmcOptYear;
						break;

					/* Default date formatting */
					default:
						var _dmcOptValue = _dmcOptYear + '-' + (_dmcDateForMonth.getMonth()+1);
						break;
				} /* end: switch */

				/* Call makeOption function */
				dmcMakeOption(_dmcId,_dmcCount,_dmcOptLabel,_dmcOptValue);

			} /* end: for */

			break;

		default:
			/* Nothing */
			break;

	} /* end: switch */

} /* end: function dmcAddOptionsList */

/**
 * dmcMakeOption()
 * Generate a new Option Tag
 * @param	id			string		ID of HTML Object
 * @param	count		int			Counter for next option Tag
 * @param	label		string		Label for next option Tag
 * @param	value		string		Value for next option Tag
 * @param	selected	boolean		true or false
 * @return void
 **/
function dmcMakeOption(_dmcId,_dmcCount,_dmcLabel,_dmcValue,_dmcSelected){

	/* Generate new Option */
	var _dmcNewOption = document.getElementById(_dmcId)[_dmcCount] = new Option(_dmcLabel,_dmcValue);

	if(_dmcSelected==true) {
		_dmcNewOption.selected = 'selected';
	} /* end: if */

} /* end: function dmcMakeOption */

/**
 * dmcSetHiddenDate()
 * Fill a hidden Field with Value
 * @param	prefixID	string		prefixID of HTML Object
 * @param	optId1		string		ID of HTML Object
 * @param	optId2		string		ID of HTML Object
 * @param	hiddenF1	string		ID of HTML Object
 * @param	hiddenF2	string		ID of HTML Object
 * @return void
 **/
function dmcSetHiddenDate(_dmcPrefixID,_dmcOptId1,_dmcOptId2,_dmcHiddenF1,_dmcHiddenF2){

	/* Fill hidden Field with formatted Date */
	document.getElementById(_dmcHiddenF1).value = document.getElementById(_dmcPrefixID+_dmcOptId1+'day').value + '.' + document.getElementById(_dmcPrefixID+_dmcOptId1+'month').value;

	/* Fill hidden Field with formatted Date */
	document.getElementById(_dmcHiddenF2).value = document.getElementById(_dmcPrefixID+_dmcOptId2+'day').value + '.' + document.getElementById(_dmcPrefixID+_dmcOptId2+'month').value;

} /* end: function dmcSetHiddenDate */

/**
 * dmcReplaceChars()
 * Replace ö with oe
 * @param	string		string		Text
 * @param	index		int			index
 * @return 	string
 **/
/*function dmcReplaceChars(obj, index){
    var anArray = new Array(2);
    anArray[0] = new Array("\u00D6", "\u00F6", "\u00C4", "\u00E4", "\u00DC", "\u00FC", "\u00DF");
    anArray[1] = new Array("Oe", "oe", "Ae", "ae", "Ue", "ue", "sz");
    
    for (var i=0; i<anArray[index].length; i++){
		myRegExp 	= new RegExp(anArray[index][i],"g");
		obj.value 	= obj.value.replace(myRegExp, anArray[(index==0?1:0)][i]);
	}
}*/
 /* end: function dmcReplaceChars */

/* Extend Date Object with 'days in Month' Function */
Date.prototype.daysInMonth = function () {
   return new Date(this.getFullYear(), this.getMonth()+1, 0).getDate()
} /* end: Prototype daysInMonth */

/* Extend Date Object with 'get Name of Month' Function */
Date.prototype.getMonthName = function() {
   return ['Januar', 'Februar', "MÃ¤rz", 'April', 'Mai', 'Juni', 'Juli', 'August', 'Sept.', 'Okt.', 'Nov.', 'Dez.'][this.getMonth()];
} /* end: Prototype getMonthName */