﻿var User = "guest";
var dir = "@www.supremesearch.net";
var uname = "Search 3000 v.5"
var store = "No Data Stored";

//Network Status
var timer1=0; 
var Network_Connection=100;

//Desktop
var Desktop = "1";
var New_File = "1";
var IconClass = "Icon";

function Terminal(){
  var Input = document.T_form.Input.value;

  //Display
  document.T_form.Display.value += "[" + User + dir + "]$ " + Input + "\n";

  //Help
  if (Input.toLowerCase() == "help"){Help();}

  //Close
  else if (Input.toLowerCase() == "close"){document.getElementById('Term').style.display = 'none'}

  //Logname
  else if (Input.toLowerCase() == "logname"){document.T_form.Display.value += User + "\n";}

  //LS & cd
  else if ((Input.toLowerCase() == "ls") || (Input.toLowerCase() == "cd")){document.T_form.Display.value += User + dir + "\n";}

  //Search
  else if (Input.toLowerCase().indexOf("srch") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("srch ","");
    window.open("http://www.supremesearch3000.bravehost.com/Search.php?User_Input=" + Final_Input, '','height=500,width=770, scrollbars=yes, resizable=yes, location=yes');
  }

  //Echo
  else if (Input.toLowerCase().indexOf("echo") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("echo ","");
    document.T_form.Display.value += Final_Input + "\n";
  }
  
  //Date
  else if (Input.toLowerCase() == "date"){
    var suffix="AM";
    var today = new Date()
    var hours = today.getHours()
    var minutes = today.getMinutes()
    if (hours > 11){suffix="PM";} 

    hours = hours % 12;
    if (hours == 0){hours = 12;}
    if (minutes < 10){minutes="0"+minutes;}
    document.T_form.Display.value += weekday[today.getDay()] + ' ' + month + '/' + day + '/' + year + ", " + hours + ":" + minutes + " " + suffix + "\n";
  }

  //Goto URL
  else if (Input.toLowerCase().indexOf("goto url") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("goto url ","");
    document.URLframe.URL.value = Final_Input;
    GoToURL()
  }

  //Change Username
  else if (Input.toLowerCase().indexOf("cguser") != -1) {
    var New_Input=Input.toLowerCase();
    User = New_Input.replace("cguser ",""); 
  }

  //Refresh
  else if (Input.toLowerCase() == "refresh"){window.location.reload( true );}

  //halt
  else if (Input.toLowerCase() == "halt"){window.close();}

  //Notepad
  else if  (Input.toLowerCase() == "notepad"){window.open('Web-App/NotePad.php', '','height=500,width=720, scrollbars=yes, resizable=yes, menubar=yes');}

  //Wordpad
  else if  (Input.toLowerCase() == "wordpad"){window.open('Web-App/WordPad.htm', '','height=500,width=750, scrollbars=yes, resizable=yes, menubar=yes');}

  //cal
  else if  (Input.toLowerCase() == "cal"){window.open('Calendar.html', '','height=280,width=340');}

  //Uname
  else if (Input.toLowerCase() == "uname"){document.T_form.Display.value += uname + "\n";}

  //Clear
  else if (Input.toLowerCase() == "clr"){document.T_form.Display.value = "";}

  //Mail
  else if  (Input.toLowerCase() == "mail"){window.open('Web-App/E-mail.html', '','height=400,width=620, scrollbars=yes');}

  //Storetxt
  else if (Input.toLowerCase().indexOf("storetxt") != -1) {
    var New_Input=Input.toLowerCase();
    store = New_Input.replace("storetxt ",""); 
  }

  //Displaytxt
  else if (Input.toLowerCase() == "displaytxt"){document.T_form.Display.value += store + "\n";}

  //sbar
  else if (Input.toLowerCase().indexOf("sbar") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("sbar ","");
    document.form.search.value = Final_Input;
  }

  //calc
  else if  (Input.toLowerCase() == "calc"){window.open('Web-App/Scientific Calculator.html', 'Calculator','height=480,width=600, scrollbars=yes');}

  //mkdir
  else if (Input.toLowerCase().indexOf("mkdir") != -1) {
    var New_Input=Input.toLowerCase();
    var Input2 = New_Input.split(" ");

    //If directory already existed
    if (dir.toLowerCase().indexOf(Input2[1].toLowerCase()) != -1) {
      document.T_form.Display.value += "Directory already existed. \n";
    }
      else
    {
      var Final_Input = New_Input.replace("mkdir ","");
      Final_Input = Final_Input.replace(/\s+/g,"_");	//Del Blank Spaces
      dir += "/" + Final_Input;
    }
  }

  //rmdir
  else if (Input.toLowerCase().indexOf("rmdir") != -1) {
    if (Input.toLowerCase().indexOf("/") != -1) {
      var New_Input=Input.toLowerCase();
      var Input2 = New_Input.split(" ");
      var Final_Input = dir.replace(Input2[1],"");
      dir = Final_Input;
    }
      else
    {
      document.T_form.Display.value += "Directory not deleted must include \"/\" before file name.\n";
    }
  }

  //Paint
  else if (Input.toLowerCase() == "xpaint"){window.open('Web-App/Paint.htm', '','height=500,width=650, scrollbars=yes, resizable=yes, menubar=yes');}

  //webapp
  else if (Input.toLowerCase() == "webapp"){window.open('Extras.htm', '','height=235, width=700, scrollbars=yes, resizable=yes, location=yes');}

  //Screen
  else if (Input.toLowerCase() == "vga"){document.T_form.Display.value += screen.width + " x " + screen.height + "\n";}

  //Browser Name
  else if (Input.toLowerCase() == "brname"){document.T_form.Display.value += navigator.appName + "\n";}

  //deltree
  else if (Input.toLowerCase() == "deltree") {
    dir = "@www.supremesearch.net";
  }

  //dsktop
  else if (Input.toLowerCase().indexOf("dsktop") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("dsktop ","");
    document.WallPaper.URL.value = Final_Input;
    New_WallPaper()
  }

  //cgcolor
  else if (Input.toLowerCase().indexOf("cgcolor") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("cgcolor ","");
    document.getElementById('Display').style.backgroundColor = Final_Input;
  }

  //txcolor
  else if (Input.toLowerCase().indexOf("txcolor") != -1) {
    var New_Input=Input.toLowerCase();
    var Final_Input = New_Input.replace("txcolor ","");
    document.getElementById('Display').style.color = Final_Input;
  }

  //Blank
  else if (Input.toLowerCase() == ""){}

  //Error
  else{document.T_form.Display.value += "command not found: \"" + Input + "\"\n";}

  document.T_form.Display.value += "\n";
  if (Input.toLowerCase() != "help"){document.getElementById('Display').scrollTop=document.getElementById('Display').scrollHeight;}
  document.T_form.Input.value = "";
  return false;
}

