﻿var IE = /*@cc_on!@*/false;
function E$(d) { return document.getElementById(d); }
function D$(e,d) { E$(e).style.display=d; }

function isdefined(variable) {
    return (typeof(window[variable]) == "undefined")?  false: true;
}

function iscms() {
	return (typeof(pgconfig_hidpid_id) === 'undefined')?false:true;
}

function isie6() {
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   return (version >= 5.5 && version < 7);
}

function iever() {
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   return version;
}

function isiphone() {
	if ((navigator.userAgent.match(/iPhone/i)) )
		return true;
	else return false;
}

function isipad() {
	if ((navigator.userAgent.match(/iPad/i)) )
		return true;
	else return false;
}

function isiphoneipad() {
	if ((navigator.userAgent.match(/iPhone/i)) ||  (navigator.userAgent.match(/iPad/i)))
		return true;
	else return false;
}

function isNum(value){
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(value)) return true;
	return false;
}

function randomSort(a,b) {    
    var temp = parseInt( Math.random()*10 ); // Get a random number between 0 and 10    
    var isOddOrEven = temp%2; // Get 1 or 0, whether temp is odd or even    
    var isPosOrNeg = temp>5 ? 1 : -1; // Get +1 or -1, whether temp greater or smaller than 5    
    return( isOddOrEven*isPosOrNeg ); // Return -1, 0, or +1
}

function stamptodate(t) {
	var yr=t.substr(0,4);
	var mt=t.substr(4,2)-1;
	var dy=t.substr(6,2);
	var hr=t.substr(8,2);
	var mi=t.substr(10,2);
	return new Date(yr,mt,dy,hr,mi,0,0);
}	  

function getnewsdatefmt(s) {
	var f = "";
	if (s.indexOf('y')>=0) f+=".Y";
	if (s.indexOf('m')>=0) f+=".m";
	if (s.indexOf('d')>=0) f+=".d";		
	if (f.length>0) f=f.substr(1);
	return f;
}

function setnewsdate() {
	$(".date").each( function() { 
		var d = stamptodate($(this).text()); 
		var s = $(this).attr('dtdisp');
		$(this).text(d.format( getnewsdatefmt(s) )); 
	} );
}

function trim(str, chars) {	return ltrim(rtrim(str, chars), chars); }
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/*function gosearch() {
	var v = trim($("#searchtxtbox").val());
	if (v!="" && v!="--- Search by keyword ---") {
		location.href="/result.aspx?key="+$("#searchtxtbox").val();
		//return true;
	} //else return false;
}*/

function gosearch(lang) {
	var v = trim($("#searchtxtbox").val());
	if (v!="" && v!="--- Search by keyword ---" && v != "--- 请输入搜寻字 ---") {
		location.href="/result.aspx?key="+$("#searchtxtbox").val()+"&lang="+lang;
		//return true;
	} //else return false;
}
function entersearch(c,lang) {

	if (c == 13) { gosearch(lang); 	return false; }
}
function setsearch(lang) {	
	$("#searchlnk").attr("href","javascript:gosearch('"+lang+"');");
	$("#searchtxtbox").focus( function() {
		if (trim($("#searchtxtbox").val()) == "--- Search by keyword ---" || trim($("#searchtxtbox").val()) == "--- 请输入搜寻字 ---")
			$("#searchtxtbox").val("");
	});
	$("#searchtxtbox").blur( function() {
	    var search_text="--- Search by keyword ---";
		if (trim($("#searchtxtbox").val()) == ""){
		    switch(lang){
		        case 'en':search_text="--- Search by keyword ---";
		        break;
		        case 'sc':search_text="--- 请输入搜寻字 ---";
		        break;
		        
		        default:search_text="--- Search by keywords ---";
		        break;
		    }
			$("#searchtxtbox").val(search_text);
			}
	});	
}

function adjustPgWidth() {
	if ($(window).width()<955) {
		$('.centerpage').css('left','0px').css('margin-left','0px');
		$('#footersitemapholder').width(955);
	} else {
		$('.centerpage').css('left','50%').css('margin-left','-481px');
		$('#footersitemapholder').width($(window).width());
	}
}
				
