/*
*
* Change management functions...
*
*
*
*  sal 12/14/2002  I added a function call OpenPopupSmall.  This opens a window smaller than OpenPopup.
*/

var bFormChange = false;

function
doSubmit()
{
	document.forms['form1'].submit();
	return( 1 );
}

function 
ClearFormChange()
{
	bFormChange = false;
}

function 
SetFormChange()
{
	bFormChange = true;
}

function
CheckFormChange(bShow)
{
	if ( bShow && bFormChange ) 
		return( confirm("Save your changes?") );
}

function
ChangeCloseForm()
{
	if ( bFormChange ) 
	{
		if ( !confirm("You have unsaved changes.\x0aDo you wish to lose all changes?") )
			return;
	}

	window.close(self);
}

function 
JumpTab( iTab )
{
    var f = document.forms['form1'];

	f.old_tab_nbr.value = f.cur_tab_nbr.value;
	f.cur_tab_nbr.value = iTab;
	f.cmd.value = 'new_tab';
	
	if ( CheckFormChange(true) )
		f.cmd.value = "save_item";
    
	f.submit();
	return( 1 );
}

function 
CleanNumber(val)
{
	// Strips a number field of all that is evil.
	var sNewVal;
	var sOldVal = String(val);
	var i;
	var bWebTV = 0;
	
	sNewVal = "";
	
	for ( i = 0; i < sOldVal.length; i++ )
	{
		if ( ( sOldVal.charAt(i) >= "0" && sOldVal.charAt(i) <= "9" ) || sOldVal.charAt(i) == "-" || sOldVal.charAt(i) == "." )
			sNewVal = sNewVal + sOldVal.charAt(i);
	}
	
	return( sNewVal );
}

function 
CleanDecimal(val)
{
	// Strips a number field of all that is evil.
	var sNewVal;
	var sOldVal = String(val);
	var i;
	var bWebTV = 0;
	
	sNewVal = "";
	
	for ( i = 0; i < sOldVal.length; i++ )
	{
		if ( ( sOldVal.charAt(i) >= "0" && sOldVal.charAt(i) <= "9" ) )
			sNewVal = sNewVal + sOldVal.charAt(i);
	}
	
	return( sNewVal );
}

NS = (document.layers); 
IE = (document.all); 

function 
handleEnter(e)
{
	// This takes over the enter key in the specified field 
	if((NS && e.which == 13) || (IE && window.event.keyCode == 13))
	{ 
      doSubmit(); 
      return( false ); // cancel the enter (Dings in Netscape) 
	} 
} 

function
installHandler(f)
{
	if (NS || IE)
	{
		/* Msie will submit on all fields - more code is needed to stop that Netscape will not submit with document.onkeypress if focus is on form fields */ 
		document.onkeypress = handleEnter; 
		f.onKeyPress  = handleEnter; 
	} 
}

function OpenSecureLink(sURL, sServer, sWidth)
{
	var win;
	
	win = open('https://' + sServer + sURL,'SecureWin','width=725,height=550,screenX=50,screenY=50,status=1,scrollbars=1,resizeable=0,dependent=1');
	
	if (win.opener == null) 
		win.opener = self;
}

function OpenPopup(sName, sURL, sServer)
{
	var win;
	
	if ( sName != 'itemPreviewWin' )
		win = open(sURL, sName, 'width=687,height=550,screenX=50,screenY=50,status=1,scrollbars=1,resizable=1,dependent=1');
	else
		win = open(sURL, sName, 'scrollbars=1,resizable=1,status=1');
		
	
	if (win.opener == null) 
		win.opener = self;
}

function OpenPopupSmall(sName, sURL, sServer)
{
	var win;
	
	if ( sName != 'itemPreviewWin' )
		win = open(sURL, sName, 'width=550,height=500,screenX=50,screenY=50,status=1,scrollbars=0,resizable=0,dependent=1');
	else
		win = open(sURL, sName, 'scrollbars=1,resizable=1,status=1');
		
	
	if (win.opener == null) 
		win.opener = self;
}

function CloseWindow()
{
	window.close(self);
}

function
SetParentURL(sUrl, bCloseChild)
{
	var myOpener = window.opener;
	myOpener.location.href = sUrl;

	if ( bCloseChild )
		window.close();
	
	return( false );
}

function 
SingleItemSelected( ff, sMsg )
{
	if ( ff.length != null )
	{
		//	Multiple values...
		for ( i = 0; i < ff.length; i++ )
		{
			if ( ff[i].checked )
			{
				return( ff[i].value );
				break;
			}
		}
		
		if ( i == ff.length ) 
		{
			if ( "" != sMsg )
				alert(sMsg);
			return( 0 );
		}
	}
	else
	{
		if ( ff.checked == false )
		{
			if ( "" != sMsg )
				alert(sMsg);
			return( 0 );
		}
	
		return( ff.value );
	}
	
	//	Nada...
	return( 0 );
}
