/*----------------------------------------------------------
*****************  伍剑 斗地主 1.0  *****************
作者：张辉
网站：http://www.wj008.net 
程序员代号：wj008
联系QQ：496865687
版权：版权全体,源代码公开,各种用途均可免费使用
**********************************************************
----------------------------------------------------------*/
function $(obj){return document.getElementById(obj)}
var Images=new Array();
var PKP;
var M_man1,M_man2,M_man3;
var M_UsObj=null;
var Game=0;

M_man1=null;//自己
M_man2=null;//上家
M_man3=null;//下家
var Mqd=0;
var CardDivs1=new Array();
var CardDivs2=new Array();
var CardDivs3=new Array();
var CardDivs4=new Array();

var CpCardDivs1=new Array();
var CpCardDivs2=new Array();
var CpCardDivs3=new Array();

var M_man1Cards=new Array();
var M_man2Cards=new Array();
var M_man3Cards=new Array();
var M_mandCards=new Array();

var M_BtnKS=null;
var M_BtnKS2=null;
var M_PanlZB1=null;
var M_PanlZB2=null;
var M_PanlZB3=null;

var M_Panltime1=null;
var M_Panltime2=null;
var M_Panltime3=null;

var M_PaiXinText;

var M_Name1,M_Name2,M_Name3;

var M_BtnQdz=null;
var M_BtnQbq=null;

var M_BtnCP=null;
var M_BtnBC=null;


var UsUpChuPai="-";
var UsDownChuPai="-";
var UsMeChuPai="-";

var MyCard="";

//上家或下家是不是地主
var UsUpIsDz=0;
var UsDownIsDz=0;

var ChuPaiRen=0;

var JieguoDiv=null;

//准备完成
function loadImgOk()
{
 
 var c =  $("show");  

 document.body.style.backgroundImage='url(images/BACKGD1024.gif)';
 document.body.style.backgroundRepeat='no-repeat';

 SendDate("F=1");
 

 M_PaiXinText=new Div("");
 M_PaiXinText.SetXY(483,660);
 M_PaiXinText.SetHtml("牌型提示");
 M_PaiXinText.SetV(false);
 M_PaiXinText.SetId("Ptext");
 M_BtnKS=new Div("");
 M_BtnKS.SetXY(395,440);
 M_BtnKS.SetHtml("<img src=\"images/kbt0.gif\" onmouseout=\"this.src='images/kbt0.gif'\" onmouseover=\"this.src='images/kbt1.gif'\" onmousedown=\"this.src='images/kbt2.gif'\" onclick=\"BiginGame()\" >");
 var d=M_BtnKS.GetDiv()
 d.style.cursor='pointer';
 
 M_BtnKS2=new Div("");
 M_BtnKS2.SetXY(490,440);
 M_BtnKS2.SetHtml("<img src=\"images/ksbt0.gif\" onmouseout=\"this.src='images/ksbt0.gif'\" onmouseover=\"this.src='images/ksbt1.gif'\" onmousedown=\"this.src='images/ksbt2.gif'\" onclick=\"BiginMinPai()\" >");
 var g=M_BtnKS2.GetDiv()
 g.style.cursor='pointer';
 PKP=$("KK");
 NewGame();
}
function NewGame()
{
 redo();
 M_BtnKS.SetV(true);
 M_BtnKS2.SetV(true);
 ManSite(0);
 UsUpIsDz=0;
 UsDownIsDz=0;
}
function NewGameTow()
{
 Game=0;
 UsUpIsDz=0;
 UsDownIsDz=0;

}
function BiginGame()
{
 SendDate("Bg=1&Bk=1&Bn=8");
/* NewGameTow();
 redo();
 Game=0;*/

}
function BiginMinPai()
{
	SendDate("Bg=2&Bk=1&Bn=8");
/*	 NewGameTow();
     redo();
     Game=0;*/
	
}
function SetReady(str)
{
	if(str==1)
	{
	if(M_PanlZB1==null)
	{
	M_PanlZB1=new Div("images/READY.gif");
	M_PanlZB1.SetXY(475,440);
	M_PanlZB1.SetV(true);
	M_BtnKS.SetV(false);
	M_BtnKS2.SetV(false);
	}
	}
	if(str==2)
	{
	if(M_PanlZB2==null)
	{
		M_PanlZB2=new Div("images/READY.gif");
		M_PanlZB2.SetXY(200,350);
		M_PanlZB2.SetV(true);
	}
	}
	if(str==3)
	{
	if(M_PanlZB3==null)
	{
		M_PanlZB3=new Div("images/READY.gif");
		M_PanlZB3.SetXY(780,350);
		M_PanlZB3.SetV(true);
	}
	}
}

