 /* ------------------------------------------*/
 /* java public function					  */
 /* get multiple picks from option select   */
 /* ------------------------------------------*/
 function select_multiple_pick(ctrl) 
 {
 
 	var selectedArray = new Array();
	var selObj = document.getElementById(ctrl);
	var i;
	var count = 0;
	for (i=0; i<selObj.options.length; i++) 
	{
		if (selObj.options[i].selected) 
		{
		selectedArray[count] = selObj.options[i].value;
		count++;
		}
	}
	
	return selectedArray;

 
 }
 /* ------------------------------------------*/
 /* java public function					  */
 /* ------------------------------------------*/
 function isset(  ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FremyCompany
    // +   improved by: Onno Marsman
    // *     example 1: isset( undefined, true);
    // *     returns 1: false
    // *     example 2: isset( 'Kevin van Zonneveld' );
    // *     returns 2: true
    
    var a=arguments; var l=a.length; var i=0;
    
    if (l==0) { 
        throw new Error('Empty isset'); 
    }
    
    while (i!=l) {
        if (typeof(a[i])=='undefined' || a[i]===null) { 
            return false; 
        } else { 
            i++; 
        }
    }
    return true;
}
 // trim function left
 
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}
 // trim function right
function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
 // trim function all
function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

 /* ------------------------------------------*/
 // format day or month user input ... 
function format_day_mo (ctrl)
{
	day_mo = ctrl.value;
	day_mo_len = day_mo.length;
	
	if (
		(day_mo_len == 1) &&
		(is_int(day_mo)) &&
		(day_mo > -1) &&
		(day_mo < 10) 
		)
	{
		day_mo = '0'+day_mo;
	}	
	
	ctrl.value = day_mo;

}
 
 /**************************************************************/
// replace_str(main_str, to_repace_str, replace_value)
//
// main_str = 'hello world of xintenger'
// to_replace = xinteger
// replace_value = 2
// return = 'hello world of 2'
//
/**************************************************************/

function replace_str(main_str, to_replace_str, replace_value)
{
	re = new RegExp(to_replace_str, 'g');
	str2 = main_str.replace(re, replace_value);
	
	return str2;
} 

/* ----------------------------------------- */
// html editor 

/* ----- on mouse over -----*/
	function selOn(ctrl,btName)
	{
	
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
	
			if (ctrl.disabled==false)
			{	
				ctrl.style.borderColor = '#000000';
				ctrl.style.backgroundColor = '#B5BED6';
				oldCursor = ctrl.runtimeStyle.cursor;
				ctrl.style.cursor = 'hand';
			}
		}
		else
		{
			ctrl.style.cursor = 'pointer';
		}
		}
		else
		{
		ctrl.style.cursor = 'pointer';
		}
		
	
	}
	/* ----- on mouse off -----*/
	function selOff(ctrl,btName)
	{
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
			if (ctrl.disabled==false)	
			{				
				ctrl.style.borderColor = '#D6D3CE';  
				ctrl.style.backgroundColor = '#D6D3CE';
				ctrl.style.cursor = oldCursor;
				
			}
		}
		}
	}
	/* ----- on mouse down -----*/
	function selDown(ctrl,btName)
	{
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
			if (ctrl.disabled==false)
			{
				ctrl.style.backgroundColor = '#8492B5';
			}
		}
		}

	}

	/* ----- on mouse up -----*/
	function selUp(ctrl,btName)
	{
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{

			if (ctrl.disabled==false)		
			{					
				ctrl.style.backgroundColor = '#B5BED6';					
			}
		}
		}
	}

	/* ----- doBold -----*/			
	function doBold(typeChar2)
	{		
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
				document.formFields.editor_content.innerHTML = 
						document.formFields.editor_content.innerHTML+"&lt;b&gt;&lt;/b&gt;";
			}
			else
			{
				document.formFields.editor_content.value = 
						document.formFields.editor_content.value+"<b></b>";
			}
		}
		else
		{
			document.formFields.editor_content.value = 
						document.formFields.editor_content.value+"<b></b>";
		}
	}

	function doUnderline()
	{		
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
				document.formFields.editor_content.innerHTML = 
					document.formFields.editor_content.innerHTML+"&lt;u&gt;&lt;/u&gt;";	
			}
			else
			{
				document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<u></u>";
			}
		}
		else
		{
			document.formFields.editor_content.value = 
				document.formFields.editor_content.value+"<u></u>";	
		}
			
	
	}
	function doItalic()
	{			
	if (browser_array[0] == "Win")
	{
		if (browser_array[1] == "IE")
		{
				document.formFields.editor_content.innerHTML = 
					document.formFields.editor_content.innerHTML+"&lt;i&gt;&lt;/i&gt;";			
			}
			else
			{
					document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<i></i>";			
			}
		}
		else
		{
			document.formFields.editor_content.value = 
			document.formFields.editor_content.value+"<i></i>";			
		}
				
	
	}
	function doCRetrun()
	{		
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
				document.formFields.editor_content.innerHTML = 
					document.formFields.editor_content.innerHTML+"&lt;p&gt;&lt;/p&gt;";			
			}
			else
			{
				document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<p></p>";			
			}
		}
		else
		{
		document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<p></p>";			
		}
			
	
	}
	function doLink()
	{		
		if (browser_array[0] == "Win")
		{
		if (browser_array[1] == "IE")
		{
				document.formFields.editor_content.innerHTML = 
					document.formFields.editor_content.innerHTML+"&lt;a href=\"\"&gt;&lt;/a&gt;";		
			}
			else
			{
				document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<a href=\"\"></a>";	
			}
		}
		else
		{
		document.formFields.editor_content.value = 
					document.formFields.editor_content.value+"<a href=\"\"></a>";	
		}	
	
	}
