﻿// JavaScript Document
var g_agt = navigator.userAgent.toLowerCase();
var is_opera = (g_agt.indexOf("opera") != -1);
function exist(s)
{
	return $(s)!=null;
}
function myInnerHTML(idname, html)
{
	if (exist(idname))
	{
		$(idname).innerHTML = html;
	}
}

function dialog(v_w, v_h, v_title /*, v_needhead*/)
{
	var width = v_w;
	var height = v_h;
	var title = v_title;
	g_title = title;
	
	var sBox = '\
		<div id="dialogBox" style="display:none;z-index:19999;width:'+width+'px;height:'+height+'">\
			<div class="ts3" >\
				';
	var sClose = '<a href="javascript:" onclick="javascript:new dialog().close();">close</a>';
	sBox +=	'\
								<div id="dialogBoxTitle" class="ts31">'+title+'</div>\
								<div id="dialogClose" class="ts32">' + sClose + '</div>\
						   </div>\
						   <div id="dialogBody" style="height:' + (height-35) + 'px; "></div>\
	';
	sBox += '\
			</div>\
		</div><div id="dialogBoxShadow" style="display:none;z-index:19998;"></div>\
	';
	
	var sIfram = '\
		<iframe id="dialogIframBG" name="dialogIframBG" frameborder="0" marginheight="0" marginwidth="0" hspace="0" vspace="0" scrolling="no" style="position:absolute;z-index:19997;display:none;"></iframe>\
	';
	
	var sBG = '\
		<div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;"></div>\
	';
	
	this.init = function()
	
	{
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		
		
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		if (!is_opera)
		{
			oDiv.innerHTML = sBG + sIfram + sBox;
		}
		else
		{
			oDiv.innerHTML = sBG + sBox;
		}
		document.body.appendChild(oDiv);
	}

	this.open = function(_sUrl)
	{		
		this.show();
		var openIframe = "<iframe width='100%' height='100%' name='iframe_parent' id='iframe_parent' src='" + _sUrl + "' frameborder='0' scrolling='auto'></iframe>";
		myInnerHTML('dialogBody', openIframe);
	}

	this.show = function()
	{
		this.middle('dialogBox');
		if ($('dialogIframBG'))
		{
			$('dialogIframBG').style.top = $('dialogBox').style.top;
			$('dialogIframBG').style.left = $('dialogBox').style.left;
			$('dialogIframBG').style.width = $('dialogBox').offsetWidth + "px";
			$('dialogIframBG').style.height = $('dialogBox').offsetHeight + "px";
			$('dialogIframBG').style.display = 'block';
		}
		if (!is_opera) {
			this.shadow();
		}
	}
	
	this.reset = function()
	{
		this.close();
	}

	this.close = function()
	{
		if (window.removeEventListener) 
		{
			window.removeEventListener('resize', this.event_b, false);
			window.removeEventListener('scroll', this.event_b, false);
		} 
		else if (window.detachEvent) 
		{
			try {
				window.detachEvent('onresize', this.event_b);
				window.detachEvent('onscroll', this.event_b);
			} catch (e) {}
		}
		if ($('dialogIframBG')) {
			$('dialogIframBG').style.display = 'none';
		}
		$('dialogBox').style.display='none';
		$('dialogBoxBG').style.display='none';
		$('dialogBoxShadow').style.display = "none";
		if (typeof(parent.onDialogClose) == "function")
		{
			parent.onDialogClose($('dialogBoxTitle').innerHTML);
		}
	}

	this.shadow = function()
	{
		this.event_b_show();
		if (window.attachEvent)
		{
			window.attachEvent('onresize', this.event_b);
			window.attachEvent('onscroll', this.event_b);
		}
		else
		{
			window.addEventListener('resize', this.event_b, false);
			window.addEventListener('scroll', this.event_b, false);
		}
	}
	
	this.event_b = function()
	{
		var oShadow = $('dialogBoxShadow');
		
		if (oShadow.style.display != "none")
		{
			if (this.event_b_show)
			{
				this.event_b_show();
			}
		}
	}
	
	this.event_b_show = function()
	{
		var oShadow = $('dialogBoxShadow');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['display']	= "";		
		oShadow['style']['opacity']	= "0.5";
		oShadow['style']['filter'] = "alpha(opacity=50)";
		oShadow['style']['background']	= "#000";
		var sClientWidth = parent ? parent.document.body.offsetWidth : document.body.offsetWidth;
		var sClientHeight = parent ? parent.document.body.offsetHeight : document.body.offsetHeight;
		var sScrollTop = parent ? (parent.document.body.scrollTop+parent.document.documentElement.scrollTop) : (document.body.scrollTop+document.documentElement.scrollTop);
		oShadow['style']['top'] = '0px';
		oShadow['style']['left'] = '0px';
		oShadow['style']['width'] = sClientWidth + "px";
		oShadow['style']['height'] = (sClientHeight + sScrollTop) + "px";
	}

	this.middle = function(_sId)
	{
		$(_sId)['style']['display'] = '';
		$(_sId)['style']['position'] = "absolute";

		var sClientWidth = parent.document.body.clientWidth;
		var sClientHeight = parent.document.body.clientHeight;
		var sScrollTop = parent.document.body.scrollTop+parent.document.documentElement.scrollTop;

		var sleft = (sClientWidth - $(_sId).offsetWidth) / 2;
		var iTop = sScrollTop + 60;
		var sTop = iTop > 0 ? iTop : 0;

		$(_sId)['style']['left'] = sleft + "px";
		$(_sId)['style']['top'] = sTop + "px";
	}
}

