/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 $(document).ready(function()
	{
		if($(".add_location_form").length>0){
			 $('html,body').animate({
			scrollTop: $(".add_location_form").offset().top},
			'slow');
		}	
	
			$(document).on('click','.busLoc',function(){ 
				  $(".show").hide();	
				  $("#wait").show();
			}); 
            // business add page
            var countryID   =   $('#businessCountryID').val();
            var state  =   $('#statehidValue').val();
            listStates(countryID,state);
            $("#ListStatusLinkCheckbox").prop('checked',false);
            // business locations page
            var countryLocID   =   $('#locCountryID').val();
            if(countryLocID){
            listStates(countryLocID,state);
            }
			$(document).on('click','#showAddNewBusinessLocation',function(){
				 $('#adNewBusinessLocation').show();
				 $('#showAddNewBusinessLocation').hide();
				
				});
            $('#adNewBusinessLocation').hide();
            $("ul li:first-child").addClass("first-one");
		$("ul li:last-child").addClass("last-one");
		// Navigation 
		// tab 
		$('#c01').show();
		$('#a01').addClass("cur_menu");
		$('#c02,#c03,#c04,#c05,#c06').hide();
		$('#a02,#a03,#a04,#a05,#a06').addClass("in_active");

	$('.switch label').removeClass('selected');
	$('.switch label').each(function(index) {
			 var cb_hidden_field=$(this).closest('.switch').attr("rel");
			 var cb_hidden_field_value = $("#"+cb_hidden_field).val();
			 if(cb_hidden_field_value==$(this).attr("rel")) {
				$(this).addClass('selected');
			 }

    });
        //check box validation to update status
        $(".update_btn_table").click(function(){
                   var ListAllCheckedCount = $(".ListAll:checked").size();
				   var businessStatus= $('#businessStatusList').val();				  
		  if($(".ListAll:checked").size()==0){
			   jAlert(msgSelectItem);
                           return false;
		   } else if(businessStatus==""){
			   jAlert(lblSelectAction);
                           return false; 
		   }  
				   
                    if(businessStatus=='Deleted')
                    {              jConfirm(msgConfirmDelete, 'Alert', function(r) {
                                            if(r==true) {
                                                    $('#formBusiness').submit();
                                            }
                                    });
                    } else	{
                            return true;
                    }
                    return false;

      });    
     $(".status-active,.status-inactive").click(function(){ 
		var obj=$(this);
		var data=new Object();
		data.businessLocationID=$(this).attr('businessLocationID');
		if($(this).hasClass('status-active'))
			{
			data.newClass='status-inactive';
			data.locStatus='Inactive';	
			$(this).closest('tr').find('td:first').find('input').removeClass('ListActive').addClass('ListInactive');
			}
		else if($(this).hasClass('status-inactive'))
			{
			data.newClass='status-active';
			data.locStatus='Active';
			$(this).closest('tr').find('td:first').find('input:checkbox').removeClass('ListInactive').addClass('ListActive');	
			}
			$.ajax({
			   type: "POST",
			   url: GLOBAL_BASE_PATH+"/business/ajaxlocchangestatus/",
			   data:data,
			   success: function(msg){
				   
					if(msg.trim()=="")
						{
						jNotifyShow(statusChange, "common_message","message_success");
						obj.attr('class',data.newClass+' hide-txt icon-set');
						obj.attr('title',data.locStatus);
						}
			    }
  			});	
		
	}); 
  });
function getStateHiddenValue(val)
{
     $('#statehidValue').val(val);
}
function listStates(countryID,stateID)
{
  if(countryID){
     $("#loadProcessImage").append('<img src="'+GLOBAL_ROOT_PATH+'/public/default/manage/standard/images/ajax-loader.gif" id="loading_gif2"  />');
 } 
  $('#statehidValue').val(stateID);

  $.ajax({
   type: "POST",
   url: GLOBAL_BASE_PATH+"/city/ajaxState/",
   data: "countryID="+countryID+"&stateID="+stateID,
   success: function(msg){  
 	$("#loadProcessImage").empty();
	
    if(msg!=''){
         $("#stateInput").show();
		 $('#locStateID').empty();
         $("#stateProvinceInput").hide();
         $("#locStateID").append('<option value="">Select</option>'+msg);
         $("#stateSelectedType").val("state");
		 $("#locProvince").val('');
		 $("#div_err_frmBusiness_provincehidden").css("display","none");
    } else {
          $("#stateInput").hide();
          $("#stateProvinceInput").show();
		  $('#locStateID').empty();
		  $("#locStateID").append('<option value="">Select</option>');
          $("#stateSelectedType").val("province");
		  $("#div_err_frmBusiness_statehidden").css("display","none");
    }
    
    }
  });
}
function getLocation()
{
	    return true;
}

function delsubconfirm(businsLocID,urlink) {
	
    jConfirm(msgConfirmDelete, 'Alert',function (r) {
        if (r == true) {
            window.location.href = GLOBAL_BASE_PATH +'/business/AjaxDestroyloc/id/'+businsLocID+'/'+urlink;			
        } else {
            return false;
        }
    },okText,cancelText);
}