/**********************************************************************************/
/******************************* Documentation ************************************
This Javascript Library controls the video player and media library on the
ECSI video page at www.ecsi.net/video.  It creates a JS object class of Videos.

Possible Query String parameters:
  dispCat    - Category to Display
  playVideo  - vidSeqNo of video to play
  sortOrder  - sort Order of the displayed tab
  searchText - text to search for - automatically displays search tab with results

Possible Sort Orders:
  chron     - Chronological by dateAdded
  revchron  - Reverse Chronological by dateAdded - this is the default sort order
  alpha     - Alphabetic by vtitle
  revalpha  - Reverse Alphabetic by vtitle
  length    - Increasing by vlength
  revlength - Decreasing by vlength

Special Categories (tabs):
  new    - shows all videos added in the last month - this is the default category displayed if no
           category is specified to display
  all    - shows all videos regardless of the category definded in the Video instance
  search - tab displays a search box and adds videos where the title or description include
           the text in the search box

User Defined Categories (tabs):
  general
  testimonials
***********************************************************************************/
/********************************* Global Vars ************************************/
//array of videos
//new Video(vidSeqNo, vidFileName, screenCapFileName, vtitle, vdesc, vlength, dateAdded, category)
var videos = [new Video("0000","0000.the.impact.of.consolidation.wmv","0000.the.impact.of.consolidation.jpg","The Impact of Consolidation on Cash Flow","John Lynch, President / CEO of ECSI, discusses the impact of consolidation on cash flow in higher education and how it may effect your school.","2:24",new Date("02/04/2008 00:00"),"general"),
              new Video("0001","0001.about.ecsi.wmv","0001.about.ecsi.jpg","About ECSI","John Lynch, President / CEO of ECSI, discusses the history of the company.","2:47",new Date("03/20/2008 00:00"),"general"),
              new Video("0002","0002.commitment.to.service.wmv","0002.commitment.to.service.jpg","ECSI's Commitment to Service","John Lynch, President / CEO of ECSI, discusses ECSI's ongoing commitment to service.","2:10",new Date("03/20/2008 00:01"),"general"),
              new Video("0003","0003.earma.recap.wmv","0003.earma.recap.jpg","EARMA 2008 Conference Recap","In this video Tracy Schumann, Senior Systems Consultant at ECSI, shares his experiences at this year's EARMA Conference in New Jersey.","5:00",new Date("04/21/2008 00:00"),"general"),
              new Video("0004","0004.kumc.testimonial.wmv","0004.kumc.testimonial.jpg","KUMC Client Testimonial","In this video Keith Fitzsimmons, Director of Student Financial Accounting, at the University of Kansas Medical Center (KUMC) discusses his experience with ECSI.  KUMC converted to ECSI from CLM.","1:49",new Date("09/08/2008 00:00"),"testimonials"),
              new Video("0005","0005.mtunion.testimonial.wmv","0005.mtunion.testimonial.jpg","Mount Union Client Testimonial","In this video Michelle Baker-Sams, Controller, at Mount Union College discusses her experience with ECSI.  Mount Union College converted to ECSI from UAS.","1:34",new Date("09/08/2008 00:01"),"testimonials"),
              new Video("0006","0006.musc.testimonial.wmv","0006.musc.testimonial.jpg","MUSC Client Testimonial","In this video Melissa Smith at the Medical University of South Carolina (MUSC) discusses her experience with ECSI's eRefund Solution.","1:21",new Date("11/24/2008 00:00"),"testimonials"),
              new Video("0007","0007.cornell.testimonial.wmv","0007.cornell.testimonial.jpg","Cornell University Client Testimonial","In this video Ed Baker, Assistant Bursar, at Cornell University discusses his experience with ECSI.  Cornell University converted to ECSI from LMS.","1:41",new Date("11/24/2008 00:01"),"testimonials"),
              new Video("0008","0008.compilation.testimonial.wmv","0008.compilation.testimonial.jpg","Client Testimonial Compilation","In this video Ed Baker (Cornell University), Dennis Swartz (Ball State University), Michelle Baker-Sams (Mount Union College), Keith Fitzsimmons (University of Kansas Medical Center), and Melissa Smith (Medical University of South Carolina) share their experiences with ECSI.","1:23",new Date("11/24/2008 00:02"),"testimonials"),
              new Video("0009","0009.state.of.lending.wmv","0009.state.of.lending.jpg","The State of Lending","In this video John Lynch, President / CEO of ECSI, discusses the current state of lending in Higher Education today and into 2009.","3:18",new Date("11/25/2008 00:00"),"general"),
              new Video("0010","0010.1098t.services.wmv","0010.1098t.services.jpg","ECSI's 1098-T Services","In this video Ron Shell, Sr VP of Business Development, and Mike Trombetta, 1098-T Product Specialist, discuss ECSI's 1098-T Solution.","2:21",new Date("11/25/2008 00:01"),"general")];
