$(document).ready(function () {

    $('div.stoc').hover(function () {
        $(this).find('div.popup').fadeIn('fast');
    }, function () {
        $(this).find('div.popup').hide();
    })

    var top = $('div#social div.wrapper').offset().top - parseFloat($('div#social div.wrapper').css('marginTop').replace(/auto/, 0));
    $(window).scroll(function (event) {
        var y = $(this).scrollTop();

        if (y >= top) {
            $('div#social div.wrapper').addClass('fixed');
        } else {
            $('div#social div.wrapper').removeClass('fixed');
        }
    });

    $(".tooltip").simpletooltip();
});
(function ($) {
    $.fn.simpletooltip = function () {
        return this.each(function () {
            var text = $(this).attr("title");
            $(this).attr("title", "");
            if (text != undefined) {
                $(this).hover(function (e) {
                    var tipX = e.pageX;
                    var tipY = e.pageY + 20;
                    $(this).attr("title", "");
                    $("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'><h3>" + text + "</h3><div style=\"display: none;\" class=\"body\"></div><div style=\"display: none;\" class=\"url\"></div></div>");
                    if ($.browser.msie) var tipWidth = $("#simpleTooltip").outerWidth(true)
                    else var tipWidth = $("#simpleTooltip").width()
                    $("#simpleTooltip").width(tipWidth);
                    $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
                }, function () {
                    $("#simpleTooltip").remove();
                    $(this).attr("title", text);
                });
                $(this).mousemove(function (e) {
                    var tipX = e.pageX;
                    var tipY = e.pageY + 20;
                    var tipWidth = $("#simpleTooltip").outerWidth(true);
                    var tipHeight = $("#simpleTooltip").outerHeight(true);
                    if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
                    if ($(window).height() + $(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
                    $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
                });
            }
        });
    }
})(jQuery);

function tooltip(id) {
    var text = $('#' + id).attr("title");
    $('#' + id).attr("title", "");
    if (text != undefined) {
        $('#' + id).mousemove(function (e) {
            if ($("#simpleTooltip").html() == null) $("body").append("<div id='simpleTooltip' style='position: absolute; z-index: 100; display: none;'><h3>" + text + "</h3><div style=\"display: none;\" class=\"body\"></div><div style=\"display: none;\" class=\"url\"></div></div>");
            var tipX = e.pageX;
            var tipY = e.pageY + 20;
            var tipWidth = $("#simpleTooltip").outerWidth(true);
            var tipHeight = $("#simpleTooltip").outerHeight(true);
            if (tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
            if ($(window).height() + $(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
            $("#simpleTooltip").css("left", tipX).css("top", tipY).fadeIn("medium");
        })
        $('#' + id).mouseout(function () {
            $("#simpleTooltip").remove();
            $('#' + id).attr("title", text);
        });
    }
}

function autosuggest() {
    var categorie = $('#cautaCategorii').val();
    $.get("http://www.vexio.ro/Ajax_cautaCategorii.php", {
        categorie: categorie
    }, function (data) {
        if (data != "") {
            $('#rezultatSCategorii').html(data);
            $('#rezultatSCategorii').show();
        } else {
            $('#rezultatSCategorii').hide();
        }
    });
}
var IE6 = false

function modalBox(content, width, topM) {
    var topM = (topM != undefined) ? topM : 250;
    if (!content) {
        $('#ntz_modal').remove();
        $('#ntz_overlay').fadeOut(function () {
            $(this).remove();
        });
        try {
            if (IE6) {
                $('body').find('select').visibility('visible');
            }
        } catch (err) {};
        return false;
    }
    try {
        if (IE6) {
            $('body').find('select').visibility('hidden');
        }
    } catch (err) {};
    $('body').append('<div id="ntz_overlay"><\/div>');
    $('#ntz_overlay').css({
        width: '100%',
        height: $(document).height(),
        position: 'absolute',
        left: 0,
        top: 0,
        backgroundColor: '#000',
        zIndex: 9990,
        opacity: 0
    }).fadeTo(200, 0.5).click(function () {
        modalBox()
    });
    $('body').append('<div id="ntz_modal"><\/div>');
    $('#ntz_modal').css({
        width: width ? width : 408,
        position: 'absolute',
        border: '1px solid #E7E7E7',
        backgroundColor: '#E7E7E7',
        left: '50%',
        top: $(document).scrollTop() + topM,
        zIndex: 9995,
        marginLeft: -(Math.ceil((width ? width : 300) / 2))
    }).append(content);
    $('#ntz_modal a:eq(0), #ntz_modal input, #ntz_modal textarea').focus();
    $(document).bind('scroll', function () {
        $('#ntz_modal').css({
            top: $(document).scrollTop() + topM
        });
    });
};

function golestecos() {
    $("#cosproduse").html('<img src="http://www.vexio.ro/img/indicator.gif" title="Va rugam sa asteptati." alt="Va rugam sa asteptati." />');
    $.get("http://www.vexio.ro/Ajax_Golestecos.php", {}, function (data) {
        $("#golestecos").html(data);
        $("#cosproduse").html('Nu aveti produse in cos.');
        $("#simpleTooltip").remove();
    });
}

function golestewishlist() {
    $("#wishlistproduse").html('<img src="http://www.vexio.ro/img/indicator.gif" title="Va rugam sa asteptati." alt="Va rugam sa asteptati." />');
    $.get("http://www.vexio.ro/Ajax_Golestewishlist.php", {}, function (data) {
        $("#golestewishlist").html(data);
        $("#wishlistproduse").html('Nu aveti produse in wishlist.');
        $("#simpleTooltip").remove();
    });
}

function popUpWindow(URLStr, left, top, width, height) {
    if (width == 0 && height == 0) {
        var fullsc = 'fullscreen=yes,';
        var marime = "";
    } else {
        var fullsc = "";
        var marime = ',width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top + '';
    }
    popUpWin = open(URLStr, '_blank', '' + fullsc + 'toolbar=no,location=no,,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes' + marime + '');
}

function popUpCenter(url, w, h) {
    sw = screen.width;
    sh = screen.height;
    l = (sw - w) / 2;
    t = (sh - h) / 2;
    var marime = ',width=' + w + ',height=' + h + ',left=' + l + ', top=' + t + '';
    popUpWin = open(url, '_blank', 'toolbar=no,location=no,,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes' + marime + '');
}

function cautareVexio(prefix) {
    document.cauta.action = 'http://www.vexio.ro/' + prefix + 'cauta-in-site/' + document.cauta.camp_produs.value + '/Categorie,toate/P1';
}

function cautaProdus(prefix) {
    var produs = (document.cautas.camp_produs.value == "") ? "" : document.cautas.camp_produs.value + '/';
    document.cautas.action = 'http://www.vexio.ro/' + prefix + 'cauta-in-site/' + produs + 'Categorie,' + document.cautas.camp_categorie.value + '/P1';
}

function tipersoane(tip) {
    if (tip == 'fizica') {
        $('#persoana_fizica').show();
        $('#persoana_juridica').hide();
        $('#fizica').attr("checked", "checked");
        $('#juridica').attr("checked", "");
    } else if (tip == 'juridica') {
        $('#persoana_fizica').hide();
        $('#persoana_juridica').show();
        $('#fizica').attr("checked", "");
        $('#juridica').attr("checked", "checked");
    }
}

function showMenuF(id) {
    $('#secundarF_' + id).show();
}

function hideMenuF(id) {
    $('#secundarF_' + id).hide();
}

function actiuneMeniu(idMeniu) {
    var statusMeniu = $('#' + idMeniu).css("display");
    if (statusMeniu == 'none') {
        $('#' + idMeniu).slideDown(100);
        status = 0;
    } else {
        $('#' + idMeniu).slideUp(100);
        status = 1;
    }
    $.get("http://www.vexio.ro/Ajax_meniuVizitator.php", {
        idMeniu: idMeniu,
        status: status
    }, function (data) {
        $("#inchideTot").html(data);
    });
}

function actiuneToate(tip) {
    $.get("http://www.vexio.ro/Ajax_meniuVizitatorToate.php", {
        tip: tip
    }, function (data) {
        var splitV = data.split(',');
        for (i = 0; i < splitV.length; i++) {
            if ($("#subcat_" + splitV[i])) {
                if (tip == 'inchis') $("#subcat_" + splitV[i]).show();
                else $("#subcat_" + splitV[i]).hide();
            }
        }
        if (tip == 'deschis') inchideTotx = "Produsele noastre<a href=\"javascript:void(0);\" id=\"deschideTot_\" onmouseover=\"tooltip('deschideTot_');\" title=\"Deschide tot meniul\" onclick=\"actiuneToate('inchis');\" class=\"btnBox\"><img src=\"http://www.vexio.ro/img/btn_deschide_mn.jpg\" alt=\"\" /></a>";
        else inchideTotx = "Produsele noastre<a href=\"javascript:void(0);\" id=\"inchideTot_\" onmouseover=\"tooltip('inchideTot_');\" title=\"Inchide tot meniul\" onclick=\"actiuneToate('deschis');\" class=\"btnBox\"><img src=\"http://www.vexio.ro/img/btn_inchide_mn.jpg\" alt=\"\" /></a>";
        $("#inchideTot").html(inchideTotx);
        $("#simpleTooltip").remove();
    });
}

function actiuneMeniuUt(idMeniu) {
    var statusMeniu = $('#' + idMeniu).css("display");
    if (statusMeniu == 'none') {
        $('#' + idMeniu).slideDown(100);
        status = 1;
    } else {
        $('#' + idMeniu).slideUp(100);
        status = 0;
    }
    $.get("http://www.vexio.ro/Ajax_meniuUtilizator.php", {
        idMeniu: idMeniu,
        status: status
    }, function (data) {
        $("#inchideTot").html(data);
    });
}

function actiuneToateUt(tip) {
    $.get("http://www.vexio.ro/Ajax_meniuUtilizatorToate.php", {
        tip: tip
    }, function (data) {
        var splitV = data.split(',');
        for (i = 0; i < splitV.length; i++) {
            if ($("#subcat_" + splitV[i])) {
                if (tip == 'inchis') $("#subcat_" + splitV[i]).show();
                else $("#subcat_" + splitV[i]).hide();
            }
        }
        if (tip == 'deschis') inchideTotx = "Produsele noastre<a href=\"javascript:void(0);\" id=\"deschideTot_\" onmouseover=\"tooltip('deschideTot_');\" title=\"Deschide tot meniul\" onclick=\"actiuneToateUt('inchis');\" class=\"btnBox\"><img src=\"http://www.vexio.ro/img/btn_deschide_mn.jpg\" alt=\"\" /></a>";
        else inchideTotx = "Produsele noastre<a href=\"javascript:void(0);\" id=\"inchideTot_\" onmouseover=\"tooltip('inchideTot_');\" title=\"Inchide tot meniul\" onclick=\"actiuneToateUt('deschis');\" class=\"btnBox\"><img src=\"http://www.vexio.ro/img/btn_inchide_mn.jpg\" alt=\"\" /></a>";
        $("#inchideTot").html(inchideTotx);
        $("#simpleTooltip").remove();
    });
}