function SetGameBigin()
{
	M_BtnKS.SetV(false);
	M_BtnKS2.SetV(false);
	if(M_PanlZB1!=null)
	{
	M_PanlZB1.remove();
	M_PanlZB1=null;
	}
	if(M_PanlZB2!=null)
	{
	M_PanlZB2.remove();
	M_PanlZB2=null;
	}
	if(M_PanlZB3!=null)
	{
	M_PanlZB3.remove();
	M_PanlZB3=null;
	}
}
//添加自己
function AddUsSelf(obj)
{
if(M_man1==null)
{
 M_man1=new Div(man,"man");
 M_man1.SetXY(440,500);
 M_man1.SetV(true);
 M_Name1= new Div("");
 M_Name1.SetXY(460,655);
 M_Name1.SetHtml("<table><tr><td>"+obj+"</td></tr></table>");
 M_Name1.SetV(true);
 M_Name1.SetClass("cls1");
 M_Name1.SetId("P1");
}
}
function delSelf()
{
	if(M_man1)
	{
	M_man1.remove();
	M_Name1.remove();
	M_man1=null;
	M_Name1=null;
	}
}
//添加上家
function AddUsUp(obj)
{
 if(M_man2==null)
 {
 M_man2=new Div(man,"man");
 M_man2.SetXY(20,240);
 M_man2.SetV(true);
 M_Name2 = new Div("");
 M_Name2.SetXY(33,387);
 M_Name2.SetHtml("<table><tr><td>"+obj+"</td></tr></table>");
 M_Name2.SetV(true);
 M_Name2.SetClass("cls1");
 M_Name2.SetId("P2");
 }
}
//移除上家
function delUsUp()
{
	if(M_man2)
	{
	M_man2.remove();
	M_Name2.remove();
	M_man2=null;
	M_Name2=null;
	}
}
//添加下家
function AddUsDown(obj)
{
 if(M_man3==null)
 {
 M_man3=new Div(man,"man");
 M_man3.SetXY(850,240);
 M_man3.SetImg(man,1);
 M_man3.SetV(true);
 
 M_Name3= new Div("");
 M_Name3.SetXY(880,387);
 M_Name3.SetHtml("<table><tr><td>"+obj+"</td></tr></table>");
 M_Name3.SetV(true);
 M_Name3.SetClass("cls1");
 M_Name3.SetId("P3");
 }
}
//移除下家
function delUsDown()
{
	if(M_man3)
	{
	M_man3.remove();
	M_Name3.remove();
	M_man3=null;
	M_Name3=null;
	}
}
//
function AddUserObj(Obj)
{
M_UsObj=Obj;
}

function addImg(img)
{
	if ( img.constructor == window.Array ) 
   {
	for (var i=0; i<img.length; i++)
	Images[Images.length]=img[i];
   }
   else
   {
	Images[Images.length]=img;
   }
}

//炸弹效果
/*var M_timce=1;
function zdman()
{   if(M_timce==1)
{   var mids=$("music")

   mids.play();
}
    M_man1.SetImg(man[M_timce]);
	M_man2.SetImg(man[M_timce]);
	M_man3.SetImg(man[M_timce],1);
	M_timce++;
	if(M_timce<15)
	{
	setTimeout('zdman()',200);
	}
	else
	{
	M_timce=0;
	
	}
}*/
//回复服务器信息
function BackOk(M)
{
	setTimeout('SendDate("Bk=1&Bn='+M+'");',10);
}

//抓牌
function Gcak(str,type,Nb)
{
	if(type==1)
	{
	CzhhenUpCard(str,Nb)
	}
	else if(type==2)
	{
	CzhhenSelfCard(str,Nb)
	ManSite(1);
	}
	else if(type==3)
	{
	CzhhenDownCard(str,Nb)
	}
}

//主角位置变换
function ManSite(str)
{
	if(M_man1!=null){
	if(str==1)
	{
		M_man1.SetXY(203,480);
		M_Name1.SetXY(223,625);
	}
	else
	{
		M_man1.SetXY(440,500);
		M_Name1.SetXY(460,655);
	}
	}
}


//清楚错误滞留牌信息
function qc()
{
var   divs = document.getElementsByTagName("div");   
  var   i;   
  for(i=0;i<divs.length;i++)
  {   
          if(divs[i].name=="Card")
		  document.body.removeChild(divs[i]);
		  
  } 
}


