﻿// JScript 文件

function showMsg(aControl,aMsg) {
    window.alert(aMsg);
    if (aControl != null){
        aControl.focus();
        aControl.select();
    }
}
function sameInput(aControl,aRefControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	if (typeof(aRefControl) == "string") {
		aRefControl = document.getElementById(aRefControl);
	}
    if (aControl.value != aRefControl.value ){
        window.alert("两次输入的" + aMsg +"不一致，请检查");
        aControl.focus();
        aControl.select();
        throw "";
    }
    return true;
}
function emptyInput(aControl, msgText){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    if (aControl.value.length < 1) {
        showMsg(aControl, msgText + "不能为空");
        throw "";
    }
    return true;
}
function minMaxLengthInput(aControl,aMin,aMax,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    emptyInput(aControl,aMsg);
    if ( aControl.value.length < aMin || aControl.value.length > aMax){
        var tmsg = "["+aMsg+"] "+aMsg+"的长度应该大于"+aMin + " 位并且小于"+aMax+"位";
        showMsg(aControl,tmsg);
        throw "";
    }
    return true;
}
function numericInput(aControl,msgText){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    var ttext = aControl.value;
    if (isNaN(ttext) == true){
        window.alert(msgText + "输入内容不是数字");
        aControl.value='';
        aControl.focus();
        aControl.select();
        throw "";
    }
    return true;
}

function minMaxInput(aControl,aMin,aMax,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    if (aMin > 0 && aControl.value.length < 1){
        window.alert(aMsg + "不能为空");
        aControl.focus();
        aControl.select();
        throw "";
    }
    numericInput(aControl,aMsg)
    var tvalue = parseFloat(aControl.value);
    if ( tvalue < aMin || tvalue > aMax){
        window.alert(aMsg+"值应该大于 "+aMin + " ,且小于 " + aMax + ",请检查.. ");
        aControl.focus();
        aControl.select();
        throw "";
    }
    return true;
}

function dateInput(aControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    if (aControl.value == "") return true;
    var x = Date.parse(aControl.value);
    if ( x < 0 || x != x){
        showMsg(aControl,"["+aMsg+"] "+aMsg+"格式不正确，日期格式: 1900/01/01 、 01/01/1900 ");
        throw "";
    }
    return true;
}

function ddlbInput(aControl,aMsg) {
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    if (aControl.selectedIndex > 0 ) return true;
    window.alert("[" + aMsg + "] 不能为空，请选择");
    aControl.focus();
        throw "";
}



//var URLRegExp = "http(s)?://(\w|\-.)+(\w|\-)+(/)?(\w|\-|\ |./?%&=]*)?"
/* 
var EMAILRegExp = /\w+([\-+.']\w+)*@\w+([\-.]\w+)*\.\w+([\-.]\w+);
var URLRegExp = /\w{3}/;
var CAIDIDRegExp = /\d{15} | \d{18}(X|x)?/;
var FIXPHONERegExp = /0\d{2,3}\-\d{7,8}|(0\d{2,3})\d{7,8}/;
var MOBILEPHONERegExp = /0?1(3|5)\d{9}/;
*/

function regexInput(aControl,aRegex,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    if (aControl.value.length == 0 ) return true;
    var tret = aRegex.exec(aControl.value);
    var tlength = aControl.value.length;
    if (tret != null && tret.index == 0 && tret.lastIndex == tlength ) return true;
    window.alert(aMsg+"格式不正确，请重新输入 ... ");
    aControl.focus();
    aControl.select();
        throw "";
}

function URLInput(aControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	var treg = new RegExp("http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w\\.\\?\\&\\=\\%]*)*","ig");
	return  regexInput(aControl,treg,aMsg);
}
function EMailInput(aControl,aMsg) {
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	var treg = new RegExp("\\w*@([\\w-]+\\.)+[\\w-]+","ig");
	return  regexInput(aControl,treg,aMsg);
}
function FixPhoneInput(aControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	var treg = new RegExp("(0\\d{2,3}-?\\d{7,8}|(0{2,3})\\d{7,8})(:\\d{2,4})?","ig");
	return  regexInput(aControl,treg, aMsg);
}
function MobilePhoneInput(aControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	var treg = new RegExp("0?1[3-5]\\d{9}","ig");
	return  regexInput(aControl,treg,aMsg);
}
function CardIDInput(aControl,aMsg){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
	var treg = new RegExp("(\\d{15}|\\d{18})[xX]?","ig");
	return  regexInput(aControl,treg,aMsg);
}

function Elem(aElemName){
	if (typeof(aControl) == "string") {
		aControl = document.getElementById(aControl);
	}
    return document.getElementById(aElemName);
}
function CheckList(aName){
    var i=0;
    var ch1="";
    var str="";
    while((ch1=document.getElementById(aName+"_"+i))!=null)
    {
      if(ch1.checked)
      {     
       return true; 
      } 
       i++;         
    }
    alert("请选择一项！");  
    return false;
}


