/*****************************************************
 * ajaxload
 *****************************************************/	
function ajaxload(url, div)
{
	$('#'+div).html('');
	$('#'+div).load(url);
}

/*****************************************************
 * Request
 *****************************************************/	
function Request(sName)
{
  /*
   retrieve value before next //by33
  */
  
  var sURL = new String(window.location);
  var iQMark= sURL.lastIndexOf('?');
  var iLensName=sName.length;
  
  //retrieve loc. of sName
  var iStart = sURL.indexOf('?' + sName +'=') //limitation 1
  if (iStart==-1)
        {//not found at start
        iStart = sURL.indexOf('&' + sName +'=')//limitation 1
      if (iStart==-1)
         {//not found at end
          return 0; //not found
         }   
        }
        
  iStart = iStart + + iLensName + 2;
  var iTemp= sURL.indexOf('&',iStart); //next pair start
  if (iTemp ==-1)
      {//EOF
      iTemp=sURL.length;
      }  
  return sURL.slice(iStart,iTemp ) ;
  sURL=null;//destroy String
} 

/*****************************************************
 * cookie functions
 *****************************************************/	
function setcookie(name,value){
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}


function getcookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)){
		return unescape(arr[2]);
	}
	else{
		return null;
	}
}
/*****************************************************
 * achievement_flash
 *****************************************************/	
function check_achievement(){
	/*
	 var showen = getcookie(achievement_name+'_'+achievement_grade);
	
	 if(  achievement_grade != "" && showen != 1){
		 showAllFlash("http://my.850312.tming.tmc/images/sns_images/achievement.swf",800,218,1,"achievement_grade="+achievement_grade+"&achievement_name="+achievement_name);
	 }
	 setcookie(achievement_name+'_'+achievement_grade,1)*/
}
/*****************************************************
 * tooltip
 *****************************************************/	
function tooltip(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 200;
	var speed = 1000;
	var timer = 1;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	this.x = false;
	var o = this;
	o.x_x = false;
	
	return{
		show:function(v,w){
			if(this.x){
				if(tt == null){
					tt = document.createElement('div');
					tt.setAttribute('id',id);
					t = document.createElement('div');
					t.setAttribute('id',id + 'top');
					c = document.createElement('div');
					c.setAttribute('id',id + 'cont');
					b = document.createElement('div');
					b.setAttribute('id',id + 'bot');
					tt.appendChild(t);
					c.appendChild(b);
					tt.appendChild(c);
					
					document.body.appendChild(tt);
					tt.style.opacity = 0;
					tt.style.filter = 'alpha(opacity=0)';
					
					o.x_x = true;
					
					document.onmousemove = this.pos;
				}
				tt.style.display = 'block';
				c.innerHTML = v;
				tt.style.width = w ? w + 'px' : 'auto';
				if(!w && ie){
					t.style.display = 'none';
					b.style.display = 'none';
					tt.style.width = tt.offsetWidth;
					t.style.display = 'block';
					b.style.display = 'block';
				}
				if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
				h = parseInt(tt.offsetHeight) + top;
				clearInterval(tt.timer);
				tt.timer = setInterval(function(){tooltip.fade(1)},timer);
			
			}
		},
		pos:function(e){
			if( o.x_x ){
				var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
				var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;			
				tt.style.top = (u - h) + 'px';
				tt.style.left = (l + left) + 'px';
			}
		},
		fade:function(d){
			if( o.x_x ){
				var a = alpha;
				if((a != endalpha && d == 1) || (a != 0 && d == -1)){
					var i = speed;
					if(endalpha - a < speed && d == 1){
						i = endalpha - a;
					}else if(alpha < speed && d == -1){
						i = a;
					}
					alpha = a + (i * d);
					tt.style.opacity = alpha * .01;
					tt.style.filter = 'alpha(opacity=' + alpha + ')';
				}else{
					clearInterval(tt.timer);
					if(d == -1){tt.style.display = 'none'}
				}
			}
		},
		hide:function(){
			if( o.x_x ){
				clearInterval(tt.timer);
				tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
			}
		}
	};
}




