/*
 * used for lists data
 * Version: 1.0
 */
jQuery(document).ready(function(e){
	jQuery("#o365_ms_booking_activate_button").click(function(e){
		var key = jQuery.trim( jQuery("#o365_ms_booking_license_key").val() );
		var sku_id= jQuery("#o365_ms_booking_plugin_sku_id").val();
		var data = { 'key':key,'sku_id':sku_id,'action':'get_key_data_from_plugin_site'};
		url = "https://api.wpintegrate.com/check_key_updates.php";
        jQuery.post( url, data , function( response, txtStatus, jqXHR ){
			if( response == 1){
				var data = { 'action':'o365_ms_booking_update_plugin_activate','key':key};
				jQuery.post( ajaxurl, data , function( response, txtStatus, jqXHR ){
					if(response.success){
						jQuery("#o365_ms_booking_plugin_notification").html("<p>" + response.data.message + "</p>");
						jQuery("#o365_ms_booking_plugin_notification").removeClass("update-nag");
						jQuery("#o365_ms_booking_plugin_notification").removeClass("notice notice-error");
						jQuery("#o365_ms_booking_plugin_notification").addClass("notice notice-success");
						jQuery("#o365_ms_booking_message").html("<p class='notice notice-success'>" + response.data.message + "</p>");
						jQuery("#o365_ms_booking_activate_button").prop('disabled', true);
					}
				})
				.fail(function(){
					alert("ERROR");
				});
			}
			else{
				jQuery("#o365_ms_booking_message").html("<p class='notice notice-error'>Please enter valid key.</p>");
			}
		})
		.fail(function(){
			alert("ERROR");
		});
    });
});