var videoSearchResults = [];
var qsParms = new Array(); //array of parameters passed via query string
var currentCategory; //category currently displayed
var currentSearchText = ""; //search text currently in text box;

/**********************************************************************************/
/********************** Video Object Helper Functions *****************************/
function loadVideoPage(showCategory) {
  //function to load the video player and video list
  //set default category to show to 'new'
  if (!showCategory) {
    showCategory = 'new';
  }
  //get query string parameters
  qsParms['dispCat'] = null;
  qsParms['playVideo'] = null;
  qsParms['sortOrder'] = null;
  qsParms['searchText'] = null;

  parseQueryString();

  var catToDisp = qsParms['dispCat'];
  var videoToPlay = qsParms['playVideo'];
  var sortOrder = qsParms['sortOrder'];
  var searchText = qsParms['searchText'];

  //decide what to do
  if (searchText) {
    currentSearchText = searchText;
    catToDisp = 'search';
  }

  if (catToDisp) {
    if (sortOrder) {
      createVideoPageList(catToDisp,sortOrder);
    } else {
      createVideoPageList(catToDisp);
    }
  } else {
    if (sortOrder) {
      createVideoPageList(showCategory,sortOrder);
    } else {
      createVideoPageList(showCategory);
    }
  }

  if (videoToPlay) {
    playVideo(videoToPlay);
  }
}
function createVideoPageList(showCategory, sortOrder) {
  //function to display the list of videos on a tab in a particular order
  //set default category to show to 'new'
  if (!showCategory) {
    showCategory = 'new';
  }
  //clear global search text variable if move out of search tab
  if (showCategory != 'search') {
    currentSearchText = "";
  }

  //store selected category in a global variable for use later
  currentCategory = showCategory;

  //set sort order to same if it is not specified
  if (!sortOrder) {
    var sel = document.getElementById('selSortOrder');
    sortOrder = sel.options[sel.selectedIndex].value;
  }

  //sort the videos array
  switch (sortOrder) {
    case 'revchron':
      videos.sort(Video.videoReverseChronSorter);
      break;
    case 'chron':
      videos.sort(Video.videoChronSorter);
      break;
    case 'alpha':
      videos.sort(Video.videoTitleAlphaSorter);
      break;
    case 'revalpha':
      videos.sort(Video.videoTitleReverseAlphaSorter);
      break;
    case 'length':
      videos.sort(Video.videoRunTimeLengthSorter);
      break;
    case 'revlength':
      videos.sort(Video.videoRunTimeReverseLengthSorter);
      break;
    default: //revchron
      videos.sort(Video.videoReverseChronSorter);
      break;
  }

  //initialize the html created to blank
  var videoListHTML = "";
  var vidCount = 0;

  //if category is all, add html for all videos,
  //if category is new, add html for videos less than oneMonthInMS
  //else add html for showCategory
  switch (showCategory) {
    case 'all':
      for (var i=0; i < videos.length; i++) {
        videoListHTML += videos[i].toHTML('videoThumb');
        vidCount++;
      }
      showVidCount('vidCount', vidCount, false);
      break;
    case 'new':
      for (var i=0; i < videos.length; i++) {
        if (videos[i].isNew()) {
          videoListHTML += videos[i].toHTML('videoThumb');
          vidCount++;
        }
      }
      showVidCount('vidCount', vidCount, false);
      break;
    case 'search':
      if (currentSearchText == "") {
        videoListHTML += '<p>Search: <input type="text" id="searchtext" value="' + currentSearchText + '" maxlength="40"> <input type="button" id="searchButton" value="Search" onclick="javascript:searchVideos(document.getElementById(\'searchtext\').value)"></p>';
        vidCount = 0;
        showVidCount('vidCount', vidCount, true);
      } else {
        searchVideos(currentSearchText);
      }
      break;
    default:
      for (var i=0; i < videos.length; i++) {
        if (videos[i].category == showCategory) {
          videoListHTML += videos[i].toHTML('videoThumb');
          vidCount++;
        }
      }
      showVidCount('vidCount', vidCount, false);
      break;
  }

  //highlight the correct tab
  var divElems = document.getElementsByTagName("div");
  for (var j=0; j < divElems.length; j++) {
    if (divElems[j].id == showCategory + "CatTab") {
      divElems[j].className = "catTabSelected";
    } else if (divElems[j].id.indexOf("CatTab") != -1) {
      divElems[j].className = "catTab";
    }
  }

  //add html of video list to vidBox div
  if (currentSearchText == "") {
    document.getElementById("vidBox").innerHTML = videoListHTML;
  }

  //set the focus of the cursor to the search text box if it exists
  if (document.getElementById('searchtext')) {
    document.getElementById('searchtext').focus();
    document.getElementById('searchtext').select();
  }
}
function playVideo(playSeqNo) {
  //function to play a particular video
  //change style of any previously selected video blocks
  var prevSelected = getElementsByClass("vidSingleSelected");
  if (prevSelected.length != 0) {
    prevSelected[0].className = "vidSingle";
  }
  var prevSelected_sm = getElementsByClass("vidSingleSelected_sm");
  if (prevSelected_sm.length != 0) {
    prevSelected_sm[0].className = "vidSingle_sm";
  }

  //change style of selected video block
  if (document.getElementById("vidSingle" + playSeqNo).className == "vidSingle") {
    document.getElementById("vidSingle" + playSeqNo).className = "vidSingleSelected";
  } else {
    document.getElementById("vidSingle" + playSeqNo).className = "vidSingleSelected_sm";
  }


  for (var i=0; i < videos.length; i++) {
    if (videos[i].vidSeqNo == playSeqNo) {
      //set up information html block
      var infoBlockHTML = videos[i].toHTML("infoBlock");
      document.getElementById("vidNowPlayingInfo").innerHTML = infoBlockHTML;
      //add video HTML
      var videoBlockHTML = videos[i].toHTML("playVideo");
      document.getElementById("vidNowPlaying").innerHTML = videoBlockHTML;
      //get out of for loop
      break;
    }
  }
}
function createVideoList(where, listType, whichVideos, numVideos) {
  //function to create the direct link to a particular video
  //where = id of element to add the link to (required)
  //listType = [ul, ol, thumb] (optional, if not specified, 'ul' is used)
  //whichVideos = [all|allnew|newest|oldest|{seqNo}] (optional, if not specified, 'newest' is used)
  //              all: all videos
  //              allnew: all new videos (same videos that appear on "new" tab) - single newest video if no "new" videos
  //              newest: a specific number of the newest videos (does not look at if video is "new")
  //              oldest: a specific number of the oldest videos (does not look at if video is not "new")
  //              seqNo: a single specific video specified by the seqNo (if invalid seqNo given, single newest video is displayed)
  //numVideos = for all: numVideos has no meaning (ignored)
  //            for allnew: numVideos has no meaning (ignored)
  //            for newest and oldest: numVideos is the number of videos to show - this is an integer and should not be in quotes (optional, if not specified, 1 video is displayed)
  //            for seqNo: numVideos has no meaning (ignored)
  //"new" is defined by isNew method of Video class

  //set defaults
  if (!where) {return false;}
  if (!whichVideos) {whichVideos = 'newest'};
  if (!listType) {listType = 'ul'};
  if (whichVideos == "all" || whichVideos == "allnew") {
    numVideos = videos.length;
  }
  if (whichVideos == "newest" || whichVideos == "oldest") {
    if (!numVideos) {numVideos = 1};
    if (numVideos > videos.length) {numVideos = videos.length};
  }

  var toHTMLType = '';
  var vidLinkHTML = '';

  //add opening ul tag
  switch (listType) {
    case 'ul':
      toHTMLType = 'linkToVideoPage'
      vidLinkHTML += '<ul class="videoLinkList">';
      break;
    case 'ol':
      toHTMLType = 'linkToVideoPage'
      vidLinkHTML += '<ol class="videoLinkList">';
      break;
    case 'thumb':
      toHTMLType = 'videoThumbExternal'
      vidLinkHTML += '<ul class="videoThumbList">';
      break;
  }

  //determine which video(s) to use and create the link
  switch (whichVideos) {
    case 'all':
      //sort newest first
      videos.sort(Video.videoReverseChronSorter);
      for (i=0; i < numVideos; i++) {
        vidLinkHTML += '<li>';
        vidLinkHTML += videos[i].toHTML(toHTMLType);
        vidLinkHTML += '</li>';
      }
      break;
    case 'allnew':
      //sort newest first
      videos.sort(Video.videoReverseChronSorter);
      var found = false;
      for (i=0; i < numVideos; i++) {
        if (videos[i].isNew()) {
          vidLinkHTML += '<li>';
          vidLinkHTML += videos[i].toHTML(toHTMLType);
          vidLinkHTML += '</li>';
          found = true;
        }
      }
      //if no new videos were found, display single newest video
      if (!found) {
        vidLinkHTML += '<li>';
        vidLinkHTML += videos[0].toHTML(toHTMLType);
        vidLinkHTML += '</li>';
      }
      break;
    case 'newest':
      //sort newest first
      videos.sort(Video.videoReverseChronSorter);
      for (i=0; i < numVideos; i++) {
        vidLinkHTML += '<li>';
        vidLinkHTML += videos[i].toHTML(toHTMLType);
        vidLinkHTML += '</li>';
      }
      break;
    case 'oldest':
      //sort oldest first
      videos.sort(Video.videoChronSorter);
      for (i=0; i < numVideos; i++) {
        vidLinkHTML += '<li>';
        vidLinkHTML += videos[i].toHTML(toHTMLType);
        vidLinkHTML += '</li>';
      }
      break;
    default:
      //if seqNo specified, display video with seqNo or the single newest video if seqNo is not found
      var found = false;
      for (var i=0; i < videos.length; i++) {
        if (videos[i].vidSeqNo == whichVideos) {
          vidLinkHTML += '<li>';
          vidLinkHTML += videos[i].toHTML(toHTMLType);
          vidLinkHTML += '</li>';
          found = true;
        }
      }
      //if the seqNo is not found, display single newest video
      if (!found) {
        //sort newest first
        videos.sort(Video.videoReverseChronSorter);
        vidLinkHTML += '<li>';
        vidLinkHTML += videos[0].toHTML(toHTMLType);
        vidLinkHTML += '</li>';
      }
      break;
  }

  //add closing list tag
  switch (listType) {
    case 'ul':
      vidLinkHTML += '</ul>';
      break;
    case 'ol':
      vidLinkHTML += '</ol>';
      break;
    case 'thumb':
      vidLinkHTML += '</ul>';
      break;
  }

  //add URL to page
  document.getElementById(where).innerHTML = vidLinkHTML;
}
function searchVideos(searchText) {
  //Search the videos for searchText
  //initialize variables
  var videoListHTML = "";
  videoSearchResults = [];

  //if searchText is blank, alert error
  if (!searchText) {alert('Please enter a search term.'); return;};
  currentSearchText = searchText;

  //if text is in videos title or description add video to search results array
  for (var i = 0; i < videos.length; i++) {
    if (videos[i].containsText(searchText)) {
      videoSearchResults.push(videos[i]);
    }
  }

  //initialize the video count
  var vidCount = 0;

  //show the search tab...uses videoSearchResult array rather than videos array
  if (videoSearchResults.length != 0) {
    videoListHTML += '<p>Search: <input type="text" id="searchtext" value="' + searchText + '" maxlength="40"> <input type="button" id="searchButton" value="Search" onclick="javascript:searchVideos(document.getElementById(\'searchtext\').value)"></p>';
    for (var i=0; i < videoSearchResults.length; i++) {
      videoListHTML += videoSearchResults[i].toHTML('videoThumb');
      vidCount++;
    }
    showVidCount('vidCount', vidCount, true);
  } else {
    videoListHTML += '<p>Search: <input type="text" id="searchtext" value="' + searchText + '" maxlength="40"> <input type="button" id="searchButton" value="Search" onclick="javascript:searchVideos(document.getElementById(\'searchtext\').value)"></p>';
    videoListHTML += '<p><b>No results found for "' + searchText + '"...Please try again.</b></p>';
    showVidCount('vidCount', vidCount, true);
  }

  //add html of video list to vidBox div
  document.getElementById("vidBox").innerHTML = videoListHTML;

  //set the focus of the cursor to the search text box if it exists
  if (document.getElementById('searchtext')) {
    document.getElementById('searchtext').focus();
    document.getElementById('searchtext').select();
  }
}
function showVidCount(where, vidCount, searchFlag) {
  //where = id of element where count text will be placed
  //vidCount = number of videos counted
  //searchFlag = [true|false] whether this is search count or not
  var vidCountHTML = "";
  vidCountHTML += vidCount + ' Videos ';
  if (searchFlag) {
    if (vidCount == 0) {
      vidCountHTML = '';
    } else {
      vidCountHTML += 'Found';
    }
  } else {
    vidCountHTML += 'in this Category';
  }
  document.getElementById(where).innerHTML = vidCountHTML;
}

