Formfill for Citrix

We have a form fill which is working for the html fields, but one is generated by a .js page .

The login.html, and login.js are included later in this post, but this is where the issue lies.

The loginbox of the login.html pages is generated by calling: <SCRIPT language=JavaScript>ns_showpwd();</SCRIPT>

How do we fill this in using ff? I looked into the ns_showpwd(), and find that it is called from another script, login.js, earlier in the login.html.

The part of the function that generates the password part of the form is:
document.write('<div class="right"><input type="Password" title="' + _("Enter password") + '" name="passwd" size="30" maxlength="127" ></div></div>');

So weve put functions to keep as ns_showpwd(), and statements to execute on submit, but no joy.

Any suggestions appreciated:

Included below are the complete login.html page source below, and login.js for reference.
------------------------------------------------------------------------------------------------------------------------------------------ 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD><TITLE>Citrix Access Gateway</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META content=noindex,nofollow,noarchive name=robots>
<link rel="SHORTCUT ICON" href="/vpn/images/AccessGateway.ico" type="image/vnd.microsoft.icon">
<link href="/vpn/css/ctxs.mainstyle.css" rel="stylesheet" type="text/css" media="screen" />
<link href="/vpn/css/ctxs.authentication.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/vpn/resources.js"></script>
<script type="text/javascript" language="javascript">
var Resources = new ResourceManager("resources/{lang}", "logon");
</script>
<style type="text/css">
body
{
display : none;
visibility: hidden;
}
</style>
<script language="javascript" type="text/javascript" src="/vpn/nsshare.js"></script>
<script language="JavaScript" type="text/javascript" src="login.js"></script>
<SCRIPT language=JavaScript>
// frame-busting script
function changePage()
{
if( self == top ) {
document.getElementsByTagName("body")[0].style.display = 'block' ;
document.getElementsByTagName("body")[0].style.visibility = 'visible' ;
ns_fillName();
} else {
top.location = self.location ;
}

}
function setFocus(obj)
{
if (obj != null) {
obj.focus();
}
}
//-->
</SCRIPT>

<META content="MSHTML 6.00.2900.2802" name=GENERATOR></HEAD>
<BODY id=bodyTag onLoad="changePage();">
<!-- Copyright 2001-2012 Citrix Systems, Inc. All Rights Reserved -->

<NOSCRIPT>
<div id="authentication" >
<div id="logonbelt-topshadow">
</div>
<div id="logonbox-container">
<div id="logonbox-innerbox">
<div id="logonbox-logoarea">
<div id="logonbox-logoimage">
</div>
</div>
<div id="logonbox-logonform">
<div class="field CredentialTypenone"><div class="left"><div class="label error">
<span id="errorMessageLabel">
JavaScript is either disabled in or not supported by the Web browser.
To continue logon, use a Web browser that supports JavaScript or enable JavaScript in your current browser.
</span>
</div></div></div>
</div>
</div>
</div>
<div id="logonbelt-bottomshadow">
</div>
</div>
<div style="display:none">

</NOSCRIPT>

<div id="authentication" >
<div id="logonbelt-topshadow">
</div>
<div id="logonbox-container">
<div id="logonbox-innerbox">
<div id="logonbox-logoarea">
<div id="logonbox-logoimage">
</div>
</div>
<div id="logonbox-logonform">

<SCRIPT type="text/javascript">
function getCookie(name) { // use: getCookie("name");
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 3600 * 1000); // plus 28 days
var expired = new Date(today.getTime() - 24 * 3600 * 1000); // less 24 hours

function setCookie(name, value) { // use: setCookie("name", value);
document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}

function storeValues(form) {
setCookie("domainvalue", "#" + form.domainvalue.value +"#");
return true;
}
</SCRIPT>

<FORM method="post" action="/cgi/login" name="vpnForm" autocomplete="off" style="margin:0" onSubmit="return storeValues(this); clean_name_cookie(this);">
<DIV class="label plain CTX_ContentTitleHeader" id="ctl08_loginAgentCdaHeaderText2"></DIV>
<div class="field CredentialTypeusername">
<div class="left"><label for="username" class="label plain"><span id="User_name"></span></label></div>
<div class="right"><input id="Enter user name" class="prePopulatedCredential" autocomplete="off" spellcheck="false" type="text" title="" name="login" size="30" maxlength="127" onFocus="loginFieldCheck()" /></div></div>

<SCRIPT language=JavaScript>ns_showpwd();</SCRIPT>
<div class="field CredentialTypeusername">
<div class="left"><label for="username" class="label plain"><span id="User_name">Domain:</span></label></div>
<div class="right"><select class="dropdown" name="domainvalue" size="1″ style="width: 160px;"> <option value="AD">AD</option> <option value="NA">NA</option> <option value="ASIA">ASIA</option> <option value="EU">EU</option> <option value="WI">WI</option> <option value="WIAD">WIAD</option> <option value="FI">FI</option> </select></div></div>

