function update_toplinks() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"p": "json", "c": "toplink_oh"},
		type: "POST",
		success: function(html) {
			// fade out what is already there
			$("#toplinks").fadeOut("normal", function() {
				// swap the content
				$("#toplinks").html(html);
				// bring top links back in
				$("#toplinks").fadeIn();
			});
		}
	});
}
/* Login and user functionality */
function login() {
	if ($("#remember:checked").val() == "yes") { remember = "yes"; }
	else { remember = "no"; }
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "user", "v": "login", "e": $("#email").val(), "p": $("#password").val(), "r": remember},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			IB_notify_msg_show();
			$("#OHsearch, #OHclipboard").equalizeCols();
			// now we've successully logged in, change the toplinks to match
			update_toplinks();
		}
	});
}
function logout() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "user", "v": "logout"},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
			IB_notify_msg_show();
			// now we've successully logged out, change the toplinks to match
			update_toplinks();
		}
	});
}
function show_password_recover() {
	data = {"c": "user", "v": "password-recover" };
	if($("#email-recover").val() !=  undefined) {
		jQuery.extend(data, {"e": $("#email-recover").val()} );
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
		}
	});
}
function show_signup() {
	var data = $("#signup").serialize();
	if(data !=  undefined) {
		data += "&c=user&v=signup";
	}
	else {
		data = {"c": "user", "v": "signup" };
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
			$("#OHsearch, #OHclipboard").equalizeCols();
			update_toplinks();
		}
	});
}
function show_account() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "user", "v": "account" },
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
			$("#OHsearch, #OHclipboard").equalizeCols();
			IB_notify_msg_show();
		}
	});
	return false;
}
function process_account() {
	var data = $("#account").serialize();
	if(data !=  undefined) {
		data += "&c=user&v=account";
	}
	else {
		data = {"c": "user", "v": "account" };
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
			$("#OHsearch, #OHclipboard").equalizeCols();
			IB_notify_msg_show();
		}
	});
}
/* Search Functionality */
function show_oh_results_page(view, search, page, rpp) {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "results_page", "v": view, "s": search, "page": page, "rpp": rpp},
		type: "POST",
		success: function(html){
			$("#OHResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function show_oh_pr_results_page(url, search, page, rpp) {
	$.ajax({
		url: url,
		dataType: "html",
		data: {"c": "results_page", "s": search, "page": page, "rpp": rpp},
		type: "POST",
		success: function(html){
			$("#OHResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function open_manage_cb() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "manage_clipboards"},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function view_cb(id, page, rpp) {
	data = {"c": "view_clipboard"};
	if(id !=  undefined) {
		jQuery.extend(data, {"id": id} );
	}
	if(page !=  undefined) {
		jQuery.extend(data, {"page-cb": page} );
	}
	if(rpp !=  undefined) {
		jQuery.extend(data, {"rpp-cb": rpp} );
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function new_cb() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "new_clipboard"},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			IB_notify_msg_show();
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function save_cb() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "save_clipboard"},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
			IB_notify_msg_show();
		}
	});
}
function delete_cb(id) {
	data = {"c": "delete_clipboard", "id": id };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
function delete_cb_process(id) {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "delete_clipboard_process", "id": id},
		type: "POST",
		success: function(html){
			tb_remove();
			$("#CBResultsHolder").html(html);
			IB_notify_msg_show();
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function delete_cbs_all() {
	data = {"c": "delete_clipboards_all" };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
function delete_cbs_all_process() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "delete_clipboards_all_process"},
		type: "POST",
		success: function(html){
			// close the thicbox
			tb_remove();
			$("#CBResultsHolder").html(html);
			IB_notify_msg_show();
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function add_to_cb(icon, t, u, d, tick) {
	data = {"c": "add_to_clipboard", "t": t, "u": u, "d": d, "s": SEARCH_STRING};
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			IB_notify_msg_show();
			$(".added").slideDown(function() {
				$("#OHsearch, #OHclipboard").equalizeCols();
			}); 
			$("#"+tick).addClass("cb-button-tick"); 
		}
	});
}
function remove_from_cb(id) {
	data = {"c": "remove_from_clipboard", "id": id, "s": SEARCH_STRING};
	$.ajax({
		url: "/OcchealthSearch/json/",
		dataType: "json",
		data: data,
		type: "POST",
		success: function(data){
			if(data.Notify) {
				IB_notify_msg(data.Notify);
			}
			$("#CBitem"+id).fadeOut("normal", function() {
				if(!data.count) {
					view_cb();
				}
				else {
					// load in next item in clipboard
					remove_from_cb_get_next(id);
				}
			}); 
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function remove_from_cb_get_next(id) {	
	data = {"c": "get_clipboard_next_item", "id": id, "s": SEARCH_STRING};
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			if(html) { 
				$("#OHclipboard ul.results").append(html).fadeIn();
			}
		}
	});
}
/* Clipboard Note specific functions */
function show_notes_clipboard() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "update_note_clipboard"},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
function save_notes_clipboard() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "update_note_clipboard", "note": $("#NoteInput").val()},
		type: "POST",
		success: function(html){
			$("#CBResultsHolder").html(html);
		}
	});
}
function note_view() {
	$("#cb-note .note").show(); $("#cb-note .note-input").hide();
	$("li#cb-note-view a").addClass('selected');
	$("li#cb-note-edit a").removeClass('selected');	
	$("#OHsearch, #OHclipboard").equalizeCols();
}
function note_edit() {
	$("#cb-note .note-input").show(); $("#cb-note .note").hide();
	$("li#cb-note-edit a").addClass('selected');
	$("li#cb-note-view a").removeClass('selected');
	$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
	$("#OHsearch, #OHclipboard").equalizeCols();
}
function note_close() {
	$("#cb-note").fadeOut();
	view_cb();
}
/* Item Note specific functions */ 
function show_notes_item(id) {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "update_note_item", "id": id},
		type: "POST",
		success: function(html){
			$("#cb-item-note").html(html);
			// position the note container
			pos = $("#CBitem"+id).position();
			$("#cb-item-note").css({ top: pos.top, left: pos.left });
			$("#cb-item-note").slideDown(200, function() {});
		}
	});
	$(".results-pp").fadeOut();
}
function save_notes_item(id) {
	data = {"c": "update_note_item", "id": id, "note": $("#NoteInput").val()};
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#cb-item-note").html(html);
			// position the note container
			pos = $("#CBitem"+id).position();
			$("#cb-item-note").css({ top: pos.top, left: pos.left });
			$("#cb-item-note").slideDown(200);
			// change the icon to selected
			$("#CBitem"+id+" li a.cb-button-note").addClass("cb-button-note-selected");
			$("#CBitem"+id+" li a.cb-button-note").removeClass("cb-button-note");
		}
	});
}
function item_note_view() {
	$("#cb-item-note .note").show(); $("#cb-item-note .note-input").hide();
	$("li#cb-note-item-view a").addClass('selected');
	$("li#cb-note-item-edit a").removeClass('selected');
}
function item_note_edit() {
	$("#cb-item-note .note-input").show(); $("#cb-item-note .note").hide();
	$("li#cb-note-item-edit a").addClass('selected');
	$("li#cb-note-item-view a").removeClass('selected');
	$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
} 
function item_note_close() {
	$("#cb-item-note").fadeOut();
	if($("#NoteInput")) {
		$("#NoteInput").val("");
	}
	$(".results-pp").show();
}
/* Email Clipboard Functionality */
function show_email_clipboard() {
	data = {"c": "email_clipboard" };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
			$("#email-cb-container .button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
function show_email_clipboard_add() {
	html = '<p class="inline"><label>&nbsp;</label> <input type="text" name="to_email[]" /></p>';
	$("#email-multiple").append(html);
	$("#email-cb-container .dropShadow").remove();
	$("#email-cb-container .button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
}
function process_email_clipboard() {
	var data = $("#email-cb-form").serialize();
	if(data !=  undefined) {
		data += "&c=email_clipboard_process";
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#email-cb-container").html(html);
			$("#email-cb-container .button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
function show_email_clipboard_again() {
	data = {"c": "email_clipboard_again" };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#email-cb-container").html(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
/* Print Clipboard Functionality */
function show_print_clipboard() {
	data = {"c": "print_clipboard" };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
			$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
/* Rename Clipboard Functionality */
function rename_cb() {
	data = {"p": "json", "c": "clipboard_rename", "name": $("#CB-name").val() };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "json",
		data: data,
		type: "POST",
		success: function(json){
			if(json.Notify) {
				IB_notify_msg(json.Notify);
				$("#CBRename p.save-name strong").html("&ldquo;"+json.name+"&rdquo;");
				rename_cb_hide();
			}
		}
	});
}
function rename_cb_show() {
	$("#CBRename").hide();
	$("#CBRenameInput").show();
	$(".button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
	$("#CBRenameInput #CB-name").focus();
}
function rename_cb_hide() {
	$("#CBRenameInput").hide();
	$("#CBRename").show();
}
/* Search History */
function clear_search_history() {
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: {"c": "delete_search_history" },
		type: "POST",
		success: function(html){
			tb_remove();
			$("#OHResultsHolder").html(html);
			IB_notify_msg_show();
			$("#OHsearch, #OHclipboard").equalizeCols();
		}
	});
}
/* Email Expert Functionality */
function show_email_expert() {
	data = {"c": "email_expert" };
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			tb_ajax(html);
			$("#email-cb-container .button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}
function process_email_expert() {
	var data = $("#email-cb-form").serialize();
	if(data !=  undefined) {
		data += "&c=email_expert_process";
	}
	$.ajax({
		url: "/OcchealthSearch/",
		dataType: "html",
		data: data,
		type: "POST",
		success: function(html){
			$("#email-cb-container").html(html);
			$("#email-cb-container .button").dropShadow({left: 3, top: 0, opacity: 0.8, blur: 1});
		}
	});
}