function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}
function cent(amount) 
{ 
	return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount); 
} 
function isan(string) {
    if (string.length == 0)
        return false;
    for (var i=0;i < string.length;i++)
        if (((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9')) &&(string.substring(i,i+1)!='.'))
            return false;
    return true;
}
String.prototype.isEmail = function()
{ 
    return( /^[\w~][\w\.\-~]*[\w~]@[\w~][\w\-~]*[\.][\w~][\w\.\-~]*[\w]$|^$/.test(this) && !/[\.]{2}/.test(this) ); 
}
function validateOnBlur(inputform){
}
function focusFirstOpenField(objForm, strDefault) {
	var blnSet = false;
	if (strDefault != "" && objForm[strDefault].value == "") {
		blnSet = true;
		objForm[strDefault].focus();
	}
	for (var i = 0; i < objForm.elements.length && !blnSet; i++) {
		if ((objForm.elements[i].type == "text" || objForm.elements[i].type == "textarea" || objForm.elements[i].type == "file" || objForm.elements[i].type == "password") && objForm.elements[i].value == "") {
			try {
				objForm.elements[i].focus();
				blnSet = true;
			} catch (e) {
			}
		}
	}
	if (!blnSet && strDefault != "") {
		objForm[strDefault].focus();
	}
}
function getPopupProps(intHeight, intWidth, strResize, strScrollbars) {
	var rv = "";
	rv += "toolbar=no,location=no,directories=no,status=no,menubar=no,";
	rv += "scrollbars="+strScrollbars+",resizable="+strResize+",height="+intHeight+",width="+intWidth ;
	return rv
}
function addToSelectBox(msbFrom, msbTo, strValues, strDelimiter) {	
	var i, j, arrValues, rePattern;
	strValues = trim(strValues);
	rePattern = new RegExp("\\s*" + strDelimiter + "\\s*");
	arrValues = strValues.split(rePattern);
	for (i=0; i < arrValues.length; i++){
		selectThis(msbFrom, arrValues[i]);
	}
	selectBoxMove(msbFrom, msbTo,0);
}
function clearSelBox(msbFrom, msbTo) {
	var i;
	if(msbFrom.options.length ==0){
		alert("Please select the categories.");
	}else
	{
		for (i=0; i < msbFrom.options.length; i++){
			msbFrom.options[i].selected = true;
		}
		selectBoxMove(msbFrom, msbTo,0);	
	}
}
function isSelectBox(msbInput, strValue) {
	var i;

	for (i = 0; i < msbInput.options.length; i++) {
		if (strValue == msbInput.options[i].value) {
			return true;
		} 
	}
	return false;		
}	
function selectBoxMove(msbFrom, msbTo, iLimitOne) {
	var arrFrom = new Array();
	var arrTo = new Array();
	var arrLookup = new Array();
	var i, j, lenFrom, lenTo;
	if(msbFrom.options.length < 1)
	{
		alert("Please select the categories.");
		return;
	}
	if (iLimitOne==1 && msbTo.options.length > 0) {
		return;
	}
	for (i = 0; i < msbTo.options.length; i++) {
		arrLookup[msbTo.options[i].text] = msbTo.options[i].value;
		arrTo[i] = msbTo.options[i].text;
	}
	lenFrom = 0;
	lenTo = arrTo.length;
	noofselected=0;
	for(i = 0; i < msbFrom.options.length; i++) {
		arrLookup[msbFrom.options[i].text] = msbFrom.options[i].value;
		if (!isSelectBox(msbTo, msbFrom.options[i].value)) { 
			if (msbFrom.options[i].selected && msbFrom.options[i].value != "") {
				arrTo[lenTo] = msbFrom.options[i].text;
				lenTo++;
				noofselected++;
			} else {
				arrFrom[lenFrom] = msbFrom.options[i].text;
				lenFrom++;
			}
		}
	}
	if(noofselected==0)
	{
		alert("Select at least one contact to move.");
	}
	msbFrom.length = 0;
	msbTo.length = 0;
	for(j = 0; j < arrFrom.length; j++) {
		var optFrom = new Option();
		optFrom.value = arrLookup[arrFrom[j]];
		optFrom.text = arrFrom[j];
		msbFrom[j] = optFrom;
	}
	for(j = 0; j < arrTo.length; j++) {
		var optTo = new Option();
		optTo.value = arrLookup[arrTo[j]];
		optTo.text = arrTo[j];
		msbTo[j] = optTo;
	}
}
function saveSelectBox(msbInput){
	var s, i;
	s = "";
	for (i = 0; i < msbInput.options.length; i++) {
		s += "<option value=" + msbInput.options[i].value + ">";
		s += msbInput.options[i].text;
		s += "</option>";
	}
	return s;
}
function saveSelectBoxEmail(msbInput){
	var s, arrNames, i, delimiter = "", txtInput;
	s = "";
	for (i = 0; i < msbInput.options.length; i++) {
		if ( s != "" )  { delimiter = ";" ; } 
		s += delimiter;
		txtInput = msbInput.options[i].text;
		arrNames = txtInput.split(/\s*,/);
		s += arrNames[0] + " " + arrNames[1];
	}
	return s;
}
function saveSelectBoxValues(msbInput)
{
	var s, i, delimiter = "";
	s = "";
	for (i = 0; i < msbInput.options.length; i++) {
		if ( s != "" )  { delimiter = ";" ; } 
		s += delimiter;
		s += msbInput.options[i].value;
	}
	return s;
}
function refresh() {
	if (document.mainform) {
		submitPage();
	}
}
function submitPage() {
	document.mainform.submit();
}