function popiframe(popupUrl, popupWidth, popupHeight) {
	var content = '<iframe id="frameTiny" src="' + popupUrl + '" width="100%" height="'+popupHeight+'" scrolling="no" frameborder="no" marginwidth="0" marginheight="0"></iframe>';
	TINY.box.show(content, 0, popupWidth, popupHeight, 0);		
}
    							

function pop_contactform() { pop_form("",'en'); }	
function pop_contactform(lang) { pop_form("",lang); }			

function pop_form(f) { var q=(f=="")?"":"?f="+f; popiframe("/contactform.aspx"+q,700,700); }
function pop_form(f,lang) { var q=(f=="")?"":"&f="+f; popiframe("/contactform.aspx?lang="+lang+q,700,700); }


function track_enews(pdf) {
	if (isdefined('pageTracker')) pageTracker._trackPageview('/downloads/enewsletter/'+pdf);
}

function track_doc(doc) {
	if (isdefined('pageTracker')) pageTracker._trackPageview('/downloads/others/'+doc);
}

function track_event(cat,act,lbl) {
	if (isdefined('_gaq')) _gaq.push(['_trackEvent', cat, act, lbl]);
}
//tiny box
var TINY={};function T$(c){return document.getElementById(c)}
TINY.box=function(){var c,h,g,k,l,m,n,o,p=0;return{show:function(a,b,d,e,i,f){if(!p){c=document.createElement("div");c.id="tinybox";h=document.createElement("div");h.id="tinymask";g=document.createElement("div");g.id="tinycontent";document.body.appendChild(h);document.body.appendChild(c);c.appendChild(g);h.onclick=TINY.box.hide;window.onresize=TINY.box.resize;p=1}if(!i&&!b){c.style.width=d?d+"px":"auto";c.style.height=e?e+"px":"auto";c.style.backgroundImage="none";g.innerHTML=a}else{g.style.display=
"none";c.style.width=c.style.height="100px"}this.mask();k=a;l=b;m=d;n=e;o=i;this.alpha(h,1,80,3);f&&setTimeout(function(){TINY.box.hide()},1E3*f)},fill:function(a,b,d,e,i){if(b){c.style.backgroundImage="";var f=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");f.onreadystatechange=function(){f.readyState==4&&f.status==200&&TINY.box.psh(f.responseText,d,e,i)};f.open("GET",a,1);f.send(null)}else this.psh(a,d,e,i)},psh:function(a,b,d,e){if(e){if(!b||!d){e=c.style.width;
var i=c.style.height;g.innerHTML=a;c.style.width=b?b+"px":"";c.style.height=d?d+"px":"";g.style.display="";b=parseInt(g.offsetWidth);d=parseInt(g.offsetHeight);g.style.display="none";c.style.width=e;c.style.height=i}else g.innerHTML=a;this.size(c,b,d)}else c.style.backgroundImage="none"},hide:function(){TINY.box.alpha(c,-1,0,3)},resize:function(){TINY.box.pos();TINY.box.mask()},mask:function(){h.style.height=TINY.page.total(1)+"px";h.style.width="";h.style.width=TINY.page.total(0)+"px"},pos:function(){var a=
TINY.page.height()/2-c.offsetHeight/2;a=a<10?10:a;c.style.top=a+TINY.page.top()+"px";c.style.left=TINY.page.width()/2-c.offsetWidth/2+"px"},alpha:function(a,b,d){clearInterval(a.ai);if(b==1){a.style.opacity=0;a.style.filter="alpha(opacity=0)";a.style.display="block";this.pos()}a.ai=setInterval(function(){TINY.box.ta(a,d,b)},20)},ta:function(a,b,d){var e=Math.round(a.style.opacity*100);if(e==b){clearInterval(a.ai);if(d==-1){a.style.display="none";a==c?TINY.box.alpha(h,-1,0,2):g.innerHTML=c.style.backgroundImage=
""}else a==h?this.alpha(c,1,100):TINY.box.fill(k,l,m,n,o)}else{b=Math.ceil(e+(b-e)*(IE?1:0.5));b=b==1?0:b;a.style.opacity=b/100;a.style.filter="alpha(opacity="+b+")"}},size:function(a,b,d){a=typeof a=="object"?a:T$(a);clearInterval(a.si);var e=a.offsetWidth,i=a.offsetHeight,f=e-parseInt(a.style.width),j=i-parseInt(a.style.height),q=e-f>b?0:1,r=i-j>d?0:1;a.si=setInterval(function(){TINY.box.ts(a,b,f,q,d,j,r)},20)},ts:function(a,b,d,e,i,f,j){d=a.offsetWidth-d;f=a.offsetHeight-f;if(d==b&&f==i){clearInterval(a.si);
c.style.backgroundImage="none";g.style.display="block"}else{if(d!=b){b=d+(b-d)*0.5;a.style.width=e?Math.ceil(b)+"px":Math.floor(b)+"px"}if(f!=i){b=f+(i-f)*0.5;a.style.height=j?Math.ceil(b)+"px":Math.floor(b)+"px"}this.pos()}}}}();
TINY.page=function(){return{top:function(){return document.documentElement.scrollTop||document.body.scrollTop},width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},total:function(c){var h=document.body,g=document.documentElement;return c?Math.max(Math.max(h.scrollHeight,g.scrollHeight),Math.max(h.clientHeight,g.clientHeight)):Math.max(Math.max(h.scrollWidth,
g.scrollWidth),Math.max(h.clientWidth,g.clientWidth))}}}();


