﻿$(document).ready(function(){

// Efecto mostrar ocultar menu en Home
	$(".enlace").click(function () {
		$(this).parent().next().slideToggle(500);
	});

// Efecto mostrar ocultar texto en join-us
	 $("a.muestraOculta").click(function () {
	      $("div.textoBeneficios").toggle("300");
	      return false;
	 });
     $("#expandPayment").click(function () {
          $("#paymentCurrency").toggle("300");
          $("#expandPayment").toggle("300");
          return false;
     });



     $('.seleccionmoneda').change(function () {
        var ordernum = $('#ordernum').attr("value");
        var selmoneda = $(this).val();
        var url = "/payment/set-currency/"+ordernum+"/?c="+selmoneda;
        $.ajax({
            url: url, type: "get",  dataType: "html",
            success: function (response){ },
            error: function (response){ }
        });


     });

     $('#save_keywords').click(function () {
        var url = "/company/save/keyword/";
        $.ajax({
            url: url, type: "POST", 
            data: $('#header_form').serialize(),
            dataType: "html",
            success: function (response){ },
            error: function (response){ }
        });

	      $("#flagwords").toggle("300");
     });

     $('#save_telephone').click(function () {
        var url = "/spamlyapp/save/telephone/";
        $.ajax({
            url: url, type: "GET", 
            data: $('#telephone_form').serialize(),
            dataType: "html",
            success: function (response){ },
            error: function (response){ }
        });
	      $("#ask_telephone").toggle("300");
     });

     /* ######################## VOTACIONES! ########################### */

     $('.vote_good, .vote_maybe').click( function () {
            var id_relation = $(this).parent().parent().parent().attr("name");
            var id_request = $("#request_id_"+id_relation).attr("value");
            var id_response = $("#response_id_"+id_relation).attr("value");
            var choosen = $(this).attr("name");
            var url = "/myspamly/rank/"+id_request+"/"+id_response+"/?choosen="+choosen;

            jQuery('#show_error_'+id_request).css("display", "none");
            
            $.ajax({
                url: url, type: "GET", 
                dataType: "html",
            });
            var x = jQuery("#"+id_relation);
            var header_x = jQuery("#theader"+id_relation);
            
            if (choosen == "3") {
                $("#msg_voting_"+id_relation).html("This company has been asked to email you directly with more information. To ensure they get in touch you may wish to also supply your telephone number and click press:");
            jQuery(x).attr("style", "background:url(/media/images/mailbox_like.gif)");
            jQuery(header_x).html("Actioned: Like it!");
            } else if (choosen == "2") {
                $("#msg_voting_"+id_relation).html("This company may email you directly with more information. If you would like this company to contact you with further information by telephone please note your number below:");
            jQuery(x).attr("style", "background:url(/media/images/mailbox_maybe.gif)");
            jQuery(header_x).html("Actioned: Maybe");
            }
            $("#show_contact_"+id_relation).toggle(300);
            $("#show_rating_"+id_relation).toggle(300);

            var x = jQuery("#"+id_relation).parent();
            jQuery(x).removeClass('rank_pending');
                
     });

     $('.vote_bad').click(function () {
            var id_relation = $(this).parent().parent().parent().attr("name");
            var id_request = $("#request_id_"+id_relation).attr("value");
            var id_response = $("#response_id_"+id_relation).attr("value");
            var choosen = $(this).attr("name");
            var url = "/myspamly/rank/"+id_request+"/"+id_response+"/?choosen=1";
            
            $.ajax({
                url: url, type: "GET", 
                dataType: "html",
            });
            $("#msg_voting2_"+id_relation).html("Noted. We hope one of the other replies will be more suitable.");
            $("#show_rating_"+id_relation).toggle(300);

            var x = jQuery("#"+id_relation).parent();
            jQuery(x).removeClass('rank_pending');
            jQuery('#show_error_'+id_request).css("display", "none");
     });
     $('.vote_junk').click(function () {
            var id_relation = $(this).parent().parent().parent().parent().attr("name");
            var id_request = $("#request_id_"+id_relation).attr("value");
            var id_response = $("#response_id_"+id_relation).attr("value");
            var choosen = $(this).attr("name");
            var url = "/myspamly/rank/"+id_request+"/"+id_response+"/?choosen=0";
            $.ajax({
                url: url, type: "GET", 
                dataType: "html",
            });
            $("#show_rating_"+id_relation).toggle(300);

            var x = jQuery("#"+id_relation).parent();
            jQuery(x).removeClass('rank_pending');
            jQuery('#show_error_'+id_request).css("display", "none");
     });



/*
     $('#vote_good, #vote_maybe, #vote_bad').click(function () {
             var id_relation = $(this).parent().attr("name");
             var id_request = $("#request_id_"+id_relation).attr("value");
             var id_response = $("#response_id_"+id_relation).attr("value");
             var choosen = $(this).attr("name");
            var url = "/myspamly/rank/"+id_request+"/"+id_response+"/?choosen="+choosen;
            $.ajax({
                url: url, type: "GET", 
                data: $('#form_'+id_relation).serialize(),
                dataType: "html",
                success: function (response){ },
                error: function (response){ }
            });
     });
*/

// Efecto mostrar mensaje al pulsar en altavoz en index supplier
	$('.mostrarInfoDiv').click(function() {
	       $.blockUI({ message: $('.msjAltavoz'), css: { width:'550px', background:'transparent', border:'0' } });
    });
    $('.cerrarVentana').click(function(){$.unblockUI();return false;});

    
     $("#f_button, #f_icon").click(function () {
	      $("#flagwords").toggle("300");
     });
});

