/* 
判断指定的内容是否为空，若为空则弹出 警告框 
*/ 
function isEmpty(theValue, strMsg){ 
if(theValue==""){ 
alert(strMsg+"不能为空!"); 
return true; 
} 
return false; 
} 

/*
 * 函数说明：去除头尾空格
 * 参数：	字符串
 * 返回值：	无
 */
function trim(inputString) {
	return inputString.replace(/^ +/,"").replace(/ +$/,"");
}

/* 
中文判断函数，允许生僻字用英文“*”代替 
返回true表示是符合条件，返回false表示不符合 
*/ 
function isChinese(str){ 
var badChar ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
badChar += "abcdefghijklmnopqrstuvwxyz"; 
badChar += "0123456789"; 
badChar += " "+"　";//半角与全角空格 
badChar += "`~!@#$%^&()-_=+]\\\\|:;\\\\\'<,>?/";//不包含*或.的英文符号 
if(""==str){ 
return false; 
} 
for(var i=0;i<str.length;i++){ 
var c = str.charAt(i);//字符串str中的字符 
if(badChar.indexOf(c)<0){ 
 return false; 
} 
} 
return true; 
} 
/* 
数字判断函数，返回true表示是全部数字，返回false表示不全部是数字 
*/ 
/*function isNumber(str){ 
if(""==str){ 
return false; 
} 
var reg = /\\D/; 
return str.match(reg)==null; 
} */

function isNumber(str)
{
	if(str=="")
	{return false;}
	if(str*1+""=="NaN")
	{return false;}
	return true;
}
/* 
判断给定的字符串是否为指定长度的数字 
是返回true，不是返回false 
*/ 
function isNumber_Ex(str,len){ 
if(""==str){ 
return false; 
} 

if(str.length!=len){ 
return false; 
} 

if(!isNumber(str)){ 
return false; 
} 
return true; 
} 

function checkEmail(EmailAddress){
//--------------------------------------------------------------------------------
//  Name				Mode		Description
//	EmailAddress		Input		the email address
//
//  Return Value        :   true/false
//	Return Type         :   boolean
//--------------------------------------------------------------------------------	
	var i=0;
	var chr;
	var len;
	var Numbers="0123456789";
	var UpperLetters="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var LowerLetters="abcdefghijklmnopqrstuvwxyz";
	var EmailChar= Numbers + UpperLetters + LowerLetters + "@-_.";
	
	len=EmailAddress.length;
	
	//validate all characters
	for(i=0;i<len;i++){
		chr=EmailAddress.charAt(i);
		if(EmailChar.indexOf(chr)==-1){			
			return false;
		}
	}
	
	//Email address must include "@"
	if(EmailAddress.indexOf("@")==-1) return false;		
	//Email address must include "."
	if(EmailAddress.indexOf(".")==-1) return false;	
	//Email address must include only one "@"
	if(EmailAddress.lastIndexOf("@")!=EmailAddress.indexOf("@")) return false;
	//"@" must not be the first or last character
	if(EmailAddress.indexOf("@")==0 || EmailAddress.lastIndexOf("@")==len-1 ) return false;
	if(EmailAddress.indexOf("@.")>-1) return false;
	//"." must be not the first or last character
	if(EmailAddress.indexOf(".")==0 || EmailAddress.lastIndexOf(".")==len-1 ) return false;
	//OK
	return true;
}
/*
图片缩放函数
参数说明：
	ImgD --图片地址
	width --目标宽度
	height --目标高度
*/
var flag=false;
function DrawImage(ImgD,width,height){
    var image=new Image();
    var iwidth =width;  //定义允许图片宽度
    var iheight =height;  //定义允许图片高度
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= iwidth/iheight){
        if(image.width>iwidth){  
        ImgD.width=iwidth;
        ImgD.height=(image.height*iwidth)/image.width;
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        //ImgD.alt=image.width+"×"+image.height;
        }
    else{
        if(image.height>iheight){  
        ImgD.height=iheight;
        ImgD.width=(image.width*iheight)/image.height;        
        }else{
        ImgD.width=image.width;  
        ImgD.height=image.height;
        }
        //ImgD.alt=image.width+"×"+image.height;
        }
    }
} 

