// JavaScript Document

function switchMonth(mouth)

{

	switch(mouth)

	{

		case 1 : strmm = "January";

		break;

		case 2 : strmm = "February";

		break;

		case 3 : strmm = "March";

		break;

		case 4 : strmm = "April";

		break;

		case 5 : strmm = "May";

		break;

		case 6 : strmm = "June";

		break;

		case 7 : strmm = "July";

		break;

		case 8 : strmm = "August";

		break;

		case 9 : strmm = "September";

		break;

		case 10 : strmm = "October";

		break;

		case 11 : strmm = "November";

		break;

		case 12 : strmm = "December";

		break;

	}

	return strmm;

}


function lastmodify()

{

var today = new Date(document.lastModified);

var dd=today.getDate();

var mm=today.getMonth()+1;

var yy=today.getFullYear();

if ( yy <= 1999 ) {

yy=yy+100;

}

if((document.location.pathname.indexOf("/tc/") != -1)||(document.location.pathname.indexOf("\\tc\\") != -1))

	{

	document.write( yy +" &#24180; "+ mm +" &#26376; " + dd +" &#26085; ");

	}

else if ((document.location.pathname.indexOf("/en/") != -1)||(document.location.pathname.indexOf("\\en\\") != -1))

	{

	document.write( dd +" " + switchMonth(mm) +" " + yy);

	}

else if ((document.location.pathname.indexOf("/sc/") != -1)||(document.location.pathname.indexOf("\\sc\\") != -1))

{

	document.write( yy +" &#24180; "+ mm +" &#26376; " + dd +" &#26085; ");

}

}

var myxmlhttp;
var lang;
var url_temp;

function check (urls, langs) {
	// REQUEST URL should be replaced by the URL you need to request
	// For example: http://www.websitetoolbox.com/tool/register/USERNAME/create_account
	//var url = "http://10.0.8.63/tc/speeches/SCED/P201001260168.html";
	url_temp = urls;
	lang = langs;
	myxmlhttp = CreateXmlHttpReq(resultHandler);
	if (myxmlhttp) {
		XmlHttpGET(myxmlhttp, urls);
	} else {
		alert("An error occured while attempting to process your request.");
		// provide an alternative here that does not use XMLHttpRequest
	}
}

function resultHandler () {
	// request is 'ready'

	if (myxmlhttp.readyState == 4) {
		// success
		if (myxmlhttp.status == 200) {
			//alert("Success!");
			top.location.replace(url_temp);
			// myxmlhttp.responseText is the content that was received from the request
		} else {
			//alert("There was a problem retrieving the data:\n" );
			var locationx = top.location.href.substring(0, url_temp.indexOf('/'+lang+'/'))
			if(lang == 'en' || lang == 'txt_en')
			{
				window.location = locationx + '/errorpageE.html';
			}else if (lang == 'sc' || lang == 'txt_sc')
			{
				window.location = locationx + '/errorpageSC.html';
			}else if (lang == 'tc' || lang == 'txt_tc')
			{
				window.location = locationx + '/errorpageTC.html';
			}
			
		}
	}
}

function CreateXmlHttpReq(handler) {
	var xmlhttp = null;

	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// users with activeX off
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	}

	if (xmlhttp) xmlhttp.onreadystatechange = handler;

	return xmlhttp;
}

// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
	try {
		xmlhttp.open("GET", url, true);	
		
		
		
		xmlhttp.send(null);
		
	} catch (e) {}
	
}




