function showWait()
{
	document.body.style.cursor = 'wait';
	var links = document.links;
	for ( var i = 0; i < links.length; i++ )
	{
		links[i].style.cursor = 'wait';
	}
}

function imgPress( evt ) //check for spacebar on checkbox and radio button images
{
    if ( testKeyCode( evt, 32 ) )
	{
		evt.returnValue = false;
		tgt = getEventTarget( evt );
		clickElement( tgt );
	}
}

function wcsToggle( image )	//WebcollapsibleSection Toggle
{
	if ( image.getAttribute( "open" ) )
	{
		image.src = "Images/16x16/ico_plus.gif";
		image.setAttribute( "open", null );
		image.parentNode.parentNode.lastChild.style.display = "none";
	}
	else
	{
		image.src = "Images/16x16/ico_minus.gif";
		image.setAttribute( "open", true );
		image.parentNode.parentNode.lastChild.style.display = "block";
	}
}

function wcpaToggle( image )	//Collapsible WebPanel Toggle
{
    var pnlMR = document.getElementById( "pnlMR" + image.getAttribute( "pnlMR" ) );
    
    if ( image.getAttribute( "open" ) )
	{
		image.src = "Images/13x13/ico_plus.gif";
		image.setAttribute( "open", null );
		pnlMR.style.display = "none";
	}
	else
	{
	    image.src = "Images/13x13/ico_minus.gif";
		image.setAttribute( "open", true );
		pnlMR.style.display = "inline";
	}
}

//
//START Radio Buttons
//
function rbClick( evt ) 
{
	if (!evt) evt = window.event;
		tgt = getEventTarget( evt );
		
	var imgEl	= tgt;
	var hidEl	= document.getElementById( imgEl.getAttribute('name').substring( 2 ) );
	
	if ( hidEl.disabled )
		return;
	
	var oldVal = hidEl.getAttribute('value');
	var newVal = imgEl.getAttribute('value');
	
	setAttribute( hidEl, 'nsel', imgEl.getAttribute('id') );
	setAttribute( hidEl, 'value', newVal );
}

function rbChanged()
{
	if ( lastAttName == "disabled" ) //disabling
	{
		rbDisabledChanged( lastAttEl );
		return;
	}
	else if ( lastAttName != "value" ) //value changes
		return;
	
	var hidEl	= lastAttEl;
	var oldEl	= null;
	var newEl	= null;
	var sel		= hidEl.getAttribute('sel');
	var nsel	= hidEl.getAttribute('nsel');
	
	if ( sel != "" )
		oldEl	= document.getElementById( sel );
	if ( nsel != "" )
		newEl	= document.getElementById( nsel );
		
	hidEl.setAttribute( 'sel', nsel );
	
	if ( oldEl != null )
	{
		if ( hidEl.disabled )
			oldEl.src = 'images/16x16/crtl_radiobutton_dis.gif';
		else
			oldEl.src = 'images/16x16/crtl_radiobutton.gif';
	}
	
	if ( newEl != null )
	{
		if ( hidEl.disabled )
			newEl.src = 'images/16x16/crtl_radiobutton_chk_dis.gif';
		else
			newEl.src = 'images/16x16/crtl_radiobutton_chk.gif';
	}
	else
		rbSelFromValue( hidEl );
		
	var och = hidEl.getAttribute( 'och' );
	
	if ( och != undefined && och != null )
	    eval( och );
}

function rbDisabledChanged( hidEl )
{
	hidEl.disabled	= lastAttVal;
	var isDisabled	= hidEl.disabled;
	var sel			= hidEl.getAttribute('sel');
	var rbImgs		= document.getElementsByName( 'i-' + hidEl.getAttribute('name') );

	var rbImg;
	for ( var i = 0; i < rbImgs.length; i++ )
	{
		rbImg = rbImgs[i];
		
		if ( isDisabled )
		{
			rbImg.tabIndex = -1;
			
			if( rbImg.id == sel ) 
				rbImg.src = 'images/16x16/crtl_radiobutton_chk_dis.gif';  
			else 
				rbImg.src = 'images/16x16/crtl_radiobutton_dis.gif';
		}
		else
		{
			rbImg.tabIndex = 0;
			
			if( rbImg.id == sel ) 
				rbImg.src = 'images/16x16/crtl_radiobutton_chk.gif';  
			else 
				rbImg.src = 'images/16x16/crtl_radiobutton.gif';
		}
	}
}

function rbSelFromValue( hidEl )
{
    var rbImgs	= document.getElementsByName( 'i-' + hidEl.getAttribute('name') );
	var hidVal	= hidEl.getAttribute('value');
	var rbVal;
	
	var rbImg;
	for ( var i = 0; i < rbImgs.length; i++ )
	{
		rbImg	= rbImgs[i];
		rbVal	= rbImg.getAttribute('value');
		
		if ( rbVal == hidVal )
		{
			if( hidEl.disabled ) 
				rbImg.src = 'images/16x16/crtl_radiobutton_chk_dis.gif';  
			else 
				rbImg.src = 'images/16x16/crtl_radiobutton_chk.gif';
				
			hidEl.setAttribute( 'sel', rbImg.getAttribute('id') );
			break;
		}
	}
}

