//AJAX HANDLERS
function ajax_json_call(callUrl, callType, callVars, onCompleteFunc) {
	try {
		$.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 (eval("typeof " + onCompleteFunc + " == 'function'")) {
					eval(onCompleteFunc+'()');
				}
			}
		});
	} catch (e) {
		//nothing for now
	}
}

function process_success_ajax_json_call(data) {
	if (data) {
		var alert_content="";
		$.each(data, function(id, dataHolder) {
			if ($("#"+id) && id!="alert_msg") {
				if (dataHolder.jAction.indexOf('insert')>-1) {
					$(dataHolder.jContentReturn)[dataHolder.jAction]('#'+dataHolder.jHelpId);
				} else {
					$("#"+id)[dataHolder.jAction](dataHolder.jContentReturn);
				}
			}
			if (id=="alert_msg") alert_content += content+"\n";
		});
		if (alert_content != "") alert(alert_content);
	}
	else {
		//process error here...
	}
}
//
function getMoreSearchResults(sid, iteration) {
	if (document.getElementById('extra_search_button')) {
		document.getElementById('extra_search_button').innerHTML = '<img src="filebin/images/retrieving_btn.gif" alt="Retrieving..."  />';
	}
	var callVars = "action=getMoreSearchResults&iteration="+iteration+"&sid="+sid;
	ajax_json_call('resources/js/ajax_php/searchAJAX.php', 'POST', callVars);
	return false;
}
function getMoreEventResults(rows, iteration, totalRows, url) {
	if (document.getElementById('extra_search_button')) {
		document.getElementById('extra_search_button').innerHTML = '<img src="filebin/images/retrieving_btn.gif" alt="Retrieving..." />';
	}
	var callVars = "action=getMoreEventResults&iteration="+iteration+"&rows="+rows+"&totalRows="+totalRows+"&url="+url;
	ajax_json_call('filebin/ajax/php/searchAJAX.php', 'POST', callVars);
	return false;
}
