﻿function a(a){alert(a);}    

var $getName    =$('input:text[name=nome_in]');
var $getEmail   =$('input:text[name=email_in]');
var $getComment =$('textarea[name=comment_in]');


var $getNameFeed    =$('input:text[name=feedback_nome_in]');
var $getEmailFeed   =$('input:text[name=feedback_email_in]');
var $getCommentFeed =$('textarea[name=feedback_comment_in]');


function getComment(){
//return
var $uir  =$('#commentResult');

//Limpa os resultados de commentResult (User Interface Result iur)
$uir.text('').removeClass();

//$('input:button[name=enviar_btn]').val('aguarde o envio...').attr('disabled', 'disabled');
if($getName.val()!='')
    {
    if($getEmail.val()!='' && $getEmail.val().match(/(\w+)@(.+)\.(\w+)$/)!=null)
        {
        if($getComment.val()!='')
            {
            txt = insertParagraph($getComment.val());
            nome    = insertParagraph($getName.val());
                //$uir.ajaxStart(function() {alert('ajaxStart');}).ajaxStop(function() {alert('ajaxStop');});
                $uir.ajaxStart(function() {
                                            //alert('ajaxStart');
                                            $('input:button[name=enviar_btn]').val('aguarde o envio...').attr('disabled', 'disabled');
                                        })
                     .ajaxStop(function() {
                                            //alert('ajaxStop');
                                            $('input:button[name=enviar_btn]').val('Enviar').attr('disabled', '');                                   
                                        });
                //Postagem do comment
                $.ajax({
                        type: 'POST',
                        url: 'comment.asp',
                        data: 't=1&n='+ nome +'&e='+ $getEmail.val() +'&c='+ txt +'&u='+location.href,
                        success: function(msg){callBackEnvio(msg,$uir,1);},
                        error: function(msg){callBackEnvio(false,$uir,1);}
                        });

            }else{
                    $uir.text('Dedique algumas palavras ao seu comentário.').addClass('notice');
                    $getComment.focus();
            }
        }else{
                $uir.text('Insira seu email corretamente.').addClass('notice');
                $getEmail.focus();
            }
    }else{
            $uir.text('Por favor, qual o seu nome?').addClass('notice');
            $getName.focus();
            }
}



function getFeedback(){
//return
var $uir  =$('#feedback_Result');

//Limpa os resultados de commentResult (User Interface Result iur)
$uir.text('').removeClass();

//$('input:button[name=enviar_btn]').val('aguarde o envio...').attr('disabled', 'disabled');
if($getNameFeed.val()!='')
    {
    if($getEmailFeed.val()!='' && $getEmailFeed.val().match(/(\w+)@(.+)\.(\w+)$/)!=null)
        {
        if($getCommentFeed.val()!='')
            {
                txt     = insertParagraph($getCommentFeed.val());
                nome    = insertParagraph($getNameFeed.val());
                //$uir.ajaxStart(function() {alert('ajaxStart');}).ajaxStop(function() {alert('ajaxStop');});
                $uir.ajaxStart(function() {
                                            //alert('ajaxStart');
                                            $('input:button[name=enviar_btn]').val('aguarde o envio...').attr('disabled', 'disabled');
                                        })
                     .ajaxStop(function() {
                                            //alert('ajaxStop');
                                            $('input:button[name=enviar_btn]').val('Enviar').attr('disabled', '');                                   
                                        });
                //Postagem do comment
                $.ajax({
                        type: 'POST',
                        url: 'comment.asp',
                        data: 't=2&n='+ nome +'&e='+ $getEmailFeed.val() +'&c='+ txt +'&u='+location.href,
                        success: function(msg){callBackEnvio(msg,$uir,0);},
                        error: function(msg){callBackEnvio(false,$uir,0);}
                        });

            }else{
                    $uir.text('Fale conosco').addClass('notice');
                    $getCommentFeed.focus();
            }
        }else{
                $uir.text('Insira seu email corretamente.').addClass('notice');
                $getEmailFeed.focus();
            }
    }else{
            $uir.text('Por favor, qual o seu nome?').addClass('notice');
            $getNameFeed.focus();
            }
}


function callBackEnvio(msg,obj,t){
$uir = obj
    if(msg=='true')
        {
            $uir.text('Enviado com sucesso').addClass('success').fadeIn(600);
            $getName.val('');$getEmail.val('');$getComment.val('');$getNameFeed.val('');$getEmailFeed.val('');$getCommentFeed.val('');
            if(t==1){toggle('#comentarPagina')};
            $uir.fadeOut(2400);
            return true;}
    else{$uir.text('Pedimos desculpas, ocorreu um erro.').addClass('error');return false;}
}
//function toggle(obj){$(obj).slideToggle('slow', function() { });}


function insertParagraph(input) {
var output = "";
for (var i = 0; i < input.length; i++) {
if ((input.charCodeAt(i) == 13) || (input.charCodeAt(i+1) == 10)) {
i++;
output += input.charAt(i-1)+'<br />';
} else {
    if(input.charCodeAt(i) == 32){
        output += input.charAt(i)+'%20';
        }else{output += input.charAt(i); }
    }
}
return output;
}

function insertList(input) {
var output = "";
for (var i = 0; i < input.length; i++) {
if (input.charCodeAt(i+1) == 44) {
i++;
output += input.charAt(i-1)+'</li><li>';
} else {
output += input.charAt(i);
   }
}
return output;
}
  
//$("form[name=frm]").attr("action", "/Shared/code/PageCRUD.asp?k="+k+"&p="+p+"&acao=addKeywordInPage");
//$("form[name=frm]").submit();

