/*
global variable for
$(selector).mouseover()
*/
var mouseX = 0;
var mouseY = 0;

var global_timer = null;
var current_show_layer = new String;

var usingIE = false;
var usingIEold = false;
var usingFF = false;
var usingSF = false;
var usingCR = false;
var usingIPhone = false;
var usingIPad = false;
var usingMAC = false;

if(navigator.userAgent.indexOf('Macintosh')>0)
	usingMAC = true;
if(navigator.userAgent.indexOf('iPhone')>0)		//the sequence is very important
	usingIPhone = true;
else if(navigator.userAgent.indexOf('iPad')>0)
	usingIPad = true;
else if(navigator.userAgent.indexOf('Chrome')>0)
	usingCR = true;
else if(navigator.userAgent.indexOf('Safari')>0)			
	usingSF = true;
else if(navigator.userAgent.indexOf('Firefox')>0)
	usingFF = true;
else if(navigator.userAgent.indexOf('MSIE')>0) {
	usingIE = true;
	if(navigator.userAgent.indexOf('MSIE 6.0')>0 || navigator.userAgent.indexOf('MSIE 7.0')>0 || navigator.userAgent.indexOf('MSIE 8.0')>0)
		usingIEold = true;
}

var actionAfterClose = null;	//run after showHide();
Array.prototype.getUniqueValues=function(){var h = new Object();for(j=0; j<this.length; j++)h[this[j]] = true;var a=new Array();for(v in h)a.push(v);return a;}
String.prototype.trim=function(){return this.replace(/^\s*|\s*$/g,"");}
String.prototype.substr_count=function(s){var r=0;for(var i=0;i<this.length;i++){if(s==this.substr(i,s.length))r++;}return r;}
function getFileExtension(f){return(/[.]/.exec(f)) ? /[^.]+$/.exec(f) : undefined;}
function getFileName(f){return f.replace(/^.*(\\|\/|\:)/, '');}
function realTypeOf(obj) {return Object.prototype.toString.call(obj).slice(8, -1);} 
function removeHTMLTags(s){s=s.replace(/&(lt|gt);/g,function(strMatch,p1){return (p1=="lt")?"<":">";});return s.replace(/<\/?[^>]+(>|$)/g,"");}
function padzero(n,l){var s=''+n;while(s.length<l){s='0'+s;}return s;}
function getToday(){var d=new Date();return d.getFullYear() + "-" + padzero((d.getMonth()+1),2) + "-" + padzero(d.getDate(),2);}
function getNow(){var d=new Date();return d.getFullYear() + "-" + padzero((d.getMonth()+1),2) + "-" + padzero(d.getDate(),2) + " " + padzero(d.getHours(),2) + ":" + padzero(d.getMinutes(),2)+ ":" + padzero(d.getSeconds(),2);}
function isDigit(e,min,max){if(e==null)return false;if(min!=null && e.value.length<min)return false;if(max!=null && e.value.length>max)return false;var r=new RegExp("^[0-9]+$");return r.test(e.value);}
function isID(s){if(s==null||s.length<1)return true;var r=new RegExp("^[0-9A-Za-z_.()#-]+$");return r.test(s);}
function getObject(id){

	if(document.getElementById){
		return document.getElementById(id);
	}
	else if(document.all){
		return document.all[id];
	}
	return null;
}

function getElement(f,n){for(i=0;i<f.elements.length;i++){e=f.elements[i];if(e.name==n)return e;}}

function debug()
{
	var ret = new String();
	for(var i=0; i<arguments.length; i++)
		ret += '[' + arguments[i] + ']\n';
    alert(ret);
}

function charDebug(str)
{
	var ret = new String();
	for(var i=0; i<str.length; i++)
		ret += i + ' [' + str.substring(i, i+1) + ']\n';
	alert(ret);
}
function runningInFrame(d){try{if(top.location.href===location.href){return false;}else if(top.location.hostname.toString()!==d){return true;}}catch(error){return true;}return false;} 
var afterCloseAction = new String();
function showMesg(HTMLmesg, offsetX, offsetY, absolute_position)
{
	var bsd = getObject('blackoutScreenDIV');
	if(HTMLmesg==null || HTMLmesg==0) {
		jQuery("#facebox").fadeOut();
		if(bsd!=null)
			jQuery("#blackoutScreenDIV").fadeOut();
		if(afterCloseAction!=null && afterCloseAction.length>0)
			eval(afterCloseAction);
		return;
	}
	HTMLmesg = "<table cellpadding=0 cellspacing=0 border=0>" +
				"<TR><TD align=right height=20 valign=top><a href=# onClick='showMesg(); return false;'><img src=/v1/_image/cross2.gif border=0></a></td>" +
				"<tr><TD>" + HTMLmesg + "</td></table>";

	jQuery("#faceboxContent").html(HTMLmesg);

	if(absolute_position!=null && absolute_position=='blackout') {
		jQuery('#blackoutScreenDIV').css({'opacity':0.5, 'width':jQuery(document).width(), 'height':jQuery(document).height()});   	
		jQuery('#blackoutScreenDIV').fadeIn('fast');
	}

	if(offsetX!=null) {
		if(absolute_position==null)
			jQuery("#facebox").css("left", mouseX+offsetX);
		else if(absolute_position!='center' && absolute_position!='blackout')
			jQuery("#facebox").css("left", offsetX);
	}
	if(offsetY!=null) {
		if(absolute_position==null)
			jQuery("#facebox").css("top", mouseY+offsetY);
		else if(absolute_position=='center' || absolute_position=='blackout') {
			jQuery("#facebox").center();
		} else
			jQuery("#facebox").css("top", offsetY);
	}
	if( jQuery("#facebox").css("display")=='none' ) {
		jQuery("#facebox").fadeIn();
	}
}

