/*  +---------------------------------------------------------------------------+  | Europa-Feriendorf (frontend)									  		  |  +---------------------------------------------------------------------------+  | Filename: feriendorf.js											 	 	  |  | Version: 1.0.5															  |  | Created: 18-12-2003											  	  		  |  | Revised: 8-2-2005											  			  |  +---------------------------------------------------------------------------+  | Copyright (c) 2003-2005: Code 9 Media (http://www.code9.nl)				  |  +---------------------------------------------------------------------------+  | This software is protected by copyright law and international treaties.	  |  | Unauthorized modification, reproduction or distribution of this software, |  | or any portion of it, may result in severe civil and criminal penalties,  |  | and will be prosecuted to the maximum extent possible under the law.	  |  +---------------------------------------------------------------------------+*/   /**   	* {{{ Opens a new window   	*   	* @access	private   	* @param	string	*/	function Ef_Window ( filename )	{		var winleft = 0;		var wintop = 0;		if ( screen.width ) {			winleft = ( screen.width - 450 ) / 2;			wintop = ( screen.height - 525 ) / 2;			if ( winleft < 0 ) winleft = 0;			if ( wintop < 0 ) wintop = 0;		}		var features =			'toolbar=no,location=no,directories=no,status=no,menubar=no,' + 			'scrollbars=no,resizable=no,width=450,height=525,top=' +			wintop + ',left=' + winleft;		var openwin = window.open(filename, "Fototour", features);		( openwin.opener == null ) ? openwin.opener = window : openwin.focus();	}   /** end of function }}} */   /**   	* {{{ Sets the values of the search form   	*   	* @access	public	*/	function Ef_InitSearch ( )	{		var theform = document.forms['frm_search'];		var index = theform.smonth.selectedIndex;		var sdate = theform.smonth.options[index].value.split(/#/);		index = theform.sday.selectedIndex;		var sday = theform.sday.options[index].value;		if ( sday.length == 1 ) {			sday = '0' + sday;		}		if ( sdate[0].length == 1 ) {			sdate[0] = '0' + sdate[0];		}		var params = '?sdate=' + sdate[1] + sdate[0] + sday;		index = theform.emonth.selectedIndex;		var edate = theform.emonth.options[index].value.split(/#/);		index = theform.eday.selectedIndex;		var eday = theform.eday.options[index].value;		if ( eday.length == 1 ) {			eday = '0' + eday;		}		if ( edate[0].length == 1 ) {			edate[0] = '0' + edate[0];		}		params += '&edate=' + edate[1] + edate[0] + eday;		params += '&persons=' + theform.persons.value;		params += '&start=' + theform.start.value;		document.location.href = theform.action + params;	}   /** end of function }}} */	function Ef_BrowseResults ( )	{		var theform = document.forms['frm_browse_search'];		var params = '?sdate=' + theform.sdate.value;		params += '&edate=' + theform.edate.value;		params += '&persons=' + theform.persons.value;		var index = theform.page.selectedIndex;		var start = theform.page.options[index].value;		params += '&start=' + start;		document.location.href = theform.action + params;	}   /** end of function }}} */	function Ef_ReturnToResults ( )	{		var theform = document.forms['frm_return_search'];		var params = '?sdate=' + theform.sdate.value;		params += '&edate=' + theform.edate.value;		params += '&persons=' + theform.persons.value;		params += '&start=' + theform.start.value;		document.location.href = theform.action + params;	}   /** end of function }}} */   /**   	* {{{ Sets the form's destination and submits it!   	*   	* @access	public   	* @param	string	*/	function Ef_SubmitForm ( action )	{		var theform = document.forms['frm_input'];		theform.action = action;		theform.submit();	}   /** end of function }}} */	function Ef_ReturnToCabin ( Id )	{		var theform = document.forms['frm_input'];		var params = '?cmd=detail&id=' + Id + '&abort=true';		document.location.href = theform.action + params;	}   /** end of function }}} */   /**    * {{{ Retrieves the currently selected date in a proper format    *    * @access	private    * @params	object, object    * @return	array    */	function Ef_GetDate ( sel_day, sel_month )	{		var ay_date = new Array();		var index = sel_month.selectedIndex;		ay_date = sel_month.options[index].value.split(/#/);		index = sel_day.selectedIndex;		ay_date.push(sel_day.options[index].value);		for ( index in ay_date ) {			ay_date[index] = parseInt(ay_date[index]);		}		return ay_date;	}   /** end of function }}} */   /**    * {{{ Calculates the number of days in the given month    *    * @access	private    * @params	int, int    * @return	int    */	function Ef_GetNumDaysInMonth ( year, month )	{    	var date_cur  = new Date(year, month, 1).getTime();    	var date_next = new Date(year, month + 1, 1).getTime();		var temp = date_next - date_cur - 3600000; /** one hour */		return Math.ceil(temp / 86400000); /** one day */	}   /** end of function }}} */   /**    * {{{ Validates the given date and sets a correct date in case of failure    *    * @access	private    * @params	bool, array, object, object    * @return	array    */	function Ef_SetDate ( reset, ay_date, sel_day, sel_month )	{		var size = sel_month.options.length;		var nextselect = sel_month.selectedIndex + 1;		var date = new Date(ay_date[1], ay_date[0] - 1, ay_date[2]);		var temp = date.getDate();		if ( reset ) {			sel_day.selectedIndex = temp - 1;			ay_date[2] = temp;		} else if ( temp != ay_date[2] ) {			var daystr = '1,2,3,4';			if (( daystr.indexOf(temp) != -1 ) && ( nextselect == size )) {				temp = Ef_GetNumDaysInMonth(ay_date[1], ay_date[0]);			}			sel_day.selectedIndex = temp - 1;			ay_date[2] = temp;		}		temp = date.getMonth() + 1;		if ( reset ) {			var selected = size - 1;			var monthstr = temp + '#' + ay_date[1];			for ( var index = 0; index < size; ++index ) {				var value = sel_month.options[index].value;				if ( value == monthstr ) {					selected = index;					break;				}			}			sel_month.selectedIndex = selected;			ay_date[0] = temp;		} else if ( temp != ay_date[0] ) {			var selected = ( nextselect < size ) ? nextselect : size - 1;			sel_month.selectedIndex = selected;			ay_date[0] = temp;		}		return ay_date; /** possibly changed */	}   /** end of function }}} */   /**    * {{{ Adjusts the dates on selection (leap years, can't select 31th April, etc.)    *    * @access	public    * @params	bool, bool    */	function Ef_AdjustDates ( from_changed, is_search )	{		var theform = ( is_search )			? document.forms['frm_search']			: document.forms['frm_input'];		if ( from_changed )	{			var ay_from = Ef_GetDate(theform.sday, theform.smonth);			ay_from = Ef_SetDate(false, ay_from, theform.sday, theform.smonth);			var ay_to = Ef_GetDate(theform.eday, theform.emonth);			if ((( ay_to[2] <= ay_from[2] ) && ( ay_to[0] <= ay_from[0] )			  && ( ay_to[1] <= ay_from[1] ))			  || (( ay_to[0] < ay_from[0] ) && ( ay_to[1] <= ay_from[1] ))			  || ( ay_to[1] < ay_from[1] )) {				ay_to = ay_from;				Ef_SetDate(true, ay_to, theform.eday, theform.emonth);			}		} else {			var ay_to = Ef_GetDate(theform.eday, theform.emonth);			ay_to = Ef_SetDate(false, ay_to, theform.eday, theform.emonth);			var ay_from = Ef_GetDate(theform.sday, theform.smonth);			if ((( ay_from[2] >= ay_to[2] ) && ( ay_from[0] >= ay_to[0] )			  && ( ay_from[1] >= ay_to[1] ))			  || (( ay_from[0] > ay_to[0] ) && ( ay_from[1] >= ay_to[1] ))			  || ( ay_from[1] > ay_to[1] )) {				ay_from = ay_to;				//--ay_from[2];				Ef_SetDate(true, ay_from, theform.sday, theform.smonth);			}		}	}   /** end of function }}} */	function Ef_Stripe ( )	{		var evenColor = '#fff';		var oddColor = '#ff3';		var size = arguments.length;		for ( var index = 0; index < size; ++index ) {			var even = false;			var table = document.getElementById(arguments[index]);		    if ( !table ) {		    	continue; /** mmm, try the rest */		    }			var tbodies = table.getElementsByTagName('tbody');			var isize = tbodies.length;			for ( var i = 0; i < isize; ++i ) {				var trs = tbodies[i].getElementsByTagName('tr');				var jsize = trs.length;				for ( var j = 0; j < jsize; ++j ) {					if ( trs[j].style.backgroundColor ) {						continue;					}					var tds = trs[j].getElementsByTagName('td');					var hsize = tds.length;					for ( var h = 0; h < hsize; ++h ) {						var mytd = tds[h];						if ( mytd.style.backgroundColor ) {							continue;						}						mytd.style.backgroundColor = even ? evenColor : oddColor;					}					even = !even;				}			}		}	}   /** end of function }}} */  // this function is need to work around   // a bug in IE related to element attributes  function hasClass(obj) {     var result = false;     if (obj.getAttributeNode("class") != null) {         result = obj.getAttributeNode("class").value;     }     return result;  }    function stripe ( ) {    // the flag we'll use to keep track of     // whether the current row is odd or even    var even = false;      // if arguments are provided to specify the colours    // of the even & odd rows, then use the them;    // otherwise use the following defaults:    //var evenColor = arguments[1] ? arguments[1] : "#fff";    //var oddColor = arguments[2] ? arguments[2] : "#ff3"; 	var evenColor = "#fff"; 	var oddColor = "#ff3";    // obtain a reference to the desired table    // if no such table exists, abort    var table = document.getElementById('formtable');    if (! table) {    	table = document.getElementById('formtablelist');    	if ( !table ) {    		table = document.getElementById('kernlist');    		if ( !table ) {    			return;    		}    	}    }        // by definition, tables can have more than one tbody    // element, so we'll have to get the list of child    // &lt;tbody&gt;s     var tbodies = table.getElementsByTagName("tbody");    // and iterate through them...    for (var h = 0; h < tbodies.length; h++) {         // find all the &lt;tr&gt; elements...       var trs = tbodies[h].getElementsByTagName("tr");            // ... and iterate through them      for (var i = 0; i < trs.length; i++) {	    // avoid rows that have a class attribute        // or backgroundColor style	    //if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {	    if (!trs[i].style.backgroundColor) {          // get all the cells in this row...          var tds = trs[i].getElementsByTagName("td");                  // and iterate through them...          for (var j = 0; j < tds.length; j++) {                    var mytd = tds[j];            // avoid cells that have a class attribute            // or backgroundColor style	        //if (! hasClass(mytd) && ! mytd.style.backgroundColor) {	        if (!mytd.style.backgroundColor) {        		      mytd.style.backgroundColor = even ? evenColor : oddColor;                          }          }        }        // flip from odd to even, or vice-versa        even =  ! even;      }    }  }	function Ef_EnlargePhoto ( src )	{		var image = document.getElementById('enlarged');		if ( !image ) {			return;		}		image.src = src;	}   /** end of function }}} */   /**   	* {{{ Opens the print window   	*   	* @access	public   	* @param	int	*/	function Ef_PrintBooking ( id )	{		var winleft = 0;		var wintop = 0;		if ( screen.width ) {			winleft = ( screen.width - 650 ) / 2;			wintop = ( screen.height - 500 ) / 2;			if ( winleft < 0 ) winleft = 0;			if ( wintop < 0 ) wintop = 0;		}		var features =			'toolbar=no,location=no,directories=no,status=no,menubar=yes,' + 			'scrollbars=yes,resizable=yes' +			',width=' + 650 + ',height=' + 500 + ',top=' + wintop +			',left=' + winleft;		var page = document.forms['frm_input'].action + '?cmd=print&id=' + id;		var openwin = window.open(page, "Printen", features);		( openwin.opener == null ) ? openwin.opener = window : openwin.focus();	}   /** end of function }}} */	function GetRandom ( page )	{		var randimg = document.getElementById('randimg');		if ( !randimg ) {			return;		}		randimg.src = page + '/images/rotate/rotate.php?id=' + new Date().getTime();		setTimeout("GetRandom('" + page + "')", 5000);	}   /** end of function }}} */
