﻿	function My_Substr(strPara,Place1,Place2)
	{
        var Len,Supply;
        Len = strPara.length;
        Supply = "";
        if (Len < Place2)
        {
            for(var i = 0; i < Place2 - Len; i ++) { Supply += "&nbsp;";}
            strPara += Supply;
        }
        else { strPara = strPara.substr(Place1,Place2); }
        return strPara;
    }

	function strLen(str)
	{
		var Chinese_OS;
		var strTest, ch, slen, i;
		Chinese_OS = false;
		strTest = "中文";
		if ( strTest.length == 2 )	Chinese_OS = true;
		if ( Chinese_OS )
		{
			slen = 0;
			for ( i = 0; i < str.length; i ++)
			{
				ch = str.charCodeAt( i );
				if ( ch < 0 ) ch = ch + 65536;
				if ( ch > 255 ) slen = slen + 1;
				slen = slen + 1;
			}
		}
		else
		{ slen = str.length }
		return (slen);
	}

	function chkText(iptID,explain,bulk,must,regExpressions)
	{
		switch(must)
		{
			case 0:
			if (iptID.value != "")
			{
				if (iptID.value.length > bulk)
				{
					alert(explain + "不得超过" + bulk + "个字，现在是：" + iptID.value.length + "个字！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false
				}
			}
			break;
			case 1:
				if (iptID.value == "")
				{
					alert("请填入" + explain + "！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false;
				}
				else
				{
					if (iptID.value.length > bulk)
					{
						alert(explain + "不得超过" + bulk + "个字，现在是：" + iptID.value.length + "个字！！");
						if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
						return false
					}
				}
			break;
			case 2:
				if (iptID.value == "")
				{
					alert("请填入" + explain + "！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false;
				}
			break;
		}

		if (regExpressions)
		{
			if (!regExpressions.test(iptID.value))
			{
				alert("请正确填写" + explain + "！！");
				if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
				return false;
			}
		}
		return true;
	}

	function checkRadio(sRadioName,sFieldName){
		var radioGroup = document.getElementsByName(sRadioName);
		var isSelected = false;
		for(i=0;i<radioGroup.length;i++){if(radioGroup[i].checked){isSelected = true}}
		if(!isSelected){alert("请选择" + sFieldName + "！！！")}
		return isSelected;
	}
	function getRadioValue (sRadioName){
		var radioGroup = document.getElementsByName(sRadioName);
		var radioValue = null;
		for(i=0;i<radioGroup.length;i++){if(radioGroup[i].checked){radioValue = radioGroup[i].value}}
		return radioValue;
	}

	function chkNumber(iptID,explain,isnull,minbulk,maxbulk)
	{

		var chkNumberF = function()
		{
			var regNumber = /^[0-9\.]*$/;
			if (!regNumber.test(iptID.value))
			{
				alert(explain + "必须填入数字！！");
				if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
				return false;
			}
			if (minbulk != "")
			{
				if (Number(iptID.value) < Number(minbulk))
				{
					alert(explain + "值不得小于 " + minbulk + " ！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false;
				}
			}
			if (maxbulk != "")
			{
				if (Number(iptID.value) > Number(maxbulk))
				{
					alert(explain + "值不得大于 " + maxbulk + " ！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false;
				}
			}
			return true;
		}
		if(isnull == 1)
		{
			if (iptID.value == "")
			{
				alert("请填入" + explain + "！！");
				if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
				return false;
			}
			return chkNumberF();
		}
		else
		{
			return chkNumberF();
		}
		return true;
	}


	function chkSelect(iptID,explain,nullValue)
	{
		if (iptID.value == nullValue)
		{
			alert("请选择" + explain + "！！");
			if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
			return false;
		}
		return true;
	}

	function chkNoChinese(str)
	{
		var re = /[a-zA-Z0-9]+/;
		return re.test(str);
	}


	function chkNotChinese(iptID,explain,must)
	{
		if (must == 1)
		{
			if (iptID.value == "")
			{
				alert("请填入" + explain + "！！");
				if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
				return false;
			}
			else
			{
				if (!chkNoChinese(iptID.value))
				{
					alert(explain + "不得输入汉字！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false
				}
			}
		}
		else
		{
			if (iptID.value != "")
			{
				if (!chkNoChinese(iptID.value))
				{
					alert(explain + "不得输入汉字！！");
					if (iptID.type != "hidden" && iptID.style.display != "none" ) iptID.focus();
					return false
				}
			}
		}
		return true;
	}

	function chkDate(sDate)
	{
		var r = /\d{4}-\d{1,2}-\d{1,2}/;
		if (sDate.match(r) == sDate)
		{
			return true;
		}
		return false;
	}


	function ViewCode()
	{
		var w = open();
		w.document.open();
		w.document.write(document.documentElement.outerHTML.replace(/&/g,"&").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/ /g,"&nbsp;").replace(/\r\n/g,"<br>"));
		w.document.close();
	}

	function checkPic(strExplain,srcPic,srcShowPic,intHeight,intWidth,intSize,strAllowExt,intMust,intCheckType)
	{
		//var srcPic = event.srcElement;
		var strPicUrl = srcPic.value;
		var strPicAllowExt,arrAllowExt;
		var strAlert,strErr;
		var objTmpSrc;
		var bitAllowExt = true;
		var picHeight,picWidth,picSize;
		var spHeight = srcShowPic.offsetHeight;
		var spWidth = srcShowPic.offsetWidth;
		strErr = "[" + strExplain + "]上传图片错误！！";
		strAlert = "请为 [" + strExplain + "] 选择上传图片";
		if ( intHeight != "" ) 		{ strAlert += "\n图片高度为：" + intHeight; }
		if ( intWidth != "" )		{ strAlert += "\n图片宽度为：" + intWidth; }
		if ( intSize != "" ) 		{ strAlert += "\n图片大小为：" + intSize; }
		if ( strAllowExt != "" )	{ strAlert+= "\n" + "图片格式为：" + strAllowExt; }
		if ( strPicUrl != "" )
		{
			strPicAllowExt = strPicUrl.substring(strPicUrl.lastIndexOf(".") + 1).toLowerCase();
			if (strPicAllowExt == "") { alert(strAlert);  srcPic.focus(); return false; }
			else
			{
				if ( strAllowExt != "" )
				{
					arrAllowExt = strAllowExt.split(";");
					for ( var i = 0 ; i < arrAllowExt.length; i ++)
					{
						if ( arrAllowExt[i].toString().toLowerCase()  != strPicAllowExt ) { bitAllowExt = false; }
						else { bitAllowExt = true; break; }
					}
				}
				if ( bitAllowExt == false ) { alert( strErr + "\n上传图片格式应为：" + strAllowExt + "\n请重新选择上传图片！！"); srcPic.focus();return false; }
				objTmpSrc = document.getElementById(srcPic.id.toString() + "_Pic");
				if (objTmpSrc) { srcShowPic.removeChild(objTmpSrc); }
				objTmpSrc = document.createElement("IMG");
				objTmpSrc.id = srcPic.id.toString() + "_Pic";
				objTmpSrc.name = srcPic.id.toString() + "_Pic";
				objTmpSrc.src = "file:///" + strPicUrl.replace("\\", '/');
				picHeight = objTmpSrc.height;
				picWidth = objTmpSrc.width;
				picSize = objTmpSrc.fileSize;
				if ( intHeight != "" )  { if ( intHeight < picHeight ) { alert( strErr + "\n上传图片高度应为：" + intHeight + "， 目前选择的图片高度为：" + picHeight );  srcPic.focus();  return false;  } }
				if ( intWidth != "" ) { if ( intWidth < picWidth )  { alert( strErr + "\n上传图片宽度应为：" + intWidth + "， 目前选择的图片高度为：" + picWidth );  srcPic.focus();  return false;  } }
				if ( intSize != "" ) { if ( (intSize * 1024 ) < picSize ) { alert( strErr + "\n上传图片大小应为：" + intSize + "， 目前选择的图片大小为：" + parseInt(picSize / 1024) );  srcPic.focus();  return false; }}
			}
		}
		else { if (intMust == 1) { alert(strAlert); return false; }	}
		if (intCheckType == 0) {
		    if (srcShowPic) {
		        srcShowPic.innerHTML = "";
		        var spHeight = srcShowPic.offsetHeight;
		        var spWidth = srcShowPic.offsetWidth;
		        if (objTmpSrc.height > spHeight) { objTmpSrc.height = spHeight * 0.95; }
		        if (objTmpSrc.width > spWidth) { objTmpSrc.width = spWidth * 0.95; }
		        srcShowPic.appendChild(objTmpSrc);
		    }
		}
		return true;
	}

	function CutPic(srcPic,intHeight,intWidth)
	{
		if ( srcPic.height > intHeight ) { srcPic.height = intHeight ; }
		if ( srcPic.width > intWidth ) { srcPic.width = intWidth; }
	}
