<!-- #include file="config.asp" -->
<!-- #include file="app_inc/db.asp" -->
<!-- #include file="app_inc/form.asp" -->
<!-- #include file="app_inc/dt.asp" -->

<%
call db_open()
if (Request.Form() <> "") then
	
	' Monta a SQL
	sql = "insert into CF_Mensagem ("
	for each item in request.Form()
		if ((left(item,3) = "txt") or (left(item,3) = "chk") or (left(item,3) = "rdo") or (left(item,3) = "cmb")) then
			sql_campos = sql_campos & right(item,len(item) - 4)& ", "
			sql_valores = sql_valores & "'" &request.form(item) & "', "
		end if
	next
	sql = sql & left(sql_campos,len(sql_campos) -2) & ") values ("&left(sql_valores,len(sql_valores) -2) & ")"
	str_sql = sql
	' Executa
	con.execute(sql)
	' Seta a mensagem como respondida
	if (request.form("id_mensagem") <> "") then
		id_mensagem = request.form("id_mensagem")
		if (id_mensagem <> "") then
			con.execute("update cf_mensagem set respondida = 1 where id_cf_mensagem = "&id_mensagem&"")
		end if
	end if
	form_alert("Mensagem enviada.") : form_script("top.location.href = 'Mensagem_Recebida.asp'")
end if

if (request("id_mensagem") <> "") then
	id_mensagem = request("id_mensagem")
	sql = "select msg.*, ent_de.nome as de_nome, ent_para.nome as para_nome from cf_mensagem msg, cf_entrevistador ent_de,  cf_entrevistador ent_para "_
	& "where (msg.de = ent_de.id_cf_entrevistador) and (msg.para = ent_para.id_cf_entrevistador) and msg.id_cf_mensagem = "&id_mensagem&"  "_
	& "order by convert(datetime, data_envio, 103), convert(datetime, hora, 103) desc"
	set rs = con.execute(sql)
	if (id_mensagem <> "") then	
		con.execute("update cf_mensagem set lida = 1, data_leitura = "&dt_date("dd/mm/yyyy",now)&" where id_cf_mensagem = "&id_mensagem&"")
	end if
end if
%>
<html>
<style type="text/css">
<!--
#Layer1 {
	position:absolute;
	left:77px;
	top:60px;
	width:145px;
	height:139px;
	z-index:1;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<head>
 
<title>IPESO</title>
<link href="css.css" rel="stylesheet" type="text/css">
<script src="form.js" type="text/javascript"></script>
<script>
function form_reset()
	{
	frmCadastra.reset();
	}
function envia_contato()
{
//alert('nome='+f.nome)
enviaPage('envia_form.asp', 'GET', 'true', 'conteudo','nome='+f.nome.value)
}
function enviaPage(url, metodo, modo, tagId, parametros)
{
    goAjax( url+"?"+parametros+"&rnd"+ Math.random() , metodo, modo , tagId); 
}


function goAjax(url, metodo, modo, tagRetorno, parametros) {
        document.getElementById(tagRetorno).innerHTML='<div align="center" class="">carregando...</div>'
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP") // acrescentei
            if(metodo == "GET") {
                xmlhttp.open("GET", url, modo);
            } else {        
                xmlhttp.open("POST", url, modo);
                xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
                xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
                xmlhttp.setRequestHeader("Pragma", "no-cache");
            }    
            
            xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4) {
                    retorno=xmlhttp.responseText
                    document.getElementById(tagRetorno).innerHTML=retorno
                    //findScript(retorno)
                }
            }
            if(metodo == "GET") {
                xmlhttp.send(null);
            } else {        
                xmlhttp.send(parametros);
            }
}

function msg(str)
    {
    alert(str)
    }
	
	
	function estado()
{
	if(document.getElementById("cmb-cidade") == undefined)
	{
	
		if (!(document.getElementById("cmb-estado").value==""))
			{
				enviaPage('cidade.asp', 'GET', 'true', 'td_cidade','estado='+document.getElementById("cmb-estado").value);
				alert('Escolha a cidade');
				return false;
			}
	}
	return true;
}	

	
</script>
</head>
<body>
<form name="frmCadastra" method="post" action="#" onSubmit="return required(frmCadastra);" conf_message="Confirma ação?">
<center>
			  <div class="div_topic" style="width: 330px">Responder  mensagem</div>
                    <table width="320" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="table">
                      <tr>
                        <td width="" align="left" bgcolor="f0f0f0" class="td"> <b>T&iacute;tulo/descri&ccedil;&atilde;o </b></td>
                      </tr>
                      <tr>
                        <td height="30" align="left" valign="bottom" bgcolor="f0f0f0" class="td">
						<input name="txt-titulo" type="text" class="Caixa" id="Digite seu C&oacute;digo" value="Re: <% = rs("titulo") %>" size="50" maxlength="50" required="true" message="Digite o Título/descrição"></td>
                      </tr>
					  
                      <tr align="center">
                        <td align="left" bgcolor="f0f0f0" class="td"><b>Para</b></td>
                      </tr>
                      <tr align="center">
                        <td align="left" bgcolor="f0f0f0" class="td"><% = rs("de_nome") %>
                       	<!-- Até esta data 20/09/2006 só se enviavam mensagens a uma gerente de campo -->
                       	<input name="txt-para" type="hidden" id="txt-para" value="<% = rs("de") %>"></td>
                      </tr>
                      <tr align="center">
                        <td align="left" bgcolor="f0f0f0" class="td"><b>Mensagem</b></td>
                      </tr>

                      <tr align="center">
                        <td height="40" bgcolor="#F0F0F0" class="td">
						<textarea name="txt-mensagem" cols="37" rows="5" id="txt-convite" required="true" message="Digite a mensagem."  onKeyUp="max(this,Digitado,Restante)" onKeyPress="max(this,Digitado,Restante)" max_length="250"></textarea>
						<center><font id="Digitado" color="red">0</font> Caracteres digitados / Restam <font id="Restante" color="red">250</font>
                          <br>  <br>
						  <script>
						function nome()
							{
							document.all['txt-convite'].value += document.all['texto'].value;
							document.all['txt-convite'].focus;
							}
												
						  </script>						</td>
                      </tr>
                      <tr align="center">
                        <td height="40">
						
							<input name="txt-id_cf_mensagem_mae" type="hidden" id="txt-hora" value="<% = Request("id_mensagem") %>">
							<input name="id_mensagem" type="hidden" id="txt-hora" value="<% = Request("id_mensagem") %>">
							<input name="txt-hora" type="hidden" id="txt-hora" value="<% = dt_time("h:m:s",now) %>">
							<input name="txt-de" type="hidden" id="txt-de" value="<% = session("id_pessoa") %>">
							<input type="hidden" value="<% = dt_date("dd/mm/yyyy",now) %>" name="txt-DATA_ENVIO">
							<input name="Button" type="submit" class="Botao" value="Enviar">
						
						</td>
                      </tr>
  </table>
</form>
</body>
</html>