// 选择框动作变化函数
function on_change()
{
   document.searchentform.submit();
}

// 搜索框动作函数
function clear_text_sysop()
{

   if(document.searchform.admin.value=="请输入要查找的管理员昵称关键字")
   { 
       document.searchform.admin.value="";
       document.searchform.admin.focus();
   } 
} 

// 搜索框动作函数
function clear_text_user()
{

   if(document.searchform.entkey.value=="请输入要查找的企业名称关键字!")
   { 
       document.searchform.entkey.value="";
       document.searchform.entkey.focus();
   } 
} 

//添加企业信息
function clear_ent_text(address)
{
   switch(address){
       case "street":
          if(document.addentform.ent_address_street.value=="Street(街区)")
	  {
             document.addentform.ent_address_street.value="";
             document.addentform.ent_address_street.focus();
	  }
          break;       
       case "city":
          if(document.addentform.ent_address_city.value=="City(城市)")
	  {
             document.addentform.ent_address_city.value="";
             document.addentform.ent_address_city.focus();
	  }
          break;
       case "state":
          if(document.addentform.ent_address_state.value=="State(州/省)")
	  {
             document.addentform.ent_address_state.value="";
             document.addentform.ent_address_state.focus();
	  }
          break;
   }   
}

//未名黄页首页选择查询检查函数
function checkindex()
{
   if(document.searchform.cat.value=="")
   {
      alert("请选择企业所属分类!");
      document.searchform.cat.focus();
      return false;
   }
   else if(document.searchform.loc.value=="")
   {
      alert("请选择企业所在地区!");
      document.searchform.loc.focus();
      return false;
   }   
   return true;
}

//翻页输入框检查函数 
function checkpage()
{
    if(isNaN(document.pageform1.page.value) || parseFloat(document.pageform1.page.value)<=0 || document.pageform1.page.value.indexOf('.')!=-1)
    {
       alert("对不起,只能输入正整数!");
       document.pageform1.page.value="";
       document.pageform1.page.focus();
       return false;
    }     
    else if(isNaN(document.pageform2.page.value) || parseFloat(document.pageform2.page.value)<=0 || document.pageform2.page.value.indexOf('.')!=-1)
    {
       alert("对不起,只能输入正整数!");
       document.pageform2.page.value="";
       document.pageform2.page.focus();
       return false;
    }    
    return true;
}