function openWindow(_sUrl, _sWidth, _sHeight, _sTitle /*,_sNeedHead*/)
{
	if(typeof arguments[4] != "undefined")
	{
		var oEdit = new dialog(_sWidth, _sHeight, _sTitle, arguments[4]);
	}
	else
	{
		var oEdit = new dialog(_sWidth, _sHeight, _sTitle);
	}
	oEdit.init();
	oEdit.open(_sUrl);
}



function frm_submitonce(theform)
{
  if (document.all||document.getElementById)
  {
    for (i=0;i<theform.length;i++)
    {
      var tempobj=theform.elements[i]
      if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="image") { tempobj.disabled=true; }
    }
  }
}

var xmlHttp = false;
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}

function callServer(sType,sValue,valCode) {
  if ((sValue == null) || (sValue == "")) return;
  var url = "/ajax/?type=" + escape(sType)+"&value="+escape(sValue)+"&valcode="+escape(valCode);
  xmlHttp.open("GET", url, false);
  xmlHttp.send(null);  
 //alert(unescape(xmlHttp.responseText));
  return xmlHttp.responseText;
  //callServer=xmlHttp.responseText;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

	var HeaderMenu = function(_name){
		var name = _name;	
		var viewDelay = 100;
		var closeDelay = 200;
		var parentId="";
		var viewTimer;
		var closeTimer;
		var targetObj;
		this.viewLayer = function(idnum) {
			if(parentId!=""&&idnum!=parentId)	this.closeLayerImpl(parentId);
			parentId=idnum;
			clearTimeout(closeTimer);
			viewTimer = setTimeout(name + ".viewLayerImpl(" + idnum+ ")", viewDelay);
		},
		this.viewLayerImpl = function(idnum){
			
			var obj = document.getElementById("menu" + idnum);
			obj.className = "on";
		},					
		this.closeLayer = function(idnum) {
			clearTimeout(viewTimer);
			closeTimer = setTimeout(name + ".closeLayerImpl(" + idnum + ")", closeDelay);
		},
		this.closeLayerImpl = function(idnum){
			var obj = document.getElementById("menu" + idnum);
		    obj.className = "";
		} 						
	}
var myMenu = new HeaderMenu("myMenu");


/*静态页面下的下拉导航菜单*/
function subMenu()
{
	var sBox = '\
	<div id="submenuBody" class="subnav" style="display:none;z-index:19998;" onMouseOver="display_menu();" onMouseOut="close_sub_menu();">\
	</div>\
	';
	this.init = function()	
	{
		$("submenuBox").innerHTML= sBox;
	}
	
	this.show = function(_objID)
	{
		$('submenuBody')['style']['display'] = '';
        var l;
		var t;
	    var e;
		e=$(_objID);	
        l=e.offsetLeft;   
        t=e.offsetTop+e.offsetHeight;   
        while (e['nodeName'] != "BODY")
		{ 
		 e = e.offsetParent;
		 if ( e['nodeName'] != 'FORM')
		 {
            l += e.offsetLeft;  
            t += e.offsetTop; 
		  }
        }
		$('submenuBody')['style']['left'] = l + "px";
		$('submenuBody')['style']['top'] = t + "px";
	}
	
	this.reset = function()
	{
		this.close();
	}

	this.close = function()
	{

		$('submenuBody').style.display='none';
		
	}

}
function ShowSubMenu(aType)
{
	var Arry;
	var subArry;
	var SubMenu_Content;
	var tmp_html;
	tmp_html='<ul>';
	
	switch(aType)
	{
		case 1:
		     for (i=0; i<games.length; i++){
				 Arry=games[i].split("|||");
				 for(j=1;j<Arry.length;j++){
					 subArry=Arry[j].split(":");
					 if(subArry[2]=="a"){
						SubMenu_Content=Arry[0].split(":");
						tmp_html+='\
						            <li><a href="/powerleveling_list.asp?id=' + SubMenu_Content[1] + '">' + SubMenu_Content[0] + '</a></li>\
						          ';
						break;
					 }
				 }
			 }
		     break;

		case 2:
		     for (i=0; i<games.length; i++){
				 Arry=games[i].split("|||");
				 for(j=1;j<Arry.length;j++){
					 subArry=Arry[j].split(":");
					 if(subArry[2]=="b"){
						SubMenu_Content=Arry[0].split(":");
						tmp_html+='\
						            <li><a href="/currency_list.asp?id=' + SubMenu_Content[1] + '">' + SubMenu_Content[0] + '</a></li>\
						          ';
						break;
					 }
				 }
			 }
		     break;
			 
		case 3:
		     for (i=0; i<games.length; i++){
				 Arry=games[i].split("|||");
				 for(j=1;j<Arry.length;j++){
					 subArry=Arry[j].split(":");
					 if(subArry[2]=="c" || subArry[2]=="d" || subArry[2]=="e"){
						SubMenu_Content=Arry[0].split(":");
						tmp_html+='\
						            <li><a href="/items_list.asp?id=' + SubMenu_Content[1] + '">' + SubMenu_Content[0] + '</a></li>\
						          ';
						break;
					 }
				 }
			 }
		     break;
	}
	
	tmp_html+='</ul>';
	var oEdit = new subMenu ();
	oEdit.init();
	oEdit.show("menu_"+aType);
	myInnerHTML('submenuBody', tmp_html);
}

function display_menu()
{
	    //$(objID).className='on';
		$('submenuBody')['style']['display'] = '';
		//$('submenuBody')['style']['position'] = "absolute";	
}
function close_sub_menu()
{
	new subMenu().close();
	//$(strVar).className='';
	//var ArryNode=new Array();
	//ArryNode=$('menu').getElementsByTagName('a');
	//for(i=0;i<ArryNode.length;i++)
	//{
		//if(ArryNode[i].className=='on'){
			//ArryNode[i].className='';
			//return;
		//}
	//}

}
function showGmMenu(li_Index){
  var menus=$$('#gm_menu li');
  menus.each(function(section, index){
            if( index !== li_Index ) {
                section.className='';
            }else{
                section.className='on';
            };
        }, this);
}

