function JQuerySite() {

    this.lockForm = function(obj) {

        obj.value = "Enviando...";
        obj.disabled = true;

    }
	
	
	this.retirarAcento = function(objResp)
	{
		var varString = new String(objResp.value);
		var stringAcentos = new String('àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ');
		var stringSemAcento = new String('aaeouaoaeioucuAAEOUAOAEIOUCU');

		var i = new Number();
		var j = new Number();
		var cString = new String();
		var varRes = '';

		for (i = 0; i < varString.length; i++) 
		{
			cString = varString.substring(i, i + 1);
			for (j = 0; j < stringAcentos.length; j++) 
			{
				if (stringAcentos.substring(j, j + 1) == cString)
				{
					cString = stringSemAcento.substring(j, j + 1);
				}
			}
			varRes += cString;
		}
		objResp.value = varRes;
	}
	
    this.unLockForm = function(obj,valor) {

        $("#"+obj).val(valor);
        $("#"+obj).attr("disabled",false);

    }
    this.requestForm = function(form) {

        $("#"+form).ajaxSubmit({
            dataType:'script',
            type:"post"
        });

    }
    this.loadCidades = function(objSource,objTarget) {
		
        uf = objSource.options[objSource.selectedIndex].value;
        if (uf!="") {
            document.getElementById(objTarget).options[0].text = "Carregando...";
            document.getElementById(objTarget).disabled = true;
            ajax.addParameter("page","cidades");
            ajax.addParameter("uf",uf);
            ajax.addParameter("objTgt",objTarget);
            ajax.request({
                url:"/ajax/ajaxRequest.php",
                data:ajax.parameters,
                dataType:'script',
                type:"post"
            });
        }
    }
    this.submitPrepareUrl = function(e,url,texto,pag) {
		
        if(e.keyCode==13)
            this.prepareUrl(url,texto,pag);
    }
    this.prepareUrl = function(url,texto,pag) {

        var pesquisa = $("#"+texto).val().toLowerCase();
        if($("#"+texto).val().length>=2)
            window.top.location = ""+url +'pesquisa/'+pesquisa+'/'+pag+"";
        else alert('Digite no minimo 2 caracteres para a pesquisa seja efetuada corretamente!');
    }
    this.checkBusca = function() {

        if($("#inputString").val().length<2) {

            alert("Digite no minimo 2 caracteres para a pesquisa seja efetuada corretamente!");
            return false;
        }
        return true;

    }
    this.clearInput = function(id,information) {

        jQuery("#"+id).focus(function(){
            if(jQuery(this).val()==information || jQuery(this).val()=="")
                jQuery(this).val("");
            
        }).blur(function(){
            if(jQuery(this).val()==information || jQuery(this).val()=="")
                jQuery(this).val(information);
            
        });

    }

    this.execVoto = function(id,value) {

        ajax.addParameter("page","estrela");
        ajax.addParameter("id",id);
        ajax.addParameter("value",value);

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            type:"GET",
            data:ajax.parameters,
            dataType:"script",
            success:function(response) {

            }

        });

    }


    this.checkLogin = function() {

        val = $("#login_user").val();
        if(val=="" || val=="email do usuario") {
            $("#login_user").val("");
        }

    /*val = $("#senha_user").val();
        if(val=="" || val=="senha") {
            $("#senha_user").val("");
     }*/


    }
    this.checkLoginFancy = function() {

        val = $("#login_user_fancy").val();
        if(val=="" || val=="email do usuario") {
            $("#login_user_fancy").val("");
        }
    }
    
    this.sair = function() {

        ajax.addParameter("page","sair");
        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script'
        });

    }
    this.votarPergunta = function(id,tipo,obj) {

        $("#"+obj).html("<img src='/imgs/ajax-loader-voto.gif' style='width:25px;' border='0'/>");

        ajax.addParameter("page","votar_pergunta");
        ajax.addParameter("id_pergunta",id);
        ajax.addParameter("tipo",tipo);
        ajax.addParameter("obj",obj);

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script'
        });

    }

    this.votoDisabled = function(obj,tipo) {

        if(tipo=="menos")
            $("#"+obj).html("<span><img src='/imgs/voto_negativo_ok.gif' border='0'/></span>");
        if(tipo=="mais")
            $("#"+obj).html("<span><img src='/imgs/voto_positivo_ok.gif' border='0'/></span>");

    }

    this.login = function() {

        JS.checkLogin();
        ajax.addParameter("page","login");
        ajax.addParameter("login_user",$("#login_user").val());
        ajax.addParameter("senha_user",$("#senha_user").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script'
        });
    }

    this.loginFancy = function() {

        JS.checkLoginFancy();
        ajax.addParameter("page","login_fancy");
        ajax.addParameter("login_user_fancy",$("#login_user_fancy").val());
        ajax.addParameter("senha_user_fancy",$("#senha_user_fancy").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script'
        });
    }
    
    this.initHome = function() {

        JS.clearInput("inputString","digite sua busca");
        JS.clearInput("login_user","email do usuario");
    //JS.clearInput("senha_user","senha");

    }
    this.changeAba = function(obj,id) {

        for(var i=1;i<5;i++) {
            
            $("#conteudo_"+i).hide();
            $("#aba_"+i).attr("class","");

        }
        $("#conteudo_"+id).fadeIn();
        $(obj).attr("class","select");

    }
    this.sendPergunta = function(obj) {

        this.lockForm(obj)
        ajax.addParameter("page","fazer_pergunta");
        ajax.addParameter("titulo_pergunta",$("#titulo_pergunta").val());
        ajax.addParameter("keywords",$("#keywords").val());
        ajax.addParameter("decricao_pergunta",$("#decricao_pergunta").val());
        ajax.addParameter("select_categoria",$("#select_categoria").val());
        if ($("#select_subcategoria"+$("#select_categoria").val()).html()!=null) {
		
            ajax.addParameter("temsubcategoria","sim");
            ajax.addParameter("select_subcategoria"+$("#select_categoria").val(),$("#select_subcategoria"+$("#select_categoria").val()).val());
	  
        }
	  
	  
	  
        ajax.addParameter("select_categoria",$("#select_categoria").val());
	  
        ajax.addParameter("checkbox_pergunta",$("#checkbox_pergunta").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }

    this.sendResposta = function(obj) {

        this.lockForm(obj);
        this.requestForm("resposta_pergunta_user");
    }
    
    this.sendFaleConosco = function(obj) {

        this.lockForm(obj);
        this.requestForm("fale_conosco_user");
        
    }
    this.sendIndicarEmail = function(obj) {

        this.lockForm(obj);
        ajax.addParameter("page","indicar_email");
        ajax.addParameter("indicar_email",$("#indicar_email").val());
        ajax.addParameter("id_pergunta",$("#id_pergunta").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }
    
    this.denunciar = function(obj) {

        //this.lockForm(obj);
        ajax.addParameter("page","denunciar");
        ajax.addParameter("id_pergunta",$("#id_pergunta").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }
	
    this.mensagemErroMelhor = function(obj)
	{
		 $("#"+obj).html("<span class='message_information_resposta' style='position:absolute;top:-14px;right:-4px;width:150px;text-align:center;'>Desculpe, voc&ecirc; n&atilde;o possui status suficiente. Participe mais do jogo!</span>");
	}
	
    this.mensagemErroMaximoMelhor = function(obj)
	{
		 $("#"+obj).html("<span class='message_information_resposta' style='position:absolute;top:-14px;right:-4px;width:150px;text-align:center;'>Desculpe, voc&ecirc; j&aacute; votou em muitas respostas hoje. Tente novamente amanh&atilde;.</span>");
	}
	
    this.confirmationEscolherPergunta = function(obj) {

        $("#"+obj).html("<span class='message_information_resposta' style='position:absolute;top:-14px;right:-4px;width:150px;text-align:center;'>Resposta escolhida!</span>");

    }
    this.sendEscolherResposta = function(obj,id_pergunta,id_resposta,id_usuario) {

        this.lockForm(obj);
        $(".escolher_resposta").hide();
        $(obj).show();
        
        ajax.addParameter("page","escolher_resposta");
        ajax.addParameter("id_pergunta",id_pergunta);
		ajax.addParameter("id_resposta",id_resposta);
        ajax.addParameter("id_usuario",id_usuario);

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }
    
    this.sendExcluirPergunta = function(obj,id_pergunta) {

        if (confirm("Deseja realmente excluir esta pergunta?\nOs pontos que voce obteve com esta pergunta\nserao automaticamente retirados.")) {

            this.lockForm(obj);
            ajax.addParameter("page","excluir_pergunta");
            ajax.addParameter("id_pergunta",id_pergunta);

            ajax.request({
                url:"/ajax/ajaxRequest.php",
                data:ajax.parameters,
                type:"post",
                dataType:'script'
            });
        }
    }
    this.sendExcluirResposta = function(obj,id_resposta) {

        if (confirm("Deseja realmente excluir esta resposta?\nOs pontos que voce obteve com esta resposta\nserao automaticamente retirados.")) {

            this.lockForm(obj);
            ajax.addParameter("page","excluir_resposta");
            ajax.addParameter("id_resposta",id_resposta);

            ajax.request({
                url:"/ajax/ajaxRequest.php",
                data:ajax.parameters,
                type:"post",
                dataType:'script'
            });
        }
    }
    
    this.messageExclusaoPergunta = function() {

        $("#coluna-1-pergunta-respondida").html("<div class='message_information_resposta' style='text-align:center;width:620px;'>Feito! Pergunta excluida com sucesso!</div>");

    }
	
	this.messageErroExclusaoPergunta = function(id) {

        $("#resposta_site"+id).html("<div class='message_information_resposta' style='text-align:center;width:620px;'>Desculpe! Ocorreu um erro ao tentar excluir a pergunta.</div>");

    }

	this.messageErroExclusaoPerguntaIlegal = function(id) {

        $("#resposta_site"+id).html("<div class='message_information_resposta' style='text-align:center;width:620px;'>N&atilde;o tente trapacear ou ser&aacute; punido.</div>");

    }
	
    this.messageExclusaoResposta = function(id) {

        $("#resposta_site"+id).html("<div class='message_information_resposta' style='text-align:center;width:620px;'>Feito! Resposta excluida com sucesso!</div>");

    }
	
	this.messageErroExclusaoResposta = function(id) {

        $("#resposta_site"+id).html("<div class='message_information_resposta' style='text-align:center;width:620px;'>Desculpe! Ocorreu um erro ao tentar excluir a resposta.</div>");

    }

	this.messageErroExclusaoRespostaIlegal = function(id) {

        $("#resposta_site"+id).html("<div class='message_information_resposta' style='text-align:center;width:620px;'>N&atilde;o tente trapacear ou ser&aacute; punido.</div>");

    }
    
    this.updatePerfil = function(obj) {

        this.lockForm(obj);
        ajax.addParameter("page","update_pergil");
        ajax.addParameter("estado",$("#estado").val());
        ajax.addParameter("cidade",$("#cidade").val());
        ajax.addParameter("sexo",$("#sexo").val());
        ajax.addParameter("data_nascimento",$("#data_nascimento").val());
        ajax.addParameter("perfil",$("#perfil").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }
    this.updateSenha = function(obj) {

        this.lockForm(obj);
        ajax.addParameter("page","update_senha");
        ajax.addParameter("senha",$("#senha").val());
        ajax.addParameter("new_senha",$("#new_senha").val());
        ajax.addParameter("confirmation_senha",$("#confirmation_senha").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            type:"post",
            dataType:'script'
        });
    }
    this.cadastro = function() {
		
	
        ajax.addParameter("page","salvar_user");
        ajax.addParameter("caduser_nome",$("#caduser_nome").val());        
        ajax.addParameter("caduser_email",$("#caduser_email").val());        
        ajax.addParameter("caduser_senha",$("#caduser_senha").val());        
        ajax.addParameter("caduser_confirmacao",$("#caduser_confirmacao").val());  
        ajax.addParameter("checkbox",(document.getElementById("checkbox").checked)?1:0);
		
        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script',
            type:"post"
        /*success:function(response) {
			
                alert(response);
		
            }*/
        });

    }
    this.esqueciSenha = function(obj) {

        this.lockForm(obj);
        ajax.addParameter("page","esqueci_senha");
        ajax.addParameter("esqueci_senha",$("#esqueci_senha").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script',
            type:"post"
        /*success:function(response) {

                alert(response);

            }*/
        });

    }
    
    this.showForm = function(id) {

        $("#"+id).animate({
            height:"toggle",
            opacity:"toggle"
        });

    }
    this.showData = function(id) {

        $("#"+id).html("<input type=\"file\" name=\"materia_user\" onchange=\"JS.showCrop({ arquivo:this,form:\'formupload_user\',url:\'/upload_foto_user.php\' })\" style='font-size:11px;' id='foto_usuario' value='' width='50' /><a href='javascript:void(0)' onclick='JS.showData(\"container_upload_foto\");' style='background:none;padding:0;float:left;font:normal 11px arial;color:red;text-decoration:underline;margin-bottom:5px;'>cancelar</a>");
        if($("#"+id).css("display")=="block") {
            $("#"+id).fadeOut();
        }
        else {
            $("#"+id).fadeIn();
        }

    }
    this.messageOk = function() {

        $("#container_form_resposta").hide();
        $("#responder_pergunta_usuario").hide();
        $("#form_resposta").html("");
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta");
        $("#message_information_resposta").html("Feito! Resposta enviada com sucesso!");
        window.setTimeout("$('#message_information_resposta').fadeOut(500)",2000);

    }
    this.messageIndicacaoOk = function() {

        $("#container_form_indicar").hide();
        $("#indicar_email").val("");
        this.unLockForm("button_send_indicar", "Indicar Email");
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta");
        $("#message_information_resposta").html("Feito! Indicacao enviada com sucesso!");
        window.setTimeout("$('#message_information_resposta').fadeOut(500)",2000);

    }
    
    this.messageDenunciaOk = function() {

        $("#denuncia_pergunta").hide();
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta");
        $("#message_information_resposta").html("Feito! Denuncia realizada!");
        window.setTimeout("$('#message_information_resposta').fadeOut(500)",2000);

    }
    
    this.confirmationCadastro = function() {

        $("#container_cadastro_usuario").html("<div class='message_information_resposta' style='margin-left:9px;width:600px;text-align:center;'>Cadastro realizado com sucesso! Acesse seu email e ative seu cadastro!</div>");
        
    }
    this.confirmationEnvioSenha = function() {

        $("#container_esqueci_senha").html("<div class='message_information_resposta' style='margin-left:9px;width:600px;text-align:center;'>Senha enviada com sucesso!</div>");

    }

    this.confirmationSavePergunta = function() {
        $("#fazer-pergunta").html("<div class='message_information_resposta' style='margin-left:9px;width:600px;text-align:center;'>Feito! Pergunta inserida com sucesso!<a style='color:blue;font:normal 13px arial;' href='/fazer-pergunta/'>Fazer outra pergunta.</a></div>");
    }

    this.confirmationSavePerguntaNoLimite = function() {
        $("#fazer-pergunta").html("<div class='message_information_resposta' style='margin-left:9px;width:600px;text-align:center;'>Feito! Pergunta inserida com sucesso!</div>");
    }

    this.confirmationSavePerguntaSemLimite = function() {
        $("#fazer-pergunta").html("<div class='message_information_resposta_erro' style='margin-left:9px;width:600px;text-align:center;'>Desculpe! Voce excedeu o limite de 10 perguntas por dia.");
    }

    
    this.confirmationFaleConosco = function() {
        $("#fale-conosco").html("<div class='message_information_resposta' style='margin-left:9px;width:600px;text-align:center;'>Feito! Mensagem Envida com sucesso! &nbsp;<a style='color:blue;font:normal 13px arial;' href='/fale-conosco.php'>Enviar outra mensagem</a></div>");
    }

    this.confirmationUpdatePerfil = function() {
        $("#table_editar_perfil").html("<div class='message_information_resposta' style='margin-left:9px;width:620px;text-align:center;'>Feito! Perfil atualizado com sucesso!<br><a href='/'>Voltar a página principal!</a></div>");
    }
    
    this.confirmationUpdateSenha = function() {
        $("#result_perfil").html("<div class='message_information_resposta' style='margin-left:9px;width:350px;text-align:center;'>Feito! Senha alterada com sucesso!</div>");
    }

    this.messageError = function() {
        
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta_erro");
        $("#message_information_resposta").html("Erro ao enviar resposta!");

    }
	this.messageErrorLimite = function() {
        
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta_erro");
        $("#message_information_resposta").html("Erro ao enviar resposta! Voce excedeu o limite de respostas");

    }
	this.messageErrorJaRespondeu = function() {
        
        $("#message_information_resposta").show();
        $("#message_information_resposta").attr("class","message_information_resposta_erro");
        $("#message_information_resposta").html("Erro ao enviar resposta! Voce ja respondeu a essa pergunta");

    }
	
    this.showCrop = function(obj) {

        document.getElementById(obj.form).appendChild(obj.arquivo);
        document.getElementById(obj.form).action = obj.url + name;
        document.getElementById(obj.form).submit();
        obj.arquivo.style.display = "none";

        height_body = $("#corpo-site").height();
        
        jQuery("#result").css({
            height:""+height_body+"px",
            width:""+$(window).width()+"px",
            opacity:0.2
        });
        jQuery("#loader_crop").css({
            top:jQuery(window).scrollTop()+250,
            left:((jQuery(window).width() - 125)/2)
        });

        jQuery("#result").show();
        jQuery("#loader_crop").show();


    }
    this.rum = function() {
        
        api = $.Jcrop('#cropbox',{
            setSelect: [ 0, 0, 300, 225 ],
            aspectRatio:1,
            bgColor:'white',
            bgOpacity:.3,
            onSelect: this.updateCoords,
            onChange:this.updateCoords

        });

    }
    this.updateCoords = function(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
    }
    this.closeCropCutFoto = function() {

        jQuery("#loader_crop").hide();
        jQuery("#result").hide();
        jQuery("#container_image_crop").hide();
        jQuery("#aux_crop").hide();
        jQuery("#container_upload_foto").html("<input type='file' name='materia_user' onchange='JS.showCrop( {  arquivo:this,form:\"formupload_user\",url:\"/upload_foto_user.php\" } )' class='text-file-admin'/><a href=\"javascript:void(0)\" onclick=\"JS.showData('container_upload_foto');\" style=\"background:none;padding:0;float:left;font:normal 11px arial;color:red;text-decoration:underline;margin-bottom:5px;\">cancelar</a>");

    }
    this.confirmCropBox = function(paran) {

        if(paran==0) {
            jQuery("#container_image_crop").hide("slow");
            jQuery("#aux_crop").show("slow");
        }
        else {

            jQuery("#container_image_crop").show();
            jQuery("#aux_crop").hide();
            ajax.addParameter("tipo",0);
            ajax.addParameter("foto",jQuery("#foto_cropbox").val());
            ajax.request({
                url:'/cancel_upload_foto_user.php',
                data:ajax.parameters,
                dataType:'script',
                type:"post"
            });

        }
    }
    this.cropBox = function() {
         
        setTimeout("JS.rum()",4000);

    }
    this.showCropImage = function(foto,tam,alt,param) {

        jQuery("#loader_crop").hide();
        
        if(param==0) {
            this.cropBox();
            jQuery("#container_image_load").html("<img id='cropbox' src='/t_responde/imgs/temp_images_geral/"+foto+"\'/>");
            jQuery("#foto_cropbox").val(foto);
            jQuery("#container_image_crop").fadeIn("slow");
            jQuery("#container_image_crop").css({
                width:tam,
                height:alt,
                top:jQuery(window).scrollTop()+40,
                left:((jQuery(window).width() - tam)/2)
            });
        }
        else if(param==1) {

            jQuery("#container_crop_box").html("<img id='litle_cropbox' src='/t_responde/imgs/temp_images_geral/"+foto+"\'/>");
            jQuery("#litle_foto_cropbox").val(foto);
            jQuery("#aux_crop").css({
                width:tam,
                height:alt,
                top:jQuery(window).scrollTop()+40,
                left:((jQuery(window).width() - tam)/2)
            });
            this.confirmCropBox(0);

        }

    }
    this.appendFotoUser = function() {

        ajax.addParameter("page","update_foto");
        ajax.addParameter("foto",$("#foto_cropbox").val());

        ajax.request({
            url:"/ajax/ajaxRequest.php",
            data:ajax.parameters,
            dataType:'script',
            type:"post"
        });
        

    }
    this.showFormSenha = function() {

        $("#editar-perfil-1-meio-2").hide();
        $("#interna-perfil-1-meio-2").hide();
        $("#interna-perfil-1-meio-3").show();

    }
    this.inputLimiter = function(input,maxlength,counter) {

        diff = maxlength - input.value.length;

        if (diff < 0) {

            input.value = input.value.substr(0,maxlength);

            return false;

        }

        $(counter).text(diff + " caracteres restante(s)");

    }
	
    this.selectedUpCat = "";

    this.showSubCategoria = function(obj) {
		
        $("#subcat"+this.selectedUpCat).hide();
					
        this.selectedUpCat = $(obj).val();
		
        $("#subcat"+$(obj).val()).show();
			
	
    }
   
    
}

var JS = new JQuerySite();