/**********************************************************************************/
/********************************* Video Class ************************************/
/****************************** Constructor Function ******************************/
function Video(vidSeqNo, vidFileName, screenCapFileName, vtitle, vdesc, vlength, dateAdded, category) {
  this.vidSeqNo = vidSeqNo;
  this.vidFileName = vidFileName;
  this.vidLocation = '/video/video_files/' + vidFileName;
  this.screenCapFileName = screenCapFileName;
  this.screenCapLocation = '/video/video_files/' + screenCapFileName;
  this.vtitle = vtitle;
  this.vdesc = vdesc;
  this.vlength = vlength;
  this.dateAdded = dateAdded;
  this.category = category;
}
/************************************* Methods ************************************/
Video.prototype.toHTML = function(whichBlock) {
  //Creates HTML for the Video Object to be added to the document
  //whichBlock = [videoThumb|videoThumbExternal|infoBlock|playVideo|linkToVideoPage|urlToVideoPage]
  if (!whichBlock) {whichBlock = 'videoThumb'}
  var urlProtocol =(window.top.location.toString().substring(0,5)=="https")? "https" : "http";
  switch (whichBlock) {
    case 'videoThumb':
      //creates the video thumbnail box
      var listHTML = '';
      listHTML += '<div id="vidSingle' + this.vidSeqNo + '" class="vidSingle" title="' + this.vdesc + '">';
      listHTML += '<a href="javascript:playVideo(\'' + this.vidSeqNo + '\')"><img class="vidScreenCap" src="' + this.screenCapLocation + '"></a>';
      listHTML += '<p class="vidTitle"><a href="javascript:playVideo(\'' + this.vidSeqNo + '\')">' + this.vtitle + '</a></p>';
      listHTML += '<p class="vidDate">' + this.dateAdded.mmddyyyyFmt() + '</p>';
      listHTML += '<p class="vidPlayingTime">' + this.vlength + '</p>';
      listHTML += '</div>';
      return listHTML;
      break;
    case 'videoThumbExternal':
      //creates the video thumbnail box
      var vidURL = this.toHTML('urlToVideoPage');
      var listHTML = '';
      listHTML += '<div id="vidSingle' + this.vidSeqNo + '" class="vidSingle_sm" title="' + this.vdesc + '">';
      listHTML += '<a href="' + vidURL + '"><img class="vidScreenCap_sm" src="' + this.screenCapLocation + '"></a>';
      listHTML += '<p class="vidTitle_sm"><a href="' + vidURL + '">' + this.vtitle + '</a></p>';
      listHTML += '</div>';
      return listHTML;
      break;
    case 'infoBlock':
      //creates the contents of the "Now Playing" box on video page
      var infoHTML = '';
      infoHTML += '<p id="infoBoxTitle">Now Playing</p>'
      infoHTML += '<p><span id="vidNowPlayingTitle">' + this.vtitle + '</span>';
      infoHTML += '<span id="vidNowPlayingRunTime"> ' + this.vlength + '</span></p>';
      infoHTML += '<p id="vidNowPlayingDesc">' + this.vdesc + '</p>';
      infoHTML += '<p id="vidNowPlayingDate">Added on ' + this.dateAdded.mmddyyyyFmt() + '</p>';
      infoHTML += '<p id="vidNowPlayingVideoURL">URL: <input type="text" name="videoURL" id="videoURL" size="20" onClick="javascript:this.focus();this.select();" value="' + this.toHTML("urlToVideoPage") + '"></p>';
      return infoHTML;
      break;
    case 'playVideo':
      //creates the video player on video page
      var videoHTML = '';
      videoHTML += '<embed type="application/x-mplayer2" ';
      videoHTML += 'pluginspage="http://microsoft.com/windows/mediaplayer/en/download/" ';
      videoHTML += 'id="mediaPlayerEmbed" name="mediaPlayerEmbed" ';
      videoHTML += 'displaysize="false" autosize="false" showcontrols="true" showtracker="true" ';
      videoHTML += 'showdisplay="false" showstatusbar="false" videoborder3d="false" autostart="true" ';
      videoHTML += 'designtimesp="5311" loop="false" ';
      videoHTML += 'src="' + this.vidLocation + '">';
      videoHTML += '</embed>';
      return videoHTML;
      break;
    case 'linkToVideoPage':
      //creates entire anchor tag to a video
      var linkHTML = '';
      linkHTML += '<a href="' + urlProtocol + '://www.ecsi.net/video/index.html?playVideo='+ this.vidSeqNo + '&dispCat=' + this.category + '">'+ this.vtitle + '</a>';
      return linkHTML;
      break;
    case 'urlToVideoPage':
      //creates only the url to a video
      var urlHTML = '';
      urlHTML += urlProtocol + '://www.ecsi.net/video/index.html?playVideo='+ this.vidSeqNo + '&dispCat=' + this.category;
      return urlHTML;
      break;
  }
}
Video.prototype.toString = function(whichBlock) {
  return this.vidSeqNo + ": " + this.vtitle;
}
Video.prototype.containsText = function(searchText) {
  //Searches title and description of video for searchText - returns true or false
  return (this.vtitle.toLowerCase().indexOf(searchText.toLowerCase()) != -1 ||
          this.vdesc.toLowerCase().indexOf(searchText.toLowerCase()) != -1);
};
Video.prototype.isNew = function(timePeriod) {
  //method to determine if Video is new
  //if timePeriod is not specified, it defaults to one month
  var today = new Date();
  //one day in milliseconds = 1 day * 24 hours * 60 mins * 60 seconds * 1000 milliseconds = 2,592,000,000
  //one week in milliseconds = 7 days * 24 hours * 60 mins * 60 seconds * 1000 milliseconds = 2,592,000,000
  //one month in milliseconds = 30 days * 24 hours * 60 mins * 60 seconds * 1000 milliseconds = 2,592,000,000
  //one year in milliseconds = 365 days * 24 hours * 60 mins * 60 seconds * 1000 milliseconds = 31,536,000,000
  var oneDayInMS = 1*24*60*60*1000;
  var oneWeekInMS = 7*24*60*60*1000;
  var oneMonthInMS = 30*24*60*60*1000;
  var oneYearInMS = 365*24*60*60*1000;

  switch (timePeriod) {
    case 'day':
      var isNewAge = oneDayInMS;
      break;
    case 'week':
      var isNewAge = oneWeekInMS;
      break;
    case 'month':
      var isNewAge = oneMonthInMS;
      break;
    case 'year':
      var isNewAge = oneYearInMS;
      break;
    default:
      var isNewAge = oneMonthInMS;
      break;
  }

  var videoAgeInMS = today.getTime() - this.dateAdded.getTime();
  if (videoAgeInMS < isNewAge) {
    return true;
  } else {
    return false;
  }
}