<script language='javascript'>ns_disperrmsg();</script>

<div class="field buttons"><div class="right"><input type="submit" id="Log_On" value="" class="custombutton" onClick="ns_check();" /></div></div>

</form>
</div>
</div>
</div>
<div id="logonbelt-bottomshadow">
</div>
</div>
<DIV id=scriptArea></DIV>
<script type="text/javascript" language="javascript">
Resources.Load();
</script>
</BODY>
</HTML>
------------------------------------------------------------------------------------------------
login.js (ns_showpwd) is the last function in the script:
var loginPrefilled = false;

function UnsetCookie(cookieName) {
document.cookie=cookieName+"=nothing;expires=Thurs day, 1 Jan 1970 00:00:00 GMT; path=/";
}

function ns_check()
{
var login = document.forms['vpnForm'].login.value;
var passwd = document.forms['vpnForm'].passwd.value;
if(login == "") {
window.alert(_("You need to enter login name")); return false;
}
if (passwd == "") {
window.alert(_("You need to enter passwd")); return false;
}
return true;
}
function ns_disperrmsg()
{
var vpnerrCookieVal = ns_getcookie("NSC_VPNERR");
if( !(isNaN(vpnerrCookieVal)) && (vpnerrCookieVal >= "4001") && (vpnerrCookieVal <= _("errorMessageLabelMax"))) {
document.writeln('<div id="feedbackArea">');
document.writeln('<div id="feedbackStyle" class="feedbackStyleError">');
document.writeln('<span id="errorMessageLabel" class="messageStyle">');

document.writeln(_(_("errorMessageLabelBase") + vpnerrCookieVal));

document.writeln('</span>');
document.writeln('</div>');
document.writeln('</div>');
UnsetCookie("NSC_VPNERR");
return;
}
document.writeln("&nbsp;");
}

UnsetCookie("NSC_USER");
function ns_getcookie(name)
{
var cookie=document.cookie;
if(cookie.length > 0) {
begin=cookie.indexOf(name+"=");
if(begin!=-1) {
begin+=name.length+1;
end=cookie.indexOf(";", begin);
if(end==-1) end=cookie.length;
return decodeURIComponent(cookie.substring(begin, end));
}
}
return null;
}
function ns_fillName()
{
var value=ns_getcookie("NSC_NAME");

document.vpnForm.login.focus();
if(value!=null) {
document.vpnForm.login.value = value;
loginPrefilled = true;
document.vpnForm.login.style.color = "#777";
document.vpnForm.passwd.focus();
}
}
function loginFieldCheck()
{
if(loginPrefilled == true)
{
document.vpnForm.login.blur();
}
}

function clean_name_cookie()
{
UnsetCookie("NSC_NAME");
}

function ns_showpwd_default()
{
var pwc = ns_getcookie("pwcount");
document.write('<div class="field CredentialTypeusername"><div class="left"><SPAN>' + _("Password"));
if ( pwc == 2 ) { document.write('&nbsp;1'); }
document.write(':</SPAN></div>');
document.write('<div class="right"><input type="Password" title="' + _("Enter password") + '" name="passwd"></div>');
if ( pwc == 2 ) {
document.write('<TR><TD align=right style="padding-right:10px;white-space:nowrap;"><SPAN class=CTXMSAM_LogonFont>' + _("Password2") + '</SPAN></TD> <TD colspan=2 style="padding-right:8px;"><input class=CTXMSAM_ContentFont type="Password" title="' + _("Enter password") + '" name="passwd1" size="30" maxlength="127" style="width:100%;"></TD></TR>');
}
UnsetCookie("pwcount");
}



function ns_showpwd()
{
var pwc = ns_getcookie("pwcount");
document.write('<div class="field CredentialTypeusername"><div class="left"><SPAN>' + _("Password"));
if ( pwc == 2 ) { document.write('&nbsp;1'); }
document.write(':</SPAN></div></TD>');
document.write('<div class="right"><input type="Password" title="' + _("Enter password") + '" name="passwd" size="30" maxlength="127" ></div></div>');
if ( pwc == 2 ) {
document.write('<TR><TD align=right style="padding-right:10px;white-space:nowrap;"><SPAN class=CTXMSAM_LogonFont>' + _("Password2") + '</SPAN></TD> <TD colspan=2 style="padding-right:8px;"><input class=CTXMSAM_ContentFont type="Password" title="' + _("Enter password") + '" name="passwd1" size="30" maxlength="127" style="width:100%;"></TD></TR>');
}
UnsetCookie("pwcount");
}