<search function="login">
  <name>Login links to Personal Websites</name>
  <description>
    After adding site and login information to the preferences file, they may be accessed using user-defined switches or the DQSD menu.
  </description>
  <category nomenu="true">Login</category>
  <contributor>Ryan Carpenter</contributor>

  <script><![CDATA[

    function login(q)
    {
      loginSw = loginSites[0][1];
      for (mItem=1;mItem<loginSites.length;mItem++) loginSw = loginSw + ", " + loginSites[mItem][1];
      var args = parseArgs(q, loginSw);
      if( args.switches.length != 1 )
      {
        giveLoginHelp();
        return false;
      }
      for (mItem=0;mItem<loginSites.length;mItem++) if (loginSites[mItem][1]==args.switches[0].name) sendLogin(loginSites[mItem]);
    }

    function loginMenuHook(mb)
    {
      var loginMenu = mb.InsertSubMenu("Login", 3);
      for (mItem=0;mItem<loginSites.length;mItem++)
      {
        ls = loginSites[mItem];
        mb.AppendMenuItem( ls[0], "sendLogin(loginSites["+mItem+"])", "/"+ls[1], loginMenu);
      }
      mb.AppendMenuItem("Login Help...", "giveLoginHelp()", "url", loginMenu);
      ensureLauncher();
    }
	
    registerMenuHook(loginMenuHook);

    function sendLogin(ls)
    {
      document.getElementById('delaymsg').innerHTML = "<form name='loginForm' style='margin-bottom:0;' "
                                                    + "onSubmit = 'document.deff.q.style.display=\"inline\";document.all.delaymsg.style.display=\"none\";'>"
                                                    + "<input type='password' id='readyPass' size='9' onfocus='clr()' onBlur='document.deff.q.style.display=\"inline\";document.all.delaymsg.style.display=\"none\";rst()'>"
                                                    + "</form><i>password</i>";
      var f = document.loginForm;
      f.target = "_blank";
      f.action = ls[2];
      f.method = ls[3];
      var fia = new Array(ls[4].length);
      for (fi=0;fi<fia.length;fi++)
      {
        fia[fi] = document.createElement('input');
        fia[fi].name = ls[4][fi];
        switch(ls[5][fi])
        {
          case "user":
            fia[fi].type = "hidden";
            fia[fi].value = ls[6][fi];
            break;
          case "password":
            fia[fi].type = "password";
            if (ls[6][fi])
            {
              var hasPass = true;
              fia[fi].value = ls[6][fi];
            }else{
              if (hasPass)
              {
                document.deff.q.style.display = "inline";
                document.getElementById('delaymsg').style.display = "none";
              }else{
                var hasPass = false;
                document.deff.q.style.display = "none";
                document.getElementById('delaymsg').style.display = "inline";
                document.getElementById('delaymsg').style.position = "relative";
                document.getElementById('delaymsg').style.left = "19";
                fia[fi] = document.getElementById('readyPass');
                fia[fi].name = ls[4][fi];
                setTimeout("document.deff.q.style.display='inline';document.all.delaymsg.style.display='none';rst()",20000)
              }
            }
            break;
          case "text":
            fia[fi].type = "hidden";
            fia[fi].value = ls[6][fi];
            break;
          case "hidden":
            fia[fi].type = "hidden";
            fia[fi].value = ls[6][fi];
            break;
          case "radio":
            fia[fi].type = "radio";
            if (ls[6][fi].split(":").length>1) offRad.value = ls[6][fi].split(":")[1];
            selRad = parseInt(ls[6][fi].split(":")[0]);
            for (ri=0;ri<selRad;ri++)
            {
              offRad = document.createElement('input');
              offRad.name = ls[4][fi];
              offRad.type = "radio";
              if (ls[6][fi].split(":").length>1) offRad.value = ls[6][fi].split(":")[1];
              f.appendChild(offRad);
            }
            break;
          case "select":
            fia[fi] = document.createElement('select');
            selOpt = parseInt(ls[6][fi].split(":")[0]);
            for (oi=0;oi<=selOpt;oi++)
            {
              nextOpt = document.createElement('option');
              if (ls[6][fi].split(":").length>1) nextOpt.value = ls[6][fi].split(":")[1];
              fia[fi].appendChild(nextOpt);
            }
            break;
          case "checkbox":
            fia[fi].type = "checkbox";
            fia[fi].checked = ls[6][fi].split(":")[0];
            if (ls[6][fi].split(":").length==2) fia[fi].value = ls[6][fi].split(":")[1];
            break;
          default:
            alert("The selected login site uses an input element of an unrecognized type: "+ls[5][fi]);
            break;
        }
        f.appendChild(fia[fi]);
      }

      //alert("PersistentCookie: value="+document.loginForm.PersistentCookie.value+" check:"+document.loginForm.PersistentCookie.checked);
      if (hasPass) f.submit();
    }

    function giveLoginHelp()
    {
      lhHTML = "<html><head><title>DQSD Login Help</title></head><body bgcolor='#bbbbbb'>"
             + "<div style='text-align:center;font-size:20pt;font-weight:bold'>DQSD Login Help</div>"
             + "<h3>Using the Login Tool</h3>Like most searches for DQSD, this tool may be accessed either by typing in it's name, 'login' or by using the DQSD menu.  Unlike most searches, this tool has no category in the DQSD menu, it is placed near the top of the primary menu.  It also requires no query or search word."
             + "<p>To login to a specific site, either select it from the 'Login' submenu or enter its name as a search switch, such as <i>login/gmail</i>.  User and password information is passed to the site by the same method that it would be if entered to the usual form.  Typically, login capabilities will be availible to any who has access to this copy of DQSD."
             + "<p>Alternatively, a site login profile may be setup without a pre-defined password, which would prompt the user for the password whenever the login tool is used.  DQSD will change appearance to a password input box and wait 20 seconds for the password to be entered.  The password is not saved anywhere and sent only to the site the user is logging in to.  The password may be submitted by using the enter button."
             + "<h3>Configuration</h3>The DQSD login tool will not properly function without first defining the variable <i>loginSites</i> in the <a href='view-source:file:///C:/Program%20Files/Quick%20Search%20Deskbar/localprefs.js'>local preferences</a> file.  <i>loginSites</i> is an array of profiles on the secure forms used to login to your websites.  Each profile is also an array (making <i>loginSites</i> an array of arrays)."
             + "<p>Each site profile array has seven elements, the last three of which are more arrays (a third level).  The following table explains the site profile for dqsd-user@gmail.com.<p><table border=1 align=center><tr><td>Element</td><td>Description</td><td>Example</td></tr><tr><td>0</td><td>site title, for DQSD menu</td><td><i>\"Joe's GMail Account\"</i></td></tr>"
             + "<tr><td>1</td><td>switch to be typed in (<i>login/gmail</i>)</td><td><i>\"gmail\"</i></td></tr><tr><td>2</td><td>login form action, as used by original site</td><td><i>\"https://www.google.com/<br/>accounts/ServiceLoginBoxAuth\"</i></td></tr><tr><td>3</td><td>login form method, as used by original site</td><td><i>\"post\"</i></td></tr>"
             + "<tr><td>4</td><td>an array of input names</td><td><i>['login','passwd','foo']</i></td></tr><tr><td>5</td><td>an array of input types ('user' works like 'hidden')</td><td><i>['user','password','hidden']</i></td></tr><tr><td>6</td><td>an array of input values (with or without password)</td><td><i>['dqsd-user','qwertyuiop','bar']</i></td></tr></table>"
             + "<p>This information is combined into the following line for your <a href='view-source:file:///C:/Program%20Files/Quick%20Search%20Deskbar/localprefs.js'>local preferences</a> file:<p><i>loginSites = [<br/>['yahoo.com','yahoomail','https://login.yahoo.com/config/login?5cvirbqubok5q','post',['login','passwd'],['user','password'],['dqsd-user','']]<br/>];</i>"
             + "<h3>Form Inputs Detail</h3>"
             + "<p><div style='text-align:center;font-size:7pt;font-style:italic'>Created by Ryan Carpenter [Dec. 2004]</div></body></html>";
      lHlpWin = window.open("","","width=400,height=500, scrollbars=yes, resizable=yes, status=yes");
      lHlpWin.document.write(lhHTML);
    }
  ]]></script>
</search>
