//Author: 王跃
//Last Modified Date:011-08-20001
//Description:定义门店端的JavaScip函数,变量

var baksss 
var bakcolor
var szTableHighBgColor="#E7E7F7"


//定义多选函数


 function ShowNormal(orow,cb,bk)//设置选中的表格的颜色
 {
  var obj=document.all(cb)
   
  if (obj!=null)
   if (obj.checked==true)
    {
      obj.checked=false
      orow.bgColor=bk
     } 
   else if (obj.checked==false)
    {
      obj.checked=true
      orow.bgColor=szTableHighBgColor
     }
   event.cancelBubble =true//画面重画
 }

 function ShowMuSelected(obj,bk)
 {
   if (obj!=null)
    if (obj.parentElement!=null)
      {
       var t=new String(obj.parentElement.tagName)
       var p=obj.parentElement
        if(t.toUpperCase()=="TD")
          if (p.parentElement!=null)
            if (obj.checked==true)
             p.parentElement.bgColor=szTableHighBgColor
            else
             p.parentElement.bgColor=bk
  
       }
   event.cancelBubble =true

 }

 



//参数sss传递表的行对象,szTypeID传递当前节点id
//bFirst表示是否初始化焦点
//oCurrParId 存储当前记录的父节点

function SetFocusIt(sss,szTypeID,bFirst,oCurrParId)
{
    if (bFirst!=0){
	baksss.bgColor=bakcolor
    }
    baksss=sss 
    bakcolor=sss.bgColor
    sss.bgColor=szTableHighBgColor
    oCurrParId.value=szTypeID
}

function Check(lpszStr) //检查字符串是否由数值构成
 {
     var nLen=lpszStr.length
     for (var nLoop=0;nLoop<nLen;nLoop++)
        if ((lpszStr.charAt(nLoop)>='0') && (lpszStr.charAt(nLoop)<='9')) continue
        else break

    if (nLoop>=nLen)
       return true 
    else
      return false 
 }

function ValidatePageNum(nPageNo,nPageCount)//验证页面的有效性
{
  if (!Check(nPageNo))
    {
     window.alert("无效的页面!")
     return false
    }
 if ((parseInt(nPageNo)<1) || (parseInt(nPageNo)>parseInt(nPageCount)))
   {
     window.alert("无效的页面!")
     return false
    }
 else 
    return true
}

//删除字符串中的空格
function KillSpace(x){
	while((x.length>0) && (x.charAt(0)==' '))
		x = x.substring(1,x.length);
	while((x.length>0) && (x.charAt(x.length-1)==' '))
		x = x.substring(0,x.length-1);
	return x;
}

//检查字符串是否是一个合法的日期
function DateCheckString (szDate)
{
  var nLimite, szYear,szMonth,szDay
  var fcompart,scompart  
  szDate = KillSpace(szDate)
  
  if (szDate.length>10 || szDate.length<8) return false
  fcompart =szDate.indexOf("-")
  szYear = szDate.substring(0, fcompart)
  if (szYear.length != 4) return false
  if (!Check(szYear)) return false

  if ((szYear-0)<1900 || (szYear-0)>2079) return false
  
  scompart = szDate.indexOf("-",fcompart+1)  
  szMonth = szDate.substring(fcompart+1,scompart)

  if (szMonth.length>2) return false

  if (!Check(szMonth))  return false
  if (szMonth.charAt(0)=="0")  szMonth=szMonth.substring(1,2)

  if ((szMonth-0)<0 || (szMonth-0)>12) return false
  
  szDay = szDate.substring(scompart+1,szDate.length)
  if (szDay.length>2) return false
  if (! Check(szDay)) return false
  if (szDay.charAt(0)=="0") szDay=szDay.substring(1,2)
  if ((szDay-0)<1 || (szDay-0)>31)  return false
   
  switch(szMonth-0){
      case 1: nLimite = 31
              break
     case  3: nLimite = 31
              break
     case  4: nLimite = 30
              break
     case  5: nLimite = 31
              break
     case  6: nLimite = 30
              break
     case  7: nLimite = 31
              break
     case  8: nLimite = 31
              break
     case  9: nLimite = 30
               break
     case  10: nLimite = 31
               break
     case  11: nLimite = 30
               break
     case  12: nLimite = 31
               break
     case  2: if ((((szYear % 4) == 0 && (szYear % 100)!=0)) || 
                  (((szYear % 100) == 0 && (szYear % 400) == 0))) 
                       nLimite = 29
             else nLimite = 28
             break
               
     }                          
    if (szDay-0>nLimite) return false     
    return true
}