//重新发牌
function redo()
{
	del(CardDivs1);
	del(CardDivs2);
	del(CardDivs3);
	del(CardDivs4);
	del(CpCardDivs1);
	del(CpCardDivs2);
	del(CpCardDivs3);
    CpCardDivs1=[];
	CpCardDivs2=[];
	CpCardDivs3=[];
	CardDivs1=[];
	CardDivs2=[];
	CardDivs3=[];
	CardDivs4=[];
	delSelf();
	delUsUp();
	delUsDown();
$("KK").value="";
SetBtnQDZ(0);
DelPanltime();
	
if(JieguoDiv!=null)
{
JieguoDiv.remove();
JieguoDiv=null;
}
if(M_BtnCP!=null)
		{
			M_BtnCP.remove();
	        M_BtnCP=null;
		}
		if(M_BtnBC!=null)
		{
			M_BtnBC.remove();
	        M_BtnBC=null;
		}	
}


document.oncontextmenu=function(){       
 if(M_BtnCP!=null)
 {
  var mids=$("music2");
  mids.play();
  MEChupai();
 }
return false;       
} 

//设置出现消除抢地主图标
function SetBtnQDZ(str)
{
	if(str==1)
	{
		if(M_BtnQdz==null)
		{
		 
			 M_BtnQdz= new Div("");
			 M_BtnQdz.SetXY(430,480);
			 M_BtnQdz.SetHtml("<img src=\"images/qdz0.gif\" onmouseout=\"this.src='images/qdz0.gif'\" onmouseover=\"this.src='images/qdz1.gif'\"  onclick=\"MEQDZ()\" >");
			 M_BtnQdz.SetV(true);
			 M_BtnQdz.SetId("BtnQ1");
			 M_BtnQdz.Div.style.cursor='pointer';
			 M_BtnQbq= new Div("");
			 M_BtnQbq.SetXY(540,480);
			 M_BtnQbq.SetHtml("<img src=\"images/bq0.gif\" onmouseout=\"this.src='images/bq0.gif'\" onmouseover=\"this.src='images/bq1.gif'\"  onclick=\"MEBQDZ()\" >");
			 M_BtnQbq.SetV(true);
			 M_BtnQbq.SetId("BtnQ2");
			 M_BtnQbq.Div.style.cursor='pointer';
		
		}
	}
	else
	{
		if(M_BtnQdz!=null)
		{
			M_BtnQdz.remove();
	        M_BtnQdz=null;
		}
		if(M_BtnQbq!=null)
		{
			M_BtnQbq.remove();
	        M_BtnQbq=null;
		}
	}
}

function SetBtnCP(str)
{
	if(str==1)
	{
		//alert(UsUpChuPai)
	    //alert(UsDownChuPai)
		if(M_BtnCP==null)
		{
		    if(IsAllPass())
			{
			 M_BtnCP= new Div("");
			 M_BtnCP.SetXY(495,480);
			 M_BtnCP.SetHtml("<img src=\"images/cp0.gif\" onmouseout=\"this.src='images/cp0.gif'\" onmouseover=\"this.src='images/cp1.gif'\"  onclick=\"MEChupai()\" >");
			 M_BtnCP.SetV(true);
			 M_BtnCP.SetId("BtnC1");
			 M_BtnCP.Div.style.cursor='pointer';
			}
			else
			{
			 M_BtnCP= new Div("");
			 M_BtnCP.SetXY(450,480);
			 M_BtnCP.SetHtml("<img src=\"images/cp0.gif\" onmouseout=\"this.src='images/cp0.gif'\" onmouseover=\"this.src='images/cp1.gif'\"  onclick=\"MEChupai()\" >");
			 M_BtnCP.SetV(true);
			 M_BtnCP.SetId("BtnC1");
			 M_BtnCP.Div.style.cursor='pointer';
			 M_BtnBC= new Div("");
			 M_BtnBC.SetXY(530,480);
			 M_BtnBC.SetHtml("<img src=\"images/bc0.gif\" onmouseout=\"this.src='images/bc0.gif'\" onmouseover=\"this.src='images/bc1.gif'\"  onclick=\"MEBChupai()\" >");
			 M_BtnBC.SetV(true);
			 M_BtnBC.SetId("BtnC2");
			 M_BtnBC.Div.style.cursor='pointer';
			}
		}
	}
	else
	{
		if(M_BtnCP!=null)
		{
			M_BtnCP.remove();
	        M_BtnCP=null;
		}
		if(M_BtnBC!=null)
		{
			M_BtnBC.remove();
	        M_BtnBC=null;
		}
	}
}

//设置出现消除抢地主图标



var Jsq=null;
var time=0;
var Mtime=0;
function MEQDZ()
{
  SendDate("Q=1");
  var mids=$("music3");
  mids.play();
  time=0;
  Mtime=0;
}