/**********************************************************************************/
/******************************* Sorting Methods **********************************/
Video.videoChronSorter = function(video1, video2) {
  //Sort helper to sort videos in chronological order based on date added
  //chron
  return video1.dateAdded - video2.dateAdded;
};
Video.videoReverseChronSorter = function(video1, video2) {
  //Sort helper to sort videos in reverse chronological order (most recent first) based on date added
  //revchron
  return video2.dateAdded - video1.dateAdded;
};
Video.videoTitleAlphaSorter = function(video1, video2) {
  //Sort helper to sort videos in alphabetic order by Title
  //alpha
  if (video1.vtitle.toLowerCase() <  video2.vtitle.toLowerCase()) return -1;
  if (video1.vtitle.toLowerCase() == video2.vtitle.toLowerCase()) return 0;
  if (video1.vtitle.toLowerCase() >  video2.vtitle.toLowerCase()) return 1;
};
Video.videoTitleReverseAlphaSorter = function(video1, video2) {
  //Sort helper to sort videos in reverse alphabetic order by Title
  //revalpha
  if (video2.vtitle.toLowerCase() <  video1.vtitle.toLowerCase()) return -1;
  if (video2.vtitle.toLowerCase() == video1.vtitle.toLowerCase()) return 0;
  if (video2.vtitle.toLowerCase() >  video1.vtitle.toLowerCase()) return 1;
};
Video.videoRunTimeLengthSorter = function(video1, video2) {
  //Sort helper to sort videos in length order by Run Time (shortest first - length of video)
  //length
  var tempDate1 = new Date(2008,00,01,00,00,00,00);
  var tempDate2 = new Date(2008,00,01,00,00,00,00);
  tempDate1.setMinutes(video1.vlength.substring(0,video1.vlength.indexOf(':')));
  tempDate2.setMinutes(video2.vlength.substring(0,video2.vlength.indexOf(':')));
  tempDate1.setSeconds(video1.vlength.substring(video1.vlength.indexOf(':')+1));
  tempDate2.setSeconds(video2.vlength.substring(video2.vlength.indexOf(':')+1));
  return tempDate1 - tempDate2;
};
Video.videoRunTimeReverseLengthSorter = function(video1, video2) {
  //Sort helper to sort videos in reverse length order by Run Time (longest first - length of video)
  //revlength
  var tempDate1 = new Date(2008,00,01,00,00,00,00);
  var tempDate2 = new Date(2008,00,01,00,00,00,00);
  tempDate1.setMinutes(video1.vlength.substring(0,video1.vlength.indexOf(':')));
  tempDate2.setMinutes(video2.vlength.substring(0,video2.vlength.indexOf(':')));
  tempDate1.setSeconds(video1.vlength.substring(video1.vlength.indexOf(':')+1));
  tempDate2.setSeconds(video2.vlength.substring(video2.vlength.indexOf(':')+1));
  return tempDate2 - tempDate1;
};