//检查字符串是否是有效的数值（包括小数和负数）
function IsNumeric(lpstr)
{
 var s=KillSpace(lpstr)
 var nLen=s.length
   for (var nLoop=0;nLoop<nLen;nLoop++)
      if ((s.charAt(nLoop)>='0') && (s.charAt(nLoop)<='9')) continue
      else      
        if (s.charAt(nLoop)=='.') continue
	  else 
	    if(nLoop==0 && s.charAt(nLoop)=='-') continue
       else break
 
   if (nLoop>=nLen && nLen>0)
      return true 
   else
      return false 
  
}

//定义显示单据明细函数
function DisplayAllVch(szBillId)
{
  var re
  if (KillSpace(szBillId)!="")
  {
   re=showModalDialog("../DispVch/DisplayAllVch.asp?BillId="+szBillId,"","dialogWidth=500pt;dialogHeight=400pt;center:yes;status:no;help:no;scroll:no") 
   return true 
  }
  else
  return false
}
  //定义门店端Cookie保存报表日期
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {//获得cookie
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; 
}
return null;
}  
function SetCookie (name, value) { //设置cookid
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function UpdateCookieExpiresDate() {
var expdate = new Date();
var num;
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31)); 
if(!(num = GetCookie("Version"))) 
num = "1.0";
SetCookie ("Version", num, expdate);
}

function DateRange()
{
 var StartDate
 var EndDate
}


function GetDate(d)
{
 var temp
 var cdate=GetCookie('StartDate')

 if(d.StartDate==null||typeof(d.StartDate)=='undefined') //是否传进了参数
 {
	 if(!cdate)
	 {
		temp=new Date()
		temp=temp.getYear()+"-"+(temp.getMonth()+1)+"-"+temp.getDate()
	  } 
      else
		temp=cdate
	  d.StartDate=temp
 } 


 cdate=GetCookie('EndDate')

 if(d.EndDate==null||typeof(d.EndDate)=='undefined') //是否传进了参数
 {
	if(!cdate)
	{
		temp=new Date()
		temp=temp.getYear()+"-"+(temp.getMonth()+1)+"-"+temp.getDate()
	} 
	else
		temp=cdate
	d.EndDate=temp
 }
}

function SetDate(d)
{
var expdate = new Date()
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31))

SetCookie('StartDate',d.StartDate,expdate)
SetCookie('EndDate',d.EndDate,expdate)
}


//Author: 刘畅
//Last Modified Date:03-15-2001

// 把字符串转化为URL标准
function URLCode(szStr)
{
var iLen      // 字串长度
var cChr      // 处理字符
var iLoop     // 循环
var szDec=""  // 目的字串

iLen=szStr.length
for (iLoop=0;iLoop<iLen;iLoop++)
{
   cChr=szStr.charAt(iLoop)
   switch(cChr){
   case '&' : szDec+="~"
              break
   case ' ' : szDec+="+"
              break
   case "'" : szDec+="%27"
              break
   case '%' : szDec+="%25"
              break
   default : szDec+=cChr
              break
   }
}
return szDec
}
// 过滤条件数据结构
function FilterRange()
{
	 var szFilteID
	 var szFilteFullName
	 var szReSearth="No"
}
// 数值四舍五入
function GetRound(nNum,pre)
{
	if (IsNumeric(nNum))
	{
		return Math.round((nNum*Math.pow(10,pre)))/(Math.pow(10,pre)) 
	}
	else
	{
		return 0
	}
}
// GetOne的数据结构
function GetOne()
{
	var szDBName
	var szLike
	var Flag
	var szTypeID
	var szUserName
	var szFullName
}
// 
function GetAllOrPart()
{
  var szAllOrPart ;
}

