// JavaScript Document

function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

star={};

star.mouse=function(e,o) { if(star.stop || isNaN(star.stop)) { star.stop=0;

	document.onmousemove=function(e) { var n=star.num;
	
		var p=abPos($('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

		if(oX<1 || oX>84 || oY<0 || oY>19) { star.stop=1; star.revert(); }
		
		else {

			$S('starCur'+n).width=oX+'px';
			$S('starUser'+n).color='#111';
			$('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
		}
	};
} };

star.update=function(e,o) { var n=star.num, v=parseInt($('starUser'+n).innerHTML);

	n=o.id.substr(4); $('starCur'+n).title=v;

	req=new XMLHttpRequest(); req.open('GET','/AJAX_Star_Vote.php?vote='+(v/100),false); req.send(null);    

};

star.revert=function() { var n=star.num, v=parseInt($('starCur'+n).title);

	$S('starCur'+n).width=Math.round(v*84/100)+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';
	
	document.onmousemove='';

};

star.num=0;


		
// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/
function sprintf()
{
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
					var param = arguments[numSubstitutions];
					var pad = '';
					       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
					  else if (pPad) pad = pPad;
					var justifyRight = true;
					       if (pJustify && pJustify === "-") justifyRight = false;
					var minLength = -1;
					       if (pMinLength) minLength = parseInt(pMinLength);
					var precision = -1;
					       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
					var subst = param;
					       if (pType == 'b') subst = parseInt(param).toString(2);
					  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
					  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
					  else if (pType == 'u') subst = Math.abs(param);
					  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
					  else if (pType == 'o') subst = parseInt(param).toString(8);
					  else if (pType == 's') subst = param;
					  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
					  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}
		

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function refresh_verifycode() {
	var img_src = imageDomain + 'authimage.php?r='+Math.random();
	if ($('img_verifycode') != null) {
		$('img_verifycode').src = img_src;
	}
	if ($('img_verifycode_ticket') != null) {
		$('img_verifycode_ticket').src = img_src;
	}
}


function showPopup(element_id,event){
  var div = createElement("div");  
  div.id = "popup";
  //div.style.display="none";
  var popup = $(element_id);
  //
  var evt = event ? event : (window.event ? window.event : null);  
  var x = Event.pointerX(evt)+5;
  var y = Event.pointerY(evt)+5;
  div.innerHTML='\
        <table style="top:' + y + 'px; left:' + x + 'px;" class="popup">\
          <tbody>\
            <tr>\
              <td class="corner" id="topleft"></td>\
              <td class="top"></td>\
              <td class="corner" id="topright"></td>\
            </tr>\
            <tr>\
              <td class="left"></td>\
              <td><table class="popup-contents">\
                <tbody>\
                    <tr>\
                      <td>' + popup.innerHTML + '</td>\
                    </tr>\
                </tbody>\
              </table></td>\
              <td class="right"></td>\
            </tr>\
            <tr>\
              <td id="bottomleft" class="corner"></td>\
              <td class="bottom"><!--<img src="/images/bubble-tail2.png" alt="popup tail" height="29" width="30">--></td>\
              <td class="corner" id="bottomright"></td>\
            </tr>\
          </tbody>\
        </table>';
  document.body.appendChild(div);
  //Element.show("popup");
}

function hidePopup(){
  Element.remove("popup");
}

function createElement(element) {
    if (typeof document.createElementNS != 'undefined') {
        return document.createElementNS('http://www.w3.org/1999/xhtml', element);
    }
    if (typeof document.createElement != 'undefined') {
        return document.createElement(element);
    }
    return false;
}

// mouse over e // 
function _m_over(o) {
	g(o).style.border='1px solid #999999';
	g(o).style.backgroundColor='#CCFFFF';
}
function _m_out(o) {
	g(o).style.border='1px solid #FFFFFF';
	g(o).style.backgroundColor='#FFFFFF';
}

function g(o){return document.getElementById(o);} 

function HoverLi(n, t){ 
	for(var i=1;i<=t;i++){
		g('tb_'+i).className='normaltab';
		g('tbc_0'+i).className='undis';
	}
	g('tbc_0'+n).className='dis';
	g('tb_'+n).className='tabs-selected'; 
}

		
function roundFun(numberRound, roundDigit)
{
	var digit;
	digit = Math.pow(10, roundDigit);
	return (Math.round(numberRound * digit)/digit);
}

function setCookie(name,value,expires,path,cookie_domain,secure)
{
	var expDays = expires * 24 * 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + expDays);
	var expString = ((expires == null) ? "" : (";expires = " + expDate.toGMTString()))
	var pathString = ((path == null) ? "/" : (";path=" + path))
	var domainString = ((cookie_domain == null) ? "" : (";domain=" + cookie_domain))
	var secureString = ((secure == true) ? ";secure" : "" )
	document.cookie = name + "=" + escape(value) + expString + pathString + domainString + secureString;
}

function getCookie(name)
{
	var result = null;
	var myCookie = document.cookie + ";";
	var searchName = name + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCookie;
	if (startOfCookie != -1)
	{
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";",startOfCookie);
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));
	}
	return result;
}

