var selectedEtiDiv = 'null';
var globalEtiquetteCountry = "";


function getEtiquetteCountryList(){
			DWREngine._execute(dwrURL, 'DestinationDWR', 'getEtiquetteCountryList', loadEtiquetteCountries);
}

function loadEtiquetteCountries(result){
	var etiquetteDiv= '<ol class="genList fs-10">';

	for (var i=0;i<result.length ;i++ )
	{
		var country=result[i].countryName.toLowerCase();
		if (country.indexOf(' ') != -1)
			country = country.replace(" ","_");
//		etiquetteDiv += '<li id="'+result[i].columbusCountryCode+'"><a  href="/jsp/destination/countryEtiquette.jsp?name='+country +'">' + result[i].countryName +'</a></li>';
		etiquetteDiv += '<li id="'+result[i].columbusCountryCode+'"><a  href="/'+country +'-etiquette">' + result[i].countryName +'</a></li>';
	} 
	etiquetteDiv += '</ol>';
	document.getElementById("etiquetteCountryList").innerHTML = etiquetteDiv;
	
}




function getEtiquetteDetails(country,columbusCountryCode){
	country = country.toLowerCase();
	if (country.indexOf('_') != -1)
	{
	country = country.replace("_"," ");
	}
	if( country=='hong kong')
	document.getElementById("etiCityListTitle").innerHTML = "<h2>Explore our city guides for China:</h2>";	
	else
	document.getElementById("etiCityListTitle").innerHTML = "<h2>Explore our city guides for " + toProperCase(country) + ":</h2>";		

	if(selectedEtiDiv != null && selectedEtiDiv != "" && selectedEtiDiv != 'null'){
		if(document.getElementById(selectedEtiDiv) != "undefined" && document.getElementById(selectedEtiDiv) != "null" && document.getElementById(selectedEtiDiv) != null){ 		
			document.getElementById(selectedEtiDiv).className = "";
		}
	}

	if(document.getElementById(columbusCountryCode) != "undefined" && document.getElementById(columbusCountryCode) != "null" && document.getElementById(columbusCountryCode) != null) {
		if(typeof(document.getElementById(columbusCountryCode)) != "undefined" && typeof(document.getElementById(columbusCountryCode)) != "null" && typeof(document.getElementById(columbusCountryCode)) != null && typeof(document.getElementById(columbusCountryCode)) != "")
		{
			document.getElementById(columbusCountryCode).className = "selected";
		}
	}
	selectedEtiDiv = columbusCountryCode;
		if(columbusCountryCode == 'hkg' || columbusCountryCode == 'HKG')
		columbusCountryCode = 'chn';
	DWREngine._execute(dwrURL, 'DestinationDWR', 'getCityListForCityGuideOrTransport', columbusCountryCode ,"Cityguide", loadEtiquetteCityList);
}

function loadEtiquetteCityList(cityList){

	

	if (cityList != null && cityList != "")
	{
	
		if(cityList.length == 1)
		document.getElementById("etiCityListTitle").innerHTML = "<h2>Explore our city guide for " + toProperCase(globalEtiquetteCountry) + ":</h2>";
		
		document.getElementById("boxSeals").style.visibility='visible';
		document.getElementById("boxSeals").style.height='auto';
		document.getElementById("boxSeals").style.display= '';
		var testCityList = cityList;
		var url = "";
		var cityListDiv= '<ol class="genList fs-10">';
		for (var i=0;i<cityList.length ;i++ )
		{
			url = appcontextPath + "/jsp/destination/exploreDestinations.jsp?citycode=" + cityList[i].code;
			cityListDiv += '<li ><a href="'+url+'" >' + cityList[i].name +'</a></li>';
		} 
		cityListDiv += '</ol>';
		document.getElementById("etiCityList").innerHTML = cityListDiv;
	}else {
		document.getElementById("boxSeals").style.visibility='hidden';
		document.getElementById("boxSeals").style.display= 'none';
	}
}

function loadPage(divid,linkpath){
	if(selectedEtiDiv != null && selectedEtiDiv != "" && selectedEtiDiv != 'null'){
		if(document.getElementById(selectedEtiDiv) != "undefined" && document.getElementById(selectedEtiDiv) != "null" && document.getElementById(selectedEtiDiv) != null){ 		
			document.getElementById(selectedEtiDiv).className = "";
		}
	}
	LoadAjaxContent(divid,linkpath);
	document.getElementById("boxSeals").style.visibility='hidden';
	document.getElementById("boxSeals").style.display= 'none';
	if(linkpath == '/html/Content/Etiquette/genericPage.html')
		document.title = " Etiquette for the World Traveler";

}

function getCountryCode(country){
	
	country = country.toLowerCase();
	if (country.indexOf('_') != -1)
	{
	country = country.replace("_"," ");
	}
	globalEtiquetteCountry = country;
	if(country != null && country != "null" && country != "")
	DWREngine._execute(dwrURL, 'DestinationDWR', 'getCountryCodeForCountry', country , callBackCountryCode);

}

function callBackCountryCode(columbusCountryCode){
	if(country != null && country != "null" && country != "")
	getEtiquetteDetails(globalEtiquetteCountry,columbusCountryCode);
}


function toProperCase(s)
{
  return s.toLowerCase().replace(/^(.)|\s(.)/g, 
          function($1) { return $1.toUpperCase(); });
}

function getEtiquetteTitle(country){
	var dynamicTitle = '';
	var culture = '';
	if (country.indexOf('_') != -1)
	{
	country = country.replace("_"," ");
	}
	var etiquetteCountry = toProperCase(country);
	var etiHtmlHeading = document.getElementById("etiTitle").innerHTML;
	if (etiHtmlHeading.split(' ')[1] == "Etiquette" || etiHtmlHeading.split(' ')[1] == "etiquette" )
		culture	= etiHtmlHeading.split(' ')[0];
	else
		culture	= etiHtmlHeading.split(' ')[0] + " " + etiHtmlHeading.split(' ')[1];
	if(country == "hong kong" || country == "Hong Kong" || country == "singapore" || country == "Singapore")
	dynamicTitle = etiquetteCountry + " Etiquette Tips, "+ etiquetteCountry + " Do's and Don'ts in  - vayama";
	else
	dynamicTitle = etiquetteCountry + " Etiquette Tips, "+ culture + " Do's and Don'ts in  - vayama";
	document.title = dynamicTitle;
}