/* a cleverer version */
function showMesgV2(HTMLmesg, obj)
{
	if(jQuery('#div_mesgbox').length<1) {
		jQuery("<div id='div_mesgbox' style='position:absolute; display:none;'><table width=240 height=80 cellpadding=3 cellspacing=0 border=0 bgcolor=white style='border: 2px solid #96a6c0'><TR><TD align=right height=20 valign=top><a href=# onClick='showMesg(); return false;'><img class=moi src=/v1/_image/btn-close.gif border=0 title='Close 關閉'></a></td><TR><TD id=cell_mesg valign=middle align=center></td></table></div>").appendTo("body")
		jQuery(".moi").moi();
	}
	var dm = jQuery('#div_mesgbox');
	if(HTMLmesg==null) {
		dm.hide();
		jQuery('#cell_mesg').html('');
		if(afterCloseAction!=null && afterCloseAction.length>0) {
			eval(afterCloseAction);
			afterCloseAction = null;
		}
		return;
	}

	jQuery('#cell_mesg').html(HTMLmesg);
	if(obj==null)
		dm.center();
	else {
		var x = jQuery(obj).offset().left;
		var y = jQuery(obj).offset().top - dm.height();
		dm.css('left', x);
		dm.css('top', y);
	}
	dm.show();
}
function getQueryString(p){p=p.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]").toLowerCase();var r="[\\?&]"+p+"=([^&#]*)";var rx=new RegExp(r);var rr=rx.exec(window.location.href.toLowerCase());if(rr==null)return "";else return rr[1];} 
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function getCheckedValue2(f,en){if(f==null	|| en==null || en.length<0)return "";var r=0;for(i=0;i<f.elements.length;i++) {e=f.elements[i];if(e.name==en && (e.type=='checkbox'||e.type=='radio')&&e.checked)r+=parseInt(e.value);}return r;}
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
//remove duplciated values and split into correct lines
function normalizeInput(obj, delimiter)
{
	if(delimiter==null)
		delimiter = "\n";
	ret = obj.value.trim().split(/\s|[^A-Za-z0-9_.@-]/).getUniqueValues();
	ret.sort();
	obj.value = ret[0];
	for(i=1; i<ret.length; i++)
		obj.value += delimiter + ret[i];
}

function validateEmail(elementValue){   
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
   return emailPattern.test(elementValue);   
}  

function verifyEmail(formElement, mesgDIV)
{
	if(mesgDIV==null)
		return validateEmail(formElement.value);
	else {
		getObject(mesgDIV).innerHTML = "";
	}

	if(formElement.value==null || formElement.value.length<1)
		return;

	if(!validateEmail(formElement.value)) {
		formElement.focus();
		//formElement.value = '';
		getObject(mesgDIV).innerHTML = "Invalid Email address!";
	}
}
function MM_preloadImages() {var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src=a[i];}}}
function getImageRealDim(src){var t=new Image();t.src = src;return new Array(t.width, t.height);}
function reloadImg(id){var o=document.getElementById(id);if(o==null){alert('No image to reload');return false;}var s=o.src;var p=s.indexOf('?');if(p>=0){s=s.substr(0,p);}var d=new Date();o.src =s+'?v='+d.getTime();return false;}

