// Author: Allen Shymchuk
<!--

    arrow = 'http://www.gmpsecurities.com/images/about/arrow.gif';
    arrowUp = 'http://www.gmpsecurities.com/images/about/arrowUp.gif';
    arrowDwn = 'http://www.gmpsecurities.com/images/about/arrowDwn.gif';

    function Staff() {
      this.Add = StaffAdd;
      this.Display = StaffDisplay;
      this.Sort = StaffSort;
      this.staff = [];
    }
    function StaffAdd(fname, mname, lname, url, department, location) {
      var person = new Person();
      person.Add(fname, mname, lname, url, department, location);
      this.id = this.staff.length;
      this.staff[this.id] = person;
    }
    function StaffDisplay( item ) {
      x = this.staff.length;
      for(i=0;i<x;i++) {
        if( item == 'fname' ) this.staff[i].Display('fname');
        else this.staff[i].Display();
      }
      document.write('<br/><br/>');
    }
    // item = {fname|lname|department|location}
    // type = {ascending|descending}
    function StaffSort( item, type ) {
      switch( item ) {
        case 'fname' :
          if( type == 'ascending' ) {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_fname)
            break;
          } else {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_fname_d)
            break;
          }
          alert( 'Type not specified.' );
          break;
        case 'lname' :
          if( type == 'ascending' ) {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_lname)
            break;
          } else {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_lname_d)
            break;
          }
          alert( 'Type not specified.' );
          break;
        case 'department' :
          if( type == 'ascending' ) {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_department)
            break;
          } else {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_department_d)
            break;
          }
          alert( 'Type not specified.' );
          break;
        case 'location' :
          if( type == 'ascending' ) {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_location)
            break;
          } else {
            pm_array_qsort(this.staff,0,this.staff.length - 1,_pm_array_location_d)
            break;
          }
          alert( 'Type not specified.' );
          break;
        default :
          alert( 'Item not found.');
          break;
      }
    }

    // The JavaScript Quicksort algorithm was written by Achille Hui of Stanford University.
    function _pm_array_qsort(vec,lo,up,cmp_fun){
      var i, j, t;
      while(up > lo){
        i = lo;
        j = up;
        t = vec[lo];
        while(i < j){
          while(cmp_fun(vec[j],t) > 0)
            j -= 1;
          vec[i] = vec[j];
          while((i < j) && (cmp_fun(vec[i],t) <= 0))
            i++;
          vec[j] = vec[i];
        }
        vec[i] = t;
        if(i - lo < up - i){
         _pm_array_qsort(vec,lo,i-1,cmp_fun); lo = i+1;
        } else {
         _pm_array_qsort(vec,i+1,up,cmp_fun); up = i-1;
        }
      }
    }
    function _pm_array_defcmp(a,b){
      return (a == b) ? 0 : (a > b) ? 1 : -1;
    }
    function pm_array_qsort(vec,lo,hi,cmp_fun){
      if(vec == null){
        return;
      } else if(cmp_fun == null){
       _pm_array_qsort(vec,lo,hi,_pm_array_defcmp);
      } else {
       _pm_array_qsort(vec,lo,hi,cmp_fun);
      }
    }
    // custom comparison functions
    function _pm_array_fname(a,b){ //ascending
      return (a.fname == b.fname) ? 0 : (a.fname > b.fname) ? 1 : -1;
    }
    function _pm_array_fname_d(a,b){ //descending
      return (a.fname == b.fname) ? 0 : (a.fname < b.fname) ? 1 : -1;
    }
    function _pm_array_lname(a,b){ //ascending
      return (a.lname == b.lname) ? 0 : (a.lname > b.lname) ? 1 : -1;
    }
    function _pm_array_lname_d(a,b){ //descending
      return (a.lname== b.lname) ? 0 : (a.lname< b.lname) ? 1 : -1;
    }
    function _pm_array_department(a,b){ //ascending
      return (a.department== b.department) ? 0 : (a.department> b.department) ? 1 : -1;
    }
    function _pm_array_department_d(a,b){ //descending
      return (a.department== b.department) ? 0 : (a.department< b.department) ? 1 : -1;
    }
    function _pm_array_location(a,b){ //ascending
      return (a.location== b.location) ? 0 : (a.location> b.location) ? 1 : -1;
    }
    function _pm_array_location_d(a,b){ //descending
      return (a.location== b.location) ? 0 : (a.location< b.location) ? 1 : -1;
    }

    function Person() {
      this.Add = PersonAdd;
      this.Display = PersonDisplay;
      this.fname = new String();
      this.mname = new String();
      this.lname = new String();
      this.url = new String();
      this.department = new String();
      this.location = new String();
    }
    function PersonAdd(fname, mname, lname, url, department, location) {
      this.fname = fname;
      this.mname = mname;
      this.lname = lname;
      this.url = url;
      this.department = department;
      this.location = location;
    }
    function PersonDisplay( item ) {
      document.write('<tr>\n');
      if( item == 'fname' ) document.write('  <td valign="top" align="left" class="text"><a href="javascript:openWindow(\'' + this.url + '\',500,500,50,50,50,50);" class="link">' + this.fname + ' ' + this.mname + ' ' + this.lname + '</a></td>\n');
      else document.write('  <td valign="top" align="left" class="text"><a href="javascript:openWindow(\'' + this.url + '\',500,500,50,50,50,50);" class="link">' + this.lname + ', ' + this.fname + ' ' + this.mname + '</a></td>\n');
      document.write('	<td><img src="/images/spacer.gif" width="10" height="1"></td>\n');
      document.write('  <td valign="top" align="left" class="text">' + this.department + '</td>\n');
      document.write('	<td><img src="/images/spacer.gif" width="10" height="1"></td>\n');
      document.write('  <td valign="top" align="left" class="text">' + this.location + '</td>\n');
      document.write('</tr>\n');
    }

//-->
