/**********************************************
 * CONECTO Business Communication GmbH        *
 * Project: Hotel Stadt Wien                  *
 **********************************************/

parseQueryString = function(str) {
	// Build an empty URL structure in which we will store
	// the individual query values by key.
	var objURL = {};

	// Use the String::replace method to iterate over each
	// name-value pair in the query string. Location.search
	// gives us the query string (if it exists).
	str.replace(
		new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
		// For each matched query string pair, add that
		// pair to the URL struct using the pre-equals
		// value as the key.
		function( $0, $1, $2, $3 ){
			objURL[ $1 ] = $3;
		}
	);
	return objURL;
};


jQuery(function( $ ){
	
	$('#mainNavList li:first-child').css('border-left', 'none');
	$('#mainNavList li:last-child').css('border-right', 'none');
	
	$('div#nuggetContainerStartseite .nuggetEntry:first-child').css('margin-left', '0px');
	
	
	
	var sidebarHeight = $('div#sidebar').height() + 170;
	var contentHeight = $('div#content').height();
	if( sidebarHeight > contentHeight ) {
		$('div#content').height(sidebarHeight+'px'); 
	}
	else { 
		//$('div#sidebar').height(contentHeight-10+'px'); 
		$('div#sidebar').height((contentHeight-10) +'px'); 
	}
		
	
	
	//Datumsfelder für Anfrage
	var queryString = parseQueryString(window.location.search);
	if(queryString["quickFrom"])	
		$("#anfrageFormFromDate, #quickFrom").val(queryString["quickFrom"]);	
						
	if(queryString["quickTo"]) 
		$("#anfrageFormToDate, #quickTo").val(queryString["quickTo"]);

});
 

function toggleAnz(fieldElem, toggleId) {	
	var toggleElem = document.getElementById(toggleId);
	//var fieldElem = document.getElementById(fieldId);
	
	if( fieldElem.checked ) {
		toggleElem.disabled = false;
		toggleElem.focus();
	}
	else {
		toggleElem.value = 0;
		toggleElem.disabled = true;
		//toggleElem.focus();
	}

	return true;
}

 
function mkDefDate(addDays) {
	addDays = addDays||false;
	
	today = new Date();
	year = today.getFullYear();
	month = today.getMonth()+1;
	day = today.getDate();
	dayOfWeek = today.getDay();

	if( addDays ) {
		newDay = day+addDays;
		newDate = new Date( year, month-1, newDay );
	
		newDay = newDate.getDate();
		newMonth = newDate.getMonth()+1;
		newYear = newDate.getFullYear();

		return newDay+'.'+newMonth+'.'+newYear;
	}
	else {
		return day+'.'+month+'.'+year;
	}
}

function getURLParam(srch, strParamName){
  var strReturn = "";
  var strHref = srch;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
};