/* ---- end html editor ---- */
 
 // Detect browser ...
function browserSniffer ()
{
	uAgent = navigator.userAgent;
	
	if (navigator.platform.indexOf("Win32") != -1)
	{
	if (uAgent.indexOf("Netscape") != -1) browser = "Win:NS";
	else if (uAgent.indexOf("Opera") != -1) browser = "Win:Op";
	else if (navigator.appName.indexOf ("Explorer") != -1) browser = "Win:IE";
	else  if (uAgent.indexOf("Mozilla") != -1) browser = "Win:Mo";
	else browser = "Unknown";
	}
	else if (navigator.platform.indexOf("Mac") != -1)
	{
	if (uAgent.indexOf("Netscape") != -1)  browser = "Mac:NS";
	else if (uAgent.indexOf("Opera") != -1)  browser = "Mac:Op";
	else if (navigator.appName.indexOf ("Explorer") != -1)  browser = "Mac:IE";
	else  if (uAgent.indexOf("Mozilla") != -1) browser = "Mac:Mo";
	else browser = "Unknown";
	}
	else //we assume Linux/UNIX
	{
	if (uAgent.indexOf("Netscape") != -1)  browser = "Lin:NS";
	else if (uAgent.indexOf("Opera") != -1)  browser = "Lin:Op";
	else if (navigator.appName.indexOf ("Explorer") != -1)  browser = "Lin:IE";
	else  if (uAgent.indexOf("Mozilla") != -1) browser = "Lin:Mo";
	else browser = "Unknown";
	}
	if ((uAgent.indexOf("5") != -1) || (uAgent.indexOf("6") != -1) || (uAgent.indexOf("7") != -1))
	version = "5plus";
	else
	version = "4minus";
	
	return(browser + ":"  + version);
}

/* ---------------------------------------------------------- */
/* ----- read error messages from an error message table -----*/

function getMsg(msgKey,msgLanguage)
{
	returnMsg = "Error msg not found";
	for (i=0;i<msgArray.length;i++)
	{
		if (
			(msgArray[i].key == msgKey) &&
			(msgArray[i].language == msgLanguage) 
			)
		{
			returnMsg = msgArray[i].msg;
			break;
		}
	}
	return returnMsg;
}
/* ----------- is empty ------------ */

function isEmpty(x)
{	
	var re = new RegExp(" " , "g");
	var x = x.replace(re, "");				// trim all spaces off
	if (
		(x == "") ||
		(x == null)
		)
	{
		return true;
	}
	return false;
}

/* ----------- is number even ------------ */

function numberIsEven(x)
{	
	return is_int(x / 2);	
}

/* ---- is it an integer ------*/

function is_int(x)
{
	
	var y = parseInt(x);
	if (
		(isNaN(y)) ||
		(y != x)
		)
	{
		return false;
	}
	else
	{
		return true;
	}
	
}
/* ---------- money format ----------- */