function MEBQDZ()
{
  SendDate("Q=0");
  var mids=$("music4");
  mids.play();
  time=0;
  Mtime=0;
}
//抢地主返回值
function SetQUsJiao(UM,UU,UD)
{
	ClearAllzbPanl();
	if(Mqd==0)
	{
	if(UM==1)
	{
		
		M_PanlZB1=new Div("images/PICTURE_ROB.gif");
		M_PanlZB1.SetXY(500,430);
		M_PanlZB1.SetV(true);
	     
	}
	else
	{ if(UM==0)
	{
		M_PanlZB1=new Div("images/PICTURE_ROBPASS.gif");
		M_PanlZB1.SetXY(500,430);
		M_PanlZB1.SetV(true);
	}
	}
	}
	if(UU==1)
	{
		M_PanlZB2=new Div("images/PICTURE_ROB.gif");
		M_PanlZB2.SetXY(260,300);
		M_PanlZB2.SetV(true);
	}
	else
	{if(UU==0)
	{
		M_PanlZB2=new Div("images/PICTURE_ROBPASS.gif");
		M_PanlZB2.SetXY(260,300);
		M_PanlZB2.SetV(true);
	}

	}
	if(UD==1)
	{
		M_PanlZB3=new Div("images/PICTURE_ROB.gif");
		M_PanlZB3.SetXY(685,300);
		M_PanlZB3.SetV(true);
	}
	else
	{
		if(UD==0)
		{
		M_PanlZB3=new Div("images/PICTURE_ROBPASS.gif");
		M_PanlZB3.SetXY(685,300);
		M_PanlZB3.SetV(true);
		}
	}
}
function DelPanltime()
{
	if(M_Panltime1!=null)
	{
		M_Panltime1.remove();
	    M_Panltime1=null;
	}
	if(M_Panltime2!=null)
	{
		M_Panltime2.remove();
	    M_Panltime2=null;
	}
	if(M_Panltime3!=null)
	{
		M_Panltime3.remove();
	    M_Panltime3=null;
	}
}
//开始抢地主
function SetQtime(UM,UU,UD)
{
//alert(1);
    
	if(UM==1)
	{
		if(M_Panltime1==null)
		{
		 clearTimeout(Jsq);
	     Mtime=1;
	     M_Panltime1= new Div("");
		 M_Panltime1.SetXY(485,440);
		 M_Panltime1.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime1.SetV(true);
		 M_Panltime1.SetClass("clstime");
		 M_Panltime1.SetId("T1");
		 time=15;
		 TimeCounta();
		 SetBtnQDZ(1);
		 Mqd=1
		}
	}
	else
	{
		if(M_Panltime1!=null)
		{
		M_Panltime1.remove();
	    M_Panltime1=null;
		}
		SetBtnQDZ(0);
		Mqd=0
	}
	if(UU==1)
	{
		if(M_Panltime2==null)
		{
		 clearTimeout(Jsq);
		 Mtime=2;
	     M_Panltime2= new Div("");
		 M_Panltime2.SetXY(47,450);
		 M_Panltime2.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime2.SetV(true);
		 M_Panltime2.SetClass("clstime");
		 M_Panltime2.SetId("T2");
		 time=15;
		 TimeCountb();
		}
	}
	else
	{
		if(M_Panltime2!=null)
		{
		M_Panltime2.remove();
	    M_Panltime2=null;
		}

	}
	if(UD==1)
	{
		if(M_Panltime3==null)
		{
		 clearTimeout(Jsq);
		 Mtime=3;
	     M_Panltime3= new Div("");
		 M_Panltime3.SetXY(890,450);
		 M_Panltime3.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime3.SetV(true);
		 M_Panltime3.SetClass("clstime");
		 M_Panltime3.SetId("T3");
		 time=15;
		 TimeCountc();
		}
	}
	else
	{
	if(M_Panltime3!=null)
	{
		M_Panltime3.remove();
	    M_Panltime3=null;
	}
	}
}
//倒计时开始
function TimeCounta()
{
	
		if(time>=0)
		{
			if(M_Panltime1!=null)
			{
				M_Panltime1.SetHtml("<table><tr><td class=f>"+time+"</td></tr></table>");
			}
			
			time=time-1;
			Jsq=setTimeout('TimeCounta()',1000);

		}
		else
		{
			if(M_BtnQbq!=null)
			{
			MEBQDZ();
			}
		
			if(M_BtnCP!=null)
			{
				if(IsAllPass())
				AutoChupai();
			    else
				MEBChupai();
			}
		clearTimeout(Jsq);
		}
}
function TimeCountb()
{
	if(time>=0)
	{
        if(M_Panltime2!=null)
		{
			M_Panltime2.SetHtml("<table><tr><td class=f>"+time+"</td></tr></table>");
		}
		time=time-1;
		Jsq=setTimeout('TimeCountb()',1000);
	}
	else
	{
		clearTimeout(Jsq);
	}

}
function TimeCountc()
{
	if(time>=0)
	{
        if(M_Panltime3!=null)
		{
			M_Panltime3.SetHtml("<table><tr><td class=f>"+time+"</td></tr></table>");
		}
		time=time-1;
		Jsq=setTimeout('TimeCountc()',1000);
	}
	else
	{
		clearTimeout(Jsq);
	}

}



