<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../CheckAdmin.Asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../Images/Admin_style.css">
<script language="javascript" src="../JavaScript/Admin.js"></script>
<script language="javascript" src="../JavaScript/select_date.js"></script>
<%
If InStr(session("GroupPurview"), "|6,") = 0 Then
    response.Write ("<br /><br /><div align=""center""><font style=""color:red; font-size:9pt; "")>您没有管理该模块的权限！</font></div>")
    response.End
End If
Dim Result
Result = request.QueryString("Result")
Dim ID,showid,mMemName, mRealName,kCompany,kabout,kDemo,SortName,SortID,SortPath
Dim kAddress, kZipCode, kTelephone, kFax, kCname,kMobile, kEmail, kHomepage,kCQQ, kWorking,AddTime,kUpdatime
Dim kattribute1
ID = request.QueryString("ID")
showid=request.QueryString("showid")
 response.Write "<script language='javascript' for='window' event='onload'>ShowTabs("&showid&");</script>"
Call KehuEdit()
%>
<br />
<table class="tableBorder" width="95%" border="0" align="center" cellpadding="5" cellspacing="1">
  <form name="editForm" method="post" action="KehuEdit.Asp?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>&showid=<%=showid%>" onSubmit="return CheckMemEdit()">
    <tr>
      <th height="22" sytle="line-height:150%">【<%If Result = "Add" then%>添加<%ElseIf Result = "Modify" then%>修改<%End If%>客户信息】</th>
    </tr>
	<tr>
      <td class="forumRowHighlight">
	  <script language="javascript">
var tID=0;
function ShowTabs(ID){
  if(ID!=tID){
    TabTitle[tID].className="title5";
    TabTitle[ID].className="title6";
    Tabs[tID].style.display="none";
    Tabs[ID].style.display="";
    tID=ID;
  }
}
</script>
	  <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
        <tr align="center">
            <td id="TabTitle" class="title6" onclick="ShowTabs(0)">基本信息</td>
            <td id="TabTitle" class="title5" onclick="ShowTabs(1)">联系人<%
                  if Result="Modify" and kattribute1<>"" then
                     kattribute1_1=Split(kattribute1,"§§§")
                     cnum=UBound(kattribute1_1)+1
                  else
                     cnum=0
                  end if%>(<font color="#FF0000"><%=cnum%></font>)</td>
            <td id="TabTitle" class="title5" onclick="ShowTabs(2)">合作意向</td>
            <td id="TabTitle" class="title5" onclick="ShowTabs(3)">其 它</td>
            <td>&nbsp;</td>
        </tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" class="border"><tr class="tdbg"><td valign="top">
  <table width="100%" align="center" cellpadding="2" cellspacing="1">
  <tbody id="Tabs" style="display:">
  <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
  <tr>
	
      <td align="right" class="forumRow">跟进人：</td>
      <td class="forumRowHighlight"><input name="MemName" type="hidden" id="MemName" style="width: 120;background-color:#EBF2F9" value="<%=mMemName%>" maxlength="16" <%response.write ("readonly")%>>
	  <input name="RealName" type="text" id="RealName" style="width: 120;background-color:#EBF2F9" value="<%=mRealName%>" maxlength="16" <%response.write ("readonly")%>>
	  </td>
    </tr>
	<tr>
      <td align="right" class="forumRow">公司名称：</td>
      <td class="forumRowHighlight"><input name="Company" type="text" id="Company" style="width: 280" value="<%=kCompany%>" maxlength="249">
	  客户分类：
	  <input name="SortID" type="hidden" id="SortID" style="width: 18; background-color:#fffff0" value="<%=SortID%>"> 
	  <input name="SortPath" type="hidden" id="SortPath" style="width: 70; background-color:#fffff0" value="<%=SortPath%>">   <input name="SortName" type="text" id="SortName" value="<%=SortName%>" style="width:80;" readonly>
	  <a href="javaScript:OpenScript('../SelectSort.Asp?Result=KehuSort',500,500,'')"><img src="../Images/Select.gif" /></a>
	  </td>
	</tr>
        <tr>
      <td align="right" class="forumRow">电 话：</td>
      <td class="forumRowHighlight"><input name="Telephone" type="text" id="Telephone" style="width: 120" value="<%=kTelephone%>" maxlength="50"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">传真号码：</td>
      <td class="forumRowHighlight"><input name="Fax" type="text" id="Fax" style="width: 120" value="<%=kFax%>" maxlength="16"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">电子信箱：</td>
      <td class="forumRowHighlight"><input name="Email" type="text" id="Email" style="width: 280" value="<%=kEmail%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">地 址：</td>
      <td class="forumRowHighlight"><input name="Address" type="text" id="Address" style="width: 280" value="<%=kAddress%>" maxlength="100"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">邮政编码：</td>
      <td class="forumRowHighlight"><input name="ZipCode" type="text" id="ZipCode" style="width: 120" value="<%=kZipCode%>" maxlength="16"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">网 址：</td>
      <td class="forumRowHighlight"><input name="HomePage" type="text" id="HomePage" style="width: 280" value="<%=kHomePage%>" maxlength="50"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">经理：</td>
      <td class="forumRowHighlight"><input name="Cname" type="text" id="Cname" style="width: 120" value="<%=kCname%>" maxlength="16"></td>
    </tr>
	<tr>
      <td align="right" class="forumRow">Q Q：</td>
      <td class="forumRowHighlight"><input name="CQQ" type="text" id="CQQ" style="width: 120" value="<%=kCQQ%>" maxlength="50"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">手机号码：</td>
      <td class="forumRowHighlight"><input name="Mobile" type="text" id="Mobile" style="width: 120" value="<%=kMobile%>" maxlength="16"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">公司简介：</td>
      <td class="forumRowHighlight">
	    <textarea name="about" cols="50" rows="8" id="about" style="width: 280"><%=kabout%></textarea></td>
    </tr>
    
  </tbody>
  <tbody id="Tabs" style="display:none">
  <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight"></td>
    </tr>