function delCookie(name)
{
	var ThreeDays = 3 * 24 * 60 * 60 * 1000;
	var expDate = new Date();
	expDate.setTime(expDate.getTime() - ThreeDays);
	document.cookie = name + "=;expires=" + expDate.toGMTString();
}



function verify_name(s)
{
	var patrn = /^[A-Z-_a-z]{2,128}$/;
	if (!patrn.exec(s)){
		return false;
	}else{
		return true;
	}
}
function verify_numeric(s)
{
	s = s.trim();
	// var patrn = /^[0-9]\d*$/;
	var patrn = /^\d+(\.\d+)?$/; 
	// var patrn = /^[-+]?\d*\.?\d*$/;
	if (!patrn.exec(s)){
		return false;
	}else{
		return true;
	}
}
function verifyEmail(s){
	// \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
	// \b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b
	var patrn = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	if (!patrn.exec(s)){
		return false;
	}else{
		 return true;
	}
}




function objdisplay(obj){
	if (obj.style.display == "block") {
		obj.style.display = "none";
	}else{
		obj.style.display = "block";
	}
}

function removemsg(t){
	if (t == 32){
		$('msg32').addClassName('hidden');
	}else{
		$('msg16').addClassName('hidden');
	}
}
function showmsg(t, s, msg){
	if (msg == null)
		msg = "";
	if (t == 32){
		objmsg = "msg32";
	}else{
		objmsg = "msg16";
	}
	if ($(objmsg) != null) {
		$(objmsg).removeClassName('hidden');
	}
	if(s==true){
		$('msg_content').removeClassName('f');
		$('msg_content').addClassName('t');
		$('msg_content').innerHTML = msg;
	}
	else{
		$('msg_content').removeClassName('t');
		$('msg_content').addClassName('f');
		$('msg_content').innerHTML = msg;
	}
}

