/* $Id$ */
/**
* ClientScripts.cli.js.asp - common file for client-side scripting
*/
/**
* Global variables
* These are commonly used global variables and may be set or used
* by the functions below. See a function's comments for information
* on prerequisites for calling.
*/
var g_futExpiryXML = null; // storage for FutExpiry XML document
var g_futListXML = null; // storage for FutList XML document
/**
* GetXML - retrieve an XML response from the specified URL,
* optionally POSTs a source XML document. Expects XML response.
* Error response should look like:
*
* If an error response is received, the client error message is
* displayed and null is returned. If no document is received
* or some other error occurs, an error message is displayed and
* null is returned. Otherwise, the XML document received is
* returned.
*
* @param url string, the URL to be opened
* @param xmlMessage optional, XML DOM document to POST. If null,
* then nothing POSTed, URL is simply opened.
* @return XML DOM with response document, or null if no valid
* response received (see notes above).
*/
function GetXML (url, xmlMessage)
{
var responseXML;
// If xmlMessage != null, the provided XML is HTTP POSTed.
if (xmlMessage != null)
{
responseXML = GetXMLPOST(url, xmlMessage);
}
// If xmlMessage == null, the url is simply opened using HTTP GET.
else
{
responseXML = GetXMLGET(url);
}
return ValidateResponseXML(responseXML);
} // GetXML()
/**
* ValidateResponseXML - Validates the provided XML object
* as a response from some page request. If there is an Error
* element, display the specified error with option for user
* to see error details. For format, see comments
* for GetXML above.
*
* @param responseXML XML DOM object to be validated
* @param silent Optional parameter indicating that no
* alerts should be generated
* @return null if with XML ( element or failure
* in parsing XML), responseXML if all is OK
*/
function ValidateResponseXML(responseXML, silent)
{
var errCode, errorNode, clientMessage;
var errNumber, errDesc, errLocation, errPage;
if (responseXML == null)
{
return null;
}
errCode = responseXML.parseError.errorCode;
if (errCode != 0)
{
// don't show an error message for the "operation aborted by
// caller" error.
if (errCode != -1072897514)
{
var msg = "There was an error retrieving the requested information (error code " + responseXML.parseError.errorCode + ").\nPlease refresh your browser (F5), and try your request again.\nIf the problem persists, please contact customer service for assistance.";
if (silent == true) {
var err = new Error();
err.number = 5046;
err.description = msg;
err.errorCode = responseXML.parseError.errorCode;
err.reason = responseXML.parseError.reason;
err.url = responseXML.parseError.url;
throw err;
} else {
alert(msg);
}
}
return null;
}
errorNode = responseXML.selectSingleNode("//Error");
if (errorNode)
{
try
{
clientMessage = errorNode.selectSingleNode("//@ClientMessage").value;
errNumber = errorNode.selectSingleNode("//@Number").value;
errDesc = errorNode.selectSingleNode("//@Description").value;
errLocation = errorNode.selectSingleNode("//@Location").value;
errPage = errorNode.selectSingleNode("//@Page").value;
}
catch (e)
{
clientMessage = "Error retrieving requested information and error number";
errNumber = 9830;
errDesc = "Error node found but details not available";
errLocation = "ValidateResponseXML";
errPage = "ClientScripts.cli.js.asp";
}
if (silent == true) {
var err = new Error();
err.number = errNumber;
err.description = errDesc;
err.ClientMessage = clientMessage;
err.location = errLocation;
err.page = errPage;
throw err;
} else {
if (confirm (clientMessage + "\nPlease press Cancel, refresh your browser (F5), and try your request again.\nIf the problem persists, please press OK for additional problem details and contact customer service for assistance."))
{
alert ( "Number = " + errNumber + "\n" +
"Description = " + errDesc + "\n" +
"Location = " + errLocation + "\n" +
"Page = " + errPage + "\n");
}
}
return null;
}
if (responseXML.length == 0)
{
return null;
}
return responseXML;
} // ValidateResponseXML()
/**
* GetXMLPOST - Get XML from the specified URL, HTTP POSTing the
* supplied XML as part of the request.
*
* @param url The URL to open
* @param xmlMessage XML DOM object to be POSTed
* @return null if there was a problem opening the URL or with
* the returned XML, XML DOM object of returned XML if all is OK
*/
function GetXMLPOST (url, xmlMessage)
{
var xmlHttp, errDesc, ok;
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST", url, false);
var topCast = null;
if (Cast && Cast.TopWindow)
{
topCast = Cast;
}
else
{
topCast = (window.top || {}).Cast;
}
if (topCast && topCast.TopWindow && topCast.TopWindow.masthead && topCast.TopWindow.masthead.document
&& topCast.TopWindow.masthead.document.getElementById("CSRFtoken"))
{
csrfToken = topCast.TopWindow.masthead.document.getElementById("CSRFtoken").value;
xmlHttp.setRequestHeader("CAST-CSRF-Value", csrfToken);
}
xmlHttp.send(xmlMessage);
if (xmlHttp.status != 200)
{
errDesc = "";
ok = false;
switch (xmlHttp.status)
{
case 100:errDesc="The request can be continued.";break;
case 101:errDesc="The server has switched protocols in an upgrade header.";break;
case 200:errDesc="The request completed successfully.";ok = true;break;
case 201:errDesc="The request has been fulfilled and resulted in the creation of a new resource.";ok = true;break;
case 202:errDesc="The request has been accepted for processing, but the processing has not been completed.";break;
case 203:errDesc="The returned meta information in the entity-header is not the definitive set available from the origin server.";break;
case 204:errDesc="The server has fulfilled the request, but there is no new information to send back.";break;
case 205:errDesc="The request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action.";break;
case 206:errDesc="The server has fulfilled the partial GET request for the resource.";break;
case 300:errDesc="The server couldn't decide what to return.";break;
case 301:errDesc="The requested resource has been assigned to a new permanent URI (Uniform Resource Identifier), and any future references to this resource should be done using one of the returned URIs.";break;
case 302:errDesc="The requested resource resides temporarily under a different URI (Uniform Resource Identifier).";break;
case 303:errDesc="The response to the request can be found under a different URI (Uniform Resource Identifier) and should be retrieved using a GET method on that resource.";break;
case 304:errDesc="The requested resource has not been modified.";break;
case 305:errDesc="The requested resource must be accessed through the proxy given by the location field.";break;
case 307:errDesc="The redirected request keeps the same verb. HTTP/1.1 behavior.";break;
case 400:errDesc="The request could not be processed by the server due to invalid syntax.";break;
case 401:errDesc="The requested resource requires user authentication.";break;
case 402:errDesc="Not currently implemented in the HTTP protocol.";break;
case 403:errDesc="The server understood the request, but is refusing to fulfill it.";break;
case 404:errDesc="The server has not found anything matching the requested URI (Uniform Resource Identifier).";break;
case 405:errDesc="The method used is not allowed.";break;
case 406:errDesc="No responses acceptable to the client were found.";break;
case 407:errDesc="Proxy authentication required.";break;
case 408:errDesc="The server timed out waiting for the request.";break;
case 409:errDesc="The request could not be completed due to a conflict with the current state of the resource. The user should resubmit with more information.";break;
case 410:errDesc="The requested resource is no longer available at the server, and no forwarding address is known.";break;
case 411:errDesc="The server refuses to accept the request without a defined content length.";break;
case 412:errDesc="The precondition given in one or more of the request header fields evaluated to false when it was tested on the server.";break;
case 413:errDesc="The server is refusing to process a request because the request entity is larger than the server is willing or able to process.";break;
case 414:errDesc="The server is refusing to service the request because the request URI (Uniform Resource Identifier) is longer than the server is willing to interpret.";break;
case 415:errDesc="The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.";break;
case 449:errDesc="The request should be retried after doing the appropriate action.";break;
case 500:errDesc="The server encountered an unexpected condition that prevented it from fulfilling the request.";break;
case 501:errDesc="The server does not support the functionality required to fulfill the request.";break;
case 502:errDesc="The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request.";break;
case 503:errDesc="The service is temporarily overloaded.";break;
case 504:errDesc="The request was timed out waiting for a gateway.";break;
case 505:errDesc="The server does not support, or refuses to support, the HTTP protocol version that was used in the request message.";break;
default:errDesc="An unknown error (" + xmlHttp.status + ") occurred at the server. Please retry your request.";break;
}
if (!ok)
{
alert("Error: " + errDesc + "\nURL: " + url);
return null;
}
}
return ValidateResponseXML(xmlHttp.responseXML);
} // GetXMLPOST()
/**
* GetXMLGET - Get XML from the specified URL
*
* @param url The URL to open
* @return null if there was a problem opening the URL or with
* the returned XML, XML DOM object of returned XML if all is OK
*/
function GetXMLGET (url)
{
var doc;
doc = new ActiveXObject("Microsoft.XMLDOM");
doc.async = false;
doc.load (url);
if (doc.parseError.errorCode != 0)
{
alert("Error loading data from server.\nURL: " + doc.parseError.url + "\nDescription: " + doc.parseError.reason);
return null;
}
return doc;
} // GetXMLGET()
/**
* PopupCalendar - display a modal dialog with a dynamic calendar. Set
* the specified control to the date selected in the calendar, if any.
* Date format is: [day] [MonthAbbrev] [year4digit]
* [MonthAbbrev] is one of: "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
* NOTE: if not able to set the specified control, no error message is generated!
*
* @param elTarget Control to be set with selected date
* @return none
*/
function PopupCalendar(elTarget)
{
var sRtn;
sRtn = showModalDialog("/Global/Calendar.asp","","center=true;dialogWidth=200pt;dialogHeight=200pt;status=no;");
if (sRtn!="")
{
try
{
elTarget.value = sRtn;
}
catch (e) {}
}
}
/**
* PopupUCS - display a modal dialog box containg the Universal Contract
* Selector (UCS).
*
* @param elTarget Control to be set with selected contract, or null
* if nothing should be set (XML is still returned).
* @return XML DOM object containing the selected contract and, if
* changed, the complete personal list. Format is:
*
* If personal list is included, there will be a element with the
* same format as FutExpiry.
*/
function PopupUCS(elTarget)
{
var sRtn, outXML, selectedContract;
sRtn = null;
outXML = new ActiveXObject("Microsoft.XMLDOM");
sRtn = showModalDialog("/Languages//Trade/UCS/UCSdialog.asp","","center=yes;dialogWidth=460pt;dialogHeight=250pt;status=no;");
if (sRtn != null)
{
outXML.loadXML(sRtn);
try
{
selectedContract = outXML.selectSingleNode("/Root/c").getAttribute("s");
}
catch (e)
{
selectedContract = "";
alert("Error retrieving selected contract");
}
if ( (elTarget != null) && (selectedContract != "") )
{
elTarget.value = selectedContract;
}
}
else
{
outXML.loadXML("");
}
return outXML;
}
/**
* PopulateMonthYear - populates the specified