/******************************************************************
提供:
	1、去除空格;
	2、检测整数及整数范围;
	3、检测浮点数及浮点数范围;
	4、解析、合成QueryString字符串;
	5、检测日期格式 YYYY-MM-DD;
	6、弹出模态对话框;
	7、得到字符串长度;
时间: 2006-10-08
*******************************************************************/

var ObjBase = new Object();

//去左右空格//
ObjBase.Trim = function (AValue)
{
	if (AValue == "")
	{
		return "";
	}
	var i = 0;
	var len = AValue.length;
	while (i < len && AValue.substring(i,i+1) <= " ")
	{
		i++;
	}
	if (i > len)
	{
		return "";
	}
	else
	{
		while (AValue.substring(len-1,len) <= " ")
		{
			len --;
		}
		return AValue.substring(i,len);
	}
}
//去左空格//
ObjBase.TrimLeft = function (AValue)
{
	if (AValue == "")
	{
		return "";
	}	
	var i = 0;
	var len = AValue.length;
	while (i <= len && AValue.substring(i,i+1) <= " ")
	{
		i++;
	}
	return AValue.substring(i,len);
}
//去右空格//
ObjBase.TrimRight = function (AValue)
{
	if (AValue == "")
	{
		return "";
	}	
	var len = AValue.length;
	while (AValue.substring(len-1,len) <= " ")
	{
		len --;
	}
	return AValue.substring(0,len);
}
//得到长度//
ObjBase.Length = function (AValue)
{
	var len = 0;
	for (var i = 0; i < AValue.length; i++)
	{
		if (AValue.charCodeAt(i) > 0 && AValue.charCodeAt(i) < 255)
		{
			len ++;
		}
		else
		{
			len += 2;
		}
	}
	return len;
}
//是否为整数//
ObjBase.CheckNum = function (AValue)
{
	if (AValue.length == 0)
	{
		return false;
	}

	var sValidate = "0123456789", sTmp = "";
	for (var i = 0; i < AValue.length; i++)
	{
		sTmp = AValue.charAt(i);
		if (sValidate.indexOf(sTmp) == -1)
		{
			return false;
		}
	}
	return true;
}
//满足指定范围整数//
ObjBase.NumRange = function (AMaxValue, AMinValue, AValue)
{
	if (ObjBase.CheckNum(AValue))
	{
		var Num = parseInt(AValue);
		return Num >= AMinValue && Num <= AMaxValue;
	}
	else
	{
		return false;
	}
}
//是否为浮点数//
ObjBase.CheckFloat = function (AValue)
{
	if (AValue.length == 0)
	{
		return false;
	}

	var sValidate = "0123456789", sTmp = "", bDot = false;
	for (var i = 0; i < AValue.length; i++)
	{
		sTmp = AValue.charAt(i);
		if (sTmp == "." && !bDot)
		{
			bDot = true;
			continue;
		}
		if (sValidate.indexOf(sTmp) == -1)
		{
			return false;
		}
	}
	return true;
}
//满足指定范围浮点数//
ObjBase.FloatRange = function (AMaxValue, AMinValue, AValue)
{
	if (ObjBase.CheckFloat(AValue))
	{
		var Num = parseFloat(AValue);
		return Num >= AMinValue && Num <= AMaxValue;
	}
	else
	{
		return false;
	}}
