jQuery(document).ready(function($) {

	$.extend({
		applyNotRequiredFields: function() {
			return $.ajax({
				type: "POST",
				url: "app/includes/ajax.php",
				data: {"action": "get_not_required_fields"}
			})
		}
	})

	var arr = window.location.pathname.split("/");
	var permalink = arr[arr.length - 1];
	
	$.applyNotRequiredFields().done(function(data){
		try {
			data = JSON.parse(data);
			if(data.notrequired[permalink] !== undefined && data.all[permalink] !== undefined) {
				//edit not required fields
				$(".mark-compulsory").css("display", "none");
				for(var key in data.all[permalink]) {
					if(jQuery.inArray(data.all[permalink][key], data.notrequired[permalink]) === -1) {
						$("#"+data.all[permalink][key]).prop('required',true);
						// $("#"+data.all[permalink][key]).parent().addClass("position-relative");
						$("<small for='"+"#"+data.all[permalink][key]+"' class=\"required_field_marker\">&nbsp;*<small>").insertBefore("#"+data.all[permalink][key]);
					} else {
						$("#"+data.all[permalink][key]).parent().find(".required_field_marker[for='"+data.all[permalink][key]+"']").css("display", "none");
						$("#"+data.all[permalink][key]).prop('required',false);
					}
				}
			}
		}
		catch(err) {
			console.log(err);
			console.log(data);
		}
		finally {
			
		}
	})
})