//-----------------Start of Smart Search function Using Autocomplete----------------------//
function ajaxLive(key,elemnt_nam,path){

	if(key){//if there is a key pressed and has a value
		jQuery.ajax({
			url: path +'/' +key +'/' +elemnt_nam,
			success:function(searchArray){
				
				jQuery("#"+elemnt_nam).autocomplete ({
					source: searchArray,
					select: function(event,ui){
							
						event.preventDefault();
						jQuery(this).val(ui.item.label);  //Gives Label to Text Field
						jQuery("#"+elemnt_nam+"_ID").val(ui.item.value); //Assigns ID to hidden field
					},
						
					focus: function( event, ui ) {
						event.preventDefault(); //Disables showing values onFocus	
					}
				});
			}
		});
	}//if ends
}
//-----------------End of Smart Search function Using Autocomplete----------------------//

//-------------------- Start of Function for dependable dropdown --------------------------------->
function changeDropdown(key,TrgDrpdwnID,path) {
	
	if(key){//if there is a typeId pressed and has a value
		jQuery.ajax({ // AJAX for Target name
			url: path +'/' +key,
 			success: function(Dropdown) //were calling the response json array activities
 			{
				jQuery("#"+TrgDrpdwnID +" > option").remove(); //first of all clear select items
				 opt = jQuery('<option />').text("Select an option");
				 opt.val(""); //first append with null value so we can get error in form validation
				 jQuery("#"+TrgDrpdwnID).append(opt); 

				jQuery.each(Dropdown,function(id,name) //here we're doing a foeach loop round each activity with id as the key and activity as the value
 				{
 					opt = jQuery('<option />'); // here we're creating a new select option with for each activity
 					opt.val(id);
					opt.text(name);
 					jQuery("#"+TrgDrpdwnID).append(opt); //here we will append these new <span class="adtext" id="adtext_1">select options</span> to a dropdown
 				});
				jQuery("#"+TrgDrpdwnID).trigger("liszt:updated"); //Trigger to update dropdown with chosen plugin
 			}
		});
	}//if ends
}
//-------------------- End of Function for dependable dropdown --------------------------------->

//-----------Start of AJAX to change enable disable status of module dynamically----------------------
function changeEnableDisable(RelDtlID,CheckStatus,path) {
 if(CheckStatus==1){
  var EnaDisChangeConfirm = confirm("Are you sure you want to Enable this module?");
 }else{
  var EnaDisChangeConfirm = confirm("Are you sure you want to Disable this module?");
 }

 if(EnaDisChangeConfirm){
  $.post(path+"index.php/hrchyMngt/manager/ajaxChangeEnableDisable/"+RelDtlID+'/'+CheckStatus);
 }else{
  //=======If user clicks cancel on confirmation, checkbox checked status should not be changed=======
  var checkbox = jQuery('input.module[value="' + RelDtlID + '"]');
  checkbox.prop("checked", !checkbox.prop("checked"));
 }
}
//-----------End of AJAX to change enable disable status of module dynamically----------------------