//是否符合YYYY-MM-DD格式//
ObjBase.CheckDate = function (AValue)
{
	var reg = /^(\d{4})(-)(\d{2})(-)(\d{2})$/;
	var r = AValue.match(reg);
	if (r == null)
	{
		return false;
	}
	else
	{
		var d = new Date(r[1],r[3]-1,r[5]);
		//var newStr=d.getFullYear()+r[2]+(d.getMonth()+1)+r[4]+d.getDate();
		//return (newStr == AValue);
		return (parseInt(r[1]) == d.getFullYear() && parseInt(r[3]) == d.getMonth() + 1 
			&& parseInt(r[5]) == d.getDate());
	}
}
//弹出模态对话框//
ObjBase.PopDialog = function (AUrl,ATitle,ADialogArguments,AWidth,AHeight,AModalFramePath)
{
	
	if (AWidth == "")
	{
		AWidth = "500";
	}
	if (AHeight == "")
	{
		AHeight = "400";
	}
	var sParams = "scrollbar:no;status:no;resizable:no;unadorne:yes;";
	sParams += "dialogHeight:" + AHeight + "px;dialogWidth:" + AWidth + "px";
	
	var sUrl = ObjBase.ComposeQueryString(AModalFramePath, "TITLE", ATitle);
	sUrl += "&SRC=" + encodeURIComponent(decodeURI(AUrl)); 
	
	return showModalDialog(sUrl,ADialogArguments,sParams);
}
//分析QueryString//
ObjBase.AnalyzeQueryString = function (AQueryString, AParamName)
{
	if (ObjBase.Trim(AParamName) == "")
	{
		return "";
	}
	
	AQueryString = decodeURI(AQueryString);
	AParamName = AParamName.toUpperCase();
	var rValue = "";
	var iPos = AQueryString.indexOf("?");
	if (iPos != -1)
	{
		var iStart = -1, iEnd = -1;
		iStart = AQueryString.indexOf(AParamName+"=",iPos + 1);
		if (iStart != -1)
		{
			iEnd = AQueryString.indexOf("&", iStart + 1);
			if (iEnd == -1)
			{
				iEnd = AQueryString.length;
			}
			rValue = AQueryString.slice(iStart, iEnd);
			rValue = rValue.substring(rValue.indexOf("=") + 1, rValue.length)
		}
	}
	return rValue;
}
//解析QueryString, 返回参数名为下标的数组//
ObjBase.AnalyzeQueryStringToArray = function (AQueryString)
{
	if (ObjBase.Trim(AQueryString) == "")
	{
		return null;
	}	
	AQueryString = decodeURI(AQueryString);
	var rValue = new Array;
	var iPos = AQueryString.indexOf("?");
	if (iPos != -1)
	{
		var sParam = AQueryString.slice(iPos + 1);
		var rList = sParam.split("&");
		for (var i=0; i<rList.length; i++)
		{
			iPos = rList[i].indexOf("=");
			if (iPos != -1)
			{
				rValue[rList[i].substring(0, iPos)] = rList[i].substring(iPos + 1, rList[i].length);
			}
		}
	}
	return rValue;
}
//合成QueryString//
ObjBase.ComposeQueryString = function (AQueryString, AParamName, AParamValue)
{
	if (ObjBase.Trim(AQueryString) == "")
	{
		return "";
	}	
	if (ObjBase.Trim(AParamName) == "")
	{
		return AQueryString;
	}	
	AQueryString = decodeURI(AQueryString);
	AParamName = AParamName.toUpperCase();
	var sParam = AParamName + "=" + decodeURI(AParamValue);
	var rValue = "";
	var iPos = AQueryString.indexOf("?");
	if (iPos != -1)
	{
		var iStart = -1, iEnd = -1;
		iStart = AQueryString.indexOf(AParamName+"=",iPos + 1);
		if (iStart != -1)
		{
			iEnd = AQueryString.indexOf("&", iStart + 1);
			if (iEnd == -1)
			{
				iEnd = AQueryString.length;
			}
			rValue = AQueryString.slice(0, iStart) + sParam + AQueryString.slice(iEnd, AQueryString.length);
		}
		else
		{
			rValue = AQueryString + "&" + sParam;
		}
	}
	else
	{
		rValue = AQueryString + "?" + sParam;
	}
	return decodeURI(decodeURIComponent(rValue));
}