/**********************************************************************************/
/******************************** Date Object *************************************/
/********************************** Methods ***************************************/
Date.prototype.mmddyyyyFmt = function() {
  // Custom Date function to display a date in MM/DD/YYYY format
  return (this.getMonth() + 1) + "/" + this.getDate() + "/" + this.getFullYear();
}
Date.prototype.mmddyyyyhhmmFmt = function() {
  // Custom Date function to display a date in MM/DD/YYYY HH:MM format
  return (this.getMonth() + 1) + "/" + this.getDate() + "/" + this.getFullYear() + " " + this.getHours() + ":" + this.getMinutes();
}


/**********************************************************************************/
/********************** Functions to Get Query String *****************************/
function parseQueryString() {
  //function to parse the query string of the URL into 2 global arrays
  if (!window.location.search) {return}

  var query = window.location.search.substring(1);
  query = decodeURIComponent(query);
  var parms = query.split('&');

  for (var i = 0; i < parms.length; i++) {
    var pos = parms[i].indexOf('=');
    if (pos > 0) {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos + 1);
      qsParms[key] = val;
    }
  }
}


/**********************************************************************************/
/******************* Utility Functions, Data, & Methods ***************************/
function getElementsByClass(classname){
  //function to return an array of elements with the given classname
  ccollect = new Array();
  var inc = 0;
  var alltags = document.all ? document.all : document.getElementsByTagName("*");
  for (i = 0; i < alltags.length; i++) {
    if (alltags[i].className == classname) {
      ccollect[inc] = alltags[i];
      inc++;
    }
  }
  return ccollect;
}
function PopUpWindow(URL) {
  window.open(URL, 'popup', 'width=400,height=300,scrollbars,menubar,resizable');
}
