
// 12-FEB-2000 jzhuk edit() to scale and compose new
// 22-SEP-2000 okuskin new varible hrefURL
// 04-oct-jzhuk changed link to file from action=update_page to action=readPage
// 20001227-jzhuk/alt insert <head> between <html> and <title> in 
var name = '';
var nCheckBoxes = 0;
var nFolders = 0;
var currentdir = '';
var isPrivate = true;
var isPublic = false;
var isShared = false;
var printJS;
var webInterface;

var uploadPart;
var myCall;
var tie;
var Public;
var pub,priv,club;
var arrayOfDir = new Array();
var pathArray  = new Array();

var LYFKwindow;
var hrefURL = this.location.href+"?";

// alex 10-13 
var docObj;
var aLinks = ['intercarnet','http://slayer.dorms.spbu.ru/intercarnet','javaschool','http://JavaSchool.com']

function isGood(what) {
    var i, ch; 
    var Good = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ -_.:()/\"\\\\';
    if (what.length == 0) 
        return 0;     
    for (i=0; i < what.length; i++) {
        ch = what.charAt(i);
        if (Good.indexOf(ch) == -1) 
            return 0;
    }
    return 1;
}
//var fileActions = new Array('Copy','Cut','Paste','Send');

function postTo(obj, action) {
//alert('obj='+obj+' action='+action+' objName='+obj.name+' form='+obj.form);
    var form = obj.form;
    var objName = obj.name;
    if(objName == 'showType') {
        action = form.services.value;
    } else if(objName == 'app') {
        action = 'go';
    } else if(objName == 'changeCurrent' || objName == 'changeChecked') {
        obj.options[0].selected = true;
    }
    
alert('objName='+objName + ' form='+form + ' formAction='+form.action + ' action='+action);
    form.action.value = action;
    if(action == 'Send') {
//alert('fileAction='+action + ' form='+form.name);
        form.action.value = '';
        form.call.value = action;
        form.submit();
    }
    if(action == 'edit') {
        return edit(form);
    } else if(action == 'new_folder') {
        return makeNewDir();
    } else if(action == 'new_page') {
        form.arg.value = prompt('Enter the name');
    } else if(action == 'rename') {
        return changeName(form);
    } else if(action == 'unzip') {
        return unzip(form);
    } else if(action == 'Compress') {
        return zip(form);
    } else if(action == 'new_link') {
        return easyDialog('this.form', 'Create a NEW Link: provide URL and Title for the link', 
          'New Link', 'new_link', 'URL,Title',form); 
    } else if(action == 'favorite') {
        return easyDialog('this.form', 'Please evaluate (grade) your Favorite Page',
          'Beyond Expectations,Excellent,Very Good,Good,Useful', 'favor5,favor4,favor3,favor2,favor1', '', form);
    }
//alert('formAction='+form.action.value);
    form.submit();
}
function setCommonArgs() {
    commonArgs = 'u=' + u + '&s='+ session;
    
}
function getTo(action) {
    setCommonArgs();
    var url = '/go/private.ip?'+commonArgs + '&action='+action;
    main.location = url;
}
function goToURL(start, action, paramName, param) {
    var url = start+action + '&' + paramName + '=' + param;
//alert('url='+url);
    main.location = url;
}

function writeLinks(arrayOfLinks)
{
   var iLoop = 0;
   //Loop through the array and write the menu
   for(iLoop=0; iLoop < arrayOfLinks.length; iLoop+=3)
   {
       writeLink(arrayOfLinks[iLoop], arrayOfLinks[iLoop + 1],arrayOfLinks[iLoop + 2]);
   }

}

function writeLink(Url, LinkName, type)
{
   //If type is 'S' it is a submenu
   if(type == 'S')
   {
       document.write('    <a href=' + Url + '>' + LinkName + '</a><br>');
   }
   else
   {
       document.write('<a href=' + Url + '>' + LinkName + '</a><br>');
   }
}

function demo(name, documentObj) {
    var i=0;
    for(i=0; i<aLinks.length; i+=2) {
        if(name == aLinks[i] ) {   
            documentObj.location.href = aLinks[i+1];
        }
    }
}
///////////////////////////////////////////////////////////////
function demo1(name, documentObj) {
    documentObj.location.href = 'http://slayer.dorms.spbu.ru/intercarnet';
}
function setReadOnlyAlert() {
    alert('Read Only Access');
}

function printUpName (lowerCaseStr) {
   var firstLetter = lowerCaseStr.charAt(0).toUpperCase();
   return firstLetter + lowerCaseStr.substring(1, lowerCaseStr.length);
}
var hostName = printUpName(this.location.hostname);

function launchNewWindow(location, width, height) {
    var x = Math.round((screen.width - width)/2);
    var y = Math.round((screen.height - height)/2);
    var windowFeatures = 'menubar=no,toolbar=no,location=no,status=no,scrollbars=auto,resizable=yes,maximize=no';
    myWin = open(location,'_blank','left='+x+',top='+y+',width='+width+',innerWidth='+width+',height='+height+',innerHeight='+height+','+windowFeatures);
}
function openNewWindow(location, windowName) {
    openNewWindow(location,0.1,0.1,0.8,0.7,'menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes,maximize=yes',windowName);
}
function openNewWindow(location,w,h) {
    openNewWindow(location,0.1,0.1,0.8,0.7,'menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes,maximize=yes');
}

function openNewWindow(location,left, top, width, height, features) {
    openNewWindow(location,left, top, width, height, features,"");  
}
function openNewWindow(location,left, top, width, height, features, windowName) {
    if(features == null) {
        features = "";
    }
    if(windowName == null || windowName == "") {
        windowName = "displayWindow";
    }
    myWin = open(location,windowName,'left='+(screen.width*left)+',top='+(screen.height*top)+',width='+(screen.width*width)+',innerWidth='+(screen.width*width)+',height='+(screen.height*height)+',innerHeight='+(screen.height*height)+','+features);
}

/////// alex 11-3
function redirect(newURL, formObj, documentObj,param) {
  //var param = "";
  for (i=0 ; i < formObj.elements.length; i++) {
      if((formObj.elements[i].type == 'checkbox') && !(formObj.elements[i].checked)) {
         continue;
      }
      if (param == null || param.length == 0) {
          param = formObj.elements[i].name + "=" + formObj.elements[i].value;
      }else {
          param = param + "&" + formObj.elements[i].name +"=" + escape(formObj.elements[i].value);
      }
 }
//alert(newURL + "?" + param);
 documentObj.location.href = newURL + "?" + param;
}