function GetOdertype()
{
var szGetOdertype;
}
//组号设置，删除
function Team()
{
	var TeamNo;
	var Type;
}
function SortField()
{ 
	var Field;
}

//陈亮 2004-11-03
//发送数据
//id:单据类型，headdata单据索引，detaildata单据明细,callback回调函数
function PostData(ob,id,headdata,detaildata,callback)
{
	var	strTemp=new Date();
	
	if (ob==null || id==null || headdata==null || detaildata==null || callback==null ) return false;
	ob.close();
	ob.open("text/html; charset=gb2312");

	switch(parseInt(id))
	{
         case 298://询价单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchthinkaboutBill.asp'>");
		  break;

 	 case 300://销售订单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchSaleOrderBill.asp'>");
		  break;
	 case 305://零售单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchRetailBill.asp'>");
		  break;
 	 case 11://销售单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchSaleBill.asp'>");
		  break;
 	 case 45://销售退货单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchSaleBack.asp'>");
		  break;
 	 case 34://进货开单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchBuy.asp'>");
		  break;
 	 case 6://进货退货
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchBuyBack.asp'>");
		  break;
	 case 4://销售收款
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchGathering.asp'>");
		  break;
     case 66://进货付款
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchPayVch.asp'>");
		  break;

	 case 17://同价调拨单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchAllotBill.asp'>");
		  break;
	 case 21://变价调拨单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchPriceAllotBill.asp'>");
		  break;
	 case 9://报损单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchLoseBill.asp'>");
		  break;
	 case 14://报益单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchOverFlowBill.asp'>");
		  break;
	 case 57://调价单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchAdPriceBill.asp'>");
		  break;
     case 115://应收（付）增加（减少）
     case 116://应收（付）增加（减少）
     case 128://应收（付）增加（减少）
     case 129://应收（付）增加（减少）
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchAddEbt.asp'>");
		  break;
	 case 16://商品拆装单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchPacketBill.asp'>");
		  break;
	 case 36://一般费用单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchExpenseBill.asp'>");
		  break;
	 case 93://其他收入单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchIncomeBill.asp'>");
		  break;
	 case 77://转款单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchMonChaBill.asp'>");
		  break;
		  
	 case 71://借进开单
		  ob.writeln("<form name='Post_Form' method='post' action='js_PassVchBorrowBill.asp'>");
		  break;		  
	 case 87://借出开单
		  ob.writeln("<form name='Post_Form' method='post' action='js_PassVchLendBill.asp'>");
		  break;
	 case 88://借出还回
		  ob.writeln("<form name='Post_Form' method='post' action='js_PassVchLendBackBill.asp'>");
		  break;
	 case 72://借进还出
		  ob.writeln("<form name='Post_Form' method='post' action='js_PassVchBorrowBackBill.asp'>");
		  break;
 	 case 301://进货订单
		  ob.writeln("<form name='Post_Form' method='post' action='j_PassVchBuyOrderBill.asp'>");
		  break;
	  	
     default:
          alert("无效的单据类型!"+id);
          return;

	}
   ob.writeln("<input type=text name=callback value='"+escape(callback)+"'>")
   ob.writeln(headdata);
   ob.writeln(detaildata);
   ob.writeln("<input type=hidden name=TimeCheckPoint Value='"+strTemp.valueOf()+"'>");
   // 刘畅加入序列号过账参数 
   ob.writeln("<input type=hidden name=SerialBillID Value='"+escape(top.SerialLocalValue.szBillNumberID)+"'>");
   ob.writeln("</form>")
   ob.writeln("<script language='javascript' differ>document.Post_Form==null?alert('发生错误，不能更新数据！'):document.Post_Form.submit()</script>"); 

}


