var clockID = 0;

function aweOnload()
{
	Go();
	//StartClock();
}

function aweOnunload()
{
	//KillClock();
}

function writeObj(str){
	document.write(str);
}

function UpdateClock() {
	if(clockID) {
	   clearTimeout(clockID);
	   clockID  = 0;
	}

	var tDate = new Date();
	var hour;
	var tempHour;
	var minute;
	var amOrPm;
	var time;
	var date;
	var day;
	var month;
	var year;

	hour = tDate.getHours();
	minute = tDate.getMinutes();
	tempHour = hour;
	if (hour <=12)
	{
	  amOrPm = "am";
	}
	else
	{
	  amOrPm = "pm";
	}
	if (tempHour > 12)
	{
	  tempHour = tempHour - 12;
	}
	hour = addZeroToOneDigit(tempHour);
	minute = addZeroToOneDigit(minute);
	time = "GMT (+8) : " + hour + ":" + minute + amOrPm;

	day = tDate.getDate(); 
	month = tDate.getMonth() + 1;
	year = tDate.getFullYear();
	day = addZeroToOneDigit(day);
	month = addZeroToOneDigit(month);
	date = month + "-" + day + "-" + year;

	var clocklocation = document.getElementById('theTime');
	clocklocation.innerHTML = time + "&nbsp;&nbsp;" + date;
	   
	//clockID = setTimeout("UpdateClock()", 1000);
	clockID = setTimeout("UpdateClock()", 30000);
}

function StartClock() {
	//clockID = setTimeout("UpdateClock()", 500);
	clockID = setTimeout("UpdateClock()", 0);
}

function KillClock() {
	if(clockID) {
	   clearTimeout(clockID);
	   clockID  = 0;
	}
}

function addZeroToOneDigit(i) {
	var twoDigitNumber;

	if (i < 10)
	{
	  twoDigitNumber = "0" + i;
	}
	else
	{
	  twoDigitNumber = i;
	}

	return twoDigitNumber;
}

function moveLayer()
{
	var th;
	var bh = 19;
	var topButton = document.getElementById? document.getElementById("moreHighlight") : document.all.moreHighlight;
	var index = document.getElementById? document.getElementById("index") : document.all.index;
	th = document.body.scrollTop + document.body.clientHeight - bh;
	if (th > index.offsetHeight)
	{
		th = index.offsetHeight - bh;
	}
	topButton.style.top = th;
	displayMoreButton(topButton);
}

function displayMoreButton(tb)
{
	var indexHeader = document.getElementById? document.getElementById("indexHeader") : document.all.indexHeader;
	var footer = document.getElementById? document.getElementById("footer") : document.all.footer;
	var indexMain = document.getElementById? document.getElementById("indexMain") : document.all.indexMain;
	var temph = tb.style.top.replace("px", "");
	var h = parseInt(temph);
	if (h <= indexHeader.offsetHeight || h >= (indexHeader.offsetHeight + indexMain.offsetHeight))
	{
		tb.style.visibility="hidden";
	}
	else
	{
		tb.style.visibility="visible";
	}
}

function hideMoreLabel()
{
	var topButton = document.getElementById? document.getElementById("moreHighlight") : document.all.moreHighlight;
	topButton.style.visibility="hidden";
}

function openNewWin(imgurl, w, h, url, bgcolor, fgcolor, acolor, text, winname)
{
	var popupurl = '/popup.aspx?media=print';
	
	popupurl += '&imageurl=' + imgurl;
	if (url != null)
		popupurl += '&url=' + url;
	if (bgcolor != null)
		popupurl += '&bgcolor=' + escape(bgcolor);
	if (fgcolor != null)
		popupurl += '&fgcolor=' + escape(fgcolor);
	if (acolor != null)
		popupurl += '&acolor=' + escape(acolor);
	if (text != null)
		popupurl += '&text=' + escape(text);
	if (winname == null)
		winname = "AsiaworldExpo";
		
	var newWin = window.open(popupurl, winname, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes, width=' + w + ', height=' + h);
	newWin.focus();
}

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

	if(value == null){
		value = 1;
	}else if (value > 1)
	{
		value = 1;
	}else if (value < -1)
	{
		value = -1;
	}

	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}

	return null;
}


function readLang(l){
	var langnow = l;

	var classname;

	var lang = readCookie("lang");
	
	
	if(lang != "en" && lang != "sc" && lang != "zh"){
		lang = "en";
	}
//	fonts = parseInt(fonts);


//	if (lang > 1)	{
//		lang = 1;
//	}
//	alert(lang);
	if (lang == "en"){
		if ( lang != langnow )
		{
			//window.location.href=window.location.href.replace('/'+ langnow +'/','/en/')	
		}
		classname = "en";
	}else if (lang == "zh"){
		if ( lang != langnow )
		{
			//window.location.href=window.location.href.replace('/'+ langnow +'/','/zh/')
		}
		classname = "zh";
	}else if (lang == "sc"){
		classname = "sc";
		if ( lang != langnow )
		{
			//window.location.href=window.location.href.replace('/'+ langnow +'/','/sc/')
		}
		
	}else {
		classname = "en";
		//window.location.href=window.location.href.replace('/'+ langnow +'/','/en/')
	}

//	removeClass(document.getElementById("wrapper"), "Large");
//	removeClass(document.getElementById("wrapper"), "Medium");
//	removeClass(document.getElementById("wrapper"), "Small");
//
//	addClass(document.getElementById("wrapper"), ""+classname);
	
	createCookie("lang",lang,5);
}
