
function HJBizDir_listing_form() {
  var data = jQuery("#hjbizdir_listing_form").serialize();
  
  jQuery.post(hjbizdir_wpurl + "/wp-content/plugins/hj-bizdir/Controller.php?c=listing", 
    data,
    function(data, textStatus) {
      if ("success" != textStatus || !data.status) {
        alert("An error occurred and your changes were not saved.");
      }
      else {
        var dataArray = jQuery("#hjbizdir_listing_form").serializeArray();
        if (dataArray[0].value) {
          history.go(-1);
        }
        else {
          jQuery("#hjbizdir_listing_form").html("<p>Listing submitted successfully. It must first be approved before it will show up on our website.</p>")
        }
        
      }
    },
    "json");
    
}

function HJBizDir_new_category() {
  var data = jQuery("#hjbizdir_new_category_form").serialize();
  
  jQuery.post(hjbizdir_wpurl + "/wp-content/plugins/hj-bizdir/Controller.php?c=category", 
    data,
    function(data, textStatus) {
      if ("success" != textStatus || !data.status) {
        alert("An error occurred and your changes were not saved.");
      }
      else {
        window.location.href=window.location.href;
      }
    },
    "json");
    
    return false;
}

function HJBizDir_ListingDestory(id) {
  var id;
  
  jQuery.post(hjbizdir_wpurl + "/wp-content/plugins/hj-bizdir/Controller.php?c=listing&a=destroy", 
    { 'id': id },
    function(data, textStatus) {
      if ("success" != textStatus || !data.status) {
        alert("An error occurred and your changes were not saved.");
      }
      else {
        jQuery("#hjbizdir_listing_" + id).fadeOut("normal");
      }
    },
    "json");
    
    return false;    
}

function HJBizDir_ListingApprove(id) {
  var id;
  
  jQuery.post(hjbizdir_wpurl + "/wp-content/plugins/hj-bizdir/Controller.php?c=listing&a=approve", 
    { 'id': id },
    function(data, textStatus) {
      if ("success" != textStatus || !data.status) {
        alert("An error occurred and your changes were not saved.");
      }
      else {
        jQuery("#hjbizdir_listing_entry_approve_" + id).fadeOut("normal");
      }
    },
    "json");
    
    return false;    
}

function HJBizDir_TagManage(action, id, type) {
  var action;
  var id;
	var type;
  var name = jQuery("#hjbizdir_"+ type + "_name_input_field_" + id).val();

  jQuery.post(hjbizdir_wpurl + "/wp-content/plugins/hj-bizdir/Controller.php?c="+ type + "&a=" + action, 
    { 'id': id,
       'name': name },
    function(data, textStatus) {
      if ("success" != textStatus || !data.status) {
        alert("An error occurred and your changes were not saved.");
      }
      else {
        if ("approve" == action) {
          jQuery("#hjbizdir_"+ type + "_approve_" + id).fadeOut("normal");
        }
        else if ("update" == action) {
          jQuery("#hjbizdir_"+ type + "_name_" + id).html(name);
          jQuery("#hjbizdir_"+ type + "_name_input_" + id).hide();
          jQuery("#hjbizdir_"+ type + "_name_" + id).show();
        }        
        else if ("destroy" == action) {
          jQuery("#hjbizdir_"+ type + "_" + id).fadeOut("normal");
        }
      }
    },
    "json");
    
    return false;    
}



