function AJAXSubmit(jsObj, formObj, url,formId, submitObj, refreshObj, fn){
	var httpRequest = httprequestpool.get();
	httpRequest.submitRequest(jsObj, formObj, url,formId, submitObj, refreshObj, fn, null);
}

function AJAXSubmit(jsObj, formObj, url,formId, submitObj, refreshObj, fn, addParam){
	var httpRequest = httprequestpool.get();
	httpRequest.submitRequest(jsObj, formObj, url,formId, submitObj, refreshObj, fn, addParam);
}



function nav_getXMLHttp(xhr){
	if(xhr != null) return xhr;
	if(window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else {
		try { 
			xhr = new ActiveXObject("Msxml2.XMLHTTP"); 
		} catch (e) {
			try {
				xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
			} catch (e) {
				xhr = false; 
			} 
	    }
	}
	return xhr;
}

function checkResponseText(url, xhr){
	if (xhr.responseText)
	{
		if (url.indexOf("checkRTQAuth") <0){	//For normal ajax request check session
			if (xhr.responseText.indexOf("<?xml version")<0)	//Not found xml header,assume session timeout
			{
				//var rtnMsg = openXMLHttpObject(null, "/cas/logout")
				redirectURL(url);
			}
		} else {
			if (xhr.responseText != "Y")
				redirectURL(urlRedirect);
		}
	}
}

//from igf_core.js
function updateScript(httpReq){
	//var xmlDoc = getRespXml();
	var xmlDoc = httpReq.getRespXml();
	if(xmlDoc.documentElement){
		var results = xmlDoc.documentElement;
		var components = results.getElementsByTagName("component");
	
		if (typeof components != 'undefined' && components != null){
			// iterate through the component we got from the server
			for (var i=0; i<components.length; i++) {
				// get a component
				var component = components.item(i);
				// get the component id
				var componentId = component.getAttribute("id"); //getAttribute(result, "ocid");
				// we have an id
				if (NaES(componentId)) {
					// try to get the component from the document source
					var currentComponent = getElementById(componentId);
					//if (!isNull(currentComponent)) {
					if (typeof currentComponent != "undefined" && currentComponent!=null) {
						// we found the component from the document source
						// great, we can start the real work
						var content = component.getElementsByTagName("content").item(0);
						// we need to refresh the content of this component
						if (typeof content != "undefined" && content!=null) {
							// get the html content
							var contentAsHtml = (typeof content.firstChild!="undefined" && content.firstChild!=null) ? content.firstChild.nodeValue : "";
							// the content is not null/empty
							if (NaES(contentAsHtml)) {
								// parse the html we got
								var parsedContent = parseHtml(contentAsHtml, false);
								//var parsedContent = parseHtml(contentAsHtml);
//alert("before update\r\n" + contentAsHtml);
								// the content has been successfully parsed!!
								if (typeof parsedContent != "undefined" && parsedContent != null) {
									// need to re-create script nodes so that scripts are correctly interpreted by the browser...
									var cscripts = parsedContent.getElementsByTagName("script");
									var scripts = [];	// scripts with a src attribute
									var iscripts = [];	// inline scripts
									if (isArray(cscripts)) {
										// store the script src and content
										for (var j=0; j<cscripts.length; j++) {
											var aScript = cscripts[j];
											if (NaES(aScript.src)) {
												scripts.push(aScript.src);
											}
											else {
												var scriptContent = aScript.innerHTML;													
												if (NaES(scriptContent)) {
													// removes <!-- and //-->0
													scriptContent = scriptContent.replace(/<!--/g, "");
													scriptContent = scriptContent.replace(/\/\/-->/g, "");
													iscripts.push(scriptContent);
												}
											}
										}
										// remove the script nodes
										while (cscripts.length > 0) {
//purge(cscripts[0]);
											deleteNode(cscripts[0]);
//ig.deleteChildren(cscripts[0]);
										}																						
									}
												
									// we can now continue and insert the node at the right place
									var parentNode = currentComponent.parentNode;
									var insertBeforeNode = currentComponent.nextSibling;
									var newNode = findDescendant(parsedContent, "id", componentId);
									while (!isNull(newNode)) {
										var existingNode = null;
										if (NaES(newNode.id)) {
											existingNode = findDescendant(parentNode , "id", newNode.id);
										}
										// keep track of the next sibling now, we will nedd it later-on
										var nextSibling = newNode.nextSibling;																
										// there are have two cases: children already exists or not
										if (!isNull(existingNode)) {
										// the component already exist, swap nodes
											replaceNode(existingNode, newNode); 
										} 
										else {
										// the component doesn't exist yet in the source document
											// look up its parent id and add it right after it
											if (!isNull(parentNode) ) {
												parentNode.insertBefore(newNode, insertBeforeNode);
											}
										}
										// move on to the next sibling
										newNode = nextSibling;																						
									}
									// re-load each javascript script, one after the other
									for (j=0; j<scripts.length; j++) {
//alert("scripts = " + scripts[j]);
										try{
											httpReq.loadScript(scripts[j]);
										}catch(err){}
									}		
									// re-load each inline javascript script
									for (j=0; j<iscripts.length; j++) {
//alert("iscripts = " + iscripts[j]);
										try{
											executeScript(iscripts[j]);
										}catch(err){}
									}																																																				
								}
							}
							// IMPORTANT to delete the parsed content and free-up ressources
//alert(parsedContent.name);
//										deleteNode(parsedContent);
deleteChildren(parsedContent);
						}
					}
				}
			}		
		}				
	}
}


//from igf_core.js
function updateViewState(formId, httpReq){
	//var xmlDoc = getRespXml();
	var xmlDoc = httpReq.getRespXml();
	var results = xmlDoc.documentElement;
	if (results && results.getElementsByTagName("state")){
		var clientState = results.getElementsByTagName("state").item(0);
		if (typeof clientState != "undefined" && clientState !=null) {
			var clientStateContent  = clientState.getElementsByTagName("content").item(0);
			// we need to refresh the content of this component
			if (typeof clientStateContent != "undefined" && clientStateContent != null) {										
				// get the html content
				var clientStateAsHtml = (typeof clientStateContent.firstChild != "undefined" && clientStateContent.firstChild != null) ? clientStateContent.firstChild.nodeValue : "";
				// the clientState section is not null/empty
					// parse the html we got but do NOT append it to the document
					// otherwise we won't be able to find the current state in the source document
					// because of duplicates ids/names
					var parsedClientState = parseHtml(clientStateAsHtml, false);
					// the clientState section has been successfully parsed!!
					if (typeof parsedClientState != "undefined" && parsedClientState != null) {
					// we got the state from the server, but we can't assume its name since it's implementation dependant
					// simply iterate over all elements and replace them in the souce document
					// it's very likely that the state is stored in one hidden field but who knows...
						var nodes = parsedClientState.childNodes;
						for (var k=nodes.length-1; k>=0; k--) {
							var aNode = nodes.item(k);
							if (aNode.nodeName == "INPUT") {
							// we are only interested in input element
								//var id = aNode.id;
								var currentNode = null;
								//if (ig.NaES(id)) {
								// locate the node by its id
								//	currentNode = document.getElementById(id);
								//}
								//else {
								// no id, locate the node by its name
									var name = aNode.name;
									// get all elements in the source document that have the same name
									var elements = document.getElementsByName(name);
									// make sure there is only ONE match
									if (elements.length==1) {
									// replace the previous state with the one we got from the server
										currentNode = elements[0];
									} else {
										var length = elements.length;
										//var pId1 = ig.getFormId(document.getElementById(httpReq.sourceOfRequest));
										var pId1 = formId;
										for(i=length-1; i>=0; i--) {
										  var el = elements[i];	
										  if(el.parentNode.id == pId1) {
										  currentNode = elements[i];
									  }	
									}
								}				
							}
							if (typeof currentNode != "undefined" && currentNode != null) {
							// we got the node, do a swap
								replaceNode(currentNode, aNode);
							}									
						//}
					}
						// IMPORTANT to delete the parsed content and free-up ressources
	//										deleteNode(parsedClientState);
				}
			}
		}
	}
}

String.prototype.trim = function String$trim() {
    /// <summary locid="M:J#String.trim" />
    /// <returns type="String"></returns>
    if (arguments.length !== 0) throw Error.parameterCount();
    return this.replace(/^\s+|\s+$/g, '');
}




		function formToUri(frm) {
			var qs = new IgUri();
			if (typeof frm != 'undefined' && frm != null) {
				//qs = frm.action;
				for (var i=0; i<frm.elements.length; i++) {
					var control = frm.elements[i];
					if (typeof control != 'undefined' && control != null) {
						// get the name of the control
						var name = control.name;
//alert("control.name = " + control.name + ", naes = " + NaES(name) + "disabed + " + control.disabled);
						if (NaES(name) && (control.disabled!==true)) {
							// get the type of the control
							var type = control.type;
							// process the control based-upon its type
							if (type=="hidden" 
									|| type=="password"
									|| type=="text"
									|| type=="textarea") {
								qs.addParameter(name, control.value);
							}
							else {
								if (type=="button") {
								// TODO. Need to submit the x and y mouse coordinate for image button					
								}
								else {
									if (type=="checkbox") {
										if (control.checked===true) {
											qs.addParameter(name, control.value);
										}
									}
									else {
										if (type=="radio") {
											if (control.checked===true) {
												qs.addParameter(name, control.value);
											}
										}
										else {
											if (type=="select-one") {
												// loop through all options and return the first selected one
												for (var j=0; j<control.options.length; j++) {
													if (control.options[j].selected===true) {
														qs.addParameter(name, control.options[j].value);
														break;
													}
												}
											}
											else {
												if (type=="select-multiple") {
													// loop through all options and return the first selected one
													for (var k=0; k<control.options.length; k++) {
														if (control.options[k].selected===true) {
															qs.addParameter(name, control.options[k].value);															
														}
													}
												}
												else {
													if (type=="submit") {
													// TODO: need to look at the html 4.0 spec to determine what we need to do in that case
													}								
												}
											}
										}
									}
								}
							}
						}
					}					
				}
			}
			return qs;
		}


function getAllFormsData(cse, refreshObj) {
    var formArray = document.forms;
    var formData;
    for (var i = 0; i < formArray.length; i++) {
        formData = getFormData(formArray[i], cse, refreshObj);
    }
    return formData;
}

function addParam(name, value, emptyString) {
	var dataString = "";
//    dataString += (dataString.length > 0 ? "&" : "")
//        + escape(name).replace(/\+/g, "%2B") + "="
//        + escape(value ? value : "").replace(/\+/g, "%2B");
//    dataString += (dataString.length > 0 ? "&" : "")
//        + encodeURIComponent(name) + "="
//        + encodeURIComponent(value);
    dataString += (!emptyString ? "&" : "")
        + encodeURIComponent(name) + "="
        + encodeURIComponent(value);
return dataString;
}


/*
function addParam(name, value) {
alert("name = " + name + " and value = " + value);
			if (typeof name=='string' && typeof name.length != 'undefined' && name.length!=null && name.length>0) {
alert("A");
				if (typeof dataString !='undefined' && dataString != null) {
alert("B");
				 	if (dataString.charAt(dataString.length-1)!='&') {
				 		dataString = dataString + "&";
				 	}
				 }
				 else {
					dataString = "";
				}				
				dataString = dataString + encodeURIComponent(name) + "=" + encodeURIComponent(value);
			}
}
*/
function getFormData(form, cse, refreshObj) {
    var dataString = "";
    var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
                    || elemType == "HIDDEN"){
                //addParam(elemName, encodeURIComponent(element.value));
		dataString += addParam(elemName, element.value, (dataString == ""));
            }else if (elemType == "CHECKBOX" && element.checked)
                dataString += addParam(elemName, 
                    element.value ? element.value : "On", (dataString == ""));
            else if (elemType == "RADIO" && element.checked)
                dataString += addParam(elemName, element.value, (dataString == ""));
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        dataString += addParam(elemName,
                            option.value ? option.value : option.text, (dataString == ""));
                }
        }
    }
