function encodeURI( sVar)
{
    return sVar;
}
function AddOption( oControl, sValue, sData )
{
        if (oControl.disabled)
            return;
        //Remove any line breaks
        while( sValue.search( '\r\n' ) != -1 )
                sValue = sValue.replace( '\r\n', ' ' );
        while( sValue.search( '\r' ) != -1 )
                sValue = sValue.replace( '\r', ' ' );
        while( sValue.search( '\n' ) != -1 )
                sValue = sValue.replace( '\n', ' ' );

        var sValue2 = sValue
        while( sValue2.search( ' \\\\ ' ) != -1 )
                sValue2 = sValue2.replace( ' \\ ', '' );

        while( sData.search( '\r\n' ) != -1 )
                sData = sData.replace( '\r\n', ' ' );
        while( sData.search( '\r' ) != -1 )
                sData = sData.replace( '\r', ' ' );
        while( sData.search( '\n' ) != -1 )
                sData = sData.replace( '\n', ' ' );


        if( sData.length == 0 )
                sData = sValue

        if( sValue2.length > 0 )
        {
                oControl.options[ oControl.length ] = new Option( sValue, sData, false, false);
        }
}

function RemoveOption( oControl )
{
        if (oControl.disabled)
            return;
        for( var nCurrent = oControl.length - 1; nCurrent >= 0; nCurrent-- )
        {
                if( oControl.options[ nCurrent ].selected )
                {
                        oControl.options[ nCurrent ] = null;
                }
        }  
}

function MoveOption( oSrcControl, oDstControl, sAppendValue, bDelete )
{
        if (oSrcControl.disabled || oDstControl.disabled)
            return;
        for( var nCurrent = oSrcControl.length - 1; nCurrent >= 0; nCurrent-- )
        {
                if( oSrcControl.options[ nCurrent ].selected )
                {

                        var sValue = new String( oSrcControl.options[ nCurrent ].text );
                        var asValues = sValue.split(' \\'); //Note: No trailing space

                        var sData = new String( oSrcControl.options[ nCurrent ].value );
                        var asDatas = sData.split(' \\'); //Note: No trailing space

                        if( asValues.length > 0 )
                        {
                                AddOption( oDstControl, asValues[0] + sAppendValue,  asDatas[0] + sAppendValue );

                                if( bDelete )
                                {
                                        if (document.all)
                                        {
                                        	// fix for strange IE behavior
                                        	// @see Jira Defect CC-358 : http://apps.dytech.com.au/jira/secure/ViewIssue.jspa?key=CC-358
	                                        
	                                        oSrcControl.options[ nCurrent ].removeNode();
                                        }
                                        else
                                        {
                                        	oSrcControl.options[ nCurrent ] = null;
                                        }
                                }
                        }

                }
        }  
        

}

function CopyOption( oSrcControl, oDstControl )
{
        for( var nCurrent = oSrcControl.length - 1; nCurrent >= 0; nCurrent-- )
        {
                if( oSrcControl.options[ nCurrent ].selected )
                {

                        var sValue = new String( oSrcControl.options[ nCurrent ].text );
                        var sData = new String( oSrcControl.options[ nCurrent ].value );

                        AddOption( oDstControl, sValue,  sData );
                }
        }  
}

function SelectAll( oControl )
{
	if(oControl)
	{
		
        for( var nCurrent = 0; nCurrent < oControl.length; nCurrent++ ) 
        {
                oControl.options[ nCurrent ].selected = true;
        }
    }
}

function SelectVal( oControl, val )
{
        for( var nCurrent = 0; nCurrent < oControl.length; nCurrent++ ) 
        {
                if (oControl.options[ nCurrent ].value == val)
                    oControl.options[ nCurrent ].selected = true;
                else oControl.options[ nCurrent ].selected = false;
        }
}

function CtrlOff()
{
    return false;
}

function DisableText( oControl, bVis )
{
        var mHandler = null;
        if (bVis == true)
            mHandler = CtrlOff;

        oControl.disabled = bVis;
        oControl.onkeydown = mHandler;
}

function DisableAll( oControl, bVis )
{
        oControl.disabled = bVis;
}

function DisableBoxes( oControl, bVis )
{
        var mHandler = null;
        if (bVis == true)
            mHandler = CtrlOff;
        oControl.disabled = bVis;
        oControl.onlick = mHandler;
        for( var nCurrent = 0; nCurrent < oControl.length; nCurrent++ ) 
        {
                oControl[ nCurrent ].disabled = bVis;
                oControl[ nCurrent ].onclick = mHandler;
        } 
}

function MoveOptionUp( oSrcControl )
{
        if (oSrcControl.disabled)
		return;		
        for( var nCurrent = 1; nCurrent < oSrcControl.length; nCurrent++ )
        {
                if( oSrcControl.options[ nCurrent ].selected )
                {
			var cur = new Option (oSrcControl.options [ nCurrent ].text, oSrcControl.options [ nCurrent ].value, false, false);
			var other = new Option (oSrcControl.options [ nCurrent - 1 ].text, oSrcControl.options [ nCurrent - 1 ].value, false, false);
			
			var curSel = oSrcControl.options [ nCurrent ].selected;
			var otherSel = oSrcControl.options [ nCurrent - 1 ].selected;
			
			oSrcControl.options [ nCurrent ] = other;
			oSrcControl.options [ nCurrent - 1 ] = cur;
			
			oSrcControl.options [ nCurrent ].selected = otherSel;
			oSrcControl.options [ nCurrent - 1].selected = curSel;
		}
        }  
}

function MoveOptionDown( oSrcControl )
{
        if (oSrcControl.disabled)
		return;		
        for( var nCurrent = oSrcControl.length - 2; nCurrent >= 0; nCurrent-- )
        {
                if( oSrcControl.options[ nCurrent ].selected )
                {
			var cur = new Option (oSrcControl.options [ nCurrent ].text, oSrcControl.options [ nCurrent ].value, false, false);
			var other = new Option (oSrcControl.options [ nCurrent + 1 ].text, oSrcControl.options [ nCurrent + 1 ].value, false, false);
			
			var curSel = oSrcControl.options [ nCurrent ].selected;
			var otherSel = oSrcControl.options [ nCurrent + 1 ].selected;
			
			oSrcControl.options [ nCurrent ] = other;
			oSrcControl.options [ nCurrent + 1 ] = cur;
			
			oSrcControl.options [ nCurrent ].selected = otherSel;
			oSrcControl.options [ nCurrent + 1].selected = curSel;
		}
        }  
}

