var fileDialogWindow;
var filecontent="";
var filename="";

function getArgs()
{
 var args = new Object();
 var query = document.location.search.substring(1);
 var pairs = query.split("\&");
 for(var i=0;i < pairs.length; i++)
 {
  var pos=pairs[i].indexOf('=');
  if(pos==-1){ continue;};
  var argname = pairs[i].substring(0,pos);
  var value = pairs[i].substring(pos+1);
  args[argname]=unescape(value);
 };
 return args;
};
function getCookie(name)
{
 var str;
 var cookies
 var i;
 var cookie;
 var re;
 str=document.cookie+"";
 if(str!="")
 {
  re=/\s*;\s*/;
  cookies=str.split(re);
  for(i=0;i<cookies.length;i++)
  {
   re=/\s*=\s*/;
   cookie=cookies[i].split(re);
   if(cookie.length==2)
   {
    if(name==cookie[0])
    {
     return unescape(cookie[1]);
    };
   };
  };
  return "undefined";
 };
 return "undefined";
};
function delCookie(name)
{
 var expireDate = new Date();
 expireDate.setFullYear(expireDate.getFullYear()-1);
 document.cookie=name+"=;expires="+expireDate.toGMTString()+";path=/";
};
function setCookie(name,value)
{
 var expireDate = new Date();
 expireDate.setFullYear(expireDate.getFullYear()+1);
 document.cookie=name+"="+escape(value)+";expires="+expireDate.toGMTString()+";path=/";
};
function onAServer()
{
 var re=/^http/i;
 return re.test(document.location);
};
function fileDialog(action,ext)
{
 if(onAServer() || localFilePossible())
 {
  if(!action)
  {
   if(onAServer())
   {
    window.open("../fs/filedialog.html", "","width=650,height=650,toolbar=no,location=no,menubar=no,resizable=no,status=no,scrollbars=yes");
   }
   else
   {
    window.open("filedialog.html", "","width=650,height=650,toolbar=no,location=no,menubar=no,resizable=no,status=no,scrollbars=yes");
   };
  }
  else
  {
   if(fileDialogWindow)
   {
    if(!fileDialogWindow.closed){fileDialogWindow.close();};
   };
   if(onAServer())
   {
    fileDialogWindow=window.open("../fs/filedialog.html?action="+action+"&ext="+ext, "FileDialog","width=450,height=600,toolbar=no,location=no,menubar=no,resizable=no,status=no,scrollbars=yes");
   }
   else
   {
    fileDialogWindow=window.open("filedialog.html?action="+action+"&ext="+ext, "FileDialog","width=450,height=600,toolbar=no,location=no,menubar=no,resizable=no,status=no,scrollbars=yes");
   };
  };
 }
 else
 {
  alert("Local file operations not possible with this browser");
  return false;
 };
 return true;
};
function saveFileAs(ext)
{
 return fileDialog("Save",ext);
};
function editFile(filename,ext)
{
 if(onAServer())
 {
  window.open("../fs/Edit.php?filename="+escape(filename)+"&ext="+ext, "EditWindow","width=650,height=650,toolbar=no,location=no,menubar=no,resizable=no,status=no");
 }
 else
 {
  window.open("Edit.html?filename="+escape(filename)+"&ext="+ext, "EditWindow","width=650,height=650,toolbar=no,location=no,menubar=no,resizable=no,status=no");
 };
};
function newFile()
{
 window.open("../oxcal/OxCalInput.html?","", "toolbar=yes,location=yes,menubar=no,resizable=yes,status=yes");
};
function localFilePossible()
{
 if(document.URL.indexOf("file://")==0)
 {
  if(typeof Components!="undefined"){return true;};
 };
 return false;
};
if(!onAServer() && localFilePossible())
{
 document.writeln('<script type="text\/javascript" src="../fs/moz_extensions.js"><\/script>');
};