//Trigger server side infragistics service
dataString += addParam("com.infragistics.faces.CLIENT_SIDE_EVENT", cse, (dataString == ""));	
dataString += addParam("com.infragistics.faces.SMART_REFRESH_COMPONENTS", refreshObj, (dataString == ""));
// fix for sun implementation 1.1.02
dataString += addParam("com.sun.faces.FORM_CLIENT_ID_ATTR", form.id, (dataString == ""));
// end of fix for sun implementation 1.1.02
    return dataString;
}

/*
function getRespXml(xhr) {
	// Portals support
	var xmlDoc;
	var xmlText;
	if ((xhr.responseXML==null && xhr.responseText!=null)
	|| (xhr.responseXML!=null && xhr.responseXML.documentElement==null))
	{
	    var endIdx = xhr.responseText.indexOf("</fragments>");
	    xmlText = xhr.responseText.substring(0, endIdx)+"</fragments>";
	}
	// the response coming from the portals is XML, but since the content-type is not XML, our responseXML property
	// is null in Firefox, and not null in IE (in IE the documentElement of the responseXML is null)
	// therefore we need to parse/feed the xml text into a DOM object 
	if (xhr.responseXML==null && xhr.responseText!=null)
	{
		xmlDoc = (new DOMParser()).parseFromString(xmlText, 'text/xml');
		return xmlDoc;
	} else if (xhr.responseXML!=null && xhr.responseXML.documentElement==null) {
		if (window.ActiveXObject) {
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(xmlText);
			return xmlDoc;
		}							
	}
	// in all other cases we have a standard non-portal response
	return (xhr!=null ? xhr.responseXML : null);
}
*/

