﻿jQuery.fn.eede = function(options) {
	var defaults = {
	    speed: 'slow'
	},

	opts = jQuery.extend(defaults, options);
	
	return this.each(function(){
		var selector = jQuery(this).attr('detail'),
			collapse = jQuery(selector),
			clickable;
		var hide = jQuery(this).attr('hide')
	    if (hide == "true")
		    collapse.hide();
		jQuery(this)
			.css('cursor','pointer')
			.css('cursor','hand')
			.click(function() {
				collapse.toggle(opts.speed);
				clickable = jQuery(this);
				clickable.children('.collapsed').toggle();
				clickable.children('.expanded').toggle();
			})
			.children('.expanded').hide();
	});
};

function Notify(msg)
{
    $("#notify").html(msg);
    $("#ctrNotify").show();

}

function HideNotify()
{
    $("#notify").html("");
    $("#ctrNotify").hide();

}

function Error(msg)
{
    $("#error").html(msg);
    $("#ctrError").show();

}

function HideError()
{
    $("#error").html("");
    $("#ctrError").hide();

}

function DeleteOrderItem(id) {

    $.post("AjaxHtmlContent.aspx?Content=DeleteOrderItem",
                   { id: id
                   },
                   function(data) {
                       GetHTML();
                   }
                   );

               }

function DeleteOrder(id) {

                   $.post("AjaxHtmlContent.aspx?Content=DeleteOrder",
                   { id: id
                   },
                   function(data) {
                       GetHTML();
                   }
                   );

               }
function CreateOrOpenPopup(div, width, height, title, calbackFunction, callbackIds, callbackNames, page, urlParams, sortCol, sortDir, keyword) 
{
    var queryParams = "";
    POPUP_KEYWORD = undef(keyword) ? "" : keyword;
    if ($("#" + div + ".ui-dialog-content").length == 1 && $("#" + div).attr("queryParams") == queryParams)
        $("#" + div).dialog("open");
    else 
    {
        if ($("#" + div).length == 0) 
        {
            /*var ids = ',';
            var names = ',';
            if ($('#' + callbackIds).length == 1 && $.trim($('#' + callbackIds).val()) != "")
                   ids = ',' + $.trim($('#' + callbackIds).val()) + ',';
            if ($('#' + callbackNames).length == 1 && $.trim($('#' + callbackNames).val()) != "")
                   names = ',' + $.trim($('#' + callbackNames).val()) + ',';*/
            $('<div id="'+div+'" style="overflow:auto;"/>').appendTo("body")
        }
        var url = 'AjaxPages/Popup/' + page + '.aspx?'+urlParams;
        $("#" + div).load(url);
        $("#" + div).unbind("dialogopen");
        /*$("#" + div).bind("dialogopen", function() {
                   SetupPopupParameter(div, 10, url, queryParams, sortCol, sortDir, POPUP_KEYWORD);
        });*/
        if ($("#" + div + ".ui-dialog-content").length == 0) {
            $("#" + div).dialog({ modal: true, title: title });
        } else {
            $("#" + div).dialog("open");
        }
        $("#" + div).unbind("dialogclose");
        /*$("#" + div).bind("dialogclose", function() {
                   RestorePageParameter()
        });*/
        $("#" + div).attr("queryParams", queryParams);
        /*GetHTML();*/
    }
}
               function SetSelectCheckboxId(element, obj) {
                   var div = (obj.length == 1) ? obj : $('#' + obj);
                   if (div.length == 1) {
                       var ids = div.attr('ids');
                       var names = div.attr('names');

                       if (element.value != "") {
                           var oldLength = ids.length;
                           ids = ids.replace("," + element.value + ",", ",");
                           if (ids.length < oldLength)
                               names = names.replace("," + $(element).attr("xtitle") + ",", ",");
                           if (element.checked) {
                               ids += element.value + ",";
                               names += $(element).attr("xtitle") + ",";
                           }
                       }
                       //alert('SetSelectCheckboxId :' + ids + ' : ' + names)
                       div.attr('ids', ids);
                       div.attr('names', names);
                   }
               }
               function ChangeSize(id, orderItemId)
               {
               $.post("AjaxHtmlContent.aspx?Content=ChangeSize",
                   { id: id,
                     orderItemId: orderItemId
                   },
                   function(data) {
                       GetHTML();
                   }
                   );
               }
               function undef(obj) {
                   return typeof (obj) == 'undefined' || obj == null;
               }