function Strings( xmlDOM, sLanguageCode ) {
	this.DOM = xmlDOM;
	this.LanguageCode = sLanguageCode;
	
	this.Load = Strings_Load;
	this.Lookup = Strings_Lookup;
}

function Strings_Load( sPath ) { this.DOM = LoadXML( sPath ) }

///////////////////////////////////////////////////////////////////////////////////////////////////
//	STRINGS LOOKUP METHOD
//	Try to return the string with the specified language code
//	If that language isn't found, try returning standard English
//	If standard English wasn't specified, return the first available string
//	Otherwise, as an error handler, return the hardcoded default or the ID itself
//
//	The string may include <data/> which are substituted for matching strings in aData[] 
//
function Strings_Lookup( sID, sDefault, aData, bCapitalize, bEscape ) {
	try {
		if( this.DOM.parseError.errorCode != 0 || sID == "" ) throw new Error();
		with( this.DOM.documentElement ) {
			var nString = selectSingleNode( "strings/language[@xml:lang='" + this.LanguageCode + "']/string[@id='" + sID + "']" );
			if( nString == null ) {
				nString = selectSingleNode( "strings/language[@xml:lang='en-us']/string[@id='" + sID + "']" );
				if( nString == null ) {
					nString = selectSingleNode( "strings/language/string[@id='" + sID + "']" );
					if( nString == null ) throw new Error();
				}
			}
		}
		var nClone = nString.cloneNode( true );
		var i = 0, eData;
		while( ( eData = nClone.selectSingleNode( "data" ) ) != null ) {
			if( aData != null ) var sData = aData[i++];
			var tData = this.DOM.createTextNode( ( sData != null ) ? sData : "" );
			nClone.replaceChild( tData, eData );
		}
		var sText = nClone.text.replace( /[\f\n\r\v]/g, "" ).replace( /\t/g, " " );
		if( sText == "" ) throw new Error();
		if( bCapitalize == true ) sText = sText.charAt(0).toUpperCase() + sText.slice( 1, sText.length );
		if( bEscape == true ) {
			try { sText = sText.replace( /(^|[^\\])(['"])/g, "$1\\$2" ) }
			catch(e){}
		}
		return sText;
	}
	catch(e) { 
		return ( sDefault != null ) ? sDefault : sID; 
	}
}
