NS4 = document.layers;
IE4 = document.all;
ver4 = (NS4 || IE4);
IE5 = (navigator.userAgent.indexOf("MSIE 5.")!=-1);
IE5UP = (IE5 && navigator.userAgent.indexOf("MSIE 5.0")==-1);
IE6 = (navigator.userAgent.indexOf("MSIE 6.")!=-1);
IE7 = (navigator.userAgent.indexOf("MSIE 7.")!=-1);
NS6 = (navigator.userAgent.indexOf("Netscape6")!=-1);
NS7 = (navigator.userAgent.indexOf("Netscape/7")!=-1);
FF = (navigator.userAgent.indexOf("Firefox")!=-1);
MZ5 = (navigator.userAgent.indexOf("Mozilla/5")!=-1);
isDOM = NS7 || FF || IE5UP || IE6 || IE7 || MZ5;
isOpera=(document.addEventListener && document.attachEvent);
isSafari=isSafariBug();

//selectBoxLayers = new Array(); 	// This contains a list of select box layers. Dynamic HTML such as hiermenus
				 // can use this to turn them invisible if necessary
function captureEnter(action,args,ev){
	if(! ev) ev = window.event;
	var keyPressed = null;
	if (ev.which) keyPressed = ev.which;
	else if (ev.keyCode) keyPressed = ev.keyCode;
	if (keyPressed == 13){
		action.apply(null,args);
	}
	return false;
}

function setDomain(){
	arrayOfStrings=document.domain.split(".");
	if(arrayOfStrings.length>=3){
		var newDomain='';
		for(var i=1;i<arrayOfStrings.length; i++){
			newDomain+=arrayOfStrings[i];
			if(i+1!=arrayOfStrings.length)
				newDomain+=".";
		}
		document.domain=newDomain;
	}
}

function contains(arry, value){
	var l=arry.length;
	for(var i=0;i<l;i++){
		if(arry[i]==value){
			return true;
		}
	}
	return false;
}

var AFSJSNameValues; // Global array

function processNameValues(){
	var docURL = document.URL;
	var varString = docURL.substring(docURL.indexOf('?')+1,docURL.length);
	var varArray = varString.split('&');
	AFSJSNameValues = new Array();
	for (y=0;y<varArray.length;y++) {
		AFSJSNameValues[y] = new Array();
		AFSJSNameValues[y] = varArray[y].split('=');
	}
	return AFSJSNameValues;
}


// Good for query strings only
function getNameValue(thisName){
	if(typeof(AFSJSNameValues)=="undefined"){
		processNameValues();
	}
	var l=AFSJSNameValues.length;
	for(var i=0;i<l;i++){
		if(AFSJSNameValues[i][0]==thisName){
			if(typeof(AFSJSNameValues[i][1])=="undefined") return "";
			return AFSJSNameValues[i][1];
		}
	}

	return "";
}

function splitNameValues(varString){
	var varArray = varString.split('&');
	var nameValues = new Array();
	for (y=0;y<varArray.length;y++) {
		var temp = varArray[y].split('=');
		nameValues[temp[0]]=temp[1];
	}
	return nameValues;
}

function getAllMatchingNameValues(varString, name){
	var varArray = varString.split('&');
	var nameValues = new Array();
	for (y=0;y<varArray.length;y++) {
		var temp = varArray[y].split('=');
		if(temp[0]==name)
			nameValues[nameValues.length]=temp[1];
	}
	return nameValues;
}

function getQueryStringValue(queryString,thisName){
	var pairs=new Array();
	pairs=queryString.split("&");
	for(var i=0;i<pairs.length;i++){
		if(pairs[i].indexOf(thisName+"=")==0)
			return unescape(pairs[i].substr(thisName.length+1));
	}
	return "";
}


function getCommission(_comm){
	if(_comm==""){
		commission="";
	}else if(_comm.substr(0,1)=='S'){
		commission=_comm.substr(1);
	}else if(_comm.substr(0,1)=='*'){
		commission=_comm.substr(1);
	}else if(_comm.indexOf('%')>0){
		var percent=Number(_comm.substr(0,_comm.indexOf('%')));
		if(_comm.substr(_comm.length-1,1)=='O'){
			commission=percent.toString();
		}else{
			if (contains(percent,'-')){
				commission=(Math.abs(percent)).toString();
			}else{
				commission=(0-Math.abs(percent)).toString();
			}
		}
	}else{
		commission=_comm;
	}
	return commission;
}

function getCommissionType(_comm){
	if(_comm==""){
		commissionType="";
	}else if(_comm.substr(0,1)=='S'){
		commissionType="schedule";
	}else if(_comm.substr(0,1)=='*'){
		commissionType="per_share";
	}else if(_comm.indexOf('%')>0){
		var percent=Number(_comm.substr(0,_comm.indexOf('%')));
		if(_comm.substr(_comm.length-1,1)=='O'){
			commissionType="percent_order";
		}else{
			if (contains(percent,'-')){
				commissionType="percent_discount";
			}else{
				commissionType="percent_surcharge";
			}
		}
	}else{
		commissionType="flat";
	}
	return commissionType;
}

function getFormValue(layerName, formName, fieldName){
	if(!document.forms[formName]){
		//alert(formName); // Use this to tell you which form is failing
		return "";
	}
	if(!document.forms[formName][fieldName]){
		//alert(fieldName); // Use this to tell you which field is failing
		return "";
	}
	return document.forms[formName][fieldName].value;
}

function getFormChecked(layerName, formName, fieldName){
	if(!document.forms[formName]){
		//alert(formName); // Use this to tell you which form is failing
		return false;
	}
	if(!document.forms[formName][fieldName]){
		//alert(fieldName); // Use this to tell you which field is failing
		return false;
	}
	return document.forms[formName][fieldName].checked;
}


// Positions any layer at the x/y coordinates specified. Note that the zindex is set to 1
// this is primarily for initialization purposes, but note that if you move a layer with this
// function you may want to adjust the zindex afterwards
function positionLayer(layerName, x, y, _z){
	positionLayerDoc(document, layerName, x, y, _z);
}

function positionLayerDoc(doc, layerName, x, y, _z){
	var argv = positionLayerDoc.arguments;
	var z = argv[4];
	if(!z) z=1;
	if(document.getElementById){
		if(doc.getElementById(layerName)){
			if(y!=null) doc.getElementById(layerName).style.top=y;
			doc.getElementById(layerName).style.left=x;
			doc.getElementById(layerName).style.zIndex=z;
		}
	}else if(doc.all[layerName]){
		if(y!=null) doc.all[layerName].style.top=y;
		doc.all[layerName].style.left=x;
		doc.all[layerName].style.zIndex=z;
	}
}

function showLayer(layerName, _doc){
	var argv = showLayer.arguments;
	var doc = argv[1];
	if(!doc) doc=document;
	if (doc.getElementById) {
		if(doc.getElementById(layerName))
			doc.getElementById(layerName).style.visibility = 'visible';
	}else if(doc.all){
		if(doc.all[layerName])
			doc.all[layerName].style.visibility = 'visible';
	}
}

function hideLayer(layerName, _doc){
	var argv = hideLayer.arguments;
	var doc = argv[1];
	if(!doc) doc=document;
	if (doc.getElementById){
		if(doc.getElementById(layerName))
			doc.getElementById(layerName).style.visibility = 'hidden';
	}else if(doc.all){
		if(doc.all[layerName])
			doc.all[layerName].style.visibility = 'hidden';
	}
}

function displayLayer(layerName, _doc, _displayType){
	var argv = displayLayer.arguments;
	var doc = argv[1];
	if(!doc) doc=document;
	var displayType = argv[2];
	if(!displayType) {
		if(doc.attachEvent && !doc.addEventListener) displayType="block";
		else displayType="table-row";
	}
	if(doc.getElementById){
		if(doc.getElementById(layerName))
			doc.getElementById(layerName).style.display = displayType;
	}else if(doc.all){
		if(doc.all[layerName])
			doc.all[layerName].style.display = displayType;
	}
}


function compactLayer(layerName, _doc){
	var argv = compactLayer.arguments;
	var doc = argv[1];
	if(!doc) doc=document;
	if(doc.getElementById){
		if(doc.getElementById(layerName))
			doc.getElementById(layerName).style.display = 'none';
	}else if(doc.all){
		if(doc.all[layerName])
			doc.all[layerName].style.display = 'none';
	}
}

function changeLayerText(layerName, text){
	changeLayerTextDoc(document, layerName, text);
}

function changeLayerTextDoc(doc, layerName, text){
	if(doc.getElementById){
		if(doc.getElementById(layerName))
			doc.getElementById(layerName).innerHTML=text;
	}else if(doc.all){
		if(doc.all[layerName])
			doc.all[layerName].innerHTML=text;
	}
}