function SetQUsBooOk(UM,UU,UD,UsMc,UuMc,UdMc,UsMcN,UuMcN,UdMcN)
{
	SetBtnQDZ(0)//消除界面上的按钮
	SetQtime(0,0,0)//消除计时器
	if(UM==1)
	{
		if(M_man1!=null)
		{
			M_man1.SetImg(dman);
			CzhhenSelfCard(UsMc,UsMcN);
		}
	}
	if(UU==1)
	{
		if(M_man2!=null)
		{
		M_man2.SetImg(dman);
		UsUpIsDz=1;
		CzhhenUpCard(UuMc,UuMcN);
		}
	}
	if(UD==1)
	{
		if(M_man3!=null)
		{
			M_man3.SetImg(dman,1);
			UsDownIsDz=1;
			CzhhenDownCard(UdMc,UdMcN);
		}
	}
	
	
}

function IsAllPass()
{
	if((UsUpChuPai==""||UsUpChuPai=="-"||UsUpChuPai=="#")&&(UsDownChuPai==""||UsDownChuPai=="-"||UsDownChuPai=="#"))
	return true;
	else
	return false
	
}

//收到出牌指令
function GenOderChuPai(UM,UU,UD)
{

	if(UM==1)
	{
		
		if(M_PanlZB1!=null)
		{  
		M_PanlZB1.remove();
		M_PanlZB1=null;
		}
		ChuPaiRen=1;
		if(M_Panltime1==null)
		{
		 clearTimeout(Jsq);
	     Mtime=1;
	     M_Panltime1= new Div("");
		 M_Panltime1.SetXY(485,440);
		 M_Panltime1.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime1.SetV(true);
		 M_Panltime1.SetClass("clstime");
		 M_Panltime1.SetId("T1");
		 time=40;
		 TimeCounta();
		 setTimeout('SetBtnCP(1);',10);
		}
	}
	else
	{
		if(M_Panltime1!=null)
		{
		
		M_Panltime1.remove();
	    M_Panltime1=null;
		}
		SetBtnCP(0);
	}
	if(UU==1)
	{
		ChuPaiRen=2;
		if(M_Panltime2==null)
		{clearTimeout(Jsq);
		 Mtime=2;
	     M_Panltime2= new Div("");
		 M_Panltime2.SetXY(47,450);
		 M_Panltime2.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime2.SetV(true);
		 M_Panltime2.SetClass("clstime");
		 M_Panltime2.SetId("T2");
		 time=40;
		 TimeCountb();
		
		 	

		}
	}
	else
	{
		if(M_Panltime2!=null)
		{
		
		M_Panltime2.remove();
	    M_Panltime2=null;
		}

	}
	if(UD==1)
	{
		ChuPaiRen=3;
		if(M_Panltime3==null)
		{
		clearTimeout(Jsq);
		 Mtime=3;
	     M_Panltime3= new Div("");
		 M_Panltime3.SetXY(890,450);
		 M_Panltime3.SetHtml("<table><tr><td class=f>10</td></tr></table>");
		 M_Panltime3.SetV(true);
		 M_Panltime3.SetClass("clstime");
		 M_Panltime3.SetId("T3");
		 time=40;
		 TimeCountc();
		 
		}
	}
	else
	{
	if(M_Panltime3!=null)
	{   
		M_Panltime3.remove();
	    M_Panltime3=null;
	}
	}
}