<%
If Result = "Modify" Then
    Set rs = server.CreateObject("adodb.recordset")
    sql = "select * from Zqj_Kehu where ID="& ID
    rs.Open sql, conn, 1, 1
    If rs.bof And rs.EOF Then
        response.Write ("<center>数据库记录读取错误！</center>")
        response.End
    End If
    If rs("attribute1")<>"" Then
        attribute1_1 = Split(rs("attribute1"), "§§§")
        attribute1_value_1 = Split(rs("attribute1_value"), "§§§")
		attribute1_value_2 = Split(rs("attribute1_value2"), "§§§")
		attribute1_value_3 = Split(rs("attribute1_value3"), "§§§")
        Num_1 = UBound(attribute1_1) + 1
    Else
        Num_1 = 0
    End If
    rs.Close
    Set rs = Nothing
Else
    Num_1 = 0
End If
%>
	<tr>
      <td align="right" class="forumRow" valign="top">自定义联系人：</td>
      <td class="forumRowHighlight"><input name="Num_1" type="text" id="Num_1" value="<%=Num_1%>" size="5" />个 <input name="button2" type="button" id="button2" value="设置" onClick="num_1()" /> <input type="button" name="button7" id="button7" value="增加一个" onClick="num_1_1()" />
        <br />
        <span id="num_1_str">
        <%For i=0 to (Num_1-1)%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="28">联系人<%=i+1%>：<input name="attribute<%=i+1%>" type="text" id="attribute<%=i+1%>" value="<%=attribute1_1(i)%>" size="10" />
              手机：<input name="attribute<%=i+1%>_value" type="text" id="attribute<%=i+1%>_value" value="<%=attribute1_value_1(i)%>" size="15" />
			  QQ：<input name="attribute<%=i+1%>_value2" type="text" id="attribute<%=i+1%>_value2" value="<%=attribute1_value_2(i)%>" size="15" />
			  E_mail：<input name="attribute<%=i+1%>_value3" type="text" id="attribute<%=i+1%>_value3" value="<%=attribute1_value_3(i)%>" size="20" />
			  </td>
          </tr>
        </table>
        <%Next%>
        </span> </td>
    </tr>
  </tbody>
  <tbody id="Tabs" style="display:none">
    <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
    <tr>
      <td width="20%" align="right" class="forumRow">合作意向：</td>
      <td width="80%" class="forumRowHighlight">
	    <textarea name="Demo" cols="50" rows="5" id="Demo"><%=kDemo%></textarea>
	  </td>
    </tr>
  </tbody>
  <tbody id="Tabs" style="display:none">
    <tr>
      <td width="20%" align="right" class="forumRow">&nbsp;</td>
      <td width="80%" class="forumRowHighlight">&nbsp;</td>
    </tr>
  </tbody>

  </table>
