/*从cookie中读取信息*/
function GetCookie(name)
{
  var IsFond = false;
  var start = 0;
  var end = 0;
  var CookieString = document.cookie;
  var i = 0;
  name += '=';
  while ( i < CookieString.length)
  {
    start = i;
    end = start + name.length;
    if (CookieString.substring(start, end) == name)
    {
      IsFond = true;
      break;
    }  
    i++;
  }   
  
  if (IsFond == true)
  {
    start = end;
    end = CookieString.indexOf(";", start);
    if (end < start)
      end = CookieString.length;
    return unescape(CookieString.substring(start, end));
  }
  
  return ("NoName");
}

/*保存数据在cookie中*/
function SaveCookie(name, avalue, expires)
{
  var AExpires = new Date();
  var astr 
  if (expires == 0)
  {  AExpires.setTime(AExpires.getTime() + 24 * 60 * 60 * 365 * 1000); }
  else
    AExpires = expires;
  
  if (expires >= 0)
  {  astr = name + "=" + escape(avalue) + ";expires=" + AExpires.toGMTString(); }
  else
    astr = name + "=" + escape(avalue) + ";";
  
  document.cookie = astr;
}

/*响应键盘消息*/
function document_onKeyPress() 
{
	var vsTextNamee;            
	if (window.event.keyCode==13)
	{
		vsTextName = window.event.srcElement.name;
		if (vsTextName!="button1"&&vsTextName!="button2")
 				window.event.keyCode = 0;
		switch(vsTextName)
		{
			case "selInstance":
				fmloadpad.TxtUserID.select();
				fmloadpad.TxtUserID.focus();
				break;
			case "TxtUserID":
				fmloadpad.TxtPassword.select();
				fmloadpad.TxtPassword.focus();
				break;
			case "TxtPassword":
				fmloadpad.TxtDutyID.select();
				fmloadpad.TxtDutyID.focus();
				break;
			case "TxtDutyID":
			    fmloadpad.Txtkjdate.select();
			    fmloadpad.Txtkjdate.focus();
				break;
			case "Txtkjdate":    			
                            if (fmloadpad.Txtkjdate.value.length!=10)
                            {
                              alert("会计日期输入有误");
                              fmloadpad.Txtkjdate.focus();
                             }
                            else
                             {
                              var
                                  s=""+fmloadpad.Txtkjdate.value;
                                  i=0
                                  while ((i>=0)&&i<(s.length))
                        	    { 
                            	       if ((i!=4)&&(i!=7))
                                        if (s.substring(i,i+1)==".")
                                        {
                                            alert("会计日期输入有误");
                                            fmloadpad.Txtkjdate.focus();
                                            break;
                                         }                                    
                                       i=i+1;
                             	    }                                
                              if ((i==s.length)&&(isDate(s)==true)) 
                               {
                                 UserLogin();
                                 break;
                               }
                              else
                                {
                                   alert("会计日期输入有误");
                                   fmloadpad.Txtkjdate.focus(); 
                                 }

                              }
			
		 }
	}
	else
        { 
           if  (window.event.srcElement.name=='Txtkjdate')
            {
               if ((window.event.keyCode>57)||(window.event.keyCode<48))
               {
                if (window.event.keyCode!=46)                   
                  {
                    window.event.keyCode=0;              
                    alert("非法输入"); 
                  }
               }
            }

          if (window.event.keyCode==27)
  		     window.close();
        }
          
}

/*将字符串转换为数组*/
function TransStrs()
{  
  var vsArr = vAppInstanceStr.split(";");  
  if (vsArr.length==0)
  {
      alert("系统未找到用户建立的应用，请检查应用是否正确注册！");
	  return false;
  }    
  for (i=0;i<vsArr.length-1;i++) 
  {
    var vsArrbh = vsArr[i].split("~");    
    document.write("<OPTION value="+vsArrbh[0]+">"+vsArrbh[1]+"</OPTION>");
  }  
}

function Txt_blur()
{
	event.srcElement.className = "";
}

function Txt_focus()
{
	event.srcElement.className = "TextOn";
}

/*语法检查*/
function SyntexCheck()
{
  if (fmloadpad.selInstance.options[fmloadpad.selInstance.selectedIndex].text == "") 
  {
    alert("请选择一个帐套");
    fmloadpad.selInstancetxt.focus();
    return false;
  }
  else if (fmloadpad.TxtUserID.value == "")
  {
    alert("请输入用户代码");
    fmloadpad.TxtUserID.focus();
    return false;
  }  
  /*else if (fmloadpad.TxtDutyID.value == ""&&fmloadpad.TxtUserID.value!="9999")
  {
      alert("请输入职责代码");
      fmloadpad.TxtDutyID.focus(); 
       return false;     
   }*/
  else if (fmloadpad.TxtUserID.value!="9999") 
  {
    if (fmloadpad.Txtkjdate.value =="")
    {
      alert("请输入会计日期");
      fmloadpad.Txtkjdate.focus();
      return false;
     }

    if (fmloadpad.Txtkjdate.value.length!=10) 
    {
       alert("会计日期输入有误");
       fmloadpad.Txtkjdate.focus();
    }
    else
      {
        var
           s=""+fmloadpad.Txtkjdate.value;
           i=0;
           while ((i>=0)&&i<(s.length))
     	    { 
              if ((i!=4)&&(i!=7))
              if (s.substring(i,i+1)==".")
                 {
                   alert("会计日期输入有误");
                   fmloadpad.Txtkjdate.focus();
                   break;
                 }
             i=i+1;
             }
         if ((i==s.length)&&(isDate(s)==true)) 
             return true;
          else
             {
               alert("会计日期输入有误");
               fmloadpad.Txtkjdate.focus();
               return false;                            
              }
       }
  }
  else
    return true;
}

