<!--#include file="head.asp"-->

<%dim dtitle,dcolor,dbgcolor1,dcu,dlei,dtext,dstop,dtop,sql,rs
dtitle=HtmlEncode(trim(request.form("dtitle")))
dlei=HtmlEncode(trim(request.form("dlei")))
dtext=HtmlEncode(request.form("dtext"))
dusername=HtmlEncode(trim(request.form("dusername")))
dcardid=HtmlEncode(trim(request.form("dcardid")))
dtel=HtmlEncode(trim(request.form("dtel")))
dstop=dateadd("d",request.form("dstop"),date())
dip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") 
If dip = "" Then 
dip = Request.ServerVariables("REMOTE_ADDR") 
end if

sql="select * from data"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
if dtitle<>"" then
rs.addnew
rs("title")=dtitle
rs("cu")="yes"
rs("type")=dlei
rs("text")=dtext
rs("username")=dusername
rs("cardid")=dcardid
rs("tel")=dtel
rs("stop")=dstop
rs("mark")="yes"
rs("ip")=dip
rs.update
response.write"<script>alert('发布成功！');location='show.asp?id="&rs("adid")&"'</script>"
rs.close  
set rs=nothing                                                                                     
end if%>


<SCRIPT LANGUAGE="JavaScript">
<!--//
function checkadd()
{   

                   //检查年月日是否是合法日期

                   function isdate(intYear,intMonth,intDay){ 

                      if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;     

                      if(intMonth>12||intMonth<1) return false;  

                      if ( intDay<1||intDay>31)return false;  

                      if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30)) return false;  

                      if(intMonth==2){  

                         if(intDay>29) return false;    

                         if((((intYear%100==0)&&(intYear%400!=0))||(intYear%4!=0))&&(intDay>28))return false;  

                        }  

                      return true;  

                   }  

 

                   //检查身份证是否是正确格式

                   function checkCard(dcardid) 

                   {

                       var pattern;

                            if (dcardid.length==15)

                            {

                                 pattern= /^\d{15}$/;//正则表达式,15位且全是数字

                                 if (pattern.exec(dcardid)==null)

                                 {

                                    alert("15位身份证号码必须为数字！")


                                      return false;

                                 }

                                 if (!isdate("19"+dcardid.substring(6,8),dcardid.substring(8,10),dcardid.substring(10,12)))

                                 {

                              alert("身份证号码中所含日期不正确") 

                                 return false;}

                                 

                            }

                            else     if (dcardid.length==18)

                            {

                                pattern= /^\d{17}(\d|x|X)$/;//正则表达式,18位且前17位全是数字，最后一位只能数字,x,X

                                 if (pattern.exec(dcardid)==null)

                                 {

                                            alert("18位身份证号码必须为数字！")

                                          return false;

                                 }

                                 if (!isdate(dcardid.substring(6,10),dcardid.substring(10,12),dcardid.substring(12,14)))

                                 {

                                        alert("身份证号码中所含日期不正确")  

                                 return false;

                                 }

                                 var strJiaoYan  =[  "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];

                                 var intQuan =[7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1];

                                 var intTemp=0;

                                 for(i = 0; i < dcardid.length - 1; i++)

                                 intTemp +=  dcardid.substring(i, i + 1)  * intQuan[i];  

                                 intTemp %= 11;

                                 if(dcardid.substring(dcardid.length - 1,dcardid.length).toUpperCase()!=strJiaoYan[intTemp])

                                 {

                                        alert("身份证末位验证码失败！")

                                 return false;

                                 }

                            }

                            else

                            {

                            alert("身份证号长度必须为15或18！")

                            return false;

                            }

                    return true;   

                   }


    if (document.postart.dtitle.value.length<1)
	{
        alert("请您填写广告标题！");
        document.postart.dtitle.focus();
        return false;
    }
    if (document.postart.dlei.value=="选择类别")
	{
        alert("请您选择广告类别！");
        document.postart.dlei.focus();
        return false;
    }
    if (document.postart.dtext.value.length<1)
	{
        alert("请您填写广告内容！");
        document.postart.dtext.focus();
        return false;
    }
    if (document.postart.dtext.value.length>80)
	{
        alert("请把广告内容的字数控制在80以内！");
        document.postart.dtext.focus();
        return false;
    }
	if (document.postart.dusername.value.length == 0) {
		alert("请您填写联系人姓名！");
		document.postart.dusername.focus();
		return false;
	}
	var str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./'[]{}`1234567890-=\~!@#$%^&*()_+|?><:";
	var errorChar
	errorChar = isCharsInBag(postart.dusername.value,str)
	if (errorChar != "" )
	{
		alert('联系人姓名必须是中文！');
		postart.dusername.focus();
		return false;
	} 
function isCharsInBag (s, bag)
{ 
var i,c;
for (i = 0; i < s.length; i++)
{ 
c = s.charAt(i);//字符串s中的字符
if (bag.indexOf(c) > -1) 
return c;
}
return "";
}
	
	    if(document.postart.dusername.value.length<2||document.postart.dusername.value.length>4){
		alert("联系人姓名不能少于2字多于4字！");
		document.postart.dusername.focus();
		return false;
	}	
	if (document.postart.dcardid.value.length == 0) {
		alert("请填写您的身份证号！");
		document.postart.dcardid.focus();
		return false;
	}
		if(checkCard(document.postart.dcardid.value)==false)
		{
			document.postart.dcardid.focus(); 
			return false; 
		} 
	
    if (document.postart.dtel.value.length<1)
	{
        alert("请填写您的联系电话！");
        document.postart.dtel.focus();
        return false;
    }

if (isNaN(postart.dtel.value)){
alert('电话号码必须是数字');
postart.dtel.focus();
return false;
}

    if (document.postart.dstop.value=="选择有效期")
	{
        alert("请您选择有效期限！");
        document.postart.dstop.focus();
        return false;
    }
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">      
<!-- Begin
maxLen = 80;
function checkMaxInput(form) {
if (form.dtext.value.length > maxLen)
form.remLen.value = 0;
else form.remLen.value = maxLen - form.dtext.value.length;
}
//  End -->
</script><body bgcolor="#FFFFFF">
                                            
<table width="760" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="CAE2F8">
  <tr>
    <td bgcolor="#FFFFFF"><form action="" method="post" name="postart" onsubmit="return checkadd()">
      <table width="466" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="EFF7FE">
        <tr align="center" bgcolor="#FFFFFF">
          <td width="100%" height="10" colspan="3"><table cellspacing="4">
              <tr>
                <td align="right" colspan="2"><p align="center">游 客 快 速 发 布 信 息
                        <p align="center">强烈建议：<a href="reg.asp"><font color="#FF0000">注册成为会员</font></a>可发布图片信息,信息内容可<br>达<font color=red>1500字</font>,自由管理信息和更多功能。</p></td>
              </tr>
          </table></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td width="35%" height="26" align="right">广告标题：</td>
          <td width="65%" height="26"><input type="text" name="dtitle" size="20" maxlength="10">
              <font color="#FF0000">* 10字以内</font></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td height="26" align="right">广告类别：</td>
          <td height="26"><select name="dlei" size="1">
              <option selected value="选择类别">选择类别</option>
              <%set rs_lei = server.createobject("adodb.recordset")                                            
			sql = "select * from type"                                            
			rs_lei.open sql,conn,1,1                                          
			do while not rs_lei.eof%>
              <option value="<%=rs_lei("name")%>"><%=rs_lei("name")%></option>
              <%rs_lei.movenext                                        
		  loop                                                
		  rs_lei.close                                       
		  set rs_lei = nothing       
		  conn.close     
          set conn=nothing%>
            </select>
              <font color="#FF0000">*</font> </td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td align="right">广告内容：</td>
          <td><textarea rows="6" name="dtext" cols="30" onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput(this.form)"></textarea>
              <font color="#FF0000">*&nbsp;80字以内</font></td>
        </tr>
        <tr>
          <td height="26" align="right" bgcolor="#FFFFFF">&nbsp;</td>
          <td height="26" bgcolor="#FFFFFF"><font color="#FF0000">目前还可以写
                <input readonly type=text name=remLen size=2 maxlength=2 value="80" style="border: 1 solid #888888">
        个字</font></td>
        </tr>
        <tr>
          <td height="26" align="right" bgcolor="#FFFFFF">联系人：</td>
          <td height="26" bgcolor="#FFFFFF"><input name="dusername" type="text" id="dusername" size="20" maxlength="20">
              <font color="#FF0000">* 中文(2-4字)</font></td>
        </tr>
        <tr>
          <td height="26" align="right" bgcolor="#FFFFFF">身份证号：</td>
          <td height="26" bgcolor="#FFFFFF"><input name="dcardid" type="text" id="dcardid" size="20" maxlength="18">
              <font color="#FF0000">* 本站保密，如实填写</font></td>
        </tr>
        <tr>
          <td height="26" align="right" bgcolor="#FFFFFF">联系电话：</td>
          <td height="26" bgcolor="#FFFFFF"><input name="dtel" type="text" id="dtel" size="20" maxlength="20">
              <font color="#FF0000">* 数字(8位以上)</font></td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td height="26" align="right">有效期限：</td>
          <td height="26"><select size="1" name="dstop">
              <option selected value="选择有效期">选择有效期</option>
              <option value="7">一星期</option>
              <option value="15">半个月</option>
              <option value="31">一个月</option>
              <option value="61">两个月</option>
              <option value="92">三个月</option>
              <option value="183">半年</option>
              <option value="365">一年</option>
            </select>
              <font color="#FF0000">*</font> </td>
        </tr>
        <tr bgcolor="#FFFFFF">
          <td height="30" align="right"></td>
          <td height="30" align="right"><p align="left">
              <input type="submit" value="发布" name="submit">
    &nbsp;
              <input type="reset" value="取消" name="reset">
               &nbsp;
               <input type="button" value="返回" name="back" onclick="javascript:history.back()">

          </td>
        </tr>
      </table>
    </form></td>
  </tr>
</table>


<!--#include file="foot.asp"-->