﻿
function changeMenubyId(id, selected_class, unselected_class) {

    $("div[id*=li_opt]").each(
        function() {
            $(this).addClass("menuOpt").removeClass(selected_class).addClass(unselected_class);
        }
    );

    $("div[id*=view_opt]").each(
        function() {
            $(this).hide();
        }
    );

    $("#li_opt"+id).removeClass(unselected_class).removeClass("menuOpt").addClass(selected_class);

    $("#view_opt" + id).show();

    if ($("#li_opt" + (parseInt(id) + 1)).length > 0) {
        $("#navNext").css("visibility", "visible");
    }
    else {
        $("#navNext").css("visibility", "hidden");
    }
    if ($("#li_opt" + (parseInt(id) - 1)).length > 0) {
        $("#navPrev").css("visibility", "visible");
    }
    else {
        $("#navPrev").css("visibility", "hidden");
    }

    $jq.setFragment({ "id": id });
}
function changeMenu(obj, selected_class, unselected_class) {

    $("div[id*=li_opt]").each(
        function() {
            $(this).addClass("menuOpt").removeClass(selected_class).addClass(unselected_class);
        }
    );

    $("div[id*=view_opt]").each(
        function() {
            $(this).hide();
        }
    );

    obj.removeClass(unselected_class).removeClass("menuOpt").addClass(selected_class);
    
    $("#view_opt" + obj[0].id.substring(obj[0].id.length - 1)).show();

    if ($("#li_opt" + (parseInt(obj[0].id.substring(obj[0].id.length - 1)) + 1)).length > 0) {
        $("#navNext").css("visibility", "visible");
    }
    else {
        $("#navNext").css("visibility", "hidden");
    }
    if ($("#li_opt" + (parseInt(obj[0].id.substring(obj[0].id.length - 1)) - 1)).length > 0) {
        $("#navPrev").css("visibility", "visible");
    }
    else {
        $("#navPrev").css("visibility", "hidden");
    }

    $jq.setFragment({ "id": obj[0].id.substring(obj[0].id.length - 1) });
}

function navigate(option, selected_class, unselected_class)
{
    $("div[id*=li_opt]").each(
        function() {
            if ($(this).is("." + selected_class)) {
                var nextOpt = "#li_opt" + (parseInt($(this)[0].id.substring($(this)[0].id.length - 1)) + 1); ;
                var prevOpt = "#li_opt" + (parseInt($(this)[0].id.substring($(this)[0].id.length - 1)) - 1); ;

                switch (option) {
                    case "N": //Next
                        if ($(nextOpt).length > 0) {
                            changeMenu($(nextOpt), selected_class, unselected_class)
                        }
                        return false;
                        break;
                    case "P": //Previous
                        if ($(prevOpt).length > 0)
                            changeMenu($(prevOpt), selected_class, unselected_class)
                        return false;
                        break;
                }
            }
        }
    );
}


var activePublisher = 0;

function navArrows(opt, obj) {
    var newVisible = "";
    var sDirection = "";
    var sCtrl = obj.id.substring(0,3);
    switch (opt) {
        case "N":
            newVisible = parseInt(activePublisher) + 1;
            sDirection = "right";
            break;
        case "P":
            newVisible = parseInt(activePublisher) - 1;
            sDirection = "left";
            break;
    }

    if ($('#obj_img_' + sCtrl + newVisible).length > 0) {
        $('#obj_img_' + sCtrl + activePublisher).hide();
        $('#obj_img_' + sCtrl + newVisible).show('slide', { direction: sDirection }, 600);        
        activePublisher = newVisible;
    }
}

function openUrl(obj)
{
    if (obj.href!="")
        window.open(obj.href);
}

function encodeTextInput()
{
    $("textarea").each(
        function(elem) {
            if (this.value == '') { return; }
            var rx = new RegExp('[^<>]+');
            var matches = rx.exec(this.value);
            if (matches != this.value) {
                this.value = this.value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
                return;
            }
        }
    );
    $("input").each(
        function(elem) {
            if (this.value == '') { return; }

            var rx = new RegExp('[^<>]+');
            var matches = rx.exec(this.value);
            if (matches != this.value) {

                this.value = this.value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
                return;
            }
        }
    );
}

mktime = function()
{
    var no, i = 0, d = new Date(), argv = arguments, argc = argv.length;
    var dateManip = 
    {
        0: function(tt) { return d.setHours(tt); },
        1: function(tt) { return d.setMinutes(tt); },
        2: function(tt) { return d.setSeconds(tt); },
        3: function(tt) { return d.setMonth(parseInt(tt) - 1); },
        4: function(tt) { return d.setDate(tt); },
        5: function(tt) { return d.setYear(tt); }
    };
    for (i = 0; i < argc; i++) 
    {
        no = parseInt(argv[i]);
        if (no && isNaN(no)) {
            return false;
        } else if (no) {
            // arg is number, let's manipulate date object
            if (!dateManip[i](no)) {
                // failed
                return false;
            }
        }
    }
    return Math.floor(d.getTime() / 1000);
}

function set_Background(obj, section) {
    var heigthMap = 545 - (obj.height() - 10);
    $(section).css({ 'background': 'url(/images/adclip/fundo_Homepage.gif) 0 -' + heigthMap + 'px repeat-x', 'top': '-10px' });
}