function GetCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function SetCookie (name,value, expires)
{
	var myString = ""
	myString = name+"="+escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + "; path = /" ;
	document.cookie =  myString;
}

function GoToCountry()
{
    var myindex = document.formcountryselect.countryselect.selectedIndex;
    var myCountry = document.formcountryselect.countryselect.options[myindex].value;
    if (myCountry == "-1")
    {
        alert("Please select a country/region");
    }
    else
    {
		if(checkNavItem(myCountry))
		{
			var windowStyle = dropDownArray[counter][inCounter][1];
			var popupWidth  = dropDownArray[counter][inCounter][2];
			var popupHeight = dropDownArray[counter][inCounter][3];
			var popupResize = dropDownArray[counter][inCounter][4];
			var popupScroll = dropDownArray[counter][inCounter][5];
			var enableRememberCountry = dropDownArray[counter][inCounter][6];
			var countryLink = CountryLinks[dropDownArray[counter][inCounter][0]];
			
			if (document.formcountryselect.chkCookie.checked)
			{
				myURL = countryLink;
				myURL = myURL.toLowerCase();
				if(enableRememberCountry == "1")
				{
					CallSetCookie();
				}
			}
			navigateByWidowStyle(countryLink, windowStyle, popupWidth, popupHeight, popupResize, popupScroll);
		}
		else /*This is locale*/
		{
			if (document.formcountryselect.chkCookie.checked)
			{
				myURL = CountryLinks[myCountry];
				myURL = myURL.toLowerCase();
				CallSetCookie();
			}	
			document.location.href = CountryLinks[myCountry];
		}
    }
}

function OnChange()
	{
		var myindex = document.formcountryselect.countryselect.selectedIndex;
	    var myCountry = document.formcountryselect.countryselect.options[myindex].value;
	
		if(checkNavItem(myCountry))
		{
			var enableRememberCountry = dropDownArray[counter][inCounter][6];
			if(enableRememberCountry == "0"){
				document.formcountryselect.chkCookie.disabled = true;
				
			}else{
					document.formcountryselect.chkCookie.disabled = false;
			}
		}else
		{
			document.formcountryselect.chkCookie.disabled = false;
		}
	} 

function checkNavItem(myCountry)
{
	var navItemFound = false;
	for(counter = 0; counter < dropDownArray.length; counter++)
	{
		for(inCounter = 0; inCounter < dropDownArray[counter].length; inCounter++)
		{
			if(myCountry == dropDownArray[counter][inCounter][0])
			{
				navItemFound = true;
				break;
			}
		}
		if(navItemFound)
		{
			break;
		}
	}
	return navItemFound;
}
	
function isCookieeEnabled()
{
	var cookieEnabled = false;
	var testCookieString = (GetCookie("HM_CountryPromotionCookie") == null) ? "" : GetCookie("HM_CountryPromotionCookie");
	if (testCookieString.length > 0)
	{
		cookieEnabled = true;
	}else
	{
		SetTestCookie();
		testCookieString = (GetCookie("HM_CountryPromotionCookie") == null) ? "" : GetCookie("HM_CountryPromotionCookie");
		if (testCookieString.length > 0)
		{
			cookieEnabled = true;
		}else
		{
			cookieEnabled = false;
		}
	}
	return cookieEnabled;
}

function SetTestCookie()
{
	var myDate = new Date();
	myDate.setTime(myDate.getTime() + 100000*24*60*60*1000);
	SetCookie ("HM_CountryPromotionCookie", "Hellomoto", myDate);
}

function CallSetValues(){
	var myDate = new Date();
	myDate.setTime(myDate.getTime() + 100000*24*60*60*1000);
	var getCookieString=GetCookie(name);
	values=getCookieString;
	nhp=0;
	if(values == "" || values == null){
		values = localeGUID+"::"+uRLVersion;
	}else{
		end = values.length;
		var subString = values.substring(0,end);
		var selectedValue = subString.split("::");
		var num=0;
		while (num < selectedValue.length)
		{
			valuesInCookie=selectedValue[num];
			if(selectedValue[num]==localeGUID){
				if(selectedValue[num+1] == uRLVersion){
			//		alert("redirect to NHP");
					nhp = 1;
					break;
				}
				num+=1;
			}
			num+=1;
		}
		if(nhp == 0)
		{
			values = values+"::"+localeGUID+"::"+uRLVersion;
			SetCookie (name, values, myDate);
		}
	}
	return nhp;
}