﻿// JScript 文件
var strErr="";
function NumCheck(strValue){ 
	nr1=strValue; 
	errors="";	
	for (var i=0;i<nr1.length;i++){ 
			cmp="0123456789"; 
			tst=nr1.substring(i,i+1) 
			if (cmp.indexOf(tst)<0){ 
				errors=AlertStr.strIsNum;
			} 
			 
			
		} 
	
	return errors;
} 

function LTrim(string) 
{
  for (i=0; i<string.length; i++) {
    if (string.charAt(i) != " ") {
       string = string.substring(i,string.length)
       return(string);
    }
  }
  return("");
}

function RTrim(string) 
{
  for (i=string.length; i>0; i--) {
    if (string.charAt(i-1) != " ") {
       string = string.substring(0,i)
       return(string);
    }
  }
  return("");
}

function Trim(string) {
	S1 = LTrim(string);
	S2 = RTrim(S1);
    return(S2);
}

function CheckValue(tInput,IsR,IsNum,strTile)
{
    theInput=document.getElementById(tInput);
    theAlt=document.getElementById(tInput+"_S");
    theMaxSize= document.getElementById(tInput+"_Max_Size");
    theMinSize= document.getElementById(tInput+"_Min_Size");
    theSize= document.getElementById(tInput+"_Size");
     
    if(theInput!=null)
    {
        if(IsR==1)
        {
            if((Trim(theInput.value)==""&&IsNum!=4&&IsNum!=5)||((IsNum==4||IsNum==5)&&theInput.value==""))
            {
                strErr=strTile+AlertStr.strIsNull;
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                }
                else
                {
                    alert(strErr);
                }
                theInput.focus();
                return false;
            }
            else
            {
                if(IsNum!=4&&IsNum!=5)
                {
                    iLength=Trim(theInput.value).length;
                }
                else
                {
                    iLength=theInput.value.length;
                }
                strErr="";
                if(theSize!=null)
                {
                    if(iLength!=theSize.value)
                    {
                        strErr=strTile+AlertStr.strLength;
                    }
                }
                if(theMaxSize!=null)
                {
                    if(iLength>theMaxSize.value)
                    {
                        strErr=strTile+AlertStr.strLength;
                    }
                }
                if(theMinSize!=null)
                {
                    if(iLength<theMinSize.value)
                    {
                        strErr=strTile+AlertStr.strLength;
                    }
                }
                if(strErr=="")
                {
                    if(theAlt!=null)
                    {
                        theAlt.innerHTML="<br><img src='"+strPath+"/images/h_ok.gif' style='vertical-align:middle;'>";
                    }
                }
                else
                {
                    if(theAlt!=null)
                    {
                        theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                    }
                    else
                    {
                        alert(strErr);
                    }
                    theInput.focus();
                    return false;
                }
            }
        }
        if(IsNum==1&&Trim(theInput.value)!="")
        {
            strNum=NumCheck(Trim(theInput.value));
            strErr=strTile+AlertStr.strNum;
            if(strNum!="")
            {
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                }
                else
                {
                    alert(strErr);
                }
                theInput.focus();
                return false;
            }
            else
            {
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_ok.gif' style='vertical-align:middle;'>";
                }
            }
        }
        
        if(IsNum==2&&Trim(theInput.value)!="")
        {
            strDate=checkDateByMask(Trim(theInput.value),"yyyy-MM-dd");
            if(!strDate)
            {
                alert(strTile+AlertStr.strAlertDate);
                theInput.focus();
                strErr=strTile+AlertStr.strAlertDate;
                return false;
            }
        }
        
        if(IsNum==3&&Trim(theInput.value)!="")
        {
            patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            if (!patrn.test(theInput.value))
            {
                strErr=strTile+AlertStr.strFormat;
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                }
                else
                {
                    alert(strErr);
                }
                theInput.focus();
                return false;
            }
            else
            {
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_ok.gif' style='vertical-align:middle;'>";
                }
            }
        }
        
        if(IsNum==4&&theInput.value!="")
        {
            strAZ=AZCheck(theInput.value);
            if(strAZ!="")
            {
                strErr=strTile+AlertStr.strValidate;
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                }
                else
                {
                    alert(strErr);
                }
                theInput.focus();
                return false;
            }
        }
        
        
        if(IsNum==5&&theInput.value!="")
        {
            strAZ=AZCheck(theInput.value);
            if(strAZ!="")
            {
                strErr=strTile+AlertStr.strValidate;
                if(theAlt!=null)
                {
                    theAlt.innerHTML="<br><img src='"+strPath+"/images/h_error.gif' style='vertical-align:middle;'>"+strErr;
                }
                else
                {
                    alert(strErr);
                }
                theInput.focus();
                return false;
            }
        }
        
    }
    return true;
     
}
function CheckAZValue(theInput,strTile)
{
    
        if(Trim(theInput.value)=="")
        {
            alert(strTile+AlertStr.strIsNull);
            theInput.focus();
            strErr=strTile+AlertStr.strIsNull;
            return false;
        }
    
    
        strNum=AZCheck(Trim(theInput.value));
        if(strNum!="")
        {
            alert(strTile+strNum);
            theInput.focus();
            strErr=strTile+AlertStr.strNum;
            return false;
        }
   
    return true;
     
}
function AZCheck(strValue){ 
	nr1=strValue; 
	errors="";	
	for (var i=0;i<nr1.length;i++){ 
			cmp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; 
			tst=nr1.substring(i,i+1) 
			if (cmp.indexOf(tst)<0){ 
				errors=AlertStr.strValidate;
			} 
			 
			
		} 
	
	return errors;
} 