var wasNSelLast = false;
function rbPC() //propertychanged - used to fix back-button bug in IE
{
    if ( event.propertyName != "value" )
    {
        wasNSelLast = ( event.propertyName == "nsel" );
        return;
    }
    
    if ( wasNSelLast )
        return;
        
    tgt         = getEventTarget( event );
    wasNSelLast = false;
    
    var rbImg = document.getElementById( tgt.getAttribute('sel') );
    if( tgt.disabled ) 
		rbImg.src = 'images/16x16/crtl_radiobutton_dis.gif';  
	else 
		rbImg.src = 'images/16x16/crtl_radiobutton.gif';
    rbSelFromValue( tgt );
}

//
//END Radio Buttons
//

//
//START Checkbox lists
//
function ccLi( evt ) //checkClick for lists
{ 
    if (!evt) evt = window.event;
	tgt = getEventTarget( evt );
		
	var imgEl	= tgt;
	var checkEl = imgEl.nextSibling;
	
	ccLiClick( checkEl );
}

function ccLiClick( checkEl )
{
	if( checkEl.getAttribute('cdis') == 1 ) //disabled
		return;
		
	var imgEl = checkEl.previousSibling;
	
	if ( checkEl.getAttribute('chk') == 1 )
		setAttribute( checkEl, 'chk', 0 );
	else
		setAttribute( checkEl, 'chk', 1 );
		
	if ( checkEl.getAttribute('chk') == 1 )
		setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk.gif' );
	else 
		setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox.gif' );
	
	//if the current check state is the same as the starting check state,
	//don't send it back to the database with the form	
	if ( checkEl.getAttribute('chk') == checkEl.getAttribute('schk') || checkEl.getAttribute('cdis') == 1 )
		checkEl.disabled = true;
	else
		checkEl.disabled = false;	
}

function ccLiSetDisable( checkEl, isDisabled ) //equivalent of checkEl.disabled = isDisabled
{
	var imgEl = checkEl.previousSibling;
	
	if( isDisabled )
		setAttribute( checkEl, 'cdis', 1 );
	else
		setAttribute( checkEl, 'cdis', 0 );
		
	if( checkEl.getAttribute('cdis') == 1 )
	{
		setAttribute( imgEl, 'tabIndex', -1 );
		
		if ( checkEl.getAttribute('chk') == 1 )
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk_dis.gif' );
		else
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_dis.gif' );
	}
	else
	{
		setAttribute( imgEl, 'tabIndex', 0 );
		
		if ( checkEl.getAttribute('chk') == 1 )
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk.gif' );
		else
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox.gif' );
	}
	
	//if the current check state is the same as the starting check state,
	//don't send it back to the database with the form	
	if ( checkEl.getAttribute('chk') == checkEl.getAttribute('schk') || checkEl.getAttribute('cdis') == 1 )
		setAttribute( checkEl, 'disabled', true );
	else
		setAttribute( checkEl, 'disabled', false );
}
//
//END Checkbox lists
//

//
//START New Checkbox handling
//
function ncLi( evt ) //new checkClick
{ 
	if (!evt) evt = window.event;
		tgt = getEventTarget( evt );
	
	var imgEl	= tgt;
	var checkEl = imgEl.nextSibling;
	
	if( checkEl.disabled )
		return;
	
	ncLiClick( checkEl );
}

function ncLiClick( checkEl ) //equivalent of checkEl.click()
{
	if( checkEl.disabled ) //disabled
		return;
		
	var imgEl = checkEl.previousSibling;
	
	if ( checkEl.value == 1 ) //checked
		checkEl.value = 0;
	else
		checkEl.value = 1;
		
	if ( checkEl.value == 1 ) //checked
		setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk.gif' );
	else
		setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox.gif' );
}

function ncLiSetDisable( checkEl, isDisabled ) //equivalent of checkEl.disabled = isDisabled
{
	var imgEl = checkEl.previousSibling;
	
	if( isDisabled )
		checkEl.disabled = true;
	else
		checkEl.disabled = false;
		
	if( checkEl.disabled )
	{
		setAttribute( imgEl, 'tabIndex', -1 );
		
		if ( checkEl.value == 1 ) //checked
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk_dis.gif' );
		else 
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_dis.gif' );
	}
	else
	{
		setAttribute( imgEl, 'tabIndex', 0 );
		
		if ( checkEl.value == 1 ) //checked
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox_chk.gif' );
		else 
			setAttribute( imgEl, 'src', 'images/16x16/crtl_checkbox.gif' );
	}
}
//
//END New Checkbox handling
//

var lastAttEl	= null;
var lastAttName = null;
var lastAttVal	= null;

function setAttribute( el, attName, attVal ) 
{
    el.setAttribute( attName, attVal );
	
	var elOnPC = el.getAttribute( 'onPC' );
	
	if ( elOnPC == null || elOnPC == "" )
		return;
		
	lastAttEl	= el;
	lastAttName = attName;
	lastAttVal	= attVal;
	
	eval( elOnPC );
}
