 // These two lines are used for the HTMLArea DHTML
 _editor_url = "/htmlarea/";
 _editor_lang = "en";
	   
/**
 * This is an array of functions that should be called
 * during the onload event.  Pages should call registerOnLoadEvent()
 * to add to the array
 */
var onLoadEventFunctions = new Array();

function dsRegisterOnLoadEvent( functionName )
{
	onLoadEventFunctions[ onLoadEventFunctions.length ] = functionName;
}

function onLoadEvent()
{
	for ( var i = 0; i < onLoadEventFunctions.length; i++ )
	{
		eval( onLoadEventFunctions[i] );
	}
}


/**
 * Hide an HTML element
 */
function dsHideElement( elemId )
{
	var e = document.getElementById( elemId );
	
	e.style.display = 'none';
	e.style.visibility = 'hidden';
}

/**
 * Show an HTML element
 */
function dsShowElement( elemId )
{
	var e = document.getElementById( elemId );
	
	e.style.display = 'block';
	e.style.visibility = 'visible';
}


// Count the number of selected items in a SELECT control
// or series of checkboxes.
function dsCountSelected( aCtrl ) 
{
	if ( aCtrl == null )
		return 0;
		
	if ( aCtrl.length == null ) {
		return ( aCtrl.checked || aCtrl.selected ) ? 1 : 0;
	} else {
		var count = 0;
		for ( var i = 0; i < aCtrl.length; i++ )
			count += (( aCtrl[i].checked || aCtrl[i].selected ) ? 1 : 0);
		return count;
	}
}

// Move all selected options from one SELECT tag
// to another SELECT tag.
function dsMoveSelected( fromCtrl, toCtrl )
{
	var i = fromCtrl.length;
	var x = toCtrl.length;
			
	for ( n = (i-1); n >= 0; n-- )
	{
		if ( fromCtrl[n].selected )
		{
			toCtrl.length = (x + 1);
			toCtrl[x].text = fromCtrl[n].text;
			toCtrl[x].value = fromCtrl[n].value;
			toCtrl[x].selected = true;
			fromCtrl[n] = null;
			x = x + 1;
		}
	}
}

// Remove all selected options from the 
// SELECT tag.
function dsRemoveSelected( fromCtrl )
{
	var i = fromCtrl.length;

	for ( n = (i-1); n >= 0; n-- )
	{
		if ( fromCtrl[n].selected )
		{
			fromCtrl[n] = null;
		}
	}
}

// Move selected options up in the 
// SELECT tag.
function dsMoveSelectedUp( ctrl )
{
	var i = ctrl.length;

	for ( n = 0; n < i; n++ )
	{
		if ( ctrl[n].selected && n > 0 )
		{
			t = ctrl[n-1].text;
			v = ctrl[n-1].value;
			
			ctrl[n-1].text  = ctrl[n].text;
			ctrl[n-1].value = ctrl[n].value;
			ctrl[n-1].selected = true;
			
			ctrl[n].text = t;
			ctrl[n].value = v;
			ctrl[n].selected = false;
		}
	}
}

// Move selected options down in the 
// SELECT tag.
function dsMoveSelectedDown( ctrl )
{
	var i = ctrl.length - 1;

	for ( n = i; n >= 0; n-- )
	{
		if ( ctrl[n].selected && n != i )
		{
			t = ctrl[n+1].text;
			v = ctrl[n+1].value;
			
			ctrl[n+1].text  = ctrl[n].text;
			ctrl[n+1].value = ctrl[n].value;
			ctrl[n+1].selected = true;
			
			ctrl[n].text = t;
			ctrl[n].value = v;
			ctrl[n].selected = false;
		}
	}
}

// Add a new option to the select control
function dsAddSelectOption( toCtrl, value, text, selectIt )
{
	var x = toCtrl.length;
	
	toCtrl.length = (x + 1);

	toCtrl[x].text = text
	toCtrl[x].value = value;
	toCtrl[x].selected = selectIt;
}

