$(document).ready(function () {
    $("#searchBusiness").multiselectCustom({
        noneSelectedText: lblSelectBusiness,
        selected: 'business'
    });
    $("#searchProductCategory").multiselectCustom({
        noneSelectedText: lblSelectCategory,
        selected: 'categories'
    });
  //check box validation to update status
	$(document).on('click', "#submitProduct", function () 
	{
		var changeStatus= $('#changeStatus').val();
	   if($(".ListAll:checked").size()==0)
	   {
		   jAlert(msgSelectItem);
			return false;
	   }
	   else if(changeStatus=="")
	   {
		   jAlert(lblSelectAction);
			return false; 
	   }
		if(changeStatus=='Deleted')
		{
			jConfirm(msgConfirmDelete,lblAlert, function(r) 
			{
				if(r==true) {
					$('#formProduct').submit();
				}
			});
		}
		else
		{
			$('#formProduct').submit();
		}
		return false;
	}); 
	
});
$(document).ready(function () {
    if ($(".clone,.setpriority").length > 0) {
        $(".clone,.setpriority").colorbox({
            iframe: true,
            innerWidth: "80%",
            innerHeight: "80%"
        });
    }
    setSideMenu();
    $("#submit").click(function () {
        if (
				$.trim($('#searchProductName').val()) == "" 
				&& $('#searchProductDate').val() == "" 
				&& $('#searchAttrSet').val() == "" 
				&& $('#businessKey').val() == ""
				&& $('#searchDeal').val() == ""
			) 
		{		
			if
			(
				$("[name='multiselect_searchProductCategory']:checked").length == 0 
				&& $('#productStatus').val() == "" 
				&& $('#searchPriceFrom').val() == '' 
				&& $('#searchPriceUpto').val() == ''
				&& $('#searchDiscountFrom').val() == '' 
				&& $('#searchDiscountTo').val() == ''
				&& $('#searchQuantityBelow').val() == ''
			) 
			{
                jAlert(msgSelectSearchCriteria);
                return false;
            } 
        }
        return true;
    });
$(document).on("click",".add01",function () {
	$(this).removeClass("add01")
	$(this).addClass("minus01")
	var rel = $(this).attr('rel');
	 $(".details_"+rel).show();
});
$(document).on("click",".minus01",function () {
	var rel = $(this).attr('rel');
	 $(".details_"+rel).fadeOut();
	 $(this).removeClass("minus01")
	$(this).addClass("add01")
});

});
$(".deleteproduct").click(function () {
    var ID = $(this).attr('productid');
    jConfirm(msgConfirmDeletepdt, lblAlert, function (r) {
        if (r == true) {
            $.ajax({
                type: "POST",
                url: GLOBAL_BASE_PATH + "/product/ajaxChangeStatus/",
                data: "did=" + ID,
                success: function (msg) {
                    location.reload();
                }
            });
        }
    });
});
$("#searchLink").click(function () {
    if ($(this).attr('rel') == 'basic') {
        $(this).text(lblAdvanceSearch);
        $('#searchOption').val('basic');
        $(this).attr('rel', 'advance');
        $(".advanceSearch").hide();
    } else {
        $(this).text(lblBasicSearch);
        $('#searchOption').val('advance');
        $(this).attr('rel', 'basic');
        $(".advanceSearch").show();
    }
});

$(document).on('click', ".ListStatusLinkCheckbox", function () {
	if ($(this).prop("checked") == true) {
		$(".ListAll").prop('checked',true);
	} else {
		$(".ListAll").prop('checked',false);
	}
});
$(document).on('click', ".editbox", function () {
	$("#inlineButtonSection").show();
});	

setActiveTabSaveButton();
function setActiveTabSaveButton()
{
	var cmButtonsFloating = $(".cm-buttons-floating");
	var cmButtons = $(".cm-buttons");
	$.scrollPane({
			floating: cmButtonsFloating,
			fixed: cmButtons,
			padding:71
			});
	
}

Array.prototype.unique = function() {
    var o = {}, i, l = this.length, r = [];
    for(i=0; i<l;i+=1) o[this[i]] = this[i];
    for(i in o) r.push(o[i]);
    return r;
};

function checkOptSKUexist(params){
	var skus =[];
	var counter = 0;
	$(".optionSKU").each(function(){
		if(params['currValue'] == $(this).val()){
			counter++;
		}
	});

	if ( counter > 1){
		return false;
	} 
	else{
		return true;
	} 
}
function checkComSKUexist(params){
	var skus =[];
	var counter = 0;
	$(".combinationSKU").each(function(){
		if(params['currValue'] == $(this).val()){
			counter++;
		}
	});

	if ( counter > 1){
		return false;
	} 
	else{
		return true;
	} 
}