/*****************************************************
 * topmenu
 *****************************************************/	
function drop(num){
	//alert($('#drop_menu'+num).attr('class'));
	if( $('#drop_menu'+num).hasClass('on') ){
		$('.nav_bg span').addClass('off');
	}else{
		$('#drop_menu1').addClass('off');
		$('#drop_menu2').addClass('off');
		$('#drop_menu3').addClass('off');
		$('#drop_menu4').addClass('off');
		$('#drop_menu'+num).attr('class','on');	
	}
}

document.onclick   = function (e){
	e = window.event || e;
	cur_o = e.srcElement || e.target;
	if (cur_o.className != 'drop')
	{
		if( $('.nav_bg span').hasClass('on') ){
			$('.nav_bg span').removeClass('on');
		}
	}

}
/*****************************************************
 * ShowFlash not for index
 *****************************************************/
function showFlash(iUrl,iWidth,iHeight,iWmode,flashVars)
{
	var myDate = new Date();
	var rand_time = myDate.getTime();
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ iWidth +'" height="' + iHeight +'"  id="lomowall" name="lomowall"/>';
	flash = flash + '<param name="movie" value="'+ iUrl +'" />';
	flash = flash + '<param name="allowScriptAccess" value="always" />';
	flash = flash + '<param name="quality" value="high" />';
	flash = flash + '<param name="menu" value="false" />';
	if(flashVars){
		flash = flash + '<param name="FlashVars" value='+flashVars+'&rtime'+rand_time+'" />';
	}
	if (iWmode == 1) {
	   flash = flash + '<param name="wmode" value="transparent" />';      
	}
	flash = flash + '<embed src="' + iUrl + '" width="'+ iWidth +'" height="'+ iHeight +'" menu="false" quality="high" ';
	if (iWmode == 1) {
	   flash = flash + 'wmode="transparent" ';      
	}
	flash = flash + ' pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" type="application/x-shockwave-flash" ';
	if(flashVars){
		flash = flash + 'flashvars="'+flashVars+'&rtime'+rand_time+'"';
	}
	flash = flash + ' mwode="transparent" name="lomowall" id="lomowall"></embed>';
	flash = flash + '</object>';
	
	document.writeln(flash); 
}


/*****************************************************
 * ShowFlash not for all
 *****************************************************/
function showAllFlash(iUrl,iWidth,iHeight,iWmode,flashVars)
{
	var flash = '<param name="movie" value="'+ iUrl +'" />';
	flash = flash + '<param name="allowScriptAccess" value="always" />';
	flash = flash + '<param name="quality" value="high" />';
	flash = flash + '<param name="menu" value="false" />';
	if(flashVars){
		flash = flash + '<param name="FlashVars" value="'+flashVars+'" />';
	}
	if (iWmode == 1) {
	   flash = flash + '<param name="wmode" value="transparent" />';      
	}
	flash = flash + '<embed src="' + iUrl + '" width="'+ iWidth +'" height="'+ iHeight +'" menu="false" quality="high" ';
	if (iWmode == 1) {
	   flash = flash + 'wmode="transparent" ';      
	}
	flash = flash + ' pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" type="application/x-shockwave-flash" ';
	if(flashVars){
		flash = flash + 'flashvars="'+flashVars+'"';
	}
	flash = flash + ' name="lomowall" id="lomowall"></embed>';


	$('#bodyInners').html("<div>"+flash+"</div>"); 
}

/*****************************************************
 * Friends & msg
 *****************************************************/