// Count the number of selected items in a SELECT control
// or series of checkboxes.
function dsSelectWithValue( aCtrl, aValue ) 
{
	if ( aCtrl == null )
		return 0;
		
	if ( aCtrl.length == null ) {
		return 0;
	} else {
		var count = 0;
		for ( var i = 0; i < aCtrl.length; i++ )
		{
			if ( aCtrl[i].value == aValue )
			{
				aCtrl[i].selected = true;
				count++;
			}
		}
		return count;
	}
}

// Select or deselect all options in a SELECT control
// based on value of trueOrFalse		
function dsSelectAll( ctrl, trueOrFalse )
{
	var n = ctrl.length;
			
	for ( i = 0; i < n; i++ )
	{
		ctrl[i].selected = trueOrFalse;
	}
			
	return true;
}

/**
 * Check all checkboxes
 */
function dsCheckAll( ctrl, trueOrFalse )
{

	var n = ctrl.length;

	if ( n == null )
	{
		ctrl.checked = trueOrFalse;
	}
	else
	{
		for ( i = 0; i < n; i++ )
		{
			ctrl[i].checked = trueOrFalse;
		}
	}
}

/**
 * Count all Checked checkboxes
 */
function dsCountChecked( ctrl )
{
	var n = ctrl.length;
	var c = 0;
	
	if ( n == null )
	{
		if ( ctrl.checked ) 
		{
			c = 1;
		}
	}
	else
	{
		for ( i = 0; i < n; i++ )
		{
			if ( ctrl[i].checked )
			{
				c += 1;
			}
		}
	}
	
	return c;
}

/**
 * Do nothing
 */
function noop() {}

/**
 *	Standards Compliant Rollover Script
 *	Author : Daniel Nolan
 *	http://www.bleedingego.co.uk/webdev.php
 */
function dsInitRollovers() 
{
	if (!document.getElementById) return;
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) 
	{		
		if (aImages[i].className == 'imgover') 
		{
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_o'+ftype);

			aImages[i].setAttribute('hsrc', hsrc);
			
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			aImages[i].onmouseover = function() 
			{
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			aImages[i].onmouseout = function() 
			{
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_o'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}


/**
 * Function to bust out of frames.
 * Frame Buster - code by Gordon McComb
 */
function dsBustFrames() 
{
	if (self.parent.frames.length != 0)
	{
		self.parent.location=document.location;
	}
}


/**
 * Open a standard popup window using provided settings
 */
function dsOpenPopupWindow(url, windowName, settings) 
{
	if ( settings == null )
	{
		settings = 'toolbar=no,status=no,scrollbars=yes,resizable=yes,width=400,height=400';
	}
	return window.open(url, windowName, settings);
}

 
/**
 * Open a popup window centered on the screen
 */
function dsOpenCenteredPopupWindow(url, windowName, windowWidth, windowHeight, settings ) 
{
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;

	if ( settings == null )
	{
		settings = 'toolbar=no,status=no,scrollbars=yes,resizable=yes';
	}

	settings = settings + ",width=" + windowWidth + ",height=" + windowHeight + ",top=" + windowY + ",left=" + windowX;

	return window.open(url, windowName, settings);
}

/**
 * Get width of a window
 */
function dsGetWindowWidth()
{
    return document.body.clientWidth;
}

/**
 * Get width of a window
 */
function dsGetWindowHeight()
{
    return document.body.clientHeight;
}

/**
 * Center an element on the page (should be a floating element with 
 * a z-position)
 */
function dsCenterElement( elemId, eWidth, eHeight )
{
	var x = (dsGetWindowWidth() - eWidth) / 2;
	var y = (dsGetWindowHeight() - eHeight) / 2;

	var e = document.getElementById(elemId);

	e.style.left = x + 'px';
	e.style.top = y + 'px';
			
	return true;
}
		
/**
 * Move an element on the page so that its top-left corner
 * is where the mouse pointer is (should be a floating element with 
 * a z-position)
 */
function dsMoveElementToPointer( elemId )
{
	var e = document.getElementById(elemId);

	y = window.event.clientY + document.body.scrollTop;
	x = window.event.clientX + document.body.scrollLeft;
	
	e.style.left = x + 'px';
	e.style.top = y + 'px';
			
	return true;
}

// add load event to initialize rollover images
dsRegisterOnLoadEvent( "dsInitRollovers()" );

// set the onload event
window.onload = onLoadEvent;

