ServerName="";
ServerAddress="";
ServerPort=443;
ServerTimeout=30;
AuthType="PrivateArk";
NTAuthAgentName="";
NTAuthAgentKeyFileName="";
DistinguishedName="";
BehindFirewall="no";
ReconnectPeriod=-1;
UseOnlyHTTP1InProxyConnection="no";
UseOnlyHTTP1InFirewallConnection="no";
CIFSGatewayName="";
HTTPGatewayName="";
ProxyAutoDetect="yes";
ProxyType="";
ProxyAddress="";
ProxyPort="";
ProxyUsername="";
OldServerName="";
OldServerAddress="";

//Should be exactly as the vars above
function InitVars()
{
ServerName="";
ServerAddress="";
ServerPort=443;
ServerTimeout=30;
AuthType="PrivateArk";
NTAuthAgentName="";
NTAuthAgentKeyFileName="";
DistinguishedName="";
BehindFirewall="no";
ReconnectPeriod=-1;
UseOnlyHTTP1InProxyConnection="no";
UseOnlyHTTP1InFirewallConnection="no";
CIFSGatewayName="";
HTTPGatewayName="";
ProxyAutoDetect="yes";
ProxyType="";
ProxyAddress="";
ProxyPort="";
ProxyUsername="";
OldServerName="";
OldServerAddress="";
}

function AddServer()
{
    ReplaceDetails = OldServerName + ";" + OldServerAddress;
    ServerNameAddress = ServerName + ";" + ServerAddress;

    AuthTypeAndInfo = AuthType + ";";
    if (DistinguishedName != "")
    {
        AuthTypeAndInfo = AuthTypeAndInfo + DistinguishedName;
    }
    else if (NTAuthAgentName != "")
    {
        AuthTypeAndInfo = AuthTypeAndInfo + NTAuthAgentName + ";" + NTAuthAgentKeyFileName;
    }

    ConnectionInfo = BehindFirewall + ";" + ReconnectPeriod + ";" + UseOnlyHTTP1InProxyConnection + ";" + UseOnlyHTTP1InFirewallConnection;

    ProxyInfo = ProxyAutoDetect;
    if (ProxyType != "" || ProxyAddress != "" || ProxyPort != "" || ProxyUsername != "")
    {
        ProxyInfo = ProxyInfo + ";" + ProxyType + ";" + ProxyAddress + ";" + ProxyPort + ";" + ProxyUsername;
    }

    GatewayNames = "";
    if (CIFSGatewayName != "" || HTTPGatewayName != "")
    {
      GatewayNames = CIFSGatewayName  + ";" + HTTPGatewayName;
    }

/*  alert(ReplaceDetails);
    alert(ServerNameAddress);
    alert(ServerPort);
    alert(ServerTimeout);
    alert(AuthType);
    alert(ConnectionInfo);
    alert(CIFSGatewayName);
    alert(ProxyInfo);*/
    rc = 0;
    rc = PAMain.AddServer(ReplaceDetails, ServerNameAddress, ServerPort, ServerTimeout, AuthTypeAndInfo, ConnectionInfo, GatewayNames, ProxyInfo);
    var agent = window.navigator.appVersion;
    var i = agent.indexOf("MSIE ")+5;
    if ((rc != 0) && (navigator.appName.indexOf('Microsoft') != -1) && (parseFloat(navigator.appVersion.substring(i,navigator.appVersion.length)) >= 4))
    {
        msgrc = "";
        if (rc == 1)
        {
            msgrc = "Too many Vaults";
        }
        else if (rc == 2)
        {
            msgrc = "Vault already exists";
        }
        else if (rc == 3)
        {
            msgrc = "Missing Vault name";
        }
        else if (rc == 4)
        {
            msgrc = "Missing Vault address";
        }
        else if (rc == 5)
        {
            msgrc = "Invalid Vault port";
        }
        else if (rc == 6)
        {
            msgrc = "Invalid timeout";
        }
        else if (rc == 7)
        {
            msgrc = "Invalid authentication type";
        }
        else if (rc == 8)
        {
            msgrc = "Invalid NT authentication agent";
        }
        else if (rc == 9)
        {
            msgrc = "Invalid NT authentication agent key";
        }
        else if (rc == 10)
        {
            msgrc = "Invalid NT authentication info";
        }
        else if (rc == 11)
        {
            msgrc = "Invalid PKI Distinguished Name";
        }
        else if (rc == 12)
        {
            msgrc = "Invalid Proxy info";
        }
        else if (rc == 13)
        {
            msgrc = "Invalid CIFS gateway info";
        }
        else if (rc == 14)
        {
            msgrc = "Internal Error";
        }
        else if (rc == 15)
        {
            msgrc = "Invalid connection timeout";
        }
        if (msgrc != "")
        {
            msgrc = "(error=" + msgrc + ")";
        }
        alert("Failed to add Vault '" + ServerName + "' " + msgrc);
    }
    InitVars();
}

function SetShortcut(ShortcutName)
{
   var parentUrl;
   var parentWin = window.opener;
   if (parentWin != null && !parentWin.closed)
   {
      parentUrl = parentWin.location.href;
   }
   else
   {
      parentUrl = window.location.href;
   }
   //alert(parentUrl);
   PAMain.SetShortcut(parentUrl, ShortcutName);
}

function doWins(InstallType)
{
   var winProps = new Array(",resizable=yes,width=", ",height=", ", left=0, top=0,toolbar=no,menubar=no,location=no,fullscreen=no");
   var URL = "";
   var WidthSpace = 700;
   var HeightSpace = 500;
	var currWin = "paweb/pacheck" + InstallType + ".htm";
	var d = new Date();
	var IsStatusBar;

	if(navigator.appName.indexOf('Netscape') != -1) {
		IsStatusBar = "status=no";
		WidthSpace = window.screen.width*0.99;
		HeightSpace = window.screen.height*0.90;
	}
	else {
		IsStatusBar = "status=yes";
		var agent = window.navigator.appVersion;
		var i = agent.indexOf("MSIE ")+5;
		if(parseFloat(navigator.appVersion.substring(i,navigator.appVersion.length)) >= 4) {
			WidthSpace = window.screen.width*0.99;
			HeightSpace = window.screen.height*0.88;
		}
	}
	window.open(currWin, "wnd"+d.getMinutes()+d.getSeconds(),
	 IsStatusBar+winProps[0] + (WidthSpace) + winProps[1] + (HeightSpace) + winProps[2]); //open application container window

}

