/* $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 control to be populated. * @param xBit Int, the specified commodity. * @return none */ function PopulateMonthYear(mthYrCtrl, xBit) { var i, newOption, mthYrArray; mthYrCtrl.innerHTML = ""; mthYrArray = GetAllMonthYear(xBit); for (i = 0; i < mthYrArray.length; i++) { newOption = document.createElement("OPTION"); newOption.text = g_mthAbbrev[mthYrArray[i][0]] + " " + mthYrArray[i][1]; newOption.value = g_mthChar[mthYrArray[i][0]] + mthYrArray[i][1]; mthYrCtrl.options.add(newOption); } } /** * GetCookie - Gets a cookie that is part of a cookie array (or group) * cookie groups are separated by a ";" and individual cookies within * a group are separated by an ampersand "&"; a cookie group will look * like this: Group=Cookie1=Cookie1_Value&Cookie2=Cookie2_Value * * @param group group that the cookie is part of * @param name name of the cookie within the group * @return returns the value of the cookie if found and null if not **/ function GetCookie(group, name) { var value = null; var pos; var start, end; var grp_value; pos = document.cookie.indexOf(group + "="); if (pos != 1) { start = pos + group.length + 1; end = document.cookie.indexOf(";",start); if (end == -1) end = document.cookie.length; grp_value = "&" + document.cookie.substring(start, end); pos = grp_value.indexOf("&" + name + "="); if (pos != -1) { start = pos + name.length + 2; end = grp_value.indexOf("&",start); if (end == -1) end = grp_value.length; value = grp_value.substring(start, end); value = unescape(value); } } return value; } /** * XMLRequest - Constructor for the XMLRequest class; used to * post XML to a URL and retrieve the response, asynchronously * or synchronously * * @param async true if the object is to make the request * asynchronously false otherwise * @param handler handler to use as callback for asynchronous requests **/ function XMLRequest(async, handler) { // member data this.XMLHTTP = new ActiveXObject("Microsoft.XMLHttp"); this.async = (async == null) ? false : async; this.handler = handler; // set this to set an error handler function that will be // called when ValidateResponseXML returns null this.errhandler = null; // set this public variable to true to prevent alerts // from displaying this.Silent = false; // methods this.PostXML = XMLRequestGetXML; this.IsLoaded = XMLRequestIsLoaded; this.GetResponseXML = XMLRequestGetResponseXML; this.GetStatus = XMLRequestGetStatus; this.GetStatusText = XMLRequestGetStatusText; this.IsOK = XMLRequestIsOK; } /** * XMLRequestGetXML - Posts the provided XML to the specified * URL * * @param url URL to post to * @param postXML XML document to post to the URL * @return If this is not asyncronous, this will return * the responseXML; otherwise nothing is returned **/ function XMLRequestGetXML(url, postXML) { var xmlhttp = this.XMLHTTP; var async = this.async; xmlhttp.open("POST", url, async); if (async) { this.XMLHTTP.onreadystatechange = this.handler; } 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(postXML); if (!async) return this.GetResponseXML(); } /** * XMLRequestIsLoaded - Checks the readyState of the * document to see if it has been full loaded * * @return Returns true if the XML has finished loaded (readyState = 4) * or false if not **/ function XMLRequestIsLoaded() { var xmlhttp = this.XMLHTTP; var loaded; loaded = (xmlhttp.readyState == 4) ? true : false; return loaded; } /** * XMLRequestGetResponseXML - Validates and retrieves the XML * document that was returned from the request * * @return Returns the validated response XML document **/ function XMLRequestGetResponseXML() { var respxml = ValidateResponseXML(this.XMLHTTP.responseXML, this.Silent); if (!respxml && (this.errhandler != null)) { this.errhandler(); } return respxml; } /** * XMLRequestGetStatus - Gets the status of the pending HTTP request * * @return The HTTP status of the pending request **/ function XMLRequestGetStatus() { return this.XMLHTTP.status; } /** * XMLRequestIsOK - Checks the status of the pending HTTP request * and returns whether it returned with a valid non-error status * * @return Returns true if the request was successful, false if not **/ function XMLRequestIsOK() { var status = this.XMLHTTP.status; if (status == 200 || status == 201) return true; else return false; } /** * XMLRequestGetStatusText - Returns the text message associated with the * status of the current HTTP Request * * @return The text description of the HTTP status of this request **/ function XMLRequestGetStatusText() { var errDesc; var status = this.XMLHTTP.status; switch (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.";break; case 201:errDesc="The request has been fulfilled and resulted in the creation of a new resource.";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; } return errDesc; } /** * MoveElementToBottom - This function * will move the supplied element to the * bottom of the page offset by the specified amt * * @param elem The HTML element to move to the bottom * @param offset The offset (in pixels) from the bottom **/ function MoveElementToBottom(elem, offset) { elem.style.top = document.body.clientHeight - offset; } /** * chooseEnvironment - a function to check to see if the * specified Trader has any accounts that are local (assigned to * environment that they are currently logged into) or remote (assigned * to any other environment). If remote accounts exist, then display * a modal dialog of those accounts. If the dialog is closed, then * check for local account. If no local accounts, display a warning. **/ function chooseEnvironment(traderId) { var xdocLocalRemoteAccounts = GetXML("/Global/LocalRemoteAccounts.xml.asp"); if (xdocLocalRemoteAccounts != null) { var remoteAccountNodes = xdocLocalRemoteAccounts.selectNodes("//RemoteAccounts/Account"); if (remoteAccountNodes.length > 0) { var remoteMenu = window.parent.navBarFrame.document.all("RemoteAcctDiv"); if (remoteMenu != null) { remoteMenu.style.display = "inline"; } // note that at logon time, to maintain the auto-redirect functionality, we will display // the remote account information in a modal dialog. That way, they can get the info // and we can maintain the flow of auto-redirect. window.location.href = "/Languages//PrvLbl//front.asp"; window.showModalDialog("/Global/RemoteAccounts.asp",remoteAccountNodes,"center=yes;dialogWidth=425pt;dialogHeight=350pt;status:no;resizable:yes"); } var localAccountNodes = xdocLocalRemoteAccounts.selectNodes("//LocalAccounts/Account"); if (localAccountNodes.length == 0) { alert("You are not authorized on any accounts local to this environment!"); } } }