/*swich the layer*/
function layerswich(){	
	if($('boxswitch') === null ) {return;}
	var e, i = 0;
	var evtType = $('boxswitch').getAttribute('evt');	
	while (e = $('boxswitch').getElementsByTagName ('DIV') [i++]) {
		if (e.className == 'on' || e.className == 'off') {
			if(evtType=='click'){
				e.onclick = function () {
					var getEls = $('layer_switch').getElementsByTagName('DIV');
						for (var z=0; z<getEls.length; z++) {
						getEls[z].className=getEls[z].className.replace('show', 'hide');
						getEls[z].className=getEls[z].className.replace('on', 'off');
						}
					this.className = 'on';
					var max = this.getAttribute('title');
					$(max).className = "show";
				}
			}
			else{
				e.onmouseover = function () {
					var getEls = $('layer_switch').getElementsByTagName('DIV');
						for (var z=0; z<getEls.length; z++) {
						getEls[z].className=getEls[z].className.replace('show', 'hide');
						getEls[z].className=getEls[z].className.replace('on', 'off');
						}
					this.className = 'on';
					var max = this.getAttribute('title');
					$(max).className = "show";
				}
			}
		}	
	}

}
/*swich the layer*/
function clicklayerswich(){	
	if($('boxswitch') == null ) return;
	var e, i = 0;
	while (e = $('boxswitch').getElementsByTagName ('DIV') [i++]) {
		if (e.className == 'on' || e.className == 'off') {
		e.onclick = function () {
			var getEls = $('layer_switch').getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
				getEls[z].className=getEls[z].className.replace('show', 'hide');
				getEls[z].className=getEls[z].className.replace('on', 'off');
				}
			this.className = 'on';
			var max = this.getAttribute('title');
			$(max).className = "show";
			}
		}		
	}
}
/* marque => bof*/
function srcMarquee(){
	this.ID = $(arguments[0]);
	if(!this.ID){this.ID = -1;return;}
	this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.Correct = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
	this.Step = 1;
	this.Timer = 30;
	this.DirectionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};
	if(typeof arguments[1] == "number")this.Direction = arguments[1];
	if(typeof arguments[2] == "number")this.Step = arguments[2];
	if(typeof arguments[3] == "number")this.Width = arguments[3];
	if(typeof arguments[4] == "number")this.Height = arguments[4];
	if(typeof arguments[5] == "number")this.Timer = arguments[5];
	if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
	if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
	if(typeof arguments[8] == "number")this.ScrollStep = arguments[8]
	this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
	this.ID.noWrap = false;
	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	if(arguments.length >= 7)this.Start();
}

srcMarquee.prototype.Start = function(){
	if(this.ID == -1)return;
	if(this.WaitTime < 800)this.WaitTime = 800;
	if(this.Timer < 20)this.Timer = 20;
	if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
	if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
	if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
	this.HalfWidth = Math.round(this.Width / 2);
	this.BakStep = this.Step;
	this.ID.style.width = this.Width;
	this.ID.style.height = this.Height;
	if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
	var msobj = this;
	var timer = this.Timer;
	var delaytime = this.DelayTime;
	var waittime = this.WaitTime;
	msobj.StartID = function(){msobj.Scroll()}
	msobj.Continue = function(){
		if(msobj.MouseOver == 1){
		setTimeout(msobj.Continue,delaytime);
     }
     else{ clearInterval(msobj.TimerID);
		msobj.CTL = msobj.Stop = 0;
		msobj.TimerID = setInterval(msobj.StartID,timer);
     }
    }
	msobj.Pause = function(){
		msobj.Stop = 1;
		clearInterval(msobj.TimerID);
		setTimeout(msobj.Continue,delaytime);
    }
	msobj.Begin = function(){
   msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth : msobj.ID.scrollHeight;
   if((msobj.Direction <= 1 && msobj.ClientScroll <msobj.Height) || (msobj.Direction > 1 && msobj.ClientScroll <msobj.Width))return;
   msobj.ID.innerHTML += msobj.ID.innerHTML;
   msobj.TimerID = setInterval(msobj.StartID,timer);
   if(msobj.ScrollStep < 0)return;
   msobj.ID.onmousemove = function(event){
       if(msobj.ScrollStep == 0 && msobj.Direction > 1){
			var event = event || window.event;
			if(window.event){
				if(msobj.IsNotOpera){msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : 

event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;}
				else{msobj.ScrollStep = null;return;}
			}
			else{msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;}
			msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
			msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
			msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
			}
		}
		msobj.ID.onmouseover = function(){
			if(msobj.ScrollStep == 0)return;
			msobj.MouseOver = 1;
			clearInterval(msobj.TimerID);
		}
		msobj.ID.onmouseout = function(){
		if(msobj.ScrollStep == 0){
			if(msobj.Step == 0)msobj.Step = 1;
			return;
		}
		msobj.MouseOver = 0;
		if(msobj.Stop == 0){
			clearInterval(msobj.TimerID);
			msobj.TimerID = setInterval(msobj.StartID,timer);
		}}}
		setTimeout(msobj.Begin,waittime);
}