function GetNo(AStr)
{
  var AArray = AStr.split(" "); 
  
  return AArray[0];
}

/*用户登录*/
function UserLogin(){ 
  
  if (SyntexCheck())
  {
    var mm;
//	mm=GetClientMsg1.GetClientName();
//	mm=GetClientMsg1.GetClientMac();
	mm=GetClientMsg1.GetClientIP();
    fmloadpad.hdclentip.value=mm;
    document.fmloadpad.submit();  
   } 
   
}

/*语法检查*/
function SyntexCheckD()
{
  if (TxtDutyID.value == "")
  {
    alert("请输入职责代码");
    TxtDutyID.focus();
    return false;
  }
  else
    return true;
}


/*更换职责*/
function ChangeDuty()
{
  var param= null;
  var BackValue = null;
  var BackArray = new Array();
  
  if (SyntexCheckD())
  {
    param = "DutyID=" + TxtDutyID.value;
    param += "&ADate=" + "";
    param += "&StationMsg=" + "hello";
    BackValue = window.showModalDialog("w_onChangeDuty.asp?" + param,"","status:no;dialogHeight:1px;dialogWidth:300px;center:yes");    
    BackArray = BackValue.split(";");
    if (BackArray[0] == "1")
    { 
      //alert(BackArray[1]);
      //window.location.href="MainPage.asp?processID="+BackArray[1];
      SaveCookie("ProcessID", BackArray[1], -1); 
      window.location.href="../../sys/menushow/mainmenu.asp";
    }
    else
      alert(BackArray[1]);
  }
}
/*语法检查*/
function SyntexCheckUD()
{
  if (TxtUserID.value == "")
  {
    alert("请输入用户代码");
    TxtUserID.focus();
    return false;
  }
  else if (TxtDutyID.value == "")
  {
    alert("请输入职责代码");
    TxtDutyID.focus();
    return false;
  }
  else
    return true;
}

/*更换操作员和职责*/
function ChangeUserAndDuty()
{
  var param= null;
  var BackValue = null;
  var BackArray = new Array();
  if (SyntexCheckUD())
  {
    SaveCookie("Extra", TxtPassword.value, -1);
    
    param = "UserID=" + TxtUserID.value;
    param += "&DutyID=" + TxtDutyID.value;
    param += "&ADate=" + "";
    param += "&StationMsg=" + "hello";
    BackValue = window.showModalDialog("w_onChangeUD.asp?" + param,"","status:no;dialogHeight:1px;dialogWidth:300px;center:yes");    
    BackArray = BackValue.split(";");
    if (BackArray[0] == "1")
    { 
      //alert(BackArray[1]);
      SaveCookie("ProcessID", BackArray[1], -1);       
       window.location.href="../../sys/menushow/mainmenu.asp";
    }
    else
      alert(BackArray[1]);
  }
}

/*登录页面初始*/
function LoginOnload()
{
 var   indexid=1;
 var   str;
 var   DateStr;
 var   vsTempDate;
 var   month;
 var   date;

	vsTempDate=new Date();
	month=vsTempDate.getMonth()+1;            
	date=vsTempDate.getDate();
	if (month<10)
		month="0"+month;
	if (date<10)
		date="0"+date;    
	fmloadpad.Txtkjdate.value=""+vsTempDate.getFullYear()+"."+month+"."+date;
	
	
/*var AExpires = new Date();
//AExpires.setTime(AExpires.getTime() + 24 * 60 * 60 * 365 * 1000); 
AExpires.setMonth(AExpires.getMonth()+1); 
document.cookie = "UserID="+"9999"+";expires=" + AExpires.toGMTString();	*/
//alert(document.cookie);
  
 if (GetCookie("AppID")!='NoName')
  {  
  }
  var aCookie = document.cookie.split(";");
  for (var i=0; i<aCookie.length; i++)
  {
   var curCookie= aCookie[i].split("=");
    if (trim(curCookie[0])=="UserID") 
    {
		fmloadpad.TxtUserID.value=curCookie[1];
    }
    if (trim(curCookie[0])=="ExtraDate") 
    {
		fmloadpad.Txtkjdate.value=curCookie[1];
    }
    if (trim(curCookie[0])=="AppInstanceID") 
    {
	    for(indexid=0;indexid<=fmloadpad.selInstance.options.length-1;indexid++)
        {     
			str=fmloadpad.selInstance.options[indexid].value;
			if (trim(str)==trim(curCookie[1]))
			{
				fmloadpad.selInstance.selectedIndex=indexid;
				fmloadpad.selInstancetxt.value=fmloadpad.selInstance.options [fmloadpad.selInstance.selectedIndex].text;
				fmloadpad.selInstanceid.value=fmloadpad.selInstance.options [fmloadpad.selInstance.selectedIndex].value;
			}
	    }    
     }
    if (trim(curCookie[0])=="ProcessID") 
    {
     
        fmloadpad.hdProcessID.value=curCookie[1];
    }
  }
 fmloadpad.TxtUserID.select();
 fmloadpad.TxtUserID.focus();
 
}

/*用户退出*/
function UserQuit()
{
  var BackValue = null;
  var BackArray = new Array();
  
  BackValue = window.showModalDialog("w_onUserQuit.asp?","","status:no;dialogHeight:1px;dialogWidth:300px;center:yes");

  BackArray = BackValue.split(";");

  if (BackArray[0] == "1")
  {     
    window.location.href="../../SYS/userlogin/UserLoad.asp";
  }
  else
    alert(BackArray[1]);
}



