// This is DlgBase3D.js - Support for the 3D user interface elements
// 
// The following functions provide support for a system of 3D buttons.  They are
// all somewhat dependent up the dlgBase Functions
//
//  3D Check and Radio Button support is provided by creating 2 fields for each button
//  the first field is a displayed link, and the second field contains a hidden input
//  field of the value of the CheckBox.  The link field must be name Base_check and the
//	input field must be named Base_hid.  Refer to SetCheck3D to see the class names
//  used to simulate the check box in the link field.
//
//  ToggleRadio3DButton(BaseName)
//		Will toggle a radio button and if it is toggled on, it will then 
//		determine of the button is part of a group and if so, it will turn off
//		all of the other members of the group.
//  SetCheck3D(BaseName,iValue)
//		Will set the 3D check button identified by Base name to either checked or 
//		unchecked.  iValue should be either 1 or 0
//  SetRadio3DGroup(Array)
//		Add the base names contained in Array to the list of 3D button groups.  The
//		group arrays will then be scanned when ToggleRadio3DButton is called.
//  AddCheckBoxBuddy(BaseName,inputField)
//		Check BaseName_hid and if it is zero inactivate the associated input field
//  SetAllCheckBoxBuddies()
//		Go through the buddy list and enable or disable the input fields as needed
//  SetCheckBoxBuddy(BaseName,iField=null)
//		Check a single check box and enable/disable its buddy
//
function DlgBase3D_ToggleRadio3DButton(bName)
{
	var fHidden=FormObj(bName+"_hid");
	var fBox=FormObj(bName+"_check");
	if( (fHidden==null) || (fBox==null) ) return(false);
	var iVal=(fHidden.value==0) ? 1:0;
	this.SetCheck3D(bName,iVal);
// Now find out if this button is a member of a group, and if so turn off
// all of the other members in the group.	
	var nGroups=this.Radio3DGroups.length;
	if( nGroups==0 ) return(false);	
	for( var iGroup=0; iGroup< nGroups;	iGroup++){
		var eArray=this.Radio3DGroups[iGroup];
		var eCount=eArray.length;
		for( var iElem=0; iElem< eCount; iElem++){
			if( bName!==eArray[iElem] ) continue;
			for( var i=0; i< eCount; i++){
				if( bName===eArray[i] ) continue;
				this.SetCheck3D(eArray[i],0);
			}
			return( false);
		} // next iElem
	}
	return(false);
}

function DlgBase3D_SetCheck3D(bName,iValue)
{
	var fHidden=FormObj(bName+"_hid");
	var fBox=FormObj(bName+"_check");
	if( (fHidden==null) || (fBox==null) ) return(false);
	fHidden.value=iValue;
	if( iValue==0 ) fBox.className="CheckBlue18";
	else fBox.className="CheckedBlue18";
	this.SetCheckBoxBuddy(bName);
	return( false);
}

function DlgBase3D_SetRadio3DGroup(sArray)
{
	var k=this.Radio3DGroups.length;
	this.Radio3DGroups[k]=sArray;
}

function DlgBase3D_AddCheckBoxBuddy(BaseName,inputField)
{
	var k=this.CheckBuddies.length;
	this.CheckBuddies[k]=Array(BaseName,inputField);
}

function DlgBase3D_SetAllCheckBoxBuddies(){ // This would normally be called from on load
	var k=this.CheckBuddies.length;
	for( var i=0; i< k; i++){
		var bArray=this.CheckBuddies[i];
		 this.SetCheckBoxBuddy(bArray[0],bArray[1]); 
	} // next buddy
}

function DlgBase3D_SetCheckBoxBuddy(BaseName,iField)
{
	var iTarget=null;
	if( arguments.length<2 ){  // see if BaseName is in the list or not
		var k=this.CheckBuddies.length;
		for( var i=0; i< k; i++){
			var bArray=this.CheckBuddies[i];
			if( BaseName==bArray[0] ){ iTarget=bArray[1]; break; }
		} // next buddy
	} else iTarget=iField; // End of checking for iField
	if( iTarget==null ) return;
// Step 1 is to see if the base name hidden field exists or not
	var pHid=document.getElementById(BaseName+"_hid");
	if( pHid==null ) return;		// Shouldn't happen
	var pField=document.getElementById(iTarget);
	var pLabel=document.getElementById(iTarget+"_label");
	if( pField==null ) return;		// Will happen often
	if( pHid.value==1 ){ // Enable the field
		pField.disabled=false;
		if( pLabel!=null ){
//			pLabel.style.fontStyle='normal';
			pLabel.style.color='black';
			}
	} else{ // Disable the field
		pField.disabled=true;
		if( pLabel!=null ){
//			pLabel.style.fontStyle='italic'; // Internet Explorer didn't like this
			pLabel.style.color='#a0a0a0';
			}
	}
}

function DlgBase3D_Enable3DButton(Name,Status,fColor,fSize)
{
	if( arguments.length != 4) return;
	var Field=document.getElementById(Name);
	if( Field == null ) return;
	var sClass;
	if( Status ) sClass="Std"+fColor+"Button"+fSize;
	else sClass="Std"+fColor+"Label"+fSize;
	Field.className=sClass;
}

function DlgBase3D(bIsConstructor)
{
	if( arguments.length>0 ) return;		// Bail if this is the very first constructor
	this.Radio3DGroups=Array();
	this.CheckBuddies=Array();
}


new DlgBase3D(true);

DlgBase3D.prototype=new dlgBase();
DlgBase3D.prototype.constructor=DlgBase3D;
DlgBase3D.prototype.ToggleRadio3DButton=DlgBase3D_ToggleRadio3DButton;
DlgBase3D.prototype.SetCheck3D=DlgBase3D_SetCheck3D;
DlgBase3D.prototype.SetRadio3DGroup=DlgBase3D_SetRadio3DGroup;
DlgBase3D.prototype.AddCheckBoxBuddy=DlgBase3D_AddCheckBoxBuddy;
DlgBase3D.prototype.SetAllCheckBoxBuddies=DlgBase3D_SetAllCheckBoxBuddies;
DlgBase3D.prototype.SetCheckBoxBuddy=DlgBase3D_SetCheckBoxBuddy;
DlgBase3D.prototype.Enable3DButton=DlgBase3D_Enable3DButton;
