function IntresBooker(){
	//this.baseAddr = "http://89.166.54.4/scripts/fi/Intres4.dll/OMA_MATKAT?";
	this.baseAddr = "http://e-varaukset.lehtimaenmatkat.fi/scripts/fi/Intres4.dll/OMA_MATKAT?";
	this.type = "AS";
	this.country = "FIN";
	this.adults = 2;
	this.children = 0;
	this.infants = 0;
	this.filter = "EI_RAJAUSTA";
	
	this.operator = "PIILOAGENTTI";
	
	this.winopts = null;
	
	this.openBooker = function(input1, input2, input3){
		var winAddr = null;
		
		if(this.type == "AS"){
			var queryOpts = new Array();
				queryOpts.push("tyyppi=" + this.type);
				queryOpts.push("maa=" + this.country);
				queryOpts.push("Valittu_Aikuisia=" + this.adults);
				queryOpts.push("Valittu_Lapsia=" + this.children);
				queryOpts.push("Valittu_IlmLapsia=" + this.infants);
				if(input1 != null && input2 != null && input3 != null){
					queryOpts.push("CLASS1=" + input1);
					queryOpts.push("CLASS2=" + input2);
					queryOpts.push("CLASS3=" + input3);
				}
				queryOpts.push("Valittu_Rajaus=" + this.filter);
			
			winAddr = this.baseAddr + queryOpts.join("&");
		}
		else if(this.type == "AG"){
			var queryOpts = new Array();
				queryOpts.push("TYYPPI=" + this.type);
				queryOpts.push("MAA=" + this.country);
				
				if(input1 != null && input2 != null && input3 != null){
					queryOpts.push("AGNRO=" + input1);
					queryOpts.push("USERNAME=" + input2);
					queryOpts.push("PASSWORD=" + input3);
				}
				
				queryOpts.push("OPER=" + this.operator);
				queryOpts.push("VALITTU_AIKUISIA=" + this.adults);
			
			winAddr = this.baseAddr + queryOpts.join("&");
		}
		
		if(winAddr != null){
			var winInstance = window.open(winAddr);
			return winInstance;
		}
		else{
			return null;
		}
	}
}

(function($){
	function formatTime(){
		var date = new Date(),
			dateFormatStr = "%D_DAYNAME_SHORT% %D_DATE%.%D_MONTH%. klo %D_HOURS%:%D_MINUTES%",
			dateFormatOptions = {
				locale: 'fi',
				digits: {
					year: 4,
					date: 1,
					month: 1,
					hours: 2,
					minutes: 2,
					seconds: 2
				}
			};
		
		return new DateFormatter(date, dateFormatOptions).getString(dateFormatStr);
	}

	$(document).ready(function(){
		$('#datetime').html(formatTime());
		
		// Duplicate HTML5 placeholder attribute functionality
		$('input[title], textarea[title]').each(function(){
			$(this).val($(this).attr('title'));
			$(this).focus(function(){
				if($(this).val() === $(this).attr('title')){
					$(this).val('');
				}
			});
			
			$(this).blur(function(){
				if($(this).val().replace(/\s/g, '') === ''){
					$(this).val($(this).attr('title'));
				}
			});
		});
		
		$('.public .box_suosituimmat li h3').each(function(){
			if(($(this).text()).length < 3){
				$(this).parents('li:first').hide();
			}
		});
	});
})(jQuery);