//Parse response xhtml to xml parser for further process
function loadXML(content){
	var xDoc=null;
	if( window.ActiveXObject && /Win/.test(navigator.userAgent) )
	{
		xDoc = new ActiveXObject("Microsoft.XMLDOM");
		xDoc.async = false;
		xDoc.loadXML(content);
//		xNode = xDoc.getElementsByTagName("input");
//		if (xNode)
//			alert(xNode[0].getAttribute("value"));
	}
	else
	{
		xDoc=document.implementation.createDocument("http://www.w3.org/1999/xhtml","html",null);
		xDoc.documentElement.innerHTML = content;
		//xmlDoc.load(content);
		//alert(xmlDoc.documentElement);
		//alert("docElem = " + xmlDoc.documentElement.getElementById("sideEmail:sendEmailStatus"));
//		alert("docElem = " + xmlDoc.getElementById("sideEmail:sendEmailStatus").value);
	}
	return xDoc;
}

//Get component attribute with passed attribute parameter
//or get whole node value with passed attribute parameter
function getComponentContent(componentId, tagName, attribute, xhr){
	//var xmlDoc = getRespXml(xhr);
	var xmlDoc = xhr.getRespXml();
	var results = xmlDoc.documentElement;
	var components;
	if (componentId == "javax.faces.ViewState")
	{
		components = results.getElementsByTagName("state");
		componentId = null;
	}
	else
		components = results.getElementsByTagName("component");

//alert("xmlDoc = " + (new XMLSerializer()).serializeToString(xmlDoc));
	// iterate through the component we got from the server
	for (var i=0; i<components.length; i++) {
		// get a component
		var component = components.item(i);
		// get the component id
		var id = component.getAttribute("id");
		//Enumerate all components
		if(id==componentId)
		{
//alert("id = " + componentId);
			var content = component.getElementsByTagName("content").item(0);
			if (typeof content != 'undefined' && content != null)
				var contentAsHtml = (typeof content.firstChild != 'undefined' && content.firstChild != null) ? content.firstChild.nodeValue : "";
//contentAsHtml = xmlencode(contentAsHtml);

//document.getElementById("ABCABC").value = contentAsHtml;
//alert("contentAsHtml = " + contentAsHtml);


//			contentAsHtml = removeScript(contentAsHtml);
//alert(contentAsHtml);
			if (typeof attribute != "undefined" && attribute != null)
			{
				//Convert JSF generated script
				contentAsHtml = contentAsHtml.replace("i \< adp.length", "i &lt; adp.length");
				contentAsHtml = "<content>" + contentAsHtml + "</content>";
//alert("contentAsHtml=" + contentAsHtml);
				var xContent = loadXML(contentAsHtml);
				if (xContent.getElementsByTagName(tagName) && xContent.getElementsByTagName(tagName).length>0)
				{
//alert(xContent.getElementsByTagName(tagName).length);
//alert((new XMLSerializer()).serializeToString(xContent.getElementsByTagName(tagName)[0]));

					if (attribute == "innerHTML")
					{
						//if (typeof xContent.getElementsByTagName(tagName)[0].innerHTML == 'undefined')	//For IE
							//return xContent.getElementsByTagName(tagName)[0].text;
//alert(xContent.getElementsByTagName("content")[0].firstChild.nodeValue);
							return xContent.getElementsByTagName(tagName)[0].firstChild.nodeValue;

						//else	//For firefox/chrome/safari
						//	return xContent.getElementsByTagName(tagName)[0].innerHTML;
					}
					else if (attribute == "toString")
					{
						var rtnVal = "";
//						for (var j=0;j<xContent.getElementsByTagName(tagName).length;j++)
//						{
							if (xContent.getElementsByTagName(tagName)[0].xml)
								rtnVal += xContent.getElementsByTagName(tagName)[0].xml;
							else
								rtnVal += (new XMLSerializer()).serializeToString(xContent.getElementsByTagName(tagName)[0]);
							//return innerHTML(xContent.getElementsByTagName(tagName)[j]);
							//if (typeof xContent.getElementsByTagName(tagName)[j].innerHTML!='undefined')
							//{
							//	return xContent.getElementsByTagName(tagName)[j].innerHTML;	//firefox/chrome/safari
							//}
							//else
							//{
							//	return xContent.getElementsByTagName(tagName)[j].xml;		//IE
							//}
//						}
						return rtnVal;
					}
					else if (attribute == "allTag")
					{
						var rtnVal = "";
						for (var j=0;j<xContent.getElementsByTagName(tagName).length;j++)
						{
							if (xContent.getElementsByTagName(tagName)[0].xml)
								rtnVal += xContent.getElementsByTagName(tagName)[0].xml;
							else
								rtnVal += (new XMLSerializer()).serializeToString(xContent.getElementsByTagName(tagName)[0]);
						}
						return rtnVal;

					}
					else
					{
						return xContent.getElementsByTagName(tagName)[0].getAttribute(attribute);
					}
				}
				return null;
			} else {
				return contentAsHtml;
			}
		}
	}
}

