﻿$(Initialize);

function Initialize() {
    $("#j-link-legal").click(function () {
        ClickLegal();        
        return false;
    });

    $("#j-link-terminos").click(function () {
        ClickTerminos();
        return false;
    });

    $("#close-legal").click(function () {
        ClickLegal();     
        return false;
    });

    $("#close-terminos").click(function () {
        ClickTerminos();
        return false;
    });

    $("#j-general-search").click(function () {
        GeneralSearch();
        return false;
    });

    $("#j-txt-search").keypress(function (e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            GeneralSearch();
            e.preventDefault();
        }
    });  
}

function ClickLegal() {

    if ($("#j-terminos").is(":visible")) {
        $("#j-terminos").hide('300');
        $("#j-aviso-legal").show('300');        
    }
    else {
        $("#container-innner").toggle('300');
        $("#j-aviso-legal").toggle('300');
    }    
}

function ClickTerminos() {
    if ($("#j-aviso-legal").is(":visible")) {
        $("#j-aviso-legal").hide('300');
        $("#j-terminos").show('300');
    }
    else {
        $("#container-innner").toggle('300');
        $("#j-terminos").toggle('300');
    }
}

function GeneralSearch() {
    var search = $("#j-txt-search").val();
    if ($.trim(search) != '') window.location.href = '../html/Chica.aspx?q=' + search;
}

function AjaxCall(methodName, onSuccess, onFail) {
    var args = '';
    var l = arguments.length;
    if (l > 3) {
        for (var i = 3; i < l - 1; i += 2) {
            if (args.length != 0) args += ',';
            args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
        }
    }

    $.ajax({
        type: "POST",
        url: methodName,
        data: "{" + args + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}