//整理上家的牌
function CzhhenUpCard(CStr,nPai)
{
	if(nPai!=0)
	{
	del(CardDivs1);//删除原来的牌
	CardDivs1=[];
	M_man1Cards=[];
	M_man1Cards=GetCard(CStr,nPai);
	if(CStr!="-")
	M_man1Cards=SZPX(M_man1Cards);
	var Len=M_man1Cards.length;
	var Y=300-(Len*8)
		for(var i=0;i<Len;i++)
		{
		if(UsUpIsDz==1&&M_man1Cards[i].Munber=="1-0")
		{
		CardDivs1[i]=new Div("Gcards/CARDBADK_Loard.gif","dw",2);
		CardDivs1[i].SetXY(160,Y+(i*17));
		CardDivs1[i].SetV(true);
		}
		else
		{
		CardDivs1[i]=new Div(M_man1Cards[i].Img,"dw",2);
		CardDivs1[i].SetXY(160,Y+(i*17));
		CardDivs1[i].SetV(true);
		}
		}
	}
	else
	{
	del(CardDivs1);//删除原来的牌
	CardDivs1=[];
	M_man1Cards=[];
	}
}
//整理下家的牌
function CzhhenDownCard(CStr,nPai)
{
	if(nPai!=0)
	{
	del(CardDivs3);//删除原来的牌
	CardDivs3=[];
	M_man3Cards=[];
	M_man3Cards=GetCard(CStr,nPai);
	if(CStr!="-")
	M_man3Cards=SZPX(M_man3Cards);
	var Len=M_man3Cards.length;
	var Y=300-(Len*8)
	for(var i=0;i<Len;i++)
	{
		if(UsDownIsDz==1&&M_man3Cards[i].Munber=="1-0")
		{
		CardDivs3[i]=new Div("Gcards/CARDBADK_Loard.gif","dw",2);
		CardDivs3[i].SetXY(785,Y+(i*17));
		CardDivs3[i].SetV(true);
		}
		else
		{
		CardDivs3[i]=new Div(M_man3Cards[i].Img,"dw",2);
		CardDivs3[i].SetXY(785,Y+(i*17));
		CardDivs3[i].SetV(true);
		}
	}
	}
	else
	{
	del(CardDivs3);//删除原来的牌
	CardDivs3=[];
	M_man3Cards=[];
	}
}
//整理自己的牌
function CzhhenSelfCard(CStr,nPai)
{
	if(nPai!=0)
	{
	MyCard=CStr;
	del(CardDivs2);//删除原来的牌
	CardDivs2=[];
	M_man2Cards=[];
	//alert(CStr);
	M_man2Cards=GetCard(CStr,nPai);
	if(CStr!="-")
	M_man2Cards=SZPX(M_man2Cards);
	var Len=M_man2Cards.length;
	var X=490-(Len*7)
	for(var i=0;i<Len;i++)
	{
		CardDivs2[i]=new Div(M_man2Cards[i].Img,M_man2Cards[i].Munber,1);
        CardDivs2[i].SetXY(X+(i*18),560);
        CardDivs2[i].SetV(true);
	}
	}
}
function CzhhenDiPai(CStr)
{
	    del(CardDivs4);//删除原来的牌
		CardDivs4=[];
		if(CStr=="-")
		{
			for(var i=0;i<3;i++)
			{
			CardDivs4[i]=new Div("Gcards/CARDBADK_Loard.gif","dw",2);
			CardDivs4[i].SetXY(396+(i*83),54);
			CardDivs4[i].SetV(true);
			}
		}
		else
		{
			M_mandCards=GetCard(CStr,3);
			for(var i=0;i<3;i++)
			{
			CardDivs4[i]=new Div(M_mandCards[i].Img,"dw",2);
			CardDivs4[i].SetXY(396+(i*83),54);
			CardDivs4[i].SetV(true);
			}
			
		}
}
var IsAnBtn=false;
function MEChupai()
{
	if(IsAnBtn==false)
	{
	IsAnBtn=true;
	setTimeout('CanAnBtn()',100);
	var ChStr=PKP.value;
	if(ChStr=="")
	{
	alert("还没有选择要出的牌");
	return;
	}
	if(GetPaxingNb(ChStr)==0)
	{
	alert("您选择的牌型不对");
	return;
	}
	if(!(UsUpChuPai==""||UsUpChuPai=="-"))
	{
		if(!IsMaxPaxing(ChStr,UsUpChuPai))
		{
		alert("对不起你选择的牌不合适！");
		return;
		}
	}
	else
	{
		if(!(UsDownChuPai==""||UsDownChuPai=="-"))
		{
			if(!IsMaxPaxing(ChStr,UsDownChuPai))
			{
			alert("对不起你选择的牌不合适！");
			return;
			}
			
		}	
	}
	ChStr="Card="+ChStr;
	PKP.value="";
	SendDate(ChStr);
	clearTimeout(Jsq);
	
	}
}
function CanAnBtn()
{
	IsAnBtn=false;
}
function MEBChupai()
{
	SendDate("Card=-");
	PKP.value="";
	clearTimeout(Jsq);

}
function AutoChupai()
{
	var str=GetMinCard(MyCard);
	SendDate("Card="+str);
	PKP.value="";
	clearTimeout(Jsq);
}
//删除现有牌面
function ClearAllPaiMian()
{
	    del(CpCardDivs1);//删除原来的牌
		CpCardDivs1=[];
		del(CpCardDivs2);//删除原来的牌
		CpCardDivs2=[];
		del(CpCardDivs3);//删除原来的牌
		CpCardDivs3=[];
		ClearAllzbPanl();
		
}
function ClearAllzbPanl()
{
	   
		if(M_PanlZB1!=null)
		{  
		M_PanlZB1.remove();
		M_PanlZB1=null;
		}
	
		if(M_PanlZB2!=null)
		{  
		M_PanlZB2.remove();
		M_PanlZB2=null;
		}
	
		if(M_PanlZB3!=null)
		{  
		M_PanlZB3.remove();
		M_PanlZB3=null;
		}
}
//显示出牌
function SetChuPai(UM,UU,UD)
{
	
	UsMeChuPai=UM;
	UsUpChuPai=UU;
	UsDownChuPai=UD;
	ClearAllPaiMian();
	
	if(ChuPaiRen!=1)
	{
		if(UM!="#"){
		if(UM!="-")
		{
		   
			MCpXianshi(UM);
		}
		else
		{   
		
				M_PanlZB1=new Div("images/PASS.gif");
				M_PanlZB1.SetXY(500,430);
				M_PanlZB1.SetV(true);
			
		}
		}
	}
	 if(ChuPaiRen!=2)
	 {
		 if(UU!="#")
		 {
			if(UU!="-")
			{  
				UCpXianshi(UU);
			}
			else
			{	
			
					M_PanlZB2=new Div("images/PASS.gif");
					M_PanlZB2.SetXY(260,300);
					M_PanlZB2.SetV(true);
				
			}
		 }
	 }
	if(ChuPaiRen!=3)
	{
		if(UD!="#")
		{
			if(UD!="-")
			{
			
				DCpXianshi(UD);
			}
			else
			{
			
					M_PanlZB3=new Div("images/PASS.gif");
					M_PanlZB3.SetXY(685,300);
					M_PanlZB3.SetV(true);
				
			}
		}
	}

}

