//File: javascripts.js with functions for handling setting of language
//For pack templates

//Function for setting session cookie
function SetCookie (name, value) {
	document.cookie = name + "=" + escape(value);
}

//Function for getting session cookie
function GetCookie (name) {
	var search = name + "=";
	if (document.cookie.length > 0) { //If there are any cookies
		offset = document.cookie.indexOf(search);
		if (offset != -1) { //If cookie exists
			//Set index of beginning of value
			offset +=search.length; 
			//Set index of end of cookie value
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				 end = document.cookie.length;
			return unescape(document.cookie.substring(offset, end));
		}
	}
}

//Function to display text in selected language
function ShowText(path) {
	//Read current language code stored in session cookie
	var CurrLanguage = GetCookie('SelectedLanguage');
	//Check if this is valid. If not do something about it
	if ((CurrLanguage != "en") && (CurrLanguage != "da") && (CurrLanguage != "oo")) {
		//Do something serious here if no valid language code
		alert("Language has not been selected\n\nVous n'avez pas choisi la langue\n\nDer er ikke valgt sprog");
		//Change location to index.html
		self.location = path+"index.html";
	} else { //Link to appropriate Style Sheet
		var StyleSheet = "href="+path+"styles/"+CurrLanguage+".css";
		document.write('<link rel="STYLESHEET" ' +StyleSheet+' type="text/css">');
	}
}//end ShowText

//Function to display ALT text or Status text in selected language
function ShowAlt(t_da, t_en) {
	switch (GetCookie('SelectedLanguage')) {
		case "da" :
			return t_da;
			break;
		case "en" :
			return t_en;
			break;
		default : return "";
	}//end switch
}//End ShowAlt

//Function to display Last Update time of page
function ShowLastUpdate() {
//	var LanguageCode = GetCookie('SelectedLanguage')
	var LanguageCode = "da";
	if (LanguageCode != "oo") {
/*		var LangText = ShowAlt(
		"Sidst opdateret: ",
    "Last updated: "
		)*/
    var LangText = "Sidst opdateret: ";
		var a;
		a=new Date(document.lastModified);
		lm_year=a.getYear();
		if (lm_year<1000){ 		//just in case date is delivered with 4 digits
			if (lm_year<70){
			lm_year=2000+lm_year;
			}
			else lm_year=1900+lm_year;
		}								//end workaround
		lm_month=a.getMonth()+1;
		if (lm_month<10){
			lm_month='0'+lm_month;
		}
		lm_day=a.getDate();
		if (lm_day<10){
			lm_day='0'+lm_day;
		}
		document.write('<p class="' + LanguageCode + '"> ' +
			LangText + lm_day+'.'+lm_month+'.'+lm_year + '</p>'
		)
	}//End if
}//End ShowLastUpdate

// Function for showing enlarged image in new window
function enl_image (title,img_scr,wid,hei) {
  // Open new window
  w = open("", 'image', 'dependent=yes,resizable=yes,scrollbars=no,titlebar=yes,status=no,width=' + wid + ',height=' + hei + ',top=20,left=20');
  w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"><html><head><title>" + title + "<\/title>");
  w.document.write("<\/head><body style=\"margin: 0px;  margin-top: 0px;\" bgcolor=\"#FFFFFF\"> <div align=\"center\"> <img src=\"" + img_scr + "\" border=\"0\" alt=\"" + title + "\" title=\"" + title + "\"></div>");
  w.document.write("<\/body><\/html>");
  w.document.close();
} // End function enl_image

