
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function downloadFile()
{
  var count = 0;
  for (var i = 1; i < document.listFiles.elements['file_name[]'].length; i++)
  {
    if (document.listFiles.elements['file_name[]'][i].checked && document.listFiles.elements['file_type[]'][i].value == 'f')
      count++;
  }
  if (count < 1)
    alert("Please select one File to download...");
  else if (count > 1)
    alert("Please select only one File to download...");
  else
  {
    document.listFiles.elements['action'].value = "download";
    document.listFiles.elements['show'].value = "";
    document.listFiles.submit();
  }
}

function deleteFile()
{
  var count = 0;
  var types = "";
  for (var i = 1; i < document.listFiles.elements['file_name[]'].length; i++)
  {
    if (document.listFiles.elements['file_name[]'][i].checked)
    {
      count++;
      if (document.listFiles.elements['file_type[]'][i].value == 'd')
        types = types + "d,";
      else
        types = types + "f,";
    }
  }
  if (count < 1)
    alert("Please select at least one File / Folder to delete...");
  else
  {
    if (confirm("Are you sure you want to delete selected files / folders?"))
    {
      document.listFiles.elements['action'].value = "delete";
      document.listFiles.elements['show'].value = types;
      document.listFiles.submit();
    }
  }
}

function renameFile()
{
  var count = 0;
  for (var i = 1; i < document.listFiles.elements['file_name[]'].length; i++)
  {
    if (document.listFiles.elements['file_name[]'][i].checked)
      count++;
  }
  if (count < 1)
    alert("Please select one File / Folder to rename...");
  else if (count > 1)
    alert("Please select only one File / Folder to rename...");
  else
  {
    document.listFiles.elements['show'].value = "rename";
    document.listFiles.submit();
  }
}

function moveFile()
{
  var count = 0;
  for (var i = 1; i < document.listFiles.elements['file_name[]'].length; i++)
  {
    if (document.listFiles.elements['file_name[]'][i].checked && document.listFiles.elements['file_type[]'][i].value == 'f')
      count++;
  }
  if (count < 1)
    alert("Please select one File  to move...");
  else if (count > 1)
    alert("Please select only one File to move...");
  else
  {
    document.listFiles.elements['show'].value = "move";
    document.listFiles.submit();
  }
}
// Cancel Operation
function CancelOps()
{
    document.DoOps.elements['action'].value = "";
    document.DoOps.elements['submit'].click();
}

// Add FTP Form
function add_ftp_form()
{
  var current_value = document.backup_form.site_backup_no.value;
  current_value++;
  var new_form = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
  new_form += "<tr><td>*FTP Host " + current_value + ": <input name='ftphost" + current_value + "' type='text' id='ftphost" + current_value + "'></td>";
  new_form += "<td>*FTP Login: <input name='ftpuser" + current_value + "' type='text' id='ftpuser" + current_value + "'></td></tr>";
  new_form += "<tr><td>*FTP Password: <input name='ftppass" + current_value + "' type='password' id='ftppass" + current_value + "'></td>";
  new_form += "<td>*Repeat Password:<input name='ftppassr" + current_value + "' type='password' id='ftppassr" + current_value + "'></td></tr></table><hr size='1'>";
  document.getElementById("ftp_form").innerHTML= document.getElementById("ftp_form").innerHTML + new_form;
  document.backup_form.site_backup_no.value = current_value;
}

// Add DB Form
function add_db_form()
{
  var current_value = document.backup_form.db_backup_no.value;
  current_value++;
  var new_form = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
  new_form += "<tr><td>*DB Host " + current_value + ": <input name='dbhost" + current_value + "' type='text' id='dbhost" + current_value + "'></td>";
  new_form += "<td>*DB Login: <input name='dbuser" + current_value + "' type='text' id='dbuser" + current_value + "'></td></tr>";
  new_form += "<tr><td>*DB Password: <input name='dbpass" + current_value + "' type='password' id='dbpass" + current_value + "'></td>";
  new_form += "<td>*DB Name: <input name='dbname" + current_value + "' type='text' id='dbname" + current_value + "'></td></tr>";
  new_form += "<tr><td>*Repeat Password:<input name='dbpassr" + current_value + "' type='password' id='dbpassr" + current_value + "'></td><td>&nbsp;</td></tr></table><hr size='1'>";
  document.getElementById("db_form").innerHTML= document.getElementById("db_form").innerHTML + new_form;
  document.backup_form.db_backup_no.value = current_value;
}