// This function draws a rectangular border. Thickness is an optional argument and will
// default to one pixel if not specified.
function createBorder(x, y, width, height, borderName, thicknessArg){
	var argv = createBorder.arguments;
	var thickness = argv[5];

	if ((thickness == null)||(thickness == ''))
		thickness = 1;

	document.write('<DIV ID="' + borderName + '_top" class="any"><img src="/images/black-pixel.gif" WIDTH="' + width + '" HEIGHT="' + thickness + '"></DIV>');
	document.write('<DIV ID="' + borderName + '_left" class="any"><img src="/images/black-pixel.gif" WIDTH="' + thickness + '" HEIGHT="' + height + '"></DIV>');
	document.write('<DIV ID="' + borderName + '_right" class="any"><img src="/images/black-pixel.gif" WIDTH="' + thickness + '" HEIGHT="' + height + '"></DIV>');
	document.write('<DIV ID="' + borderName + '_bottom" class="any"><img src="/images/black-pixel.gif" WIDTH="' + width + '" HEIGHT="' + thickness + '"></DIV>');
	positionLayer(borderName + "_top",x,y);
	positionLayer(borderName + "_left",x,y);
	positionLayer(borderName + "_right",x+width-thickness,y);
	positionLayer(borderName + "_bottom",x,y+height);
}


// This function will automatically adjust the size of input fields so that they
// approximately match on different browsers

function formSize(size){
	//return (size*1.0)  - ((size1*.0)%1);
	return (size*1.55) - ((size*1.55)%1);
}

// Convenience function sets the selected value for a select box by name. Browsers only
// support setting the select box by number. This is often inconvenient when dynamically
// building select box options.
function setSelectBox(selectBox, value){
	for (var i = 0; i < selectBox.options.length; i++) {
		if (selectBox.options[i].value == value) {
			selectBox.options[i].selected=true;
		}
	}
	return true;
}

function getSelectBoxValue(selectBox){
	for (var i = 0; i < selectBox.length; i++) {
		if(selectBox.options[i].selected==true)
			return selectBox.options[i].value;
	}
	return "";
}

function checkTrailingSpaces(value, field){
	var argv = checkTrailingSpaces.arguments;
	var field = argv[1];

	if(value.length && value.length>0 && (value.charAt(0)==' ' || value.charAt(value.length-1)==' ') ) {
		if(field!=null){
			alert('The \"' + field + '\" field contains leading/trailing spaces,\nprobably due to cutting and pasting. This may result in an error.');
		}else{
			alert('The last field you modified contains leading/trailing spaces,\nprobably due to cutting and pasting. This may result in an error.');
		}
	}
}

// This function will check the previous form entries and return anything entered
// otherwise it will send back the stored value, which is passed in as "evalue".
// If the stored value is absent then the previous form entry will be returned only

function initializeFormElement(eform, ename, evalue) {
	if(session_nv_exists(ename))
		evalue=session_nv_first(ename);

	// get correct form
	for(var i=0;i<document.forms.length;i++) {
		if (document.forms[i].name==eform) break;
	}
	// get correct input item
	var f=document.forms[i].elements[ename];
	if (f.name==ename || !f.name) {
		if (f.type=="select-one" || f.type=="select-multiple") {
				// get correct option
			for(var k=0;k<f.length;k++) {
					if (f.options[k].value==evalue) {
					f.selectedIndex=k;
					break;
				}
				}
		}else if (f.type=="text" || f.type=="password" || f.type=="button" || f.type=="reset" || f.type=="submit" || f.type=="textarea" || f.type=="hidden") {
			f.value=evalue;
		}else if (f.type=="checkbox") {
			if(f.value==evalue){
					f.checked=true;
			}else{
				f.checked=false;
			}
		}else if (f[0].type=="radio") {
			for(var j=0;j<f.length;j++) {
				if(f[j].value==evalue){
						f[j].checked=true;
				}else{
					f[j].checked=false;
				}
			}
		}
	}
}

// ErrorText object is used to store error text that will be displayed in pop up error messages.
function ErrorText(){
	this.text="";
}