//表单输入数据格式检查函数
function checkdata()
{
    /* checkfor ent_name */
    if(document.addentform.ent_name.value=="")  
    {
        alert("企业名称不能为空!");
	document.addentform.ent_name.focus();
	return false;
    }    
    // check for category    
    if(document.addentform.cat.value=="")
    {
        alert("请选择企业所属一级分类!");
	document.addentform.cat.focus();
	return false;
    }
    else if(document.addentform.subcat.value=="")
    {
        alert("请选择企业所属二级分类!");
	document.addentform.subcat.focus();
	return false;
    }
    // check for location
    if(document.addentform.loc.value=="")
    {
        alert("请选择企业所属地区!");
	document.addentform.loc.focus();
	return false;
    }
    else if(document.addentform.subloc.value=="")
    {
        alert("请选择企业所属城市或省份!");
	document.addentform.subloc.focus();
	return false;
    }
    // check for address
    if(document.addentform.ent_address_street.value=="")
    {
	alert("企业所在街区不能为空!");
	document.addentform.ent_address_street.focus();
	return false;
    }
    else if(document.addentform.ent_address_street.value=="Street(街区)")
    {
	alert("请确认企业所在街区信息是否正确!");
	document.addentform.ent_address_street.focus();
	return false;
    }
    if(document.addentform.ent_address_city.value=="")
    {
	alert("企业所在城市不能为空!");
	document.addentform.ent_address_city.focus();
	return false;
    }
    else if(document.addentform.ent_address_city.value=="City(城市)")
    {
	alert("请确认企业所在城市信息是否正确!");
	document.addentform.ent_address_city.focus();
	return false;
    }
    if(document.addentform.ent_address_state.value=="")
    {
	alert("企业所在州/省份不能为空!");
	document.addentform.ent_address_state.focus();
	return false;
    }
    else if(document.addentform.ent_address_state.value=="State(州/省)")
    {
	alert("请确认企业所在州/省份信息是否正确!");
	document.addentform.ent_address_state.focus();	
	return false;
    }
    //check for postcode
    if(document.addentform.ent_postcode.value=="")
    {
	alert("邮政编码不能为空！");
	document.addentform.ent_postcode.focus();
	return false;
    }
    else
    {
	var No="0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ";
	for(i=0;i<document.addentform.ent_postcode.value.length;i++)
	{
	   var Checkstr=document.addentform.ent_postcode.value.charAt(i);
	   if(No.indexOf(Checkstr)==-1)
	   {
		alert("邮政编码不正确，请确认！");
		document.addentform.ent_postcode.focus();
		return false;
	   }
	}
    }
    //check for telephone
    if(document.addentform.ent_telephone.value=="")
    {
	alert("电话号码不能为空！");
	document.addentform.ent_telephone.focus();
	return false;
    }
    else
    {
	var No="0123456789-+ ";
	for(i=0;i<document.addentform.ent_telephone.value.length;i++)
	{
	   var Checkstr=document.addentform.ent_telephone.value.charAt(i);
	   if(No.indexOf(Checkstr)==-1)
	   {
		alert("电话号码格式不正确，请确认！");
		document.addentform.ent_telephone.focus();
		return false;
	   }
	}
    }
    // check for website    
    if(document.addentform.ent_website.value!="")
    {
        if(document.addentform.ent_website.value.lastIndexOf(".")==document.addentform.ent_website.value.length-1 || document.addentform.ent_website.value.charAt(0)=="." || document.addentform.ent_website.value.indexOf('.')==-1)
        {
	    alert("企业网址格式有误,请参照如下格式!\n例如:http://news.sina.com.cn , www.126.com");
	    document.addentform.ent_website.focus();
	    return false;
        } 
    }
    //check for fax
    if(document.addentform.ent_fax.value!="")
    {
	var No="0123456789-+";
	for(i=0;i<document.addentform.ent_fax.value.length;i++)
	{
	   var Checkstr=document.addentform.ent_fax.value.charAt(i);
	   if(No.indexOf(Checkstr)==-1)
	   {
		alert("公司传真格式不正确，请确认！");
		document.addentform.ent_fax.focus();
		return false;
	   }
	}
    }
    // check for email address
    if(document.addentform.ent_email.value!="")
    {
	var rege = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
        if(!document.addentform.ent_email.value.match(rege))
        {
	   alert("邮箱地址格式有误,请参照如下格式!\nharry@mitbbs.com , cs@mitbbs.com");
           document.addentform.ent_email.focus();
           return false;
        }
    }
    // check for introtitle
    if(document.addentform.ent_introtitle.value=="")
    {
	alert("企业介绍标题不能为空!");
	document.addentform.ent_introtitle.focus();
	return false;
    }
    // check for introcontent
    if(document.addentform.ent_introcontent.value=="")
    {
	alert("企业介绍内容不能为空!");
	document.addentform.ent_introcontent.focus();
	return false;
    }
    return true; 
}

function checkcomm()
{
   var mark=0;
   for(var i=0;i<document.comment.score.length;i++)
   {
      if(document.comment.score[i].checked)  mark=1;
   }   
   if(mark==0)
   {
      alert("请选择星级--为当前企业打分!");
      return false;
   }
   if(document.comment.comment.value=="")
   {
      alert("企业评论不能为空,请确认!");
      document.comment.comment.focus();
      return false;
   }
   return true;
}

function checkcomm_2()
{
   var mark=0;
   for(var i=0;i<document.comment.score.length;i++)
   {
      if(document.comment.score[i].checked)  mark=1;
   } 
   
   if(document.comment.id.value=="")
   {
      alert("用户登录帐号不能为空,请确认!");
      document.comment.id.focus();
      return false;
   }
   if(document.comment.passwd.value=="")
   {
      alert("用户登录密码不能为空,请确认!");
      document.comment.passwd.focus();
      return false;
   }  
   if(mark==0)
   {
      alert("请选择星级--为当前企业打分!");
      return false;
   }
   if(document.comment.comment.value=="")
   {
      alert("企业评论不能为空,请确认!");
      document.comment.comment.focus();
      return false;
   }
   return true;
}

