
/**********************************************************
***********************************************************
*  Copyright 2004 (c) Aumediage S.P.R.L. All Rights Reserved.			*
*  This is a commercial software product, please visit					*
*  http://www.aumediage.net for more information. or send email to		*
*  aumediage@hotmail.com												*
*  See http://www.aumediage.net for Commercial License Agreement		*
*  All Copyright statements must always remain in place in all files at all times	*
*		***** PLEASE NOTE: THIS IS NOT FREE SOFTWARE	*****			*
*				*****	IT MUST BE LICENSED FOR ALL USE	*****			*
*  HISTORY																*
*	Name		Date			Action		Version						*
*	GdB			27/02/2003		Creation	1.00						*
*																		*
************************************************************
***********************************************************/

/**********************************************************/
var sSelectText;
document.onselectionchange = eOnSelectText;
/**********************************************************/
function changeToLower(__vArg){	if(__vArg)
		return __vArg.toLowerCase()
}/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function changeToUpper(__vArg){	if(__vArg)
		return __vArg.toUpperCase()
}/***********************************************************Format Number***********************************************************/function formatNumber(__iNumber, __iDecimals, __sIntegerSep, __bForceDecimal){
	var sGrousSep = (__sIntegerSep == ',')? '.':',';
	var iBuffer = '';
	if (parseFloat(__iNumber)){
		__iNumber		= parseFloat(__iNumber);
		var iInteger = parseInt(__iNumber);
		var iAfterComa = (Math.round((__iNumber - iInteger)*(Math.pow(10, __iDecimals)),__iDecimals));
		iInteger = iInteger+'';
		var iLength = iInteger.length;
		var i = iLength
		while(i > 0){
			iBuffer = iInteger.charAt(i-1) + iBuffer;
			if (i  % 3 == 1 && i < iLength && i>1)
				iBuffer = sGrousSep + iBuffer;
			i--;
		}
	}
	else{
		return(0);
	}
	return (iDecimals > 0)?iBuffer + __sIntegerSep + addLeadingZero(iAfterComa, __iDecimals, false):iBuffer;
}
/***********************************************************This put leading char(s) in front of a number/string***********************************************************/function addLeadingZero(__sText, __iLength, __bShrink){
	return addLeadingChar ("0", __sText, __iLength, __bShrink);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
function addLeadingChar(__sChar, __sText, __iLength, __bShrink){
	__sText = (typeof(__sText) == 'string')?__sText:__sText+'';
	if (__iLength > __sText.length){
		__iLength = __iLength-__sText.length;
		while (__iLength > 0){
			__sText = __sChar + __sText;
			__iLength--;	
		}
	}
	else if (__bShrink){
		var iLen = __sText.length;
		__sText = __sText.substring(iLen-__iLength,iLen);
	}
	return __sText;
}
//********************************************************
function parseHtml(__sHtml, __btoHtml){try{
	var iFrom				= __btoHtml ? 0: 1;
	var iTo					= __btoHtml ? 1: 0;
	var iLastSpecificToText	= 1
	var iFirstSpecificToHtml= 0
	var aryToParse			= new Array(
						//	['<'		, '&lt;'  ], 
						//	['>'		, '&gt;' ],
								[ '\r\n'	,'<br />'],
								[''			, '\r\n'  ]
							);
		if (__btoHtml){
			for(var i = 0; i < aryToParse.length-iLastSpecificToText; i++){
				__sHtml = replaceAll(__sHtml, aryToParse[i][iFrom], aryToParse[i][iTo], false)
			}
		}
		else{
			for(var i = aryToParse.length-1; i >= 0+iFirstSpecificToHtml; i--){
				//alert(aryToParse[i])
				__sHtml = replaceAll(__sHtml, aryToParse[i][iFrom], aryToParse[i][iTo], false)
			}
		}
	
		return (__sHtml)
}catch(e){handleClientError('parseHtml', e);}}
//********************************************************
function lTrim(__sText){
	return __sText.replace(/^\s*/, '');
}
//********************************************************
function rTrim(__sText){
	return __sText.replace(/\s*$/, '');
}
//********************************************************
function trim(__sText) {
	return lTrim(rTrim(__sText));
};
//********************************************************
function isEmpty (__sText){
	if (!__sText)
		return true
	__sText = trim(__sText);
	if (__sText == '' || __sText == 'undefined')
		return true
	return false;
}
//********************************************************
function replaceAll(__sText, __sToReplace, __sToReplaceWith, __bCaseSensitive){
	if (__sToReplace)
		return __sText.replace(new RegExp(__sToReplace,(__bCaseSensitive==true)?'g':'ig'), __sToReplaceWith);
	return __sText
}
//********************************************************
function countString(__sText, __sToFind, __bCaseSensitive){
	__sText = (__bCaseSensitive)? __sText : __sText.toLowerCase();
	__sToFind = (__bCaseSensitive)? __sToFind : __sToFind.toLowerCase();
	var iLength = __sText.length;
	var iToFindLength = __sToFind.toString().length;
	var iWhile = 0;
	var iFound = 0;
	while (iWhile <= (iLength-iToFindLength)){
		if (__sText.substring(iWhile, (iWhile+iToFindLength) ) == __sToFind)
			iFound++
		iWhile ++;
	}
	return iFound;
}
//********************************************************
function findText(){
	var strSearchString = prompt ('Search For','');
	var oRng = document.body.createTextRange();
	for (var i = 0; oRng.findText(strSearchString)!=false; i++) {
		oRng.select();
	    document.execCommand('BackColor',false,'gray');
	    document.execCommand('ForeColor',false,'white');
	    oRng.collapse(false);
		oRng.select();
	}
}
//********************************************************
function eOnSelectText(){
	//try{
		sSelectText = document.selection.createRange()
	//}
	//catch(exception){
	//	alert (exception.description);
	//}
}
//********************************************************
function copyText(){
	//try{
		sSelectText.select();
		document.execCommand('Copy');
	//}
	//catch(exception){
	//	alert (exception.description);
	//}
}
//********************************************************
function cutText(){
	//try{
		sSelectText.select();
		document.execCommand('Cut');
	//}
	//catch(exception){
	//	alert (exception.description);
	//}
}
//********************************************************
function pasteText(){
	//try{
		sSelectText.select();
		document.execCommand('Paste');
	//}
	//catch(exception){
	//	alert (exception.description);
	//}
}
//********************************************************
function selectAllText(){
	//try{
		document.execCommand('SelectAll');
	//}
	//catch(exception){
	//	alert (exception.description);
	//}
}
//********************************************************
function setClipboard(__sText, __sType){
	__sType = __sType || 'Text';
	var bSuccess = window.clipboardData.setData(__sType, __sText);
}
//********************************************************
function getClipboard(__sType) {
	if (window.clipboardData) {
		__sType = __sType || 'Text';
		return(window.clipboardData.getData(__sType));
	} 
	else if (window.netscape) { 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var clip		= Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans	= Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		clip.getData(trans,clip.kGlobalClipboard);
		var str = new Object();
		var len = new Object();
		try {
			trans.getTransferData('text/unicode',str,len);
		}
		catch(e) {	return;}
		if (str) {
			if (Components.interfaces.nsISupportsWString) 
				str	= str.value.QueryInterface(Components.interfaces.nsISupportsWString);
			else if (Components.interfaces.nsISupportsString) 
				str	= str.value.QueryInterface(Components.interfaces.nsISupportsString);
			else
				str	= null;
		}
		if (str) 
			return(str.data.substring(0,len.value / 2));
	}
	return;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function getCharBefore(__oRange) {
	if (__oRange.move('character',-1) == -1) {
		__oRange.expand('character');
		return __oRange.text;
	} 
	else
		return null;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function getCharAfter(__oRange) {
	if (__oRange.expand('character')) {
		__oRange.move('character',1);
		__oRange.expand('character');
		return __oRange.text;
	} 
	else
		return null;
}

/**********************************************************
***********************************************************
*  Copyright 2004 (c) Aumediage S.P.R.L. All Rights Reserved.								*
*  This is a commercial software product, please visit												*
*  http://www.aumediage.net for more information. or send email to					*
*  aumediage@hotmail.com																						*
*  See http://www.aumediage.net for Commercial License Agreement				*
*  All Copyright statements must always remain in place in all files at all times	*
*		***** PLEASE NOTE: THIS IS NOT FREE SOFTWARE	*****						*
*				*****	IT MUST BE LICENSED FOR ALL USE	*****								*
************************************************************
***********************************************************/

