//Copyright Malvern Translations Limited 2005+ All rights reserved
//Web:		http://www.translution.com
//E-mail:	pradeep.vardhineni@translution.net
//Licensed to: Hunt A Home
//Redistribution of the below code is not allowed under any conditions. 

//*************************TODO****************************************
//STEP 1: Add the required languages in the variable targetLangCodes (Place in the code is indicated by the comment STEP 1)
//STEP 2: Add the Key Value Pairs into the collection. This contains LangCode and Website URL((Place in the code is indicated by the comment STEP 2)
//STEP 3: Add the text in the function getButtonText() (Place in the code is indicated by the comment STEP 3)
//STEP 4: Add the text in the function getLanguageName() (Place in the code is indicated by the comment STEP 4)
//STEP 5: Add the text in the function getLabelText() (Place in the code is indicated by the comment STEP 5)

var transURL = location.href;
var PageLangCode="";

//The language code is a three letter string
//Below are the valid language codes
//Language Codes:
//English 				: eng
//French				: fra
//German				: deu
//Spanish				: esn
//Italian				: ita
//Portuguese			: ptg
//Dutch					: nld
//Swedish				: swe
//Greek					: ell
//Russian				: rus
//Arabic				: ara
//Korean				: kor
//Japanese				: jap
//Chinese(Simplified) 	: zhs
//Chinese(Traditional)	: zht

//STEP 1
var targetLangCodes=new Array("jap"); 

//The above array contains the array of language codes that the website will be localised.
//It does not contain the source language of the website. For example, an english website being localised to Chinese Simplified 
//and Chinese Traditional then the above array should contain the language codes for french(fra) and german(deu)

//Below line creates a collection to hold the website urls for source website and localised websites.
var WSColl = new CTransCollection;

//Below lines add website urls to a collection. 
//The collection requires a key and value pair. Key is the language code and the value is website URL.
//For the Source website, key is empty string
//For the localised websites, path is of the format 
//<<Source WebSite URL>>/translution/<<LanguageCode>>
//STEP 2
WSColl.addItem("","http://www.hellogoldcoast.com.au");
WSColl.addItem("jap","http://www.hellogoldcoast.jp");

var strURLPath = location.pathname;
var strQS = "";


function createTranslutionFlagBar(strLangCode){

	PageLangCode = strLangCode;
	
	
	document.write("<div id='TranslutionLB'>");
	
	//This is Change Language Label	
	document.write("<span align='centre'>");
	document.write("<p style='font-size:12px;font-weight:bold;color:white'>" + getLabelText(PageLangCode)); 
	
	//HTML for Language DROP DOWN
	document.write("<select name='cmbTransLanguage' id='cmbTransLanguage'>" + "</p>");
	
	//This is for Source Language
	if ( PageLangCode.length == 0){
		document.write("<option value=''>" + getLanguageName("",PageLangCode) + "</option>");
	}
	else{
		document.write("<option value='' selected>" + getLanguageName("",PageLangCode) + "</option>");
	}
	
	//For Target Languages
	
	for (i=0;i<targetLangCodes.length;i++){
			if ( targetLangCodes[i].toUpperCase() == PageLangCode.toUpperCase() ){
		        document.write("<option value='" + targetLangCodes[i] + "'>" + getLanguageName(targetLangCodes[i],PageLangCode) + "</option>");
	        }
			else{
				document.write("<option value='" + targetLangCodes[i] + "' selected>" + getLanguageName(targetLangCodes[i],PageLangCode) + "</option>");
			}
	}
	
	document.write("</select>");
		
	document.write("&nbsp;&nbsp;&nbsp;");
	
	//THIS IS FOR BUTTON HTML
	document.write("<input type='button' name='btnLocalise' value='" + getButtonText() + "' onclick='ChangePageLanguage()'>");
	document.write("</span>");
		
	document.write("</div>");
	
}

function ChangePageLanguage(){
try{
	//Get the Language Combo
	var objLang = document.getElementById("cmbTransLanguage");;
	
	if ( objLang != null){
		//Get the Selected option object
		var objSelOption = objLang.options[objLang.selectedIndex];
		if ( objSelOption != null){
			
			var SelValue= objSelOption.value.toUpperCase();
			if ( SelValue != PageLangCode.toUpperCase() ){
				
				strQS = location.search;
                        var RedirectionURL = "";
				if (PageLangCode != "")
				{
					//we are in japanese language
					var strActualURLPath = "";
                                
                                RedirectionURL = "http://www.hellogoldcoast.jp" + strURLPath + strQS;

										
				}
				else
				{
					strActualURLPath = strURLPath;
                              RedirectionURL = WSColl.getItem(SelValue) + strActualURLPath + strQS;

				}
	    				
				
								
				    window.location = RedirectionURL;
				
			}
		}
	}
}
catch(err){

}
}

//STEP 3
function getButtonText(){

	//This function gets the text for the button GO.
	//For different languages, different text has to be inserted.
	var strRet="GO";
	
	switch(PageLangCode.toUpperCase()){
		case "":
			strRet = "GO";
			break;
		case "JAP":
			strRet = "&#31227;&#21205";
				break;
		case "ZHS":
			strRet = "??";
				break;
	}
	return strRet;
	
}

//STEP 4
function getLanguageName(strLangCode,strPageLang){
    var strRet="";
    
	//This is to get the language name in the language of the page.
	
	if ( strPageLang.toUpperCase() == "" ){
		switch(strLangCode.toUpperCase()){
			case "":
				strRet = "English (&#33521;&#35486;)";
				break;
			
                   case "JAP":
                        strRet = "Japanese (&#26085;&#26412;)";
                       break;
		}
	}

          if ( strPageLang.toUpperCase() == "JAP" ){
		switch(strLangCode.toUpperCase()){
			case "":
				strRet = "English (&#33521;&#35486;)";
				break;
			
                   case "JAP":
                        strRet = "Japanese (&#26085;&#26412;)";
                       break;
		}
	}
        
	
	
    return strRet;
}

//STEP 5
function getLabelText(strLangCode){
	var strRet="";
    
    return strRet;
}

function showHTML(){
    var oEle = document.getElementById("TranslutionLB");
    if ( oEle != null){
        alert("Inner HTML = " + oEle.innerHTML);
    }
}

//This function is used to create a collection of website urls.
function CTransCollection(){

	this.obj = new Object();
	this.addItem=function addItem(strKey, strValue){
		this.obj[strKey]=strValue;
	}
	this.getItem=function getItem(strKey){
		return this.obj[strKey.toLowerCase()];
	}

}

