﻿jQuery.preloadImages = function() {
	$('.btn_over').each(function() {
		jQuery("<img>").attr("src", replaceFilename($(this).attr('src'), ".", "_over."));
	});
	$('.btn_o').each(function() {
		jQuery("<img>").attr("src", replaceFilename($(this).attr('src'), ".", "_o."));
	});
}
try{
}catch(e){
}

var langs = ['en','tc','sc'];
var currentLang = -1;
for(x in langs){
	if(location.href.search('/'+langs[x]+'/')!=-1){
		currentLang = langs[x];
	}
}
if(currentLang==-1){
	var tempLang = location.href.match(/lang=\d/);
	if(tempLang){
		currentLang = langs[tempLang[0].replace('lang=', '')-1];
	}
}

var textField = function(p_id, p_caption){
	this.caption=p_caption;
	this.fieldID = p_id;
	this.css={color: '#828282'};
	this.reset = function(){
		try{
			with(document.getElementById(this.fieldID)){
				value = eval('this.caption.'+currentLang);
				for(x in this.css){
					eval('style.'+x+' = this.css.'+x);
				}
			}
		}catch(errormessage){
		}
	}

}

var textFields = {
	searchbox: new textField("searchbox", {en:"Search",tc:"Search",sc:"Search"}),
	newsletter_sign_up_email: new textField("newsletter_sign_up_email", {en:"e-mail address",tc:"e-mail address",sc:"e-mail address"})
}

function search(){
	var query;
	query = $("#searchbox").val();
	if(query.replace(' ','') == ''){
		return false;
	}
	var url = "?";
	url += "tid=" + tid;
	url += "&lang=" + lang;
	url += "&query=" + escape(query);
	if(location.href.search('query=')!=-1){
		location.href = searchPage+url;
	}else{
		window.open(searchPage+url);
	}
}

function switchLang(toLang){
	location.href = location.href.replace('/'+lang+'/', '/'+toLang+'/');
}

function Menu() {
	this.contentId = 0;
	this.text = "";
	this.alt = "";
	this.href = "";
	this.target = "";
	this.childs = new Array();
}

function showHide(theOne, isShow){
	// theOne = JQuery Selector
	// isShow = true for show
	if(isShow){
		theOne.show();
	}else{
		theOne.hide();
	}
}
function hideAll(){
	clearTimeout(t);
	$(".sub").each(function(){
		$(this).css('display', 'none');
	});
}

var t;
var globalMoving = false;
function configureLeftMenu(){
	var result = '';
	$('#top_nav>li').each(function(){
		var curr = $(this);
		curr.bind('mouseover', function(){
			$(this).find('ul').each(function(){
				$(this).parents('#top_nav>li').children('a').addClass('selected');
				$(this).css({
					'display': 'block'
					//'top': (!jQuery.browser.mozilla)?(!jQuery.browser.msie)?23:30:currNode.offset().top + $(currNode).height()+8+'px',
					//'left': (!jQuery.browser.mozilla)?0:(($(currNode).offset().left)+'px')
				});
			});
		}).bind('mouseout', function(){
			$(this).find('ul').css('display', 'none').parents('#top_nav>li').children('a').removeClass('selected');
		})
	});
}

function getY(arg){
	var y = 0;
	if (arg.offsetParent){
		y = getY(arg.offsetParent);
	}
	return arg.offsetTop + y;
}

function getX(arg){
	var x = 0;
	if (arg.offsetParent){
		x = getX(arg.offsetParent);
	}
	return arg.offsetLeft + x;
}

function loadDateString(yyyy, mm, dd){
	switch (zmsCharsetID)
	{
		case 1:
		case 4:
			var monthName = new Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
			return dd+" "+monthName[mm]+" "+yyyy;
			break;
		case 2:
		case 5:
			return yyyy+"年"+mm+"月"+dd+"日";
			break;
		case 3:
		case 6:
			return yyyy+"年"+mm+"月"+dd+"日";
			break;
	}
}

function replaceFilename(url, fromstr, tostr){
	var filestart = url.lastIndexOf("/");
	var newUrl = 
		url.substring(0, filestart)
		+ url.substring(filestart)
		.replace(fromstr, tostr);
	return newUrl
}

Menu.prototype = {
	addChild : function(m) {
		this.childs[this.childs.length] = m;
	}
}

function generateMenu(rootMenu) {
	// Must override
}

function printPage() {
	var URL;
	URL = location.href.replace('#', '');
	if (URL.indexOf("?")>0) {
		URL += "&print=1";
	} else {
		URL += "?print=1";
	}
	window.open(URL);
}

function ShowPrintHeader(){
}

function ShowPrintFooter(){
}

function openPopup(path,width,height,targetname) {
  window.open(path,targetname,'height='+height+', width='+width+', toolbar=no, menubar=no, location=no, status=no, scrollbars=yes, resizable=yes');
}

function jump(target, width, height, link){
	switch(target){
		case '_self':
			location.href = link;
			break;
		default:
			var size = new Array();
			var resultSize = '';
			if(width != 0){
				size.pop('width='+width);
			}
			if(height != 0){
				size.pop('height='+height);
			}
			if(size.length!=0){
				resultSize = size.join(',');
				window.open(link,'GrandLisboa_Pop_Up',resultSize);
			}else{
				window.open(link,'GrandLisboa_Pop_Up');
			}
			break;
	}
}

function flashModal(){
	$("#flashmodal").keypress();
}

function trim(str){
	return str.replace(/(^[\s+]|[\s+]$)/, '');
}
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
/* Finally, let's start trying to figure out if the supplied address is
   valid. */
/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
	 even fit the general mould of a valid e-mail address. */
	return false
}
var user=matchArray[1]
var domain=matchArray[2]
// See if "user" is valid 
if (user.match(userPat)==null) {
	// user is not valid
	return false
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
	// this is an IP address
	  for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
		return false
		}
	}
	return true
}
// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	return false
}
/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */
/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
	domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return false
}
// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   return false
}
// If we've gotten this far, everything's valid!
return true;
}