function deleteChar(input) {
  input.value = input.value.substring(0, input.value.length - 1)
}

function Help(){
  document.T_form.Display.value = "System Help \n\n" 
  + "brname        Display web browser name \n"       
  + "cal        	Display a monthly calendar \n"
  + "calc          Open a Scientific Calculator Program \n"
  + "cd         	List current directory \n"
  + "close      	Close Terminal \n"
  + "clr	       Clear and reset the screen \n"
  + "date       	Display date and time \n"
  + "displaytxt	Will display stored text \n"
  + "deltree       Remove / Delete all subdirectories \n"
  + "echo       	Write arguments back  \n"
  + "halt       	Halt system, shut down \n"
  + "logname    	Display login name  \n"
  + "ls         	List directory \n"
  + "mail          Open a mail-client program \n"
  + "notepad    	Will open notepad  \n"
  + "refresh    	Refresh system  \n"
  + "webapp	       Menu of Web Applications \n"
  + "wordpad    	Will open wordpad \n"
  + "uname	       Will display system name \n"
  + "xpaint		Simple paint program for X \n"
  + "vga           Display Screen Resolution \n\n"

  + "Advanced Commands ________________________________________________________\n"
  + "txcolor \"color\"      Will change the text color to a specific html color. \n"
  + "cgcolor \"color\"      Will change Terminal color to a specific html color. \n"
  + "goto url \"url\"		Will goto a specific url \"Must include http://\" \n"
  + "dsktop \"url\"         Change desktop background \"Must include http://\" \n"
  + "srch \"term\" 		Will search \"Supreme Search 3000\" for your search term. \n"
  + "cguser \"new_name\"	Change Username. example: cguser Mike \n"
  + "storetxt \"text\"	Will store any text you enter. \n"
  + "sbar \"text\"		Will add text to searchbar. \n"
  + "mkdir \"dir\"		Makes a new directory. \n"
  + "rmdir \"/dir\"		Remove / Delete directory. example: rmdir /Photos \n";
	  
  return false;                
}    


