function check1(yn,act)
{
	var huohao1=getEle("huohao1");
	if(!isEmpty(huohao1))
	{
		if (huohao1.value==emptyProduit)
		{
			alert(EmptySelAlert);
			if(!huohao1.readOnly)
			{
			huohao1.focus();
			}
			return false;
		}
	}
	var shulian1=getEle("shulian1");
	if(!isEmpty(shulian1))
	{
		if (shulian1.value=="")
		{
			alert(EmptyAlert);
			if(!shulian1.readOnly)
			{
			shulian1.focus();
			}
			return false;
		}
	}
	if(!checkRepeat(yn))
	{
		var btnSave=document.getElementById("btnSave");
		if(!isEmpty(btnSave))
		{
			btnSave.disabled=true;
		}
		document.form1.submit();
		return true;
	}
}

function checkRepeat(yn)
{
	var r=false;
	for(var i=1;i<=maxproduit;i++)
	{
		var objhuohao=getEle("huohao"+i);
		if(!isEmpty(objhuohao))
		{
			var huohao=objhuohao.value;
			if(huohao!=emptyProduit)
			{
				if(yn=="yes")
				{
					var objbatch=getEle("batch"+i);
					if(!isEmpty(objbatch))
					{
						if((objbatch.value=="") && (IsBatch=="yes"))
						{
							alert(InputBatch);
							objbatch.focus();
							r=true;
							i=maxproduit+1;
							break;
						}
					}
				}
				var shulian=getEle("shulian"+i);
				if(StrToNum(shulian.value)<=0)
				{
					alert(InputQTY+" "+i+" !");
					shulian.focus();
					r=true;
					i=maxproduit+1;
					break;
				}
				var objku=getEle("ku"+i);
				getEle("ku_chu"+i).value=objku.value;
				var objku_ru=getEle("ku_ru"+i);
				if(!isEmpty(objhuohao) && !isEmpty(objku) && !isEmpty(objku_ru))
				{
					var ku=objku.value;
					for(var j=i+1;j<=maxproduit;j++)
					{
						var objhuohao2=getEle("huohao"+j);
						if(!isEmpty(objhuohao2))
						{
							var huohao2=objhuohao2.value;
							var objku2=getEle("ku"+j);
							if(huohao2!=emptyProduit)
							{
								if(!isEmpty(objku2))
								{
									var ku2=objku2.value;
									var batch2=getEle("batch"+j);
									var isrepeat=false;
									if(yn=="yes")
									{
										isrepeat=(huohao==huohao2 && ku==ku2 && objbatch.value==batch2.value)
									}
									else
									{
										isrepeat=(huohao==huohao2 && ku==ku2)
									}
									if(isrepeat)
									{
										alert(IsRepeat+" ["+huohao+"]!");
										objhuohao.focus();
										r=true;
										i=maxproduit+1;
										break;
									}
								}
							}
						}
					}
					var ku_ru=objku_ru.value;
					if(ku==ku_ru)
					{
						var txt = objku_ru.options[objku_ru.selectedIndex].text;
						alert(IsRepeat+" ["+txt+"]!");
						objku_ru.focus();
						r=true;
						i=maxproduit+1;
						break;
					}
				}
			}
		}
	}
	return r;
}

function checkShulian(idx)
{
	var huohao=getEle("huohao"+idx);
	if (huohao.value!=emptyProduit)
	{
		var url="getvjian.asp?act=move&huohao="+huohao.value+"&idx="+idx+"&d="+NewDate();
		var ku=getEle("ku"+idx);
		if(!isEmpty(ku))
		{
			url=url+"&ku="+ku.value;
		}
		var sell_id=getEle("sell_id"+idx);
		if(!isEmpty(sell_id))
		{
			url=url+"&sell_id="+sell_id.value;
		}
		var loader=new net.ContentLoader(url,callCheckShulian);
	}
}

function callCheckShulian()
{
    if(this.req.readyState==4)
    {
		if(this.req.status==200)
		{
			var list=this.req.responseText;
			var lists=list.split("$$$");
			if(lists.length==2)
			{
				var fcurIdx=lists[1];
				var vjian=StrToNum(lists[0]);
				var shulian=getEle("shulian"+fcurIdx);
				var inputshulian=StrToNum(shulian.value);
				var idp=getEle("id_produit"+fcurIdx);
				if(inputshulian>vjian)
				{
					alert(MaxOnly+" "+vjian);
					shulian.focus();
					SetProduit2(fcurIdx);
				}
			}
		}
	}
}

function SetProduit2(idx)
{
	var obj=getEle("huohao"+idx);
	var hval=obj.value;
	if(hval!=emptyProduit&&!isEmpty(hval))
	{
		var url="getProduitForBuy.asp?huohao="+obj.value+"&idx="+idx+"&d="+NewDate();
		var ku=getEle("ku"+idx);
		if(!isEmpty(ku))
		{
			url=url+"&ku="+ku.value;
		}
		var sell_id=getEle("sell_id"+idx);
		if(!isEmpty(sell_id))
		{
			url=url+"&sell_id="+sell_id.value;
		}
		var loader=new net.ContentLoader(url,callProduit2);
	}
}

function callProduit2()
{
    if(this.req.readyState==4)
    {
        if(this.req.status==200)
		{
            var list=this.req.responseText;
			var ls=list.split("|");
			var idx=ls[0];
			var huohao=getEle("huohao"+idx);
			var showshulian=getEle("showshulian"+idx);
			if(ls.length<=2)
			{
				huohao.value=emptyProduit;
				huohao.select();
				showshulian.className="red bold";
				showshulian.innerHTML=NotExist;
			}
			else
			{
				huohao.value=ls[1];
				var title=getEle("title"+idx);
				if(!isEmpty(title))
				{
					title.value=ls[2];	
				}
				var ku=getEle("ku"+idx);
				if(!isEmpty(ku))
				{
					ku.value=ls[5];	
				}
				showshulian.className="bold";
				showshulian.innerHTML=ls[6];
			}
		}
		else
		{
            alert("Abnormal");
        }
    }
}

function ScanBarCode(idx)
{
	var sell_id=getEle("sell_id"+idx);
	if(!isEmpty(sell_id))
	{
		windowOpen("../barcode/sell_scanbar.asp?idx="+idx+"&id="+sell_id.value,"");
	}
}