function Check_All(theform)
{
    tt=theform.CheckAll.checked;
    var chkObject = document.getElementsByName("CheckId");
    if(chkObject!=null)
    {
        //var CheckBoxList=theform.CheckId;
        for(i=0;i<chkObject.length;i++)   
        {  
            chkObject[i].checked=tt;
            
        }
    }
}

function DelList(StrURL,theform,ssplit)
{
    delid="";
    tt=false;
    var chkObject = document.getElementsByName("CheckId");
    if(chkObject!=null)
    {
        var CheckBoxList=chkObject;
        for(i=0;i<CheckBoxList.length;i++)   
        {  
            if(CheckBoxList[i].checked==true)
            {
                tt=true;
                if(delid=="") 
                {
                    if(ssplit==1){
                        delid="'"+CheckBoxList[i].value+"'";
                    }
                    else
                    {
                        delid=CheckBoxList[i].value;
                    }
                }
                else
                {
                    if(ssplit==1){
                        delid=delid+",'"+CheckBoxList[i].value+"'";
                    }
                    else
                    {
                        delid=delid+","+CheckBoxList[i].value;
                    }
                }
            }
            
        }
    }
    
    if(!tt)
    {
        alert(AlertStr.strDel);
    }
    else
    {
        theform.action=StrURL;
        theform.DelId.value=delid;
        theform.submit();
    }
    
}



function    checkDateByMask(s,m){  
           if  (s.length!=m.length){  
                return  false;  
           }  
           try{  
               var  d  =  getDateByMask(s,m);
               m=m.replace(/Y/g,"y").replace(/D/g,"d");  
               if  (m.indexOf("yyyy")>-1)    
                    return   (d.getFullYear()  ==  s.substr(m.indexOf("yyyy"),4) &&  d.getMonth()  ==  s.substr(m.indexOf("MM"),2)-1&&  d.getDate()  ==  s.substr(m.indexOf("dd"),2)); 
               else  
                    return   (d.getYear()  ==  s.substr(m.indexOf("yy"),2) &&d.getMonth()  ==  s.substr(m.indexOf("MM"),2)-1 &&  d.getDate()  ==  s.substr(m.indexOf("dd"),2));
            }  
            catch  (e)  
            {  
                       return  false;  
             }  
 }  

function    getDateByMask(s,m){      
           if  (s.length!=m.length){  
                       return  false;  
           }  
           try{  
                   m=m.replace(/Y/g,"y").replace(/D/g,"d");  
                   if  (m.indexOf("yyyy")>-1)    
                      return    new    Date(s.substr(m.indexOf("yyyy"),4),s.substr(m.indexOf("MM"),2)-1, s.substr(m.indexOf("dd"),2));
                   else 
                      return    new    Date(s.substr(m.indexOf("yy"),2), s.substr(m.indexOf("MM"),2)-1, s.substr(m.indexOf("dd"),2));
            }  
           catch  (e)  
            {  
                       return  null;  
            }  
  }  


function MoveList(StrURL,theform,ssplit)
{
    delid="";
    tt=false;
    var chkObject = document.getElementsByName("CheckId");
    if(chkObject!=null)
    {
        var CheckBoxList=chkObject;
        for(i=0;i<CheckBoxList.length;i++)   
        {  
            if(CheckBoxList[i].checked==true)
            {
                tt=true;
                if(delid=="") 
                {
                    if(ssplit==1){
                        delid="'"+CheckBoxList[i].value+"'";
                    }
                    else
                    {
                        delid=CheckBoxList[i].value;
                    }
                }
                else
                {
                    if(ssplit==1){
                        delid=delid+",'"+CheckBoxList[i].value+"'";
                    }
                    else
                    {
                        delid=delid+","+CheckBoxList[i].value;
                    }
                }
            }
            
        }
    }
    
    if(!tt)
    {
        alert(AlertStr.strMove);
    }
    else
    {
        if(theform.SelectGroup.value=="")
        {
            alert(AlertStr.strMemberGrp);
        }
        else
        {
            theform.action=StrURL;
            theform.DelId.value=delid;
            theform.submit();
        }
    }
    
}

function pickDate(objOb)
{
	var	strURL	= "../common/datepicker.html";
	var	strIni	= objOb.value;

	var	strFtr	= "dialogHeight: 240px; dialogWidth: 320px; ";
	strFtr	= strFtr + "dialogLeft: " + window.event.screenX + "px; ";
	strFtr	= strFtr + "dialogTop: " + window.event.screenY + "px; ";
	strFtr	= strFtr + "edge: Sunken; center: no; help: No; resizable: No; scroll: No; status: No;"

	var	strVal	= window.showModalDialog (strURL, strIni, strFtr);
	if (strVal != "")
	{
		objOb.value	= strVal;
	}
}


function len(s) { 
var l = 0; 
var a = s.split(""); 
for (var i=0;i<a.length;i++) { 
if (a[i].charCodeAt(0)<299) { 
l++; 
} else { 
l+=2; 
} 
} 
return l; 
}