// Add as friend
function addfriend(url){
	mp_pop = new Popup({ contentType:1, isReloadOnClose:true,scrollType:false, width:320, height:120 });
	mp_pop.setContent("title","Add Friends");
	mp_pop.setContent("contentUrl",url);
	mp_pop.build();
	mp_pop.show();
	return false;
}
// Send mail
function sendmail(url){
	mp_pop = new Popup({ contentType:1, isReloadOnClose:false,scrollType:false, width:520, height:220 });
	mp_pop.setContent("title","Send Mail");
	mp_pop.setContent("contentUrl",url);
	mp_pop.build();
	mp_pop.show();
	if(con){
		window.frames['ifr_popup0'].document.getElementById('messages').value=con;
	}
	return false;
}
//Close popwin
function mp_close_pop(){
	mp_pop.close();
}

	 
/*****************************************************
 * errorimg
 *****************************************************/

function erroravator(dom) { 
/*var rimg = "<!--{IMAGES_URL}-->sns_images/ava.gif"; */

	dom.src = rimg2; 
	dom.alt = "";

} 
function errorimg(dom) { 
/*var rimg = "<!--{IMAGES_URL}-->sns_images/imgbg_dead.gif"; */
	dom.src = rimg1; 
	dom.alt = ""; 
} 
	 
/*****************************************************
 * bridge
 *****************************************************/

//mmoPop
function mmoPop(num){
	if (num ==1){
	document.getElementById("moregbi").style.display = "block"
	}else{
	document.getElementById("moregbi").style.display = "none"
	}
}
//mmoHeader
function myHeader()
{
	mmoGameHeader();
}


//Footer
function myFooter()
{
	mmoFooter();
}

function login_prompt()
{
	alert('Sorry you have to sign in first!');
}
	
	
/*****************************************************
 * bg link
 *****************************************************/	
	


var Fid = function(i){return document.getElementById(i);}

var switchMusic = function(o, n, p){
   var ol = Fid(o+p);
   var cl = Fid(o+n);
   ol.style.display="none";
   cl.style.display="";
}
var doClearStyle = function( num,tab,newStyle ){
	var li = Fid( tab ).getElementsByTagName( "li" );
	for( var i = 0; i < li.length; i++ ){
		if( ( num-1 ) == i ){
			li[i].className = newStyle;
		} else {
			li[i].className = "";
		}
	}
}

/*****************************************************
 * tab swich
 *****************************************************/

//绗竴涓爣绛惧垏鎹�
var m1 = 1;
function doChange( num ){  
   doClearStyle( num,"xtab1","on1" );
   
   switchMusic("xtab_cnt", num, m1);
   m1 = num;
   return false;
}

//绗簩涓爣绛惧垏鎹�
var m2 = 1;
function doTab2( num ){  
   doClearStyle2( num,"xtab1","tab1_on","tab1_one" );
   
   switchMusic("tab1_cnt", num, m2);
   m2 = num;
   return false;
}
//绗笁涓爣绛惧垏鎹�
var m3 = 1;
function doTab3( num ){  
   if( num != 1 ){
	   Fid( "xtab3" ).className = "sidebar_column1_top2 xx";
   } else {
   	   Fid( "xtab3" ).className = "sidebar_column1_top2";
   }
   switchMusic("sidebar_column1_cnt", num, m3);
   m3 = num;
   return false;
}

//绗洓涓爣绛惧垏鎹�
var m4 = 1;
function doChange2( num ){  
   doClearStyle( num,"xtab2","on1" );
   
   switchMusic("xtab2_cnt", num, m4);
   m4 = num;
   return false;
}
//绗簲涓爣绛惧垏鎹�
var m5 = 1;
function doChange3( num ){  
   doClearStyle( num,"xtab5","on2" );
   
   switchMusic("hot_cnt", num, m5);
   m5 = num;
   return false;
}
var doClearStyle2 = function( num,tab,newStyle,firstStyle ){
	var li = Fid( tab ).getElementsByTagName( "li" );
	for( var i = 0; i < li.length; i++ ){
		li[i].className = "";
	}
	if( num == 1 ){
		li[0].className = firstStyle + " " +  newStyle;
	} else {
		li[0].className = firstStyle;
		li[num-1].className = newStyle;
	}
}