function MCpXianshi(CStr)
{
	if(M_Panltime1==null)
	{
	del(CpCardDivs1);//删除原来的牌
	CpCardDivs1=[];
	var Pai;
	Pai=GetCard(CStr);
	Pai=SZPX(Pai);
	var Len=Pai.length;
	var X=510-(Len*9)
		for(var i=0;i<Len;i++)
		{
		{
		CpCardDivs1[i]=new Div(Pai[i].Img,Pai[i].Munber,2);
        CpCardDivs1[i].SetXY(X+(i*18),430);
        CpCardDivs1[i].SetV(true);
		}
		}
	}
	
}
function UCpXianshi(CStr)
{
	del(CpCardDivs2);//删除原来的牌
	CpCardDivs2=[];
	var Pai;
	Pai=GetCard(CStr);
	Pai=SZPX(Pai);
	var Len=Pai.length;
	var Y=300-(Len*8)
		for(var i=0;i<Len;i++)
		{
		{
		CpCardDivs2[i]=new Div(Pai[i].Img,"dw",2);
		CpCardDivs2[i].SetXY(260,Y+(i*17));
		CpCardDivs2[i].SetV(true);
		}
		}
}
function DCpXianshi(CStr)
{
	del(CpCardDivs3);//删除原来的牌
	CpCardDivs3=[];
	var Pai;
	Pai=GetCard(CStr);
	Pai=SZPX(Pai);
	var Len=Pai.length;
	var Y=300-(Len*8)
		for(var i=0;i<Len;i++)
		{
		{
		CpCardDivs3[i]=new Div(Pai[i].Img,"dw",2);
		CpCardDivs3[i].SetXY(685,Y+(i*17));
		CpCardDivs3[i].SetV(true);
		}
		}
}

function UpDatePaiMian(UsMc,UsMcN)
{
	if(UsMc!="#")
	CzhhenSelfCard(UsMc,UsMcN);
	else
	{
	MyCard="";
	del(CardDivs2);//删除原来的牌
	CardDivs2=[];
	M_man2Cards=[];
	}
}
function UpDatePai(UsMc,UuMc,UdMc,UsMcN,UuMcN,UdMcN)
{
	if(UsMcN!=0)
	{ if(MyCard!=UsMc)
	  CzhhenUpCard(UuMc,UuMcN);
	}
	else
	{
	del(CardDivs2);//删除原来的牌
	CardDivs2=[];
	M_man2Cards=[];
	}
	if(UuMcN!=0)
	CzhhenUpCard(UuMc,UuMcN);
	else
	{
	del(CardDivs1);//删除原来的牌
	CardDivs1=[];
	M_man1Cards=[];
		
	}
	if(UdMcN!=0)
	CzhhenDownCard(UdMc,UdMcN);
	else
	{
	del(CardDivs3);//删除原来的牌
	CardDivs3=[];
	M_man3Cards=[];
	}
}