function removeScript(contentAsHtml){
	var startIdx;
	var endIdx;
	var scriptContent;
	//alert(contentAsHtml);
	startIdx = contentAsHtml.indexOf("<script");
	endIdx = contentAsHtml.indexOf("</script>");
	if (startIdx >=0 && endIdx >=0)
	{
		//alert(startIdx);
		//alert(endIdx);
		endIdx += 9;
		contentAsHtml = contentAsHtml.substring(endIdx);
	}
	return contentAsHtml;
}


function replaceComponent(componentId, componentTag, xhr)
{
	var resopnseHTML = null;
	elm = document.getElementById(componentId);
//alert(elm);
	if (elm)
	{
//alert("component content = " + getComponentContent(componentId, componentTag, 'toString', xhr));
//alert("component content = " + getComponentContent(componentId, componentTag, 'toString', xhr).innerHTML);
//alert(elm.outerHTML);
//alert(elm.innerHTML);
//elm.innerHTML = null;
//responseHTML = getComponentContent(componentId, componentTag, null, xhr);
//alert(getComponentContent(componentId, componentTag, null, xhr));
//document.getElementById("testtext").value = getComponentContent(componentId, componentTag, null, xhr);
//var contentScript = document.getElementsByTagName("script");
//for (var i = 0;i<contentScript.length;i++)
//{
//	contentScript[i].parentNode.removeChild(contentScript[i]);
//}

/*
var scripts = elm.getElementsByTagName("script");
if (scripts != null){
	for (var i=0;i<scripts.length;i++){
		scripts[i].outerHTML = null;
	}
}
*/

var parentNode = elm.parentNode;
//alert("script = " + getComponentContent(componentId, componentTag, "script", xhr));
//alert("outerHTML = " + elm.outerHTML);
//alert("component = " + getComponentContent(componentId, componentTag, null, xhr));
//if (parentNode != null)
//	parentNode.innerHTML = getComponentContent(componentId, componentTag, null, xhr); 

//alert (componentTag == "table")
//	alert(getComponentContent(componentId, componentTag, null, xhr));

//alert("outerHTML = " + getComponentContent(componentId, componentTag, null, xhr));
elm.outerHTML = getComponentContent(componentId, componentTag, null, xhr); 


/*
if (document.getElementById("orderTicketForm:testText"))
{
	if (componentId == "orderTicketForm:ticketPanel")
{
	alert(document.getElementById("orderTicketForm:testText").value);
		//document.getElementById("orderTicketForm:testText").value = getComponentContent(componentId, componentTag, null, xhr);
		document.getElementById("orderTicketForm:testText").value = xhr.responseText;
}
}
*/
//document.getElementById("testtext").value = resopnseHTML;
//alert(elm.outerHTML);
		//documentAppend(getComponentContent(componentId, componentTag, 'toString', xhr), componentId);
		//updateScript(xhr);	//FOR IE

	}
}


function updateComponentAttribute(componentId, componentTag, attribute)
{
	var newValue = getComponentContent(componentId, componentTag, attribute, xhr);
//alert(newValue);
	elm = document.getElementById(componentId);
//alert("before " + componentId + " , " + elm.className);
	if (elm)
	{
		
		if (attribute=="class")
		{
			elm.setAttribute("className", newValue);
			elm.className = newValue;
		}
		else if (attribute=="innerHTML")
			elm.innerHTML = newValue;
		else
			elm.setAttribute(attribute, newValue);
	}
//alert("after " + componentId + " , " + elm.className);
}


function documentAppend(eleText,eleTag) {
	var fname="documentAppend()";
	if ( this.debug ) { 
		alert( fname + "\n\n eleTag=" + eleTag + "\n\n eleText=" + eleText );
	}
	try {
		// sanity check
		if ( eleText==undefined || !eleText ){
			eleText=" ";
		} //  
		// note: W3C rules state that the p tag doesn't allow any block-level tags within it, and both LI and UL are block level tags, so lets use a <div> instead of a <p> 
		if ( eleTag==undefined || !eleTag ){
			eleTag="div";
		}
		// create and populate the new element
		var theNewEle = document.createElement(eleTag);
		// NOTE: want to preserve embedded HTML Tags that are embedded into the eleText. createTextNode() does not do this.
		//var theNewEleText = document.createTextNode(eleText);
		//theNewEle.appendChild(theNewEleText);
		theNewEle.innerHTML = eleText; 
		
		// append the new element to the end of the document
		document.body.appendChild(theNewEle);
	}
	catch(ex)
	{
		alert(fname + "\n\n Error occured: " + ex.message); 
	}
}

function xmlencode(string) {
    return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;')
        .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
}



innerHTML = function(el){
	var array = [];
	for(var i=0,c;c=el.childNodes[i++];){
		array.push(outerHTML(c))
	}
	return array.join("");
}

if(document.defaultView){
	outerHTML = function(node){
		//return new XMLSerializer().serializeToString(node).replace(xdoc.root(node).namespaceURI,"")
		return new XMLSerializer().serializeToString(node);
	}

	innerHTML = function(node){
		var s = outerHTML(node),
		re = new RegExp('<('+node.nodeName+')(?=\\s|>)[^>]*?>([\\s\\S]*?)<\\/\\1>', 'g');
		return re.exec(s)[2]
	}
}


