/* Sugira uma pergunta */


  jQuery("#enviar").click(function(){

      var error = 0;


      jQuery("input[name^='user']").each(function(){

          if( jQuery(this).val().length<2 ){
              error++;
          }

      });

      if( error>0 ){
          Sexy.error("<strong>Atenção</strong><br /><br /> Preencha seus dados pessoais corretamente.");
          return false;
      }


      jQuery("input[name^='r']").each(function(){

          if( jQuery(this).val().length<15 ){
              error++;
          }

      });

      if( error>0 ){
          Sexy.error("<strong>Atenção</strong><br /><br /> Preencha todas as respostas da pergunta. As respostas devem conter no mínimo 15 caracteres.");
          return false;
      }

      if( jQuery("#pergunta").val().length<15 || jQuery("#correta").val().length<15 ){
          Sexy.error("<strong>Atenção</strong><br /><br /> A pergunta e a resposta correta, deve conter no mínimo 15 caracteres.");
          return false;
      }

      if( jQuery("#captcha").val().length<3 ){
          Sexy.error("<strong>Atenção</strong><br /><br /> Digite o código de confirmação.");
          return false;
      }

      /* Post */

      jQuery("#frmpergunta").submit();

  });



  /* Post */

  var options = {
            success: showResponse
        };

  jQuery('#frmpergunta').submit(function() {

      jQuery(this).ajaxSubmit(options);

      return false;

  });

  function showResponse(responseText, statusText)  {

      if ( trim(responseText)=="captcha" ){

            Sexy.error("<strong>Atenção</strong><br /><br /> Código de confirmação ( Captcha ) incorreto. Tente novamente.", {onComplete:

              function() {

                  jQuery("#imgcaptcha").click();
                  jQuery("#captcha").val("");
                  return false;

              }

            });

      }else if( trim(responseText)=="true" ){

            Sexy.info("<strong>Pergunta enviada com sucesso!</strong><br /><br /> Caso sua pergunta seja aprovada, entraremos em contato.", {onComplete:

              function() {

                  document.location.href="/";
                  return false;

              }

            });

      }else{

          jQuery("#imgcaptcha").click();
          jQuery("#captcha").val("");

          Sexy.error("<strong>Atenção</strong><br /><br />" + responseText);

          return false;

      }

  }
