/*
	Copyright (c) 2004-2006, The Dojo Foundation
	All Rights Reserved.

	Licensed under the Academic Free License version 2.1 or above OR the
	modified BSD license. For more information on Dojo licensing, see:

		http://dojotoolkit.org/community/licensing.shtml
*/

/*
	This is a compiled version of Dojo, built for deployment and not for
	development. To get an editable version, please visit:

		http://dojotoolkit.org

	for documentation and information on getting the source.
*/

/* ------------------- Offline/ DVD version ---------------------------------*/
/* ------------------------ 600V8 -------------------------------------------------------------------- */
// version: 091123

/* ------------------------ Global Stuff ------------------------------------------------------------- */
var gHomeUrl;
var gDataUrl;
var gSelFilePath;
var gCurrSTfilename;  // filename current of current selection template

var gXMLstr;
var gFilename;  // only FF

var gSprasISO = false;  // NEW - since 600V5: ISO 639 lang.-key(CHAR2) of gSpras

function setScreen() {
	// NEW - since 600V4
	// only needed in offline/DVD version: maximize window
	// NEW 090828 - not needed anymore
	window.moveTo(0, 0);
	window.resizeTo(screen.availWidth,screen.availHeight);	
}
// ----------------------------------------------------------------------------
function getData() {
	// Parse location.href:
	// - does it have an attribute?
	//   - attrib 'create' + file name( of selection template) -> gMode = 'create'
	//     ...htm?create=STE-BL_DE_V5600+FULL_SCOPE.xml
	//   - attrib 'display' + file name( of selection template) -> gMode = 'display' -> no 'Save Data' button'
	//     ...htm?display=STE-BL_DE_V5600+FULL_SCOPE.xml	
	// - open ST, retrieve Solution ID (Solution ID of ST)
	// - open Solution file
	
	// If location.href has no attributes:
	// - gMode is 'edit'
	// - show openDlg to user and let him select a custom selection
	// - open CS, retrieve Solution ID (Selection ID of CS)
	// - open Solution file		
	
	if(!parseUrl()) {
		// Illegal url - error reported in function
		return;
	}
	
	// Open dialog in 'edit' mode
	if(gMode=="edit") {
		openDlg = dojo.widget.byId("openDialog");
		var oBtn = document.getElementById("openDlgCancel");		
	}	
		
	createUrls();
	
	if(gMode=='create'||gMode=='display') {	
		getData_Aux();
	}else if(gMode=="edit") {		
		openDlg.show();
	}else{
		// we should not get here
	}	
}
// ----------------------------------------------------------------------------
function getData_Aux() {
	// Create file path to current selection template
	gSelFilePath = "";
	var selUrl = gDataUrl + gCurrSTfilename;
	getSelectionFromDVD(selUrl);
	if(gSelectionAvailable) {
		// Retrieve Solution ID from selection template
		var solId = getSolIdFromSlec();
		if(!solId) {
			// Error reported in function
			gSelectionAvailable = false;
			return;
		}else{
			// Assign
			gSolution = solId;
			gSelScope = solId;
		}
		// Retrieve Selection ID from selection template
		var selId = getSelIdFromSlec();
		if(!selId) {
			// Error reported in function
			gSelectionAvailable = false;
			return;
		}else{
			// assign to gSelSelection
			gSelSelection = selId;
		}
		
		// Retrieve language key from selection template
		gSpras = getSprasFromSlec();		
		if(!gSpras) {
			// Error reported in function
			return;
		}else{
			// NEW - since 600V5: set ISO 639 lang.-key of gSpras
			gSprasISO = getSprasISO(gSpras);
			if(!gSprasISO) {
				// gSpras is not a known lang.-key(CHAR1) ... weird				
			}else{
				// gSprasISO was assigned
			}
		}
		// Create path to solution file
		var solUrl = gDataUrl + "SO" + gSpras + "-" + gSolution + ".xml";
		getSolutionFromDVD(solUrl);
		if(gSolutionAvailable) {
			// OK
		}else{
			// Error while retrieving solution data
		}
	}else{
		// Error while retrieving selection template data
	}
	
	// added 091123: set window title (descr. of solution and selection template)
	var solDescr = getSolutionDescr();
	var slecDescr = getSlecDescr();
	document.title = solDescr + " - " + slecDescr;	
	createScreen_Aux();
}
// ----------------------------------------------------------------------------
function getDataEdit() {
	// In FF, we can only process .xml files
	// In IE we also can process .txt files
	var filepath = document.getElementById("filepath").value;
	var len = filepath.length;
	if(len<4) {
		openDlg.hide();
		document.getElementById("tdLoad").innerHTML = "Processing cancelled.";		
		return;
	}
	
	var extension = filepath.toUpperCase().substr(len-4);
	if(isIE) {
		if(extension!=".TXT"&&extension!=".XML") {
			alert("Only files with extension .txt and .xml are allowed.");
			return;
		}
	}else{
		if(extension!=".XML") {
			alert("Only files with extension .xml are allowed.");
			return;
		}
	}	
	openDlg.hide();
	
	// Open file
	var delim,selUrl;
	if(isIE) {
		selUrl = "file:\\\\" + filepath;
	}else{
		filepath = filepath.replace(/\\/g,"/");
		selUrl = "file:///" + filepath;
	}	
	
	getSelectionFromDVD(selUrl);
	if(gSelectionAvailable) {
		// retrieve selection ID
		var selId = getSelIdFromSlec();
		if(!selId) {
			// Error reported in function
			gSelectionAvailable = false;		
		}else{
			// assign to gSelSelection
			gSelSelection = selId;			
			// retrieve solution ID
			var solId = getSolIdFromSlec();
			if(!solId) {
				// Error reported in function
				gSelectionAvailable = false;				
			}else{
				// assign
				gMyScope = solId;
				gSelScope = solId;				
				// Retrieve language key from custom selection
				gSpras = getSprasFromSlec();
				if(!gSpras) {
					// Error reported in function					
				}else{
					// NEW - since 600V6b: set ISO 639 lang.-key of gSpras
					gSprasISO = getSprasISO(gSpras);
					if(!gSprasISO) {
						// gSpras is not a known lang.-key(CHAR1) ... weird				
					}else{
						// gSprasISO was assigned
					}						
					// Create path to solution file (Solution ID = Solution ID in selection file) - fixed in 600V6
					var solUrl = gDataUrl + "SO" + gSpras + "-" + solId + ".xml";		
					getSolutionFromDVD(solUrl);
					if(gSolutionAvailable) {
						// Assign path for saving
						gSelFilePath = selUrl;
					}
				}				
			}			
		}				
	}else{
		// Error while importing selection file
	}	
	createScreen_Aux();
}
// ----------------------------------------------------------------------------
function cancelOpenDialog() {
	openDlg.hide();
	document.getElementById("tdLoad").innerHTML = "Processing cancelled.";	
}
// ----------------------------------------------------------------------------
function getSolIdFromSlec() {
	// Retrieve solution ID from current selection
	xPth = SEL_ROOT_L1 + "/" + SEL_SCOPE_L2;
	var solIdNod = gCurrSelXMLdoc.selectSingleNode(xPth);
	if(!solIdNod||!solIdNod.firstChild) {
		alert("Cannot retrieve Solution ID from Selection file.");
		return false;
	}else{
		var solId = solIdNod.firstChild.nodeValue;
		if(!solId||solId.length<1) {
			alert("Cannot retrieve Solution ID from Selection file.");
			return false;
		}else{
			return solId;
		}
	}	
}
// ----------------------------------------------------------------------------
function getSelIdFromSlec() {
	// Retrieve solution ID from current selection
	xPth = SEL_ROOT_L1 + "/" + SEL_SELECTION_L2;
	var selIdNod = gCurrSelXMLdoc.selectSingleNode(xPth);
	if(!selIdNod||!selIdNod.firstChild) {
		alert("Cannot retrieve Selection ID from Selection file.");
		return "";
	}else{
		var selId = selIdNod.firstChild.nodeValue;
		if(!selId||selId.length<1) {
			alert("Cannot retrieve Selection ID from Selection file.");			
			return false;
		}else{
			return selId;
		}
	}
}
// ----------------------------------------------------------------------------
function getSprasFromSlec() {
	// Retrieve language key from selection
	// There should be just 1, so we select the first node
	xPth = SEL_ROOT_L1 + "/" + SEL_DESCRS_L2 + "/" + SEL_DESCRS_L3;
	var descrNods = gCurrSelXMLdoc.selectNodes(xPth);
	if(!descrNods||descrNods.length<1) {
		alert("Cannot retrieve Langugae Key from Selection file.");
		return false;
	}else{
		var sprasNod = descrNods[0].selectSingleNode(SEL_SPRAS_L4);
		if(!sprasNod||!sprasNod.firstChild) {
			alert("Cannot retrieve Langugae Key from Selection file.");
			return false;
		}else{
			var spras = sprasNod.firstChild.nodeValue;
			if(!spras||spras.length<1) {
				alert("Cannot retrieve Langugae Key from Selection file.");
				return false;
			}else{
				return spras;
			}
		}
	}
}
// ----------------------------------------------------------------------------
function getSprasISO(gSpras) {
// NEW - since 600V5: set ISO 639 lang.-key gSprasISO according to gSpras
	switch (gSpras) {
		case "0":
			return "SR";
		case "1":
			return "ZH";
		case "2":
			return "TH";
		case "3":
			return "KO";
		case "4":
			return "RO";
		case "5":
			return "SL";
		case "6":
			return "HR";
		case "7":
			return "MS";
		case "8":
			return "UK";
		case "9":
			return "ET";
		case "A":
			return "AR";
		case "B":
			return "HE";
		case "C":
			return "CS";
		case "D":
			return "DE";
		case "E":
			return "EN";
		case "F":
			return "FR";
		case "G":
			return "EL";
		case "H":
			return "HU";
		case "I":
			return "IT";
		case "J":
			return "JA";
		case "K":
			return "DA";
		case "L":
			return "PL";
		case "M":
			return "ZF";
		case "N":
			return "NL";
		case "O":
			return "NO";
		case "P":
			return "PT";
		case "Q":
			return "SK";
		case "R":
			return "RU";
		case "S":
			return "ES";
		case "T":
			return "TR";
		case "U":
			return "FI";
		case "V":
			return "SV";
		case "W":
			return "BG";
		case "X":
			return "LT";
		case "Y":
			return "LV";
		case "Z":
			return "Z1";
		case "a":
			return "AF";
		case "b":
			return "IS";
		case "c":
			return "CA";
		case "d":
			return "SH";
		case "i":
			return "ID";
		default:
			return false;
	}	
}
// ----------------------------------------------------------------------------
function getSolutionFromDVD(solUrl) {
	gSolutionAvailable = false;
	if (document.implementation && document.implementation.createDocument) {
		// FF
		gCurrSolXMLdoc = document.implementation.createDocument("", "", null);		
		//gCurrSolXMLdoc.onload = createTable;
	}else if (window.ActiveXObject) {
		// IE
		gCurrSolXMLdoc = new ActiveXObject("Microsoft.XMLDOM");
		//gCurrSolXMLdoc.onreadystatechange = function () {
			//if (gCurrSolXMLdoc.readyState == 4) createTable()
		//};
 	}else {
		alert("Your browser cannot handle this script.");		
		return;
	}
	gCurrSolXMLdoc.async=false;
	try{
		gCurrSolXMLdoc.load(solUrl);
	}catch(e) {
		alert(e.message + "\nCannot import Solution\n" + solUrl);		
		return;
	}
// Added 090205: Check xml doc
	if(!gCurrSolXMLdoc) {
		alert("Cannot import\n" + solUrl);
		return;
	}else if(!gCurrSolXMLdoc.documentElement) {
		alert("Cannot import Solution File\n" + solUrl);
		return;
	}else if(gCurrSolXMLdoc.documentElement.nodeName!=SOL_ROOT_L1) {
		alert(solUrl + "\nis not a Solution File.");
		return;
	}		
	gSolutionAvailable = true;	
}
// ----------------------------------------------------------------------------
function getSelectionFromDVD(selUrl) {
	gSelectionAvailable = false;
	if (document.implementation && document.implementation.createDocument) {
		// FF
		gCurrSelXMLdoc = document.implementation.createDocument("", "", null);		
		//gCurrSolXMLdoc.onload = createTable;
	}else if (window.ActiveXObject) {
		// IE
		gCurrSelXMLdoc = new ActiveXObject("Microsoft.XMLDOM");
		//gCurrSolXMLdoc.onreadystatechange = function () {
			//if (gCurrSolXMLdoc.readyState == 4) createTable()
		//};
 	}else {
		alert("Your browser cannot handle this script.");
		return;
	}	
	gCurrSelXMLdoc.async=false;
	try{
		gCurrSelXMLdoc.load(selUrl);
	}catch(e) {
		alert(e.message + "\nCannot import Selection\n" + selUrl);
		return;
	}
	// Added 090205: Check xml doc
	if(!gCurrSelXMLdoc) {
		alert("Cannot import\n" + selUrl);
		return;
	}else if(!gCurrSelXMLdoc.documentElement) {
		alert("Cannot import Selection\n" + selUrl);
		return;
	}else if(gCurrSelXMLdoc.documentElement.nodeName!=SEL_ROOT_L1) {
		alert(selUrl + "\nis not a Selection.");
		return;
	}	
	gSelectionAvailable = true;	
}
// ----------------------------------------------------------------------------
function parseUrl() {
	//gHomeUrl = document.URL;  // does not work in IE6; attribs are cut off
	gHomeUrl = location.href;
	
	var parts = gHomeUrl.split("?");
	if(parts.length==1) {
		// No attributes -> gMode = 'edit'
		gCurrSTfilename = "";
		gMode = 'edit';
		return true;
	}else if(parts.length==2) {
		// Extract selection template filename
		var sParts = parts[1].split("=");
		if(sParts.length==1) {
			// Illegal - no =
			gCurrSTfilename = "";
			gMode = "";
			alert("Illegal URL\n" + document.URL);
			return false;
		}else if(sParts.length==2) {
			// legal - just one = -> retrieve gMode
			var mode = sParts[0];
			if(sParts[0].toUpperCase()=="DISPLAY") {
				gMode = 'display';
			}else if(sParts[0].toUpperCase()=="CREATE") {
				gMode = 'create';
			}else{
				// Illegal - no =
				gCurrSTfilename = "";
				gMode = "";
				alert("Illegal URL\n" + document.URL);
				return false;
			}			
			gCurrSTfilename = sParts[1];			
			return true;
		}else{
			// Illegal - more than one =
			gCurrSTfilename = "";
			gMode = "";
			alert("Illegal URL\n" + document.URL);
			return false;
		}
	}else{
		// Illegal - more than one ?
		gCurrSTfilename = "";
		gMode = "";
		alert("Illegal URL\n" + document.URL);
		return false;
	}
}
// ----------------------------------------------------------------------------
function createUrls() {
	// In IE, file paths have to use \ instead of /
	// gHomeUrl is like
	// file:///E:/abc/def/file.txt[?st=ghi.xml]
	var ls = gHomeUrl.lastIndexOf("/");
	gHomeUrl = gHomeUrl.substring(0,ls+1);
	
	if(isIE) {
		// replace file:/// with file://
		// replace other / with \
		gHomeUrl = gHomeUrl.replace(/\//g,"\\");
		gHomeUrl = gHomeUrl.replace(/file:\\\\\\/,"file://");
		gDataUrl = gHomeUrl + "data\\";
	}else{
		// FF
		gDataUrl = gHomeUrl + "data/";
	}	
}
// ----------------------------------------------------------------------------
function verifyUserSolutionId(solutionId) {
	// User provided a solution ID (and descr),
	// Since we cannot check, whether it's a new one, we
		// - check ID for illegal chars
		// If ID is valid, we
		// - close user dialog
		// - modify selection data		
		// - save selection
		
	// Check length, must be 1-40
	var tdDescr
	if(solutionId.length < 1 || solutionId.length > 40) {
		tdDescr = document.getElementById("inpUserDescr");
		tdDescr.innerHTML = "<font color=\"#AA0000\"><br/>Illegal Solution ID.<br/>Solution ID must have 1-40 characters.<br/><br/></font>";		
		// Reset ID
		gMyScope = "";
	}else{
		// Check chars
		var reslt = solutionId.search(/\W/);
		if(reslt != -1) {
			tdDescr = document.getElementById("inpUserDescr");
			tdDescr.innerHTML = "<font color=\"#AA0000\"><br/>Illegal Solution ID.<br/>Possible characters for ID: A-Z, 0-9 and underscores.<br/><br/></font>";		
			// Reset ID
			gMyScope = "";
		}else{
			userDlg.hide();	
			var useOldDescr = modifyCurrentSelection(gMyScopeDescr);
			saveCurrentSelection(useOldDescr);
		}
	}
}
// ----------------------------------------------------------------------------
function saveCurrentSelection(useOldDescr) {
	// Save current selection to file
	// - create filename, depending on gMode
	// - in 'edit' mode, we use file path from import/upload
	// - show 'Save as' dialog to user
	
	// taken from:
	// http://4umi.com/web/javascript/filewrite.htm?txt=This+is+where+the+text+goes.%0D%0ANew+lines+go+here.&filename=E%3A%5Ctmp%5Ctesttest&ext=utf-8
	
	// Since FF does not support xmlDoc.xml, we get it the hard way ...
	gXMLstr = "";
	if(isIE) {
		gXMLstr = gCurrSelXMLdoc.xml;
		// add encoding info, if it's missing
		if(gXMLstr.search(/encoding="utf-8"/)==-1) {
			gXMLstr = gXMLstr.replace(/xml version="1.0"/,"xml version=\"1.0\" encoding=\"utf-8\"");
		}	  
	}else{
		// FF		
		gXMLstr = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";		
		gXMLstr = getXmlFF(gCurrSelXMLdoc.documentElement,gXMLstr);		
	}
	
	// in FF we can use .xml as extension
	var extension;
	if(isIE) {
		extension = ".txt";
	}else{
		extension = ".xml";
	}
	
	var filename;
	if(gMode=="create") {
		filename = "CS" + gSpras + "-" + gMyScope + "+" + gSelScope + extension;
	}else if(gMode=="edit") {
		filename = "CS" + gSpras + "-" + gSelScope + "+" + gSelSelection + extension;	
	}else{
		alert("Saving not possible in current mode.");
		return false;
	}
		
	// Since FF does not know execCommand("saveAs"), we use different routines for saving
	if(isIE) {
		saveDataIE(gXMLstr,filename);
	}else{
		gFilename = filename;
		saveDataFF_Aux();
	}		
}
// ----------------------------------------------------------------------------
function saveDataIE(xmlStr,filename) {
	var w = window.frames.w;
	if(!w) {
		w = document.createElement( 'iframe' );
		w.id = 'w';
		w.style.display = 'none';
		//document.body.insertBefore(w);
		document.body.appendChild(w);
		w = window.frames.w;
		if(!w) {
			w = window.open( '', '_temp', 'width=100,height=100' );
			if(!w) {
				window.alert("Error!\nData cannot be saved.(E1)");
				return false;
			}
		}
	}
	
	var d = w.document; 	
	d.open( 'text/plain', 'replace' );
	d.charset = "utf-8";
	d.write(xmlStr);
	d.close();
	if(d.execCommand('SaveAs',null,filename)){
		updateAfterSave();
		window.alert("Saved Solution with ID\n" + gMyScope + "\n" + "successfully.");
	}else{
		window.alert("Data not saved.");
	}
  w.close();
}
// ----------------------------------------------------------------------------
function saveDataFF_Aux() {
	// In 'edit' mode, we use file path from import
	if(gMode=="edit") {
		saveDataFF();
	}else{
		saveDlg.show();
	}
}
// ----------------------------------------------------------------------------
function saveDataFF() {
	// taken from http://www.captain.at/programming/xul/
	
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to save data was denied.");
		return;
	}
	
	var filePath;
	if(gMode=="edit") {
		// In 'edit' mode, we use file path from import
		filePath = gSelFilePath;
		// Remove file:/// and replace / with \
		filePath = filePath.replace(/file:\/\/\//,"");
		filePath = filePath.replace(/\//g,"\\");
	}else{		
		var outputFolder = document.getElementById("outputFolder").value;		
		// Check, if output folder exists
		var folder = Components.classes["@mozilla.org/file/local;1"]
			.createInstance(Components.interfaces.nsILocalFile);
		folder.initWithPath( outputFolder );
		if ( folder.exists() == false ) {
			alert("Output folder\n" + outputFolder + "\ndoes not exist.");
			return;
		}	
		saveDlg.hide();
		
		var len = outputFolder.length;  	
		// append "\", if needed
		if(outputFolder.charAt(len-1)!="\\") {
			outputFolder = outputFolder + "\\";
		}
		filePath = outputFolder + gFilename;
		gSelFilePath = filePath;
	}	
	
	var file = Components.classes["@mozilla.org/file/local;1"]
		.createInstance(Components.interfaces.nsILocalFile);
	file.initWithPath( filePath );
	if ( file.exists() == false ) {		
		file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
	}else{
		// File already exists -> ask user, if it should be overwritten
		var answer = confirm(filePath + "\nalready exists.\nOverwrite it?");
		if(answer != true) {
			return;
		}
	}	
	/* Open flags 
	#define PR_RDONLY       0x01
	#define PR_WRONLY       0x02
	#define PR_RDWR         0x04
	#define PR_CREATE_FILE  0x08
	#define PR_APPEND      0x10
	#define PR_TRUNCATE     0x20
	#define PR_SYNC         0x40
	#define PR_EXCL         0x80
	*/
	/*
	** File modes ....
	**
	** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
	** The 'mode' argument may be ignored by PR_Open on other platforms.
	**
	**   00400   Read by owner.
	**   00200   Write by owner.
	**   00100   Execute (search if a directory) by owner.
	**   00040   Read by group.
	**   00020   Write by group.
	**   00010   Execute by group.
	**   00004   Read by others.
	**   00002   Write by others
	**   00001   Execute by others.
	**
	*/

	var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
		.createInstance( Components.interfaces.nsIFileOutputStream );
	outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
	
	var chrst = "UTF-8";
	var os = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
                   .createInstance(Components.interfaces.nsIConverterOutputStream);
	os.init( outputStream,chrst, 0, 0x0000 );
		
	var output = gXMLstr;
	var reslt = os.writeString(gXMLstr);
	os.close();
	if(reslt==true) {
		updateAfterSave();
		alert("Saved Solution with ID\n" + gMyScope + "\n" + "successfully.");
	}else{
		alert("Error!\nData cannot be saved.");
	}	
}
// ----------------------------------------------------------------------------
function updateAfterSave() {
	// After user has saved his data in gMode 'create'
	// - adjust solution descr.
	// - change gMode to 'edit'
	// - reassign gSelScope and gSelSelection
	if(gMode=='create') {
		var tdHeadTxt = document.getElementById("TDhead3");
		// Retrieve descr. of selection template	
		tdHeadTxt.innerHTML = "<i>" + getSlecDescr() + "</i>";
		gMode = 'edit';
		gSelScope = gMyScope;
		gSelSelection = gSolution;
	}
}
// ----------------------------------------------------------------------------
function getXmlFF(el,str) {	
	if(el.nodeName!="#text") {
		str = str + "<" + el.nodeName + ">" ;
	}else{
		str = str + el.nodeValue;
	}	
	var cs = el.childNodes;	
	for(var i=0;i<cs.length;++i) {
		str = getXmlFF(cs[i],str);
	}
	if(el.nodeName!="#text") {
		return str + "</" + el.nodeName + ">" ;	
	}else{
		return str;
	}	
}
// ----------------------------------------------------------------------------
function getLangDepDocName(docName) {
	// NEW - since 600V5:
	// Extract lang.-key from docName
	// If found, replace it with gSprasISO
	// Otherwise return original docName
	
	// docName, e.g. 117_DE_DE.htm
	// min. number of chars: A_DE_DE.htm = 11  / A_DE_DE.html = 12
	//                       12345678901
	
	if(!gSprasISO) {
		// ISO 639 lang.-key was not set
		return docName;
	}
	var len;
	if(!docName) {
		// Hu ???
		return docName;
	}
	len = docName.length;
	if(len<11) {
		// does not look like a real doc's name ...
		return docName;		 
	}
	
	// We assume, that extension has 3(.htm, .doc, .pdf ...) or 4 chars(.html)
	var docNameNoExt, docExt;
	if(docName.charAt(len-4)==".") {
		docNameNoExt = docName.substr(0,len-4);
		docExt = docName.substr(len-4,4);
	}else if(docName.charAt(len-5)==".") {
		// In this case, docName.length must be at least 12
		if(len<12) { return docName; }		
		docNameNoExt = docName.substr(0,len-5);
		docExt = docName.substr(len-5,5);
	}else{
		// does not look like a real doc's name ...
		return docName;
	}
	
	// Split at '_'
	var parts = docNameNoExt.split("_");
	// We must have at least 3 parts
	if(parts.length<3) {
		// does not look like a real doc's name ...
		return docName;
	}
	// Last 2 parts must have exactly 2 chars each
	if(parts[parts.length-1].length!=2) {
		return docName;
	}
	if(parts[parts.length-2].length!=2) {
		return docName;
	}
	
	// Now, lust but 1 part should be lang.-key -> replace with gSprasISO
	// A_DE_DE
	// 6543210
	return(docNameNoExt.substr(0,docNameNoExt.length-5) + gSprasISO + docNameNoExt.substr(docNameNoExt.length-3) + docExt);	
}
// ----------------------------------------------------------------------------
function logChanges(scenId) {
	// Dummy - only needed in BSP version
	return true;
}
// ----------------------------------------------------------------------------
function getMsgTxt(msgNr) {
	// return message text
	switch (msgNr) {
		case 1:
			return ("Details not available.\nDocument location not maintained.");
		case 2:
			return ("Details not available.\nDocument name not maintained.");
	}
}
