function isIE()
{
    return "msie".test(navigator.userAgent) && !"opera".test(navigator.userAgent);
}

//var common_load = 0;

/**
 * Default Page initializations
 */
function init() 
{
}

function setWorking( in_flag )
{
/*    if( in_flag )
    {
        common_load++;
    }
    else
    {
        common_load--;
    }
    
    if( common_load === 1 && in_flag && $("pageIconDiv"))
    {
        var img = new Element("img", {"id":"workingImg","src":"styles/dolphin/working.gif"});
        img.injectAfter($("pageIconDiv"));
    }
    else if( common_load === 0 && !in_flag )
    {
        $("workingImg").remove();
        //$("workingDiv").setStyle("visibility","hidden");
    }*/
}


function home( userType, in_sid )
{
    var sid;
    if( in_sid !== undefined && in_sid !== null )
    {
        sid = in_sid;
    }
    else
    {
        sid = getRequestParameter('sid');
    }
    
    if(userType == 'STUDENT')
    {
        window.location=g_rootUri + 'studentMain.jsp?sid='+sid;
    }
    if(userType == 'TEACHER')
    {
        window.location=g_rootUri + 'teacherMain.jsp?sid='+sid;
    }
    else if(userType == 'ADMIN')
    {
        window.location=g_rootUri + 'adminMain.jsp?sid='+sid;
    }
    else if(userType == 'DISTRICTADMIN')
    {
        window.location=g_rootUri + 'districtadminMain.jsp?sid='+sid;
    }    
}

function showHelp( in_height )
{
    var sid = getRequestParameter('sid');
    var height = 320;
    if( in_height !== null ) {height = in_height;}
    Lightbox.show('tools/help.jsp?sid='+sid, 'SkillsTutor Help', 'waitForLoad=true, width=640, height='+height);
}

function updateDisplayName( in_newName )
{
    $('username').setText( in_newName );
}

function logout()
{
    var sid = getRequestParameter('sid');
    window.location=g_rootUri + 'logout.jsp?sid='+sid;
}

function userList( userType )
{
    var sid = getRequestParameter('sid');
    window.location=g_rootUri + 'userList.jsp?sid='+sid+'&userType='+userType;
}

function classList( userID )
{
    var sid = getRequestParameter('sid');
    var newURL = g_rootUri + 'classList.jsp?sid='+sid;
    if( userID !== undefined && userID !== null )
    {
        newURL += '&userID='+userID;
    }
    window.location= newURL;
}

function editClass( classID )
{
    var sid = getRequestParameter('sid');
    window.location = 'editClass.jsp?sid='+sid+'&classID='+classID;
}
    
function reports( userID )
{
    var sid = getRequestParameter('sid');
    var newURL = g_rootUri + 'reports.jsp?sid='+sid;
    if( userID !== undefined && userID !== null )
    {
        newURL += '&userID='+userID;
    }
    window.location=newURL;
}

function standardsList( userID )
{
    var sid = getRequestParameter('sid');
    var newURL = g_rootUri + 'standardsList.jsp?sid='+sid;
    if( userID !== undefined && userID !== null )
    {
        newURL += '&userID='+userID;
    }
    window.location=newURL;
}

function resizeLeftPane()
{
    window.setTimeout("common_resizeLeftPane();", 50);
}


function common_resizeLeftPane()
{
    //var newHeight = $('mainArea').getStyle('height').toInt();
    var newHeight = $('mainArea').getSize().scrollSize.y;
    var locatorEl = $('locator');
    if( locatorEl !== null )
    {
        newHeight += locatorEl.getStyle('height').toInt();
    }

    try
    {
        if( common_leftPaneFudgeVal !== undefined && common_leftPaneFudgeVal !== null ) 
        {    
            newHeight += common_leftPaneFudgeVal;
        }
    } catch( e ) {}
    if( newHeight < 450 ){ newHeight=450; }
    
    //var resizeEffect = new Fx.Styles('leftPane', {duration: 500, transition: Fx.Transitions.linear});
    //resizeEffect.start({'height':newHeight+'px'});
    $("leftPane").setStyle("height",newHeight+"px");
}

function editSite( siteID )
{
    var sid = getRequestParameter('sid');
    Lightbox.show('tools/editSite.jsp?sid='+sid, 'Edit Site Options', 'width=400, height=200');
}

function editProperties( userID )
{
    var sid = getRequestParameter('sid');
    Lightbox.show('tools/editUser.jsp?sid='+sid+'&userID=' + userID, 'Edit User Information', 'waitForLoad=true, width=400, height=320');
}

function getRequestParameter( in_parameterName ) 
{
    var queryString = window.top.location.search.substring(1);

    // Add '=' to the parameter name (i.e. parameterName=value)
    var parameterName = in_parameterName + '=';
    if ( queryString.length > 0 ) 
    {
        // Find the beginning of the string
        var begin = queryString.indexOf ( parameterName );
    
        // If the parameter name is not found, skip it, otherwise return the value
        if ( begin != -1 ) 
        {       
            // Add the length (integer) to the beginning
            begin += parameterName.length;
            
            // Multiple parameters are separated by the '&' sign
            var end = queryString.indexOf ( '&' , begin );
            
            if ( end == -1 ) 
            {
                end = queryString.length;
            }

            // Return the string
            return unescape ( queryString.substring ( begin, end ) );
        }
        // Return 'null' if no parameter has been found
        return 'null';
    }
} 