</td>
</tr>
</table>
	  </td>
    </tr>
    	
    <tr>
      <td class="forumRowHighlight" align="center"><input name="submitSaveEdit" type="submit" id="submitSaveEdit" value="保存"> <input type="button" value="返回上一页" onclick="history.back(-1)"></td>
    </tr>
  </form>
</table>
<%
Sub KehuEdit()
    Dim Action, rs, sql
    Action = request.QueryString("Action")
    If Action = "SaveEdit" Then
        Set rs = server.CreateObject("adodb.recordset")
        If Result = "Add" Then
            If Not conn.Execute("select * from Zqj_Kehu where Company='" & Trim(Request.Form("Company")) & "' and MemName='"&session("UserName")&"'").EOF Then
                response.Write "<script language='javascript'>alert('客户[" & Trim(Request.Form("Company")) & "]已经存在！');history.back(-1);</script>"
                response.End
            End If
            sql = "select * from Zqj_Kehu"
            rs.Open sql, conn, 1, 3
            rs.addnew
            rs("MemName") = Trim(Request.Form("MemName"))
            rs("RealName") = Trim(Request.Form("RealName"))
            
            'mGroupIdName = Split(Request.Form("GroupID"), "┎╂┚")
			'if InStr(session("GroupPurview"),"|3,") = 0 then
               'rs("GroupID") = "201111268888888888"
               'rs("GroupName") = "普通客户"			    
			'else
               'rs("GroupID") = mGroupIdName(0)
               'rs("GroupName") = mGroupIdName(1)			
			'end if
            rs("Company") = StrReplace(Trim(Request.Form("Company")))
			rs("about")=Trim(Request.Form("about"))
			rs("Demo")=Trim(Request.Form("Demo"))
			rs("Cname")=Trim(Request.Form("Cname"))
            rs("Address") = StrReplace(Trim(Request.Form("Address")))
            rs("ZipCode") = StrReplace(Trim(Request.Form("ZipCode")))
            rs("Telephone") = StrReplace(Trim(Request.Form("Telephone")))
            rs("Fax") = StrReplace(Trim(Request.Form("Fax")))
            rs("Mobile") = StrReplace(Trim(Request.Form("Mobile")))
            rs("Email") = Trim(Request.Form("Email"))
            rs("HomePage") = StrReplace(Trim(Request.Form("HomePage")))
			rs("CQQ")=StrReplace(Trim(Request.Form("CQQ")))
			rs("AddTime")=now()
            If Request.Form("SortID") <> "" And Request.Form("SortPath") <> "" Then
                rs("SortID") = Request.Form("SortID")
                rs("SortPath") = Request.Form("SortPath")
            End If 