//焦点移动
ObjBase.KeyDown = function ()
{
	//屏蔽退格//
	if(event.srcElement.type != null)
	{
		if ( event.keyCode == 8 && event.srcElement.type.toUpperCase() != "TEXT" 
			&& event.srcElement.type.toUpperCase() != "TEXTAREA" && event.srcElement.type.toUpperCase() != "PASSWORD")
		{
			event.keyCode = 0;
			return false;
		}
	}
	//屏蔽刷新F5 Ctrl+R//
	if ((event.ctrlKey && event.keyCode == 82) || (event.keyCode == 116))
	{
		event.keyCode = 0;
		return false;
	}
	//回车下一个//
	if (event.keyCode == 13)
	{
		try
		{
			var obj = event.srcElement;
			var sTagName = obj.tagName.toUpperCase();
			var sType = obj.type.toUpperCase();
			
			if (sTagName == "TEXTAREA")
				return true;
			if (sTagName == "INPUT" && (sType == "SUBMIT" || sType == "RESET" || sType == "BUTTON"))
				return true;
			
			document.selection.empty();
			
			FocusObj(getNextObj(obj));
			return false;
		}
		catch(e)
		{
			return false;
		}
	}
	return true;
}
//设置焦点(全选文本)
function FocusObj(vObj)
{
	var sTagName = vObj.tagName.toUpperCase();
	var sType = vObj.type.toUpperCase();
	if (sTagName == "INPUT" && (sType == "TEXT" || sType == "FILE" || sType == "PASSWORD"))
	{
		vObj.select();
	}
	{
		vObj.focus();
		
	}
}
//得到当前活动对象的索引//
function getObjIndex(obj)
{
	var iIndex = -1;
	for (var i=0; i<document.forms[0].elements.length; i++)
	{
		if (obj == document.forms[0].elements[i])
		{
			iIndex = i;
			break;
		}
	}
	return iIndex;
}

//判断当控件隐藏时对光标焦点的判断
function GetCtrlVisible(obj)
{
	if (obj.style.display =="none" || obj.style.visibility == "hidden")
		return false;
	if (obj.parentElement == null)
		return true;
	else
		return GetCtrlVisible(obj.parentElement);
}