//接收数据--用于向一个对象附值
function GetData(ob,id,BillNumberID,parent,reserve)
{
	if (ob==null || id==null) 
	{
	  alert('参数错误！');	 
	  return false;
	}
	ob.close();
	ob.open("text/html; charset=gb2312");
	switch(parseInt(id))
	{
 	 case 11://销售单
 	 case 45://销售退货单
 	 case 34://进货单
 	 case 6://进货退货单

		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_SaleBillGetData.asp'>");
		  break;
 	 case 305://零售单

		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_RetailBillGetData.asp'>");
		  break;
 	 case 300://销售订单
 	 case 301://进货订单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_OrderBillGetData.asp'>");
		  break;

 	 case 17://同价调拨单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_AllotBillGetData.asp'>");
		  break;
 	 case 21://变价调拨单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_PriceAllotBillGetData.asp'>");
		  break;
 	 case 9://报损单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_LoseBillGetData.asp'>");
		  break;
 	 case 14://报益单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_OverFlowBillGetData.asp'>");
		  break;
	 case 57://调价单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_AdPriceBillGetData.asp'>");
		  break;
     case 4://销售收款
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_GatheringBillGetData.asp'>");
		  break;
	 case 66://进货付款
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_PayVchBillGetData.asp'>");
		  break;
     case 115://应收（付）增加（减少）
     case 116://应收（付）增加（减少）
     case 128://应收（付）增加（减少）
     case 129://应收（付）增加（减少）
          ob.writeln("<form name='Get_Form' method='post' action='../vch/js_AddEbtGetData.asp'>");
		  break;
	 case 16://商品拆装单
	      ob.writeln("<form name='Get_Form' method='post' action='../vch/js_PacketGetData.asp'>");
		  break;
	 case 36://一般费用单
	      ob.writeln("<form name='Get_Form' method='post' action='../vch/js_ExpenseVchBillGetData.asp'>");
		  break;
	 case 93://其他收入单
	      ob.writeln("<form name='Get_Form' method='post' action='../vch/js_IncomeVchBillGetData.asp'>");
		  break;
	 case 77://转款单
	      ob.writeln("<form name='Get_Form' method='post' action='../vch/js_MonChaVchBillGetData.asp'>");
		  break;
	 case 200://销售单
	      ob.writeln("<form name='Get_Form' method='post' action='../vch/js_OffLineBillGetData.asp'>");
		  break;
		  	 
	 case 87://借出开单
		  ob.writeln("<form name='Get_Form' method='post' action='../LendBorrow/js_LendBillGetData.asp'>");
		  break;		  
	 case 71://借进开单
		  ob.writeln("<form name='Get_Form' method='post' action='../LendBorrow/js_BorrowBillGetData.asp'>");
		  break;
	 case 88://借出还回
		  ob.writeln("<form name='Get_Form' method='post' action='../LendBorrow/js_LendBackBillGetData.asp'>");
		  break;
	 case 72://借进还出
		  ob.writeln("<form name='Get_Form' method='post' action='../LendBorrow/js_BorrowBackBillGetData.asp'>");
		  break;
 	 case 500://销售开单调入销售订单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_SaleBillLoadOrderBillGetData.asp'>");
		  break;
 	 case 501://进货开单调入进货订单
		  ob.writeln("<form name='Get_Form' method='post' action='../vch/js_BuyBillLoadOrderBillGetData.asp'>");
		  break;
		  
     default:
          alert("无效的单据类型!");
          return;
	}
   ob.writeln("<input type=hidden name=ID value='"+escape(id)+"'>")
   ob.writeln("<input type=hidden name=BillNumberID value='"+escape(BillNumberID)+"'>")
   ob.writeln("<input type=Hidden name=Parent value='"+escape(parent)+"'>")
   
   //////////////王跃添加
   if(reserve!=null)
   ob.writeln("<input type=Hidden name=GridType value='"+escape(reserve)+"'>")
   
   ob.writeln("</form>")
   ob.writeln("<script language='javascript' differ>document.Get_Form==null?alert('发生错误，不能得到数据！'):document.Get_Form.submit()</script>"); 
}

