﻿var SiteRoot = "/";


$(document).ready(function () {
    
    //    $('a.minibutton').bind({
    //        mousedown: function () {
    //            $((this).addClass('mousedown'));
    //        },
    //        blur: function () {
    //            $((this).removeClass('mousedown'));
    //        },
    //        mouseup: function () {
    //            $((this).removeClass('mousedown'));
    //        }
    //    });
    $('.rounded').corner('#cccccc 5px');
    $("img").lazyload();
    // $("a[rel='cb']").colorbox();
});






//$("#txtFind").result(function(event, data, formatted) {
  //  window.location = data.value;
//});

//$("#SubmitReview").click(function() {
    //var itemId = $(this).attr("itemId");
    //var ctrl = $(this);
    //var link = SiteRoot + "Helpers/SubmitReview.aspx?itemId=" + itemId;
    //if (link != null) {
        //$.get(link, function(data) {
            //$(ctrl).fadeOut("fast", function() {
                //$(ctrl).replaceWith(data);
                //$(this).fadeIn("slow");

//                $("#Comment").wysiwyg();
  //          });
    //    });
    //}
//});

function SaveReview(ItemId, rating, TitleTextBox, ContentTextBox, MsgCtrl, Container) {
    $.ajax({
        type: 'POST',
        url: SiteRoot + 'WebService.asmx/SaveReview',
        data: '{"itemId": ' + ItemId + ',"rating": ' + $("#" + rating).val() +
        ', "title": "' + $("#" + TitleTextBox).val() +
        '", "review":"' + escapeHTML($('#' + ContentTextBox).val()) + '"}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(msg) {
            var result = msg.d;
            if (result != "") {
                if (result.toString().indexOf('Thanks', 0) >= 0)
                    $('#' + Container).html(result);
                else
                    $('#' + MsgCtrl).html(result);
            }
        }
    });
}

function escapeHTML(html) {
    return html.
    replace(/"/gmi, '&quot;');
}

$("#SubmitReview").click(function() {
    var itemId = $(this).attr("itemId");
    var ctrl = $(this);
    var link = SiteRoot + "Helpers/SubmitReview.aspx?itemId=" + itemId;
    if (link != null) {
        $.get(link, function(data) {
            $(ctrl).fadeOut("fast", function() {
                $(ctrl).replaceWith(data);
                $(this).fadeIn("fast");

                $("#Body").wysiwyg();
            });
        });
    }
});

function SaveListItem(catId, systemObjectId, systemObjectRecordId, ctrlId) {
    $.ajax({
        type: 'POST',
        url: SiteRoot + 'WebService.asmx/SaveListItem',
        data: '{      "sysObjectId":' + systemObjectId +
                    ',"sysObjRecordId":' + systemObjectRecordId +
                    ',"catId": ' + catId +
                    '}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (msg) {
            var result = msg.d;
            if (result != "") {
              if (result.toString().indexOf('ote', 0) >= 0)
                    $("#" + ctrlId).replaceWith(result);
            }
        }
    });
}
function ShowMessageBox(message) {
    return new Boxy(message, { title: "Message", closeable: true });
}