function isValidEmail(email, errorText){
	if(email.length==0) return true;

	re=/^([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\@(([A-Z0-9]+[-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i;
	myResult=re.exec(email);
	if (myResult) return true;
	errorText.text="<SPAN CLASS='errorExample'>\"" + email + "\"</SPAN> is not a valid email address.";
	return false;
}

//TODO make the numeric detection work
function isValidPhoneNumber(phone, errorText){
	if(phone.length==0) return true;
	if(phone.length==10) return true;
	//if(phone.length==3) return true; // Hack, if they've filled in 3 digits we'll let it go because it is probably the first three
	//if(phone.length==6) return true; // Likewise for the second 3
	errorText.text="<SPAN CLASS='errorExample'>\"" + phone + "\"</SPAN> is not a valid phone number.";
	return false;
}

function isValidDate(value, errorText){
	if(value.length==0) return true;
	if(value.length==8) return true;
	errorText.text="<SPAN CLASS='errorExample'>\"" + value + "\"</SPAN> is not a valid date.";
	return false;
}

function isValidPassword(password, errorText){
	// Any password is valid
	return true;
}

//TODO make the numeric detection work
function isValidPin(pin, errorText){
	if(pin.length==0) return true;
	if(pin.length==4) return true;
//	if(pin[0]<'0' || pin[0]>'9') return false;
//	if(pin[1]<'0' || pin[1]>'9') return false;
//	if(pin[2]<'0' || pin[2]>'9') return false;
//	if(pin[3]<'0' || pin[3]>'9') return false;
	errorText.text="Pin numbers must be four digits. Only numbers are allowed.";
	return false;
}

function areaCode(phoneNumber){
	if(phoneNumber.length<3) return phoneNumber;
	return phoneNumber.substr(0,3);
}

function prefix(phoneNumber){
	if(phoneNumber.length<4) return "";
	var length=phoneNumber.length-3;
	if(length>3) length=3;
	return phoneNumber.substr(3,length);
}

function suffix(phoneNumber){
	if(phoneNumber.length<7) return "";
	var length=phoneNumber.length-6;
	if(length>4) length=4;
	return phoneNumber.substr(6,length);
}


// You'll need to build the containsError() function for your form. Use an example from a current form as a template.
// We assume that the hidden form is called "hidden_form"

function changeValue(field, value){
	if(typeof(containsError)!="undefined"){
		if(!containsError(field, value)){
			hideErrorLabel();
		}
	}
	document.hidden_form[field].value=value; // We'll store the value of the field in the hidden form
											// even if it is wrong, since our interface allows customers
											// to enter wrong stuff if they *really* want to.
											// This also helps the interface keep track of which fields
											// to display in red.
	return true;
}

// This function creates a button with some standard functionality. It will
// automatically do a gif change on rollover. It assumes that the two source images
// for the gifs are "/buttons/btn_source_on.gif" and "/buttons/btn_source_off.gif"
// where source is the name of the gif. Although less flexible, it cuts down on the
// number of parameters and encourages good directory structure.
//
// buttonAction is the name of the function to call when the button is pressed (without parentheses)
// Note that to get roll-overs to work in Netscape we need to jerryrig by using an anchor that goes nowhere

function createButton(layerName, source, x, y, buttonAction, alt){
	var buttonOn="/images/" + source + ".gif";
	var buttonOff="/images/" + source + ".gif";

	var newText;
	newText='<DIV ID="' + layerName + '" CLASS="any" STYLE="{top:' + y + 'px ; left:' + x + 'px ; }">';
	newText+='<A HREF="javascript:void(0);" onclick="' + buttonAction + '(); return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'' + layerName + '\',\'\',\'' + buttonOn + '\',1)"><IMG SRC="' + buttonOff + '" NAME="' + layerName + '" ALT="' + alt + '" BORDER=0></A>';
	newText+='</DIV>';
	document.write(newText);
}

// This is a generic function for making AFS style tables, that is no borders or padding.
function makeTable(tStyle, tText, tHeight, tWidth){
	var newText;
	newText='<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN="RIGHT" CLASS="' + tStyle + '" HEIGHT="' + tHeight + '" WIDTH="' + tWidth + '">';
	newText+=tText;
	newText+='</TD></TR></TABLE>';
	return newText;
}


// A label (for a field) in the AFS world is nothing more than a table of size 22x200.
function changeLeftLabel(layerName, text, labelClass, width){
	var argv = changeLeftLabel.arguments;
	var width = argv[3];
	if ((width == null)||(width == ''))
	  width=200;

	var newText=makeTable(labelClass, text + "&nbsp;&nbsp;", 22, width);
	changeLayerText(layerName, newText);
}

// Simply initializes a layer for the floating error label
function createFloatingErrorLabel(){
	document.write('<DIV ID="error_label" CLASS="anyHide" style="filter:progid:DXImageTransform.Microsoft.DropShadow(OffX=4, OffY=4, Color=\'grey\', Positive=\'true\');"></DIV>');
}

function createBalancesBox(){
	document.write('<DIV ID="balance_box" CLASS="anyHide"></DIV>');
}

function hideErrorLabel(){
	hideLayer("error_label");
}

// First off we calculate where to put the error label based on the label
// with an error. We rely on other code to figure this out. This function may
// not be flexible enough though since it assumes labels on the left side of
// the screen.
// Note that we reset the zindex to 5 since positionLayer will set it to 1. Why 5? Why not!
// xOffset and yOffset control the relative position that the error label will display
// in, the absolute position being determined on the fly based on the x,y location of the
// label in error itself.

function showErrorLabel(changedLabel, text, argalign, xOffset, yOffset){
	var argv = showErrorLabel.arguments;
	var align = argv[2];
	var xOffset = argv[3];
	var yOffset = argv[4];

	if ((align == null)||(align == ''))
	  align = "CENTER";
	if(xOffset == null) xOffset=450;
	if(yOffset == null) yOffset=-80;

	var x;
	var y;
	if(document.getElementById){
		if(document.getElementById(changedLabel)){
			x=document.getElementById(changedLabel).style.left;
			y=document.getElementById(changedLabel).style.top;
		}
	}
		x=document.all[changedLabel].style.left;
		y=document.all[changedLabel].style.top;
	// Netscape stores as integers while IE stores as strings
	// As an example Netscape stores "38" while IE stores "38px"
	// So we substring out the px part and then evaluate the string
	// to get an integer value when working in IE
	x=parseInt(x);
	y=parseInt(y);
	x+=xOffset;
	y+=yOffset;

/*
	if(!document.all){
		x+=xOffset;
		y+=yOffset;
	}else{
		var i=x.indexOf('p');
		x=x.substr(0, i);
		x=eval(x) + xOffset;

		i=y.indexOf('p');
		y=y.substr(0,i);
		y=eval(y) + yOffset;
	}
*/
	showErrorLabelCoord(x, y, text, argalign);
}

function showErrorLabelCoord(x, y, text, argalign, title, style){

	var argv = showErrorLabelCoord.arguments;
	var align = argv[3];
	if ((align == null)||(align == ''))
		align = "CENTER";

	var title = argv[4];
	if( title==null || title=='' )
		title='ERROR';

	var styleName=argv[5];
	if ((styleName == null)||(styleName == ''))
		styleName = "formerror";

	var newText;
	newText='<TABLE WIDTH=190 BORDER=0 CELLSPACING=0 CELLPADDING=4><TR>';
	newText+='<TD ALIGN="CENTER" CLASS="'+styleName+'">';
	newText+=title;
	newText+='</TD></TR><TR>';
	newText+='<TD ALIGN="' + align + '" WIDTH="190" VALIGN="MIDDLE" CLASS="formerrortext">';
	newText+=text;
	newText+='</TD></TR>';
	newText+='</TABLE>';

	changeLayerText("error_label", newText);
	positionLayer("error_label", x, y);
	if(document.getElementById){
		document.getElementById("error_label").style.zIndex=5;
	}else{
		document.all["error_label"].style.zIndex=5;
	}
	showLayer("error_label");
	hideLayer("success_label");
}

// This makes a standard AFS label 22xWidth and places it on the screen. The sixth argument
// is an optional override style. Otherwise we will use the ".fieldlabel" style
function makeLabel(layerName, x, y, text, width, labelStylePM, height){
   var argv = makeLabel.arguments;
	var labelStyle = argv[5];
	if ((labelStyle == null)||(labelStyle == ''))
	  labelStyle = "fieldlabel";
	var height= argv[6];
	if ((height == null)||(height == ''))
		height=22;

	document.write('<DIV ID="' + layerName + '" CLASS="any" STYLE="{top:' + y + 'px ; left:' + x + 'px ; }">');
	document.write(makeTable(labelStyle, text + "&nbsp;&nbsp;", height, width));
	document.write('</DIV>');
}

// typeOfPadding set to:
// "padToDecimalPlaces" - Always pad out to the number of decimalPlaces
// "noPadding" - Decimal places are exactly as passed in
// "noPaddingUpToDecimalPlaces" - Decimal places are exactly passed in but no greater than decimalPlaces
// "removeZeroDecimalPlaces" - Decimal places are exactly passed in but no greater than decimalPlaces and trailing zeros removed from decimal portion

function formatNumber(exp, decimalPlaces, typeOfPadding, removeComma) {
  if(!typeOfPadding) typeOfPadding="padToDecimalPlaces";
  if(!exp){
	var s="0.";
	for(var i=0;i<decimalPlaces;i++){
		s+="0";
	}
	return s;
  }
  if(exp=="&nbsp;") return exp;
  if(exp=="") return exp;
  var i;
  var parts;
  if(!exp.indexOf)	// if we are already an integer then we'll convert ourselves to a string
	exp=exp.toString();
  if(exp.indexOf('$')!=-1){	// In case we already have a dollar sign we'll remove it and reformat
	exp=exp.substr(1,exp.length-1);
  }
  exp=Math.round(exp*100000000)/100000000;	// Changed by Terry 8/20 to eliminate very small decimal portions
  parts=(exp+'.0').split('.');
  exp='';

  var negative=false;
  var plusWasThere=false;
  if (parts[0].substr(0,1)=='-') {
	parts[0]=parts[0].substr(1);
	negative=true;
  }else if (parts[0].substr(0,1)=='+') {
	parts[0]=parts[0].substr(1);
	plusWasThere=true;
  }
  if (parts[0]=='') {exp+='0'};
  for (i=parts[0].length;i>0;i-=1) {
  	if(!removeComma){
		if (!(i%3) && (i!=parts[0].length)) {exp+=',';}
	}
	exp+=parts[0].charAt(parts[0].length-i);
  }

  if(decimalPlaces>0 && typeOfPadding=="padToDecimalPlaces"){
	exp+='.';
	for(var i=0;i<parts[1].length && i<decimalPlaces;i++)
	  exp+=parts[1].charAt(i);
	for(var i=parts[1].length;i<decimalPlaces;i++)
	  exp+="0";
  }else if(decimalPlaces>0 && typeOfPadding=="noPaddingUpToDecimalPlaces"){
	for(var i=0;i<parts[1].length && i<decimalPlaces;i++){
	  if(i==0) exp+='.';
	  exp+=parts[1].charAt(i);
	}
  }else if(decimalPlaces>0 && typeOfPadding=="removeZeroDecimalPlaces"){
	while(parts[1].substr(parts[1].length-1,1)=="0") parts[1]=parts[1].substr(0,parts[1].length-1);
	if(parts[1]=='.') parts[1]='';
	for(var i=0;i<parts[1].length && i<decimalPlaces;i++){
	  if(i==0) exp+='.';
	  exp+=parts[1].charAt(i);
	}
  }else if(typeOfPadding=="noPadding"){
	for(var i=0;i<parts[1].length;i++){
	  if(i==0) exp+='.';
	  exp+=parts[1].charAt(i);
	}
  }

  if(negative)
	exp="-" + exp;
  if(plusWasThere)
	exp="+" + exp;
  return exp;
}

function QuoteItem(exp) {
  if (exp=='') return '';
  var i;
  var parts;
  exp=exp.toString();
  parts=(exp+'.0').split('.');
  exp='';
  if (parts[0].substr(0,1)=='-') {
	exp+='-';
	parts[0]=parts[0].substr(1);
  }else if (parts[0].substr(0,1)=='+') {
	exp+='+';
	parts[0]=parts[0].substr(1);
  }
  if (parts[0]=='') {exp+='0'};
  for (var i=parts[0].length;i>0;i--) {
	if (!(i%3) && (i!=parts[0].length)) {exp+=',';}
	exp+=parts[0].charAt(parts[0].length-i);
  }

  while (parts[1].length<2) {
	parts[1]=parts[1].concat(0);
  }
  return exp+'.'+parts[1];
}

function Money(exp) {
  if(!exp) return '$ 0.00';
  if(exp=="&nbsp;") return exp;
  if(exp=="") return exp;
  var i;
  var parts;
  if(!exp.indexOf)	// if we are already an integer then we'll convert ourselves to a string
	exp=exp.toString();
  if(exp.indexOf('$')!=-1){	// In case we already have a dollar sign we'll remove it and reformat
	exp=exp.substr(1,exp.length-1);
  }
  exp=Math.round(exp*100)/100;
  parts=(exp+'.0').split('.');
  exp='';

  var negative=false;
  if (parts[0].substr(0,1)=='-') {
	parts[0]=parts[0].substr(1);
	negative=true;
  }
  if (parts[0]=='') {exp+='0'};
  for (var i=parts[0].length;i>0;i-=1) {
	if (!(i%3) && (i!=parts[0].length)) {exp+=',';}
	exp+=parts[0].charAt(parts[0].length-i);
  }
  if (negative) {
	return '($ '+exp+'.'+(parts[1]+'00').substr(0,2) + ')';
  }else{
	return '$ '+exp+'.'+(parts[1]+'00').substr(0,2);
  }
}

function BalanceMoney(exp) {
  if(!exp) return '$ 0.00';
  if(exp=="&nbsp;") return exp;
  if(exp=="") return exp;
  var i;
  var parts;
  if(!exp.indexOf)	// if we are already an integer then we'll convert ourselves to a string
	exp=exp.toString();
  if(exp.indexOf('$')!=-1){	// In case we already have a dollar sign we'll remove it and reformat
	exp=exp.substr(1,exp.length-1);
  }
  exp=Number(exp).toString();
  parts=(exp+'.0').split('.');
  exp='';

  var negative=false;
  if (parts[0].substr(0,1)=='-') {
	parts[0]=parts[0].substr(1);
	negative=true;
  }
  if (parts[0]=='') {exp+='0'};
  for (var i=parts[0].length;i>0;i-=1) {
	if (!(i%3) && (i!=parts[0].length)) {exp+=',';}
	exp+=parts[0].charAt(parts[0].length-i);
  }
  while (parts[1].length<2) {
	parts[1]=parts[1].concat(0);
  }
  if (negative) {
	return '($ '+exp+'.'+parts[1]+')';
  }else{
	return '$ '+exp+'.'+parts[1];
  }
}


function Percentage(exp,precision) {
  if (exp=='') return '';
  var i;
  exp=exp.toString();
  if(exp=='NaN') exp=0;
  exp=Math.round(Number(exp)*Math.pow(10,precision))/Math.pow(10,precision);

  parts=(exp+'.0').split('.');
  exp='';
  if (parts[0].substr(0,1)=='-') {
	exp+='-';
	parts[0]=parts[0].substr(1);
  }
  if (parts[0]=='') {exp+='0'};
  for (var i=parts[0].length;i>0;i-=1) {
	if (!(i%3) && (i!=parts[0].length)) {exp+=',';}
	exp+=parts[0].charAt(parts[0].length-i);
  }
  return  exp +(precision>0?'.':'')+(parts[1]+'00000000').substr(0,precision)+'%';
}

function formatPhoneDashes(phone){
	if(phone=="") return "";
	if(phone.length>10) return phone;
	return '(' + phone.substr(0,3) + ') ' + phone.substr(3,3) + '-' + phone.substr(6,4);
}

function formatSSNDashes(ssn){
	if(ssn=="") return "";
	if(ssn.length>9) return ssn;
	return ssn.substr(0,3) + '-' + ssn.substr(3,2) + '-' + ssn.substr(5,4);
}

function drawMessage(doc, message){
	doc.open();
	doc.writeln('<HTML><BODY>');
	doc.writeln('<link rel="stylesheet" href="/css/contentstyle.css">');
	doc.writeln(message);
	doc.writeln('</BODY></HTML>');
	doc.close();
}

function drawPleaseWait(doc,center){
	if(center) doc.writeln('<CENTER>');
	doc.writeln('<DIV ID="please_wait" style="display:none;"><IMG SRC="/images/loading.gif"></DIV>');
	if(doc!=document) doc.writeln('<SCRIPT>setTimeout("document.getElementById(\'please_wait\').style.display = \'inline\';", 1000);</SCRIPT>');
	else setTimeout("document.getElementById('please_wait').style.display = 'inline';", 1000);
	if(center) doc.writeln('</CENTER>');
}

// If append is true then any symbol chosen by the symbol wizard will be appended. This is used
// for input lines that require multiple symbols separated by spaces. Otherwise the input field
// will be replaced with the symbol selected.

function openSymbolWizard(item, append, securityType) {
	var argv = openSymbolWizard.arguments;
	var securityType = argv[2];
	var url;

	if(securityType==null || typeof(securityType)=="undefined"){
		url="/symbol_wizard/symbol_wizard.html?target_item=" + item.name;
	}else{
		url="/symbol_wizard/symbol_wizard.html?security_type=" + securityType + "&target_item=" + item.name;
	}
	if(append) url+="&append";
	w=window.open(url,'symbol_wizard_frameset','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=450');
	return false;
}

function openTradingSymbolWizard(item, securityType) {
	var argv = openTradingSymbolWizard.arguments;
	var securityType = argv[1];
	var url="/symbol_wizard/symbol_wizard.html?source=trading&target_item=" + item.name;

	if(securityType!=null){
		url+="&security_type=" + securityType;
	}
	w=window.open(url,'symbol_wizard_frameset','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=450');
	return false;
}

// This function assumes that an image of btn_<buttonName>_on.gif and btn_<buttonName>_off.gif exist in the button directory
function drawButton(doc, buttonName, url){
	doc.writeln('<A href="' + url + '" class="linknav" onMouseOut="MM_swapImgRestore()" onmouseover="MM_swapImage(\'' + buttonName + '\',\'\',\'/buttons/btn_' + buttonName + '_on.gif\',1)"><img src="/buttons/btn_' + buttonName + '_off.gif" border="0" name="' + buttonName + '"></a>');
}

function rowClass(row){
	if(row%2>0) return "tableDataOdd";
	return "tableDataEven";
}

// This might be improved in the future by passing in a Param class, but I'm too lazy right now - Terry
function createHTMLPageTitle(doc, pageName, printDate, printTitle, printAccount){
	if(printTitle==null) printTitle=true;
	if(printAccount==null) printAccount=true;
	var s="";
	if(printTitle) s+='<TITLE>'
	s+=pageName;
	if(printAccount && top.left_main_frame.displayedWorkingCustomer!=""){
		s+=' for account: ' + top.left_main_frame.displayedWorkingCustomer;
		s+=' ' + top.left_main_frame.shortName;
	}
	if(typeof(printDate)=="string" && printDate!=""){
		s+=' (as of ' + printDate + ')';
	}else if(typeof(printDate)=="boolean" && printDate){
		if(typeof(system_get_system_date)!="undefined" && system_get_system_date.data.result!="ERROR"){
			var now=new Date(system_get_system_date.data[0].date);
			s+=' (as of ' + formatMMDDYYHHMM(now) + ' ET)';
		}
	}
	if(printTitle) s+='</TITLE>';
	if(doc!=null) doc.writeln(s);
	else return s;
}

function drawTitleLine(title){
	document.writeln('<table width=785 border=0>');
	document.writeln('<tr><td class="pageTitle" align="left" valign="bottom">' + title + '</td></tr>');
	document.writeln('</table><hr>');
}

function createCustomerLink(exp, page, _target){
	var argv = createCustomerLink.arguments;
	var target = argv[2];
	if(target==null) target="";
	else target=" target='" + target + "'";
	return '<A CLASS="customerAnchor" HREF="/cgi/online/ABSSetWorkingCustomer?file=' + page + '&text=' + exp + '&' + session_nv_output() + '" ALT="Enable this customer" onMouseOver="self.status=\'Enable customer ' + exp + '\'; return true" onMouseOut="self.status=\'\'; return true"' + target + '>' + exp + '</A>';
}

function getShortSymbol(symbol) {
  var symbolArray=symbol.split(' ');
  if(symbolArray.length==1) return symbol;
  if (symbolArray[0]=='CUSIP') return 'C.' + symbolArray[1];
  else if (symbolArray[0]=='FIXED') return 'F.' + symbolArray[1];
  else if (symbolArray[0]=='OPTION') return '.' + symbolArray[1];
  else if (symbolArray[0]=='INDICATOR') return '$' + symbolArray[1];
  else if (symbolArray[0]=='INDEX') return '#' + symbolArray[1];
  else if (symbolArray[0]=='EQUITY') {
	if (!symbolArray[2]) return symbolArray[1];
	else if (symbolArray[2]=='PREFERRED') return symbolArray[1]+'p'+(symbolArray[3]?symbolArray[3]:'');
	else if (symbolArray[2]=='CLASS') return symbolArray[1]+'/'+symbolArray[3];
	else if (symbolArray[2]=='WARRANT') return symbolArray[1]+'/WS'+(symbolArray[3]?'/'+symbolArray[3]:'');
	else if (symbolArray[2]=='WHEN_DELIVERED') return symbolArray[1]+'/WI';
	else if (symbolArray[2]=='WHEN_ISSUED') return symbolArray[1]+'w';
	else if (symbolArray[2]=='RIGHTS') return symbolArray[1]+'r';
	else if (symbolArray[2]=='EX_DIVIDEND') return symbolArray[1]+'/XD';
	else if (symbolArray[2]=='EX_RIGHTS') return symbolArray[1]+'/Xr';
	else return symbolArray[1];
  }
  return symbolArray[1];
}

function ConvertToSentence(str){
	if (str!=null|| str!='') return str.substr(0,1).toUpperCase()+str.substr(1).toLowerCase();
}

function iframeHandle(windowLevel,frameName){
	var iframe=windowLevel.document.getElementById(frameName);
	if(!iframe){ //IE4
		return windowLevel.frames[frameName];
	}else if(iframe.contentWindow){//IE5.5+
		return iframe.contentWindow;
	}else if(isSafariBug()){ //Safari
		return windowLevel.frames[frameName];
	}else if(iframe.contentDocument && iframe.contentDocument.defaultView){//NS6+
		return iframe.contentDocument.defaultView;
	}else if(windowLevel.frames && windowLevel.frames[frameName]){//IE5
		return windowLevel.frames[frameName];
	}else{
		return iframe;
	}
}

function iframeDoc(iframeHandle){
	if(iframeHandle.document)   //IE and others
		return iframeHandle.document;
	else   //NS6+
		return iframeHandle.contentDocument;
}

function isSafariBug(){ //take advantage of the bug detection
	var test=true;
	if(test && !document.defaultView) test=false;
	if(test && window.getComputedStyle) test=false;
	//alert(test);
	return test;
}

function getNav(){
	if(typeof(top.globalWindow)=="undefined"){
		return top;
	}else{
		return top.globalWindow;
	}
}

function storeGlobalVariable(name, value){
  var obj=getNav();
  if(obj==null){
	alert("cannot store global variable");
	return;
  }
  obj[name]=value;
}

function getGlobalVariable(name){
  var obj=getNav();
  if(obj==null){
	return "";
  }
  var v=eval("obj." + name);
  rc=v;
  if(typeof(rc)=="undefined") rc=null;
  return rc;
}

// This will display all the properties of the JavaScript object passed in.
function inspectProperties(theObject){
   var theProperties = ""
   for (var i in theObject){
	if(i!="outerText" && i!="innerText" && i!="outerHTML" && i!="innerHTML")
	theProperties +=  i + " = " + theObject[i] + "\t"
   }
   alert(theProperties)
}

function formatMMDDYY(strDate){
   if(strDate=="") return "";
   date = new Date(strDate);
   var da = new Array(  date.getEDTFullYear() , date.getEDTDate(), date.getEDTMonth() )

   var result="";
   for(var i=da.length-1; i>=0; i--){
      if(i<2) result +="/";
      if(da[i]<=9){
         result += "0"+da[i];
      }else if(da[i]<=99){
         result +=da[i];
      }else{
         var tmp=String(da[i]);
         result +=tmp.substr(tmp.length-2,2);
      }
   }
   return result;
}

function formatMMDDYYHHMM(strDate){
   date = new Date(strDate);
   var da = new Array(  date.getEDTMinutes(), date.getEDTHours(), date.getEDTFullYear() , date.getEDTDate(), date.getEDTMonth() )
	var result="";
   for(var i=da.length-1; i>=0; i--){
      switch(i){
      case 2: case 3: result +="/";
      break
      case 1: result+="&nbsp;";
      break
      case 0: result+=":";
      break;
      }
      if(da[i]<=9){
         result += "0"+da[i];
      }else if(da[i]<=99){
         result += da[i];
      }else{
         var tmp=String(da[i]);
         result += tmp.substr(tmp.length-2,2);
      }
   }
   return result;
}
function formatDHHMMSS(seconds){
   var days=seconds/86400;
   seconds=seconds%86400;
   var hours=seconds/3600;
   seconds=seconds%3600;
   var min=seconds/60;
   seconds=seconds%60;
   days=Math.floor(days);
   hours=Math.floor(hours);
   min=Math.floor(min);
   seconds=Math.floor(seconds);
   if(hours<10) hours='0'+hours;
   if(min<10) min='0'+min;
   if(seconds<10) seconds='0'+seconds;

   var result="";
   if(days==1){
	result+=days+" day "+hours+":"+min+":"+seconds;
   }else if (days>1){
	result+=days+" days "+hours+":"+min+":"+seconds;
   }else if(hours>1){
	result+=hours+":"+min+":"+seconds;
   }else {
	result+=min+":"+seconds;
   }
   return result;
}

// private


Date.prototype.calculateEdtEquivilent = function() {
	//apparently this function was created to convert GMT to EST or EDT
	//This functionality is no longer needed as the BOM returns EST.
	//But it is still used in many places, so we have to fix.
	//It will only work if the OS retroactively applies the same DST formula. 
	//If the OS can handle different DST periods in different years (ala Vista),
	//then the function will need to be modified and the commented out lines added in.

   this.edtEquivilent=new Date();
   this.utcEpoch = 0;
   this.edt = false;

   var thisYear, StartDate, EndDate;

   utcEpoch=this.valueOf()
   this.edtEquivilent.setTime(utcEpoch - 18000000) // GMT-5


   thisYear = this.edtEquivilent.getUTCFullYear();

   // is it in the DST area?
   //if(thisYear<2007){
   //	StartMonth = 4;  //April
   //	EndMonth = 10;  //October
   //}else{
   	StartMonth = 3;  //March
   	EndMonth = 11;  //November
   //}

   month= this.edtEquivilent.getUTCMonth()+1;

   if(month<StartMonth || month>EndMonth) return;
   if(month>StartMonth && month<EndMonth) {
	  this.edtEquivilent.setTime(utcEpoch - 14400000) // GMT-4
	  this.edt = true;
	  return;
   }

   //if(thisYear<2007){
   //	StartDate = (2+6 * thisYear - Math.floor (thisYear / 4) ) % 7 + 1;  //First Sunday in April
   //	EndDate=  (31-( Math.floor (thisYear * 5 / 4) + 1) % 7);  //Last Sunday in October
   //}else{
   	StartDate = 14 - ( ( Math.floor (thisYear * 5 / 4) - 6) % 7 );  //Second Sunday in March
   	EndDate = 7 - ( ( Math.floor (thisYear * 5 / 4) + 8) % 7 );  //First Sunday in November
   //}

   todaysDate= this.edtEquivilent.getUTCDate();

   if( (month==StartMonth && todaysDate > StartDate) || (month==EndMonth && todaysDate < EndDate) ){
	this.edtEquivilent.setTime(utcEpoch -  14400000) // GMT-4
	this.edt=true;
	return;
   }
   if( (month==StartMonth && todaysDate < StartDate) || (month==EndMonth && todaysDate > EndDate) ){
	return;
   }

   todaysHour=this.edtEquivilent.getUTCHours();

   if( (month==StartMonth && todaysHour>=2) || (month==EndMonth && todaysHour<1) ){
	this.edtEquivilent.setTime(utcEpoch -  14400000) // GMT-4
	this.edt=true;
	return;
   }
}


// public

Date.prototype.getEDTDate = function (){
   // Returns the day (date) of the month in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCDate()
}
Date.prototype.getEDTDay = function (){
   //Returns the day of the week in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCDay()
}

Date.prototype.getEDTFullYear = function (   ){
   // Returns the year in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCFullYear()
}

Date.prototype.getEDTHours = function (){
   // Returns the hours in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCHours()
}

Date.prototype.getEDTMilliseconds = function (   ){
   // Returns the milliseconds in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCMilliseconds()
}

Date.prototype.getEDTMinutes = function (   ){
   // Returns the minutes in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCMinutes()
}

Date.prototype.getEDTMonth = function (   ){
   // Returns the month according in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCMonth() + 1;
}

Date.prototype.getEDTSeconds = function (   ){
   // Returns the seconds in the specified date according to universal time.
	if( this.valueOf() != this.utcEpoch ){
		this.calculateEdtEquivilent();
	}
	return this.edtEquivilent.getUTCSeconds()
}


Date.prototype.toEDTString = function (){
   // Converts a date to a string, using EST locale's conventions
	if( this.valueOf() != this.utcEpoch ) this.calculateEdtEquivilent();
	time="";
	switch(this.edtEquivilent.getUTCDay()){
		case 0: time="Sun "; break;
		case 1: time="Mon "; break;
		case 2: time="Tue "; break;
		case 3: time="Wed "; break;
		case 4: time="Thu "; break;
		case 5: time="Fri "; break;
		case 6: time="Sat "; break;
	}
	switch(this.edtEquivilent.getUTCMonth()){
		case 0: time+="Jan "; break;
		case 1: time+="Feb "; break;
		case 2: time+="Mar "; break;
		case 3: time+="Apr "; break;
		case 4: time+="May "; break;
		case 5: time+="Jun "; break;
		case 6: time+="Jul "; break;
		case 7: time+="Aug "; break;
		case 8: time+="Sep "; break;
		case 9: time+="Oct "; break;
		case 10: time+="Nov "; break;
		case 11: time+="Dec "; break;
	}
	time+=this.edtEquivilent.getUTCDate();
	time+=" ";
	hours=this.edtEquivilent.getUTCHours();
	minutes=this.edtEquivilent.getUTCMinutes();
	seconds=this.edtEquivilent.getUTCSeconds();

	if(hours<10){
	   time+="0";
	}
	time+=hours;

	time+=":"

	if(minutes<10){
	   time+="0";
	}
	time+=minutes;

	time+=":"


   	if(seconds<10){
   	   time+="0";
   	}
   	time+=seconds;


   	if(this.isDstInEST()){
   	   time+=" EDT ";
   	}else{
   	   time+=" EST ";
   	}
   	time+=this.edtEquivilent.getUTCFullYear();
   	return time;
}

Date.prototype.isDstInEST = function (){
    if( this.valueOf() != this.utcEpoch ) this.calculateEdtEquivilent();
	return this.edt;
}

function formatDateTime(dateVal) {
//e.g. "Thu, 06 Nov 2003 10:00:48 am EST"
	var dateTimeET=new Date(dateVal);
	time=dateVal.substr(dateVal.indexOf(":")-2);
	time=time.replace("EST","ET");
	time=time.substr(0,5)+time.substr(8);
	result=time+" " +(dateTimeET.getMonth()+1)+"/"+dateTimeET.getDate()+"/"+dateTimeET.getFullYear().substr(2);
	return (result);
}
//TODO convert this function to our own
function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function formatDate(dateVal) {
//e.g. "Thu, 06 Nov 2003 10:00:48 am EST"
	var dateTimeET=new Date(dateVal);
	result=(dateTimeET.getMonth()+1)+"/"+dateTimeET.getDate()+"/"+dateTimeET.getFullYear();
	return (result);
}

//used for complex options
function tableCell (data,level,row,align,wrap) {
	if (align=='R') alignment=' ALIGN=RIGHT';
	else if (align=='C') alignment=' ALIGN=CENTER';
	else if (align=='L') alignment=' ALIGN=LEFT';
	if (wrap) alignment+=' NOWRAP';
	if (level=='H') document.writeln('<TD'+alignment+' class="tableHeader">');
	else if (level=='P') document.writeln('<TD'+alignment+' class="mainContent">');
	else if (level=='E') document.writeln('<TD'+alignment+' class="errorMessages">');
	else if (level=='S') document.writeln('<TD'+alignment+' class="tableSubheader">');
	else if (level=='T') document.writeln('<TD'+alignment+' class="tableTotal">');
	else if (level=='R') {
		if (row%2>0) document.writeln('<TD'+alignment+' class="tableDataOdd">');
		else document.writeln('<TD'+alignment+' class="tableDataEven">');
	}
	else if (level=='r') {
		if (row%2>0) document.writeln('<TD'+alignment+' class="tableDataOdd">');
		else document.writeln('<TD'+alignment+' class="tableDataEven">');
	}
	document.writeln(data);
	document.writeln('</TD>');
}

function zoomit(layer, last, doc){
	if(doc==null) doc=document;
	l=doc.getElementById(layer);
	if(last==100) return;
	if(last==-1){
		l.style.visibility="hidden";
		if(navigator.userAgent.indexOf("MSIE")>-1){
			var arr=doc.getElementsByTagName("*");
			for(var i=0;i<arr.length;i++) {
				if(arr[i].getAttribute("hideIfZoom")=="true") arr[i].style.visibility="visible";
			}
		}
		return;
	}
	if(last>0){
		last*=1.3;
	}else{
		last/=1.3;
	}
	if(last>=100) last=100;
	if(last>-1 && last<0) last=-1;
	if(last>0) pct=last;
	else pct=last*-1;
	l.style.zoom=pct + "%";
	//setTimeout("zoomit(\'" + layer + "\', " + last + ")", 1);
	var f = function(){
		zoomit(layer,last,doc);
	}
	setTimeout(f, 1);

}

function zoom(layer, forward, doc){
	if(doc==null) doc=document;
	l=doc.getElementById(layer);
	if(forward>0){
		if(navigator.userAgent.indexOf("MSIE")>-1){
			var arr=doc.getElementsByTagName("*");
			for(var i=0;i<arr.length;i++) {
				if(arr[i].getAttribute("hideIfZoom")=="true") arr[i].style.visibility="hidden";
			}
		}
		l.style.zoom="1%";
		l.style.visibility="visible";
		var f = function(){
			zoomit(layer,1,doc);
		}
		setTimeout(f, 1);
	}else{
		var f = function(){
			zoomit(layer,-100,doc);
		}
		setTimeout(f, 1);
	}
}

function formatODBCDateTime(dtTime) {
	//format the string to YYYYMMDDHHMMSS for transaction grab bag
	var odbcdt="";
	odbcdt=dtTime.replace(/[-:\s]/g,"");
	odbcdt=odbcdt.replace(/\.(\d+)/g,"");
	return(odbcdt);
}


function TitleLineObject(title) {
	this.title=title;
	this.download=isGreen("ALLOW_DOWNLOAD_CUSTOMER_DATA");
	this.print=isNotRed("ALLOW_PRINT_CUSTOMER_DATA");
	this.localPrintFunction=false;
	this.refresh=isNotRed("ALLOW_REFRESH_CUSTOMER_DATA");
	this.downloadUrl="";
	this.doc=null;
	this.padding=false;
	this.url="";
	this.windowToPrint="window";	//Override this to print a different frame
}

function randomNumber(){
	var d=new Date();
	return d.valueOf().toString();
}

function randomizeUrl(url,querystring,targetstring){
	var ret=url+"?nocache="+randomNumber();
	if(querystring!="" && querystring != null) ret+="&"+querystring;
	var command=targetstring+'.location.href="'+ret+'"';

	if(url.match(/open_orders.html/)){
		//manipulate the tab-based menu
		var openOrderTab = iframeHandle(iframeHandle(top,'main_iframe'),'menu_frame').location.href;
		openOrderTab=openOrderTab.substr(0,openOrderTab.indexOf("?"))+"?tab=account_info";
		iframeHandle(iframeHandle(top,'main_iframe'),'menu_frame').location.replace(openOrderTab);
	}

	eval(command);
}

function fillInFormElement(eform, ename, evalue, doc) {
	if(typeof(doc)=="undefined") doc=document;
	// get correct form
	for(var i=0;i<doc.forms.length;i++) {
		if (doc.forms[i].name==eform) break;
	}
	// get correct input item
	var f=doc.forms[i].elements[ename];
	if (f.name==ename || !f.name) {
		if (f.type=="select-one" || f.type=="select-multiple") {
 			    // get correct option
			for(var k=0;k<f.length;k++) {
       				if (f.options[k].value==evalue) {
					f.selectedIndex=k;
					break;
				}
     			}
   		}else if (f.type=="text" || f.type=="password" || f.type=="button" || f.type=="reset" || f.type=="submit" || f.type=="textarea" || f.type=="hidden") {
			f.value=evalue;
   		}else if (f.type=="checkbox" || f.type=="radio") {
			if(f.value==evalue){
    				f.checked=true;
			}else{
				f.checked=false;
			}
  		}else if (f[0].type=="radio") {
			for(var j=0;j<f.length;j++) {
				if(f[j].value==evalue){
	    				f[j].checked=true;
				}else{
					f[j].checked=false;
				}
			}
		}
	}
}


function createFormElement(name,value) {
	document.writeln('<INPUT TYPE="HIDDEN" NAME="'+name+'" VALUE="'+value+'">');
}

function formatAction(nameValue){
	if(session_nv_first(nameValue)=='buy_to_open' || nameValue=='buy_to_open') return 'Buy to Open';
	else if(session_nv_first(nameValue)=='sell_to_open' || nameValue=='sell_to_open') return 'Sell to Open';
	else if(session_nv_first(nameValue)=='buy_to_close' || nameValue=='buy_to_close') return 'Buy to Close';
	else if(session_nv_first(nameValue)=='sell_to_close' || nameValue=='sell_to_close') return 'Sell to Close';
	else if(session_nv_first(nameValue)=='buy' || nameValue=='buy') return 'Buy';
	else if(session_nv_first(nameValue)=='sell' || nameValue=='sell') return 'Sell';
	else if(session_nv_first(nameValue)=='sell_short' || nameValue=='sell_short') return 'Sell Short';
	else if(session_nv_first(nameValue)=='buy_to_cover' || nameValue=='buy_to_cover') return 'Buy to Cover';
	else if(session_nv_first(nameValue)=='switch' || nameValue=='switch') return 'Switch';
}

function refreshOutput(){
	var output="immediate";
	if(!session_get_name_values) return output;
	for (var nv=0;nv<session_get_name_values.data.length;nv++){
		if(session_get_name_values.data[nv].name!="immediate" && session_get_name_values.data[nv].name!="nocache" && session_get_name_values.data[nv].name!="separator" && session_get_name_values.data[nv].name!="quote_character")
			output+="&"+session_get_name_values.data[nv].name+"="+escape(session_get_name_values.data[nv].value);
	}
	return escape(output);
}

function printWindow(windowToPrint){
	w=eval(windowToPrint);
	w.focus();	// To print another frame you have to first set the focus in there
	w.print();
}

function drawTitleLineV2(param){
	if(!param.doc) param.doc=document;
	var doc=param.doc;
	var height="height=27";
	if(param.noPadding==true) height="";

	doc.writeln('<table width="771" border=0 cellpadding=0 cellspacing=0>');
	doc.writeln('	<tr>');
	doc.writeln('		<td width="22"><img src="/images/px1.gif" width="20" height="1"></td>');
	doc.writeln('		<td valign="bottom" ' + height + '><font class="title">&nbsp;' + param.title + '</font></td>');
	if(param.print || param.refresh || param.download){
		doc.writeln('<td align=right>');
	}
	if(param.print){
		if(param.localPrintFunction){
			doc.writeln('&nbsp;&nbsp;&nbsp;<a href="javascript:localPrintFunction(\'' + param.windowToPrint + '\');" onMouseOver="self.status=\'Print\'; return true" onMouseOut="self.status=\'\'; return true"><img style="vertical-align:bottom;" src="/images/print_button.gif" border=0 alt="Print"></a>');
		}else{
			doc.writeln('&nbsp;&nbsp;&nbsp;<a href="javascript:printWindow(' + param.windowToPrint + ');" onMouseOver="self.status=\'Print\'; return true" onMouseOut="self.status=\'\'; return true"><img style="vertical-align:bottom;" src="/images/print_button.gif" border=0 alt="Print"></a>');
		}
	}
	if(param.refresh){
		doc.writeln('&nbsp;&nbsp;&nbsp;<a href="javascript:randomizeUrl(\'' + param.url + '\',\''+refreshOutput()+'\',\'window\');" onMouseOver="self.status=\'Refresh\'; return true" onMouseOut="self.status=\'\'; return true"><img style="vertical-align:bottom;" src="/images/refresh_button.gif" border=0 alt="Refresh"></a>');
	}
	if(param.download){
		doc.writeln('&nbsp;&nbsp;&nbsp;<a href="javascript:randomizeUrl(\'' + param.downloadUrl + '\',\''+refreshOutput()+'\',\'window\');"" onMouseOver="self.status=\'Download\'; return true" onMouseOut="self.status=\'\'; return true"><img style="vertical-align:bottom;" src="/images/download_button.gif" border=0 alt="Download"></a>');
	}
	if(param.print || param.refresh || param.download){
		doc.writeln('</td>');
	}

	doc.writeln('	</tr>');
	doc.writeln('</table>');
	doc.writeln('<table width="771" cellspacing="0" cellpadding="0" border="0">');
	doc.writeln('	<tr>');
	doc.writeln('		<td width="22" height="4"><img src="/images/px1.gif" width="20" height="1"></td>');
	doc.writeln('		<td width="749" height="4"><img src="/images/grad749x4.gif" width="749" height="4"></td>');
	doc.writeln('	</tr>');
	doc.writeln('</table>');
}

function getEntitlementLight(entitlement){
	if(typeof(entitlements_get_entitlement)=="undefined") return "NONE"; // TODO, throw an error
	if(entitlements_get_entitlement.result.result!="OK") return "NONE";
	for(i=0;i<entitlements_get_entitlement.data.length;i++){
		if(entitlements_get_entitlement.data[i].name==entitlement) return entitlements_get_entitlement.data[i].light;
	}
	return "NONE";
}

function isGreen(entitlement){
	var light=getEntitlementLight(entitlement);
	if(light=="GREEN") return true;
	return false;
}

function isNotRed(entitlement){
	var light=getEntitlementLight(entitlement);
	if(light=="RED") return false;
	return true;
}

function tradingAllowedV2(entitlement){
	if(!entitlements_get_trading_status) return false;
	if(entitlements_get_trading_status.result.result!="OK") return false;
	if(entitlement=="EQUITY") entitlement="ALLOW_TRADE_EQUITY";
	if(entitlement=="OPTION") entitlement="ALLOW_TRADE_OPTION";
	if(entitlement=="MUTUAL_FUND") entitlement="ALLOW_TRADE_MUTUAL";
	for(i=0;i<entitlements_get_trading_status.data.length;i++){
		if(entitlements_get_trading_status.data[i].name==entitlement)
			if(entitlements_get_trading_status.data[i].light=="ALLOWED"){
				return true;
			}else{
				return false;
			}
	}
	return false;
}

function showPopupCalendar(){
	var anchor=arguments[0];
	var formField=arguments[1];
	var formt;
	if (arguments[2] == null)
		formt = 'mm/dd/yyyy';
	else
		formt = arguments[2];
	vWinCal = window.open('/calendar.html?anchor='+anchor+'&form_field='+formField+'&date_format='+formt, 'Calendar','width=230,height=180,titlebar=no,status=no,resizable=no,top=100,left=100');
	vWinCal.focus();
	return false;
}

function getStyleFromPage(styleName){
	var ret = null;
	var allStyleSheets = document.styleSheets;
	for (var i = 0; i < allStyleSheets.length; ++i){
	    var rulesList = allStyleSheets[i].rules;
		var rulesLength = rulesList.length;
		for (var r = 0; r < rulesLength; ++r){
			//alert(rulesList[r].selectorText);
		    if (rulesList[r].selectorText == styleName){
				//alert("found")
		        ret = rulesList[r].style;
				break;
			}
		}
		if (ret != null) break;
	}
	return ret;
}

function outputScriptTag(doc, jsname){
	doc.writeln('<script type="text/javascript" language="javascript1.2" src="'+jsname+'"><\/script>');
}


// This function combined with writeBottomFormat() writes a table to the page that is be used to contain page content.
// Table width, top spacing (margin), bottom spacing (margin), border width, and content area can be customized via optional parameters passed to the function.
// if no arguments are passed to the function default perameters are used.

function writeTopFormat(){
	writeTopFormatDoc(document);
}

function writeBottomFormat(){
	writeBottomFormatDoc(document);
}

function writeTopFormatDoc(doc){

	doc.write('<table class="borderTable" width="95%"><tr><td>');

}

function writeBottomFormatDoc(doc)
{

	doc.write('</td></tr></table>');
}

function MM_preloadImages()
{ //v3.0
  var d=document;
  if (d.images)
  {
	if (!d.MM_p)
	  d.MM_p=new Array();
	var i,j = d.MM_p.length, a=MM_preloadImages.arguments;
	for (var i=0; i<a.length; i++)
	  if (a[i].indexOf("#")!=0)
	  {
		d.MM_p[j]=new Image;
		d.MM_p[j++].src=a[i];
	  }
  }
}

function MM_swapImgRestore()
{ //v3.0
  var i,x,a = document.MM_sr;
  for (var i=0; a && i<a.length&&(x=a[i]) && x.oSrc; i++)
	x.src=x.oSrc;
}

function MM_findObj(n, d)
{ //v3.0
  var p,i,x;
  if (!d)
	d = document;
  if ((p=n.indexOf("?"))>0&&parent.frames.length)
  {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if (!(x=d[n]) && d.all)
	x=d.all[n];
  for (var i=0; !x && i<d.forms.length; i++)
	x=d.forms[i][n];
  return x;
}

function MM_swapImage()
{ //v3.0
  var i,j = 0,x,a = MM_swapImage.arguments;
  document.MM_sr = new Array;
  for (var i=0; i<(a.length-2); i+= 3)
	if ((x = MM_findObj(a[i]))!=null)
	{
	  document.MM_sr[j++]=x;
	  if (!x.oSrc)
		x.oSrc=x.src;
	  x.src=a[i+2];
	}
}

// The sendNoCache flag will force a unique string into the query string. IE sometimes inadvertently
// caches dynamic pages with layers, so this will ensure that IE does do this since every page will
// be an absolutely unique hit

function loadPage(newPage, sendNoCache){
	var argv = loadPage.arguments;
	sendNoCache = argv[1];
	if(sendNoCache==null) sendNoCache=false;

	if(sendNoCache){
		var newUniquePage=newPage;
		var d=new Date();
		if(newUniquePage.indexOf('?')==-1){ // If we already have a query string then add a new name value, otherwise simply add the query string
			newUniquePage+='?nocache=' + d.valueOf();
		}else{
			newUniquePage+='&nocache=' + d.valueOf();
		}
		top.left_main_frame.workspace_frame.location.href=newUniquePage;
	}else{
		top.left_main_frame.workspace_frame.location.href=newPage;
		// We use an href because we want the back button to work
	}
}

function loadJSPPage(newPage, sendNoCache){
	loadPage("/jsp/" + JSPBrokerDirectory + newPage, sendNoCache);
}

function loadOutsidePage(newPage){
	window.open(newPage,'shadow_retail','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,');
}

function loadOutsideQuotePage(newPage){
	var quote_bar_offset=window.screen.availHeight - 130;
	w=window.open(newPage,'quote_bar','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=620,height=30,left=1,top=' + quote_bar_offset.toString());
	w.targetItem=item;
}

function closeWindow(){
	var msg= "\nYou are about to be logged off the system.\n\nYour browser window will be closed.";
	if (confirm(msg))
		top.location.replace("cgi/online/ABSLogoffPage");
	else
		loadPage("/splash/splash.html");
}


function copyStyle(target, source){
	target.backgroundColor=source.backgroundColor;
	target.color=source.color;
	target.frontWeight=source.fontWeight;
}


function cookieVal(offset) {
   var endstr=document.cookie.indexOf(";",offset);
   if (endstr == -1) {endstr=document.cookie.length;}
   return unescape(document.cookie.substring(offset,endstr));
}

function getCookie(name) {
   var arg=name+"=";
   var alen=arg.length;
   var clen=document.cookie.length;
   var i=0;
   while (i<clen) {
      var j=i+alen;
      if (document.cookie.substring(i,j) == arg) {
          return cookieVal(j);
          }
      i=document.cookie.indexOf(" ",i) + 1;
      if (i === 0) {break;}
   }
}

function saveCookie(name, value, path){
	var cookie=name + "=" + value + "; expires=Wednesday, 01-Jan-30 23:59:59 GMT";
	if(path) cookie+="; path=" + path;
	document.cookie=cookie;
}

function deleteCookie(name){
	var ckyDate = new Date;
	ckyDate.setFullYear(ckyDate.getFullYear() -10);
	var cookie=name + "=; expires=" + ckyDate.toGMTString() + ";";
	document.cookie=cookie;
}

function console(text){
	javascriptConsole=window.open("",'javascript_console','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=450,height=450');
	doc=javascriptConsole.document;
	doc.write("<pre>" + text + "</pre>");
}

function compressNameValues(string){
	var newString="";
	for(var i=0;i<string.length;i++){
		switch(string.charAt(i)){
		case '&':
			newString+='~';
			break;
		case '=':
			newString+='`';
			break;
		default:
			newString+=string.charAt(i);
			break;
		}
	}
	return escape(newString);
}

function uncompressNameValues(string){
	string=unescape(string);
	var newString="";
	for(var i=0;i<string.length;i++){
		switch(string.charAt(i)){
		case '~':
			newString+='&';
			break;
		case '`':
			newString+='=';
			break;
		default:
			newString+=string.charAt(i);
			break;
		}
	}
	return newString;
}

//***** This function turns any object into a namevalue string. Object must contain string types (no numbers)
function object2NV(obj){
	var text="";
	for(var i in obj){
		if(i==null) continue;
		if(obj[i]==null) continue;
		if(typeof(obj[i].indexOf)=="undefined" && typeof(obj[i])!="number") continue;
		text+=i + "=" + obj[i] + "&";
	}
	return text;
}

function objectFromNV(obj, nameValues, isNumeric){
	for(var i in obj){
		if(i==null) continue;
		if(nameValues==null){	// From session name values
			if(session_nv_exists(i)){
				if(isNumeric)
					obj[i]=Number(session_nv_first(i));
				else
					obj[i]=session_nv_first(i);
			}
		}else{ // From name values that are passed in
			if(isNumeric)
				obj[i]=Number(nameValues[i]);
			else
				obj[i]=nameValues[i];
		}
	}
}

// This function can be used automatically if the buttons follow the _off / _on paradigm. Just set mouseover and mouseout to point to this function
function rollover(e){
	if(!e) var e=window.event;
	if (e.target) e.srcElement = e.target;

	var imageName=e.srcElement.src;
	if(e.type=="mouseover"){
		e.srcElement.src=imageName.replace("_off","_on");
	}else{
		e.srcElement.src=imageName.replace("_on","_off");
	}
}

function setCursorPointer(elem){
	if(IE5) elem.style.cursor="hand";
	else elem.style.cursor="pointer";
}

function addEvent(eventName,elem,functionRef){
	if(elem && elem.addEventListener) elem.addEventListener(eventName,functionRef,false);
	else if(elem && elem.attachEvent) elem.attachEvent("on"+eventName,functionRef);
}

function addStatusMessage(elem,statusText){
	elem.setAttribute("statusText",statusText);
	addEvent("mouseover",elem,defaultMouseover);
	addEvent("mouseout",elem,defaultMouseover);
}

function defaultMouseover(e){
	if(!e) var e=window.event;
	if (e.target && !e.srcElement) e.srcElement = e.target;
	var elem=e.srcElement;
	if(elem.nodeType==3) //TEXT_NODE
		elem=e.srcElement.parentNode;
	if(e.type=="mouseover") self.status=elem.getAttribute("statusText");
	else self.status="";
}

function createInputField(doc,type,name,id,value,maxLength,size,checked,className){
	var field=doc.createElement("input"); //non-ie;
	if(!doc.addEventListener) field=doc.createElement('<input type="'+type+'" name="'+name+'" />'); //try ie way
	field.setAttribute("id",id);
	field.setAttribute("type",type);
	field.setAttribute("name",name);
	field.setAttribute("defaultValue",value);
	field.setAttribute("value",value);
	if(maxLength>-1) field.setAttribute("maxLength",maxLength);
	if(size>-1) field.setAttribute("size",size);
	if(checked) field.setAttribute("defaultChecked",checked);
	if(checked) field.setAttribute("checked",checked);
	if(className!=null && className!="") field.className=className;
	return field;
}

function createSelectBox(doc,id,className,defaultSelectValue,onChange,size,multiple){
	var select=doc.createElement("select");
	if(!doc.addEventListener) select=doc.createElement('<select'+(multiple?' multiple':'')+(size?' size="'+size.toString()+'"':'')+' />'); //try ie way
	select.doc=doc;
	select.defaultSelectValue=defaultSelectValue;
	select.id=id;
	select.name=id;
	select.className=className;
	if(size) select.size=size;
	if(multiple) select.multiple=true;
	if(onChange!="" && onChange!=null && typeof(onChange)!="undefined"){
		addEvent("change",select,onChange);
		addEvent("keyup",select,onChange);
	}
	// we create the functions using new Function() instead of function() because we do not want them compiled till run time
	// that way we won't have a memory leak.  It's slower but more effective.

	select.addOption=new Function('value','text','isDefaultValue','\
		var option=this.doc.createElement("option");\
		option.appendChild(this.doc.createTextNode(text));\
		option.value=value;\
		this.appendChild(option);\
		if(value==this.defaultSelectValue || isDefaultValue){\
			this.options[this.options.length-1].selected=true;\
			this.options[this.options.length-1].defaultSelected=true;\
		}');
	//only used to change a select box value in a script
	select.selectOption=new Function('value','\
		for(var i=0;i<this.options.length;i++){\
			if(this.options[i].value==value)\
				this.options[i].selected=true;\
		}');
	//only used to change a select box value in a script
	select.deselectOption=new Function('value','\
		for(var i=0;i<this.options.length;i++){\
			if(this.options[i].value==value)\
				this.options[i].selected=false;\
		}');
	select.removeOption=new Function('value','\
		for(var i=0;i<this.options.length;i++){\
			if(this.options[i].value==value)\
				this.removeChild(this.childNodes[i]);\
		}');
	select.reset=new Function('\
		for(var i=0;i<this.options.length;i++){\
			if(this.options[i].selected=this.options[i].defaultSelected);\
		}');
	select.clear=new Function('this.length=0;');
	select.exportArrayValues=new Function('\
		var a=new Array();\
		if(!this.multiple) a[0]=this.options[this.options.selectedIndex].value;\
		else for(var i=0;i<this.options.length;i++){\
			if(this.options[i].selected) a[a.length]=this.options[i].value;\
		}\
		return a;');

	return select;
}

// Original Author: Michael van Ouwerkerk
function addStyleSheet(doc,href) {
	var r = false;
	// Trying createStyleSheet first, because that seems to work best with IE5/Mac.
	if (doc.createStyleSheet) {
		doc.createStyleSheet(href);
		r = true;
	}else if (doc.getElementsByTagName && doc.createElement) {
		var head = doc.getElementsByTagName("head")[0];
		if (!head || !head.appendChild) return false;
		var link = doc.createElement("link");
		link.rel = "stylesheet";
		link.type = "text/css";
		link.href = href;
		link = head.appendChild(link);
		r = true;
	}
	return r;
}

function clickable(elem,action,status){
	setCursorPointer(elem);
	addEvent("click",elem,action);
	addStatusMessage(elem,status);
}

//Frozen headers
//Requires that the column widths be set in the header row and that the table width be set to equal the sum of the column widths
var clonedTables=new Array();
function createFrozenHeader(doc,win,rowToFreeze,referenceTable){
	referenceTable.style.tableLayout="fixed";

	var clonedTable=referenceTable.cloneNode(false);
	clonedTable.id=referenceTable.id+"_frozen_header";
	clonedTable.style.position="absolute";
	clonedTable.style.tableLayout="fixed";
	clonedTable.referenceTable=referenceTable;
	clonedTables[clonedTables.length]=clonedTable;

	var clonedTHead=doc.createElement("thead");
	clonedTable.appendChild(clonedTHead);

	rowToFreeze.id+="_cloned";
	clonedTHead.appendChild(rowToFreeze);

	var operaOffsetTop=(isOpera||isSafari?5:0);

	var interval=50;
	if(rowToFreeze.getAttribute("intervalOnly")!="true"){
		interval=333;
		//These don't work with Safari
		addEvent("scroll",win,moveFrozenHeader);
		addEvent("mousewheel",doc,moveFrozenHeader);
		addEvent("keyup",doc,moveFrozenHeader);
		addEvent("DOMMouseScroll",win,moveFrozenHeader);
	}
	//setting interval to correct discrepancies (wheel mouse, etc)
	if(typeof(window.pageYOffset)=="undefined"){
		win.setInterval("document.getElementById('"+clonedTable.id+"').style.pixelTop=(document.body.scrollTop>document.getElementById('"+referenceTable.id+"').offsetTop+document.getElementById('"+referenceTable.id+"').offsetHeight-document.getElementById('"+clonedTable.id+"').offsetHeight?document.getElementById('"+clonedTable.id+"').style.pixelTop:(document.body.scrollTop>document.getElementById('"+referenceTable.id+"').offsetTop?document.body.scrollTop:document.getElementById('"+referenceTable.id+"').offsetTop));",interval);
	}else{
		win.setInterval("document.getElementById('"+clonedTable.id+"').style.top=(window.pageYOffset>document.getElementById('"+referenceTable.id+"').offsetTop+document.getElementById('"+referenceTable.id+"').offsetHeight-document.getElementById('"+clonedTable.id+"').offsetHeight?document.getElementById('"+clonedTable.id+"').style.top:(window.pageYOffset>document.getElementById('"+referenceTable.id+"').offsetTop?(window.pageYOffset+"+operaOffsetTop.toString()+").toString()+'px':(document.getElementById('"+referenceTable.id+"').offsetTop+"+operaOffsetTop.toString()+").toString()+'px'));",interval);
	}

	return clonedTable;
}

function moveFrozenHeader(e){

	if(!e) var e=window.event;
	if (e.target && !e.srcElement) e.srcElement = e.target;

	var doc=null;
	if(e.srcElement){
		doc=e.srcElement.ownerDocument;
		if(!doc) doc=e.srcElement.document;
	}
	if(!doc) doc=eval(document.body.getAttribute("scrollTarget"));
	if(!doc) doc=document;

	var operaOffsetTop=(isOpera||isSafari?5:0);
	for(var i=0;i<clonedTables.length;i++){

		var referenceTable=clonedTables[i].referenceTable;
		if(!referenceTable) continue;

		if(typeof(window.pageYOffset)=="undefined"){
			if(doc.body.scrollTop<referenceTable.offsetTop+referenceTable.offsetHeight-clonedTables[i].offsetHeight){
				if(doc.body.scrollTop>referenceTable.offsetTop)
					clonedTables[i].style.pixelTop=doc.body.scrollTop;
				else
					clonedTables[i].style.pixelTop=referenceTable.offsetTop;
			}
		}else{
			if(doc.defaultView.pageYOffset<referenceTable.offsetTop+referenceTable.offsetHeight-clonedTables[i].offsetHeight){
				if(doc.defaultView.pageYOffset>referenceTable.offsetTop)
					clonedTables[i].style.top=(doc.defaultView.pageYOffset+operaOffsetTop).toString()+'px';
				else
					clonedTables[i].style.top=(referenceTable.offsetTop+operaOffsetTop).toString()+'px';
			}
		}
	}
}

function_error=0;

