﻿
window.onerror=killErrors;
document.onerror=killErrors;

//document.body.onload=test;
function killErrors()
{
	return true;
}

function formCheck()
{
	Form1.onsubmit=myFormCheck;
}


function myFormCheck()
{
	var ok=true;
	var input=document.all.tags("input");		
	for(i=0;i<input.length;i++)
	{
		if(ok)
		{
			if(input[i].type=="text")
			{
				//var t=/<[^>]*>/;
				//if(t.test(input[i].value))
				//{
				//	alert("数据中不能包含<>标记");
				//	input[i].select();
				//	ok=false;
				//}
				if(input[i].value.indexOf("'")!=-1 || input[i].value.indexOf("<")!=-1 || input[i].value.indexOf("|")!=-1 || input[i].value.indexOf("\\")!=-1 || input[i].value.indexOf("&")!=-1)
				{
					alert("数据中不能包含'、<、|、\\、&");
					input[i].select();
					ok=false;
				}
			}
		}
	}
	
	if(ok)
	{		
		var t_area=document.all.tags("textarea");
		for(i=0;i<t_area.length;i++)
		{
			if(ok)
			{
				//var t=/<[^>]*>/;
				//if(t.test(t_area[i].value))
				//{
				//	alert("数据中不能包含<>标记");
				//	t_area[i].select();
				//	ok=false;
				//}
				if(t_area[i].value.indexOf("'")!=-1 || t_area[i].value.indexOf("<")!=-1 || t_area[i].value.indexOf("|")!=-1 || t_area[i].value.indexOf("\\")!=-1 || t_area[i].value.indexOf("&")!=-1)
				{
					alert("数据中不能包含'、<、|、\\、&");
					t_area[i].select();
					ok=false;
				}
			}
		}
	}
	return ok;
}
//字符串的trim()函数重写
function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
String.prototype.replaceAll  = function(s1,s2){    
return this.replace(new RegExp(s1,"gm"),s2);    
}  
function showAspx(page,name,height,width)
{
	var chasm = screen.Width;
	var mount = screen.Height;
	var mtop = (mount - height)/2;
	var mleft = (chasm - width)/2;
	
	window.open(page,name,"height="+height+",width="+width+",top="+mtop+",left="+mleft+",toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
}

function openAspx(page,name,height,width)
{

	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var mtop = (mount - height)/2;
	var mleft = (chasm - width)/2;
	
	var detailValue="dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;dialogTop:"+mtop+"px;dialogLeft:"+mleft+"px,scroll:no;resizable:no;help:no";
	window.showModalDialog(page,name,detailValue);
}

//页面数据完整
function checkData(CName,CTip,CType)
{
	var types = CType.split('|');
	var tips = CTip.split('|');
	var names = CName.split('|');
	
	for(i=0;i<types.length;i++)
	{
		switch(types[i])
		{
			case "0"://不能为空
				if(document.getElementById(names[i]).value.trim() == "")
				{
					alert(tips[i]);
					try
					{
						document.getElementById(names[i]).focus();
					}
					catch(e)
					{
						
					}
					return false;
				}
				break;
			default:
				var t=types[i].split("*");
				try{
					if(document.getElementById(names[i]).value.length>parseInt(t[1]))
					{
						alert("【"+tips[i]+"】输入了过多的字符，最多只能输入"+t[1]+"字！");
						document.getElementById(names[i]).select();
						return false;
					}
				}
				catch(e){}
				break;
		}
	}
	
	return true;
}

function clearInput()
{
	var input=document.all.tags("input");
	for(i=0;i<input.length;i++)
	{	
		if(input[i].TabIndex==0)
			input[i].focus();
		if(input[i].type=="text" || input[i].type=="file")
		{
			if(!input[i].disabled)
				input[i].value="";
		
		}
		if(input[i].type=="checkbox")
		{
			if(!input[i].disabled)
				input[i].checked=false;
		}
		//if(input[i].type=="hidden")
		//{
		//	input[i].value="";
		//}
	}
	var textarea=document.all.tags("textarea");
	for(j=0;j<textarea.length;j++)
	{
		textarea[j].value="";
	}
}