/*****************************************************
 * play flash
 *****************************************************/
 
 function playFlash(flashid){
    var fpic =document.getElementById(flashid).getElementsByTagName("img");
	var flink =document.getElementById(flashid).getElementsByTagName("a");
	var pic_width="340"; 
    var pic_height="255";
	var button_pos=fpic.length;
	var stop_time=6000;
	var show_text=0; 
	var txtcolor="dddddd";
	var bgcolor="000000";
	var imag=new Array();
	var link=new Array();
	var text=new Array();

	var flashUrl = 'http://feature.mmosite.com/flashviewer/viewer02.swf';


   for(var i=0;i<fpic.length;i++){
   imag[i]=fpic[i].src;
   }  

	var swf_height=show_text==1?pic_height+0:pic_height;
	var pics="", links="", texts="";
	for(var i=0; i<imag.length; i++){
		pics=pics+("|"+imag[i]);
		links=links+("|"+flink[i*1]);
		
		//????cms??????????+??????????2????????????????
		//links=links+("|"+flink[i*2]);
		
		links = links.replace(/(&)/g,"-");
		texts=texts+("|"+text[i]);
		//alert(flink[i*2]);
	}
	
	pics=pics.substring(1);
	links=links.substring(1);
	texts=texts.substring(1);
	
	
	var flash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ pic_width +'" height="' + pic_height +'" /><param name="allowScriptAccess" value="always" />';
	flash = flash + '<param name="movie" value="'+ flashUrl +'" />';
	flash = flash + '<param name="quality" value="high" />';
	flash = flash + '<param name="menu" value="false" />';
	flash = flash + '<param name="FlashVars" value="pics='+pics+'&links='+links+'&texts='+texts+'&picwidth='+pic_width+'&picheight='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'">';
    flash = flash + '<param name="wmode" value="transparent" />';
	flash = flash + '<embed src="' + flashUrl + '" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&picwidth='+pic_width+'&picheight='+pic_height+'&show_text='+show_text+'&txtcolor='+txtcolor+'&bgcolor='+bgcolor+'&button_pos='+button_pos+'&stop_time='+stop_time+'" quality="high" width="'+ pic_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"allowScriptAccess="always"  />';
	flash = flash + '</object>';
	document.writeln(flash); 
}

/*****************************************************
 * showGamelist
 *****************************************************/
 function getId(id) {
	return document.getElementById(id);
}
var switchpage = function(o, n, p){
   var ol = getId(o+p);
   var cl = getId(o+n);
   ol.style.display="none";
   cl.style.display="";
}

var gamelist_pre_no = 1;
function gamepage(num){  
	   var self = getId( "game-list-tab" ).getElementsByTagName("a");
	   for( var i = 0; i < self.length; i++ ){
			self[i].className = "";
	   }
	   self[num].className = "had";
	   switchpage("game-list-con", num, gamelist_pre_no);
	   gamelist_pre_no = num;
	   
	   return false;
	}
function doDisplay(){
	var game_list = getId( "game-list" );
	var game_con = getId( "game-con" );
	var gamelistbtn = getId( "gamelistbtn" );
		if(game_con.style.display == "none"){
			game_con.style.display = "block";
		} else {
			game_con.style.display = "none";
		}
		return false;
	}
	
function showGamelist(){
	var game_list = getId( "game-list" );
	var game_con = getId( "game-con" );
	var gamelistbtn = getId( "gamelistbtn" );

	game_con.style.display = "none";
	gamelistbtn.onclick = doDisplay;
	getId( "game-list-close-btn" ).onclick = doDisplay;

}
function SignIn(site_url){
	var spRefURL	= escape(window.location.href);
	

	if (typeof(site_url) != 'undefined' && (site_url == 'http://my.mmosite.tmc/')) {
		var url	= 'http://my.mmosite.tmc/?controller=Passport&action=Login&returnurl='+spRefURL;
	}else{
		var url	= 'http://my.mmosite.com/?controller=Passport&action=Login&returnurl='+spRefURL;
	}
	
	window.location.href = url;
}