function checkcomm_1()
{
   if(document.comment.comment.value=="")
   {
      alert("企业评论不能为空,请确认!");
      document.comment.comment.focus();
      return false;
   }
   return true;
}

function check_input()
{
   if(document.searchForm.user_id.value=="")
   {
      alert("用户名不能为空,请确认!");
      document.searchForm.user_id.focus();
      return false;
   }
   return true;
}

function checkaddform()
{
   var ad_mark=0;
   for(var i=0;i<document.addForm.admin_mark.length;i++)
   {
      if(document.addForm.admin_mark[i].checked)  ad_mark=1;
   }   
   if(ad_mark==0)
   {
      alert("请选择管理员类型!");
      return false;
   } 
   if(document.getElementById("show_site_id").style.display=="block") 
   {
      var station_mark=0;
      for(var i=0;i<document.addForm.station_id.length;i++)
      {
         if(document.addForm.station_id[i].checked)  station_mark=1;
      } 
      if(station_mark==0)
      {
         alert("请为站点管理员选择站点!");
	 return false;
      }
   } 
   return true;
}

function check_cl_data()
{
   if(document.addform.pid.value=="")
   {
      alert("请选择此分类所属一级分类...\n注意:如果是一级分类请选择'0:顶级分类'.");
      document.addform.pid.focus();
      return false;
   }
   if(document.addform.name.value=="")
   {
      alert("分类名称不能为空,请确认...");
      document.addform.name.focus();
      return false;
   }
   return true;
}

function check_cl_modi_date()
{
   if(document.modiform.name.value=="")
   {
      alert("分类名称不能为空,请确认...");
      document.modiform.name.focus();
      return false;
   }
   return true;
}

function check_comm_re()
{
   if(document.replyform.comm_reply.value=="")
   {
      alert("回复内容不能为空,请确认...");
      document.replyform.comm_reply.focus();
      return false;
   }
   return true;
}

function CheckAll(form) 
{
  for(var i=0;i<form.elements.length;i++)
  {
    var e=form.elements[i];
    if(e.type=="checkbox")//判断对象类型是否为复选框
    {
       e.checked=true;	
    }		
  }
}
function CheckNone(form) 
{
  for(var i=0;i<form.elements.length;i++)
  {
    var e=form.elements[i];
    if(e.type=="checkbox")//判断对象类型是否为复选框
    {
	e.checked=false;
    }		
  }
}

function check_recommend_1()
{
   if(document.recommendform.id.value=="")
   {
      alert("用户ID不能为空,请确认...");
      document.recommendform.id.focus();
      return false;
   }
   if(document.recommendform.passwd.value=="")
   {
      alert("登录密码不能为空,请确认...");
      document.recommendform.passwd.focus();
      return false;
   }
   if(document.recommendform.address.value=="")
   {
      alert("推荐对象不能为空,请确认...");
      document.recommendform.address.focus();
      return false;
   }
   if(document.recommendform.title.value=="")
   {
      alert("标题不能为空,请确认...");
      document.recommendform.title.focus();
      return false;
   }
   if(document.recommendform.content.value=="")
   {
      alert("内容对象不能为空,请确认...");
      document.recommendform.content.focus();
      return false;
   }   
   return true;
}
function check_recommend()
{
   if(document.recommendform.address.value=="")
   {
      alert("推荐对象不能为空,请确认...");
      document.recommendform.address.focus();
      return false;
   }
   if(document.recommendform.title.value=="")
   {
      alert("标题不能为空,请确认...");
      document.recommendform.title.focus();
      return false;
   }
   if(document.recommendform.content.value=="")
   {
      alert("内容对象不能为空,请确认...");
      document.recommendform.content.focus();
      return false;
   }   
   return true;
}

function show_site()
{
   if(document.addForm.admin_mark[3].checked)
   {
      document.getElementById("show_site_id").style.display="block";
   }
   else
   {
      document.getElementById("show_site_id").style.display="none";
      for(i=0; i<document.addForm.station_id.length; i++)
	if(document.addForm.station_id[i].checked)
	    document.addForm.station_id[i].checked = false;
   } 
}