/*
函数:Allcheck
作用：用于（全选/取消全选）
参数说明：form --表单名
*/
function Allcheck(form)
{
  for(var i=0;i<form.elements.length;i++)
  {
  
   var e=form.elements[i];
    //if(e.name!="checkall")
	//{
	  e.checked = true;
	//}
  }
}

/*
函数:Nocheck
作用：用于（取消全部选择）
参数说明：form --表单名
*/
function Nocheck(form)
{
  for(var i=0;i<form.elements.length;i++)
  {
  
   var e=form.elements[i];
    //if(e.name!="checkall")
	//{
	  e.checked = false;
	//}
  }
}

/*
函数:ReverseAll
作用：反选
参数说明：form --表单名
*/
function ReverseAll(form)
{
	for (var i=0;i<form.elements.length;i++)
	{
		var e = form.elements[i];
		if (e.checked==false)
		{
			e.checked = true;
		}
		else
		{
			e.checked = false;
		}
	}
}

/*
函数:GetConfirm
作用：表单提交之前判断复选框有没有选择，至少一项。
参数说明：sForm --表单名
*/
function GetConfirm(sForm)
{
  var flag=false;
  for (var i=0;i<sForm.elements.length;i++)
  {
    var e = sForm.elements[i];
    if (e.name != "allbox" && e.type.toUpperCase() == "CHECKBOX")
    {
     if (e.checked)
     {
     flag=true; 
     break;
     }
    }
  }
  if (!flag)
  {
    window.alert("请选择你需要操作的记录");
    return false;
  }
  else
  {
    return true;
  }
}

//只能选择一个CheckBox
function GetCheckedCount(sForm)
{
  var intI = 0;
  for (var i=0;i<sForm.elements.length;i++)
  {
    var e = sForm.elements[i];
    if (e.name != "allbox" && e.type.toUpperCase() == "CHECKBOX")
    {
     if (e.checked)
     { 
     	intI += 1;
     }
    }
  }
  return intI;
}

//获取所选的一个CheckBox的值
function GetCheckedValue(sForm)
{
  var strID = "";
  var intI = 0;
  for (var i=0;i<sForm.elements.length;i++)
  {
    var e = sForm.elements[i];
    if (e.name != "allbox" && e.type.toUpperCase() == "CHECKBOX")
    {
     if (e.checked)
     { 
     	intI += 1;
	    strID = e.value;
     }
    }
  }
  return strID;
}


/*
函数：ChangeImage
参数说明：
imgpath --图片地址
2005-6-9 郭立江
*/
var imagego=false;
function ChangeImage(imgpath)
  {
  	var image=new Image();
	image.src=imgpath;
	if((image.width>0)&&(image.height>0))
	{
		if((image.width>500)||(image.height>400))
		{
			alert("为了保证您的信息能被访问者迅速找到，建议您上传的图片大小不要超过500*400，\n该图片大小为："+image.width+"*"+image.height);
			imagego=false;
		}
		else
		{
			 var arrstr=new Array();
			 arrstr=imgpath.split(".")
			 var len=arrstr.length;
			 var strext=arrstr[len-1].toLowerCase();
			 if(strext=="gif"||strext=="jpg")
			 {
				imagego=true;
			 }
			 else
			 {
				alert("图片格式不正确，只允许上传JPG或GIF图片");
				imagego=false;
			 }
		}
	}
	else
	{
		imagego=false;
	}
	return imagego;
  }



function CheckImage(imgpath,intwidth,intheight)
  {
	var checkimg=false;
  	var image=new Image();
	if(imgpath.indexOf(".")<=0)
	{
		alert("图片格式不正确，只允许上传JPG或GIF图片")
		return ;
	}
	image.src=imgpath;
	if((image.width>0)&&(image.height>0))
	{
		if((image.width>intwidth)||(image.height>intheight))
		{
			alert("为了保证您的信息能被访问者迅速找到，建议您上传的图片大小不要超过" + intwidth + "*" + intheight + "，\n该图片大小为："+image.width+"*"+image.height);
			imagego=false;
		}
		else
		{
			 var arrstr=new Array();
			 arrstr=imgpath.split(".")
			 var len=arrstr.length;
			 var strext=arrstr[len-1].toLowerCase();

			 if(strext=="gif"||strext=="jpg")
			 {
				checkimg=true;
			 }
			 else
			 {
				alert("图片格式不正确，只允许上传JPG或GIF图片");
				checkimg=false;
			 }
		}
	}
	else
	{
		checkimg=false;
	}
	
	return checkimg;
  }



