var jtk = new JoookToolkit();

jtk.addEvent(window, "load", function(){
	try{
		var printLinkWrappers = jtk.select("#printLink");
		if(printLinkWrappers.length > 0 && printLinkWrappers[0] != null){
			var linkEmt = jtk.select("a", printLinkWrappers[0])[0];
			linkEmt.target = "_blank";
		}
	}
	catch(e){}
});


function openPrintView(url){
	window.open(url);
	return false;
}

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 toggleClass(emtIds, classes){
	for(var i = 0; i < emtIds.length; i++){
		var emt = jtk.select('#' + emtIds[i])[0];
		var emtClasses = emt.className.split(" ");
		for(var j = 0; j < emtClasses.length; j++){
			if(emtClasses[j] == classes[0]){
				jtk.replaceClass(emt, classes[0], classes[1]);
				break;
			}
			else if(emtClasses[j] == classes[1]){
				jtk.replaceClass(emt, classes[1], classes[0]);
				break;
			}
		}
	}
}


var tabLayout = null;

function buildTabs(){
	var tabWrapperId = "info_tabarea";
	if(jtk.select("#" + tabWrapperId).length > 0){
		tabLayout = new TabLayout();
		tabLayout.bindTab("col_head_a", "col_content_a");
		tabLayout.bindTab("col_head_b", "col_content_b");
		tabLayout.bindTab("col_head_c", "col_content_c");
		tabLayout.init();
	}
}
