function expandResults(page_id, maxProd, name, limit) {
     if (document.getElementById("expand")) { 
	  $('#expand').html('loading...');
     }
     var vars = 'action=getAllPageResults&page_id='+page_id+'&limit='+limit+'&maxProd='+maxProd+'&name='+name;
     ajax_json_call('resources/js/ajax_php/searchAJAX.php', 'POST', vars, "");
}
function closeResults(page_id, maxProd, name, limit) {
     if (document.getElementById("expand")) { 
	  $('#expand').html('<a id="expand" href="javascript:expandResults(\''+page_id+'\',\''+maxProd+'\',\''+name+'\',\''+limit+'\')">Click to See All '+maxProd+' '+name+'</a>');
     }
}
// JSON ACTIONS
function ajax_json_call(callUrl, callType, callVars, onCompleteFunc) {
	try {
		jQuery.ajax({
			type: callType,
			url: callUrl,
			data: callVars,
			dataType: "json",
			success: function(data) {
				if (data) {
					process_success_ajax_json_call(data);
				} else {
					//error
				}
		 	},
			complete: function() {
				//if we need to run something discard if we get data or not
				if (onCompleteFunc!='') {
					if (eval("typeof " + onCompleteFunc + " == 'function'")) {
						eval(onCompleteFunc+'()');
					}
				}
			}
		});
	} catch (e) {
		alert(e);
		//nothing for now
	}
}
function process_success_ajax_json_call(data) {
	if (data) {
		var alert_content="";
		jQuery.each(data, function(id, dataHolder) {
			if (jQuery("#"+id) && id!="alert_msg") {
				if (dataHolder.jAction.indexOf('insert')>-1) {
					//insertAfter, insertBefore
					jQuery(decodeURIComponent(escape(dataHolder.jContentReturn)))[dataHolder.jAction]('#'+dataHolder.jHelpId);
				} else {
					jQuery("#"+id)[dataHolder.jAction](decodeURIComponent(escape(dataHolder.jContentReturn)));
				}
			}
			//display js alert
			if (id=="reload_page") window.location.reload();
			if (id=="alert_msg") alert_content += content+"\n";

		});
		if (alert_content != "") alert(alert_content);
	}
	else {
		//process error here...
		alert(data);
	}
}
