var lg = "en";
var no = "0";
function getCMSText(lg, typeSearch, typeLink) {
	function createRequest() {			
		if(window.XMLHttpRequest) {
			textInfo = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			textInfo = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	function handleStateChange() {
		if(textInfo.readyState == 4) {	
			if(textInfo.status == 200) {
				document.getElementById("view").innerHTML = textInfo.responseText;
			}
		}
	}
	var textInfo;
	var sendTypeSearch;
	createRequest();	
	if(typeLink == "topic") {
		sendTypeSearch = "&page=";
	} else if(typeLink == "link") {
		sendTypeSearch = "&id=";
	}
	textInfo.open("GET", "cms.php?lg=" + lg + sendTypeSearch + typeSearch, true);
	textInfo.onreadystatechange=handleStateChange;
	textInfo.send(null);
}

function lastUpdate() {
	function createRequest() {			
		if(window.XMLHttpRequest) {
			textInfo = new XMLHttpRequest();
		} else if(window.ActiveXObject) {
			textInfo = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	function handleStateChange() {
		if(textInfo.readyState == 4) {	
			if(textInfo.status == 200) {	
				document.getElementById("lastUpdate").innerHTML = textInfo.responseText;
			}
		}
	}
	var textInfo;
	var sendTypeSearch;
	createRequest();
	textInfo.open("GET", "last_update.php", true);
	textInfo.onreadystatechange=handleStateChange;
	textInfo.send(null);
}

function changeLangauge(lgChange) {
	if(lgChange == "en") {
		lg = "en";
	} else {
		lg = "th";
	}
	startPage();	
}

function firstPage() {
	
}
function titleHead(lg, no) {
	var tHead;
	if(lg == "en") {
		if(no == "0") {
			tHead = "KEEP OCEANS ON OUR PLANET CLEAN";
		} else if(no == "1") {
		} else if(no == "2") {
		} else if(no == "3") {
		} else if(no == "4") {
		} else if(no == "5") {
		} else if(no == "6") {
		} else if(no == "7") {
		} else if(no == "8") {
		} else if(no == "9") {
		}
	} else if(lg == "th") {
		if(no == "0") {
			tHead = "มาช่วยกันรักษามหาสมุทรของโลกเราให้สะอาด";
		} else if(no == "1") {
		} else if(no == "2") {
		} else if(no == "3") {
		} else if(no == "4") {
		} else if(no == "5") {
		} else if(no == "6") {
		} else if(no == "7") {
		} else if(no == "8") {
		} else if(no == "9") {
		}
	}
	document.getElementById("head").innerHTML = tHead;
}

function disclaimer(lg) {
	window.open("disclaimer.php?lg=" + lg,"winname","menubar=0, toolbar=0, location=0, scrollbars=1, status=1, resizeable=on, width=526, height=278");
}

function sitemap(lg) {
	window.open("sitemap.php?lg=" + lg,"winname","menubar=0, toolbar=0, location=0, scrollbars=1, status=1, resizeable=on, width=526, height=278");
}

function startPage() {	
	lastUpdate();	
	titleHead(lg,no);
	mainPage(lg,no);
}
