//去掉空格
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
//校验字符串中的中、英文字符总长度
function checkDigit(str){
  var digit = str.length;
  var arr = str.match(/[^\x00-\x80]/ig);
  if(arr != null) digit += arr.length;
  return digit;
}
//校验字符串中是否仅为数字,返回true表示为一实数(首尾不为小数点).
function checkNumber(str){
  return /^[-|+]?\d+(\.\d+)?$/g.test(str);
}

//input框日期校验
function Vdate(obj,strAlert){
  var now = new Date(); 
  var yy = now.getYear()+"-"; 
  var mm = now.getMonth()+1;
  var dd = now.getDate();
  if(mm<10){
    mm="0"+mm+"-";
  }else{
    mm=mm+"-";
  }
  if(dd<10){
    dd="0"+dd;
  }else{
    dd=dd+"";
  }
  var date = yy+mm+dd;

	var tempdate=obj.value.trim();
	if(tempdate=="") return false;
	if(tempdate.length>10||tempdate.length<8){
		alert("请输入合法的日期，格式为 YYYY-MM-DD  例如 2000-5-12");
		//alert("\u8bf7\u6309\u7167\u6807\u51c6\u65e5\u671f\u683c\u5f0f\u8f93\u5165\u683c\u5f0f\uff01\n\u6807\u51c6\u65e5\u671f\u683c\u5f0f\uff1a2003-01-30");
		obj.select();
		obj.focus();
		return false;
	}
	var last = tempdate.lastIndexOf("-");
	var nian=parseInt(tempdate.substring(0,4),10);
	var yue=parseInt(tempdate.substring(5,last),10)-1;
	var ri=parseInt(tempdate.substring(last+1,10),10);
	var d=new Date(nian,yue,ri);

	if(tempdate.substring(4,5)=="-"&&tempdate.substring(last,last+1)=="-"){
		if(d.getMonth()==yue&&d.getDate()==ri){
			return true;
		}else{
			alert("请输入合法的月份和天数！");
			//alert("\u8bf7\u8f93\u5165\u6709\u6548\u65e5\u671f\uff01");
			obj.focus();
			obj.select();
			return false;
		}
	}else{
		alert("请输入合法的日期，格式为 YYYY-MM-DD  例如 2000-5-12");
		//alert("\u8bf7\u6309\u7167\u6807\u51c6\u65e5\u671f\u683c\u5f0f\u8f93\u5165\u683c\u5f0f\uff01\n\u6807\u51c6\u65e5\u671f\u683c\u5f0f\uff1a2003-01-30");
		obj.focus();
		return false;
	}
}

//检查文件的格式
function checkFileType(obj,filetypeArray)
{
	var source = eval("document.all."+obj);
	var eXtendName = source.value.match(/^(.*)(\.)(.{1,8})$/)[3].toLowerCase();
	var Value = false;
	var strFormat = "";
	
	for(i=0;i<filetypeArray.length;i++)
	{
		if(filetypeArray[i].toLowerCase() == eXtendName)
			return true;
		else
		{
			if(i != filetypeArray.length-1)
				strFormat += "."+filetypeArray[i].toString()+"、";
			else
				strFormat += "."+filetypeArray[i].toString(); 
			Value = false;
			continue;
		}
	}
	if(!Value)
	{
		alert("您只能上传"+strFormat.toString()+"格式的文件！");
		return false;
	}
}
	
//*****检验输入框内容是否符合要求*****//
//obj:  name	 
//type   : datetime/int/string
//len : 字符长度
//isnull : 是否必须输入内容（y/n）
//************************************//


function checkObjValue(obj,type,len,isnull,strAlert){
	var source = eval("document.all."+obj);
	source.value = source.value.trim();
	if(type=="datetime"){
		if(source.value.trim()!=""){
			Vdate(source,strAlert);
		}else{
			if(isnull=="n"){
				alert("必须输入" + strAlert + "！");
				source.focus();
				source.select();	
				return false;
			}else{
				return true;
			}
		}
	}else if(type=="int"){
		if(source.value.trim()!=""){
			if(checkNumber(source.value.trim())){
				return true;
			}else{
				alert(strAlert +"必须是数字！");
				source.focus();
				source.select();
				return false;
			}
		}else{
			if(isnull=="n"){
				alert("必须输入" + strAlert + "！");
				source.focus();
				source.select();
				return false;
			}else{
				return true;
			}
		}
	}else if(type="string"){
		if(source.value!=""){
			if(checkDigit(source.value.trim())>len){
				var a1,a2,a3;
				a1 = (len/2);
				a2 = a1.toString();

				if(a2.indexOf(".")>=0)
				{
					a3 = a2.substring(0,a2.indexOf("."));
				}
				else
				{
					a3 = a2;
				}
				alert(strAlert+"的长度超出了范围，最多" + a3 + "个汉字，" + len + "个英文！");
				source.focus();
				source.select();
				return false;
			}else {
				return true;			
				}
		}else{
			if(isnull=="n"){
				alert("必须输入" + strAlert + "！");
				source.focus();
				source.select();
				return false;
			}else{
				return true;
			}	
		}
	}		
	return true;
}




function cValue(obj){
	var source = eval("document.all."+obj);
	
	if(source.value.trim()!=""){
		if(checkNumber(source.value.trim())){
			return true;
		}else{
			alert("必须是数字！");
			source.focus();
			source.select();
			return false;
		}
	}else
	{
		alert("必须输入数值！");
		source.focus();
		source.select();
		return false;	
	}
	
	return true;
}


var ShowString = "欢迎访问中华人民共和国海事局网站 http://www.msa.gov.cn";
function Show()
{
	window.status = ShowString.toString();
	//timerID = setTimeout("Show()", 0);
}
Show();