﻿// JScript 文件

//去掉字串左边的空格 
function lTrim(str) 
{ 
    if (str.charAt(0) == " ") 
    {
    str = str.slice(1);//将空格从字串中去掉 
    str = lTrim(str); //递归调用 
    } 
    return str; 
}

//去掉字串右边的空格
function rTrim(str) 
{ 
    var iLength;
    iLength = str.length; 
    if (str.charAt(iLength - 1) == " ") 
    { 
        str = str.slice(0, iLength - 1);
        str = rTrim(str); //递归调用 
    } 
    return str; 
}  

function ShowModeWin(strPath, iWidth, iHeight, bFlushScreen)
{
    //alert('dialogWidth=' + iWidth + ';dialogHeight=' + iHeight);
    window.showModalDialog(strPath, '模式', 'status=no;dialogWidth=' + iWidth + 'px;dialogHeight=' + iHeight + 'px');
    return bFlushScreen;
}

function ShowModeWinWithParam(strPath, iWidth, iHeight, vParam)
{
    //alert('dialogWidth=' + iWidth + ';dialogHeight=' + iHeight);
    return window.showModalDialog(strPath, vParam, 'status=no;dialogWidth=' + iWidth + 'px;dialogHeight=' + iHeight + 'px');
}

function OpenWin(strPath, iWidth, iHeight, bFlushScreen)
{
    window.open(strPath, '非模式', 'status=no, width=' + iWidth + 'px, height=' + iHeight + 'px, scrollbars=yes, resizable=yes, top=20px, left=300px');
    return bFlushScreen;
}


//回车代替tab
function keyvalue(strEle) 
{ 
	if(event.keyCode=="13") 
	{ 
		var strEles = strEle.split(',');
		var bOrder = true;
		if(strEle != '')
		{
			for(var i = 0; i < strEles.length; i++)
			{
				if(event.srcElement.id == strEles[i])
				{
					bOrder = false;
					break;
				}
			}
		}
		if(bOrder && event.srcElement.type != 'button' && event.srcElement.type != 'submit' &&
		 event.srcElement.type != 'reset' && event.srcElement.type != 'textarea' && event.srcElement.type != '') 
		{ 
			event.keyCode="9"; 
		} 
	}
} 

//判断是否输入数字符合标准
function CheckNumber(iPoint)
{
    var strCheck = lTrim(rTrim(event.srcElement.value));
    var bRight = false;
    
    if(strCheck != '')
    {
        if(iPoint == 0)
        {
            var oResult = strCheck.match(/\d+/);
            if(oResult != strCheck)
            {
                alert('请输入整数');
                event.srcElement.value = '';
                event.srcElement.focus();
            }
        }
        if(iPoint > 0)
        {
            var oResult = strCheck.match(/\-{0,1}\d+\.{0,1}\d{0,2}/);
            if(oResult != strCheck)
            {
                alert('请输入有效的数字');
                event.srcElement.value = '';
                event.srcElement.focus();
            }
        }
    }
}

//判断是否输入合法日期
function CheckDate()
{
    while(event.srcElement.value.indexOf('.') != -1)
    {
        event.srcElement.value = event.srcElement.value.replace('.', '-')
    }
    while(event.srcElement.value.indexOf('．') != -1)
    {
        event.srcElement.value = event.srcElement.value.replace('．', '-')
    }
    while(event.srcElement.value.indexOf('－') != -1)
    {
        event.srcElement.value = event.srcElement.value.replace('－', '-')
    }
    var strCheck = lTrim(rTrim(event.srcElement.value));
    var bRight = false;
    if(strCheck != '')
    {
        var oResult = strCheck.match(/\d{4}\-\d{1,2}\-\d{1,2}/);
        if(oResult != strCheck)
        {
            alert('请输入正确的日期格式，如2006-06-24');
            event.srcElement.value = '';
            event.srcElement.focus();
        }
    }
}
