blnDirty = 0;


function NB_clearField( objField, szDefaultValue ) {
	if( (objField == null) || (szDefaultValue == null)) return;
	
	if( objField.value == szDefaultValue ) { objField.value = ""; }
}


function NB_eventSetDirty() { blnDirty = 1; }


function NB_windowConfirmClose( szMessage, blnForceClose, blnRefreshOpener ) {

	if( (szMessage == null) || (szMessage == "") ) {
		var szMessage = "Are you sure you want to end this editing session?\n\nYou will lose any unsaved changes.";
	}

	if( blnForceClose == null ) { 
		var blnForceClose = false;
	}

	if( blnForceClose || !blnDirty || confirm( szMessage )) {
		self.close();
	}
	
	if( (blnRefreshOpener != null) && blnRefreshOpener ) {
		opener.history.go( 0 );
	}
}


function NB_formConfirmReset( objForm, szMessage, blnForceReset ) {
	if( objForm == null ) {
		alert( 'Please supply a form object' );
		return;
	}

	if( (szMessage == null) || (szMessage == "") ) {
		var szMessage = "Are you sure you want to revert to the content you previously saved?";
	}
	
	if( blnForceReset == null ) { 
		var blnForceReset = false;
	}

	if( !blnDirty || blnForceReset || confirm( szMessage )) {
		blnDirty = 0;
		objForm.reset();
		NB_smEditControlReset( objForm );
		window.status = "Contents reverted to previously saved version";
	}
}



function NB_formFlagDirtySetup( objForm ) {
	if( objForm == null ) {
		alert( 'Please specifiy a formname for use in NB_flagDirtySetup' );
		return;
	}
	
	for( var i = 0; i < objForm.elements.length; i++ ) {
		objTarget = objForm.elements[ i ];
		if( objTarget.onchange == null )
		{
			objTarget.onchange = NB_eventSetDirty;
		} else {
			fnOriginalHandler = objTarget.onchange;
			objTarget.onchange
				= new Function( "fnOriginalHandler(); NB_eventSetDirty()" );
		}
	}
}




function NB_formRemoveHTML( objField )
{
	var szContent = objField.value;

	var currentChar = '';
	var arrTagsValid = new Array( 'a','/a','br','b','/b','strong','/strong','em','/em','i','/i','ol','/ol','ul','/ul','li','/li','p','/p' );

	for( i=0; i < szContent.length; i++ )
	{
		currentChar = szContent.charAt(i);
		
		if( currentChar == '<' )
		{
			intTagStartIndex = i;
			i++;
			szFoundTag = '';
			blnSpace = false;

			for( i=i; szContent.charAt(i) != '>'; i++ )
			{
				if (szContent.charAt(i) == ' '){ blnSpace = true }
				if (!blnSpace){ szFoundTag = szFoundTag + szContent.charAt(i) }
			}

			intTagEndIndex = i;
			
			blnTagValid = false;
			for (j=0;j < arrTagsValid.length;j++)
			{
				if( arrTagsValid[j].toLowerCase() == szFoundTag.toLowerCase() ){
					blnTagValid = true;
					break;
				}
			}
			
			if (!blnTagValid){
				first_part = szContent.slice( 0, intTagStartIndex );
				second_part = szContent.slice( intTagEndIndex + 1 );
				szContent = first_part.concat( second_part );
				i = intTagStartIndex - 1;
			}
		}
	}
	
	objField.value = szContent;
}




function NB_formGetFields( objForm ) {
	if( objForm == null ) {
		alert( 'Please specifiy a formname for use in NB_flagDirtySetup' );
		return;
	}
	
	arrFields = new Array();
	
	for( var i = 0; i < objForm.elements.length; i++ ) {
		arrFields[ i ] = objForm.elements[ i ].name;
	}
	
	document.open();
	document.write( arrFields );
	document.close();
}





function setupImages( imagePath ) {
	this.imgPath = imagePath;
	if (document.images) this.browserImg = true;
}

window.onLoad=setupImages( '../images/' );
