// JavaScript Document
function checkNewsletterInput(obj, type) {
	if(type == 'focus'){
		if(obj.value == 'Vul uw e-mail adres hier in')
			obj.value = '';
	}
	else if(type == 'blur') {
		if(obj.value == '')
			obj.value = 'Vul uw e-mail adres hier in';
	}
}


function checkInput(inputfield,initvalue,comparevalue){
	if(comparevalue){
		if(inputfield.value == ''){
			if(comparevalue != 'Wachtwoord') inputfield.value = comparevalue;
		}
	}
	else{
		if(inputfield.value == 'Wachtwoord'){
			inputfield.value = '';
			replaceT(inputfield);
		}
		else if(inputfield.value == initvalue){
			inputfield.value = '';
		}
	}
}






var HotelFinder = Class.create({
	initialize: function(type) {
		this.strAjaxUrl = '/includes/ajax/hotelfinder.php';
		switch (type) {
			case 'business': 
				this.loadCities('business');
				break;
			case 'party': 
				this.loadCities('party');
				break;
			default: 
				this.loadCountries();
				this.loadStates();
				this.loadRegions();
				this.loadCities();
		}		
	},
	loadCountries: function() {
		new Ajax.Updater('country-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'countries'},
			evalScripts:'true'
		});
		new Ajax.Updater('hotel-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'hotels'},
			evalScripts:'true'
		});
	},
	loadStates: function() {
		new Ajax.Updater('state-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'states', country: $F('country-list')},
			evalScripts:'true'
		});
		new Ajax.Updater('region-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'regions', country: $F('country-list')},
			evalScripts:'true'
		});
		new Ajax.Updater('hotel-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'hotels', country: $F('country-list')},
			evalScripts:'true'
		});
	},
	loadRegions: function() {
		new Ajax.Updater('region-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'regions', country: $F('country-list'), state: $F('state-list')},
			evalScripts:'true'
		});
		new Ajax.Updater('hotel-list', this.strAjaxUrl, {
			method:'post',
			parameters: {action: 'hotels', country: $F('country-list'), state: $F('state-list')},
			evalScripts:'true'
		});
	},
	loadCities: function(type) {
		switch (type) {
			case 'business': 
				new Ajax.Updater('city-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'cities_business'},
					evalScripts:'true'
				});
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels_business'},
					evalScripts:'true'
				});
				new Ajax.Updater('facilities-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'business_facilities'},
					evalScripts:'true'
				});
				break;
			case 'party': 
				new Ajax.Updater('city-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'cities_party'},
					evalScripts:'true'
				});
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels_party'},
					evalScripts:'true'
				});
				new Ajax.Updater('facilities-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'party_facilities'},
					evalScripts:'true'
				});
				break;
			default: 
				new Ajax.Updater('city-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'cities', country: $F('country-list'), state: $F('state-list'), region: $F('region-list')},
					evalScripts:'true'
				});
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels', country: $F('country-list'), state: $F('state-list'), region: $F('region-list')},
					evalScripts:'true'
				});
		}		


	},
	loadHotels: function(type) {
		switch (type) {
			case 'business': 
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels_business', city: $F('city-list')},
					evalScripts:'true'
				});
				break;
			case 'party': 
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels_party', city: $F('city-list')},
					evalScripts:'true'
				});
				break;
			default: 
				new Ajax.Updater('hotel-list', this.strAjaxUrl, {
					method:'post',
					parameters: {action: 'hotels', city: $F('city-list')},
					evalScripts:'true'
				});
		}		
	}
});

var Shop = Class.create({
	initialize: function() {
		this.updateCart();
	},
	addToCart: function(intId) {
		new Ajax.Request('/includes/ajax/cart_add.php', {
			method: 'post',
			parameters: {id: intId, quantity: $F('quantity_'+intId)},
			onSuccess: function(transport){
				var response = transport.responseText;
				if(response != "") {
					//$("pollholder").update(response);
					Shop.updateCart();
				}
			},
			onFailure: function(){
				$('shoppingcartcontent').update('error loading cart');
			}
		});
	},
	addChequeToCart: function() {
		if($F('freechoice') != '') {
			strVars = 'freechoice|'+$F('freechoice')+'|0';
		}
		else {
			var form = $('chequeFrm');
			arrCheckboxes = form.getInputs('checkbox');
			for(x=0; x < arrCheckboxes.length; x++)  {
				if($(arrCheckboxes[x]).checked == true) {
					strVars = $F(arrCheckboxes[x]);
					//alert(strVars);
					break;
				}
			}
			
		}
		
		if($F('cheque_name') == 'Uw naam (optioneel)') strName = '';
		else strName = $F('cheque_name');
		
		if($F('cheque_message') == 'Uw boodschap (maximaal 200 karakters)') strMsg = '';
		else strMsg = $F('cheque_message');
		
		//arrTest = $('inn_1').value;
		new Ajax.Request('/includes/ajax/cart_add_cheque.php', {
			method: 'post',
			parameters: {vars: strVars, name: strName, msg: strMsg},
			onSuccess: function(transport){
				var response = transport.responseText;
				if(response != "") {
					//$("pollholder").update(response);
					Shop.updateCart();
					for(x=0; x < arrCheckboxes.length; x++) $(arrCheckboxes[x]).checked = false;
					$('cheque_name').clear();
					$('cheque_message').clear();
				}
			},
			onFailure: function(){
				$('shoppingcartcontent').update('error loading cart');
			}
		});
	},
	removeFromCart: function(intId) {
		new Ajax.Request('/includes/ajax/cart_remove.php', {
			method: 'post',
			parameters: {id: intId},
			onSuccess: function(transport){
				var response = transport.responseText;
				if(response != "") {
					//$("pollholder").update(response);
					Shop.updateCart();
				}
			},
			onFailure: function(){
				$('shoppingcartcontent').update('error loading cart');
			}
		});
	},
	checkACheque: function(activeCheck) {
		var form = $('chequeFrm');
		arrCheckboxes = form.getInputs('checkbox');
		for(x=0; x < arrCheckboxes.length; x++)  {
			$(arrCheckboxes[x]).checked = false;
		}
		activeCheck.checked = true;
	},
	freechoice: function() {
		if($F('freechoice') != '') {
			var form = $('chequeFrm');
			arrCheckboxes = form.getInputs('checkbox');
			for(x=0; x < arrCheckboxes.length; x++)  {
				$(arrCheckboxes[x]).checked = false;
			}
		}
	},
	updateCart: function() {
		new Ajax.Updater('shoppingcartcontent', '/includes/ajax/cart.php', {
			method:'post',
			parameters: {}
		});
	}
});
