
function drh_radio_value(name)
{
	return $("input:radio[name='"+name+"']:checked").val();
}

var pageLoading = 1;

$(document).ready(function(){
	pageLoading = 0;
});

function drh_set_show(object, show)
{
	if ( show )
	{
		if ( pageLoading || jQuery.browser.safari ) {
			object.show();
		} else {
			object.slideDown("slow");
		}
	}
	else
	{
		if ( pageLoading || jQuery.browser.safari ) {
			object.hide();
		} else {
			object.slideUp("slow");
		}
	}
}

function drh_is_array(testme) {
   return ( testme.constructor.toString().indexOf("Array") != -1 );
}

// Returns true if the passed value is found in the
// array.  Returns false if it is not.
Array.prototype.inArray = function (value)
{
	var i;
	for (i=0; i < this.length; i++) {
		// Matches identical (===), not just similar (==).
		if (this[i] === value) {
    			return true;
		}
	}
	return false;
};

function setup_conditional_show_radio(checkboxname, showvalue, divname)
{
	var elements = $("input:radio[name='"+checkboxname+"']");
	var callback = function () {
		var thisValue = drh_radio_value(checkboxname);
		var thisShow = (drh_is_array(showvalue) ? showvalue.inArray(thisValue) : thisValue == showvalue);
		// if ( ! pageLoading ) window.alert("thisValue = "+thisValue+" thisShow="+thisShow+" divname="+divname);
		drh_set_show($("#"+divname), thisShow);
	}

	if ( jQuery.browser.safari ) {
		elements.click(callback);
		callback();
	} else {
		elements.change(callback).change();
	}
}

function setup_conditional_show_select(selectid, showvalues_array, noshowvalues_array, divname)
{
	$("#"+selectid).change(function () {
		var thisValue = $(this).val();
		var thisShow;
		if ( showvalues_array.length ) {
			thisShow = showvalues_array.inArray(thisValue);
		} else {
			thisShow = ! noshowvalues_array.inArray(thisValue);
		}
		drh_set_show($("#"+divname), thisShow);
	})
	.change();
}

