/**
 * RBPLUS Theme JS
 */

/**
 * Loads the ICD-9 CrossLink FLEX Tool in an overlay.
 *		Requires jQuery.
 */
function loadICD9CrossLink () {
	// Load the overlay.
	$('#icd9crosslink').overlay().load();
}

/**
 * Code Lookup FLEX Tool Callback scrolls to dynamic content and gets CLIA data.
 *		Requires jQuery.
 *
 * @param	string	code	The callback result.  This is either a single value 'code' or a CSV [0=>call, 1=>cptcode, 2=>cptcodeid]
 */
function codePicked (code) {
	var code_arr	= code.split(",");
	var call 		= "";
	var cptcode		= "";
	var cptcodeid	= "";
	var description = "";
    try {
        jQuery("#view_guest_codes").overlay().close();
    } catch( ex ) {};
	if (code_arr.length > 1) {
		// Callback returns CSV string.
		call		= code_arr[0];
		cptcode		= code_arr[1];
		cptcodeid	= code_arr[2];
        if( call.indexOf("cci") == -1 && typeof( ON_GUEST_LANDING) == "undefined" && typeof( G_GUEST_CPT_CODES ) != "undefined" ) {
            if( jQuery.inArray( cptcode, G_GUEST_CPT_CODES ) == -1  ) {
                //alert( "not_in_selected_codes");
                var html_tmp = '<ul class="guest_codes">';
                for( var i = 0; i < G_GUEST_CPT_CODES.length; i++ ) {
                    html_tmp += '<li><a href="javascript:void(0);" onclick="codePicked(\'' + call + ',' + G_GUEST_CPT_CODES[i] + ',' + G_GUEST_CPT_IDS[i] + '\');">' + G_GUEST_CPT_CODES[i] + '</a></li>';
                }
                html_tmp += "</ul>";
                jQuery("#guest_codes").empty();
                jQuery("#guest_codes").html( html_tmp );
                jQuery("#view_guest_codes").overlay({
                    api		: true,
                    fixed	: false,
                    top		: 240
                }).load();
                return false;
            }
        }

		switch (call) {
			case "clia": {
                $.scrollTo($('#maincontent'), 600, {axis: 'y'});
				$('#cptcodeid').val(cptcodeid);
				getCLIAData(cptcode);
				break;
			}

			case "cpt": {
				getCPTData(cptcodeid, cptcode);
				break;
			}

			case "dme": {
                $.scrollTo($('#maincontent'), 600, {axis: 'y'});
				getDMEData(cptcode);
				break;
			}

            case "lcd": {
                setLcdCode( cptcode );
                break;
            }

            case "cci":
            case "cci1": {
                setCCICode( cptcode );
                break;
            }

			default:
				alert("Call '" + call + "' is invalid.");
		}
	} else {
		// Callback returns a single value.
		// cptcode = code_arr[0];
	}
}

/**
 * Toggles interlink element classes according to status code.  Removes 'loading' class.
 * 		Requires jQuery.
 *
 * @param	element		The element to toggle.
 * @param	status		The status code [1 (on), 0 (off), -1 (empty), default (loading)].
 */
function toggleInterlink (element, status) {
	$(element).removeClass("loading on off empty");

	if (jQuery) {
		switch (status) {
			case "1": {
				// On.
				$(element).addClass("on");

				break;
			}

			case "0": {
				// Off.
				$(element).addClass("off");

				break;
			}

			case "-1": {
				// Empty.
				$(element).addClass("empty");
				$(element).html('');

				break;
			}

			default:
				$(element).addClass("loading");
				$(element).html('Searching...');
		}
	}
}

/**
 * Clears the interlinks and sets status to empty.
 *		Requires jQuery.
 */
function clearInterlinks () {
	// The interlinks.
	var interlinks = $('#interlinks .productBarInput');

	// Clear html.
	interlinks.html('');

	// Toggle empty class.
	toggleInterlink(interlinks, '-1');
}

/**
 * Opens a url in a popup window.
 */
function openURL(url){
	var popup = window.open(url,"Popup","width=790,height=590,resizable=1,scrollbars=1");
}

/**
 * Changes cursor style to "pointer".
 */
function cursorHand () {
	document.body.style.cursor = "pointer";
}

/**
 * Changes cursor style to "default".
 */
function cursorDefault () {
	document.body.style.cursor = "default";
}

/**
 * Loads content into the help popup iframe.
 *		Requires jQuery.
 */
/* Replace with overlay
function popHelp (item) {
	jsTargString = "http://www.reimbursementplus.com/popHelp.cfm?hi=" + item;
	$('#help_popup').css('left', ($(window).width() - $('#help_popup').outerWidth()) / 2+$(window).scrollLeft() + "px");
	$('#help_popup iframe').attr('src', jsTargString);
}

// Shows the help popup.
function showHelp () {
	document.getElementById("help_popup").style.visibility = "visible";
}

// Closes the help popup.
function closeHelp () {
	document.getElementById("help_popup").style.visibility = "hidden";
}
*/