Anfrage = {
	lang: 'de',
	
	labels: {
		children: {
			name: function(){
				return Anfrage.lang == 'de' ? 'Vorname' : 'First name'
			},
			age: function() {
				return Anfrage.lang == 'de' ? 'Geb. Dat.' : 'birth date'
			}
		},
		adults: {
			name: function(){
				return Anfrage.lang == 'de' ? 'Vorname Nachname' : 'Firstname Lastname'
			},
			age: function() {
				return Anfrage.lang == 'de' ? 'Geb. Dat.' : 'birth date'
			}
		}
	},
	
	setBegleitpersonen: function(anz) {
		/*
		var container = document.getElementById("begleitpersonen");
		if(anz > 0) {
			container.style.display = "block";
		} else {
			container.style.display = "none";
		}
		*/
		var container = document.getElementById("begleitpersonen");
		var tblContainer = document.getElementById("begleitpersonentable");

		var tableSrc = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>';	  	

		if(anz > 0) {
			container.style.display = "block";	
					
			var nameLabel = Anfrage.labels.adults.name();
			var ageLabel = Anfrage.labels.adults.age();
			var reqLabelName = Anfrage.lang == 'de' ? 'Bitte geben Sie einen Namen an!' : 'Please specify a name!';
			var reqLabelGebdat = Anfrage.lang == 'de' ? 'Bitte geben Sie das Geburtsdatum an!' : 'Please specify the date of birth!';
			
			for (var i = 1; i <= anz; i++) {
				tableSrc += '<tr>\
					<td width="55%" valign="top"><input onfocus="if(this.value == Anfrage.labels.adults.name())this.value=\'\'" name="tx_pilmailform_pi1[text][name_begleitperson_'+ i +']" type="text" class="formFieldAnfrage" style="" id="tx_pilmailform_pi1[text][name_begleitperson_'+ i +']" title="'+ nameLabel + ' ' + i +'" value="'+ nameLabel +'" /></td>\
					<td width="20%" valign="top"><label for="tx_pilmailform_pi1[text][gebdat_begleitperson_'+ i +']">'+ ageLabel +'</label></td>\
					<td width="25%" valign="top"><input onfocus="jQuery(this).unmask();jQuery(this).mask(\'99.99.9999\');" name="tx_pilmailform_pi1[text][gebdat_begleitperson_'+ i +']" type="text" class="formFieldAnfrage" style="width:60px" id="tx_pilmailform_pi1[text][gebdat_begleitperson_'+ i +']" title="'+ ageLabel + ' '+ i +'"  value="" /></td>\
				</tr>';							
			}
		} else {
			container.style.display = "none";
		}
		
		tableSrc += '</tbody></table>';
		tblContainer.innerHTML = tableSrc;
		
		if(frmvalidator != undefined)
			if(anz > 0)
				for (var i = 1; i <= anz; i++) {
					frmvalidator.addValidation('tx_pilmailform_pi1[text][name_begleitperson_' + i + ']', 'req', reqLabelName);
					frmvalidator.addValidation('tx_pilmailform_pi1[text][gebdat_begleitperson_' + i + ']', 'req', reqLabelGebdat);
				}
			else 
				for (var i = 1; i <= 10; i++) {
					frmvalidator.clearValidation('tx_pilmailform_pi1[text][name_begleitperson_' + i + ']');
					frmvalidator.clearValidation('tx_pilmailform_pi1[text][gebdat_begleitperson_' + i + ']');
				}
		
		
			
					
		
		return; 		
	}, 
	setKinder: function(anz) {
		var container = document.getElementById("kinder");
		var tblContainer = document.getElementById("kindertable");

		var tableSrc = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody>';	  	

		if(anz > 0) {
			container.style.display = "block";			

			var nameLabel = Anfrage.labels.children.name();
			var ageLabel = Anfrage.labels.children.age();

//			var reqLabelName = Anfrage.lang == 'de' ? 'Bitte geben Sie einen Namen an!' : 'Please specify a name!';
//			var reqLabelGebdat = Anfrage.lang == 'de' ? 'Bitte geben Sie das Geburtsdatum an!' : 'Please specify the date of birth!';
			
			for (var i = 1; i <= anz; i++) {
				tableSrc += '<tr>\
					<td width="55%" valign="top"><input onfocus="if(this.value == Anfrage.labels.children.name())this.value=\'\'" name="tx_pilmailform_pi1[text][name_kind_'+ i +']" type="text" class="formFieldAnfrage" style="" id="tx_pilmailform_pi1[text][name_kind_'+ i +']" title="'+ nameLabel + ' ' + i +'" value="'+ nameLabel +'" /></td>\
					<td width="20%" valign="top"><label for="tx_pilmailform_pi1[text][gebdat_kind_'+ i +']">'+ ageLabel +'</label></td>\
					<td width="25%" valign="top"><input onfocus="jQuery(this).unmask();jQuery(this).mask(\'99.99.9999\');" name="tx_pilmailform_pi1[text][gebdat_kind_'+ i +']" type="text" class="formFieldAnfrage" style="width:60px" id="tx_pilmailform_pi1[text][gebdat_kind_'+ i +']" title="'+ ageLabel + ' '+ i +'"  value="" /></td>\
				</tr>';
				/*
				if(frmvalidator) {
					frmvalidator.addValidation('tx_pilmailform_pi1[text][name_kind_' + i + ']', 'req', reqLabelName);
					frmvalidator.addValidation('tx_pilmailform_pi1[text][gebdat_kind_' + i + ']', 'req', reqLabelGebdat);
				}*/
			}
		} else {
			container.style.display = "none";
		}
		
		tableSrc += '</tbody></table>';
		tblContainer.innerHTML = tableSrc;
				
		return;
	}
}