// 页面打印
function MyWinPrn( )
{
	if (window.print != null) 
		window.print() 
	else	alert('你的机器没有安装打印机，或是打印机不可用')
}

//王浩（2001－12－2）添加 
//报表打印
function QueryPrint(Szsss)
{
  var sss
  sss=Szsss;
  //alert(sss);
  parent.parent.PrintFrame.location.href=sss
//showModalDialog(sss,"","dialogWidth=430px;dialogHeight=115px;center:yes;status:no;help:no;scroll:no ")	
  //window.open(sss,"SELECT_ONE_BASE","toolbar=no,menubar=no,resizable=yes,top=0,left=0,width=420pt,height=460pt")
}

function GetTimeCheckPoint(etypeid,action)
{
  var strTemp=new Date();
  return strTemp.valueOf()+';'+etypeid+';'+ action
}

//刘畅2001-7-23
//发送数据
//ob:发送隐含帧，formdata:帧的内容,callback回调函数
function PostDataLiu(ob,formdata,callback)
{
	var	strTemp=new Date();
	if (ob==null || formdata==null || callback==null ) return false;
	ob.close();
	ob.open("text/html; charset=gb2312");

	ob.writeln(formdata);
	
	ob.writeln("<input type=text name=callback value='"+escape(callback)+"'>");
	ob.writeln("<input type=hidden name=TimeCheckPoint Value='"+strTemp.valueOf()+"'>");
	ob.writeln("</form>");
	ob.writeln("<script language='javascript' differ>");
	ob.write("document.Post_Form==null");
	ob.write("?alert('发生错误，不能更新数据！')");
	ob.write(":document.Post_Form.submit()</script>"); 
}

// 刘畅2002-1-21
// 获得本地的常量
function GetLocalVal(szName)
{
	var ob=top.LocalValue;
	if (ob==null){ob=parent.opener.top.LocalValue;};
	if (szName=="PartUpdate") return(ob.PartUpdate);	
	if (szName=="Tax") return(ob.Tax);
	if (szName=="DiscountRate") return(ob.DiscountRate);
	if (szName=="GridType") { return(ob.GridType)};
	if (szName=="PUBLIC_USER_NAME") return(ob.FullName);
	//说明,WY后来修改了szName=="FullName"的情况，改成了szName=="PUBLIC_USER_NAME"
	//而我的程序先前已经有很多地方用了szName("FullName")，所以我这里加入一个sz("FullName")
	//以上说明：ALAN  2002-01-25
	if (szName=="FullName") return(ob.FullName);
	if (szName=="SaleDefault") return(ob.SaleDefault);
}


/////////下面函数操作Stack王跃
//公用函数定义开始
function goBack()
{	//回退一步
	var ob=top.LocalValue;
	var win;
	if (ob==null){ob=parent.opener.top.LocalValue;};
	if (!ob.trackURL.isEmpty()){
	        win=ob.trackOb.popOut()+"='"+ob.trackURL.popOut()+"'";
  		    eval(win);
	}
	else{
	    return false;
	}
}


function goHead(szStr,obWin)//szStr:URL
{
	var ob=top.LocalValue;
	if (ob==null){ob=parent.opener.top.LocalValue;};
	ob.trackURL.pushInto(szStr);
	ob.trackOb.pushInto(obWin);
}

function EmptyStack()
{
	var ob=top.LocalValue;
	if (ob==null){ob=parent.opener.top.LocalValue;};
	ob.trackURL.clearTrack();
	ob.trackOb.clearTrack();
}

//肖伟2002-3-25
//库存上下限报警设置数据传输变量 
function DateStockUpDownAlarm()
{
  var szStockUpDate;
  var szStockDownDate;
}

//公用函数定义结束
