// JavaScript Document

var EN = "English";
var PT = "Portugues";
var currentUrl = new String(window.location.href);
var newLang = null;

	if (currentUrl.indexOf("_pt") != -1) {
		newLang = EN;
	} else if (currentUrl.indexOf("_en") != -1) {
		newLang = PT;
	} else if (languageToSet) {
		//if this, then is coming from news app so see what it set this var to
		//alert("languageToSet: '" + languageToSet +"'");
		newLang = (languageToSet == EN)?EN:PT;
	}

	//if null, then assume is error page redirection and set to English
	if (newLang == null) {
		newLang = EN;
	}

	if (newLang) {
		var langLink = new String("<span><a href=\"#\" onclick=\"setLang('" + newLang + "');\" class=\"linkItems\">&nbsp;" + newLang + "</a></span>");
		document.write(langLink);
	}



function setLang(langValue) {
	//alert("langValue: " + langValue);
	var endsInLang = true;
	if (langValue == PT) {
		currentUrl= new String(window.location.href);
		if (currentUrl.indexOf(".shtml") != -1) {
			currentUrl= currentUrl.substr(0,currentUrl.indexOf("_en.shtml")) + "_pt.shtml";
		} else {
			endsInLang = false;
		}
		

	} else if (langValue == EN) {
		currentUrl= new String(window.location.href);
		if (currentUrl.indexOf(".shtml") != -1) {
			currentUrl= currentUrl.substr(0,currentUrl.indexOf("_pt.shtml")) + "_en.shtml";
		} else {
			endsInLang = false;
		}

	}
	
	if (!endsInLang) {
		if (languageToSet) {
			//is jsp, so set cookie and leave url alone
			setLanguageCookie(langValue);
		} else {
			currentUrl = "error.html";
		}
	}
	
	window.location.href = currentUrl;

}