/////// mikhail 4/17/01
function loadFile(newURL, formObj, documentObj) {
    var checks = checkArray(formObj);
    if(checks.length > 1 || checks.length == 0) {
       alert('Select one file only, please')
       return
    } else {

      var fileName = eval('parent.main.document.forms[0].checkbox_'+checks[0]+'.value')
      if(fileName.indexOf('.dxf') != -1) {
          redirect(newURL, formObj, documentObj,'loadType=Floor%20Plan')
        return
      }
      if(fileName.indexOf('.ports') != -1) {
        //alert('Site under development')
          redirect(newURL, formObj, documentObj,'loadType=PBX%20Port')
        return
      }
      loadFileDialog(newURL, formObj, documentObj);
    }
}
/////// mikhail 4/17/01
function loadFileDialog(newURL, formObj, documentObj){
   win = open("","cprompt","toolbar=no,addressbar=no,status=no,resizable=no,scrollbars=no,width=390,height=200");

   win.document.open();

   win.document.writeln("<html>\n<head>\n<title>Load File</title>\n");
   win.document.writeln("</head>\n<body bgcolor=#FFFFFF>\n" +
                       "<center>\n<font face=verdana size=2><b>" +
                       "The extension of the selected file is unknown. " +
                       "Please,specify the load process.</b></font>\n" +
                       "<FORM name='ed' onSubmit=\"opener.redirect('"+newURL+"',document.forms[0], opener.top.main.document);self.close();\">\n" +
                       "<input type=submit value='Floor Plan' onclick=\"form.loadType.value=this.value\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                       "<input type=submit value='PBX Port' onclick=\"form.loadType.value=this.value\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
                       "<input type=button value='Cancel' onclick=self.close();>");
win.document.writeln("<input type=hidden name=loadType value=\"\">");
  for(var i = 0; (formObj != null && i < formObj.elements.length); i++) {
      if((formObj.elements[i].type == 'checkbox') && !(formObj.elements[i].checked)) {
         continue;
      }
      win.document.writeln("<input type=hidden name="+formObj.elements[i].name+" value="+formObj.elements[i].value+">");
  }
  win.document.writeln("</FORM>\n" +
                       "</center>\n" +
                       "</body>\n</html>\n"
                       );
   //win.document.close();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NewWnd() - creates a new window
function NewWnd(iSrc)
{
   iSrc = hrefURL + commonArgs + iSrc + "";
//alert(iSrc);
   var w;
   w = open(iSrc,"module","resizable=yes,scrollbars=yes,width=360,height=260,left=250,top=300");
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// easyDialog() - creates a window w/ the passed number of buttons adn actions
function easyDialog(formTitle, iMesg, iButtons, iActions, iFields, iAddHidden)
{
   var win = null;
//alert('formTitle='+formTitle + ' iMesg='+iMesg + ' iButtons='+iButtons + ' iActions='+iActions + 
//' iFields='+ iFields + ' iAddHidden='+ iAddHidden +'!');
   var commonArg = printHiddenCommonArgs(commonArgs);
//alert("commonArg="+commonArg);

   var allNames = new Array();
   if(formTitle != 'this.form' && iAddHidden != null)
   {
       var hiddens = new Array();
       var nvs = new Array();
       var nv = "";
       var name = "";
       var value = "";  

       hiddens = iAddHidden.split(/,/);

       for(var h = 0; h < hiddens.length; h++)
       {
           if(hiddens[h].indexOf("=") != -1)
           {
               nv = hiddens[h];
               nvs = nv.split("=");

               name = nvs[0];
               value = nvs[1];
               allNames[h] = name;
           }
           else
           {
                name = hiddens[h];
                value = "";
           }

           commonArg += "\n<input type=hidden name='" + name + "' value='" + value + "'>";

       }
   }

   var h;    

   var fields = "<table border=0 cellspacing=2 cellpadding=2 width='100%'>\n<input type=hidden name='action' value=''>" + 
                 commonArg + "<tr>";

   var texts = "";
   var bgcolor = "#c0f0c0";

   var buttons = new Array();
   var actions = new Array();

   buttons = iButtons.split(/,/);
   actions = iActions.split(/,/);

   //chose right height
   if(buttons.length > 1)
   {
       h = (buttons.length) * 45;
   }
   else
   {
       h = (buttons.length) * 60;
   }

   //don't get it too big
   if(h > 500)
   {
       h = 500;
   }
   else if(h < 400)
   {
       h = 400;
   }


    //are there extra text fields?
   if(iFields != "" && iFields != null)
   {
      var tFields = new Array();
      tFields = iFields.split(/,/);
      texts += "<table border=0>";

        //must increase height
      h = (buttons.length +  + tFields.length) * 45;
      var allNamesLength = allNames.length;

      for(var i = 0; i < tFields.length; i++)
      {
          texts += "<tr><td><font face=verdana size=2>\n" + tFields[i] + ":</td><td><input type=text name='" + tFields[i] + "' value=''></font></td></tr>\n";
          allNames[allNamesLength++] = tFields[i];
      }

      texts += "</table>";

   }

   var splits = new Array();
   var str = "";
   var nm = "";
   var link = "";

   var MAIN = null;
   var parentFormIndex = 0;
   if(formTitle != 'this.form') {
       MAIN = getParentForm(formTitle);
       parentFormIndex = getParentFormIndex(formTitle);
   } else {
       MAIN = iAddHidden;
   } 
   if(buttons.length == actions.length)
   {
       for(var i = 0; i < buttons.length; i++)
       {
          link = "";         
          if((i%2) == 0)
          {
              bgcolor = "#c0c0f0";
          }
          else
          {
              bgcolor = "#c0f0c0";
          }
          if(buttons[i].indexOf("=>") != -1)
          {
              str = buttons[i];
              splits = str.split("=>");

              name = splits[0];
              link = splits[1];

              //link = "opener.parent.NewWnd('')";
          }
          else
          {
              name = buttons[i];
              if( texts != null && texts.length != 0){
                 link = "if(validate(document.forms[0]))";
              }     
              link += "{opener.parent.JSsubmit(" + parentFormIndex + 
                ",\'action\', \'" + actions[i] + "\');self.close();}";
          }

//alert("ED link=" + link);
          fields += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2>";
            
          var add_l = "";

          if(iFields != "")            // jz forms[0]
          {
              add_l = "opener.parent.initForm(document.forms[0],'" +  allNames + "');";
          }
          fields += "<a href=\"javascript:" + add_l + link + "\">" + name + 
                      "</font></a></td>\n";
       }
//alert("ED add_l="+ add_l);        
       if(bgcolor == "#c0c0f0")
       {
          bgcolor = "#c0f0c0";
       }
       else
       {
          bgcolor = "#c0c0f0";
       }

        //add close button
        fields += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2><a href='javascript:self.close()'>Cancel</font></a></td>\n";
   }

   if(formTitle == "" || formTitle == null)
   {
       formTitle = "Prompt";
   }

   win = open("","cprompt","toolbar=no,addressbar=no,status=no,resizable=yes,scrollbars=yes,width=390,height=" + h + "");

   win.document.open();

   win.document.writeln("<html>\n<head>\n<title>" + formTitle + "</title>\n");
   win.document.writeln("<script language=\"javascript\"><!--\n");
   win.document.writeln("function validate(frm) {");
//   win.document.writeln("  alert(frm);");
   win.document.writeln("  var i;");
//   win.document.writeln("  alert(frm.elements.length);");
   win.document.writeln("  for(i = 0; (frm != null && i < frm.elements.length); i++) {");
//   win.document.writeln("  alert('type='+frm.elements[i].type);");
//   win.document.writeln("  alert('value='+frm.elements[i].value);");
   win.document.writeln("     if((frm.elements[i] != null) && (frm.elements[i].type == \"text\") && (frm.elements[i].value == \"\")) {");
   win.document.writeln("         alert('This field can not be blank.');");
   win.document.writeln("         frm.elements[i].focus();");
   win.document.writeln("         return false;");
   win.document.writeln("     }");
   win.document.writeln("  }");
   win.document.writeln("  return true;");
   win.document.writeln("}");

   win.document.writeln("var IE4 = (document.all);");
   win.document.writeln("var NS4 = (document.layers);");
   win.document.writeln("if (NS4)");
   win.document.writeln("document.captureEvents(Event.KEYPRESS);");
   win.document.writeln("document.onkeypress = doKey;");
   win.document.writeln("function doKey(e){");
   win.document.writeln("   var whichASC = (NS4) ? e.which : event.keyCode;");
   win.document.writeln("   if (whichASC == 13)");
   win.document.writeln("   {");
   win.document.writeln("       return false;");
   win.document.writeln("   }");
   win.document.writeln("   return true;");
   win.document.writeln("}");

   win.document.writeln("\/\/-->\n","<\/","script>");
   win.document.writeln("</head>\n<body bgcolor=#FFFFFF>\n" +
                       "<center>\n<font face=verdana size=2><b>" + iMesg + "</b></font>\n" +
                       "<FORM name='" + formTitle + "'>\n" +
                       "" + texts + fields + "" + 
                       "\n</tr></table>\n</FORM>\n</center>\n" +
                       "</body>\n</html>\n"
                       );

   win.document.close();

}

////////////////////////////////////////////////////////////////////////
// ()


function choiceDialog(iTitle, iMesg, iButtons, iActions, iFields, iAddHidden)
{
   var win = null;
   var commonArg = printHiddenCommonArgs(commonArgs);
   var allNames = new Array();
   if(iAddHidden != null)
   {
       var hiddens = new Array();
       var nvs = new Array();
       var nv = "";
       var name = "";
       var value = "";  

       hiddens = iAddHidden.split(/,/);

       for(var h = 0; h < hiddens.length; h++)
       {
           if(hiddens[h].indexOf("=") != -1)
           {
               nv = hiddens[h];
               nvs = nv.split("=");

               name = nvs[0];
               value = nvs[1];
               allNames[h] = name;
           }
           else
           {
                name = hiddens[h];
                value = "";
           }

           commonArg += "\n<input type=hidden name='" + name + "' value='" + value + "'>";
       }
   }

   var h;    

   var fields = "<table border=0 cellspacing=2 cellpadding=2 width='100%'>\n<input type=hidden name='action' value=''>" + 
                 commonArg + "<tr>";

   var texts = "";
   var bgcolor = "#c0f0c0";

   var buttons = new Array();
   var actions = new Array();

   buttons = iButtons.split(/,/)
   actions = iActions.split(/,/)

   //chose right height
   if(buttons.length > 1)
   {
       h = (buttons.length) * 45;
   }
   else
   {
       h = (buttons.length) * 60;
   }

   //don't get it too big
   if(h > 500)
   {
       h = 500;
   }
   else if(h < 400)
   {
       h = 400;
   }

    //are there extra text fields?
   if(iFields != "" && iFields != null)
   {
      var tFields = new Array();
      tFields = iFields.split(/,/);
      texts += "<table border=0>";

        //must increase height
      h = (buttons.length + tFields.length) * 45;
      var allNamesLength = allNames.length;
      texts += "<tr><td><font face=verdana size=2>Select:</font></td><td><select name='" + tFields[0] + "' size=1>\n";
      allNames[allNamesLength++] = tFields[0];
      for(var i = 1; i < tFields.length; i++)
      {
          texts += "<option value='" + tFields[i] + "'>" + tFields[i] + "</option>";
      }
      texts += "</select></td></tr>\n";
      texts += "</table>";
   }

   var splits = new Array();
   var str = "";
   var nm = "";
   var link = "";

   if(buttons.length == actions.length)
   {
       for(var i = 0; i < buttons.length; i++)
       {
          link = "";
          if((i%2) == 0)
          {
              bgcolor = "#c0c0f0";
          }
          else
          {
              bgcolor = "#c0f0c0";
          }
          if(buttons[i].indexOf("=>") != -1)
          {
              str = buttons[i];
              splits = str.split("=>");

              name = splits[0];
              link = splits[1];

              //link = "opener.parent.NewWnd('')";
          }
          else
          {
              name = buttons[i];
              if(document.forms != null) {
                  if(document.forms[0] != null) {
                      link = "if(validate(document.forms[0]))";
                  }
              }
              link += "{opener.parent.JSsubmit(0,\'action\',\'" + actions[i] + "\');self.close();}";
          }

          fields += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2>";
            
          var add_l = "";

          if(iFields != "")
          {
//alert("ED before initForm");
              add_l = "opener.parent.initForm(document.forms[0],'" +  allNames + "');";
//alert("add_l="+add_l);
          }
//alert("link=" + link);
          fields += "<a href=\"javascript:" + add_l + link + "\">" + name + 
                      "</font></a></td>\n";
       }
        
       if(bgcolor == "#c0c0f0")
       {
          bgcolor = "#c0f0c0";
       }
       else
       {
          bgcolor = "#c0c0f0";
       }

        //add close button
        fields += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2><a href='javascript:self.close()'>Cancel</font></a></td>\n";
   }

   if(iTitle == "" || iTitle == null)
   {
       iTitle = "Prompt";
   }
   var MAIN = parent.main.document.forms[0];  // forms[0]
   var formName = MAIN.name;
   win = open("","cprompt","toolbar=no,addressbar=no,status=no,resizable=yes,scrollbars=yes,width=390,height=" + h + "");

   win.document.open();

   win.document.writeln("<html>\n<head>\n<title>" + iTitle + "</title>\n");
   win.document.writeln("</head>\n<body bgcolor=#FFFFFF>\n" +
                       "<center>\n<font face=verdana size=2><b>" + iMesg + "</b></font>\n" +
                       "<FORM name='" + formName + "'>\n" +
                       "" + texts + fields + "" + 
                       "\n</tr></table>\n</FORM>\n</center>\n" +
                       "</body>\n</html>\n"
                       );

   win.document.close();

}

////////////////////////////////////////////////////////////////////////
// get a proper form from a parent document based on the form name in the open JS window
function getParentForm(fromFormName) { 
    var numberOfForms = parent.main.document.forms.length;
    // get a proper form
    var MAIN = parent.main.document.forms[0];  // forms[0]
    var formName = MAIN.name;
//alert("nForms="+numberOfForms + " formName="+formName + " fromFormName="+fromFormName);
    if(numberOfForms > 1 && formName != fromFormName) {
        for(var i=1; i < numberOfForms; i++) {
            MAIN = parent.main.document.forms[i];
            formName = MAIN.name;
            if(formName == fromFormName) {
                break;
            } else {
                MAIN = parent.main.document.forms[0];
                formName = MAIN.name;
            } 
        }
    }
    return MAIN;
}
function getParentFormIndex(fromFormName) { 
    var numberOfForms = parent.main.document.forms.length;
    // get a proper form
    var MAIN = parent.main.document.forms[0];  // forms[0]
    var formName = MAIN.name;
    var parentFormIndex = 0;
// alert("nForms="+numberOfForms + " formName="+formName + " fromFormName="+fromFormName);
    if(numberOfForms > 1 && formName != fromFormName) {
        for(var i=1; i < numberOfForms; i++) {
            MAIN = parent.main.document.forms[i];
            formName = MAIN.name;
            parentFormIndex = i;
            if(formName == fromFormName) {
                break;
            } else {
                MAIN = parent.main.document.forms[0];
                formName = MAIN.name;
                parentFormIndex = 0;
            } 
        }
    }
    return parentFormIndex;
}
function initForm(iFromForm, iFlds)
{
    var CURR = iFromForm;
    var fromFormName = CURR.name;
    var MAIN = getParentForm(fromFormName);
    var names = new Array();
    names = iFlds.split(/,/);

    //names = ("Name", "tie");

//alert("form="+fromFormName + " main="+MAIN.name);

    if(names.length > 0)
    {
        for(var i = 0; i < names.length; i++)
        {    

//alert("i=" + i + " name=" + names[i] + " curr.value=" + CURR.elements[names[i]].value);
            if(MAIN.elements[names[i]])
            {
//alert(i + ":" + MAIN.elements[names[i]].value);
                MAIN.elements[names[i]].value = CURR.elements[names[i]].value;
//alert(i + ":" + MAIN.elements[names[i]].value);
            }
             //setFields(MAIN, "Name", CURR.elements[i].value);
        }

    }
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// convertToStrings() - converts a set of commonArgs (u=flanker&action=hello) to two string names, and vals
function convertToStrings(iArg)
{

//alert("convertToStrings.iArg: " + iArg);

    var fields = new Array();
    var splits = new Array();

    var Names = "";
    var Values = "";
    var str = "";

    fields = iArg.split(/&/);
     
    for(var i = 0; i < fields.length; i++)
    {
         str = fields[i];
         splits = str.split(/=/);

          Names  += "" + splits[0] + ",";
          Values += "" + splits[1] + ",";
    }

    var data = Names + "<<>>" + Values;

    //alert("convert: " + data);
     
    return (data);
    //return (Names, Values);
}


//////////////////////////////////////////////////////////////////////
// setFields() - sets fields of a form to certain values
function setFields(iFrm, iNam, iVal)
{

//alert("setFields() called");
//alert("iVal = " + iVal);
//alert("iNam = " + iNam);

     var vals = new Array();
     var nams = new Array();

     vals = iVal.split(/,/);
     nams = iNam.split(/,/);

     if(vals.length == nams.length)
     {

//alert("inside if in setFields");

          for(var i = 0; i < vals.length; i++)
          {
                if(iFrm.elements[nams[i]])
                {
                  iFrm.elements[nams[i]].value = vals[i];
                }
          }
     }
     return true;
}


//////////////////////////////////////////////////////////////////////
// printHiddenCommonArgs() - returns html code w/hidden fields
function printHiddenCommonArgs(args)
{

//alert("ARGS: " + args);
//args.replace(" ","");

    var arr = new Array();
     var splits = new Array();

     var str = "";
     var html = "";

     arr = args.split("&");

//alert("LEN: " + arr.length); 

     for(var i=0; i < arr.length; i++)
     {
         str = arr[i];
    
//alert(str);

          if(str != "" && str != "undefined")
          {
                splits = str.split(/=/);
            html += "<input type=hidden name='" + splits[0] + "' value='" + splits[1] + "'>\n"; 
          }
          else
          {
             html += "";
          }
          
     }
     return html; 
}
 
//////////////////////////////////////////////////////////////////////
// submitter() = submits a form w/ additional params
// @params = arrNames - names of fields ex: "n1,n2,n3", arrValues - values of fields
function submitter(iFID,iNames,iValues)
{  

//alert('submitter:'+iFID + ", " + iNames + ", " + iValues);
    
    var FRM = iFID;

//alert("FRM.elements[0].value = " + FRM.elements[0].value);
    
    var arrNames  = new Array();
    var arrValues = new Array();

    if((iNames != null && iValues != null))
    {
        arrNames  = iNames.split(/,/);

//alert("arrNames[0] = " + arrNames[0]);
        
        arrValues = iValues.split(/,/);
        
    }

     //must be present and equal to each other to add new fields
    if((arrNames != null && arrValues != null) && (arrNames.length == arrValues.length))
    {
        for(var i=0; i < arrNames.length; i++)
        {
            if(FRM.elements[arrNames[i]])
            {

//alert("arrValues[i]="+arrValues[i]);

                FRM.elements[arrNames[i]].value = arrValues[i];

//alert("FRM.elements[arrNames[i]].value="+FRM.elements[arrNames[i]].value);
            }
        }
    }

    FRM.submit();
}


///////////////////////////////////////////////////////////////////////
// JSsubmit() - submits a form in right frame by default
function JSsubmit(iFID, iNames, iValues)
{
    var fID = parent.main.document.forms[iFID];
    submitter(fID, iNames, iValues);
}

//////////////////////////////////////////////////////////////////////////////
// JSsubmitFullPath() - submits a form on a given path (ex: document.forms[5])
function JSsubmitFullPath(iFID, iNames, iValues)
{

//alert("FORM PATH " + iFID.attributes["action"].value + "");
    submitter(iFID, iNames, iValues);    
}

//////////////////////////////////////////////////////////////////////////////
function mailWindow(newURL) 
{
  var html;
  if(LYFKwindow == null || LYFKwindow.closed) 
  {
      LYFKwindow = open(newURL,"LYFKwindow","resizable=no,scrollbars=no,width=360,height=260,left=250,top=300");
  }
  LYFKwindow.focus();
}

 var firstSubmit = 0;
 var message = "";

 ///////////////////////////////////////////////////////////////////////////////
 // sendIt()
 function sendIt(n) 
 {

     message = LYFKwindow.document.let.body.value + "\n" + parent.main.document.composeForm.largeText.value;
    //alert("n=" + n + " first=" + firstSubmit + " message=" + message);
  
 if(n == 2 && firstSubmit == 1) 
 {
    firstSubmit = 0;
    return false;
 } 
 else if(n == 2 && firstSubmit == 2) 
 {
    return true;
 }

 if(LYFKwindow.document.let.to.value == "") 
 {
   alert("Please enter the e-mail address\nor member name")

   LYFKwindow.focus();

   if(n == 1) 
   {
       firstSubmit=1;
   }
 
 } 
 else 
 {
    parent.main.document.composeForm.emailTo.value = LYFKwindow.document.let.to.value;

    if(LYFKwindow.document.let.body.value != "") 
    {
        parent.main.document.composeForm.largeText.value = LYFKwindow.document.let.body.value + parent.main.document.composeForm.largeText.value;
    }

    if(LYFKwindow && !LYFKwindow.closed) 
    {
        LYFKwindow.close();
    }

    firstSubmit = 2;

//alert("first=" + firstSubmit + " large=" + parent.main.document.composeForm.largeText.value + " emailTo=" + parent.main.document.composeForm.emailTo.value);

    parent.main.document.composeForm.submit();

    return true;
 }

 return false;

}

var buttonWindow;

//////////////////////////////////////////////////////////////////////////////
function openWindow(text)
    {     buttonWindow=window.open(
"","buttonWindow","resizable=1,scrollbars=1,width=375,height=390,left=120,top=50");
        buttonWindow.document.open();
        buttonWindow.document.write(text);
        buttonWindow.document.close();
    }



function replaceString(s, oldPattern, newPattern) { // replace old string pattern with the new one
  var i, lenOfOldPattern, newString, restOfString;
  for(;;) { 
    i = s.indexOf(oldPattern);
    if(i == -1) { // no oldPattern found
        return s;
    }
    lenOfOldPattern = oldPattern.length;
    newString = s.substring(0, i);
    restOfString = s.substring(i+lenOfOldPattern);        
//alert('beginning=' + newString + '!lenOfOldPattern=' + lenOfOldPattern + '!rest=' + restOfString);
    newString += newPattern + restOfString;
    s = newString;
  }
  return s;
}

function replace(nameStr,oldChar,newChar) 
{
 var i;
 var newNameStr='';
 var ch = '';

   for(i=0; i < nameStr.length; i++) 
   {
       ch = nameStr.charAt(i);

       if(ch == oldChar) 
       {
          ch = newChar
       }

       newNameStr +=ch
   }

   return newNameStr
}

function changeName(form) {
      var checks = checkArray(form)
      if(checks.length > 1) {
         alert('Select one file only, please')
         return
      } 
      else if(checks.length == 0) 
      {
         alert('There is nothing to rename.\nPlease select a file or folder')
         return
      }

      newname=new String;
      newname=prompt("Enter a New Name:","");
      
      if ((newname) && (newname.length!=0)) 
      {
        newname = replace(newname,' ','_')
        JSsubmit(0,"action,newName","rename," + newname);
      }
}

function makeNewDir () 
{
          newname = new String;
          newname = prompt("Enter New Directory Name:","");

          if ((newname)&&(newname.length!=0)) 
          {
            newname = replace(newname,' ','_')
            JSsubmit(0,"arg",newname);
          }
}

function checkArray(form) 
{
   var i,j = 0
   var formName = form.name;
   var checks = new Array
      for(i = 0; i < nCheckBoxes; i++) {
          var str = 'form.checkbox_'+i+'.checked';
          if(eval(str)) {
              checks[j] = i;
              j++;
          }
      }
      return checks;
}
function checkAllOnPage(form, fEmail, lEmail) {
    var i;
    if(form.checkAllBox.checked) {
      for(i = fEmail; i <= lEmail; i++) {
           var chk = eval('form.check_'+i);
           if(chk.checked) {
               continue;
           } else {
               chk.checked=true;
           }
       }
     } else {
       for(i = fEmail; i <= lEmail; i++) {
           var chk = eval('form.check_'+i);
           if(!chk.checked) {
               continue;
           } else {
               chk.checked=false;
           }
       }
    }
}
function checkAll() {
    var i;
    if(!parent.main.document.forms[0].checkAllBox.checked) {
        for(i = nFolders; i < nCheckBoxes; i++) {
          var str = eval('parent.main.document.forms[0].checkbox_'+i);
          str.checked = false;
        }
    } else {
        for(i = nFolders; i < nCheckBoxes; i++) {
          var str = eval('parent.main.document.forms[0].checkbox_'+i);
          str.checked = true;
        }
    }
    return true;
}

function filemanager(functionName) 
{
     JSsubmit(0, "action", functionName);
}

// Returns true if character c is a digit
// (0 .. 9).
function isDigit (c)
{   
    return ((c >= "0") && (c <= "9"))
}
      
function edit(form) 
{
  var checks = checkArray(form);
  var i=0;
  var fileName="";
  var wrong = "";
  var gifNames = "";
  var scale = "";

  if(checks.length > 1) 
  {
     for(i=0; i < checks.length; i++) {
         fileName = eval('parent.main.document.forms[0].checkbox_'+checks[i]+'.value')
         if(fileName.indexOf(".gif") == -1 && fileName.indexOf(".GIF") == -1) {
              wrong += " " + fileName;
         } else {
              if(gifNames == "") {
                  gifNames = fileName;
              } else { 
                  gifNames += "," + fileName;
              }
         }
     }
     
     if(gifNames == "") 
     {
         alert('Only GIF images are allowed for multiple editing (scaling), Please make another selection');
         return;
     } 
     else 
     {
         if(wrong != "") {
             wrong = 'Other selected files: ' + wrong + ' are not changing.';
         }
         scale = prompt('Enter scale factor (2-9) or size WxH (pixels) for GIF images' + gifNames + ' to scale down. ' + wrong);
         if(scale == "" || scale == null) {
             scale = 4;         
             alert('Default scale factor = 4');
         } 
         //parent.main.document.forms[0].scale.value = scale;
         //parent.main.document.forms[0].editFile.value = gifNames;
         //parent.main.document.forms[0].submit();
         
         //var aNames  = new Array("scale","editFile"); 
         //var aValues = new Array(scale,gifNames);
         JSsubmit(0,"scale,editFile", "" + scale + "," + gifNames + "");
     }
  }  else if(checks.length == 1) {
     if(checks[0] < nFolders) 
     {
         alert('Folder can not be edited')
         return;
     }
 
     fileName = eval('parent.main.document.forms[0].checkbox_'+checks[0]+'.value');
     if(fileName.indexOf(".jpg") != -1 || fileName.indexOf(".JPG") != -1) {
         alert('Only GIF file can be edited or scaled down')
         return;
     } 
     if(fileName.indexOf(".gif") != -1 || fileName.indexOf(".GIF") != -1) {
         scale = prompt('Enter scale factor (2-9) or size WxH (pixels) for ' + fileName + ' or Press CANCEL to EDIT the image');
         if(scale == null) {
             scale = 'e';             
         }
         parent.main.document.forms[0].scale.value = scale;
     }
     //parent.main.document.forms[0].editFile.value = fileName;
     //parent.main.document.forms[0].submit();
     
     JSsubmit(0,"editFile",fileName);
  } else {
      alert("Please select a file to edit.");
  }

}

function deleteIt(form) {
    var checks = checkArray(form)
    var i
    if(checks.length == 0) {
        alert('There is nothing selected')
        return
     }
}

function compress() 
{
alert("Compress");
          newname = new String;
          var i, howManyChecked = 0, index = 0

          for( i = 0; i <= (nCheckBoxes - 1); i++) 
          {
              var strToEval = 'parent.main.document.forms[0].checkbox_'+i
              var valueOfIt = eval(strToEval+'.value')
              if(eval(strToEval+'.checked')) {
                  howManyChecked++
                  if(valueOfIt.indexOf('.gz') != -1) {
                      index++
                  }
                  if(i < nFolders) {
                      alert('Sorry.\nFolder can not be compressed')
                      return
                  }
              }
          }
          if(index > 1 && index == howManyChecked) 
          {
              alert('Please select one gz-file at the time ONLY')
          } 
          else if(index == 1 && howManyChecked == 1) 
          {
              parent.main.document.forms[0].submit();
          } 
          else if(howManyChecked > 0)
          {
              newname = prompt("Enter Resulting Compressed File Name:","");
              if ((newname)&&(newname.length!=0)) 
              {
                  newname = replace(newname,' ','_')
                  
                  //parent.main.document.forms[0].newZip.value=newname;
                  // parent.main.document.forms[0].submit();

                  JSsubmit(0,"newZip",newname);
              }
          } 
          else 
          {
              alert('There is nothing selected for un/compress')
          }
}

function closeWindow() 
{
   if(buttonWindow && !buttonWindow.closed) 
   {
       buttonWindow.close()
   }
}

/////// Search start
function resultWindow(str) 
{
  if(!buttonWindow || buttonWindow.closed) 
  {
      buttonWindow = open("","search","height=200,width=400,toolbar=0,scrollbars=1")
  } 
  else 
  {
     buttonWindow.focus()
  }
     buttonWindow.document.open()
     buttonWindow.document.writeln('<html><head><title>Search results</title>')
     buttonWindow.document.writeln('</head><body>')
     buttonWindow.document.writeln('<form><input type=button name=close value=Close onclick="window.close()">')
     buttonWindow.document.writeln('</form>')
     buttonWindow.document.writeln(str)
     buttonWindow.document.writeln('</body></html>')
     buttonWindow.document.close()
}
function submitSearchWindow(obj) {
     closeWindow();
     buttonWindow=window.open("","buttonWindow","resizable=1,scrollbars=1");
     obj.submit();
}
function isValidSrch(form) 
{
 if(form.searchText.value == "") {
     resultWindow("Some help here!")
 } else {
    search(form)
 }
}

function getPattern(form) 
{
var str = form.searchText.value
var pattern = ''
var i
  for(i = 0; i < str.length; i++) {
      if(i == 0 && str.charAt(i) != '*' && str.charAt(i) != '.') {
          pattern += '^'
      }
      if(str.charAt(i) == '*') {
          pattern += '[0-9a-zA-Z]'
      } else if(str.charAt(i) == '.') {
          pattern += '\\.'
      } else if(str.charAt(i) == '?') {
          pattern += '\\w'
      } else {
          pattern += str.charAt(i)
      }
  }
  return pattern
}

function search(form) {
 var re = new RegExp(getPattern(form),"gi")
 var i = 0, j = 0, index = 0
 var matches = ""
 var root
 for(i = 0; i < arrayOfDir.length; i++) {
     var splits = arrayOfDir[i].split('|')
     for(j = 5; j < splits.length; j++) {
         var matchArray = re.exec(splits[j])
         if(matchArray) {
              root = splits[1].substring(splits[1].indexOf('/')+1)
              matches += '<br>'+root+'/<a href=javascript:opener.parent.showDir("'+splits[1]+'","'+splits[j]+'")>'+splits[j]+'</a>\n'
              index++
         }
      }
 }
 matches = (matches.length == 0) ? "There are no matches." : "<center><font color=4><b>"+index+" matches found</b></font></center>"+matches
 resultWindow(matches)
}

//////// Search end
function arrayOfPath(n) {
var tempArr;
   for( var i = 0; i < n; i++) {
      tempArr = arrayOfDir[i].split('|')
      pathArray[i] = tempArr[1]
   }
}

function goToPrivate(str,doc) 
{
//alert("inside goToPrivate:: str=" + str + " doc=" + doc);
  isPrivate = true
  isPublic = false
  isShared = false
  docObj = doc;
  showDir(str,"",doc);
}

function goToPublic(str,doc) {
//alert("inside goToPublic:: str=" + str + " doc=" + doc);
  isPrivate = false
  isPublic = true
  isShared = false
  docObj = doc;
//alert("docObj="+docObj);
  showDir(str,"",doc);
}

function goToShared(str,doc) {
//alert("inside goToShared:: str=" + str + " doc=" + doc);
  isPrivate = false
  isPublic = false
  isShared = true
//  docObj = doc;
  showDir(str,"",doc);

}

function getIconImage(fileName) {
  var icon ='<img src=/support/images/bin.gif border=0 alt='+fileName+'>' ;
  var i = 0;
  var exts = new Array('doc','txt','gif','jpg','jpeg','htm','html','pl','wav','au','mid','pdf','zip','tar','jar','rar','gz','wri','xls','swf');

  var indexOfDot = fileName.lastIndexOf('.')
  var ext = fileName.substring(indexOfDot+1).toLowerCase()
  name = fileName.substring(0,indexOfDot)
  for(i = 0; i < exts.length; i++) {
       if(ext.indexOf(exts[i]) != -1) {
           icon = '<img src=/support/images/'+exts[i]+'.gif border=0 alt='+fileName+'>'
           return icon;
       }
  }
  return icon;
}


 function AttachmentForCompose() {
    newname=new String;
    var i, howManyChecked = 0
    for( i = 0; i <= (nCheckBoxes - 1); i++) {
        var strToEval = 'parent.main.document.forms[0].checkbox_'+i
        var valueOfIt = eval(strToEval+'.value')
        if(eval(strToEval+'.checked')) {
            howManyChecked++
            if(i < nFolders) {
                alert('Sorry.\nFolder can not be mailed')
                return
            }
        }
    }
    if(howManyChecked > 0){
            //parent.main.document.forms[0].call.value="AttachmentForCompose";
            //parent.main.document.forms[0].submit();

            JSsubmit(0,"call","AttachmentForCompose");
        
    } else {
        alert('There is nothing selected for mail')
    }
 }

function run(doc, arIn,initDir,callIn,printIn,webIn,uploadIn,tieIn,commonArgsIn,clubIn) 
{
   docObj = doc;
   arrayOfDir = arIn;
   printJS = printIn;
   webInterface = webIn;
   uploadPart = uploadIn;
   tie = tieIn;
   commonArgs = commonArgsIn;
   myCall = callIn;
   if(clubIn != null) {
      gName = clubIn.substr(3); // gName is undefined
   }

//alert ('js.run:clubIn=' + clubIn + ' + ' uploadIn=' + uploadIn + ' initDir=' + initDir + ' callIn=' + callIn + ' tieIn=' + tieIn);
    
   if((myCall.indexOf("Images") != -1) || (myCall.indexOf("Sounds") != -1)) 
   {
       pub = pubdir + '/' + myCall;
       club = clubIn;
       priv = privdir + '/' + myCall;
   } 
   else 
   {
       pub = pubdir;
       priv = privdir;
       club = clubIn;
       clubdir = club;
    }

   arrayOfPath(arrayOfDir.length);

   if(initDir != null && initDir.length>0) 
   {
       showDir(initDir,"",doc);
   }
}


/**
Function creates the HTML formatted string with directory tree
dirName - string, full folder's path
*/
function showDir(dirName,markIt,doc) 
{
 var checkIndex   = 0
 var dir_for_link = ''
 var separateDirs = ''
 var folderTree   = ''
 var directories  = ''
 var files        = ''
 var strsize      = ''
 var  i = 0, k = 0, n = 0, j = 0;
 var arr;
 var flag = (markIt.length > 0) ? markIt : ""

 if(flag.length > 0) 
 { 
     self.focus() 
 }

 if(dirName.indexOf("/",3) == -1) 
 {
     var space = ""
 } 
 else 
 {
     var space = dirName.substring(dirName.indexOf("/",3)+1)
 }

 var parentDir  = '<table border=1 width=450 cellpadding=2 cellspacing=0><TR><TD align=left bgcolor=c0d0f0>'
     parentDir += '<input type=text name=searchText size=12><input type=button name=searchButton value="Search file" onClick="parent.isValidSrch(this.form)">'
     parentDir += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=checkbox name=checkAllBox onClick="parent.checkAll()">Check all files'
     parentDir += '<br><font color=dd0000><b>'

    if(myCall.indexOf("openSpace") == -1 && myCall.indexOf("Attachments") == -1 && myCall.indexOf("Forms"))
    {
       if(isPrivate) 
       {
           parentDir += 'Private:'
           
       } 
       else if(isPublic) 
       {
           parentDir += 'Public:'
       } 
       else 
       {
           parentDir += 'Shared:'
       }
    }

    parentDir +='</b></font>'
    
    for(i = 0; i < arrayOfDir.length; i++) 
    {
       if((pathArray[i].indexOf(dirName) != -1) && ( pathArray[i].length == dirName.length)) {
            
         arr = arrayOfDir[i].split('|');
         currentdir = arr[1];                   // full path to showing directory
         separateDirs = currentdir.split('/');  // separate the current dir by /
         var length_of = separateDirs.length;  //length
         if(length_of < 1) 
         {
             parentDir += '&nbsp&nbsp '+separateDirs[0];      // if root dir that showing plain
         } 
         else 
         {
            
             if((myCall.indexOf("Images") != -1) || (myCall.indexOf("Sounds") != -1)) 
             {
               
                 for(i = 2; i < length_of-1; i++) 
                 {
                        dir_for_link += separateDirs[i];
                        parentDir += '&nbsp&nbsp<a href=\"javascript:parent.showDir(\''+separateDirs[0]+'/'+separateDirs[1]+'/'+dir_for_link+'\',\'\',document);\">'
                        parentDir += separateDirs[i]+'</a><img src=/support/images/link.gif>';
                        dir_for_link += '/';
                 }
         
                  parentDir += '  <b> '+separateDirs[i]+'</b>';

            } 
            else if((myCall.indexOf("openSpace") != -1) || (myCall.indexOf("Attachments") != -1) || (myCall.indexOf("Forms") != -1)) 
            {
               
                for(i = 1; i < length_of-1; i++) 
                {
                   dir_for_link += separateDirs[i];
                   parentDir += '&nbsp&nbsp<a href=\"javascript:parent.showDir(\''+separateDirs[0]+'/'+dir_for_link+'\',\'\',document);\">'
                   parentDir += separateDirs[i]+'</a><img src=/support/images/link.gif>';
                   dir_for_link += '/';
                }
            //alert ('parentDir=' + parentDir);
                parentDir += '  <b> '+separateDirs[i]+'</b>';

            }
         }
         parentDir = replaceString(parentDir, '//', '/'); // 2001-10-31 jz

         var totalSize = (parseInt(arr[2])/1000) + ' kB';
         var ndirs     = parseInt(arr[3]);
         var nfiles    = parseInt(arr[4]);
         nCheckBoxes   = ndirs + nfiles
         nFolders      = ndirs
         strsize       = '<font size=2><b>Content of this folder : '+ndirs+' folders, '+nfiles+' files. Total size = '+totalSize+'</b></font>';
         k             =5+ndirs;

         for(i=5; i<k; i++) 
         {
             if((j % 5) ==0) 
             {
                 directories +='\n</tr><tr>\n'
             }

             if(arr[i] == flag) 
             {
                 directories +='<td valign=top width=70 bgcolor=aquamarine>'
             } 
             else 
             {
                 directories +='<td valign=top width=70>'
             }
             directories += '  <center><font size=2>'
             if(myCall.indexOf("openSpace") != -1) {
                 directories +='\n<input type=checkbox name=checkbox_'+checkIndex+' value='+arr[i]+'>'
                 checkIndex++
             }
             directories += '\n<a href=\"javascript:parent.showDir(\''+currentdir+'/'+arr[i]+'\',\'\',document);\">'
             directories += '<img border=0 src=/support/images/folder.gif><br>'
             directories += arr[i]+'</a></center></font></td>'
             j++;
         }

         directories = replaceString(directories, '//','/'); // 2001-10-31 jz

         n = k+nfiles;

         for(i = k; i < n; i++)  
         {
             if((j % 5) == 0 ) 
             {
                 files +='\n</tr><tr>\n'
             }

             if(arr[i] == flag) 
             {
                 files += '<td valign=top width=70 bgcolor=aquamarine>'
             } 
             else 
             {
                 files += '<td valign=top width=70>'
             }

             files +='<center><font size=2>'
             
             if(myCall.indexOf("Attachments") != -1) 
             {
                 files +='\n<input type=checkbox name=checkbox_'+checkIndex+' value='+currentdir+'/'+arr[i]+'>'
                 checkIndex++;
             }

             if(myCall.indexOf("openSpace") != -1) 
             {
                 files +='\n<input type=checkbox name=checkbox_'+checkIndex+' value='+arr[i]+'>'
                 checkIndex++;
             } 
             else  
             {
                 files +='\n<a href='+hrefURL+commonArgs+'&action=view_file&tie='+currentdir+'/'+arr[i]
                 files +=' target=external>'+getIconImage(arr[i])+'<br></a>'
             }

             if(myCall.indexOf("openSpace") != -1) 
             {
                 files +='\n<a href=web/'+currentdir+'/'+arr[i]+' target=external>'+getIconImage(arr[i])+'<br>'+arr[i]+'</a>'
             }

             if(myCall.indexOf("Attachments") != -1) 
             {
                 files +='\n<a href='+hrefURL+commonArgs+'&action=download&tie='+currentdir+'/'+arr[i]+' target=external>'+arr[i]+'</a>'
             } 
             else if(myCall.indexOf("openSpace") == -1) 
             {
                 files += '\n<a href='+hrefURL+commonArgs+'&action=readPage'
                 files += '&fnum=1&ftype='+myCall+'&tie='+tie+'&fname='+currentdir+'/'+arr[i]
                 files += '>'+name+'</a>'
             }
             files += '</center></font></td>'
             j++;
         }
         files = replaceString(files, '//','/'); // 2001-10-31 jz

         folderTree  = parentDir+'\n</TD></TR>\n<TR><TD align=left><table border=0 cellspacing=0 cellpadding=5><font size=1><tr>'
         folderTree += directories+files+'</tr></table>\n</TD><TR>\n<TD bgcolor=c0d0f0 align=left>'+strsize+'</TD></TR></table>'
         var d;
         if(doc == null)
         {
            d = docObj;
         }
         else
         {
            d = doc;
         }

         if(myCall.indexOf("openSpace") != -1) 
         {
             d.writeln('<html><head><title>','FileManager@',hostName,'</title>')
             d.writeln(printJS)
             d.writeln('<input type=hidden name=space value="'+space+'">')
             d.writeln(webInterface)
         } 
         else 
         {
             d.writeln('<html><head><title>Select from your local or Web Spaces@',hostName,'</title></head><body bgcolor=ffffff text=000000>');
         }

       if(myCall.indexOf("Attachments") != -1) 
       {
             d.writeln('<FORM enctype=multipart/form-data action='+this.location.pathname+' method=POST><input type=hidden name=nd value=nd>');
       }
       if(club !=null ) {                         
          d.writeln('<font size=4>Select file(s) from your');
          if (!(isPrivate)) {
              d.writeln(' <a href="javascript:parent.goToPrivate(parent.priv, document);">' + printUpName(parent.userName) + '</a>');
          } else {
              d.writeln(printUpName(parent.userName) );
          }
          if (!(isPublic)) {
              d.writeln('<a href="javascript:parent.goToPublic(parent.pub, document);">',hostName,' Directory</a> ');
          } else {
              d.writeln(' ',hostName,' Public Directory ');
          }
          if((isPublic || isPrivate) && (club != null && club.length > 3))
          {
              d.writeln(' or <a href="javascript:parent.goToShared(parent.club, document);">' + printUpName(gName) + '</a>');                
          } else if(club != null && club.length > 3) {
              d.writeln('or  ' + printUpName(gName));
          }
          d.writeln(' Web Space </font>');
       }

       if((myCall.indexOf("Images") != -1) || (myCall.indexOf("Sounds") != -1)) 
       {
          d.writeln('<form>');
       }

       d.writeln(folderTree);
         
       if(myCall.indexOf("Images") != -1) 
       {
            d.writeln('</form><br>(To view an image - just click on an icon, to select this image - click on a link...)<br>');
       }

       if(myCall.indexOf("Sounds") != -1) 
       {
           d.writeln('</form><br>(To hear voice or music - just click on an icon, to select it for a page - click on a link...)<br>');
       }

       if(myCall.indexOf("openSpace") == -1)
       {
          d.writeln(uploadPart);
       }

       d.writeln('</form></body></html>');
       d.close();
       return;

     } //if

 } //for

 return;

} //function

//For form builder
function ChooseForm(obj) {
   var objValue;
   if(obj.value) {
      objValue = obj.value;
   }
   for(var i = 0; i< obj.length; i++) {
        if (obj[i].checked) {
           objValue = obj[i].value;
        }
   }
   buttonWindow.close();


   if (objValue == "DCR") {
       JSsubmit(0,'action,form,formType','save_form,Save,'+objValue)
   }else {
       JSsubmit(0,'action,form,formType','build_form,Save,'+objValue)
   }
}
function editform(tie) {
   easyDialog('Form','Choose one of the following','Change Form,Delete Form','change_form,delete_form','','tie='+tie);
//   easyDialog('Form','Choose one of the following','Change Form,Delete Form=>javascript:if(confirm(\'The Form will be DELETED from this page. Do you want to continue?\')) {JSsubmit(0,\'action,tie\',\'delete_form,'+tie+'\');}','change_form,delete_form','','tie='+tie);
}

function zip(form) {
          var checks = checkArray(form)
          if(checks.length == 0) 
          {
             alert('There is nothing to Compress.\nPlease select a file or folder')
             return
          }
          var pageTitle = "Compress Page";
          var buttonNames = "Compress";
          var buttonActions = "opener.parent.zipSubmit(document.forms[0])";
          var textFields = "Archive Name";
          var textFieldValues = null;
          var radioButtonName = "radioButton";
          var radioButtonValues = "c,u";
          var radioButtonDesc = "Create a new archive,Add to existing archive";
          var radioButtonTitle = "Would you like to";

          var listTitle = "You choose the following <br> files or folders:";

          var list = eval('parent.main.document.forms[0].checkbox_'+checks[0]+'.value');
          for (i=1; i < checks.length; i++) {
              list += "," + eval('parent.main.document.forms[0].checkbox_'+checks[i]+'.value') ;
          }

          complexDialog(pageTitle, null, listTitle, list, 10, buttonNames,buttonActions, textFields, 
              textFieldValues, radioButtonName, radioButtonValues, radioButtonDesc, radioButtonTitle, null, 400, 400);
}

function unzip(form) {
          var checks = checkArray(form)
          if(checks.length > 1 || checks.length == 1 && checks[0] < nFolders) {
             alert('Select one file only, please')
             return
          } 
          else if(checks.length == 0) 
          {
             alert('There is nothing to Uncompress.\nPlease select an archive.')
             return
          }
          var str = 'parent.main.document.forms[0].checkbox_'+checks[0]+'.value'
          if (confirm("You choose to uncompress " + eval(str) + ".\nDo you want to continue?")) {
              JSsubmit(0,"action","unzip");
          }

}

///////////////////////////////////////////
///////////////////////////////////////////
// complexDialog() - creates a window w/ the passed number of buttons adn actions
function complexDialog(iTitle, iMesg, iListTitle, iList, iListSize, iButtons, iButtonActions, iTextFields, iTextFieldValues,
    iRadioButtonName, iRadioButtonValues, iRadioButtonDesc, iRadioButtonTitle, iAddHidden, iWidth, iHeight)
{
//alert("complexDialog");
   var win = null;
   var hiddenFields = "";

   if(iAddHidden != null)
   {
       var hiddens = new Array();
       var nvs = new Array();
       var nv = "";
       var name = "";
       var value = "";  

       hiddens = iAddHidden.split(/,/);

       for(var h = 0; h < hiddens.length; h++)
       {
           if(hiddens[h].indexOf("=") != -1)
           {
               nv = hiddens[h];
               nvs = nv.split("=");

               name = nvs[0];
               value = nvs[1];
           }
           else
           {
                name = hiddens[h];
                value = "";
           }

           hiddenFields += "\n<input type=hidden name='" + name + "' value='" + value + "'>";

       }
   }
//////// create select
   var selectText = "";
   if (iListTitle  != null) {
       selectText +=  "<font face=verdana size=2><b>" + iListTitle + "</b></font><br>\n";
   }
   if (iListSize  == null) {
       iListSize =  10;
   }
   if (iList  != null && iList != "") {
       var list = Array();
       list = iList.split(/,/);
       selectText += "<select name='list' size=" + iListSize + ">\n";
       for (i=0; i < list.length; i++) {
           selectText += "<option value='" + list[i] +
               "'>" + list[i] + "</option>\n";
       }
       selectText += "</select>\n";
   }

/////// create radio
   var radioText = "";
   if (iRadioButtonTitle  != null) {
       radioText += "<font face=verdana size=2><b>" + iRadioButtonTitle + "<br>\n";
   }
   if (iRadioButtonDesc  != null && iRadioButtonDesc != "" && iRadioButtonValues != null && iRadioButtonValues != "") {
       var radio = Array();
       var values = Array();
       radio = iRadioButtonDesc.split(/,/);
       values = iRadioButtonValues.split(/,/);
       radioText += "<table border=0>\n";
       var checked = " checked";
       for (i=0; i < radio.length && radio.length == values.length; i++) {
           radioText += "<tr><td><font face=verdana size=2>\n<input type=radio name=" + iRadioButtonName + " value='" + 
               values[i] + "'" + (i == 0 ? checked : "") + ">" + radio[i] + "</font></td></tr>\n";
       }
       radioText += "</table>\n";
   }

////////////////// create textFields
   var fieldsText = "";
   if(iTextFields != "" && iTextFields != null)
   {
      var fieldNames = new Array();
      var fieldValues = new Array();
      if (iTextFieldValues != null) {
          fieldValues = iTextFieldValues.split(/,/);
      }

      fieldNames = iTextFields.split(/,/);
      fieldsText += "<table border=0>\n";

      for(var i = 0; i < fieldNames.length; i++)
      {
      var value = "";
          if(fieldValues != null && fieldValues.length > i) {
              value = fieldValues[i];
          }
          fieldsText += "<tr><td><font face=verdana size=2>\n" + fieldNames[i] + ":</td><td><input type=text name='" + fieldNames[i] + "' value='" + value + "'></font></td></tr>\n";
      }

      fieldsText += "</table>\n";

   }

   var buttonsText = ""
   var bgcolor = "#c0f0c0";

   var buttons = new Array();
   var actions = new Array();

   buttons = iButtons.split(/,/)
   actions = iButtonActions.split(/,/)


   var splits = new Array();
   var str = "";
   var link = "";

   if(buttons.length == actions.length)
   {
       buttonsText += "<table border=0 cellspacing=2 cellpadding=2 width='100%'><tr>";
       for(var i = 0; i < buttons.length; i++)
       {
          link = "";         
          if((i%2) == 0)
          {
              bgcolor = "#c0c0f0";
          }
          else
          {
              bgcolor = "#c0f0c0";
          }
          if(buttons[i].indexOf("=>") != -1)
          {
              str = buttons[i];
              splits = str.split("=>");

              name = splits[0];
              link = splits[1];

              //link = "opener.parent.NewWnd('')";
          }
          else
          {
              name = buttons[i];
              if( fieldsText != null && fieldsText.length != 0){
                 link = "if(validate(document.forms[0]))";
              }
              link += "{"+actions[i]+";self.close();}";
          }


          buttonsText += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2>";
            
          buttonsText += "<a href=\"javascript:" + link + "\">" + name + 
                      "</font></a></td>\n";
       }
        
       if(bgcolor == "#c0c0f0")
       {
          bgcolor = "#c0f0c0";
       }
       else
       {
          bgcolor = "#c0c0f0";
       }

        //add close button
        buttonsText += "<td bgcolor=" + bgcolor + ">\n<font face=verdana size=2><a href='javascript:self.close()'>Cancel</font></a></td>\n";
        buttonsText += "</tr></table>";
   }

   if(iTitle == "" || iTitle == null)
   {
       iTitle = "Prompt";
   }

   if(iMesg == "" || iMesg == null)
   {
       iMesg = "";
   }

   //create html document

   win = open("","cprompt","toolbar=no,addressbar=no,status=no,resizable=yes,scrollbars=yes,width=" + iWidth + 
         ",height=" + iHeight + "");
   win.document.open();

   win.document.writeln("<html>\n<head>\n<title>" + iTitle + "</title>\n");
   win.document.writeln("<script language=\"javascript\"><!--\n");
   win.document.writeln("function validate(frm) {");
   win.document.writeln("  var i;");
   win.document.writeln("  for(i = 0; (frm != null && i < frm.elements.length); i++) {");
   win.document.writeln("     if((frm.elements[i] != null) && (frm.elements[i].type == \"text\") && (frm.elements[i].value == \"\")) {");
   win.document.writeln("         alert('This field can not be blank.');");
   win.document.writeln("         frm.elements[i].focus();");
   win.document.writeln("         return false;");
   win.document.writeln("     }");
   win.document.writeln("  }");
   win.document.writeln("  return true;");
   win.document.writeln("}");

   win.document.writeln("var IE4 = (document.all);");
   win.document.writeln("var NS4 = (document.layers);");
   win.document.writeln("if (NS4)");
   win.document.writeln("document.captureEvents(Event.KEYPRESS);");
   win.document.writeln("document.onkeypress = doKey;");
   win.document.writeln("function doKey(e){");
   win.document.writeln("   var whichASC = (NS4) ? e.which : event.keyCode;");
   win.document.writeln("   if (whichASC == 13)");
   win.document.writeln("   {");
   win.document.writeln("       return false;");
   win.document.writeln("   }");
   win.document.writeln("   return true;");
   win.document.writeln("}");

   win.document.writeln("\/\/-->\n","<\/","script>");
   
   win.document.writeln("</head>\n<body bgcolor=#FFFFFF>\n" +
                       "<center>\n<font face=verdana size=2><b>" + iMesg + "</b></font><br>\n" +
                       "<FORM name='ed'>\n" +
                       "" + hiddenFields + "\n" + selectText + "<br>\n" + 
                       radioText + "<br>\n" + fieldsText + buttonsText + "" + 
                       "\n</FORM>\n</center>\n" +
                       "</body>\n</html>\n"
                       );

   win.document.close();
}

//////////////////////////////////////////
function zipSubmit(iForm)
{
   var newZip = "";
   if(iForm != null && iForm.elements != null && iForm.elements.length > 0)
   {
       newZip += iForm.elements[0].name + "=" + iForm.elements[0].value;
       for(var i = 1; i < iForm.elements.length; i++)
       {    
            if (iForm.elements[i].type == "checkbox" && iForm.elements[i].checked ||
                iForm.elements[i].type == "radio" && iForm.elements[i].checked || 
                iForm.elements[i].type != "checkbox" && iForm.elements[i].type != "radio") {
                newZip += ";" + iForm.elements[i].name + "=" + iForm.elements[i].value;
            }
       }
   }

//alert("newZip="+newZip);

    JSsubmit(0, "action,newZip", "zip,"+newZip);    
}
//////////////////////////////////////////////////////////////////////////////