Num_1 = CheckStr(Request.Form("Num_1"), 1)
            If Num_1 = "" Then Num_1 = 0
            If Num_1>0 Then
                For i = 1 To Num_1
                    If CheckStr(Request.Form("attribute"&i), 0)<>"" And (CheckStr(Request.Form("attribute"&i&"_value"), 0)<>"" or CheckStr(Request.Form("attribute"&i&"_value2"), 0)<>"" or CheckStr(Request.Form("attribute"&i&"_value3"), 0)<>"") Then
                        If attribute1 = "" Then
                            attribute1 = CheckStr(Request.Form("attribute"&i), 0)
							  if CheckStr(Request.Form("attribute"&i&"_value"), 0)="" then
								 attribute1_value = CheckStr(Request.Form("attribute"&i&"_value"), 0)&" "
							  else
							     attribute1_value = CheckStr(Request.Form("attribute"&i&"_value"), 0)
							  end if
							  if CheckStr(Request.Form("attribute"&i&"_value2"), 0)="" then
							      attribute1_value2 = CheckStr(Request.Form("attribute"&i&"_value2"), 0)&" "
							  else
							      attribute1_value2 = CheckStr(Request.Form("attribute"&i&"_value2"), 0)
							  end if
							  if CheckStr(Request.Form("attribute"&i&"_value3"), 0)="" then
							      attribute1_value3 = CheckStr(Request.Form("attribute"&i&"_value3"), 0)&" "
							  else
							      attribute1_value3 = CheckStr(Request.Form("attribute"&i&"_value3"), 0)
							  end if							
							
                        Else
                            attribute1 = attribute1&"§§§"&CheckStr(Request.Form("attribute"&i), 0)
                            attribute1_value = attribute1_value&"§§§"&CheckStr(Request.Form("attribute"&i&"_value"), 0)
							attribute1_value2 = attribute1_value2&"§§§"&CheckStr(Request.Form("attribute"&i&"_value2"), 0)
							attribute1_value3 = attribute1_value3&"§§§"&CheckStr(Request.Form("attribute"&i&"_value3"), 0)
                        End If
                    End If
                Next
            End If
            rs("attribute1") = attribute1
            rs("attribute1_value") = attribute1_value
			rs("attribute1_value2") = attribute1_value2
			rs("attribute1_value3") = attribute1_value3		
			rs.update
			rs.close
			set rs=nothing
			response.Write "<script language='javascript'>alert('设置成功！');location.replace('KehuList.Asp');</script>"
        End If
        If Result = "Modify" Then
            sql = "select * from Zqj_Kehu where ID="&ID
            rs.Open sql, conn, 1, 3
            'rs("MemName") = Trim(Request.Form("MemName"))
            'rs("RealName") = StrReplace(Trim(Request.Form("RealName")))
            rs("Company") = StrReplace(Trim(Request.Form("Company")))
			rs("about")=Trim(Request.Form("about"))
			rs("Demo")=Trim(Request.Form("Demo"))
			rs("Cname")=Trim(Request.Form("Cname"))
            rs("Address") = StrReplace(Trim(Request.Form("Address")))
            rs("ZipCode") = StrReplace(Trim(Request.Form("ZipCode")))
            rs("Telephone") = StrReplace(Trim(Request.Form("Telephone")))
            rs("Fax") = StrReplace(Trim(Request.Form("Fax")))
            rs("Mobile") = StrReplace(Trim(Request.Form("Mobile")))
            rs("Email") = Trim(Request.Form("Email"))
            rs("HomePage") = StrReplace(Trim(Request.Form("HomePage")))
			rs("CQQ")=StrReplace(Trim(Request.Form("CQQ")))
			rs("Updatime")=now()
            If Request.Form("SortID")<>"" And Request.Form("SortPath")<>"" Then
                rs("SortID") = Request.Form("SortID")
                rs("SortPath") = Request.Form("SortPath")
            End If
		Num_1 = CheckStr(Request.Form("Num_1"), 1)
            If Num_1 = "" Then Num_1 = 0
            If Num_1>0 Then
                For i = 1 To Num_1
                    If CheckStr(Request.Form("attribute"&i), 0)<>"" And (CheckStr(Request.Form("attribute"&i&"_value"), 0)<>"" or CheckStr(Request.Form("attribute"&i&"_value2"), 0)<>"" or CheckStr(Request.Form("attribute"&i&"_value3"), 0)<>"") Then
                        If attribute1 = "" Then
                            attribute1 = CheckStr(Request.Form("attribute"&i), 0)
							  if CheckStr(Request.Form("attribute"&i&"_value"), 0)="" then
								 attribute1_value = CheckStr(Request.Form("attribute"&i&"_value"), 0)&" "
							  else
							     attribute1_value = CheckStr(Request.Form("attribute"&i&"_value"), 0)
							  end if
							  if CheckStr(Request.Form("attribute"&i&"_value2"), 0)="" then
							      attribute1_value2 = CheckStr(Request.Form("attribute"&i&"_value2"), 0)&" "
							  else
							      attribute1_value2 = CheckStr(Request.Form("attribute"&i&"_value2"), 0)
							  end if
							  if CheckStr(Request.Form("attribute"&i&"_value3"), 0)="" then
							      attribute1_value3 = CheckStr(Request.Form("attribute"&i&"_value3"), 0)&" "
							  else
							      attribute1_value3 = CheckStr(Request.Form("attribute"&i&"_value3"), 0)
							  end if
							
                        Else
                            attribute1 = attribute1&"§§§"&CheckStr(Request.Form("attribute"&i), 0)
                            attribute1_value = attribute1_value&"§§§"&CheckStr(Request.Form("attribute"&i&"_value"), 0)
							attribute1_value2 = attribute1_value2&"§§§"&CheckStr(Request.Form("attribute"&i&"_value2"), 0)
							attribute1_value3 = attribute1_value3&"§§§"&CheckStr(Request.Form("attribute"&i&"_value3"), 0)
                        End If
                    End If
                Next
            End If
            rs("attribute1") = attribute1
            rs("attribute1_value") = attribute1_value	
			rs("attribute1_value2") = attribute1_value2
			rs("attribute1_value3") = attribute1_value3
            rs.update
            rs.Close
            Set rs = Nothing		
		    response.Redirect("KehuView.Asp?Result=Modify&ID="&ID&"&showid="&showid)	
        End If       
    Else
        If Result = "Modify" Then
            Set rs = server.CreateObject("adodb.recordset")
            sql = "select * from Zqj_Kehu where ID="& ID
            rs.Open sql, conn, 1, 1
			if rs.bof and rs.eof then
			response.Write "<script language='javascript'>alert('参数错误！');history.back(-1);</script>"
			response.End
			else
            mMemName = rs("MemName")
            mRealName = rs("RealName")
            kCompany = rs("Company")
            kabout = rs("about")
            kDemo = rs("Demo")
			kCname=rs("Cname")
            kAddress = rs("Address")
            kZipCode = rs("ZipCode")
            kTelephone = rs("Telephone")
            kFax = rs("Fax")
            kMobile = rs("Mobile")
            kEmail = rs("Email")
            kHomepage = rs("Homepage")
			KCQQ=rs("CQQ")
			SortName = SortText(rs("SortID"))
            SortID = rs("SortID")
            SortPath = rs("SortPath")
			kattribute1=rs("attribute1")
			end if
            rs.Close
            Set rs = Nothing
        End If
    End If
End Sub


Function SortText(ID)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_KehuSort where ID="& ID
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	SortText="未分类"
	else
    SortText = rs("SortName")
	end if
    rs.Close
    Set rs = Nothing
End Function

Function genjinText(MemName)
    Dim rs, sql
    Set rs = server.CreateObject("adodb.recordset")
    sql = "Select * From Zqj_Members where MemName='"&MemName&"'"
    rs.Open sql, conn, 1, 1
	if rs.bof and rs.eof then
	genjinText="无跟进人"
	else
    genjinText = rs("RealName")
	end if
    rs.Close
    Set rs = Nothing
End Function
%>