
var browserVersion = parseInt(navigator.appVersion);
var browserPlatform = navigator.platform;
var browserName = navigator.appName;

var isOpera = (this.browserName.indexOf('Opera') > -1) ? true : false;
var isNavigator = (this.browserName.indexOf('Netscape') > -1) ? true : false;
var isExplorer = (this.browserName.indexOf('Explorer') > -1) ? true : false;

var isMac = (this.browserPlatform.indexOf('Mac') > -1) ? true : false;

var isFour = (this.browserVersion == 4) ? true : false;

var isIE3 = ((this.browserVersion == 3) && (this.isExplorer)) ? true : false;
var isNS4 = ((this.browserVersion == 4) && (this.isNavigator)) ? true : false;
var isNS6 = ((this.browserVersion == 5) && (this.isNavigator)) ? true : false;


function setVisable( p_sId,  p_bVisible )
{
    if (isExplorer )
    {
        if ( false == p_bVisible )
        {
            document.all[p_sId].style.display = "none";
        }
        else if( true == p_bVisible )
        {
            document.all[p_sId].style.display = "";
        }
        else
        {
            //alert( "p_sId: " + p_sId );
            //alert( "p_bVisible: " + p_bVisible );
            //alert( "ERROR: arguments to setVisable must be the id of the object and either true or false" )
        }
    }
    else if (isNS6)
    {
        divObj = document.getElementById(p_sId);
        if ( false == p_bVisible )
        {
            divObj.style.display = "none";
        }
        else if( true == p_bVisible )
        {
            divObj.style.display = "";
        }
        else
        {
            //alert( "p_sId: " + p_sId );
            //alert( "p_bVisible: " + p_bVisible );
            //alert( "ERROR: arguments to setVisable must be the id of the object and either true or false" )
        }
    }
}

function toggleVisibleMsg( id )
{
    if (isExplorer )
    {
        if (document.all[id].style.display == "")
        {
            document.all[id].style.display = "none";
        }
        else
        {
            document.all[id].style.display = "";
        }
    }
    else if (isNS6)
    {
        divObj = document.getElementById(id);
        if (divObj.style.display == "")
        {
            divObj.style.display = "none";
        }
        else
        {
            divObj.style.display = "";
        }
    }
}

function popUp( name, href )
{
	var winwidth=640;
	var winheight=480;
	var toolbar="no";
	var personalbar="no";
	var location="no";
	var status="yes";
	var menubar="no";
	var resizable="yes";
	var scrollbars="yes";

	var string="width=" + winwidth + ",height=" + winheight + ",toolbar=" + toolbar + ",personalbar=" + personalbar + ",location=" + location + ",status=" + status + ",menubar=" + menubar + ",resizable=" + resizable + ",scrollbars=" + scrollbars;	
	var hwnd = window.open( href, name, string );
	hwnd.resizeTo( winwidth, winheight);
	hwnd.window.moveTo(0,0);

	if (navigator.appName == "Netscape")
	{
	    hwnd.focus()
	}
}

function popUp( name, href, toolbar, menubar, width, height )
{
	var winwidth=width;
	var winheight=height;
	var toolbar=toolbar;
	var personalbar="no";
	var location="no";
	var status="yes";
	var menubar=menubar;
	var resizable="yes";
	var scrollbars="yes";

	var string="width=" + winwidth + ",height=" + winheight + ",toolbar=" + toolbar + ",personalbar=" + personalbar + ",location=" + location + ",status=" + status + ",menubar=" + menubar + ",resizable=" + resizable + ",scrollbars=" + scrollbars;
	var hwnd = window.open( href, name, string );
	hwnd.resizeTo( winwidth, winheight);
	hwnd.window.moveTo(0,0);

	if (navigator.appName == "Netscape")
	{
	    hwnd.focus()
	}
}

function doAddAllRoles( obj, stringVal )
{
    for (var intLoop = 0; intLoop < obj.length; intLoop++)
    {
        addToHidden( stringVal, obj[intLoop].value );
    }
}


function doAddRoles( obj, stringVal )
{    
    //alert( obj );
    //alert( "before: " + stringVal );

    for (var intLoop = 0; intLoop < obj.length; intLoop++)
    {
        if( obj[intLoop].selected )
        {
     //       alert( obj[intLoop].value );
            addToHidden( stringVal, obj[intLoop].value );
        }
    }

   // alert( "after: " + StringVal );
}

function doRemoveRoles( obj, hidden )
{
   //alert("In doRemoveRoles");
   for (var intLoop = 0; intLoop < obj.length; intLoop++)
    {
        if( obj[intLoop].selected )
        {
            removeFromHidden( hidden, obj[intLoop].value );
        }
    }    
}

function removeFromHidden( str, removeStr )
{
   // alert("Value at start of removeFromHidden: " + str.name + "["+ str.value + "]");
    var indx = str.value.indexOf( removeStr);
    if( -1 != indx )
    {
        var tmpHiddenVal1=str.value.substring(0,indx);
        var indx2=indx+removeStr.length+1;
        var tmpHiddenVal2=str.value.substring(indx2,str.value.length);

        str.value="";
        str.value+=tmpHiddenVal1;
        str.value+=tmpHiddenVal2;

        if(str.value.length > 0 && str.value.substring(str.value.length-1, str.value.length) == ",")
        {
            str.value = str.value.substring(0, str.value.length-1);
        }
    }

   //alert("Value at end of removeFromHidden: " + str.name + "["+ str.value + "]")
}

function addToHidden( str, addStr )
{
   //alert("Value at start of addToHidden: " + str.name + "["+ str.value + "]");
    var indx = str.value.indexOf( addStr);
    //alert(indx);
    // Need to make sure it's the EXACT substring because one role might be a substring of another and that
    // would otherwise confuse the index check. Hence, the && condition

    /*var iAddStrLen = addStr.length;
    alert(str.value.substring(indx-1,indx));
    alert(str.value );
    alert( iAddStrLen );
    alert( indx );
    alert( indx+iAddStrLen );
    //alert(str.value.substring(indx+iAddStrLen-1,indx+iAddStrLen);
    if( -1 != indx  )
    //&& str.substring(indx-1,indx) == "," && str.substring(indx+addStr.length,indx+addStr.length+1)==","
    {

        return;
    } */

    if( str.value != "" )
    {
        str.value=str.value+",";
    }
//    alert(str.value.length-1+" | " + str.value.lastIndexOf(","))
//    if( str.value.length-1 == str.value.lastIndexOf(",") )
//    {
//        //alert("here");
//        str.value = str.value.substring( 0, str.length-1 );
//
//    }

    str.value = str.value + addStr;
   // alert("Value at end of addToHidden: " + str.name + "["+ str.value + "]");
}