// Steve's Ultimate Date Library
// copyright Stephen Chapman 6th May 2009
// instructions for use - http://www.felgall.com/datemethods.htm
// permission to use this JavaScript on your web page is granted
// provided that all of the code below in this script (including these
// comments) is used without any alteration
Date.prototype.addDays = function(days) {this.setDate(this.getDate()+days);};Date.prototype.addMonths = function(months) {this.setMonth(this.getMonth()+months);};Date.prototype.addYears = function(years) {this.setFullYear(this.getFullYear()+years);};Date.prototype.addHours = function(hours) {this.setHours(this.getHours()+hours);};Date.prototype.addMinutes = function(minutes) {this.setMinutes(this.getMinutes()+minutes);};Date.prototype.addSeconds = function(seconds) {this.setSeconds(this.getSeconds()+seconds);};Date.prototype.addPeriod = function(y,m,d,h,i,s) {this.addYears(y); this.addMonths(m); this.addDays(d); this.addHours(h); this.addMinutes(i); this.addSeconds(s);};Date.prototype.dayDiff = function(d2) {var d= Math.abs(this-d2);return Math.floor(d/(86400000));};Date.prototype.busDayDiff = function(d2) {var d = this.dayDiff(d2); var t= d%7;if (this < d2) {w1= this.getDay(); w2= d2.getDay();}else {w2= this.getDay(); w1= d2.getDay();} if (w1 > w2) t-=2;if ((w1 == 0 && w2 == 6) || w1 == 6) t--;return Math.abs((Math.floor(d/7)*5)+t);};Date.prototype.ageLastBirthday = function(dob) {var cy = this.getFullYear();var by = dob.getFullYear();var db = new Date(dob);db.setFullYear(cy);var adj = (this-db<0) ? 1 : 0;return cy - by - adj;};Date.prototype.isBetween = function(d1, d2) {return (this > Math.min(d1,d2) && this < Math.max(d1,d2));};Date.prototype.getSDay = function() {return (this.getDay() + 1) %7;};Date.prototype.getMDay = function() {return (this.getDay() + 6) %7;};Date.prototype.getISOYear = function() {var thu = new Date(this.getFullYear(),this.getMonth(),this.getDate()+3-this.getMDay());return thu.getFullYear();};Date.prototype.getISOWeek = function() {var onejan = new Date(this.getISOYear(),0,1);var wk = Math.ceil((((this - onejan) / 86400000) + onejan.getMDay()+1)/7);if (onejan.getMDay() > 3) wk--;return wk;};Date.prototype.getJulian = function() {return Math.floor((this / 86400000) - (this.getTimezoneOffset()/1440) + 2440587.5);};Date.prototype.getMonthName = function() {var m = ['January','February','March','April','May','June','July','August','September','October','November','December'];return m[this.getMonth()];};Date.prototype.getMonthShort = function() {var m = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];return m[this.getMonth()];};Date.prototype.getDayName = function() {var d = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];return d[this.getDay()];};Date.prototype.getDayShort = function() {var d = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];return d[this.getDay()];};Date.prototype.getOrdinal = function() {var d = this.getDate();switch(d) {case 1: case 21: case 31: return 'st'; case 2: case 22: return 'nd'; case 3: case 23: return 'rd'; default: return 'th';}};Date.prototype.getDOY = function() {var onejan = new Date(this.getFullYear(),0,1);return Math.ceil((this - onejan) / 86400000);}; Date.prototype.getWeek = function() {var onejan = new Date(this.getFullYear(),0,1); return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);};Date.prototype.getStdTimezoneOffset = function() {var jan = new Date(this.getFullYear(), 0, 1); var jul = new Date(this.getFullYear(), 6, 1); return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());}; Date.prototype.getDST = function() {return this.getTimezoneOffset() < this.getStdTimezoneOffset();};Date.prototype.getSwatch = function() {var swatch = ((this.getUTCHours() + 1)%24) + this.getUTCMinutes()/60 +  this.getUTCSeconds()/3600; return Math.floor(swatch*1000/24);};function _daysInMonth(month,year) {var dd = new Date(year, month, 0);return dd.getDate();};Date.prototype.format = function(f) {var fmt = f.split(''); var res = ''; for (var i = 0, l = fmt.length; i < l; i++) {switch(fmt[i]) {case '^':  res += fmt[++i]; break;  case 'd': var d = this.getDate();  res += ((d<10)?'0':'')+d;  break; case 'D': res += this.getDayShort(); break; case 'j': res += this.getDate(); break; case 'l': res += this.getDayName(); break; case 'S': res += this.getOrdinal(); break; case 'w': res += this.getDay(); break; case 'z': res += this.getDOY() - 1; break;  case 'R': var dy = this.getDOY(); if (dy<9) dy = '0'+dy; res += (dy > 99)? dy : '0'+dy; break; case 'F': res += this.getMonthName(); break; case 'm': var m = this.getMonth()+1; res += ((m<10)?'0':'')+m;  break; case 'M': res += this.getMonthShort(); break; case 'n': res += (this.getMonth()+1); break; case 't': res += _daysInMonth(this.getMonth()+1, this.getFullYear()); break; case 'L': res += (_daysInMonth(2, this.getFullYear()) == 29)? 1:0; break; case 'Y': res += this.getFullYear(); break; case 'y': var y = this.getFullYear().toString().substr(3); res += ((y<10)?'0':'')+y; break; case 'a': res += (this.getHours()>11)?'pm':'am'; break; case 'A': res += (this.getHours()>11)?'PM':'AM'; break; case 'g': var h = this.getHours()%12; res += (h==0)?12:h; break; case 'G': res += this.getHours(); break; case 'h': var h = this.getHours()%12; res += (h==0)?12:(h>9)?h:'0'+h; break; case 'H': var h = this.getHours(); res += (h>9)?h:'0'+h; break; case 'i': var m = this.getMinutes(); res += (m>9)?m:'0'+m; break; case 's': var s = this.getSeconds(); res += (s>9)?s:'0'+s; break; case 'O': var m = this.getTimezoneOffset(); var s = (m<0)?'+':'-'; m = Math.abs(m); var h = (m/60).toFixed(0); m = m%60; res += s + ((h>9)?h:'0'+h) + ((m>9)?m:'0'+m); break; case 'P': var m = this.getTimezoneOffset(); var s = (m<0)?'+':'-'; m = Math.abs(m); var h = (m/60).toFixed(0); m = m%60; res += s + ((h>9)?h:'0'+h) + ':' + ((m>9)?m:'0'+m); break; case 'U': res += (this.getTime()/1000).toFixed(0); break; case 'I': res += this.getDST() ? 1:0; break; case 'K': res += this.getDST() ? 'DST':'Std'; break; case 'c': res += this.format('Y-m-d^TH:i:sP'); break; case 'r': res += this.format('D, j M Y H:i:s P'); break; case 'Z': var tz = this.getTimezoneOffset() * -60; res += tz; break; case 'W': res += this.getISOWeek(); break; case 'X': res += this.getWeek(); break;  case 'x': var w = this.getWeek();res += ((w<10)?'0':'')+w; break;  case 'B': res += this.getSwatch(); break;  case 'N':  var d = this.getDay(); res += d?d:7; break; case 'u': res += this.getMilliseconds()*1000; break; case 'o':  res += this.getISOYear(); break; case 'J': res += this.getJulian(); break; case 'e': case 'T': break;  default: res += fmt[i];}}return res;}
