﻿function trim(s)//去空格
{
   s = s.replace(/^\s+/,"");
   return s.replace(/\s+$/,"");
}

function RequestQuery(name)
{
     var sValue=location.search.match(new RegExp("[\?\&]"+ name +"=([^\&]*)(\&?)","i"));
     return sValue ? sValue[1] : "";
}
function RequestQuerySrc(scrsting,name)
{
     var sValue = ("?"+scrsting.split('?')[1]).match(new RegExp("[\?\&]"+ name +"=([^\&]*)(\&?)","i"));
     return sValue ? sValue[1] : "";
}
function toppic(){
var str=new Array("pic/top/m1.jpg","pic/top/m2.jpg","pic/top/m3.jpg","pic/top/m4.jpg","pic/top/m5.jpg","pic/top/m6.jpg","pic/top/m7.jpg","pic/top/m8.jpg");
var a;
a=str[parseInt(Math.random()*(str.length))];
return "<img src="+a+"  border=0 />";
//document.write("<img src="+a+"  border=0 />");
}

//检测密码强度
function CheckPassStrong(PassControl)
{
	var PassStr = document.all(PassControl).value;
	var Strong = ["error","low","middle","high"];
	var level = 0
	if (PassStr.length > 5)
	{
		if (PassStr.match(/[0-9]/))
		{
			level++;
		}
		if (PassStr.match(/[a-zA-Z]/))
		{
			level++;
		}
		if (PassStr.match(/\W/))
		{
			level++;
		}
		switch (level)
		{
			case 1:
				return Strong[1];
				break;
			case 2:
				return Strong[2];
				break;
			case 3:
				return Strong[3];
				break;
			default:
				return Strong[0];
				break;
		}
	}
	else
	{
		return Strong[0];
	}
}

//检测是否日期型
function IsDate(DateControl,Msg)
{
	var DateTime = document.all(DateControl).value
	var DateLen = DateTime.length;
	var DateYear = parseInt(DateTime.split("-")[0]); 
	var DateMonth = parseInt(DateTime.split("-")[1]);
	var DateDay = parseInt(DateTime.split("-")[2]);
	
	if ((DateMonth>0) && (DateMonth<13))
	{
		if ((DateDay>0) && (DateDay<32))
		{
			switch (DateMonth)
			{
				case 1: 
				case 3: 
				case 5: 
				case 7: 
				case 8: 
				case 10: 
				case 12: 
					return true;
					break;

				case 4:
				case 6:
				case 9:
				case 11:
					if (DateDay<31)
					{
						return true;
					}
					else
					{
						alert (Msg);
						document.all(DateControl).focus();
						return false;
					}
					break;

				case 2:
					if (((DateYear % 4 == 0) && (DateYear % 100 != 0)) || (DateYear % 400 == 0))
					{
						if (DateDay<30)
						{
							return true;
						}
						else
						{
							alert (Msg);
							document.all(DateControl).focus();
							return false;
						}
					}
					else if(DateDay < 29)
					{
						return true;
					}
					else
					{
						alert (Msg);
						document.all(DateControl).focus();
						return false;
					}
					break;
			}
		}
		else
		{
			alert (Msg);
			document.all(DateControl).focus();
			return false;
		}
	}
	else
	{
		alert (Msg);
		document.all(DateControl).focus();
		return false;
	}
}

/////输入框检验
//检验是否为空
function CheckNull(name,msg)
{
	if(trim(document.all(name).value) == "")
	{
		alert(msg);
		document.all(name).focus();
		return true;
	}
}
//检验是否少于长度
function CheckLessLen(name,len,msg)
{
	if(trim(document.all(name).value).length < len)
	{
		alert(msg);
		document.all(name).focus();
		return true;
	}
}
//检验是否大于长度
function CheckLargeLen(name,len,msg)
{
	if(trim(document.all(name).value).length > len)
	{
		alert(msg);
		document.all(name).focus();
		return true;
	}
}
//检验是否等于长度
function CheckEquityLen(name,len,msg)
{
	if(trim(document.all(name).value).length == len)
	{
		alert(msg);
		document.all(name).focus();
		return true;
	}
}
//检验是否等于值
function CheckEquityValue(name,val,msg)
{
	if(trim(document.all(name).value) == val)
	{
		alert(msg);
		document.all(name).focus();
		return true;
	}
}
//检验两个控件的值是否相等
function CheckEquityControl(name1,name2,msg)
{
	if(trim(document.all(name1).value) != (document.all(name2).value))
	{
		alert(msg);
		document.all(name1).focus();
		return true;
	}
}

//自适应图片大小
function DrawImage(ImgD,ImgW,ImgH)
{
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		if(image.width/image.height>= ImgW/ImgH)
		{
			if(image.width>ImgW)
			{
				ImgD.width=ImgW;
				ImgD.height=(image.height*ImgW)/image.width;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		else
		{
			if(image.height>ImgH)
			{
				ImgD.height=ImgH;
				ImgD.width=(image.width*ImgH)/image.height;
			}
			else
			{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		} 
	}
}