﻿// Programmatically creates a login from and posts it to a url
// param to is the url
// param uid is the user name
// param pwd is the password
function LoginToPortal(to, uid, pwd) {

    // we have to push this through a delay else it fails in many browser
    // and on the server console
    window.setTimeout(function() { LoginToPortalDelayed(to, uid, pwd); }, 100);
}


function LoginToPortalDelayed(to, uid, pwd) {

    // the dirty way to do it so that the password is seen on the url
    // window.location = to + "?uid=" + uid + "&password=" + pwd;


    // a bit better way at least the password is hidden in a stream
    
    var myForm = document.createElement("form");
    myForm.method = "post";
    myForm.action = to;

   var uidInput = document.createElement("input");
    uidInput.setAttribute("name", "uid");
    uidInput.setAttribute("value", uid);
    myForm.appendChild(uidInput);

   var pwdInput = document.createElement("input");
    pwdInput.setAttribute("name", "password");
    pwdInput.setAttribute("value", pwd);
    myForm.appendChild(pwdInput);


    document.body.appendChild(myForm);
    myForm.submit();
    document.body.removeChild(myForm);
    
}


