/*
 
 // BETA BETA BETA BETA BETA - UNSUPORTED
 // This system is in the VERY early stages
 
  ---------------------------------------------------------------------------------------------
  CHAZCO Basic Javascript File API Version 1
  http://come.to/chazco
  ---------------------------------------------------------------------------------------------
  CreateFile(path, text); - Creates a text file
  var text=ImportFile(path); - Imports text from file to return value
  GetPath(file) - file is optional, use to get path from a filename, otherwise get path of page
                  returns the path to the value. e.g. var path=GetPath();
  ---------------------------------------------------------------------------------------------
  
*/

function CreateFile(path, text)
{
   var fso, tf;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   tf = fso.CreateTextFile(path, true);
   tf.WriteLine(text) ;
   tf.WriteBlankLines(1) ;
   tf.Close();
}

function ImportFile(path, breaks)
{
   var fso, ts, s;
   var ForReading = 1;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   ts = fso.OpenTextFile(path, ForReading);
   s = ts.ReadAll();
   ts.Close();

   if(breaks) {
     for (a = 0; a <= s.length; a++)
      s = s.replace("\n", "<br>");
   }
   
   return s;
}

function GetPath(file)
{
  var line="";
  if(!file){ 
    line=location.href; 
	var thePage=window.location.href.split('/')[window.location.href.split('/').length-1]; // Get filename
  }else{
    line=file;
    var thePage=line.split('\\')[line.split('\\').length-1]; // Get filename
  }
  for (a = 0; a <= line.length; a++)
    line = line.replace("/", "\\"); // Make / become \
  line = line.replace(thePage, ""); // Get rid of page title
  line = line.replace("file:\\\\\\", ""); // If offline
  line = line.replace("http:\\\\", ""); // If online
  line = line.replace("%20", " "); // Get rid of spaces
  return line;
}