//Filesystem
function New_Folder(){
  if (New_File > 1){document.FileSYS.FileInput.value += "\n";}
  document.FileSYS.FileInput.value += document.NewFolder.URL.value;
  document.FileSYS.FileOptions.selectedIndex = 0;
  document.NewFolder.URL.value = "http://";
  Filesystem(); return false;
}

function Filesystem(){

  var i = 0;
  var c = 0;
  var Icon = "";
  var Iconc = 1;
  var LinkName = "";
  var dirfiles = document.FileSYS.FileInput.value;
  var selected = document.FileSYS.FileOptions.options[document.FileSYS.FileOptions.selectedIndex].value;
  var Vfiles = dirfiles.split("\n");
  var countdirs = Vfiles.length;
  FileSYS.F_Display.value= User + dir;
  document.getElementById('Search1').style.display = 'none';

  //Display Icon
  for (i = 1; i <= 20; i=i+1){
    IconClass+=i;
    document.getElementById(IconClass).style.display = 'block';
    IconClass = "Icon";
  }

  if (selected == "3"){
    c = 2;
    selected = "1";
    dir = Vfiles[1].replace(/[\s\r\n]+$/, '');
    User =  Vfiles[0].replace(/[\s\r\n]+$/, '');
    FileSYS.F_Display.value= User + dir;
    document.FileSYS.FileInput.value = "";
    for (i = 2; i < countdirs; i=i+1){
      document.FileSYS.FileInput.value += Vfiles[i];
    }
  }

  if ((selected == "1") && (dirfiles.length >= 8)){
    document.getElementById('DisplayFiles').innerHTML = "";
    document.getElementById('DisplayFiles2').innerHTML = "";

    for (i = c; i < countdirs; i=i+1){
      LinkName = Vfiles[i].substr(11, 15); 
      Icon = Vfiles[i].substr(Vfiles[i].length-4, 4);

      //Select Icon
      if ((Icon.toLowerCase().indexOf("mp3") != -1) || (Icon.toLowerCase().indexOf("wav") != -1)) {
        Icon = "Icons/music.png";
      }
      else if ((Icon.toLowerCase().indexOf("txt") != -1) || (Icon.toLowerCase().indexOf("rtf") != -1)) {
        Icon = "Icons/txt.png";
      }
      else if ((Icon.toLowerCase().indexOf("jpg") != -1) || (Icon.toLowerCase().indexOf("gif") != -1)) {
        Icon = "Icons/Image.png";
      }
      else if (Icon.toLowerCase().indexOf("pdf") != -1){
        Icon = "Icons/pdf.png";
      }
      else if (Vfiles[i].toLowerCase().indexOf(" [folder]") != -1){
        Vfiles[i] = Vfiles[i].replace(" [folder]","");
        LinkName = Vfiles[i].substr(11, 15);
        Icon = "Icons/add.png";
      }
      else if (Vfiles[i].toLowerCase().indexOf(" [network]") != -1){
        Vfiles[i] = Vfiles[i].replace(" [network]","");
        LinkName = Vfiles[i].substr(11, 15);
        Icon = "Icons/net.png";
      }
        else
      {
        Icon = "Icons/webpage.png";
      }

      //Icon from web
      if (Vfiles[i].toLowerCase().indexOf(" [image]") != -1){
        var Input2 = Vfiles[i].split(" [image]");
        Vfiles[i] = Input2[0];
        LinkName = Input2[0].substr(11, 15);
        Icon = Input2[1];
      }


      //Make Clickable Icon
      IconClass+=Iconc;

      if (Icon == "Icons/music.png"){
        Vfiles[i] = Vfiles[i].replace(/\s/g, '%20');
        if (Iconc <= 20){document.getElementById(IconClass).innerHTML = "<a href= Web-App/Media%20Player.php?User_Input=" + Vfiles[i] + " title=\"" + Vfiles[i] + "\"  onclick=\"window.open(this.href, '','height=240,width=750, scrollbars=yes, resizable=yes');return false;\"><img src=\"" + Icon + "\" width=\"48\" height=\"48\" BORDER=0>" + LinkName + "</a>&nbsp;"}
        document.getElementById('DisplayFiles2').innerHTML += "<a href= Web-App/Media%20Player.php?User_Input=" + Vfiles[i] + " title=\"" + Vfiles[i] + "\"  onclick=\"window.open(this.href, '','height=240,width=750, scrollbars=yes, resizable=yes');return false;\"><img src=\"" + Icon + "\" width=\"48\" height=\"48\" BORDER=0>" + LinkName + "</a>&nbsp;"
      }
        else
      {
        if (Iconc <= 20){document.getElementById(IconClass).innerHTML = "<a href=\"" +Vfiles[i]+ "\" title=\"" + Vfiles[i] + "\" onclick=\"window.open(this.href, '','height=500,width=500, scrollbars=yes, resizable=yes, location=yes');return false;\"><img src=\"" + Icon + "\" width=\"48\" height=\"48\" BORDER=0>" + LinkName + "</a>&nbsp;"}
        document.getElementById('DisplayFiles2').innerHTML += "<a href=\"" +Vfiles[i]+ "\" title=\"" + Vfiles[i] + "\" onclick=\"window.open(this.href, '','height=500,width=500, scrollbars=yes, resizable=yes, location=yes');return false;\"><img src=\"" + Icon + "\" width=\"48\" height=\"48\" BORDER=0>" + LinkName + "</a>&nbsp;"
      }
      IconClass = "Icon";
      New_File++;
      Iconc++;

    }

  }

  if (selected == "2"){
    var w = window.open();
    w.document.writeln("<xmp>" + User);
    w.document.writeln(dir);
    w.document.writeln(dirfiles + "</xmp>");
  }

  if (selected == "4"){
    document.getElementById('DisplayFiles2').innerHTML = "<h1>Help Menu</h1><big>"
    + "To add files to your \"Virtual File System\" add your favorite urls in the textbox "
    + "below. You can add any type of url links including html, mp3, wav, pdf, txt, jpg, gif and more. "
    + "Also, remember to include \"http://\" in your links, and add one url per line. "
    + "You can add as many urls as you like.</big>"
    + "<br><br><h1>Optional</h1><big>"
    + "To edit your \"Username\" and \"Directory\", open Mini Terminal to make changes."
    + "Virtual File System keeps memory of all links added even after it has been closed.</big>"
    + "<br><br><h1>Import Backup</h1><big>"
    + "After you have made a \"Backup Copy\" of your virtual files, simply copy and paste the backup text in the textbox below to retrieve your data.</big>"
    + "<br><br><h1>Optional Change Icon</h1><big>"
    + "Use the following example below to change icons: <br>"
    + "Folder Icon: http://www.example.com [folder] <br>"
    + "Network Icon: http://www.example.com [network] <br>"
    + "Image as Icon: http://www.example.com [image]image_url</big>";
  }

}


