var d_card=0;
var p_card=0;
var total_p_c=0;

function err(s){alert(s);}
function set_buttons(e1,e2,e3,e4){
if (e1==1) {document.all('b1').style.background="green";document.all('b1').style.color="yellow";
}else{document.all('b1').style.background="#e0e0e0";document.all('b1').style.color="gray";}
if (e2==1) {document.all('b2').style.background="green";document.all('b2').style.color="yellow";
}else{document.all('b2').style.background="#e0e0e0";document.all('b2').style.color="gray";}
if (e3==1) {document.all('b3').style.background="green";document.all('b3').style.color="yellow";
}else{document.all('b3').style.background="#e0e0e0";document.all('b3').style.color="gray";}
if (e4==1) {document.all('b4').style.background="green";document.all('b4').style.color="yellow";
}else{document.all('b4').style.background="#e0e0e0";document.all('b4').style.color="gray";}
return 0;
}

function out_card(n){
set_buttons(0,0,0,0);
if (n<=total_p_c){
if (n==0) {
if (d_card>0){
c30.style.cursor='';
c30.src='/img/bj/empty.gif';
document.all('c1'+d_card).src='/img/bj/'+d_card+'.gif';
document.all('c1'+d_card).style.cursor='hand';
d_card=0;
}
}else{
document.all('c3'+total_p_c).style.cursor='';
document.all('c3'+total_p_c).src='/img/bj/empty.gif';
q=1;i=1;while(i<n){q*=16;i++;}
p_card=((p_card>>(n*4))<<((n-1)*4))+(p_card%q);
total_p_c--;
for (i=0;i<total_p_c;i++){q=(p_card>>(i*4))&15;document.all('c3'+(i+1)).src='/img/bj/'+q+'.gif';}
}
}
return 0;
}

function set_card(d,n){
set_buttons(0,0,0,0);
if (d==1) {
d_card=n;
c30.style.cursor='hand';
c30.src='/img/bj/'+n+'.gif';
document.all('c1'+n).style.border='0px';
}else{
if (total_p_c<5) {
q=1;i=0;while(i<total_p_c){q*=16;i++;}
p_card+=n*q;
total_p_c++;
document.all('c3'+total_p_c).style.cursor='hand';
document.all('c3'+total_p_c).src='/img/bj/'+n+'.gif';
document.all('c2'+n).style.border='0px';
}else {alert('Больше 5 карт положить нельзя');}
}
return 0;
}
function draw_cards(d){
var t='<table cellpadding=3 cellspacing=0 ><tr valign="middle" align="center" height=70>';
for (i=2;i<15;i++){
t+='<td width=56><img onclick="set_card('+d+','+i+');" src="/img/bj/'+i+'.gif" style="width:40;height:55;border:0px;cursor:hand;" id="c'+d+i+'" onmouseover="';
if (d==1) t+='if (d_card!='+i+') ';
t+='this.style.border=\'solid green 1px;\'" onmouseout="this.style.border=\'0px;\'"></td>';
}
dw(t+'</tr></table>');
return 0;
}

function subm(){
document.bj_f.d.value=d_card;
document.bj_f.t.value=total_p_c;
document.bj_f.p.value=p_card;
document.bj_f.submit();
return 0;
}

