﻿// JavaScript Document

function updatePrice(lang, id, target, show_image){

	// Initialize variables
	var multiplier = 0; 
	var priceList = new Array();

	// ****************************'
	// EDITOI TASTA ALKAEN
	// ****************************'

	//var basePrice = 97.6; // MUUTA TATA -> INDEKSIKOROTUS KAIKKIIN HINTOIHIN || POISTETTU 12.1.2011
	var basePrice = 100; // MUUTA TATA -> INDEKSIKOROTUS KAIKKIIN HINTOIHIN 97.6 --> 100 12.1.2011

	if(id == "kiiltavainen") {
		// Creates the price rows
		priceList[0]=new Array(new Array("Perushinta", "Base price", "Grund Preise", "Основная цена"), basePrice*3.1, basePrice*6.1);
		priceList[1]=new Array(new Array("23.6. - 17.8.", "23.6. - 17.8.", "23.6. - 17.8.", "В период с 23.6. - 17.8."), basePrice*5.0, basePrice*10.0);
		priceList[2]=new Array(new Array("Juhannus (to-su)", "Midsummer", "Mittsommer", "Иванов День (с четв. по воскр.)"), 0, basePrice*11.2);
		priceList[3]=new Array(new Array("23.-26.12.", "23.-26.12.", "23.-26.12.", "В период с 23.-26.12."), 0, basePrice*6.0);
		priceList[4]=new Array(new Array("29.12. - 5.1.", "29.12. - 5.1.", "29.12. - 5.1.", "В период с 29.12. - 5.1."), 0, basePrice*12.1);		
		priceList[5]=new Array(new Array("P&auml;&auml;si&auml;inen", "Eastern", "Ostern", "Пасха"), 0, basePrice*6.8);

		// Assign multiplier for the house
		multiplier = 1.04;

	} else { // This is for all the other houses apart Kiiltavainen
		// Create the price rows (using basic prices)
		priceList[0]=new Array(new Array("Toukokuu", "May", "Mai", "май"), basePrice*1.0, basePrice*2.0);
		priceList[1]=new Array(new Array("Kes&auml;kuu", "June", "Juni", "Июнь"), basePrice*1.5, basePrice*2.9);
		priceList[2]=new Array(new Array("Juhannus (to-su)", "Midsummer", "Mittsommer", "Иванов День (с четв. по воскр.)"), 0, basePrice*3.63);
		priceList[3]=new Array(new Array("Hein&auml;kuu", "July", "Juli", "Июль"), basePrice*1.9, basePrice*3.7);	
		priceList[4]=new Array(new Array("Elo-syyskuu", "Aug-Sep", "Aug-Sep", "Август-сентябрь"), basePrice*1.5, basePrice*2.9);	
		priceList[5]=new Array(new Array("Lokakuu", "October", "Oktober", "Октябрь"), basePrice*1.0, basePrice*2.0);			

		// Assign separate multipliers for each house
		if(id == "pielppa") { multiplier = 1.47; }
		if(id == "jennyntupa") { multiplier = 1.06; }
		if(id == "hippila") { multiplier = 1.2; }
		if(id == "tivoli") { multiplier = 1.4; }
		if(id == "rentola") { multiplier = 1.5; }		
	}

	// ****************************'
	// EDITOI TAHAN ASTI
	// ****************************'

	// Creates the price table
	var content = getTableInit(show_image);

	// Writes image and column header tags
	content = content + getPreContent(id, lang, show_image);
	content = content + getColumnHeaders(lang);

	// Writes the price rows
	var lang_id = 0;
	if(lang == "en") {
		lang_id = 1;	
	}
	if(lang == "ge") {
		lang_id = 2;	
	}
	if(lang == "ru") {
		lang_id = 3;	
	}

	for(var i = 0; i < priceList.length; i++) {
		if(isEven(i) == true) {
			content = content + "<tr style='background-color:#cde7fd ;'><td>";
		} else {
			content = content + "<tr><td>";			
		}
		content = content + priceList[i][0][lang_id];
		content = content + "</td><td>";
		if(priceList[i][1] != 0) {
			content = content + Math.round(multiplier*priceList[i][1]/10)*10  + "&euro;";
		} else {
			content = content + "-";
		}
		content = content + "</td><td>";
		if(priceList[i][2] != 0) {		
			content = content + Math.round(multiplier*priceList[i][2]/10)*10 + "&euro;";
		} else {
			content = content + "-";
		}
		content = content + "</td></tr>";
	}
	
	// Outputs the content and finishes the table
	document.getElementById(target).innerHTML = content + "</table>";
//	document.write(content + "</table>");
	//document.write('MAMAMAMA');	
}

function isEven(num) {
  return !(num % 2);
}



// Function for writing table tags
function getTableInit(show_image) {
	if(show_image == true) {
		return "<table width=\"418\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"priceTable\"><tr><th width=\"121\" rowspan=\"8\" scope=\"col\"><a href=\"";
	} else {
		return "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"priceTable\"><tr>";
	}
}

// Function for writing pre-content tags
function getPreContent(id, lang, show_image) {
	var content = "";
	if(show_image == true) {
		content = id + ".php?lang=" + lang + "\"><img src=\"pikakuvat/" + id + "_thumb.jpg\" alt=\"Thumbnail\" width=\"120\" height=\"80\" border=\"0\" /></a></th><th width=\"108\" scope=\"col\">&nbsp;</th><th width=\"94\" scope=\"col\">";
	} else {
		content = "<th width=\"108\" scope=\"col\">&nbsp;</th><th width=\"94\" scope=\"col\">";
	}
	return content;
}

// Function for writing column header tags
function getColumnHeaders(lang) {
	if(lang == "fi") {
		var content = "Viikonloppu";
	}
	if(lang == "en") {
		var content = "Weekend";
	}
	if(lang == "ge") {
		var content = "Wochenende";
	}
	if(lang == "ru") {
		var content = "Выходные дни";
	}
	content = content + "</th><th width=\"95\" scope=\"col\">";
	if(lang == "fi") {
		content = content + "Viikko";
	}
	if(lang == "en") {
		content = content + "Week";
	}
	if(lang == "ge") {
		content = content + "Woche";
	}
	if(lang == "ru") {
		content = content + "Неделя";
	}
	content = content + "</th></tr>";
	return (content);	
}