var Chkgo=false;
function CheckWord(filepath)
{
	if(filepath!="")
	{
		lowerext=filepath.substring(filepath.length-4,filepath.length);
		lowerext=lowerext.toLowerCase();
		if ((lowerext!=".doc")&&(lowerext!=".txt"))
		{
			alert("上传格式不正确，只允许上传doc或txt图片");
			Chkgo=false;
		}
		else
		{
			Chkgo=true;
		}
	}
	return Chkgo;
}
/*
函数：CheckDel()
作用：用于确定是否删除
*/
function CheckDel()
{
	if(confirm("你确定要删除吗？"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

/*
函数：CheckMoney()
作用：用于判断输入的是否为货币类型，返回结果为boolean类型，正确返回true;错误返回false;
参数说明：str--需要判断的字符串
*/
function CheckMoney(str)
{
	//var p=/^\d+\.?\d+$/;
	var p=/^-?\d+(\.\d+)?$/;
	var ismoney=p.test(str);
	return ismoney;
}

/*
	函数：CheckLength
	作用：检测字符是否超过规定长度
	参数：str	-字符串
		  len	-规定长度
	返回值：true;false
	时间：2006-7-21
	Author：郭立江
*/
function CheckLength(str,len)
{
	if(str.length>len)
	{
		alert("不要超过" + len + "个字符，现字符长度" + str.length);
		return true;
	}
	else
	{
		return false;
	}
}
function GetXmlHttp() 
{ 
var A=null; 
try 
{ 
A=new ActiveXObject("Msxml2.XMLHTTP") 
} catch(e) { 
try 
{ 
A=new ActiveXObject("Microsoft.XMLHTTP") 
} catch(oc) { 
A=null 
} 
} 
if ( !A && typeof XMLHttpRequest != "undefined" ) 
{ 
A=new XMLHttpRequest() 
} 
return A 
} 

function GetContent(FileUrl)
{
	var xmlurl=GetXmlHttp();
	xmlurl.open("get",FileUrl,"false");
	xmlurl.send();
	return xmlurl.responseText;
}

function SetFrm(EleName,Value)
{
	eval(EleName).innerHTML=Value;
}


function ErrImgReplace(obj)
{
    obj.src="http://img.21efz.com/default/defaultpic.gif";
}

function tot(mobnumber){
while(mobnumber.indexOf("０")!=-1){
mobnumber = mobnumber.replace("０","0");
}
while(mobnumber.indexOf("１")!=-1){
mobnumber = mobnumber.replace("１","1");}
while(mobnumber.indexOf("２")!=-1){
mobnumber = mobnumber.replace("２","2");}
while(mobnumber.indexOf("３")!=-1){
mobnumber = mobnumber.replace("３","3");}
while(mobnumber.indexOf("４")!=-1){
mobnumber = mobnumber.replace("４","4");}
while(mobnumber.indexOf("５")!=-1){
mobnumber = mobnumber.replace("５","5");}
while(mobnumber.indexOf("６")!=-1){
mobnumber = mobnumber.replace("６","6");}
while(mobnumber.indexOf("７")!=-1){
mobnumber = mobnumber.replace("７","7");}
while(mobnumber.indexOf("８")!=-1){
mobnumber = mobnumber.replace("８","8");}
while(mobnumber.indexOf("９")!=-1){
mobnumber = mobnumber.replace("９","9");}
return mobnumber;
}

//判断日期的正确性
function IsValidDate(DateStr)    
{    
    var matchArray = DateStr.match(/^[0-9]+-([0-1][0-9]|[0-9])-([0-3][0-9]|[0-9])$/)
     if (matchArray == null) {
          return false;
        }
        return true;
}    


//验证邮编
function IsValidPosts(str)
{
	var patrn = /^\d{6}$/; 
	return patrn.test(str); 	
}

//验证电话号码
function IsValidTel(str){
       var reg=/^([0-9]|[\-])+$/g ;
       if(str.length<7 || str.length>18){
        return false;
       }
       else{
         return reg.exec(str);
       }
}