//得到下一个对象//
function getNextObj(obj)
{

	var ele = document.forms[0].elements[(getObjIndex(obj) + 1) % document.forms[0].elements.length];
	if (ele == obj)
	{
		return obj;
	}
	else
	{
		if (!ele.disabled && !ele.readOnly && ele.type.toUpperCase() != "HIDDEN" && GetCtrlVisible(ele))
		{
			return ele;
		}
		else
		{
			return getNextObj(ele);
		}
	}
}
//设置焦点//
ObjBase.setFocus = function ()
{
	if (document.forms.length == 0)
		return;
		
	var obj;
	for (var i=0; i<document.forms[0].elements.length; i++)
	{
		obj = document.forms[0].elements[i];
		if (obj.tagName.toUpperCase() == "INPUT")
		{
			if ((obj.type.toUpperCase() == "TEXT" || obj.type.toUpperCase() == "PASSWORD")
				&& !obj.readOnly && !obj.disabled)
			{
				try
				{
					obj.select();
				}
				catch(e)
				{
				}
				break;
			}
		}
	}
}
//显示进度条//
ObjBase.createGuage = function ()
{
	var aWidth	= 350;	//宽度300
	var aHeight	= 70;	//高度50
	var aUrl	= "http://localhost";	//进度条页面
	//删除进度条
	ObjBase.removeGuage();
	//创建进度条
	var oDiv = window.document.createElement("DIV");
	oDiv.style.position			= "absolute";
	oDiv.style.cursor			= "wait";
	oDiv.style.height			= aHeight+"px";
	oDiv.style.width			= aWidth+"px";
	oDiv.style.top				= (window.document.body.clientHeight - aHeight) / 2;
	oDiv.style.left				= (window.document.body.clientWidth - aWidth) / 2;
	oDiv.id						= "Div_Guage"
	oDiv.style.borderright = "green thin solid";
	var oFrame = window.document.createElement("IFRAME");
	oFrame.style.position		= "absolute";
	oFrame.style.height			= "100%";
	oFrame.style.width			= "100%";
	oFrame.style.top			= "0px";
	oFrame.style.left			= "0px";
	oFrame.id					= "Frame_Guage";
	oFrame.scrolling			= "no";
	oFrame.frameBorder			= "0";
	//oFrame.src					= aUrl;
	oDiv.appendChild(oFrame);
/**/	
	var processBarHTML;
	processBarHTML  = "<style>";
	processBarHTML += "	.aa {";
	processBarHTML += "		filter: Blur(Add=1, Direction=0, Strength=18);";
	processBarHTML += "	}";
	processBarHTML += ".t1 {";
	processBarHTML += "		border-top-width: 1px;";
	processBarHTML += "		border-right-width: 1px;";
	processBarHTML += "		border-bottom-width: 1px;";
	processBarHTML += "		border-left-width: 1px;";
	processBarHTML += "		border-top-style: none;";
	processBarHTML += "		border-right-style: solid;";
	processBarHTML += "		border-bottom-style: none;";
	processBarHTML += "		border-left-style: none;";
	processBarHTML += "		border-top-color: #308A85;";
	processBarHTML += "		border-right-color: #308A85;";
	processBarHTML += "		border-bottom-color: #308A85;";
	processBarHTML += "		border-left-color: #308A85;";
	processBarHTML += "	}";
	processBarHTML += ".t2 {";
	processBarHTML += "		border-top-style: none;";
	processBarHTML += "		border-right-style: none;";
	processBarHTML += "		border-bottom-style: none;";
	processBarHTML += "		border-left-style: dotted;";
	processBarHTML += "		border-top-width: 1px;";
	processBarHTML += "		border-right-width: 1px;";
	processBarHTML += "		border-bottom-width: 1px;";
	processBarHTML += "		border-left-width: 1px;";
	processBarHTML += "		border-top-color: #308A85;";
	processBarHTML += "		border-right-color: #308A85;";
	processBarHTML += "		border-bottom-color: #308A85;";
	processBarHTML += "		border-left-color: #308A85;";
	processBarHTML += "	}";
	processBarHTML += ".tleftM {";
	processBarHTML += "		border-top: 1px none #308A85;";
	processBarHTML += "		border-right: 1px none #308A85;";
	processBarHTML += "		border-bottom: 1px none #308A85;";
	processBarHTML += "		border-left: 1px solid #308A85;";
	processBarHTML += "}";
	processBarHTML += ".tleftM2 {";
	processBarHTML += "		border-top-width: 1px;";
	processBarHTML += "		border-right-width: 1px;";
	processBarHTML += "		border-bottom-width: 1px;";
	processBarHTML += "		border-left-width: 1px;";
	processBarHTML += "		border-top-style: none;";
	processBarHTML += "		border-right-style: solid;";
	processBarHTML += "		border-bottom-style: none;";
	processBarHTML += "		border-left-style: none;";
	processBarHTML += "		border-top-color: #308A85;";
	processBarHTML += "		border-right-color: #308A85;";
	processBarHTML += "		border-bottom-color: #308A85;";
	processBarHTML += "		border-left-color: #308A85;";
	processBarHTML += "}";
	processBarHTML += ".tp {";
	processBarHTML += "		border-top-width: 1px;";
	processBarHTML += "		border-right-width: 1px;";
	processBarHTML += "		border-bottom-width: 1px;";
	processBarHTML += "		border-left-width: 1px;";
	processBarHTML += "		border-top-style: solid;";
	processBarHTML += "		border-right-style: none;";
	processBarHTML += "		border-bottom-style: none;";
	processBarHTML += "		border-left-style: none;";
	processBarHTML += "		border-top-color: #308A85;";
	processBarHTML += "		border-right-color: #308A85;";
	processBarHTML += "		border-bottom-color: #308A85;";
	processBarHTML += "		border-left-color: #308A85;";
	processBarHTML += "}";
	processBarHTML += ".tp1 {";
	processBarHTML += "		border-top-width: 1px;";
	processBarHTML += "		border-right-width: 1px;";
	processBarHTML += "		border-bottom-width: 1px;";
	processBarHTML += "		border-left-width: 1px;";
	processBarHTML += "		border-top-style: none;";
	processBarHTML += "		border-right-style: none;";
	processBarHTML += "		border-bottom-style: solid;";
	processBarHTML += "		border-left-style: none;";
	processBarHTML += "		border-top-color: #308A85;";
	processBarHTML += "		border-right-color: #308A85;";
	processBarHTML += "		border-bottom-color: #308A85;";
	processBarHTML += "		border-left-color: #308A85;";
	processBarHTML += "}";
	processBarHTML += ".tp2 {";
	processBarHTML += "		border: 1px solid #308A85;";
	processBarHTML += "}";
	processBarHTML += "</style>";
	processBarHTML += "<table width='100%' border='0' 	class='tp2' bgcolor='#F1F6F4' align='center' cellpadding='0' cellspacing='0'>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td>";
	processBarHTML += "<table width='96%' border='0' align='center' cellpadding='0' cellspacing='0'>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td>";
	processBarHTML += "			<td height='10'>";
	processBarHTML += "			</td>";
	processBarHTML += "	</tr>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td>";
	processBarHTML += "			<div align='center' style='font-size:14px'>系统正在处理中，请等待。。。</div>";
	processBarHTML += "		</td>";
	processBarHTML += "	</tr>";
	processBarHTML += "</table>";
	processBarHTML += "<table width='96%' border='0' align='center' cellpadding='0' cellspacing='0'>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td width='2'></td>";
	processBarHTML += "	    <td  height='1' >";
	processBarHTML += "			<table  width='100%'  height='1' border='0' cellpadding='0' cellspacing='0' class='tp1'>";
	processBarHTML += "				<tr>";
	processBarHTML += "				  <td height='1'></td>";
	processBarHTML += "			    </tr>";
	processBarHTML += "		      </table>";
	processBarHTML += "		</td>";
	processBarHTML += "		<td width='2'></td>";
	processBarHTML += "	</tr>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td>";
	processBarHTML += "			<table width='1'  height='22' border='0' cellpadding='0' cellspacing='0' class='tleftM'>";
	processBarHTML += "		        <tr>";
	processBarHTML += "				  <td height='1'></td>";
	processBarHTML += "		        </tr>";
	processBarHTML += "			</table>";
	processBarHTML += "		</td>";
	processBarHTML += "		<td align='center' width='500' height='20'>";
	processBarHTML += "			<marquee style='filter:blur(strength=60);' direction='right' width='100%' scrollamount='5' ";
	processBarHTML += "			scrolldelay='10'  bgcolor='#FFFFFF'>";
	processBarHTML += "			    <table align='center' cellpadding='0' cellspacing='2'>";
	processBarHTML += "					<tr height='16'>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "					    <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "			            <td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "						<td bgcolor=#308A85 width=16 class='aa'></td>";
	processBarHTML += "			            <td width='3'></td>";
	processBarHTML += "					</tr>";
	processBarHTML += "				</table>";
	processBarHTML += "	        </marquee>";
	processBarHTML += "		</td>";
	processBarHTML += "		<td align='right'>";
	processBarHTML += "			<table width='1'  height='22' border='0' cellpadding='0' cellspacing='0' class='tleftM2'>";
	processBarHTML += "		        <tr>";
	processBarHTML += "				  <td height='1'></td>";
	processBarHTML += "		        </tr>";
	processBarHTML += "			</table>";
	processBarHTML += "		</td>";
	processBarHTML += "	</tr>";
	processBarHTML += "	<tr>";
	processBarHTML += "		<td width='2'  height='1' ></td>";
	processBarHTML += "	    <td height='1'>";
	processBarHTML += "			<table width='100%' height='1' border='0' cellpadding='0' cellspacing='0' class='tp'>";
	processBarHTML += "			    <tr>";
	processBarHTML += "					<td height='1'></td>";
	processBarHTML += "		        </tr>";
	processBarHTML += "			</table>";
	processBarHTML += "		</td>";
	processBarHTML += "		<td height='1' width='1'>";
	processBarHTML += "			<table width='1' height='1' border='0' cellpadding='0' cellspacing='0' class='t2'>";
	processBarHTML += "		        <tr>";
	processBarHTML += "				  <td height='1'></td>";
	processBarHTML += "		        </tr>";
	processBarHTML += "		    </table>";
	processBarHTML += "		</td>";
	processBarHTML += "	</tr>";
	processBarHTML += "</table>";
	processBarHTML += "	<tr>";
	processBarHTML += "			<td height='10'>";
	processBarHTML += "			</td>";
	processBarHTML += "	</tr>";
	processBarHTML += "		</td>";
	processBarHTML += "			</tr>";
	processBarHTML += "				</table>";
	//oDiv.innerHTML = processBarHTML;
	window.document.forms[0].appendChild(oDiv);
	window.frames[oFrame.id].document.writeln("<body style='cursor:wait' leftmargin=0 topmargin=0>"+processBarHTML+"</body>");	
	//doSetRepeatSubmitDisabled();
}
//移除进度条//
ObjBase.removeGuage = function ()
{
	var oDiv = window.document.getElementById("Div_Guage");
	if (oDiv != null)
	{
		oDiv.removeNode(true);
	}
	//doSetRepeatSubmitEnabled();
}
function doSetRepeatSubmitDisabled()
{
	//var vElement;
	var vElementHtml;

	try
	{
		window.document.body.style.cursor = "wait";
		window.document.body.scroll = "no";
		
		vElementHtml = "<div id='BgBar' style='background:#009933;FILTER:Alpha(Opacity=8);Z-INDEX:12000;CURSOR:wait;POSITION:absolute;'></div>";
		DivBgBar = document.createElement(vElementHtml);	
		DivBgBar.style.left = -50;
		DivBgBar.style.top = -50;
		DivBgBar.style.width = window.screen.width + 100;
		DivBgBar.style.height = window.screen.height;	
			
		document.body.appendChild(DivBgBar);
		
		vButtonControl = window.document.all.tags("input");
		
		for(var index = 0;index < vButtonControl.length;index ++){
			vButtonTypeName = vButtonControl[index].type.toLowerCase();
			if(vButtonTypeName=="button"){
				if(vButtonControl[index].disabled == "false"){
					vButtonControl[index].onclick = doButtonClick;
					vButtonControl[index].style.cursor = "wait";
					vButtonControl[index].disabled = "true";
				}
			}else if(vButtonTypeName == "submit"){
				vButtonControl[index].onclick = doButtonClick;
				vButtonControl[index].style.cursor = "wait";
				//vButtonControl[index].disabled = "false";
			}
		}
	}catch(e){
		//
	}	
}

function doSetRepeatSubmitEnabled()
{
	var vButtonControl;
	
	try
	{
		window.document.body.style.cursor = "";
		window.document.body.scroll = "yes";
		
		vButtonControl = window.document.all.tags("input");
		
		for(var index = 0;index < vButtonControl.length;index ++){
			vButtonTypeName = vButtonControl[index].type.toLowerCase();
			if(vButtonTypeName=="button"){
				if(vButtonControl[index].style.cursor == "wait"){
					vButtonControl[index].onclick = "";
					vButtonControl[index].style.cursor = "";
					vButtonControl[index].disabled = "false";
				}
			}
		}
	}catch(e){
		//
	}	
}