function SetOVER(UM,UU,UD)
{
	/*if(Game==0)
	{
	M_BtnKS.SetV(true);
 	M_BtnKS2.SetV(true);
 	M_BtnKS.SetXY(395,510);
 	M_BtnKS2.SetXY(490,510);
	DelPanltime();
	ClearAllzbPanl();
	clearTimeout(Jsq);
	ClearAllzbPanl();
	if(JieguoDiv==null)
	{
		JieguoDiv=new Div("");
		JieguoDiv.SetXY(293,192);
		if(UsUpIsDz==0&&UsDownIsDz==0)
		{
		if(UM==1)
		JieguoDiv.SetHtml('<table class="jieguo" width="440" height="250" border="0" cellpadding="0" cellspacing="0" background="images/GameEnd_LordWin.gif"><tr><td width="76" height="170">&nbsp;</td><td width="137">&nbsp;</td><td width="57">&nbsp;</td><td width="98">&nbsp;</td><td width="72">&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td colspan="5" height="54" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="13%" height="40" valign="bottom">&nbsp;</td><td width="23%" valign="bottom">10</td><td width="27%" valign="bottom">60</td><td width="26%" valign="bottom">&nbsp;</td><td width="12%" valign="bottom">600</td></tr></table></td></tr></table>');
		else
		JieguoDiv.SetHtml('<table class="jieguo" width="440" height="250" border="0" cellpadding="0" cellspacing="0" background="images/GameEnd_LordLost.gif"><tr><td width="76" height="170">&nbsp;</td><td width="137">&nbsp;</td><td width="57">&nbsp;</td><td width="98">&nbsp;</td><td width="72">&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td colspan="5" height="54" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="13%" height="40" valign="bottom">&nbsp;</td><td width="23%" valign="bottom">10</td><td width="27%" valign="bottom">60</td><td width="26%" valign="bottom">&nbsp;</td><td width="12%" valign="bottom">600</td></tr></table></td></tr></table>');
		}
		else
		{
		if(UM==1)
		JieguoDiv.SetHtml('<table class="jieguo" width="440" height="250" border="0" cellpadding="0" cellspacing="0" background="images/GameEnd_FammerWin.gif"><tr><td width="76" height="170">&nbsp;</td><td width="137">&nbsp;</td><td width="57">&nbsp;</td><td width="98">&nbsp;</td><td width="72">&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td colspan="5" height="54" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="13%" height="40" valign="bottom">&nbsp;</td><td width="23%" valign="bottom">10</td><td width="27%" valign="bottom">60</td><td width="26%" valign="bottom">&nbsp;</td><td width="12%" valign="bottom">600</td></tr></table></td></tr></table>');
		else
		JieguoDiv.SetHtml('<table class="jieguo" width="440" height="250" border="0" cellpadding="0" cellspacing="0" background="images/GameEnd_FammerLost.gif"><tr><td width="76" height="170">&nbsp;</td><td width="137">&nbsp;</td><td width="57">&nbsp;</td><td width="98">&nbsp;</td><td width="72">&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td height="30">&nbsp;</td><td>e</td><td>&nbsp;</td><td>-100</td><td>&nbsp;</td></tr><tr><td colspan="5" height="54" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="13%" height="40" valign="bottom">&nbsp;</td><td width="23%" valign="bottom">10</td><td width="27%" valign="bottom">60</td><td width="26%" valign="bottom">&nbsp;</td><td width="12%" valign="bottom">600</td></tr></table></td></tr></table>');
		
		}
		JieguoDiv.SetV(true);
	}
	Game=1;
	}*/
	NewGame();
	
}



   //只有点右上角X的时候弹出提示,让用户确认(是否关闭)
   //解决了onbeforeunload()函数在刷新页面也弹出的问题)
   //而且无需再body中加载
   function window.onunload()
   {
	   SendDate("Out=1");
   }
   function window.onbeforeunload() 
   { 
          if(event.clientX>360&&event.clientY<0)
          { 
                window.event.returnValue="提示：是否要真的离开游戏，如果游戏在进行\n      中离开游戏将扣去相应的积分!"; 
          } 
   }