/*
function dpf(f) {
	var adp = f.adp;
	if (adp != null) {
		for (var i = 0;i < adp.length;i++) {
			f.removeChild(adp[i]);
		}
	}
};


function apf(f, pvp) {
	var adp = new Array();
	f.adp = adp;
	var i = 0;
	for (k in pvp) {
		var p = document.createElement("input");
		p.type = "hidden";		
		p.name = k;
		p.value = pvp[k];
		f.appendChild(p);
		adp[i++] = p;
	}
};

function jsfcljs(f, pvp, t) {
	apf(f, pvp);
	var ft = f.target;
	if (t) {
		f.target = t;
	}
	f.submit();
	f.target = ft;
	dpf(f);
};



if(window.HTMLElement) {
	Object.defineProperty(
		HTMLElement.prototype,
		'outerHTML',
		{
			set:function(sHTML){
			        var r=this.ownerDocument.createRange();
			        r.setStartBefore(this);
			        var df=r.createContextualFragment(sHTML);
			        this.parentNode.replaceChild(df,this);
			        return sHTML;
			},
			get:function(){
				var attr;
			        var attrs=this.attributes;
			        var str="<"+this.tagName.toLowerCase();
			        for(var i=0;i<attrs.length;i++){
					attr=attrs[i];
				if(attr.specified)
					str+=" "+attr.name+'="'+attr.value+'"';
				}
				if(!this.canHaveChildren)
					return str+">";
				return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";				
			}
		}
	);

	Object.defineProperty(
		HTMLElement.prototype,
		'canHaveChildren',
		{
			get:function(){
				switch(this.tagName.toLowerCase()){
					case "area":
					case "base":
					case "basefont":
					case "col":
					case "frame":
					case "hr":
					case "img":
					case "br":
					case "input":
					case "isindex":
					case "link":
					case "meta":
					case "param":
					return false;
				}
				return true;
			}
		}
	);

}
*/
/*
if(window.HTMLElement) {
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
        var r=this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df=r.createContextualFragment(sHTML);
        this.parentNode.replaceChild(df,this);
        return sHTML;
        });

    HTMLElement.prototype.__defineGetter__("outerHTML",function(){
     var attr;
        var attrs=this.attributes;
        var str="<"+this.tagName.toLowerCase();
        for(var i=0;i<attrs.length;i++){
            attr=attrs[i];
            if(attr.specified)
                str+=" "+attr.name+'="'+attr.value+'"';
            }
        if(!this.canHaveChildren)
            return str+">";
        return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
        });
        
 HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
  switch(this.tagName.toLowerCase()){
            case "area":
            case "base":
         case "basefont":
            case "col":
            case "frame":
            case "hr":
            case "img":
            case "br":
            case "input":
            case "isindex":
            case "link":
            case "meta":
            case "param":
            return false;
        }
        return true;

     });
}
*/
/*
function getFirstChildElementXMLContent(componentId, tagName, attribute, dummyHolderDivId){
	var contentAsHtml = getComponentContent(componentId, tagName, attribute, true);
//alert("content as html = " + contentAsHtml);
	var element = document.getElementById(dummyHolderDivId);
	if(element){
		element.innerHTML = contentAsHtml;
		if(element.firstChild){
			contentAsHtml = element.firstChild.innerHTML;
		}
		element.innerHTML = "";
	}
	return contentAsHtml;
}
*/

	var fnXMLHttpCallback = null;
	var urlRedirect;

	function checkSession(jsObj, url){
		urlRedirect = url + "";
		AJAXSubmit(null, this,'/its/secure/quote/checkRTQAuth.jsp', null, null, null, checkSessionCallBack);
	}

	function checkSessionCallBack(xhr){
//alert("xhr = " + xhr.getHttpRequestImpl().responseText);
		if(xhr.getHttpRequestImpl().responseText!="Y")
		{
			//Force logout from CAS
			redirectURL(urlRedirect);
			return false;
		}
	}

	function redirectURL(url){
		url = url + "";
		if (url.indexOf("secure/account")>=0)  
			window.top.location="/login.jsf?service=%2Fits%2Fsecure%2Faccount%2FmyCashPosition.jsf";
		else if (url.indexOf("secure/trade")>=0 || url.indexOf("snapshotQuoteFacelet")>=0 )
			window.top.location="/login.jsf?service=%2Fits%2Fsecure%2Ftrade%2FmyTradeBook.jsf";
		else if (url.indexOf("pageId=436")>=0)
			window.top.location="/its/express/news/news.jsf?pageId=436&amp;code=1";
		else if (url.indexOf("secure/quote")>=0)	
		{
			//close popup window and redirect the main widow to login page if it is realtime quote page
			if (window.opener)
			{
				window.opener.location="/login.jsf?service=/its/secure/quote/realTimeZone.jsf";
				window.opener.focus();
			}
			if (window.top.opener)
			{
				window.top.location="/login.jsf?service=/its/secure/quote/realTimeZone.jsf";
				window.top.focus();
				return false;
			}
			if (window.top)
				window.top.close();
			else
				self.close();
		}

	}
	
	//from igf_core.js
	function replaceNode(node1, node2) {
		var parent = node1.parentNode;
		if (typeof parent != "undefined" && parent!=null) {
			return parent.replaceChild(node2, node1);
		}
	}
	//from igf_core.js
	function deleteNode(node) {
		if (typeof node != "undefined" && node != null) {
			// remove the node from its parent if applicable
			var parent = node.parentNode;
			if (typeof parent != "undefined" && parent != null) {
				parent.removeChild(node);		
			}
			node = null;
		}
	}
	//from igf_core.js
	function parseHtml(toParse, appendToDocument) {
		// first off, create a div
		var aDiv = document.createElement("div");
		// we DO need to append this node to the document
		// as it forces the browser to evaluate css style and javascript 
		// that may be contained in the html 
		if (appendToDocument!==false) {
			document.body.appendChild(aDiv);
		}
		// now set the innerHTML of the div with the text passed in
		aDiv.innerHTML = toParse;
		return aDiv;
	}

	// ====================================================
	//
	// 				IgUri Class
	//
	// ====================================================
	//	Class to deal with Uri
	// ====================================================
	function IgUri(uri) {
		this.baseUri = null;
		this.query = "";
			
		// ====================================================
		// Add parameter
		// ====================================================
		//	argument:
		// 		name: name of the parameter
		//		value: value of the parameter
		// ====================================================
		this.addParameter = function(name, value) {
			if (NaES(name)) {
				if (NaES(this.query)) {
				 	if (this.query.charAt(this.query.length-1)!='&') {
				 		this.query = this.query + "&";				 	}
				 }
				 else {
					this.query = "";
				}				
				this.query = this.query + encodeURIComponent(name) + "=" + encodeURIComponent(value);
			}
		};
		
		// ====================================================
		// Parse the uri passed-in and get the uri part (up to the query)
		// and the query section (from the ? til the end)
		// ====================================================
		//	argument:
		//		uri: the uri to parse
		// ====================================================
		this.parseUri = function(uri) {
			if (NaES(uri)) {
				var i = uri.indexOf("?");
				if (i!=-1) {
					this.baseUri = uri.substring(0, i);				
					this.query = uri.substr(i+1);				
				}
				else {
					this.baseUri = uri;
					this.query = null;
				}
			}
		};
				
		// ====================================================
		// Convert this object to a string
		// ====================================================
		//	argument:
		// ====================================================
		this.toString = function() {
			return (NaES(this.query)) 
				? this.query
				//? this.baseUri + "?" + this.query 
				: this.baseUri;
		};
		
		// parse the uri 
		this.parseUri(uri);		
	}
	function NaES(str1) {
		return ((typeof str1=="string") && (typeof str1.length != "undefined" && str1.length != null) && str1.length > 0) ? true : false;
	}
	function getElementById(id) {
		var r = null;
	  	if(typeof(id)!="string") {
	  		r = id;
		}
		else if(NaES(id) && document.getElementById) {
			r = document.getElementById(id);
		}
		return r;
	}
	function isArray (arg) {	
	    	return ((arg && typeof arg == 'object') || (typeof arg == 'function')) && arg.length;
	}
	function isNull(v) {
		return (typeof v == 'object' && !v) || (typeof v == 'undefined');
	}
	function replaceNode(node1, node2) {
		var parent = node1.parentNode;
		if (!isNull(parent)) {
			return parent.replaceChild(node2, node1);
		}
	}

	function findDescendant(e, attrn, attrv, tag) {
		var nodes = [];
		var result = null;
		e = getElementById(e);
		// start by the first child of the node
		if (!isNull(e)) {
			if (isNull(tag)) {
				nodes = e.childNodes;
			}
			else {
				nodes = e.getElementsByTagName(tag);			
			}
		}

		if (isArray(nodes)) {
			for (var i=0; i<nodes.length; i++) {
				var node = nodes[i];
				// the current node matches the tagname. good start
				if (isNull(tag) || (!isNull(tag) && (node.nodeName.toLowerCase()==tag.toLowerCase()))) { 
					// the attribute has to match a specific value
					if (isNull(attrn)) {
						result = node;
						break;
					}
					if (!isNull(attrn) && isNull(attrv) && NaES(getAttribute(node, attrn))) {
						result = node;
						break;
					}
					if (!isNull(attrn) && !isNull(attrv) && (getAttribute(node, attrn)==attrv)) {
						result = node;
						break;
					}
					// try to see if there is a match in the child of the current node
					var tmp = findDescendant(node, attrn, attrv, tag);
					if (!isNull(tmp)) {
						result = tmp;
						break;
					}
				}
			}
		}
		return result;
	}

	function executeScript(code) {
		if (NaES(code)) {
			if (window.execScript) {
			    window.execScript(code); // eval in global scope for IE
			} 
			else {
				try{
					window.eval(code);
				}catch(err){}
			}
		}
	}
	function deleteChildren(node){
	
	    if (!isNull(node)) {

	        for(var x = node.childNodes.length - 1; x >= 0; x--){
	            var childNode = node.childNodes[x];
	             if(childNode.hasChildNodes()){
	                deleteChildren(childNode);
	
	            }
	            node.removeChild(childNode);
	               
	            if(childNode.outerHTML){
	
	                childNode.outerHTML = '';
	
	            }
	            childNode=null;   
	
	        }
	        node=null;
	
	    }
	
	}
	function getAttribute(n, attrn) {
		var node = getElementById(n);
		return (node && node.getAttribute)
			? node.getAttribute(attrn)
			: null;
	}




