﻿/// <reference path="jquery-1.4.4.js" />
/// <reference path="jquery-ui.js" />
$(window).load(function () {

    //$(".drop_shadow_box").shadowOn({ imageset: 1 });
    $(".star_rating").rating();

    $("#enlarge_image_lnk").click(function (event) {
        $("#enlargeImagePopup").dialog({
            height: 625,
            width: 600,
            modal: true,
            buttons: {
                "Close": function (element) {
                    $(this).dialog("close");
                }
            }
        });
    });

    $('input#q').keyup(function (event) {
        delay(function () {
            getProductCount();
        }, 500);
    });

    $('input[name="aid"]').change(function (event) {
        getProductCount();
    });

});

function popupDisputeForm(formOrdinal) {
    $("#disputePopup_" + formOrdinal).dialog({
        height: 350,
        width: 600,
        modal: true,
        buttons: {
            "Yes": function (element) {
                $(this).children("form").submit();
                $(this).dialog("close");
            },
            "No": function (element) {
                $(this).dialog("close");
            },
            "Cancel": function (element) {
                $(this).dialog("close");
            }
        }
    });
}

 function getProductCount() {
     $.ajax({
         url: "/Search/Count",
         type: "POST",
         dataType: "json",
         data: $("#searchForm").serialize(),
         success: function (data) {
             if (!isNaN(data) && data >= 0) {
                 if (data == 0) {
                     $("#resultCount").html("<br/>" + data + " products found.")
                 }
                 else if (data == 1) {
                     $("#resultCount").html("<br/>" + data + " product found. <a href=\"#\" onclick=\"$('#searchForm').submit();\">Show it...</a>")
                 }
                 else {
                     $("#resultCount").html("<br/>" + data + " products found. <a href=\"#\" onclick=\"$('#searchForm').submit();\">Show them...</a>")
                 }
                 $("#resultCount").show(2000);
             }
         }
     });
}

var delay = (function () {
    var timer = 0;
    return function (callback, ms) {
        clearTimeout(timer);
        timer = setTimeout(callback, ms);
    };
})();

////////////////////////////////////////////////////////
/*
*Toolbar Menu
*/
var ddmenuitem	= 0;
// open hidden layer
function mopen(id)
{	
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// close layer when click-out
document.onclick = mclose;

////////////////////////////////////////////////////////
/*
* jQuery Watermark plugin
* Version 1.2 (7-DEC-2010)
* @requires jQuery v1.3 or later
*
* Examples at: http://mario.ec/static/jq-watermark/
* Copyright (c) 2010 Mario Estrada
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function (a) {
    var k = a.browser.msie && a.browser.version < 8; a.watermarker = function () { }; a.extend(a.watermarker, { defaults: { color: "#999", left: 0, top: 0, fallback: false, animDuration: 300, minOpacity: 0.6 }, setDefaults: function (e) { a.extend(a.watermarker.defaults, e) }, checkVal: function (e, c) { e.length == 0 ? a(c).show() : a(c).hide(); return e.length > 0 }, html5_support: function () { return "placeholder" in document.createElement("input") } }); a.fn.watermark = function (e, c) {
        var i; c = a.extend(a.watermarker.defaults, c); i = this.filter("textarea, input:not(:checkbox,:radio,:file,:submit,:reset)");
        if (!(c.fallback && a.watermarker.html5_support())) {
            i.each(function () {
                var b, f, j, g, d, h = 0; b = a(this); if (b.attr("data-jq-watermark") != "processed") {
                    f = b.attr("placeholder") != undefined && b.attr("placeholder") != "" ? "placeholder" : "title"; j = e === undefined || e === "" ? a(this).attr(f) : e; g = a('<span class="watermark_container"></span>'); d = a('<span class="watermark">' + j + "</span>"); f == "placeholder" && b.removeAttr("placeholder"); g.css({ display: "inline-block", position: "relative" }); k && g.css({ zoom: 1, display: "inline" }); b.wrap(g).attr("data-jq-watermark",
"processed"); if (this.nodeName.toLowerCase() == "textarea") { e_height = b.css("line-height"); e_height = e_height === "normal" ? parseInt(b.css("font-size")) : e_height; h = b.css("padding-top") != "auto" ? parseInt(b.css("padding-top")) : 0 } else { e_height = b.outerHeight(); if (e_height <= 0) { e_height = b.css("padding-top") != "auto" ? parseInt(b.css("padding-top")) : 0; e_height += b.css("padding-bottom") != "auto" ? parseInt(b.css("padding-bottom")) : 0; e_height += b.css("height") != "auto" ? parseInt(b.css("height")) : 0 } } h += b.css("margin-top") != "auto" ?
parseInt(b.css("margin-top")) : 0; f = b.css("margin-left") != "auto" ? parseInt(b.css("margin-left")) : 0; f += b.css("padding-left") != "auto" ? parseInt(b.css("padding-left")) : 0; d.css({ position: "absolute", display: "block", fontFamily: b.css("font-family"), fontSize: b.css("font-size"), color: c.color, left: 4 + c.left + f, top: c.top + h, height: e_height, lineHeight: e_height + "px", textAlign: "left", pointerEvents: "none" }).data("jq_watermark_element", b); a.watermarker.checkVal(b.val(), d); d.click(function () { a(a(this).data("jq_watermark_element")).trigger("focus") });
                    b.before(d).bind("focus.jq_watermark", function () { a.watermarker.checkVal(a(this).val(), d) || d.stop().fadeTo(c.animDuration, c.minOpacity) }).bind("blur.jq_watermark change.jq_watermark", function () { a.watermarker.checkVal(a(this).val(), d) || d.stop().fadeTo(c.animDuration, 1) }).bind("keydown.jq_watermark", function () { a(d).hide() }).bind("keyup.jq_watermark", function () { a.watermarker.checkVal(a(this).val(), d) })
                } 
            }); return this
        } 
    }; a(document).ready(function () { a(".jq_watermark").watermark() })
})(jQuery);
