function getRadioSelectedValue( rdo )
{
	for (i = 0; i < rdo.length; i++)
	{
		if (rdo[i].checked)
		{
			return rdo[i].value;
		}
	}
	return null;
}


function uCaseInput( obj )
{
	obj.value = obj.value.toUpperCase();
}

function lCaseInput( obj )
{
	obj.value = obj.value.toLowerCase();
}

// Q531 How can I capitalise the first letter of every word ?
function capitalizeInput( obj )
{
    var a = obj.value.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {

        var firstLetter = a[i].substring(0, 1).toUpperCase();
        var restOfWord = a[i].substring(1, a.length).toLowerCase();

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }

    obj.value = a.join(' '); // join it back together
}


//**************************************
// Name: Best Trim function
// Description:Sturdy javascript trim function. A must for good form validation! Good javascript trim functions are hard to come by.
// By: David Knipper
//
//
// Inputs:Trim(your_value);
//
// Returns:String
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.1JavaStreet.com/xq/ASP/txtCodeId.3621/lngWId.2/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
function trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = rTrim(TRIM_VALUE);
	TRIM_VALUE = lTrim(TRIM_VALUE);
	return TRIM_VALUE;
}

function rTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";

	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;
	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){}
		else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}

function lTrim(VALUE)
{
	var w_space = String.fromCharCode(32);

	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){}
		else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

function trimInput( obj )
{
	obj.value = trim( obj.value );
}


// removes all spaces (if any) in a string
function removeSpace( str )
{
	var i;
	var tmp;
	tmp = "";
	
	for( i=0; i<str.length; i++ )
	{
		if( str.charAt(i) != ' ' )
			tmp = tmp+str.charAt(i);
	}
	return tmp;
}


// remove specified tailing character(s)
// e.g, removeTailingChar( "abc;;;", ";" ) returns "abc"
function removeTailingChar( str, charToRemove )
{
	while(str.length>=1)
	{
		if( str.charAt(str.length-1)==charToRemove)
		{
			str = str.substr(0, str.length-1);
		}
		else
		{
			break;
		}
	}
	return str;
}

// 排序<select>，
// oSel为列表框对象
function sortList(oSel) 
{
	var ln = oSel.options.length;
	var arr = new Array(); // 这是关键部分

	// 将select中的所有option的value值将保存在Array中
	for (var i = 0; i < ln; i++)
	{
	  // 如果需要对option中的文本排序，可以改为arr[i] = oSel.options[i].text;
	  arr[i] = oSel.options[i].value; 
	}

	arr.sort(); // 开始排序

	// 清空Select中全部Option
	while (ln--)
	{
	  oSel.options[ln] = null;
	}

	// 将排序后的数组重新添加到Select中
	for (i = 0; i < arr.length; i++)
	{
	  oSel.add (new Option(arr[i], arr[i]));
	}
}

// 按给定的值(value),把<select>对象中的option选中
function setSelectedOptionByValue( sel, val )
{
	for( var i=0; i<sel.options.length; i++ )
	{
		if( sel.options[i].value==val )
		{
			sel.options[i].selected=true;
			break;
		}
	}
}

// 按给定的显示文本(text),把<select>对象中的option选中
function setSelectedOptionByText( sel, txt )
{
	for( var i=0; i<sel.options.length; i++ )
	{
		if( sel.options[i].text==txt )
		{
			sel.options[i].selected=true;
			break;
		}
	}
}

// appends an option to a given <select>
// 把一个新的option加到指定的<select>的最后
function appendOpt( sel, optText, optVal )
{
	sel.options[sel.options.length] = new Option(optText, optVal);
}

// removes specified option from a given <select>
// 把选中的option删除
function removeOpt( sel, optIndex )
{
	sel.options[optIndex] = null;
}

// moves the selected option from <select1> to <select2>
function moveOpt( sel1, sel2 )
{
	var selIndex, selText, selVal;

	selIndex = sel1.selectedIndex;
	if( selIndex >=0 )
	{
		selText = sel1.options[selIndex].text;
		selVal = sel1.options[selIndex].value;
		appendOpt( sel2, selText, selVal);
		removeOpt( sel1, selIndex);
	}
}