/*
For this script
Visit http://java-scripts.net 
or http://wsabstract.com
*/

var ms = 0;
var state = 0;

function startstop() {
if (state == 0) {
state = 1;
then = new Date();
then.setTime(then.getTime() - ms);
} else {
state = 0;
now = new Date();
ms = now.getTime() - then.getTime();
//document.stpw.time.value = ms;
alert("Total time elapsed: " + (ms/1000) + " sec");
swreset();
   }
}

function swreset() {
state = 0;
ms = 0;
//document.stpw.time.value = ms;
}

function display() {
setTimeout("display();", 50);
if (state == 1)  {now = new Date();
ms = now.getTime() - then.getTime();
document.stpw.time.value = ms;
   }
}



	// ====================================================
	//
	// 				IgPool Class
	//
	// ====================================================
	//	Implements a pool of objects.
	// the public methods are 1) get() which returned an object, and release(obj) which put an object back in the pool 
	// ====================================================
	function IgPool(objectType) {
		// store the type of object we need to create 
		this.objectType = objectType;
		// declare an array to store objects
		this.pool = new Array();
		
		// ====================================================
		// Returns an object from the pool as follow:
		// returning the first available that's already in the pool
		// if none is found, then instantiate an object, lock it and return it
		// ====================================================
		//	argument:
		// ====================================================
		this.get = function() {
			var result = null;
			// first off, try to get an existing httpRequest from the pool
			for (i=0; i<this.pool.length; i++) {
				var anObject = this.pool[i];
				if (!isNull(anObject)) {
					if (anObject.infragisticsPool_isBusy === false) {
					// we found an object that is available
						result = anObject;
						break;
					}
				} 
			}
			if (isNull(result)) {
			// couldn't find one in the pool, so create a new one
				result = new this.objectType;
				// add the newly created element to the pool
				this.pool[this.pool.length] = result;
			}
			if (!isNull(result)) {
			// finally, "lock" the context so no one else can use it
				result.infragisticsPool_isBusy = true;
			}
			return result;
		};	
	
		// ====================================================
		// Release an object and pout in bac k inthe pool
		// ====================================================
		//	argument:
		// 		obj: the object to release
		// ====================================================
		this.release = function(obj) {
			// locate the object in the pool
			for (i=0; i<httprequestpool.pool.length; i++) {
				var anObject = httprequestpool.pool[i];
				if (anObject == obj) {
				// we found the object
				// reset the flag and mark is at "not busy"	
					anObject.infragisticsPool_isBusy = false;
					return;
				} 
			}
		};		
	};



	// ====================================================
	//
	// 				IgHttpRequest Class
	//
	// ====================================================
	//	Class to communicate with the server over http, support:
	//  synchronous and asynchronous POST requests
	// ====================================================
	function IgHttpRequest() {
		// store the real implementation of the XMLHttpRequest object
		this.httpRequestImpl = null;
		this.sourceOfRequest = null;
		this.loadedScripts = [];
		
		// ====================================================
		// Instantiate the underlying XmlHttpRequest Object depending 
		// upon the current browser
		// ====================================================
		//	argument:
		// ====================================================
		this.getHttpRequestImpl = function() {
			if (isNull(this.httpRequestImpl)) { 
			// this is the first the send method is invoked, 
			// we now need to create the underlying XmlHttpObject
				if( window.XMLHttpRequest ) {
				// mozilla based browsers
					this.httpRequestImpl = new XMLHttpRequest();
				}
				else if( window.ActiveXObject ) {
				// MS browsers
					// there are various version of the HttpRequest, try to get the newer one 
					var MSXML_VERSIONS = new Array(
					    'MSXML2.XMLHTTP.5.0',
					    'MSXML2.XMLHTTP.4.0',
					    'MSXML2.XMLHTTP.3.0',
					    'MSXML2.XMLHTTP',
					    'Microsoft.XMLHTTP'
					);
			
					for (var i=0;i < MSXML_VERSIONS.length; i++) {
					    try {
					        this.httpRequestImpl = new ActiveXObject(MSXML_VERSIONS[i]);
					        break;
					    } catch (e) {}
					}
				}	
			}
			return this.httpRequestImpl;
		};
	
		// ====================================================
		// Returns the response that has been received from the server
		// as an xml document
		// ====================================================
		//	argument:
		// ====================================================

		this.getRespXml = function() {
		
			// Portals support
			var xmlDoc;
			var xmlText;
			if (isNull(this.httpRequestImpl.responseXML) && !isNull(this.httpRequestImpl.responseText)
			|| (!isNull(this.httpRequestImpl.responseXML) && this.httpRequestImpl.responseXML.documentElement==null))
			{
			    var endIdx = this.httpRequestImpl.responseText.indexOf("</fragments>");
			    xmlText = this.httpRequestImpl.responseText.substring(0, endIdx)+"</fragments>";
			}
			// the response coming from the portals is XML, but since the content-type is not XML, our responseXML property
			// is null in Firefox, and not null in IE (in IE the documentElement of the responseXML is null)
			// therefore we need to parse/feed the xml text into a DOM object 
			if (isNull(this.httpRequestImpl.responseXML) && !isNull(this.httpRequestImpl.responseText))
			{
				xmlDoc = (new DOMParser()).parseFromString(xmlText, 'text/xml');
				return xmlDoc;

			} else if (!isNull(this.httpRequestImpl.responseXML) && this.httpRequestImpl.responseXML.documentElement==null) {

				if (window.ActiveXObject) {
					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.async="false";
					xmlDoc.loadXML(xmlText);

					return xmlDoc;
				}							
			}
			// in all other cases we have a standard non-portal response
			return (!isNull(this.httpRequestImpl)) ? this.httpRequestImpl.responseXML : null;
		};


		// ====================================================
		// Submit the RPC request to the server-side
		// ====================================================
		//	argument:
		//	url: the url to call
		// 	params: parameters to send as is to the server side (proper escaping must be done by the caller)
		// 	callback: name of the function to callback whenever we get the response from the server
		// sourceOfRequest: the component that originated this request
		// ====================================================
/*
		this.send2 = function(url, params, callback, sourceOfRequest, formId) {
			//Only check session timeout if page under 'secure' directory
//			if (url.indexOf("secure") >= 0)
//				checkSession(this, url);
			this.sourceOfRequest = sourceOfRequest;
			
			// this is needed for the WebSphere Single Portlet Refresh
			// we cannot use the original URL because it will make all portlets to be rendered 
			// we need to lookup the single portlet URL for the current portlet and 
			// send the request to it instead 
			var compNs;
			
			if (formId.indexOf("viewns")!= -1) {
			    compNs = formId.substring(6, formId.length);
			    // also remove the actual form identifier
			    var formIdidx = compNs.indexOf(":");
			    compNs = compNs.substring(0, formIdidx);
			}
			
			var singleRefreshUrl = document.getElementById("igUrlns"+compNs);
		    if (!isNull(singleRefreshUrl))
		    {
		    	// singleRefreshUrl is a hidden input element
		        url = singleRefreshUrl.value;
		    }
			
			// this is the first the send method is invoked, 
			// we now need to instanctiate the XmlHttpRequest object
			var httpReq = this.getHttpRequestImpl();
			var myself = this;
			
			if (!isNull(httpReq)) {
	
				// sets the cursor to look like an hourglass
				var srcComp = ig.getUIElementById(sourceOfRequest);
				if (!isNull(srcComp)) {
					srcComp.setCursor("wait");
				}
				
				
				var poundSign = url.indexOf("#");
				if (poundSign != -1) {
				    url = url.substring(0,poundSign);
				}
				
				// for now we only care about POST request
				httpReq.open("POST", url, true);
				// we MUST set the content type
				//httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
				httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 

	
		        // use an anonymous function to know when the result is received
		        httpReq.onreadystatechange = function() {
		            if (httpReq.readyState == 4) {
//alert("length = " + httpReq.responseText.length);
				//Begin: Added by Raymond		16 Apr 2010

				checkResponseText(url, this, httpReq, httpReq.responseText);
//alert(httpReq.responseText);
				//End: Added by Raymond			16 Apr 2010

		            	// we finally got the result form the server
						// AJAX CSOM
						var jsNode = ig.getUIElementById(sourceOfRequest);
						if (jsNode) {
							// checking if the "igfcid" attribute is present
							// it is used by the pager to specify the element (grid) on which the event sould be raised
							var targetElementID = ig.getAttribute(jsNode.elm, ig.PROP_FOR_COMPONENT);
//alert(targetElementID);
							if (targetElementID) {
								var tmpNode = ig.getUIElementById(targetElementID);
								if (tmpNode && !tmpNode.getParentComponent) {
									tmpNode = Sys.Application.findComponent(targetElementID);
								}
								if (tmpNode) jsNode = tmpNode;
							}
							// find the first parent that can raise events
							while (jsNode && !isNull(jsNode._raiseClientEvent) && !jsNode._raiseClientEvent) {
								jsNode = jsNode.getParentComponent();
							}
							if (jsNode && jsNode._raiseClientEvent) {
								jsNode._raiseClientEvent("AjaxResponseCompleted", "Ajax", null, null);
							}
						}
		            	// we now need to call the callback function
						ig.onPartialRefresh (myself, callback);
						if (!isNull(srcComp)) {
							srcComp.setCursor("");
						}					
		            }
		        };
				// send the request to the server
				httpReq.send(params);	
			}
		};
*/
		// ====================================================
		// Returns the component that is the source of the request
		// ====================================================
		//	argument:
		// ====================================================
		this.getSourceOfRequest = function() {
			return this.sourceOfRequest;
		};





		this.submitRequest = function(jsObj, formObj, url,formId, submitObj, refreshObj, fn, addParam){
			var xhr=null;
			var submittedForm=null;
			var nav_fnXMLHttpCallback = null;
			if (typeof formId != 'undefined' && formId != null)
				submittedForm = eval("document." + formId);
			var dataString = "";
			//Add submit obj to parameter
			if (typeof formId != 'undefined' && formId != null && typeof submitObj != 'undefined' && submitObj != null)
			{
				dpf(document.getElementById(formId));
				apf(document.getElementById(formId),submitObj);
			}
			if(typeof(fn)=='function') nav_fnXMLHttpCallback = fn; else nav_fnXMLHttpCallback = null;
			//getXMLHttp();
			//xhr = nav_getXMLHttp(null);
			var xhr = this.getHttpRequestImpl();
			var myself = this;
//			xhr.open("POST", url, (typeof(fn)=='function' ? true : false) );
			xhr.open("POST", url, true );
			xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
//			if(typeof(fn) != 'undefined' && typeof(fn)=='function') 
//			{
				//xhr.onreadystatechange = nav_xmlHttpResponse; 
				xhr.onreadystatechange = function(){
					if(xhr.readyState == 4){
//	alert(xhr.responseText.substring(10000,xhr.responseText.length));
						checkResponseText(url+"", xhr);
						updateScript(myself);
						updateViewState(formId, myself);
						myself.nav_xmlHttpResponse(formId, nav_fnXMLHttpCallback, myself);
						httprequestpool.release(myself);

					}
				}
//			}
//			else 
//			{
//				xhr.onreadystatechange = null;
//				//Remove submitted object from form
//				if (typeof dpf!='undefined' && dpf && document.getElementById(formId))
//					dpf(document.getElementById(formId));
//			}
			if (submittedForm != null){
				//xhr.send(dataString);


//alert("form = " + document.getElementById(formId).name);
					var params = formToUri(document.getElementById(formId));
					var cse = jsObj + "::" + "" + "::" + "";
					if (typeof addParam != 'undefined' && addParam != null)
						cse = addParam;
					params.addParameter("com.infragistics.faces.CLIENT_SIDE_EVENT", cse);	
					params.addParameter("com.infragistics.faces.SMART_REFRESH_COMPONENTS", refreshObj);
					// fix for sun implementation 1.1.02
					params.addParameter("com.sun.faces.FORM_CLIENT_ID_ATTR", formId);
//alert(params.query);
					xhr.send(params.query);

				//xhr.send(getFormData(submittedForm, submitObj, refreshObj));
			}
			else
				xhr.send();
			//if(typeof(fn)!='function') return xhr.responseText.trim();
		};

		this.nav_xmlHttpResponse = function(formId, nav_fnXMLHttpCallback, xhr){
			//if(nav_fnXMLHttpCallback && xhr.readyState == 4) {
			//alert(xhr.responseText);
			//alert(getComponentContent("javax.faces.ViewState","input","value"));
			if(nav_fnXMLHttpCallback) {
				//if (typeof dpf!='undefined' && dpf)
				//{
				//	if (document.getElementById(formId)){
				//		Remove submitted object from form
				//		dpf(document.getElementById(formId));
				//	}
				//}
				nav_fnXMLHttpCallback(xhr);
			}
		};







	this.loadScript = function(src) {
		if (NaES(src)) {
			// get the scripts already installed
			// load the script ONLY if it's not already done so
			if (!this.isScriptLoaded(src)) {				
				// dynamically load the content of the javascript file from the server side via the XmlHttpRequest Object
			  	var oxmlhttp = null;
			    try { 
			    	oxmlhttp = new XMLHttpRequest();
			        oxmlhttp.overrideMimeType("text/xml");
			   	}
			    catch(e) { 
			    	try { 
			    		oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			        }
			        catch(e) {
			        	return null;
			     	}
			 	}
			    if(!oxmlhttp) {
			    	return null;
			    }
			    try {
			    	oxmlhttp.open("GET",src,false);
			    	oxmlhttp.send(null);
			    }
			    catch(e) {
			    	return null;
			    }
			    var code = oxmlhttp.responseText;
				loadedScripts.push(src);
				executeScript(code);
			}				
		}
	};

	this.isScriptLoaded = function(src) {
		var result = false;
		if (NaES(src)) {
			var scripts = document.getElementsByTagName("script");
			if (isArray(scripts)) {
				for (var i=0; i<scripts.length; i++) {
					if (scripts[i].src==src) {
						result = true;
						break;
					}
				}				
			}
			if (!result) {
				for (var j=0; j<loadedScripts.length; j++) {
					if (loadedScripts[j]==src) {
						result = true;
						break;
					}
				}									
			}
		}
		return result;
	};





	};

	httprequestpool = new IgPool(IgHttpRequest);