function SwitchLang(lang) {

var gopath;
	if (top.location.href.indexOf("#") != -1) {
		locationx = top.location.href.substring(0, top.location.href.indexOf("#"));
	} else {
		locationx = top.location.href;
	}
	if (lang == 'en') {
		if (locationx.indexOf("/en/") == -1) {
			if (locationx.indexOf("/sc/") != -1) {
				gopath = check(locationx.replace("/sc/","/en/"), 'en');
			} else if (locationx.indexOf("/tc/") != -1) {
				gopath = check(locationx.replace("/tc/","/en/"), 'en');
			} else if (locationx.indexOf("/txt_en/") != -1) {
				gopath = check(locationx.replace("/txt_en/","/en/"), 'en');
			} else if (locationx.indexOf("/txt_sc/") != -1) {
				gopath = check(locationx.replace("/txt_sc/","/en/"), 'en');
			} else if (locationx.indexOf("/txt_tc/") != -1) {
				gopath = check(locationx.replace("/txt_tc/","/en/"), 'en');
			}
		}
	} else if (lang == 'sc') {
		if (locationx.indexOf("/sc/") == -1) {
			if (locationx.indexOf("/en/") != -1) {
				gopath = check(locationx.replace("/en/","/sc/"), "sc");
			} else if (locationx.indexOf("/tc/") != -1) {
				gopath = check(locationx.replace("/tc/","/sc/"), "sc");
			} else if (locationx.indexOf("/txt_en/") != -1) {
				gopath = check(locationx.replace("/txt_en/","/sc/"), "sc");
			} else if (locationx.indexOf("/txt_sc/") != -1) {
				gopath = check(locationx.replace("/txt_sc/","/sc/")), "sc";
			} else if (locationx.indexOf("/txt_tc/") != -1) {
				gopath = check(locationx.replace("/txt_tc/","/sc/"), "sc");
			}
		}
	} else if (lang == 'tc') {
		if (locationx.indexOf("/tc/") == -1) {
			if (locationx.indexOf("/en/") != -1) {
		 		gopath = check(locationx.replace("/en/","/tc/"), 'tc');
			} else if (locationx.indexOf("/sc/") != -1) {
		 		gopath = check(locationx.replace("/sc/","/tc/"), 'tc');
			} else if (locationx.indexOf("/txt_en/") != -1) {
		 		gopath = check(locationx.replace("/txt_en/","/tc/"), 'tc');
			}else if (locationx.indexOf("/txt_sc/") != -1) {
				gopath = check(locationx.replace("/txt_sc/","/tc/"), 'tc');
			} else if (locationx.indexOf("/txt_tc/") != -1) {
				gopath = check(locationx.replace("/txt_tc/","/tc/"), 'tc');
			}
		}
	} else if (lang == 'txt_en') {
		if (locationx.indexOf("/txt_en/") == -1) {
			if (locationx.indexOf("/en/") != -1) {
		 		gopath = check(locationx.replace("/en/","/txt_en/"),"/txt_en/");
			} else if (locationx.indexOf("/txt_sc/") != -1) {
				gopath = check(locationx.replace("/txt_sc/","/txt_en/"),"/txt_en/");
			} else if (locationx.indexOf("/txt_tc/") != -1) {
				gopath = check(locationx.replace("/txt_tc/","/txt_en/"),"/txt_en/");
			}
		}
	} else if (lang == 'txt_tc') {
		if (locationx.indexOf("/txt_tc/") == -1) {
			if (locationx.indexOf("/tc/") != -1) {
		 		gopath = check(locationx.replace("/tc/","/txt_tc/"),"/txt_tc/");
			} else if (locationx.indexOf("/txt_sc/") != -1) {
				gopath = check(locationx.replace("/txt_sc/","/txt_tc/"),"/txt_tc/");
			} else if (locationx.indexOf("/txt_en/") != -1) {
				gopath = check(locationx.replace("/txt_en/","/txt_tc/"),"/txt_tc/");
			}
		}
	} else if (lang == 'txt_sc') {
		if (locationx.indexOf("/txt_sc/") == -1) {
			if (locationx.indexOf("/sc/") != -1) {
		 		gopath = check(locationx.replace("/sc/","/txt_sc/"),"/txt_sc/");
			} else if (locationx.indexOf("/txt_tc/") != -1) {
				gopath = check(locationx.replace("/txt_tc/","/txt_sc/"),"/txt_sc/");
			} else if (locationx.indexOf("/txt_en/") != -1) {
				gopath = check(locationx.replace("/txt_en/","/txt_sc/"),"/txt_sc/");
			}
		}
	}
	
}