function openWin(url, w, h, name)
{
	if(w==null || w==0)		w = screen.width - 50;
	else if(w>screen.width)	w = screen.width;

	if(h==null || h==0)      h = screen.height - 150;
	else if(h>screen.height)  h = screen.height;

	if(name==null || name.length<1)
		name = 'newwin';
	
	var l = (screen.width - w) / 2; 
	var t = (screen.height - h) / 2 ;
	//alert(t + ',' + l);

	win = window.open(url, name, "width=" + w + ",height=" + h + ",top="+t+",left="+l+"resizable=1,scrollbars=1,status=1");
	if(win==null) {
		var lang=1;
		var pos = url.indexOf("LANG=");
		if(pos>0)
			lang = url.substr(pos+5, 1);
		if(lang==2)
			alert('对不起, 请容许浏览器跳出窗口或按着 Ctrl 再点');
		else if(lang==3)
			alert('對不起, 請容許瀏覽器彈出視窗或按著 Ctrl 再點擊');
		else
			alert('Sorry, please allow Pop-up on your Browser or hold Ctrl and click again');
	} else
		win.focus()
}

// make windows full screen
function maxWindow()
{
	window.moveTo(0,0);
	if(document.all) {
		top.window.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
		{
			top.window.outerHeight = screen.availHeight;
			top.window.outerWidth = screen.availWidth;
		}
	}
}

//return the top or left position of a given object
function getposOffset(overlay, offsettype){
	var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
	var parentEl=overlay.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
/*
function showHideLayer(obj, status, coordRefID) 
{
	var subobj = getObject(obj);
	if(subobj==null)	return;

	if(coordRefID!=null) {
		var cf = getObject(coordRefID);
		var xpos = getposOffset(cf, "left")
		var ypos = getposOffset(cf, "top")
		subobj.style.left = xpos + "px";
		subobj.style.top = ypos + "px";
	}

	if(status!=null) {
		if(status=='block' || status=='none') {
			subobj.style.display = status;
			return;
		}
	}

	if( subobj.style.display == "block") {
		subobj.style.display = "none";
	} else {
		subobj.style.display = "block";
	}
}
*/
//simple show hide effect by jQuery
function showHide(layer_name, ref_obj, offset_x, offset_y, ie_adjust_x, ie_adjust_y)
{
	var d = jQuery('#' + layer_name).css('display');
	if(d=='none') {
		//check if other layer is shown
		if(current_show_layer!=null && current_show_layer.length>0) {
			jQuery('#'+current_show_layer).hide();
			current_show_layer = '';
		}

		if(ref_obj!=null) {
			var x = jQuery(ref_obj).offset().left;
			var y = jQuery(ref_obj).offset().top;
			if(offset_x!=null)					x += offset_x;
			if(usingIE && ie_adjust_x!=null)	x += ie_adjust_x;
			if(offset_y!=null)					y += offset_y;
			if(usingIE && ie_adjust_y!=null)	y += ie_adjust_y;
			jQuery('#' + layer_name).css('left', x);
			jQuery('#' + layer_name).css('top', y);
		}
		jQuery('#' + layer_name).fadeIn();
		current_show_layer = layer_name;
	} else {
		if(jQuery("#blackoutScreenDIV").length>0)
			jQuery("#blackoutScreenDIV").fadeOut();
		jQuery('#' + layer_name).fadeOut();
		
		if(current_show_layer==layer_name)
			current_show_layer = '';

		if(actionAfterClose!=null) {
			eval(actionAfterClose);
			actionAfterClose = null;
		}
	}
}

function showLayer(dest, src)
{
	var srcHTML = jQuery('#' + src).html();
	jQuery('#'+dest).hide();
	jQuery('#'+dest).html(srcHTML);
	jQuery('#'+dest).fadeIn();
}

function convertFormData(f){if(f==null || f.elements==null){return;}var postString="";for(i=0;i<f.elements.length;i++){e=f.elements[i];if((e.type=='radio' || e.type=='checkbox')&&!e.checked)continue;if(e.name.length>0 && e.value.length>0)postString=postString+e.name+'='+EncodeParm(e.value)+'&';}return postString.slice(0,-1);}
function clearForm(formObj)
{
	for(i=0; i<formObj.elements.length; i++) {
		e = formObj.elements[i];
		if(e.type=='hidden' || e.type=='button' || e.type=='submit')
			continue;
		if(e.type=='select-one')
			e.selectedIndex = 0;
		else if(e.type=='checkbox' || e.type=='radio')
			e.checked = false
		else {
			e.value = '';
		}
	}
}

function checkAll(formObj, v) 
{
	for(i=0; i<formObj.elements.length; i++) {
		e = formObj.elements[i];
		if(e.type=='checkbox')
			e.checked = v;
	}
}
 
//http://techpatterns.com/downloads/javascript_cookies.php
function Set_Cookie(name, value, expires, path, domain, secure) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	//if the expires variable is set, make the correct 
	//expires time, the current script below will set 
	//it for x number of days, to make it for hours, 
	//delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	var cookieStr = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) +  ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
//	alert(cookieStr);
	document.cookie = cookieStr;
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
		return null;
}