//Network Status
function Check_Speed() {
  test_img=new Image();
  timer1=new Date();
  timer1=timer1.getTime();
  test_img.src="http://www.supremesearch3000.bravehost.com/Web-App/Network Test.jpg?test="+timer1;
  document.isp_speed.Replace.value="Checking in progress";
  setTimeout("Cal_Speed()",Network_Connection);
}

function Cal_Speed() {
  if (test_img.complete) {
    var isp="";
    var File_Size=8192;
    var timer2=new Date(); 
    timer2=timer2.getTime();
    var kbps=(File_Size/(timer2-timer1)) * 30.5;

    if (kbps<56){isp="Dial-up modem";}
    if ((kbps>56)&&(kbps<3072)){isp="DSL Connection";}
    if (kbps>3072){isp="DSL2+ or local network";}
    kbps=kbps.toFixed(1)
    document.isp_speed.Replace.value= isp+" (" + kbps +" kbps)";
  }
    else 
  {
    setTimeout("Cal_Speed()",Network_Connection)
  }	
}


//Desktop 2
function Desktop2(){

  if (Desktop == 1){
    Desktop = 2;

    for (i = 1; i <= 20; i=i+1){
      IconClass+=i;
      document.getElementById(IconClass).style.display = 'none';
      IconClass = "Icon";
    }

    document.getElementById('Search1').style.display = 'none';
    document.getElementById('DisplayFiles').innerHTML = "<iframe src='Desktop 2.htm?var1="+User+ "&var2=" + dir + "&var3=" + uname + "' width=" + screen.width + " height='600' frameborder='0'>"
    + "</frame>";
  }
    else
  {
    Desktop = 1;

    for (i = 1; i <= 20; i=i+1){
      IconClass+=i;
      document.getElementById(IconClass).style.display = 'block';
      IconClass = "Icon";
    }

    document.getElementById('DisplayFiles').innerHTML = "";
  }

}