/*******************************************************************************
* +--------------------------[ File Revision Info ]--------------------------+ *
* | $Revision::                                                           $: | *
* | $Date::                                                               $: | *
* | $Author::                                                             $: | *
* +--------------------------------------------------------------------------+ *
* | $Id::                                                                 $: | *
* +--------------------------------------------------------------------------+ *
*******************************************************************************/

/************************* JQUERY ONLOAD ACTIONS *****************************/
var $jQ = jQuery.noConflict();

jQuery(document).ready(function() {
 	   
    var bindDomainBehaviors = function(scope) {
		
		// DOMAIN SELECT CLICK - CHANGE DOMAINS AND UPDATE ORG LIST
		$jQ('#domainID').change(function(){
		    updateOrgList($jQ(this).attr("value"));
		});	
    }
    
	$jQ('#orgAdminBtn').click(function()
	{
		if ($jQ('#orgAdminID').attr("disabled")) {
			$jQ('#orgAdminID').attr("disabled", "");
		} else {
			$jQ('#orgAdminID').attr("disabled", "disabled");
			$jQ('#orgAdminID').val('');
		}
	});
	
	// Now bind the Events
	bindDomainBehaviors();
});


/********************** DYNAMIC DATA FUNCTIONS **********************/

function updateOrgList(domainID) 
{
	$jQ.getJSON("../../includes/ajax/org-list.php",{ domainID: domainID, ajax: 'true'}, function(j)
	{
	    $jQ('#orgID').removeOption(/./).addOption('', 'Please select one:');

		for (var i = 0; i < j.length; i++) {
			$jQ("#orgID").addOption(j[i].orgValue, j[i].orgDisplay);
		}
		
		$jQ('#orgID option:first').attr('selected', 'selected');
	});
}