function changeLang(l)
{
	var url = self.location.href;
	if(l>0 && l<4) {
		pos = url.indexOf("LANG=");
		if(pos>0)
			self.location.href = url.substr(0, pos) + 'LANG=' + l + url.substr(pos+6);
		else {
			pos = url.indexOf("?");
			if(pos>0)
				self.location.href = url + '&LANG=' + l;
			else
				self.location.href = url + '?LANG=' + l;
		}
	}
	return;
}

//useful when transferring data by AJAX
//http://www.webtoolkit.info/javascript-url-decode-encode.html
function urlEncode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";
 	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
 		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return escape(utftext);
}

function EncodeParm(str)
{
	var ret = encodeURI(str);
	ret = ret.replace(/&amp;/g, "%26");
	ret = ret.replace(/&/g, "%26");
	return ret.replace(/[+]/g, "%2B");
}
function tradSimpConvert(s, o, is){showWaiting(1);var p='t='+EncodeParm(s);if(is!=null)p+='&isSimp=1';AJAXconnect('/v5/admin/ajax-simptrad.php', p, tsc_cb, o);}
function tsc_cb(o){showWaiting();o.value = ajax_request.responseText;}

/******** general function for fetching dynamic result by HTTP *********/
// IMPORTANT: for firefox/netscape, this works only when file is on the server. local calling has no effect
function httpConnect(url, objInnerHTML, objValue, alertString)
{
	var xmlhttp = null;
	if (window.XMLHttpRequest)
		xmlhttp = new XMLHttpRequest();
	else if (window.ActiveXObject)
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 
	//does not support XMLHTTP, use popup instead
	if (xmlhttp == null)
	{
		alert("Please use IE6.0 or above to visit this site.\n请使用 IE 6.0 或更高版本 (1)");
	}
	else {
		xmlhttp.open("GET", url, true);
		xmlhttp.onreadystatechange = function(){ 

			if (xmlhttp.readyState != 4)
				return; 
			if (xmlhttp.status == 200)
			{
				if(objInnerHTML!=null)
					objInnerHTML.innerHTML = xmlhttp.responseText;
				else if(objValue!=null) 
					objValue.value = xmlhttp.responseText;
				else if(alertString!=null) 
					alert(alertString + xmlhttp.responseText);
				// it cannot return value. value is passed by reference.
			} 
			else
			{
				alert("Please use IE6.0 or above to visit this site.\n请使用 IE 6.0 或更高版本 (2)");
			}
		}
		xmlhttp.send(null);
	}
}

//http://www.captain.at/howto-ajax-form-post-request.php
var http_request = false;
function makePOSTRequest(url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if(!http_request) {
		alert('There is some problem with your browser. Cannot create XMLHTTP instance. We are going to send your message in traditional way!');
		document.form1.action = 'contactusSend.php';
		document.form1.submit();
		return false;
	}
  
	http_request.onreadystatechange = httpPostRequestHandler;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
var ajax_request=false;
function AJAXconnect(u,p,hf,hfp){ajax_request=false;if(window.XMLHttpRequest){ajax_request=new XMLHttpRequest();if(ajax_request.overrideMimeType){ajax_request.overrideMimeType('text/html');}}else if(window.ActiveXObject){try{ajax_request=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{ajax_request=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}}}if(!ajax_request){alert('Error AJAXconnect()');return false;}ajax_request.onreadystatechange=function(){if(ajax_request.readyState==4){if(ajax_request.status==200){hf(hfp);}else{alert('Error AJAXconnect()2');}}};ajax_request.open('POST', u, true);ajax_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');ajax_request.setRequestHeader('Content-length', p.length);ajax_request.setRequestHeader('Connection', 'close');ajax_request.send(p);}
function submitFormAJAX(url, formObj, handlerFunction, handlerFunctionParam, debug) {
	var xhr = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		xhr = new XMLHttpRequest();
		if (xhr.overrideMimeType) {
			xhr.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if(!xhr) {
		alert('Error submitFormAJAX(). AJAX function not available.');
		showWaiting();
		return false;
	}
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 200) {
				handlerFunction(xhr.responseText, handlerFunctionParam);
			} else {
				alert('Error submitFormAJAX(). No response from url. ('+xhr.status+')');
				showWaiting();
			}
		} 
	}
	var parameters = convertFormData(formObj) + '&dummy=' + new Date().getTime();
	if(debug!=null)
		alert(parameters);

	xhr.open('POST', url, true);
	//xhr.timeout = 5000;
	xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhr.setRequestHeader("Content-length", parameters.length);
	xhr.setRequestHeader("Connection", "close");
	xhr.send(parameters);
}

//////////////////////////////////////////// tool tips function

