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";
	}
	
	if ( scrollRecalc )
	{
	    previousScrollTop = -1;
	    scrollRecalc();
	    resetSnapY();
	    scrollWindow();
    }
}

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";
	}
}

function wclrToggle( image )	//WebCollapsibleListingRow Toggle
{
    var parNode = image.parentNode;
    
    while ( parNode.nodeName != "TR" && parNode.nodeName != "BODY" )
        parNode = parNode.parentNode;
    
    if ( image.getAttribute( "open" ) )
	{
		image.src = "Images/16x16/ico_plus.gif";
		image.setAttribute( "open", null );
		
		if ( window.createPopup )
		    parNode.nextSibling.style.display = "none";
		else
		    parNode.nextSibling.nextSibling.style.display = "none";
	}
	else
	{
		image.src = "Images/16x16/ico_minus.gif";
		image.setAttribute( "open", true );
		
		if ( window.createPopup )
		    parNode.nextSibling.style.display = "block";
		else
		    parNode.nextSibling.nextSibling.style.display = "table-row";
	}
}

function wclrgToggleAll( headerTrID, isOpening )
{
    var headerTr    = document.getElementById( headerTrID );
    var tbl         = headerTr.parentNode.parentNode;
    var cell;
    var img;
    
    for ( var i = 1; i < tbl.rows.length; i++ )
    {
        cell = tbl.rows[i].cells[0];
        
        if ( cell.childNodes.length == 0 )
            continue;
        
        img = cell.childNodes[0];
        if ( img.nodeType == 1 ) //image
            wclrgToggle( img );
    }
    //alert( tbl.rows[1].cells[0].childNodes[0].nodeType );
}

function wclrgToggle( image, forceSet )	//WebCollapsibleListingRowGroup Toggle
{
    var parNode = image.parentNode;
    
    while ( parNode.nodeName != "TR" && parNode.nodeName != "BODY" )
        parNode = parNode.parentNode;
        
    var gid = "";
    
    if ( window.createPopup )
	    gid = parNode.nextSibling.getAttribute( 'gid' );
	else
	    gid = parNode.nextSibling.nextSibling.getAttribute( 'gid' );
    
    if ( gid == null || gid == undefined )
    {
        alert( "No rows are grouped to expand/contract!" );
        return;
    }
    
    var display     = "";
    var isOpening   = true;
    
    if ( image.getAttribute( "open" ) )
		isOpening   = false;
    if ( forceSet != undefined )
        isOpening = forceSet;
    
    if ( isOpening )
	{
		image.src = "Images/16x16/ico_minus.gif";
		image.setAttribute( "open", true );
		
		if ( window.createPopup )
		    display = "block";
		else
		    display = "table-row";
	}
	else
	{
	    image.src = "Images/16x16/ico_plus.gif";
		image.setAttribute( "open", null );
		
		display = "none";
	}
	
	var nextGID     = gid;
	var workNode    = parNode;
	
	while ( nextGID == gid )
	{
	    if ( window.createPopup )
	        workNode = workNode.nextSibling;
	    else
	        workNode = workNode.nextSibling.nextSibling;
	        
	    if ( workNode == null || workNode == undefined )
	        break;
	    
	    nextGID = workNode.getAttribute( 'gid' );
	    
	    if ( nextGID == null || nextGID == undefined )
	        break;
	        
	    workNode.style.display = display;
	}
}

var skipRecalc = false;
function wclridToggle( image, forceSet )	//WebCollapsibleListingRowID Toggle
{
    var groupid = image.id;
    
    var groups  = eval( groupid + "Groups" );
    var rows    = eval( groupid + "Rows" );
    
    if ( rows == null || rows == undefined )
    {
        alert( "No rows are grouped to expand/contract!" );
        return;
    }
    
    var display = "";
    var isOpening = true;
    
    if ( image.getAttribute( "open" ) )
		isOpening   = false;
    if ( forceSet != undefined )
        isOpening = forceSet;
    
    if ( isOpening )
	{
	    image.src = "Images/16x16/ico_minus.gif";
		image.setAttribute( "open", true );
		
		if ( window.createPopup )
		    display = "block";
		else
		    display = "table-row";
	}
	else
	{
		image.src = "Images/16x16/ico_plus.gif";
		image.setAttribute( "open", null );
		
		display     = "none";
	}
	
	//loop over all the rows
	for ( var i = 0; i < rows.length; i++ )
	    document.getElementById( rows[i] ).style.display = display;
	    
	if ( rows != null && rows != undefined && !isOpening )
    {
        var subImage = null;
        
	    //loop over all the groups
	    for ( var i = 0; i < groups.length; i++ )
	    {
	        subImage = document.getElementById( groups[i] );
	        
	        if ( subImage.getAttribute( "open" ) )
	            wclridToggle( subImage );
	    }
	}

	if ( !skipRecalc )
	{
	    try
	    {
	        scrollRecalc();
	    }
	    catch ( e ) {}
	}
}

function wclridToggleAll( arr, isOpening )
{
    skipRecalc = true;
    for ( var i = 0; i < arr.length; i++ )
        wclridToggle( document.getElementById( arr[i] ), isOpening );
    skipRecalc = false;
    
    try
    {
        scrollRecalc();
    }
    catch ( e ) {}
}