function moneyFormat(moneyValue, MONEY_THOUSAND_SEP, MONEYDEC_SEP)
{
	//MONEYDEC_SEP = ",";
	//MONEY_THOUSAND_SEP =  ".";
	
	
	moneyStr3 = "";			

	moneyValue = parseFloat(moneyValue);

	if (!(isNaN(moneyValue)))
	{
		moneyValue = moneyValue * 100;
		moneyValue = Math.round(moneyValue, 2);
		moneyValue = moneyValue / 100;
		var moneyValue = new String(moneyValue);

		//alert ("1: "+moneyValue+"");

		moneyStr = moneyValue;			
		
		if (is_int(moneyValue))
		{

			//$moneyStr3 = $moneyValue.".00";
			//$moneyStr3 = ereg_replace ("[.]",$MONEYDEC_SEP,$moneyStr3);

			moneyStr3 = moneyValue+".00";
			//alert (""+moneyStr3+"");

			var re = ".";
			moneyStr3 = moneyStr3.replace (re, MONEYDEC_SEP); 

			//alert (""+moneyStr3+"");
		}
		else
		{		
			//$moneyStr2 = substr($moneyStr, strlen($moneyStr) - 2);
			//$moneyStr2 = ereg_replace ("[.]","",$moneyStr2);			

			moneyStr2 = moneyStr.substring (moneyStr.length - 3);
			
			//var re = ".";
			//moneyStr2 = moneyStr2.replace (re, "");
			
			
			if (					
				(moneyStr2.length < 2)
				)
			{
				//$moneyStr3 = ($moneyStr2 < 10) ? $moneyStr."0": $moneyStr;	
				moneyStr3 = (moneyStr2 < 10) ? ""+moneyStr+"0": moneyStr;	
			}
			else
			{
				//$moneyStr3 = $moneyStr;
				moneyStr3 = moneyStr;
			}
			//$moneyStr3 = ereg_replace ("[.]",$MONEYDEC_SEP,$moneyStr3);
			var re = ".";
			moneyStr3 = moneyStr3.replace (re, MONEYDEC_SEP); 
			//alert ("str3>"+moneyStr3+"");
			
		}				
		
			
		//$moneyStr4 = substr($moneyStr3,0,strlen($moneyStr3)-3);
		moneyStr4 = moneyStr3.substring(0,moneyStr3.length - 3);
		//$decimalStr = substr($moneyStr3,strlen($moneyStr3)-3);		
		decimalStr = moneyStr3.substring((moneyStr3.length - 3))

		strNumber = formatNumber(moneyStr, 2);			
		decimalStrX = moneyStr3.substring((strNumber.length - 2))		
			

		decimalStr = (decimalStrX.length < 2) ? ""+decimalStr+"0" : decimalStr;

		//alert ("dec: "+decimalStr+"");
		
		
		//$codedMoneyArray = array();
		//$codedMoneyArray2 = array();

		var codedMoneyArray = new Array();
		var codedMoneyArray2 = new Array();
		
		//$moneyArray = array();
		var moneyArray = new Array();
		var moneyArray2 = new Array();

		//$moneyArray = preg_split('//', $moneyStr4, -1, PREG_SPLIT_NO_EMPTY);	
		moneyArray = moneyStr4.split('');
		
		w = 0;

		// REVERT ARRAY

		//for ($n=(count($moneyArray) - 1); $n>-1; $n--)
		for (n=(moneyArray.length - 1); n>-1; n--)
		{
			moneyArray2[w] = moneyArray[n];
			w++;
		}
		
		//$moneyArray2Len = (isset($moneyArray2)) ? count($moneyArray2) : 0;
		moneyArray2Len = (moneyArray2 != "") ? moneyArray2.length : 0;
		// add thousand separator
		w = 0;
		for (n=0; n<moneyArray2.length; n++)
		{
			
			if ((is_int((n+1)/3)) &&
				(moneyArray2[n+1] != "")
				)
			{
				
				codedMoneyArray[w] = moneyArray2[n];
				codedMoneyArray[w+1] =  MONEY_THOUSAND_SEP;
				w = w + 2;
			}
			else
			{
				codedMoneyArray[w] = moneyArray2[n];
				w++;
			}			
		}

		// REVERT ARRAY
		w = 0;
		first_n = (codedMoneyArray.length - 1);
		for (n=(codedMoneyArray.length - 1); n>-1; n--)
		{			
			if (
				(first_n == n) &&
				(codedMoneyArray[first_n] == '.')
				)
			{
				
			}
			else
			{
				codedMoneyArray2[w] = codedMoneyArray[n];
				w++;	
			}
			
		}		
		
		//codedMoneyStr3 = implode("",codedMoneyArray2);	
		codedMoneyStr3 = codedMoneyArray2.join("");	
		
		

		return codedMoneyStr3+decimalStr;			
	}
	else
	{
		return "";
	}		

}

/* --- format Number ------*/

function formatNumber (num, decplaces) 
{
    // convert in case it arrives as a string value
    num = parseFloat(num);
    // make sure it passes conversion
    if (!isNaN(num)) {
        // multiply value by 10 to the decplaces power;
        // round the result to the nearest integer;
        // convert the result to a string
        var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
        // exponent means value is too big or small for this routine
        if (str.indexOf("e") != -1) {
            return "Out of Range";
        }
        // if needed for small values, pad zeros
        // to the left of the number
        while (str.length <= decplaces) {
            str = "0" + str;
        }
        // calculate decimal point position
        var decpoint = str.length - decplaces;
        // assemble final result from: (a) the string up to the position of
        // the decimal point; (b) the decimal point; and (c) the balance
        // of the string. Return finished product.
        return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
    }
	else 
	{
        return "NaN";
    }
}

/* --- call getRandom ... to get a random number ------*/

function getRandom()
{		
	random.m=714025; random.a=4096; random.c=150889; 
	random.seed = (new Date()).getTime()%random.m;
	return random.seed;
}
function random() 
{   
	random.seed = (random.seed*random.a + random.c) % random.m; 
	return random.seed / random.m; 
} 
   
   