function showTips(url, lang)
{
	var subobj = document.getElementById('tipsBox');
	if(subobj==null)
		return;

	subobj.style.width = 600;
	subobj.style.height = 300;

	if(usingIE) {
		subobj.style.left = 260; //(document.body.clientWidth - parseInt(subobj.style.width))/2;
		subobj.style.top = (document.body.clientHeight - parseInt(subobj.style.height))/2;
	} else {
		subobj.style.left = 260; //(window.innerWidth - parseInt(subobj.style.width))/2;
		subobj.style.top = (window.innerHeight - parseInt(subobj.style.height))/2;
	}
	httpConnect('http://www.pandaoffice.com/v1/ajax/tooltips.php?url='+url+'&LANG='+lang, subobj);

	// you must display it only when it really has content. displaying an empty DIV causes problems in IE7.
	setTimeout( function() 
		{
			if(subobj.innerHTML.length>0) {
				subobj.style.display = "block";
			} 
		}, 
	500); 
}

function closeToolTips(url, lang)
{
	var subobj = document.getElementById('tipsBox');
	if(subobj==null)
		return;

	if(url=='noMoreTips') {
		httpConnect('http://www.pandaoffice.com/v1/ajax/tooltips.php?action=closed&url='+url+'&LANG='+lang, subobj);
	} else {
		subobj.style.display = "none";
		if(url!=null)
			httpConnect('http://www.pandaoffice.com/v1/ajax/tooltips.php?action=closed&url='+url);
	}
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

if(typeof jQuery != 'undefined') {
	jQuery.fn.center = function () {     
		this.css("position", "absolute");     
		this.css("top", (jQuery(window).height() - this.height() ) / 2 + jQuery(window).scrollTop() + "px");     
		this.css("left", (jQuery(window).width() - this.width() ) / 2 + jQuery(window).scrollLeft() + "px");     
		return this; 
	} 

	jQuery.fn.slideLeftHide = function( speed, callback ) { this.animate( { width: "hide", paddingLeft: "hide", paddingRight: "hide", marginLeft: "hide", marginRight: "hide" }, speed, callback ); } 
	jQuery.fn.slideLeftShow = function( speed, callback ) { this.animate( { width: "show", paddingLeft: "show", paddingRight: "show", marginLeft: "show", marginRight: "show" }, speed, callback ); }

	jQuery.fn.moi = function() {
		this.hover(
			function() {
				jQuery(this).fadeTo(400, 0.7);
				var filename = jQuery(this).attr("src");
				if(filename.indexOf('-over.')<0) {
					var src = jQuery(this).attr("src").match(/[^\.]+/) + "-over." + getFileExtension(filename);         
					jQuery(this).attr("src", src); 
				}
				//show_search_box(1);
			},
			function() {
				jQuery(this).fadeTo(200, 1);
				var src = jQuery(this).attr("src").replace("-over", "");   
				jQuery(this).attr("src", src); 
			}
		);
	}

	//dim for every kind of image when mouseover EXCEPT for PNG in IE
	jQuery.fn.moi_dim = function () {     
		this.hover(
			function() {
				var extension = getFileExtension( jQuery(this).attr("src") );
				if(extension=='png' && usingIEold)
					return;
				jQuery(this).fadeTo(400, 0.7);
			},
			function() {
				var extension = getFileExtension( jQuery(this).attr("src") );
				if(extension=='png' && usingIEold)
					return;
				jQuery(this).fadeTo(200, 1);
			}
		);
	} 

	//dim for every kind of image when mouseover
	jQuery.fn.moi_dim2 = function () {     
		this.hover(
			function() {
				jQuery(this).fadeTo(400, 0.7);
			},
			function() {
				jQuery(this).fadeTo(200, 1);
			}
		);
	} 

	//you need to put a table containing those images
	jQuery.fn.moi_selected = function() {
		var currentClicked_id = new String();
		this.click(function(){
			currentClicked_id = jQuery(this).attr('id');
			jQuery(this).fadeTo(10, 1);

			jQuery(this).parents("TABLE").find("IMG").each(function(){
				var obj = jQuery(this);
				if(obj.attr('id')!=currentClicked_id) {
					var src = obj.attr("src").replace("-over", "");   
					obj.attr("src", src); 
				}
			});

		})
		this.hover(
			function() {
				var id = jQuery(this).attr("id");
				if(currentClicked_id!=id) {
					jQuery(this).fadeTo(400, 0.7);
					var filename = jQuery(this).attr("src");
					if(filename.indexOf('-over.')<0) {
						var src = jQuery(this).attr("src").match(/[^\.]+/) + "-over." + getFileExtension(filename);    
						jQuery(this).attr("src", src); 
					}
				} 
			},
			function() {
				var id = jQuery(this).attr("id");
				if(currentClicked_id!=id) {
					jQuery(this).fadeTo(200, 1);
					var src = jQuery(this).attr("src").replace("-over", "");   
					jQuery(this).attr("src", src); 
				} 
			}
		);
	}

}

//the following requires   getMouseXY(e) to be activated and must have the following HTML code at the bottom of the document
//<div id="waitingDIV" style="position:absolute; display:none; top: 0px; left: 0px; width=100%; height=100%;"><table width=100% bgcolor=white><TR><TD align=center><img src=/v1/_image/loading.gif></td></table></div>
function showWaiting(mode)
{
	var obj = getObject('waitingDIV');
	if(obj==null)	{
		if(typeof jQuery=='undefined') { 
			alert("showWaiting cannot find \'waitingDIV\'");
			return;
		} else {
			jQuery("<div id='waitingDIV' style='position:absolute; display:none; top: 0px; left: 0px;'><table width=1024><TR bgcolor=#eeeeee><TD align=center><img src=/_image/loading.gif></td></table></div>").appendTo("body")
			obj = getObject('waitingDIV');		
		}
	}
	if(mode==null || mode==0)
		obj.style.display = 'none';
	else {
		if(typeof jQuery!='undefined') { 
			jQuery("#waitingDIV").children().css('width', jQuery(window).width());
			jQuery("#waitingDIV").center();
		} else if(mouseY!=null && mouseY>0) {
			var y = mouseY + 25;
			obj.style.top = y + 'px';
		}
		obj.style.display = 'block';
	}
}

//////////////////////////////////////////////////////////// Clubbing Shanghai //////////////////////////////////////////////

function loadPage(url) {

	window.location.hash = '/#test12345.html';
	return false;
	alert(url);
/*
	if(url.substr(0,27) == "http://anshul.lessthan3.com") {
        url = url.substr(27);
    }
    else if(url.substr(0,23) == "http://qa.lessthan3.com") {
        url = url.substr(23);
    }
    else if(url.substr(0,20) == "http://lessthan3.com") {
        url = url.substr(20);
    }
    else if(url != "") {
        window.open(url, '_blank');
        return false;
    }
    if(url.substr(0,1) == "/") {
        url = url.substr(1);
    }
    _gaq.push(['_trackPageview', url]);
*/

    // if reloading page, force load since hashchange won't trigger
    if(window.location.hash == "#!/" + url) {
		alert( location.hash.substring(3) );
//        loadPageContent(location.hash.substring(3), false);
    }
	alert(url);
    window.location.hash = "!/" + url;
    return false;
}

function set_overlay_text(ref_id, offsetX, offsetY, htmltext, width, height)
{
	var div_overlaytext = 'div_' + ref_id + '_overlaytext';
	if(getObject(div_overlaytext)==null) {
		jQuery("<div id='" + div_overlaytext + "' style='position:absolute; display:block; top: 0px; left: 0px; background-image: url(_image/bk-80.png); width:" + width + "px; height:" + height + "px;'></div>").appendTo("body")
	}
	jQuery('#' + div_overlaytext).html('<table width=100% height=100% cellpadding=0 cellspacing=0 border=0><TR><TD valign=middle class=song>' + htmltext + '</td></table>');
	var x = jQuery('#' + ref_id).offset().left + offsetX;
	var y = jQuery('#' + ref_id).offset().top + offsetY;
	jQuery('#' + div_overlaytext).css('left', x);
	jQuery('#' + div_overlaytext).css('top', y);
}

var windowWidth = 0;
function cell_article_text()
{
	if(jQuery(window).width()==windowWidth) {
		;
	} else {
		windowWidth = jQuery(window).width();
		setTimeout("cell_article_text()", 500);
	}
}

function toggleExpand(no, obj, name)
{
	if(name==null)
		name = '#scroll_bottom_feed'
	else
		name = '#scroll_' + name + '_feed'

	var j = jQuery(name + '_' + no);
	var h = j.css('height');
	var sbf = jQuery(name);
	var ref_point = sbf.offset().top;
	var org_overview_top = jQuery(name + " .overview").offset().top - ref_point;
	var org_scrollthumb_top = jQuery(name + " .thumb").offset().top - ref_point;
	var ratio = sbf.get_tinyscrollbar_ratio();   /* scrollbar ratio before expand/collapse */
	var expand = false;
		
	if(h=='130px') {
		h = parseInt(j.children("TABLE").css('height'));
		if(h<130)	h = 130;
		j.css('height', h);
		jQuery(obj).find("IMG").attr('src', '_image/btn-minus.gif');
		expand = true;
	} else {
		j.css('height', 130);
		jQuery(obj).find("IMG").attr('src', '_image/btn-plus.gif');
		expand = false;
	}
	sbf.tinyscrollbar_update();

	/* reposition the view window, and scrollbar: after tinyscrollbar_update(), the scrollthumb and overview move to the top by default. this functions
	   allows them to stay in the original position before expand/collapse
	*/
	sbf.adjust_tinyscrollbar(org_overview_top, org_scrollthumb_top, ratio, expand);
}

/* automatically remove controls (minus/plus button) for record (table) of height less than 130px */
function toggleExpand_init(name)
{
	var cell_class = '.cells_toggleExpand';
	if(name==null) {
		name = '#scroll_bottom_feed_';
	} else {
		name = '#scroll_' + name + '_feed_';
		cell_class = '.cells_toggleExpand_' + name;
	}
	jQuery(cell_class).each(function(index) {
		var no = index+1;
		var	h = parseInt( jQuery(name+no).children("TABLE").css('height') );
		if(h<=130)
			$(this).html('<img src=_image/spacer.gif height=11>');
	});
}

/****************************************************** Index page *******************************************/
/* Index page cell_video rotation control */
var rotate_index_video_timer = null;
var rotate_index_video_seq = 1;
var stopRotate = false;

function change_index_video_image(no)
{
	if(no==null){
		return;
	}
	jQuery("#cell_video").hide();
	var html = jQuery('#data_cell_video' + no).html();
	jQuery("#cell_video").html(html);
	jQuery("#cell_video").fadeIn();
	jQuery(".moi").moi_dim();
}

function rotate_index_video()
{
	if(!stopRotate) 
	{
		rotate_index_video_seq++;
		if(rotate_index_video_seq>4)	rotate_index_video_seq=1;
		change_index_video_image(rotate_index_video_seq);
	}
	rotate_index_video_timer = setTimeout("rotate_index_video()", 5000);
}
/* End of Index page cell_video rotation control */


function init_index()
{
	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_bottom_feed").tinyscrollbar();

	jQuery(".moi").moi_dim();
	jQuery('#div_coverscroll').coverscroll({
		minfactor:8,	
  		distribution:1
	});
	jQuery("#scroll_trend").tinyscrollbar();
	jQuery("#scroll_coolstuff").tinyscrollbar();
	clearTimeout(rotate_index_video_timer);
	rotate_index_video_timer = setTimeout("rotate_index_video()", 5000);
	
}
/* End of Index page functions */


/************************************************ Nightlife */
var toggleScrollbar_state = new Array();
toggleScrollbar_state[1] = 1;
toggleScrollbar_state[2] = 0;
toggleScrollbar_state[3] = 0;

function toggleScrollbar(no, obj)
{
	//find the scroll bar div name
	var id_prefix = "#scroll_article_";
	if(jQuery("#scroll_nightlife_1").length>0) 
		id_prefix = "#scroll_nightlife_";

	if(toggleScrollbar_state[no]==1) {
		toggleScrollbar_state[no] = 0;
		jQuery(id_prefix + no + " .scrollbar").hide();
		jQuery(id_prefix + no + " .viewport").css('height', 170);
		jQuery(id_prefix + no).css('height', 170);
		jQuery(obj).find("IMG").attr('src', '_image/btn-plus.gif');
	} else {
		toggleScrollbar_state[no] = 1;
		jQuery(id_prefix + no + " .scrollbar").show();
		jQuery(id_prefix + no + " .viewport").css('height', 420);
		jQuery(id_prefix + no).css('height', 420);
		jQuery(id_prefix + no).tinyscrollbar();
		jQuery(obj).find("IMG").attr('src', '_image/btn-minus.gif');
	}
}

function init_nightlife()
{
	jQuery(".moi").moi_dim();

	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_bottom_feed").tinyscrollbar();

	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_nightlife_1").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_nightlife_1").tinyscrollbar();
}
/* End of Nightlife */

