function openWin( url, name, W, H )
{
	openWindow( url, name, W, H );
}

function loadFrame( frameID, URL )
{
	document.frames[ frameID ].location.href = URL;
}

function openDialog( url )
{
	window.showModalDialog( url, "", "center:yes;unadorned:yes;status=no;resizable=no;dialogWidth=500px;height=300;dialogHeight=300px;" );
	return true;
}
function openWindow( url, name, W, H )
{
	var windowW = W;
	var windowH = H;
	var windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
	var windowY = Math.ceil( (window.screen.height - windowH) / 2 );

	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion)>=4) 
		isie=true;
	else											     
		isie=false;

	if (isie) 
	{ 
		H=H+20+2; 
		W=W+2; 
	}

//alert( url );

	s = ",left="+ Math.ceil( windowX ) + ",top=" + Math.ceil( windowY ) + ",width="+W+",height="+H;

	splashWin = window.open( url, name, "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1"+s, true);
	splashWin.focus();
	
	return splashWin;
}

function closeWindow()
{
	self.close()
}

function getParentRow( element )
{
	return getParent( element, "TR" );
}

function highlightRow( element )
{
	if( element == null ) element = event.srcElement;
	var row = getParentRow( element, "TR" );
	row.style.backgroundColor = "white";
}

function normalRow( element )
{
	if( element == null ) element = event.srcElement;
	var row = getParentRow( element, "TR" );
	row.style.backgroundColor = "";
}

function toggleHighlightRow( element )
{
	if( element == null ) element = event.srcElement;
	var row = getParentRow( element, "TR" );
	if( row.style.backgroundColor!="white" )row.style.backgroundColor="white";
	else row.style.backgroundColor="";
}

function deleteSelectedRows( tableName )
{
	var tableElement = document.all(tableName);
	for (i=0; i<tableElement.rows.length; i++){
		if(tableElement.rows[i].style.backgroundColor!="")
		{
			deleteRow( tableName,i );
			i--;
		}
	}
}
function normalAllRows( tableName ){
	var tableElement = document.all(tableName);
	for (i=0; i<tableElement.rows.length;i++)
	{
		tableElement.rows[i].style.backgroundColor="";
	}
}
function getParent( element, parentTagName )
{
	var parentElement = element.parentElement;
	while( parentElement != null )
	{
		if( parentElement.tagName == parentTagName )
			return parentElement;
		else
			parentElement = parentElement.parentElement;
	}
	return element;
}


function addRow( tableName, index )
{
	var tableElement = document.all(tableName);
	if( index == null ) index = tableElement.rows.length;

	var newRow = tableElement.insertRow( index );
	return newRow;
}

function insertCells( row /*, cells as argument. Each parameter is one cell */ )
{
	for( var i = 1; i < arguments.length; i ++ )
	{
		var cell = row.insertCell();
		cell.innerHTML = arguments[i];
	}
}

function deleteRow( tableName, rowIndex )
{
	var tableElement = document.all(tableName);
	if( rowIndex == null )
		tableElement.deleteRow( );
	else
		tableElement.deleteRow( rowIndex );
}

function deleteCurrentRow( )
{
	var tableElement = getParent( event.srcElement, "TABLE" );
	var row = getParent( event.srcElement, "TR" );
	tableElement.deleteRow( row.rowIndex );
}

function makeCellEditable()
{
	for( var i = 0; i < arguments.length; i ++ )
	{
		var cell = arguments[i];
		cell.innerHTML = "<input type=text value='" + cell.innerText + "'>";
	}
}
function updateCell()
{
	for( var i = 0; i < arguments.length; i ++ )
	{
		var cell = arguments[i];
		var input = cell.all.tags("INPUT")[0];
		cell.innerText = input.value;
	}
}

function toggleHighlightRow( element )
{
	var row = getParentRow( element, "TR" );
	if( row.style.backgroundColor!="white" )row.style.backgroundColor="white";
	else row.style.backgroundColor="";
}

function deleteSelectedRows( tableName ){
	var tableElement = document.all(tableName);
	for (i=0; i<tableElement.rows.length; i++){
		if(tableElement.rows[i].style.backgroundColor!=""){
			deleteRow( tableName,i );
			i--;
		}
	}
}

function normalAllRows( tableName ){
	var tableElement = document.all(tableName);
	for (i=0; i<tableElement.rows.length;i++){
		tableElement.rows[i].style.backgroundColor="";
	}
}

function getAllInput( element )
{
	return element.all.tags("INPUT");
}	

function getCheckedInput( element )
{
	
	var inputs = getAllInput( element );
	var checkedInputs = new Array();
	var j = 0;
	for( var i = 0; i < inputs.length; i ++ )
		if( inputs[i].checked )
			checkedInputs[ j++ ] = inputs[i];
			
	return checkedInputs;
}

function moveFocus( controlName )
{
	var control = document.all( controlName );
	if( control != null )
	{	
		if( !control.disabled )
			control.focus();	
			
		if( control.select != null )
			control.select();			
			
		
	}
	
}
function closeWindowAndReloadParent()
{
	var parentWindow = window.opener;
	window.close();
	if( parentWindow != null )
	{
		// extract the current document URL
		var url = parentWindow.document.location.href;
		// If there is anchor, then remove the anchor
		// because when anchor is present, location.replace
		// just moves to the anchor instead of reloading the
		// page.
		if( url.indexOf("#") > 0 )
			url = url.substr( 0, url.indexOf("#") );
			
		parentWindow.document.location.replace( url );
	}
}

function onbeforeprint()
{
	var allItems = document.all.tags("DIV");
	
	for( var i = 0; i < allItems.length; i ++ )
	{
		var item = allItems[ i ];
		
		if( item.className == "HidePrint" )
		{
			if( item.style != null )
			{
				item._innerHTML = item.innerHTML; 
				item.innerHTML = "";
			}
		}	
		
	}
	
}
function onafterprint()
{
	var allItems = document.all.tags("DIV");
	for( var i = 0; i < allItems.length; i ++ )
	{
		var item = allItems[ i ];
		
		
		if( item.className == "HidePrint" )
			if( item.style != null )
				item.innerHTML = item._innerHTML; 
	}

}

function printPage()
{
	window.print();

}

function confirmDelete()
{
	return confirm("Are you sure? Click OK to proceed, otherwise click CANCEL to abort.");
}

function scrollAdjust()
{
	window.scrollBy( 0, -50 );
}


onerror = function()
{
	window.status = 'Error';
}

function MM_openBrWindow(theURL,winName,features) 
{ 
	window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function CheckFormFields(names)
{
var message="";
for (var i=0;i<names.length;i++)
	{
	if (document.forms[0].elements[names[i]].value == "")
		{
		message +="\n* "+document.forms[0].elements[names[i]].name
		}
	}
if (message!="")
	{
	alert("The following fields are required:\n"+message)
	return false;
	}
return true;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}