var jxmlSource="js_text";
var jxmlDoc_status = 0;
var ready_flag=0;

function getTextFromXML(msgId,msgParam,jxmlDoc)
{
	var temp_data = "";
	temp_data = jxmlDoc.getElementsByTagName(msgId)[0].firstChild.data;
	if (msgParam.length>0)
		temp_data = replaceParams(temp_data,msgParam);
	return (temp_data);
}

function replaceParams(msgText, msgParam)
{
	var param=0;
	var srch_str="";
	var pos1, pos2;
	var text1 = "";
	var text2 = "";
	while(param < msgParam.length)
	{
		srch_str = "%%" + param.toString();
		pos1 = msgText.indexOf(srch_str);
		text1 = msgText.substring(0, pos1) + msgParam[param];
		text2 = msgText.substring(pos1 + srch_str.length);
		msgText = text1 + text2;
		param = param + 1;
	}
	return (msgText);	
}


function getXMLDoc(jxmlDoc)
{
	jxmlDoc=init_xmldoc(jxmlDoc);
	return (jxmlDoc);
}


function init_xmldoc(jxmlDoc)
{
	formXMLSrcName();
	if (window.ActiveXObject)
	{
		jxmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		jxmlDoc.async = false;
	}
	else if (document.implementation && document.implementation.createDocument)
	{
		jxmlDoc=document.implementation.createDocument("","doc",null);
		jxmlDoc.onload=set_flag(1);
	}
	if (typeof jxmlDoc != "undefined")
	{
		jxmlDoc.load(jxmlSource);
	}
	else
		alert("No Definition");
	jxmlDoc = fetchXML(jxmlDoc);
	return jxmlDoc;
}


function fetchXML(jxmlDoc)
{
	if (window.ActiveXObject)
	{
		if (ready_flag == 0)
		{
			if (jxmlDoc.readyState==4)
			{
				set_flag(1);
			}
			else
			{
				setTimeout('fetchXML()',10);
			}
		}
	}
	else if (typeof jxmlDoc!="undefined")
	{
//			alert("Fetch XML init n6");
	}
	return (jxmlDoc);
}


function formXMLSrcName()
{
	var tprotocol=document.location.protocol;
	var tport=document.location.port;
	var thostname=document.location.hostname;
	var tpath=document.location.pathname;
	var tpos=tpath.indexOf("/",2);
	var tstr=tpath.substr(0,tpos+1);

	if (tport != "")
		jxmlSource=tprotocol + "//" + thostname + ":" + tport + tstr + "web/langs/" + textLanguage + "/js_text/" + jxmlSource + ".ovr";
	else
		jxmlSource=tprotocol + "//" + thostname + tstr + "langs/" + textLanguage + "/js_text/" + jxmlSource + ".ovr";
		
}


function init_lang()
{
	textLanguage=document.getElementsByTagName("nls_code")[0].getAttribute("val");
}


function set_flag(tFlag)
{
	ready_flag=tFlag;
}

