// JavaScript Document

//-------------------------------------------------------
// Se campo da mensagem ficar em branco recolocar mensagem
//-------------------------------------------------------
function updateTexto (campo,areaID) {
  if (Trim(campo.value) == ""){
	  var obj = document.getElementById(areaID);
		campo.value = "(Informe-nos o CÓDIGO ou MODELO do produto)";
	}
}
//-------------------------------------------------------
// Validar o o envio da mensagem
//-------------------------------------------------------
function snd_quickcontact_new (theform, serverPage, objID){
    var msg_usr = "<b>Por favor corrigir os campos! </b><br>";
    var erro = false;
    var nlinhas =2;

	var cep = Trim(document.f_quickcontact.cep.value);

	var mess = Trim(document.f_quickcontact.msg.value);
	if (mess == "(Informe-nos o CÓDIGO ou MODELO do produto)") {
		mess = "";
	}

    if (Trim(document.f_quickcontact.nome.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo NOME em branco  <br>";};
    if (Trim(document.f_quickcontact.email.value) == ""){
       erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMAIL em branco   <br>";
    }else {
          if (!(email_valido = is_email(Trim(document.f_quickcontact.email.value)))) {
            erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMAIL incorreto   <br>";
          }
    }

    if (Trim(document.f_quickcontact.empresa.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMPRESA  em branco   <br>";};


    var cnpj = Trim(document.f_quickcontact.cnpj2.value);
    if (cnpj == ""){
      erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo CNPJ em branco   <br>";
    }else {
       if (cnpj != ""){
          if (!(validaCNPJ ('cnpj2'))) {
            erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo CNPJ  incorreto   <br>";
          }
       }
    }


    if (Trim(document.f_quickcontact.phone_ddd.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo DDD  em branco   <br>";};
    if (Trim(document.f_quickcontact.phone.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo TELEFONE  em branco   <br>";};


    if (mess == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo MENSAGEM nao preenchido   <br>";};

    if (!erro){
      if (cep=="") {
        var areaAlert ='pnlalert';
        nlinhas = 4;
        openAlertaWin ('300',nlinhas,areaAlert,'popalerta');
        activateWaitingMessage (areaAlert,"")
        var str = getformvalues(theform);
        var serverpage = "/app/base/solicitarCep.php?nli="+nlinhas+"&msg="+msg_usr;
        processajax ("POST",serverpage,areaAlert,str);
      }else {
        var str = getformvalues(theform);
        processajax ("POST",serverPage,objID, str);
      }
    }else {
        var areaAlert ='pnlalert';
        openAlertaWin ('300',nlinhas,areaAlert,'popalerta');
        activateWaitingMessage (areaAlert,"")
        var serverpage = "/app/base/alerta.php?nli="+nlinhas+"&msg="+msg_usr;
        processajax ("GET",serverpage,areaAlert,"");
    }
}

function snd_quickcontact (theform, serverPage, objID){
    var msg_usr = "<b>Por favor corrigir os campos! </b><br>";
    var erro = false;
    var nlinhas =2;


	var mess = Trim(document.f_quickcontact.msg.value);
	if (mess == "(Informe-nos o CÓDIGO ou MODELO do produto)") {
		mess = "";
	}

    if (Trim(document.f_quickcontact.nome.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo NOME em branco  <br>";};
    if (Trim(document.f_quickcontact.email.value) == ""){
       erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMAIL em branco   <br>";
    }else {
          if (!(email_valido = is_email(Trim(document.f_quickcontact.email.value)))) {
            erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMAIL incorreto   <br>";
          }
    }

    if (Trim(document.f_quickcontact.empresa.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo EMPRESA  em branco   <br>";};



    if (Trim(document.f_quickcontact.phone.value) == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo TELEFONE  em branco   <br>";};


    if (mess == ""){erro = true;nlinhas++; msg_usr = msg_usr + ">> Campo MENSAGEM nao preenchido   <br>";};

    if (!erro){
        var str = getformvalues(theform);
        processajax ("POST",serverPage,objID, str);
    }else {
        var areaAlert ='pnlalert';
        openAlertaWin ('300',nlinhas,areaAlert,'id_quickcontact');
        activateWaitingMessage (areaAlert,"")
        var serverpage = "/app/base/alerta.php?nli="+nlinhas+"&msg="+msg_usr;
        processajax ("GET",serverpage,areaAlert,"");
    }
}


function snd_quickcontactConfirmation (formID, serverPage, areaID){
  closeAlertPanel();
  var theform = document.getElementById(formID);
  var str = getformvalues(theform);
  activateWaitingMessage (areaID,"")
  processajax ("POST",serverPage,areaID, str);
}