/* Music */
function init_music()
{
	jQuery(".moi").moi_dim();

	if(usingSF || usingCR) {
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_search_music").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_article_1").tinyscrollbar();', 1000);
	} else {
 		jQuery("#scroll_bottom_feed").tinyscrollbar();
 		jQuery("#scroll_search_music").tinyscrollbar();
		jQuery("#scroll_article_1").tinyscrollbar();
	}
}
/* End of Music */



/* Agenda */
function init_agenda()
{
	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_bottom_feed").tinyscrollbar();

	jQuery(".moi").moi_dim();
}
/* End of Agenda */



/* Clubbing Pro */
function init_clubbingpro()
{
	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_bottom_feed").tinyscrollbar();

	jQuery(".moi").moi_dim();
}
/* End of Clubbing Pro */


/* Promoter */
function init_promoter()
{
	if(usingSF || usingCR) {
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_native_feed").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_follows").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_friends").tinyscrollbar();', 1000);
		setTimeout('jQuery("#scroll_partners").tinyscrollbar();', 1000);
	} else {
		jQuery("#scroll_bottom_feed").tinyscrollbar();
		jQuery("#scroll_native_feed").tinyscrollbar();
		jQuery("#scroll_follows").tinyscrollbar();
		jQuery("#scroll_friends").tinyscrollbar();
		jQuery("#scroll_partners").tinyscrollbar();
	}

	jQuery(".moi").moi_dim();
	toggleExpand_init('native');
}
/* End of Promoter */


