    ///////////////////////////////////////////////////////////////////////////
    //                                                                       //
    //  START OF FILE                                                        //
    //                                                                       //
    //  - File Name:        /online/js/standard_functions.js                 //
    //  - File Type:        Java Script File                                 //
    //  - Purpose:          Defines functions which are used widly over the  //
    //                      entire site                                      //
    //  - Editing:          Level 4                                          //
    //  - Description:      Defines many different functions; none of which  //
    //                      are so critical that they require their own file //
    //  - Notes:                                                             //
    //  - Created By:       onassar (unknown precise date)                   //
    //  - Editted By:                                                        //
    //  - Enhancements:     AJAX profile card doesn't work in Opera          //
    //                                                                       //
    ///////////////////////////////////////////////////////////////////////////

    //    Name:        Enter Key Submit
    //    Purpose:     To allow a form to be submitted by hitting the enter key
    //    Variables:   1) var key         -    the key that was pressed
    //                 2) var form_name   -    the name of the form which is to be submitted
    //    Returns:     Nothing
    //    Notes:       This function has both Netscape (Firefox) split, since sometimes firefox does
    //                 not follow properly (eg. multiple enter's needed)
    function enter_key_submit(key,form_name)
    {
        // if the browser is Mozilla/Netscape based, submit form via enter only possible way (but with bugs)
        if(navigator.appName=="Netscape")
        {
            // if it was the enter key that was pressed
            if(key==13)
            {
                // submit the form that was sent in
                setTimeout("document."+form_name+".submit()",100);
            }
        }
        // otherwise if it's Internet Explorer or other browers, do standard way
        else
        {
            // if it was the enter key that was pressed
            if(window.event.keyCode==13)
            {
//                document.allergy_24_edit.submit();
                // submit the form that was sent in
//                setTimeout("document."+form_name+".submit()",0);
            }
        }
    }

    //    Name:        Increase Login Length
    //    Purpose:     To increase the length of login using javascript, and manage logout
    //    Variables:   1) var login_length    -  the length of time the user has been logged in
    //    Returns:     Nothing
    //    Notes:       Forwards user to timed_logout page if 10 minutes has elapsed
    function increase_login_length(login_length)
    {
        // if the length of time has reached the max (10 minutes), then popup page
        if(login_length==900)
        {
            document.location.href    =    gv_html_path+'security/timed_logout/';
        }
        // otherwise use recursion after 5 seconds to check how long they've been logged in for
        else
        {
            setTimeout("increase_login_length("+(login_length+5)+")",5000);
        }
    }

    function adjust_options_redirect(field)
    {
        obj  =    document.getElementById(field);
        op   =    obj.selectedIndex;
        scrollTop =    obj.scrollTop;

        // create timeout function that calls adjust_options
        function_call  =    'adjust_options(\''+field+'\')';
        setTimeout(function_call,1);
    }

    //    Name:           Adjust Options
    //    Purpose:        To adjust the selected options in a multiple drop down select field
    //    Variables:      1) var field  -        the field who's options are to be adjusted
    //    Returns:        Nothing
    //    Notes:          Manages selecting and deselecting all options in the field
    //    Enhancements:   Focus on last clicked, not on 2nd to last clicked
    //                    Allow for multiple deselect
    //                    Ctrl-Alt Tabbing between tabs poses problems, since unknown whether CTRL Key is
    //                    pressed or not
    function adjust_options(field)
    {
        obj  =    document.getElementById(field);
        op   =    obj.selectedIndex;
        scrollTop =    obj.scrollTop;

        // if the field is for students
        if(field=='student_recip')
        {
            field_proper_name   =    'student_recip';
            selected_options    =    selected_options_stud;
        }
        // otherwise if the field is for staff
        else if(field=='staff_recip')
        {
            field_proper_name   =    'staff_recip';
            selected_options    =    selected_options_staf;
        }
        // otherwise if the field is for guardians
        else if(field=='guardian_recip')
        {
            field_proper_name   =    'guardian_recip';
            selected_options    =    selected_options_guar;
        }
        // otherwise if the field is for classes
        else if(field=='class_recip')
        {
            field_proper_name   =    'class_recip';
            selected_options    =    selected_options_clas;
        }
        // otherwise if the field is for grades
        else if(field=='grade_recip')
        {
            field_proper_name   =    'grade_recip';
            selected_options    =    selected_options_grad;
        }
        // otherwise if the field is for grades
        else if(field=='search_criteria')
        {
            field_proper_name   =    'search_criteria';
            selected_options    =    selected_options_crit;
        }

        // define the select box which should be used
        select_box = document.getElementById(field_proper_name);

        // if it wasn't the control key that was pressed
        if(controlKey==false)
        {
            // create variable that checks whether the option was previously selected
            var was_selectedq;

            // loop through the array
            for(i=0;i< selected_options.length;i++)
            {
                // if the option in question exists in the array
                if(selected_options[i]==op)
                {
                    // remove it from the array, since it was previously selected
                    selected_options.splice(i,1);
                    // set the variable that it was selected
                    was_selectedq    =    true;
                    // break the loop
                    break;
                }
                // otherwise if the option is not in the array
                else
                {
                    // set the variable that it was not selected previously
                    was_selectedq    =    false;
                }
            }

            // loop through all the options and set them in the html to be selected
            for(i=0; i< selected_options.length; i++)
            {
                // set the option to be selected since it is in the array
                select_box[selected_options[i]].selected = true;
            }

            // if it was selected
            if(was_selectedq==true)
            {
                // unselect the option
                select_box[op].selected = false;
            }
            // otherwise if it wasn't
            else
            {
                // loop through all the available options
                for(j=0;j< obj.length;j++)
                {
                    // set was_selected to null, since now being used to check all options in html
                    was_selected  =  false;

                    // check whether the option in html at j is in the true, and already in array
                    if(obj[j].selected==true)
                    {
                        // loop through all of the entries in the selected_options array
                        for(k=0;k< selected_options.length; k++)
                        {
                            // if the selected option is already in the selected_options array
                            if(selected_options[k]==j)
                            {
                                // set that it was already in there
                                was_selected  =  true;
                            }
                        }

                        // if the option was not already in the array
                        if(was_selected==false)
                        {
                            // add the option to the array to keep track whether that it was selected
                            selected_options[selected_options.length] = j;
                        }
                    }
                }
            }
        }
        else
        {
            pre_selected_field   =    document.getElementById(field_proper_name);
            pre_selected_size    =    pre_selected_field.length;
            pre_selected         =    new Array();

            // loop through the array of all options
            for(i=0;i< pre_selected_size;i++)
            {
                pre_selected_option    =    pre_selected_field.options[i].selected;
                // if an option is pre-selected
                if(pre_selected_option==true)
                {
                    // add that option to the selected_options array (temp. holder)
                    pre_selected[pre_selected.length]    =  i;
                }
            }
            selected_options    =    pre_selected;

            switch (field_proper_name)
            {
                case 'student_recip':
                    selected_options_stud    =    selected_options;
                    break;
                case 'staff_recip': 
                    selected_options_staf    =    selected_options;
                    break;
                case 'guardian_recip': 
                    selected_options_guar    =    selected_options;
                    break;
                case 'class_recip':
                    selected_options_clas    =    selected_options;
                    break;
                case 'grade_recip': 
                    selected_options_grad    =    selected_options;
                    break;
                case 'search_criteria':
                    selected_options_crit    =    selected_options;
                    break;
            }
        }

        // manage focussing on proper element
/*        if(obj[op].selected==true)
        {
//            obj[op].selected = true;
        }
        else if(obj[op].selected==false)
        {
//            obj[op].selected = true;
//            obj[op].selected = false;
        }*/
        obj.scrollTop =         scrollTop;

//        alert(obj.options[op].selected)//=false;
/*
        obj.options[op].selected=true;*/
    }

    //    Name:        Input Focus
    //    Purpose:     to focus in on a specific field
    //    Variables:   1) var field    -    the field which should be focussed on
    //    Returns:     Nothing
    //    Notes:       Commented out since in order for function to work properly, needs to be integrated with onLoad
    //                 function on all pages (as to not focus on the element before the page has fully loaded the dynamic
    //                 hidden content)
    function input_focus(field)
    {
//        document.getElementById(field).focus();
//        document.getElementById(field).select();
    }

    //    Name:        Adjust Date Function
    //    Purpose:     To adjust a date such that it is presented in a readble way
    //    Variables:   1) var field_value    -    the field's value (eg. the date)
    //                 2) var field_html     -    the field which should have it's html altered
    //    Returns:     Nothing
    //    Notes:       Forwards user to timed_logout page if 10 minutes has elapsed
    function adjust_date_function(field_value,field_html)
    {
        // store the ogiginal date
        orig_birthdate    =    document.getElementById(field_value).value;

        // create array with month names
        monthName         =    new Array ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

        // access the year, month, and day from the direct value (field_value)
        inputYear         =    orig_birthdate.substring(0,4);
        inputMonth        =    orig_birthdate.substring(5,7);
        inputDay          =    orig_birthdate.substring(8,10);

        // if the month starts with 0, then remove that 0
        if(inputMonth.substring(0,1)=='0')
        {
            inputMonth    =    inputMonth.substring(1,2);
        }
        // if the day starts with 0 (eg. 04, then remove it)
        if(inputDay.substring(0,1)=='0')
        {
            inputDay      =    inputDay.substring(1,2);
        }

        // store the month name and day in the text to be written
        new_text          =    monthName[(inputMonth-1)]+'. '+inputDay;

        // if the day should have the 'st' extension
        if(inputDay=='1' || inputDay=='21' || inputDay=='31')
        {
            new_text      +=   'st, '+inputYear;
        }
        // otherwise if the day should have the 'nd' extension
        else if(inputDay=='2' || inputDay=='22')
        {
            new_text      +=   'nd, '+inputYear;
        }
        // otherwise if the day should have the 'rd' extension
        else if(inputDay=='3' || inputDay=='23')
        {
            new_text      +=   'rd, '+inputYear;
        }
        // otherwise, the day must have the 'th' extension
        else
        {
            new_text      +=   'th, '+inputYear;
        }

        // if the calendar return value contains 'undefined' (since no 0000-00-00 as default), print (unknown)
        if(new_text.match('undefined'))
        {
            // write (unknown)
            document.getElementById(field_html).innerHTML    =    '(unknown)';
        }
        else
        {
            // write the date format to the page
            document.getElementById(field_html).innerHTML    =    new_text;
        }
    }

    // store global javascript varaibles
    // variable that stores xmlHTTP data
    var xmlHttp;
    // the profile card which may be popped up
    var profile_card_ID                                      =    0;
    // store which card is CURRENTLY open (before new card opened)
    var open_card_ID                                         =    0;
    // the horizontal position of the mouse, upon clicking on a profile card
    var profile_card_pos_x                                   =    0;
    // the vertical position of the mouse, upon clicking on a profile card
    var profile_card_pos_y                                   =    0;
    // the border for the profile card
    var profile_card_border                                  =    '';

    // store array which keeps track of which profile cards have been opened
    var opened_profile_cards                                 =    new Array();

    //    Name:         Get Profile Card
    //    Purpose:      To retrieve the HTML code and manage a profile to be popped up
    //    Variables:    1) var field          -    the field (div) where the profile card will be stored (the code)
    //                  2) var border         -    the colour of the border for the profile card
    //                  3) var ID             -    the ID of the user profile
    //                  4) var avatar         -    the user profile's avatar
    //                  5) var name           -    the name of the user
    //                  6) var target_type    -    the user profile type
    //                  7) var pos_x          -    the position of the mouse (event)
    //                  8) var pos_y          -    the position of the mouse (event)
    //    Returns:      Nothing
    //    Notes:        Outputs the card directly
    //                  Source: W3schools.com (AJAX)
    function get_profile_card(field,border,ID,avatar,name,target_type,pos_x,pos_y)
    {
        // save the profile card ID so that it can be called later
        profile_card_ID        =    field;
        // save the border for the profile card (since it is used in the stateChanged() function, to draw the corners)
        profile_card_border    =    border;
        // store the positions
        profile_card_pos_x     =    pos_x;
        profile_card_pos_y     =    pos_y;

        // the url path (including $_GET) which should be accessed, and the contents written
        var url                =    gv_html_path+'cms/info/get_profile_card.php?uspr_ID='+ID+'&avatar='+avatar+
                                    '&name='+name+'&target_type='+target_type+'&field='+field;

        // access the xml HTTP object
        xmlHttp                =    GetXmlHttpObject(stateChanged);
        // open the source (stream) using the GET protocal (opposed to POST)
        xmlHttp.open("GET", url , true);
        // unsure of this
        xmlHttp.send(null);
    }

    //    Name:         Position X
    //    Purpose:      Retrieve the horizontal position, with respect to the scroll bar, of the mouse
    //    Variables:    1) var pos    -    the current horizontal position of the mouse
    //    Returns:      Nothing
    //    Notes:        None
    function pos_x(pos)
    {
        return pos + document.body.scrollLeft;
    }

    //    Name:         Position Y
    //    Purpose:      Retrieve the vertical position, with respect to the scroll bar, of the mouse
    //    Variables:    1) var pos    -    the current vertical position of the mouse
    //    Returns:      Nothing
    //    Notes:        None
    function pos_y(pos)
    {
        return pos + document.body.scrollTop;
    }

    //    Name:         State Changed
    //    Purpose:      To manage the output of the AJAX content (see source)
    //    Variables:    None
    //    Returns:      Nothing
    //    Notes:        Source: W3schools.com (AJAX)
    function stateChanged()
    {
        // if the xml HTTP request was successful
        if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        {
            // check whether the profile card was already opened (if it has, then only becomes visible again, not seperate
            // AJAX call)
            if(opened_profile_cards[profile_card_ID]!=true)
            {
                // output the xml HTTP content
                document.getElementById("profile_card_"+profile_card_ID).innerHTML    =    xmlHttp.responseText;
                // round the corners
                Rounded('div#profile_card_'+profile_card_ID,'all','transparent','white','border '+profile_card_border);
                // mark that it has been opened
                opened_profile_cards[profile_card_ID]                                 =    true;
            }

            // adjust the position
            document.getElementById("profile_card_"+profile_card_ID).style.left          =    profile_card_pos_x;
            document.getElementById("profile_card_"+profile_card_ID).style.top           =    profile_card_pos_y;

            // make visible
            document.getElementById("profile_card_"+profile_card_ID).style.visibility    =    'visible';

            // check whether there is an open card
            if(open_card_ID!=0)
            {
                // if so, hide it
                hide_profile_card("profile_card_"+open_card_ID);
            }
            // store the new card as being the open one
            open_card_ID    =    profile_card_ID;
        }
    }

    //    Name:        Get XML HTTP Object
    //    Purpose:     Unknown; see source
    //    Variables:   1) var handler    -    unknown; see source
    //    Returns:     Nothing
    //    Notes:       Source: W3schools.com (ajax tutorial)
    function GetXmlHttpObject(handler)
    {
        var objXmlHttp=null

/*         if (navigator.userAgent.indexOf("Opera")>=0)
        {
            alert("This example doesn't work in Opera")
            return
        } */

        if(navigator.userAgent.indexOf("MSIE")>=0)
        {
            var strName="Msxml2.XMLHTTP"
            if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
            {
                strName="Microsoft.XMLHTTP"
            }
            try
            {
                objXmlHttp=new ActiveXObject(strName)
                objXmlHttp.onreadystatechange=handler
                return objXmlHttp
            }
            // Note: not sure what the two lines purpose was, since wouldn't allow Opera when uncommented
            catch(e)
            {
//                alert("Error. Scripting for ActiveX might be disabled")
//                return
            }
        }

        if(navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0)
        {
            objXmlHttp=new XMLHttpRequest()
            objXmlHttp.onload=handler
            objXmlHttp.onerror=handler
            return objXmlHttp
        }
    }

    //    Name:        Hide Profile Card
    //    Purpose:     Allows a profile card to disappear
    //    Variables:   1) var field    -    the field which is to be hidden
    //    Returns:     Nothing
    //    Notes:       None
    function hide_profile_card(field)
    {
        document.getElementById(field).style.visibility    =    'hidden';
        // set it so that no card is open
        open_card_ID =    0;
    }

    function check_forward_history()
    {
//        alert(history.length);
        // check whether there is something in the forward history
//        alert(history.go());
//        document.getElementById('forward_lnk_txt').innerHTML    =    'yes';
    }

    //    Name:        Go Back
    //    Purpose:     Handle a page going back, with respect to the # sign being active
    //    Variables:   None
    //    Returns:     Nothing
    //    Notes:       Allows back button to work even if on page anchor was pressed
    function go_back()
    {
        // get the page url
        window_path    =    document.location.href;
        // if a page anchor is active, go back twice
        if(window_path.match("#"))
        {
            history.go(-2);
        }
        // otherwise go back just once
        else
        {
            history.go(-1);
        }
    }

    // create a global js variable, to store the number of times a field should blink
    var blink_number   =  new Array();

    //    Name:        Field Blink
    //    Purpose:     To allow a specific field to blink at a given interval and number of times
    //    Variables:   1) var field         -    the field that should blink
    //                 2) var interval      -    the interval at which it should blink
    //                 3) var max_number    -    the maximum number of times it should blink
    //    Returns:     Completion
    //    Notes:       None
    function field_blink(field,interval,max_number)
    {
        // if the number of times blinked so far is less than the total number it should
        if(blink_number[field] < max_number)
        {
            // blink
            document.getElementById(field).style.visibility = document.getElementById(field).style.visibility == "" ?
                                                              "hidden" : "";

            // create function string, that is called incrementally
            functionName  =   "field_blink('"+field+"',"+interval+","+max_number+")";
            // add one to the counter for blinks
            blink_number[field]++;
            // restart
            setTimeout(functionName,interval);
        }
        // end the function
        else
        {
            return;
        }
    }

    function how_to_use_forward()
    {
        // check if the how_to_use section is already open
        if(!sectionTabs['how_to_use'])
        {
            qvLoad('how_to_use');
            document.location.href    =    '#how_to_use';
        }
        else
        {
            qvLoad('how_to_use');
            document.location.href    =    '#top';
        }
    }

    // function to allow that one click of submit button, image is changed
    // (localised here since page won't allow \" in javascript (thinks end of <a></a> tag)
    function change_submit_button(field,txt,img)
    {
        document.getElementById('txt_'+field).innerHTML    =    '<b>'+txt+'</b>';
        document.getElementById('img_'+field).innerHTML    =    '<img src="'+img+'" alt="Button">';
    }

    // create global variable that marks whether the inputs have already been changed
    var input_changed    =    false;
    
    function change_qv_login_input()
    {
        // if the inputs havn't yet been changed
        if(!input_changed)
        {
            if(document.qv_login.username_req.value=='Username')
            {
                document.qv_login.username_req.value    =    '';
            }
            document.getElementById('password_html').innerHTML    =    '<input type="password" name="password_req" id="password_req" size="12">';
            input_changed    =    true;
        }
    }

    function file_download(id)
    {
        var today = new Date();
        var expire = new Date();

        // set the download cookie for 10 seconds
        expire.setTime(today.getTime() + 3600000*24);

/*   document.cookie= "file_download=" + id +"; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");*/

        document.cookie = "download_file="+id+ ";expires="+expire.toGMTString();
//        alert(document.cookie);
    }

    ///////////////////////////////////////////////////////////////////////////
    //                                                                       //
    //  END OF FILE                                                          //
    //                                                                       //
    ///////////////////////////////////////////////////////////////////////////