/*  -------------------------------------------------------------------------------------------------------------

Rules for CountryListTmp
New country (in alpha order) begins with a '+' and uses '_' to separate country code.
After country code uses '%' to separate each language and again '_' to separate language code(s).
e.g. +Belgium_BE%Français_FR%Nederlands_NL

Modifications
05-07-06 buildLanguage - Created the strSelectLanguage variable to hold position [0] for the language 
              drop down - Ryan O'Dell
13-07-06 submitform - Fixed the form action by inserting 'http://www.unilever.com' - Ryan O'Dell
-----------------------------------------------------------------------------------------------------------------  */

var CountryListTmp ="Austria_AT%Deutsch_DE+Belgium_BE%Français_FR%Nederlands_NL+Bulgaria_BG%Bulgarian_BG+Czech Republic_CZ%Ceština_CS+Denmark_DK%Dansk_DA+Estonia_EE%Eesti keel_ET+Finland_FI%Suomi_FI%Svenska_SV+France_FR%Français_FR+Germany_DE%Deutsch_DE+Greece_GR%Ελληνικά_EL+Cyprus_CY%Ελληνικά_EL+Hungary_HU%Magyar_HU+Ireland_IE%English_EN+Italy_IT%Italiano_IT+Latvia_LV%Latviešu valoda_LV+Lithuania_LT%Lietuviu kalba_LT+Luxembourg_LU%Français_FR+Malta_MT%English_EN%Malti_MT+Netherlands_NL%Nederlands_NL+Poland_PL%Polski_PL+Portugal_PT%Português_PT+Romania_RO%Romanian_RO+Slovak Republic_SK%Slovencina_SK+Slovenia_SI%Slovenšcina_SL+Spain_ES%Español_ES+Sweden_SE%Svenska_SV+Switzerland_CH%Français_FR%Deutsch_DE%Italiano_IT+United Kingdom_UK%English_EN"


// Create an array of structure   Country_CountryNumber%Language_LanguageNumber%Language_LanguageNumber+...
	var CountryList = CountryListTmp.split("+");
//
	function buildCountry(form,countryNumber)
	{

		for(i=0;i < CountryList.length;i++)
		{
			SubCountryArray = CountryList[i].split("%");
			SplitSubCountryArray = SubCountryArray[0].split("_");
			thisSelected = false;
			if(countryNumber == SplitSubCountryArray[1]) thisSelected = true;
			thisObj = new Option(SplitSubCountryArray[0],SplitSubCountryArray[1],thisSelected,false);
			form.selectCountry.options[i +1] = thisObj;
		}
	}

	function buildLanguage(form,languageNumber)
	{
	if(form.language)
	{

	// detect hidden select language label for position [0]
	var strSelectLanguage = "- Select lanuage -";
	if (form.selectLanguageLabel) { 
	  if (form.selectLanguageLabel.value != '') { 
	    strSelectLanguage = form.selectLanguageLabel.value;
	  }
	}

	// find currently user selected Country
	thisCountry = form.selectCountry.options[form.selectCountry.selectedIndex].text;
	thisCountryLength = thisCountry.length;

	// remove existing Languages
	form.language.options.length = 1;

	// try matching Country with array of Countries

	for(i=0;i < CountryList.length;i++)
	{
	if(thisCountry.toUpperCase() == CountryList[i].substring(0,thisCountryLength).toUpperCase())
		{
				// This is a Region match - know which element it was so extract corresponding Sub Region selection
				SubCountryArray = CountryList[i].split("%");

				if(SubCountryArray.length == 2)
					{
						SplitSubCountryArray = SubCountryArray[1].split("_");;
						thisObj = new Option(SplitSubCountryArray[0],SplitSubCountryArray[1],false,false);
						form.language.options[0] = thisObj;				
					}
				else
					{
					//thisObj = new Option("- Select language -",0,true,false);
					thisObj = new Option(strSelectLanguage,0,true,false);
					form.language.options[0] = thisObj;

					for(j=1; j < SubCountryArray.length;j++)
						{ 
						SplitSubCountryArray = SubCountryArray[j].split("_");;
						thisObj = new Option(SplitSubCountryArray[0],SplitSubCountryArray[1],false,false);
						form.language.options[j] = thisObj;
						}
					}
					
		}
	  }
    }
}

function submitForm(form,thisAction)
	{
	if(form.selectCountry.options[form.selectCountry.selectedIndex].value == "0")
		{
			alert('Please select a country');
			form.selectCountry.focus();
			return false;
		}
	else if(form.language.options[form.language.selectedIndex].value == "0")
		{
			alert('Please select a language');
			form.language.focus()	
			return false;
		}
	else
		{
			form.selectCountry.value = form.selectCountry.options[form.selectCountry.selectedIndex].value;	
			form.selectCountryName.value = form.selectCountry.options[form.selectCountry.selectedIndex].text;	
			form.language.value = form.language.options[form.language.selectedIndex].value;

			//check to see if country language includes an '*' which means it's not ready
			var iLen = String(form.language.value).length;
			var lang = form.language;
			var langcode = lang.value;

			if (iLen >= 1) {
				if (lang.value.substr(iLen-1, 1) == "*") {
					thisAction = "/comingsoon.asp";
					langcode = lang.value.substr(0, (iLen-1));
					lang.value = langcode;
				}
			}

			//form.action = "http://www.unilever.com/PIOTI/" + langcode  + thisAction;
			form.action = "/PIOTI/" + langcode  + thisAction;
			// alert(form.action);
			form.submit();
		}
	}


function submitThis(form,thisAction,country, countryName, language, brandid, productid)
{
form.selectCountry.value = country;
form.selectCountryName.value = countryName;
form.language.value = language;
form.brandid.value = brandid;
form.productid.value = productid;

if(thisAction != "") form.action = thisAction;
form.submit();
}

function submitBrandSelect(thisLine)
{
thisArray = thisLine.split(",");
document.form1.selectCountry.value = thisArray[2];
document.form1.selectCountryName.value = thisArray[3];
document.form1.language.value = thisArray[4];
document.form1.brandid.value = thisArray[5];
document.form1.productid.value = thisArray[6];

if(thisLine == "") return false;

if(thisArray[1] != "") document.form1.action = thisArray[1];
document.form1.submit();
}