//
//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
//

//
//END New Listbox handling
//
function lstClick( evt )
{
    if ( evt == null ) evt = event;
    var tgt = getEventTarget( evt );
    
    var listBox     = tgt.parentNode;
    var listBoxHid  = document.getElementById( listBox.getAttribute('id').substring( 4 ) );
    var oldOption   = findSelectedListOptionWithBox( listBox );
    var newValue    = tgt.getAttribute( 'va' );
    
    if ( newValue == null )
        return;
    
    if ( oldOption == tgt )
        return;

    listBoxHid.value    = newValue;
    
    if ( oldOption != tgt )
    {
        if ( oldOption != null )
        {
            if ( oldOption.className == 'sel' )
                oldOption.className = '';
            else
                oldOption.className = oldOption.className.replace( 'sel ', '' );
        }
        tgt.className = 'sel ' + tgt.className;
    }
}

function lstKD( evt )
{
    if ( evt == null ) evt = event;
    var tgt = getEventTarget( evt );
    
    var isUp        = ( evt.keyCode == 38 );
    var isDown      = ( evt.keyCode == 40 );
    var isPgUp      = ( evt.keyCode == 33 );
    var isPgDown    = ( evt.keyCode == 34 );
    
    if ( !isUp && !isDown && !isPgUp && !isPgDown )
        return;
    
    if ( tgt.className.indexOf( 'lst' ) < 0 )
        tgt = tgt.parentNode;
    
    var listBox     = tgt;
    var listBoxHid  = document.getElementById( listBox.getAttribute('id').substring( 4 ) );
    var oldOption   = findSelectedListOptionWithBox( listBox );
    var newOption   = null;
    
    if ( isUp )
    {
        if ( oldOption == null )
            newOption = listBox.lastChild;
        else
            newOption = oldOption.previousSibling;
        
        if ( newOption != null && newOption.nodeType == 3 ) //text
            newOption = newOption.previousSibling;
    }
    else if ( isDown )
    {
        if ( oldOption == null )
            newOption = listBox.firstChild;
        else
            newOption = oldOption.nextSibling;
        
        if ( newOption != null && newOption.nodeType == 3 ) //text
            newOption = newOption.nextSibling;
    }
    else //paging
    {
        var numberToTravel  = ( listBox.offsetHeight / 16 ) - 1;
        var travelOption    = oldOption;
        
        if ( travelOption == null )
        {
            if ( isPgUp )
                travelOption = listBox.lastChild;
            else
                travelOption = listBox.firstChild;
                
            newOption = travelOption;
        }
        
        while ( numberToTravel >= 1 )
        {
            if ( isPgUp )
                travelOption = travelOption.previousSibling;
            else
                travelOption = travelOption.nextSibling;
            
            if ( travelOption == null )
                break;   
            if ( travelOption.nodeType == 3 ) //text
                continue;
                
            newOption = travelOption;
            numberToTravel--;
        }
    }
    
    if ( newOption != null )
    {
        var newValue        = newOption.getAttribute( 'va' );
        listBoxHid.value    = newValue;
        
        if ( oldOption != null )
        {
            if ( oldOption.className == 'sel' )
                oldOption.className = '';
            else
                oldOption.className = oldOption.className.replace( 'sel ', '' );
        }
        newOption.className = 'sel ' + newOption.className;
        
        newOption.scrollIntoView( false );
    }
    
    evt.cancelBubble    = true;
    evt.returnValue     = false;
    return false;
}

function findListOptionByValue( listbox, srcVal )
{
    srcVal      = srcVal.toString();
    var options = listbox.childNodes;
    var optLen  = options.length;
    
    for ( var i = 0; i < optLen; i++ )
    {
        if ( options[i].nodeType == 3 ) //text
            continue;
        if ( options[i].getAttribute('va').toString() == srcVal )
            return options[i];
    }
    
    return null;
}

function findSelectedListOption( listboxID )
{
    return findSelectedListOptionWithBox( document.getElementById( 'lst+' + listboxID ) );
}

function findSelectedListOptionWithBox( listbox )
{
    var options = listbox.childNodes;
    var optLen  = options.length;
    
    for ( var i = 0; i < optLen; i++ )
    {
        if ( options[i].nodeType == 3 ) //text
            continue;
        if ( options[i].className.indexOf( 'sel' ) >= 0 )
            return options[i];
    }
    
    return null;
}

function fxLV( listboxID ) //fixListboxValue
{
    var listbox         = document.getElementById( 'lst+' + listboxID );
    var listboxHid      = document.getElementById( listboxID );
    
    if ( listbox == null )
        return;
        
    var selectOption    = findSelectedListOptionWithBox( listbox );
    
    if ( selectOption == null )
    {
        listboxHid.value = "";
        return;
    }
    
    var selectValue     = selectOption.getAttribute('va');
    
    if ( selectValue != listboxHid.getAttribute( 'value' ) )
        listboxHid.value = selectValue;
     
    selectOption.scrollIntoView( false );
}
//
//END New Listbox 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 );
}