/* Artist Profile */
function init_profile_focus()
{
	jQuery(".profile").focus(function()
	{  
		$(this).removeClass("profile").addClass("profile_focus");
		init_profile_focus();
	});
	jQuery(".profile_focus").blur(function()
	{  
		$(this).removeClass("profile_focus").addClass("profile");
		init_profile_focus();
	});
}

function init_artistprofile()
{
	if(usingSF || usingCR) {
		setTimeout('jQuery("#scroll_youmaylove").tinyscrollbar();', 1000);
	} else {
		jQuery("#scroll_youmaylove").tinyscrollbar();
	}
	init_profile_focus();
	jQuery(".moi").moi_dim();
}
/* Artist Profile */


/* Gallery */
var cell_gallery_big_photo_mouseover = false;
function show_gallery_big_photo_arrow(right)
{
	clearTimeout(global_timer);
	if(!cell_gallery_big_photo_mouseover)	return;
	var w = jQuery('#cell_gallery_big_photo').width()/2;
	var x = mouseX - jQuery('#cell_gallery_big_photo').offset().left;
	if(x<w) {
		jQuery('#cell_gallery_big_photo_left_arrow').slideLeftShow(300);
	} else {
		jQuery('#cell_gallery_big_photo_right_arrow').animate({left: "394px", "opacity": "show", width:"70px"}, 300); 
	}

	jQuery("#cell_gallery_big_photo").mousemove(function(event) {
		if(!cell_gallery_big_photo_mouseover) {
			jQuery('#cell_gallery_big_photo_left_arrow').slideLeftHide(100);
			jQuery('#cell_gallery_big_photo_right_arrow').animate({left: "464px", "opacity": "hide", width:"0px"}, 100); 
		} else {
			var x = event.pageX - jQuery(this).offset().left;
			if(x<w) {
				jQuery('#cell_gallery_big_photo_left_arrow').slideLeftShow(300);
				jQuery('#cell_gallery_big_photo_right_arrow').animate({left: "464px", "opacity": "hide", width:"0px"}, 300); 
			} else {
				jQuery('#cell_gallery_big_photo_left_arrow').slideLeftHide(300);
				jQuery('#cell_gallery_big_photo_right_arrow').animate({left: "394px", "opacity": "show", width:"70px"}, 300); 
			}
		}
	});
}