srcMarquee.prototype.Scroll = function(){
	switch(this.Direction){
	case 0:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollTop >= this.ClientScroll){this.ID.scrollTop -= this.ClientScroll;}
		this.ID.scrollTop += this.Step;
	}
	break;

	case 1:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollTop <= 0){this.ID.scrollTop += this.ClientScroll;}
		this.ID.scrollTop -= this.Step;
	}
	break;

	case 2:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollLeft >= this.ClientScroll){this.ID.scrollLeft -= this.ClientScroll;}
		this.ID.scrollLeft += this.Step;
	}
	break;

	case 3:
	this.CTL += this.Step;
	if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
		this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
		this.Pause();
		return;
	}
	else{
		if(this.ID.scrollLeft <= 0){this.ID.scrollLeft += this.ClientScroll;}
	this.ID.scrollLeft -= this.Step;
	}
	break;
	}
} 
/* marque => eof*/


var openShow = false;
function show_need_help(obj){
	if(openShow) {
		close_need_help();
		return;
	}
	openShow = true;
	
	// need_help_name
	var msn = obj.getAttribute("msn");
	var str = "";
	var online = obj.getAttribute("online");
	
	if(msn!=null && msn != ""){
		str += 'MSN<br />&nbsp;&nbsp;<a target="_blank" href="http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=a2c736844e995112@apps.messenger.live.com&mkt=zh-cn"><img style="border-style: none;" src="http://messenger.services.live.com/users/a2c736844e995112@apps.messenger.live.com/presenceimage?mkt=zh-cn" width="16" height="16" align="absmiddle" />'+ msn +'</a>';
	}

	$('need_help_name').innerHTML = str;
		
	show('nh-mailbox');
	clearInterval(timer);
}

function close_need_help(){
	hide('nh-mailbox');
	marquee(3000, 15 ,0 ,'nav_need_help_lay');
	openShow = false;
}


/* marque => eof*/
var timer;
function marquee(delay, liHeight, toAlign, lyorderID){	
	var o=$(lyorderID);
	var timer_bug;
	for(i=0;i<o.childNodes.length;i++){
		if(o.childNodes[i].tagName == null){
			o.removeChild(o.childNodes[i]);			
		}
	}
	if(o==null) return;
	
	function scrollup(o,h,d){	
		if(d==h){
		   var t = o.firstChild;
		   o.appendChild(t);
		   t.style.marginTop=o.firstChild.style.marginTop='0px';
		   d = 0;
		}
		else{
		   var s=3,d=d+s,l=(d>=h?d-h:0);
		   o.firstChild.style.marginTop=-d+l+'px';
		   timer_bug = setTimeout(function(){scrollup(o,h,d-l)},20);
		}
	}
	timer = setInterval(function(){clearTimeout(timer_bug);scrollup(o,liHeight,toAlign);},delay);
}


function hide(el) {
	element = $(el);
	element.style.display = 'none';
}
function show(el) {
	element = $(el);
	element.style.display = '';
}
function remove(el){
	element = $(el);
	element.parentNode.removeChild(element);
}



/* Drpodown */
var dropDownMenu = Class.create();
dropDownMenu.prototype = {
	initialize:function(cls){
		this.cls = cls;
		this.init();
	},
	
	init:function(){
		$$(this.cls).each(function(o){
			o.observe("mouseover",function(e){
				o.down('div').setStyle({'display':'block'});
				o.down('a', 0).addClassName('dropdownItemHover');
			}.bind(this));
			o.observe("mouseout",function(e){
				o.down('div').setStyle({'display':'none'});
				o.down('a').removeClassName('dropdownItemHover');
			}.bind(this));
		}.bind(this));
	}
};

document.observe("dom:loaded",function(){
	var newMenu = new dropDownMenu(".ZHQ_dropdown");
});
/* End Dropdown */