/*	Used in conjunction with getViaJQ.asp file
'
'		FUNCTIONS
'		(".dropdown").change - Calls a function to automatically populate another dropdown item based on the selection made
'
*/

function showLoaderGraphic(thisID) {
		jQuery("#loadingGIF").removeClass("hidden");
		$("#loadingGIF ~ input").remove();
	}


jQuery(document).ready( function () {
	
	//If a .dropdown type element is clicked, this function runs to determine what sub-options should be visible
	jQuery(".dropdown").change( function() {
		var thisID = jQuery(this).attr("id");									//Calling Dropdown Id (Name)
		var parentOptName = jQuery(this).attr("value");				//Calling Dropdown Value
		var thisRegID = jQuery("#mod_reg_id").attr("value");	//Reg_Id

		if (parentOptName != undefined) {		
			jQuery.get("lib/getViaJQ.asp", {'dataQueryType':'reg_sub_option', 'parentName':thisID,'parentOptName':parentOptName, 'reg_id':thisRegID}, 
			function(data){
				//If no errors were sent back, then this is a valid parent dropdown making the call
				if (jQuery(data).find("error").text() == "none") {
					var elementName = "#" + jQuery(data).find("valid_element").text();
					var vOptions = jQuery(data).find("valid_option").text();
					var optionNames = new Array();
					optionNames = vOptions.split("|");
					//First, make all children hidden				// use disabled
					jQuery(elementName).children().addClass("hidden").attr("disabled","disabled");
					//Then only show the valid children
					for (j = 0; j < optionNames.length; j++){	jQuery(elementName).children('option[value='+optionNames[j]+']').removeClass("hidden").removeAttr("disabled");}
					jQuery(elementName+' > option:first-child').focus().attr("selected", "selected");			//+' > option:first-child'
				}
			});
		}
		else {
			jQuery.get("lib/getViaJQ.asp", {'dataQueryType':'reset_sub_option','parentName':thisID,'reg_id':thisRegID}, 
				function(data){
					var elementName = "#" + jQuery(data).find("valid_element").text();
					jQuery(elementName).children().addClass("hidden").attr("disabled","disabled");
					jQuery(elementName+' > option:first-child').attr("selected", "selected");
				});
		} //End IF
		return false;
	});
});	

/*// BELOW IS CODE to use, if showing/hiding areas, such as when doing a 'review' page on a registrations
	// Show the Submit button, and get the person to review their registration
	jQuery("#reviewLink").click( function() {
		jQuery("#reviewRegMessage").hide(500);
		jQuery("#reviewText").show(1000);
		jQuery("#sel_crm_sales").focus();
		return false;
	});
*/
