$(document).ready(function() {

$('#ListStatusLinkCheckbox').prop('checked', false);
$("#submitBulkStatus").click(function() 
{
if($("#menuBulkStatus:checked").size()==0)
	{
	  jAlert(msgSelectItem);
	  return false;
	}   
	var status= $('#bulkStatus').val();
	if(!status) {
		jAlert(lblSelectAction);
		return false;
	}		 else	{
		return true;

	}
return false;
});

$("[task=changeStatus]").click(function () {	
	  var ID=$(this).attr("id");
	  var newstatus=$(this).attr("rel");
	      $.ajax({
        type: "POST",
        data: 'id=' +ID + '&newstatus=' + newstatus,
        url: GLOBAL_BASE_PATH + "/custommenu/ajaxchangeStatus/",
        success: function (data) { 
			location.reload();
			}
    })
});
$("[task=delete]").click(function(){
		var ID=$(this).attr('id');
		var count = $(this).attr('rel');
		var subItems =  (count > 0) ? subItemsText: '';
		jConfirm(subItems + msgDeleteMenus,deleteText, function(r) {
	   		if(r==true)
				{
				window.location=GLOBAL_BASE_PATH+"/custommenu/destroy/id/"+ID;
				}
			});
});	
 if($('.AllLangOptions').is(':checked')){           
            if($('input[type="radio"]:checked').val() == 'No'){
            $('.langSpecific').show();
            }else{
            $('.langSpecific').hide();
            }
        }
    $('.AllLangOptions').click(function(){       
        if($('input[type="radio"]:checked').val() == 'No'){
        $('.langSpecific').show();
        }else{
        $('.langSpecific').hide();
        }
    });
$('[name=showSubmenuitems]').change(function() {
	var show = $(this).prop("checked");
	if(show == true) {
		$('#numLevels').attr('disabled','disabled');
		$('#numLevels').val('0');
	} else {
		$('#numLevels').removeAttr('disabled');
	}
});
//DATEPICKER
	if($('#publishFrom').length > 0) {
		var currDate = new Date;
		currDate.setDate(currDate.getDate() - 1);
		currDate.setHours(00);
		currDate.setMinutes(00);
		var tpStart;
        tpStart = currDate;
	$('#publishTo').datepicker({
        minDate: tpStart
		}).change(function(){
		          checkSchedule();
		});
		$('#publishFrom').datepicker({
        minDate: tpStart
		}).change(function(){
		          checkSchedule();
		});
	}
function checkSchedule() {
	var startDate = convertDate($("#publishFrom").val(),datePickerDateFormat);
	var endDate = convertDate($("#publishTo").val(), datePickerDateFormat);	
	if ((startDate > endDate) && (startDate != "") && (endDate != "")) {
		$("#hiddenStartEndDate").val(1);		
	}	
	else {
		$("#hiddenStartEndDate").val(0);
	}
}
//=======START-to generate menu and menu item keys==========
 $('#menuTitle').change(function(){
	 if(menuAction!='Edit')			
		menuURLKey('menuTitle');
 });
 $('#menuItemTitle').change(function(){
	 if($("#menuItemKey").val()=='')			
		menuURLKey('menuItemTitle');
 });
});
function menuURLKey(field) {
	var formattedInput = $.formatUrl($('#'+field).val());
	if(field == 'menuTitle') 
   	 	$("#menuKey").val(formattedInput);
	else {
		
		$("#menuItemKey").val(formattedInput);		
		// Permanent Redirect
		if(settingsRedirectUrl == 'Yes') {
			if($("#menuItemKey").val()!=$("#menuItemKeyOld").val()) 
				$("#redirectOption").removeAttr('disabled');
			else {
				$("#redirectOption").attr("disabled", "true");
			}
		}
	}
 }
 //=======END===============================================
function ismaxlength(obj) {
   var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
   if (obj.getAttribute && obj.value.length>mlength)
   obj.value=obj.value.substr(0,mlength)
}
function showToolTip(menuID,section){
	$("#"+section+"_tooltip_"+menuID).show();
}
function hideToolTip(menuID,section){
	$("#"+section+"_tooltip_"+menuID).hide();
}
$(function(){
$(".add-link").hover(function()
	{
	$(this).parent().find(".tooltip").css("visibility","visible");
	},function()
	{
	$(this).parent().find(".tooltip").css("visibility","hidden");
	}
);
});
//==============  CALL BACK FUNCTIONS ==============================
function checkItemKey(data) {
	var menuItemID=$('#menuItemID').val();
	var brandID=$('#brandID').val();
	$.ajax({
		type : "POST",
		async: false,
		data : "key=" + data.currValue + "&menuItemID=" + menuItemID + "&brandID=" + brandID,
		url  :  GLOBAL_BASE_PATH + "/custommenu/ajaxCheckItemKey/",
		success : function (msg) {
			if(msg == 0) result	= true;
			else result	= false;
		}
	});
	return result;
}
function checkMenuKey(data) {
	var menuID=$('#menuID').val();
	$.ajax({
		type : "POST",
		async: false,
		data : "key=" + data.currValue + "&menuID=" + menuID,
		url  :  GLOBAL_BASE_PATH + "/custommenu/ajaxCheckMenuKey/",
		success : function (msg) {
			if(msg == 0) result	= true;
			else result	= false;
		}
	});
	return result;
}