function NewDate()
{
var d,s;  
d = new Date();  
s = d.getFullYear() + "-";
s = s + (d.getMonth() + 1) + "-";
s += d.getDate();
s += d.getHours() + ":";
s += d.getMinutes() + ":";
s += d.getSeconds();
return(s);
}
function getEle(el)
{
	return document.getElementById(el);
}
function isEmpty(s) 
{
  if (s == null || s=="undefined" || s.length == 0)
    return true;
  return !/\S/.test(s);
}

function left(mainStr,lngLen)
{
     if (lngLen>0) {return mainStr.substring(0,lngLen)}
     else{return null}
} 

function right(mainStr,lngLen)
{
     if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen<=mainStr.length) {
     return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
     else{return null}
}
function mid(mainStr,starnum,endnum)
{
     if (mainStr.length>=0){
     return mainStr.substr(starnum,endnum)
     }else{return null}
 }
function IsInteger (strVal)
{
    var reVal;
    strVal = strVal;
    if (strVal.length == "")
        return (false);
    reVal = /^[\-\+]?([1-9]\d*|0|[1-9]\d{0,2}(,\d{3})*)$/;
    return (reVal.test (strVal));
}
function onlyNum(o)
{
    o.value=o.value.replace(/[^\d]/g,'');   
}
function clearNoNum(obj)
{
   obj.value = obj.value.replace(/[^\d.]/g,"");
   obj.value = obj.value.replace(/^\./g,"");
   obj.value = obj.value.replace(/\.{2,}/g,".");
   obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
function JHshNumberText(a)
{ 
  var fa="";
  if(a.value.substring(0,1)=="-")
      fa="-";

  var str=(a.value.replace(/[^0-9.]/g,'')).replace(/[.][0-9]*[.]/, '.');
  

  if (str.substring(0,1)==".")
   str="0"+str;
   a.value=fa+str;
} 
function clearDefault(el)
{
  if (el.defaultValue==el.value) el.value = "";
}
function resetDefault(el)
{
  if (isEmpty(el.value)) el.value=el.defaultValue;
}

function isMobile(sMobile)
{ 
	if(!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(sMobile)))
	{ 
		return false; 
	} 
	else if(sMobile.length!=11)
	{
		return false;
	}
	{
		return true;
	}
} 

function checkMobile(obj)
{
	if(obj.value.length>0)
	{
	if(!isMobile(obj.value))
	{
		alert(EmptyAlert);
		obj.focus();
	}
	}
}
function change(obj)
{
	var val="";
	if(obj.checked)
	{
		val="1";
	}
	else
	{
		val="0";
	}
	location.href="?empty="+val;
}

function CheckAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.name != 'chkall')e.checked = form.chkall.checked; 
	}
}

function StrToNum(strValue)
{
	var reNum=Math.round(strValue*1000)/1000;
	return reNum;
}
function StrToNum2(strValue,fixNum)
{
	var reNum=Math.round(strValue*1000)/1000;
	return reNum.toFixed(fixNum);
}

function URLEncode(fld) 
{ 
if (fld == "") return false; 
var encodedField = ""; 
var s = fld; 
if (typeof encodeURIComponent == "function") 
{ 
encodedField = encodeURIComponent(s); 
} 
else 
{ 
encodedField = encodeURIComponentNew(s); 
} 
return encodedField; 
}
function DrawImage(MyPic, W, H) {
    var flag = false;
    var image = new Image();
    image.src = MyPic.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= W / H) {
            if (image.width > W) {
                MyPic.width = W;
                MyPic.height = (image.height * W) / image.width;
            }
            else {
                MyPic.width = image.width;
                MyPic.height = image.height;
            }
        }
        else {
            if (image.height > H) {
                MyPic.height = H;
                MyPic.width = (image.width * H) / image.height;
            }
            else {
                MyPic.width = image.width;
                MyPic.height = image.height;
            }
        }
    }
}

function AutoCheck(url)
{
var loader=new net.ContentLoader(url,callchkback);
}
function callchkback(){}
function nextitem(idx)
{
	clearSearch();
	var cailiaohan=getEle("cailiaohan"+idx);
	if(!isEmpty(cailiaohan))
	{
		cailiaohan.style.display="";
		getEle("huohao"+idx).focus();
	}
}

function ClearData(idx)
{
	var huohao=getEle("huohao"+idx);
	huohao.value=emptyProduit;
	getEle("shulian"+idx).value='1';
	getEle("title"+idx).value='';
	var price1=document.getElementById("price1"+idx);
	if(!isEmpty(price1))
	{
		price1.value='';
	}
	var price2=document.getElementById("price2"+idx);
	if(!isEmpty(price2))
	{
		price2.value='';
	}
	var showshulian=document.getElementById("showshulian"+idx);
	if(!isEmpty(showshulian))
	{
		showshulian.innerHTML="";
	}
	var id_produit=document.getElementById("id_produit"+idx);
	if(!isEmpty(id_produit))
	{
		id_produit.value="";
	}
	huohao.select();
	huohao.focus();
}
function windowOpen(url,title)
{
	var w = 1004;
	var h = 600;
	var t = (screen.height-h)/2-30;
	var l = (screen.width-w)/2-4;
	var win=window.open(url,title,'width='+w+',height='+h+',top='+t+',left='+l+',toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=no,scrollbars=yes');
	win.focus();
}
function windowShowDialog(url,title)
{
	var w = 1004;
	var h = 600;
	var t = (screen.height-h)/2-30;
	var l = (screen.width-w)/2-4;
	window.showModalDialog(url,title,"dialogHeight=350px;dialogwidth=410px;dialogLeft=0;dialogTop=25;help=no;resizable=no;status=no;scrollbars=no;");
}
function setpic(obj)
{
	document.all.pic.innerHTML='<img src='+obj.value+' width=100>';
}
function CheckClearAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if(e.type=="checkbox")
		{
			if (e.name != 'chkall' && e.name == 'ClearID')
			{
				e.checked = form.chkalljh.checked;
			}
		}
	}
}

function CheckDelAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if(e.type=="checkbox")
		{
			if (e.name != 'chkall' && e.name == 'ID')
			{
				e.checked = form.chkalldel.checked;
			}
		}
	}
}

function CheckPrintAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if(e.type=="checkbox")
		{
			if (e.name != 'chkall' && e.name == 'PrintID')
			{
				e.checked = form.chkalljh.checked;
			}
		}
	}
}

function PrintAll()
{
	var checkIDs="";
	var checkcount=0;
	var PickIDs=document.getElementsByName("PrintID");
	for (var i=0;i<PickIDs.length;i++)
	{
		var e = PickIDs[i];
		if(e.checked)
		{
			if(checkIDs=="")
			{
			checkIDs=e.value;
			}
			else
			{
			checkIDs=checkIDs+","+e.value;
			}
			checkcount=checkcount+1;			
		}
	}
	if(checkIDs=="")
	{
	alert(EmptySelAlert);
	return false;
	}
	else
	{
	var url="print_sell.asp?bianhao="+checkIDs;
	windowOpen(url,"");
	}
}

function SetPayment()
{
	var checkIDs="";
	var checkcount=0;
	var PickIDs=document.getElementsByName("PrintID");
	for (var i=0;i<PickIDs.length;i++)
	{
		var e = PickIDs[i];
		if(e.checked)
		{
			if(checkIDs=="")
			{
			checkIDs=e.value;
			}
			else
			{
			checkIDs=checkIDs+","+e.value;
			}
			checkcount=checkcount+1;			
		}
	}
	if(checkIDs=="")
	{
	alert(EmptySelAlert);
	return false;
	}
	else
	{
	var url="Set_sell.asp?bianhao="+checkIDs;
	windowOpen(url,"");
	}
}

function SetIsOk()
{
	var checkIDs="";
	var checkcount=0;
	var PickIDs=document.getElementsByName("PrintID");
	for (var i=0;i<PickIDs.length;i++)
	{
		var e = PickIDs[i];
		if(e.checked)
		{
			var url="sell.asp?bianhao="+e.value+"&isok=3&nextstr=ÒÑÍê³É"+"&d="+NewDate();
			AutoCheck(url);
		}
	}
	location.reload();
}


var obj2=null;
function collapse(img,objName,act)
{
	if(isEmpty(act))
	{
		act="";
	}
	var obj,objbianhao;
	obj = document.getElementById(objName);
	if (img.src.indexOf('open') != -1)
	{
		img.src = img.src.replace('open', 'close');
		obj.style.display = 'none';
	}
	else
	{
		obj2 = document.getElementById("td"+objName);
		obj2.innerHTML="<img src='../images/loading2.gif' /><br /><span class='red bold'>Loading...</span>";
		objbianhao = document.getElementById("bianhao"+objName);
		var url="../produit/getInfo.asp?act="+act+"&bianhao="+objbianhao.value+"&d="+NewDate();
		//location.href=url;
		var loader=new net.ContentLoader(url,popInfo);
		img.src = img.src.replace('close', 'open');
		obj.style.display = '';
	}
}

function popInfo()
{
    if(this.req.readyState==4)
    {
        if(this.req.status==200){
            obj2.innerHTML=this.req.responseText;
        }else{
            alert("Abnormal");
			location.reload();
        }
    }
}
function preview(){ 
bdhtml=window.document.body.innerHTML; 
sprnstr="<!--startprint-->"; 
eprnstr="<!--endprint-->"; 
prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
window.document.body.innerHTML=prnhtml; 
window.print(); 
window.document.body.innerHTML=bdhtml; 
}
function isNumberString (InString,RefString)
{
if(InString.length==0) return (false);
for (Count=0; Count < InString.length; Count++)  {
	TempChar= InString.substring (Count, Count+1);
	if (RefString.indexOf (TempChar, 0)==-1)  
	return (false);
}
return (true);
}
function clearOper(obj)
{
	obj.value = obj.value.replace("*","").replace("-","").replace("+","").replace("/","");
}
function ToUp(obj)
{
	obj.value = obj.value.toUpperCase();
}

function ShowLoading()
{
	var loading=getEle("loading");
	if(!isEmpty(loading))
	{
		loading.style.display="block";
	}
}
function showOpen(url,width,height)
{
	if(!width)
	{
		width = window.screen.availWidth;
	}
	if(!height)
	{
		height = window.screen.availHeight;
	}
	var win=window.open(url,"","toolbar=no,resizable=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no");
	win.moveTo((window.screen.availWidth-width)/2,(window.screen.availHeight-height)/2);
	win.resizeTo(width,height);
}