/*
Summary:  Manipulating URLs.
Version:  1.0
Author:   John Bentley (www.softmake.com.au)     
Depends on:

Usage Requirments:

Usage Example: 
*/

/*
Returns: The Page reference in a url. */
function getPageFileName(href) {
  return href.substr(href.lastIndexOf("/") + 1);
}

function getDirPath() {
  var url = window.location.href;
  return unescape(url.substring(0,url.lastIndexOf("/") + 1));
}

// Strip hash at the end of page names. eg take '#' off 'myPage.html#'
function stripHashOffEndOfNonZeroString(str) {
  
  if (str.length > 1 && str.lastIndexOf("#") == str.length - 1) {
    str = str.substr(0, str.length - 1);
  }
  
  return str;
}

/*
Returns: A Path Slash and File Name that is safe for web referencing
         and suppling to Scripting Runtime functions.
Example:
      getSafePathSlashFileName("file:///C:/Data/Temp/MyFile.txt")
        -> C:/Data/Temp/MyFile.txt */
function getSafePathSlashFileName(pathSlashFileName) {
  return pathSlashFileName.replace("file:///","");
}

/* 
Returns: True if the page has been loaded from a server
         (rather) than the file system
Remarks:  Alerts user if not being served. 
Usage:
      if (!isBeingServed()) { return false; }
*/ 
function isBeingServed(){
  if (location.protocol == "http:") {
    return true;
  } else {
    alert("You must open this page from a web server, not directly from the file system.");
    return false;    
  }
}

function isFromFileSystem(){
  if (location.protocol == "file:") {
    return true;
  } else {
    alert("You must open this page from the file System, not  a web server.");
    return false;    
  }
}

/*
    Development Tools
*/

/*
Returns: The current values for the window.location object */
function getLocationProperties() {
  var out = "";
  out += "protocol: " + location.protocol;
  out += "\nhostname: " + location.hostname;
  out += "\nport: " + location.port;
  out += "\npathname: " + location.pathname;
  out += "\nhash: " + location.hash;
  out += "\nhref: " + location.href;
  return out;
}
