/*
        File: browser.js
     Version: 1.0

     Created: 02/05/05
    Modified: 08/02/06
   Copyright: Matthew Cassidy 2005
       Email: matt@afterglowmedia.com.au

     Purpose: Returns information about the client browser and performs browser functions
        Note: None

     License: For use solely by The Catholic Archdiocese of Brisbane. 
*/


/*----------------------------------------*/
/* Function: clientAppName()              */
/* Returns the name of the client browser */
/*----------------------------------------*/
function clientAppName() {
  return navigator.appName;
}


/*-------------------------------------------*/
/* Function: clientAppVer()                  */
/* Returns the version of the client browser */
/*-------------------------------------------*/
function clientAppVer() {
  if (isIE) {
    var ua = navigator.appVersion;
    var MSIEOffset = ua.indexOf("MSIE ");
    return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
  }
  else {
    return navigator.appVersion;
  }
}


/*---------------------------------------------------------*/
/* Function: testClient(details, testCase)                 */
/* Returns true if the client details supplied are correct */
/*---------------------------------------------------------*/
function testClient(details, testCase) {
  if (details.indexOf(testCase) >= 0) { 
    return 1; 
  }
  return 0;
}


/*---------------------------------------------------------*/
/* Function: isIE()                                        */
/* Returns true if the client browser is Internet Explorer */
/*---------------------------------------------------------*/
function isIE() {
  return testClient(clientAppName(), "Internet Explorer");
}


/*-----------------------------------------------*/
/* Function: isMozilla()                         */
/* Returns true if the client browser is Mozilla */
/*-----------------------------------------------*/
function isMozilla() {
  return testClient(clientAppName(), "Netscape");
}


/*---------------------------------------------*/
/* Function: isWebTV()                         */
/* Returns true if the client browser is WebTV */
/*---------------------------------------------*/
function isWebTV() {
  return testClient(clientAppName(), "WebTV");
}


/*------------------------------------------*/
/* Function: isWindows()                    */
/* Returns true if the client OS is Windows */
/*------------------------------------------*/
function isWindows() {
  return testClient(clientAppVer(), "Win");
}


/*--------------------------------------*/
/* Function: isMac()                    */
/* Returns true if the client OS is Mac */
/*--------------------------------------*/
function isMac() {
  return testClient(clientAppVer(), "Mac");
}


/*-----------------------------------------*/
/* Function: isLinux()                    */
/* Returns true if the client OS is Linux */
/*----------------------------------------*/
function isLinux() {
  return testClient(clientAppVer(), "Linux");
}


/*---------------------------------------*/
/* Function: isUNIX()                    */
/* Returns true if the client OS is UNIX */
/*---------------------------------------*/
function isUNIX() {
  return testClient(clientAppVer(), "X11");
}


/*------------------------------------*/
/* Function: bookmarkPage(url, title) */
/* Bookmarks the URL provided         */
/*------------------------------------*/
function bookmarkPage(url, title) {
  if (isIE) {
    if (document.all) {
      window.external.AddFavorite(url, title);
    }
    else {
      bookmarkError();
    }
  }
  else {
    if (window.sidebar) {
      window.sidebar.addPanel(title, url, "");
    }
    else if(window.opera && window.print) {
      var elem = document.createElement('a');
      elem.setAttribute('href', url);
      elem.setAttribute('title', title);
      elem.setAttribute('rel',' sidebar');
      elem.click();
    }
    else {
      bookmarkError();
    }
  }
}


/*----------------------------------------------------------------------------------*/
/* Function: bookmarkError()                                                        */
/* Displays the error message to present to users when auto bookmark is unavailable */
/*----------------------------------------------------------------------------------*/
function bookmarkError() {
  alert("Could not auto-bookmark. Please press CTRL+D to bookmark this page");
}


/*-------------------------------------*/
/* Function: makeHomepage(url)         */
/* Sets the url to the user's homepage */
/*-------------------------------------*/
function makeHomepage(url) {
  if (isIE) {
    if (document.all) {
      if (clientAppVer() > 6) {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
      }
      else {
        homepageError();
      }
    }
    else {
      homepageError();
    }
  }
  else {
    homepageError();
  }
}


/*-------------------------------------------------------------------------------------------*/
/* Function: homepageError()                                                                 */
/* Displays the error message to present to users when auto homepage creation is unavailable */
/*-------------------------------------------------------------------------------------------*/
function homepageError() {
  alert("Could not automatically make this site your homepage due to browser security.\n\nPlease use your browser's options menu to adjust your homepage.");
}

