/*
Active Bookmarking Javascript (C) 2000 Chris F Wood 
--------------------------------------------------- 

This script may be used in the manner discribed on www.thetoxiczone.com,
plaese also note that this notice should not be removed from this file. 

If you wish to contact the author please e-mail chris@thetoxiczone.com 
*/

function getCGI(fullURL)
{
  var result;
  var sub;
  var ExpCGI = new RegExp("^.*[\?]");
  if ((result = ExpCGI.exec(fullURL)) != null)
  {
    sub = fullURL.replace(result[0],"");
    if (navigator.appName.indexOf("Internet Explorer") == -1)
    {
      return sub.replace("?","");
    }
    else
    {
      return sub;  
    }
  }
  else
  {
    return "";
  }
}

function getHost(fullURL)
{
  var result;
  var sub;
  var urlcgi;
  var ExpPath = new RegExp("(^.*[:][\\\/]*[^\\\/]*[\\\/][~][^\\\/]*[\\\/])|(^.*[:][\\\/]*[^\\\/]*[\\\/])");
  urlcgi = getCGI(fullURL);
  if (urlcgi != "")
  {
    sub = fullURL.replace(urlcgi,"");
    sub = sub.replace("?","");
  }
  else
  {
    sub = fullURL; 
  }
  if ((result = ExpPath.exec(sub)) != null)
  {
    return result[0];
  }
  else
  {
    return "";
  }
}

function getPath(fullURL)
{
  var result;
  var sub;
  var urlcgi;
  var ExpPath = new RegExp("[^\\\/]*[\.][^\\\/]*$");

  urlcgi = getCGI(fullURL);
  if (urlcgi != "")
  {
    sub = fullURL.replace(urlcgi,"");
    sub = sub.replace("?","");
  }
  else
  {
    sub = fullURL; 
  }

  sub = sub.replace(getHost(fullURL),"");

  if ((result = ExpPath.exec(sub)) != null)
  {
    return sub.replace(result[0],"");
  }
  else
  {
    return sub; 
  }
}

function getFile(fullURL)
{
  var result;
  var sub;
  var urlcgi;
  var ExpPath = new RegExp("[^\\\/]*[\.][^\\\/]*$");
  
  urlcgi = getCGI(fullURL);
  if (urlcgi != "")
  {
    sub = fullURL.replace(urlcgi,"");
    sub = sub.replace("?","");
  }
  else
  {
    sub = fullURL; 
  }

  if ((result = ExpPath.exec(sub)) != null)
  {
    return result[0];
  }
  else
  {
    return "";
  }
}

function saveBookmark()
{
  if (self.location.protocol != "file:")
  {
    var urlPath;
    if ((self!=top) && (self.document.referrer != ""))
    {
      urlPath = getHost(self.document.referrer);
    }
    else 
    {
      urlPath = getHost(self.location.href);
    }
    urlPath = urlPath + "?";
    urlPath = urlPath + getPath(self.mainFrame.location.href);
    urlPath = urlPath + getFile(self.mainFrame.location.href);
    var urlTitle = self.mainFrame.document.title;
    if (navigator.appName.indexOf("Internet Explorer") != -1)
    { 
      window.external.AddFavorite(urlPath,urlTitle);
    }
    else
    {
      var newwindow = window.open("blank.html","newbook","resizable=no,width=380,height=50");
      newwindow.focus();
      var newdocument = newwindow.document;
      newdocument.open("text/html");
      newdocument.write("<HTML>\n");
      newdocument.write("<HEAD>\n");
      newdocument.write("<TITLE>Bookmark</TITLE>\n");
      newdocument.write("</HEAD>\n");    
      newdocument.write("<BODY BGCOLOR='" + bgColour + "' BACKGROUND='" + bgImage + "' LINK='" + lColour + "' ALINK='" + alColour + "' VLINK='" + vlColour + "'>\n");
      newdocument.write("<P>To Bookmark this page and not the sites home page you will have to right click the link below, then select Add Bookmark.</P><P ALIGN=\"CENTER\"><A HREF='"+urlPath+"' onClick=\"return false;\">"+urlTitle+"</A></P>\n");
      newdocument.write("</BODY>\n");
      newdocument.write("</HTML>\n");
      newdocument.close();
    }
  }
}

function loadBookmark()
{
  if (self.location.protocol != "file:")
  {
    var cgiURL;
    if ((self!=top) && (self.document.referrer != ""))
    {
      cgiURL = getCGI(self.document.referrer);
    }
    else
    {
      cgiURL = getCGI(self.location.href);
    }
    if (cgiURL !="" )
    {
      self.mainFrame.location = cgiURL;
    }
  }
}

function popframe()
{
  if (self==top)
  {
    top.window.location.href = MWHook(getHost(self.document.URL) + "?" + getPath(self.document.URL) + getFile(self.document.URL),1);
  }
}