function init_gallery()
{
	jQuery(".moi").moi_dim();

	if(usingSF || usingCR)
		setTimeout('jQuery("#scroll_bottom_feed").tinyscrollbar();', 1000);
	else
		jQuery("#scroll_bottom_feed").tinyscrollbar();

	jQuery('#cell_gallery_big_photo').hover(  
		function () {
			cell_gallery_big_photo_mouseover = true;
			global_timer = setTimeout("show_gallery_big_photo_arrow()", 500);
			jQuery("#cell_gallery_big_photo").mousemove(function(event) {
				mouseX = event.pageX;
			});
		}, 
		function () {
			jQuery("#cell_gallery_big_photo").unbind('mousemove')
			cell_gallery_big_photo_mouseover = false;
			jQuery('#cell_gallery_big_photo_left_arrow').slideLeftHide(100);
			jQuery('#cell_gallery_big_photo_right_arrow').animate({left: "464px", "opacity": "hide", width:"0px"}, 100); 
	});
}
/* End of Gallery */

function handleArrowKeys(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if(evt) {
        switch (evt.keyCode) {
			case 27:		//ESC
				if(current_show_layer!=null && current_show_layer.length>0) {
					showHide(current_show_layer);
				}
				break;
			case 13:		//Enter
				break;
            case 38:
                break;    
            case 40:
                break;    
        }
	}
}


document.onkeyup = handleArrowKeys;


jQuery(document).ready(function($) {
	if(self.location.href.indexOf('index-v1.html')>0)
		init_index();
	else if(self.location.href.indexOf('agenda.html')>0) {
		init_agenda();
	}
	else if(self.location.href.indexOf('artistprofile.html')>0) {
		init_artistprofile();
	}
	else if(self.location.href.indexOf('clubbingpro.html')>0) {
		init_clubbingpro();
	}
	else if(self.location.href.indexOf('gallery.html')>0) {
		init_gallery();
	}
	else if(self.location.href.indexOf('music.html')>0) {
		init_music();
	}
	else if(self.location.href.indexOf('nightlife.html')>0) {
		init_nightlife();
	}
	else if(self.location.href.indexOf('promoter.html')>0) {
		init_promoter();
	}
	toggleExpand_init();
})





