//var root = "";
function getRoot() {
	//root = (root != undefined && root != null && root != "/") ? root : "";
	return "/mmt";	
}

function getObject(id, parentElement) {
	if (parentElement == null || parentElement == undefined || parentElement == "") {
		parentElement = document;
	}
	return parentElement.getElementById(id);
}

var DEFAULT_DAYS_IN_YEAR = 365;
function getDefaultDaysInYear() {
	return DEFAULT_DAYS_IN_YEAR;
}

function rightTrim() {
    return this.replace(/\s+$/gi, "");
}

function leftTrim() {
    return this.replace(/^\s*/gi, "");
}

function rightPad(str, padChar, length) {
	while (str.length < length) {
		str = str + padChar;
	}
	return str;
}

function leftPad(str, padChar, length) {
	while (str.length < length) {
		str = padChar + str;
	}
	return str;
}

function Trim() {
    return this.rightTrim().leftTrim();	
}

String.prototype.rightTrim = rightTrim;
String.prototype.leftTrim = leftTrim;
String.prototype.Trim = Trim;


var message="";
function clickIE() {
    if (document.all) {
        (message);
        return false;
    }
}

function clickNS(e) {
    if (document.layers || (document.getElementById&& !document.all)) {
        if (e.which==2||e.which==3) {
            (message);
            return false;
        }
    }
}

function noop() {
//    alert("noop");
    event.returnValue=false;
}

 /*
// Enable before going LIVE
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);;
} else {
    document.onmouseup=clickNS;
    document.oncontextmenu=clickIE;
}
document.oncontextmenu=noop;    
 */

/*
// Disable copy and cut operations
var allObjects = document.all;
for (var i = 0; i < allObjects.length; i++) {
    allObjects[i].oncopy=noop;
    allObjects[i].oncut=noop;
}
*/
var helpDialog = null;

function treeNav(mode, params) {
    parent.frames.fra_TOC.treeNav(mode, params);
}

function mainNav(mode, params) {

	var dir = getRoot()+ "/jsp/" + mode + "/";
	var params = ((params != null && params != undefined) ?  "?" + params : "");
	
	top.mainWindow.frames.fra_Main.location = dir + "index.jsp" + params;	
}


function toolNav(mode, params) {
	var dir = getRoot()+ "/jsp/tools/";
	var params = ((params != null && params != undefined) ?  "?params=" + params : "");
	
	//top.mainWindow.frames.fra_Tools.location = dir + "index.jsp" + params + "&view=" + mode;	
	
	parent.frames.fra_ToolHeader.location = dir + mode +"/navbar.jsp" + params;	
	parent.frames.fra_ToolMain.location = dir + mode + "/index.jsp" + params;	
}
            
function pageNav(tableID, showPrevious) {
	var nextTable = document.all[tableID];
	if (window.showingTable != nextTable && nextTable != null && nextTable != undefined) {
		if (window.showingTable != null) {
			window.showingTable.runtimeStyle.zindex = 0;
			if (showPrevious == null || showPrevious == undefined || showPrevious == "false") {
                        	window.showingTable.runtimeStyle.display = 'none';                        
                        }
        	}
        	window.showingTable = nextTable;
        	window.showingTable.runtimeStyle.zindex = 1;
        	window.showingTable.runtimeStyle.display = 'block';
	}
	activateLink(window.event.srcElement);	
}

function activateLink(newActiveLink) {
	if (window.previousLink != null) {
		window.previousLink.parentElement.className = 'navlink';
	}
 	window.previousLink = newActiveLink;
 	window.previousLink.parentElement.className = 'activenavlink';	
}

function helpNav(helpContext) {

//	showWindow(helpContext, "help", "800px", "400px");
//	showWindow(getRoot()+ "/jsp/help/index.jsp", "help", "800px", "400px");	
}

function snapshotNav(symbol, name) {
    var snapshotDocument = top.mainWindow.frames.fra_Snapshots.document;
    
    snapshotDocument.all['chartimg'].src="/servlet/stats?cmd=find.stats&fromdate=2003-05-01&todate=2005-01-01&output=chart&symbol="+symbol;
    snapshotDocument.all['chartsym'].value=symbol;
    snapshotDocument.all['chartname'].href="javascript:headerNav('companies', 'symbol=" + symbol + "&view=securities')";
    snapshotDocument.all['chartname'].innerText=name;
}


function showWindow(url, name, width, height, bReplace) {

    width = (width != null && width != undefined) ? width : "750px";
    height = (height != null && height != undefined) ? height : "350px";
    name = (name != null && name != undefined) ? name : "_blank";
    
    var newWindow = window.open(url, name, "width="+width+",height="+height+",status=no,resizable=yes,toolbar=no,scrollbars=yes,menubar=no,location=no", bReplace);
    newWindow.focus();
}

function showDialog(url, params, height, width, isModeless) {

    height = (height != null && height != undefined) ? height : "200px";
    width = (width != null && width != undefined) ? width : "320px";
    
    if (isModeless) {
    	return window.showModelessDialog(url, params, "dialogHeight:"+height+";dialogWidth:"+width+";status:no;scroll:no;");	
    } else {
    	return window.showModalDialog(url, params, "dialogHeight:"+height+";dialogWidth:"+width+";status:no;scroll:no;");
    }
}


function exportExcel(name, params) {
	//alert(name);
	window.open("/"+name+"?"+params);
}


function printPage() {
    window.print();
}

function formSubmit(form, action) {

	var elements = form.elements;
	for (var i = 0; i < elements.length; i++) {
		var objElement = elements[i];
		if (objElement.type != 'hidden' && !isFormDataValid(objElement)) {
			return;
		}
    }
	form.target = (form.target) ? form.target : "_self";
	form.action	= (action) ? action : document.location;
	form.submit();
}

function isFormDataValid(objElement)  {
	
	var isValid = true;
	
	// Check for the existence of a validation function
	var callback = objElement.getAttribute("validate");
    if (callback && (callback = eval("window."+callback))) {
		if (!callback.call(objElement, objElement.value)) {
			highlightElement(objElement, true);
			var errmsg = objElement.getAttribute("errmsg");
			alert(errmsg ? errmsg : "The highlighted item contains an invalid value. Please amend it then retry.");
			isValid = false;
		} else {
			highlightElement(objElement, false);
		}
    }
	return isValid;
}

function highlightElement(objElement, canHighlight) {
	var offset = objElement.className.indexOf("-highlight");
	if (canHighlight) {
		objElement.className = (offset != -1) ? objElement.className : objElement.className + "-highlight";
	} else {
		objElement.className = (offset != -1) ? objElement.className.substring(0, offset) : objElement.className;
	}
}



function doFormClear() {
  var form = document.all['formEntry'];
  var colElements = form.elements;
  for (var i = 0; i < colElements.length; i++) {
    var objElement = colElements[i];
    if (objElement.tagName == "INPUT" || objElement.tagName == "SELECT" || objElement.tagName == "TEXTAREA") {    
      if (objElement.type != "submit" && objElement.type != "reset") {
      	if (objElement.type == "radio" || objElement.type == "checkbox" ) {
	  objElement.checked = false;
	} else {
	  objElement.value = "";	
	}
      }
    }
  }  
}

function doFormSubmit(form, action, mp1, mp1name, mp2, mp2name, callback, target) {

  var cmd = (form.all['cmd'] != undefined) ? form.all['cmd'].value : null;

  if (mp1 != null) {
    var val = form.all[mp1].value;
    if (val == null || val == undefined || val.Trim() == "" ) {
      alert("Please specify " + mp1name); return;
    }
  }

  if (mp2 != null) {
    var val = form.all[mp2].value;
    if (val == null || val == undefined || val.Trim() == "" ) {
      alert("Please specify " + mp2name); return;
    }
  }
  
  if (callback != null && callback != undefined) {
  	if (!callback()) {
  		return;
  	}
  }
  
  if (cmd != null && cmd.substring(0,3) == "add") {

    var aInputs = form.getElementsByTagName("INPUT");
    var failed = false;
    for (var i = 0; i < aInputs.length; i++) {
      var objInput = aInputs[i];
      if (objInput.type != 'submit' && objInput.type != 'hidden' && objInput.className == "text") {
        if (objInput.value == "") {
          objInput.style.color = 'black';
          objInput.style.backgroundColor = '#fad354';
          failed = true;
        } else if (objInput.className == "text") {        
	  objInput.style.color = 'white';        
          objInput.style.backgroundColor = 'black';
        }
      }
    }

    if (failed) {
       if (!confirm("The highlighted fields have empty values. Continue saving?")) {
       	return;
       }
    }
  }
  
  if (cmd != null && cmd.substring(0,6) == "remove") { 
      if (!confirm("Are you sure you want to permanently delete '" + form.all[mp1].value + "'?")) {
      	return;      
      }
  }

  if (target != null) {
      form.target = target;
  } else {
      form.target= "_self";
  }  

  form.action=action;
  form.submit();
}


            function stripAll(str, pattern) {
                var result = "";
                var sections = str.split(pattern);
                for (var i = 0; i < sections.length; i++) {
                    //alert(i +"="+sections[i]);
                    result+=sections[i];
                }
                return result;
            }
			
			function expandDouble(val, fractionDigits) {

				//alert(str);
				var str = (val instanceof String) ? val : new String(val);
				
				str = stripAll(str, ",");
				// Expand abbreviated values e.g. 1B, 45.67M etc
				var length = str.length;
				//alert(length);
				var floatValue = parseFloat(str.substring(0, length));
				//alert(floatValue);
				var lastChar = str.charAt(length - 1);
				//alert(lastChar);
				if (lastChar == 'B' || lastChar == 'b') {
					floatValue *= 1000000000;
				} else if (lastChar == 'M' || lastChar == 'm') {
					floatValue *= 1000000;
				} else if (lastChar == 'K' || lastChar == 'k') {
					floatValue *= 1000;
				}
				floatValue = (fractionDigits != undefined) ? new Number(floatValue, fractionDigits) : floatValue;
				//alert(floatValue);
				
				return floatValue;
			}
			            
            function formatDouble(val) {
				
				var pattern = ",";
				var interval = 3;
				
				var str = (val instanceof String) ? val : new String(val);
                
                var mantissa = "";                
                var exponentLength = str.indexOf('.');
                if (exponentLength != -1) {
                	mantissa = str.substring(exponentLength, str.length);
               	} else {
               		exponentLength = str.length;
               	}

				var sections = str.split("");
                var count = 1;               	
                var result = "";               	
                for (var i = exponentLength - 1; i >= 0; i--) {
                    //alert(i +"="+sections[i] +" count="+count);
                    if (count > interval) {
                    	result = sections[i] + pattern + result;
                    	count=1;
                    } else {
	                    result=sections[i] + result;
                    }
                    count++;
                }
                return result + mantissa;
            }

            function sumUpTextArea(textArea) {
                var sum = 0;
                var allText = textArea.value;
                var lines = allText.split("\n");
                for (var i = 0; i < lines.length; i++) {
                    if (lines[i].length > 0) {
                        var str = lines[i].replace('\t', ' ');
                        //alert(str);
                        var pos = str.lastIndexOf(' ');
                        if (pos != -1) {
                            //alert("pos="+pos+", num="+str.substring(pos, str.length));
                            sum += parseFloat(stripAll(str.substring(pos, str.length), ','));
                        }
                    }

                }
                //alert(sum);

                return sum;
            }

    function toggleSelect(selectA, selectB, buttonA, buttonB, value, displayMode) {

        displayMode = (displayMode != undefined) ? displayMode : "block";
        if (value != undefined) {
            if (value == true) {

                document.all[selectA].runtimeStyle.display='none';
                document.all[selectB].runtimeStyle.display=displayMode;

                document.all[buttonA].runtimeStyle.display=displayMode;
                document.all[buttonB].runtimeStyle.display='none';

            } else if (value == false) {
                document.all[selectB].runtimeStyle.display='none';
                document.all[selectA].runtimeStyle.display=displayMode;

                document.all[buttonA].runtimeStyle.display='none';
                document.all[buttonB].runtimeStyle.display=displayMode;
            }
        }
    }
    

function clearForm(objForm) {

    var aInputs = objForm.getElementsByTagName("INPUT");
    for (var i = 0; i < aInputs.length; i++) {
      var objInput = aInputs[i];
      if (objInput.type != "hidden" && objInput.type != "submit" && objInput.type != "reset") {
          objInput.value="";
      }
    }


    var aTextAreas = objForm.getElementsByTagName("TEXTAREA");
    for (var i = 0; i < aTextAreas.length; i++) {
      var objTextArea = aTextAreas[i];
      objTextArea.value="";
    }


    var aSelects = objForm.getElementsByTagName("SELECT");
    for (var i = 0; i < aSelects.length; i++) {
      var objSelect = aSelects[i];
      objSelect.value="";
    }
}

function createParameters(quantity) {
    document.paramArray = new Array(quantity);
    for (var i = 0; i < document.paramArray.length; i++) {
        document.paramArray[i] = new Array(2);
    	document.paramArray[i][0] = null;
    	document.paramArray[i][1] = null;

    }
    //alert("Created "+quantity);
}

function setDateParameter(index) {
    document.dateIndex = index;
}

function setSelectParameter(index) {
    document.chooseIndex = index;
}


function showParameterDialog(context, isSynchronous, width, height) {
    
    var i = 0;    
    for (; i < document.paramArray.length; i++) {	
    	if (document.paramArray[i][0] == null) {
    	    break;
    	}
    }
    
    width = (width != null && width != undefined && width != "") ? width : "320px";
    height = (height != null && height != undefined && height != "") ? height : "200px";    
    
    //alert("Showing "+i+",cxt="+context);
    if (i != 0) {
    	
    	var dateIndex = (document.dateIndex != null && document.dateIndex != undefined) ? document.dateIndex : "";
    	var chooseIndex = (document.chooseIndex != null && document.chooseIndex != undefined) ? document.chooseIndex : "";
    
    	var contextStr 	  = (context != null && context != undefined) ? ("study="+context) : "";    	
        var newValueArray = window.showModalDialog(getRoot()+ "/jsp/tools/parameters.jsp?cxt="+contextStr+"&numparams="+i+"&dateparam="+dateIndex+"&chooseparam="+chooseIndex, document.paramArray,  "dialogHeight:"+height+";dialogWidth:"+width+";status:no;scroll:no;");        
        if (newValueArray != null && newValueArray != undefined) {        	
            if (isSynchronous != "true") {
            	var objOBJECT = findElementByTagName('OBJECT', 0); 
            	for (i = 0; i < newValueArray.length; i++) {                
            	    document.paramArray[i][1] = newValueArray[i];
            	    objOBJECT.handleCallback('setParameterValue'+i, newValueArray[i]);
            	}
            } else {
            	return newValueArray;
            }
        } else {
            return null;
        }
    }
	    
}



function setParameter(index, newLabel, newValue) {
    if (document.paramArray != undefined && index < document.paramArray.length) {
    	if (newValue != null) {
    	    document.paramArray[index][0] = newLabel;
    	    document.paramArray[index][1] = newValue;
        } else {
    	    document.paramArray[index][0] = null;
    	    document.paramArray[index][1] = null;
        }
        //alert("setParam "+index+",param="+document.paramArray[index]);
    }
}

function getNameParameter(nameLabel) {
    createParameters(1);
    setParameter(0, nameLabel, "");
    var newValueArray = showParameterDialog(null, "true");
    
    return (newValueArray != null && newValueArray != undefined) ? newValueArray[0] : "";
}
    
function showTradeOrderDialog(orderID) {
     
     var url = getRoot()+ "/jsp/myterminal/trades/orders/orderslip.jsp";
     

    if (orderID != undefined && orderID != null) {
        url += "?cmd=find.trade_orders&torderid=" + orderID;
    }     
 
     showWindow(url, '', '480px', '570px', true);
}

function showSearch(searchCxt) {
	if (searchCxt != null && searchCxt != undefined){
		var url = getRoot() + '/jsp/tools/search/' + searchCxt + '/index.jsp';
		showWindow(url, searchCxt);
	}
}

function showOpenAccountDialog() {
     
     var url = getRoot() + "/jsp/account/accounts/openaccountslip.jsp";
 
     showWindow(url, '', '560px', '460px', true);
}


function showCreateMessageDialog(replyTo, replySubject) {
     
    replyTo = (replyTo != null && replyTo != undefined) ? replyTo : ""; 
    replySubject = (replySubject != null && replySubject != undefined) ? replySubject : "";
    
    var url = getRoot() + "/jsp/tools/messages/showmessage.jsp?msgto="+replyTo+"&msgsubj="+replySubject;
    showWindow(url, '_blank', '580px', '380px', true);
}

function showMessageDialog(msgID) {
     
     var url = getRoot() + "/jsp/tools/messages/showmessage.jsp";
     
     
     if (msgID != undefined && msgID != null) {
     	url += "?cmd=find.messages&msgid=" + msgID;
     }     
 
     showWindow(url, '', '580px', '380px', true);
}


function showCreateAccountTransactionDialog(acctID) {
     var url = getRoot() + "/jsp/myterminal/accounts/transactions/createtransaction.jsp?acctid=" + acctID; 
     showWindow(url, '', '500px', '330px', true);
}


function addMonth(dateMillis, targetDayOfMonth, factor) {
	var date = new Date(dateMillis);

	//alert("addMonth:stage1: date="+date+",time="+date.getTime()+",dateMillis="+dateMillis);

	var month = date.getMonth();
	var targetMonth = month + factor;
	if (targetMonth < 0) {
		targetMonth = 12 - Math.abs(targetMonth);
	} else if (targetMonth > 11) {
		targetMonth = Math.abs(targetMonth) - 12;
	}
	date.setMonth(date.getMonth() + factor);
	//alert("addMonth:stage2: date="+date+",time="+date.getTime());

	if (date.getMonth() == targetMonth) {
		date.setDate(targetDayOfMonth);
	}
	
	month = date.getMonth();
	if (date.getMonth() != targetMonth) {
		date.setDate(0);
	}
	//alert("month="+month+",targetMonth="+targetMonth+",date="+date);
	return date.getTime();
}


function showAccountTransactionsDialog() {
}

function setSelectedOption(selectList, newValue) {
	selectList.value = newValue;
}


function getSelectedOption(selectList) {

    var col_Opts = selectList.options;
    var i;

    for (i = 0; i < col_Opts.length; i++) {
		var opt = col_Opts[i];
		if (opt.selected) {
		    return opt;
		}
    }
    return null;
}

function replaceOption(selectList, optionValue, optionText, index) {
    addOption(selectList, optionValue, optionText, index, true);
}

function addOption(selectList, optionValue, optionText, index, canReplace) {

    if (canReplace) {
        removeOption(selectList, optionValue);
    }
    
    var obj_Opt = document.createElement("OPTION");
    if (index != null && index != undefined && index >= 0 && index < selectList.options.length) {
        selectList.options.add(obj_Opt, index);
    } else {
        selectList.options.add(obj_Opt);    
    }
    obj_Opt.value 	= optionValue;
    obj_Opt.innerText 	= optionText;
    obj_Opt.selected 	= true;
    
    //alert("Adding option value="+optionValue+", text="+optionText+", position="+index);
    //alert("Final selectList.innerHTML="+selectList.innerHTML);        
}

function findOptionIndex(selectList, optionValue) {

    var col_Opts = selectList.options;       
    for (var i = 0; i < col_Opts.length; i++) {
        var opt = col_Opts[i];        
        if (opt.value == optionValue) {
            return i;
        }        
    }
    return -1;
}

function clearOptions(selectList, optionValue) {
	var opts = selectList.options;
	while (opts.length > 0) {
	    opts.remove(0);
	}
}

function findOption(selectList, optionValue) {
    var index = findOptionIndex(selectList, optionValue);
    if (index != -1) {
    	return selectList.options.item(index);    
    }
    return null;
}

function removeOption(selectList, optionValue) {

    var index = findOptionIndex(selectList, optionValue);
    if (index != -1) {
    	selectList.options.remove(index);    
    }    
}

function moveOption(selectList, optionValue, distance) {

    if (distance == null || distance == undefined) {
    	distance = 0;
    }
    
    var index = findOptionIndex(selectList, optionValue);
    if (index != -1) {
    	var optval = selectList.options.item(index).value;
    	var opttxt = selectList.options.item(index).innerText;

    	selectList.options.remove(index);
    	
    	var nextpos = index + distance;
    	addOption(selectList, optval, opttxt, (nextpos >= 0) ? nextpos : 0);
    }
}

function selectAll(selectList) {
	toggleSelect(selectList, true);
}

function deselectAll(selectList) {
	toggleSelect(selectList, false);
}

function toggleSelect(selectList, canSelect) {
    var col_Opts = selectList.options;
    var i;
    for (i = 0; i < col_Opts.length; i++) {
		col_Opts[i].selected = canSelect;
    }
}

function createEntity(form, idKey, nameKey, nameLabel, cmd) {

    var name = getNameParameter(nameLabel);
 	if (name != null && (name = name.Trim()) != "") {
        form.all[idKey].value = "-1";
        form.all[nameKey].value = name;
		form.all['cmd'].value = cmd;
    	form.submit();
	}
}


function deleteTransactionAccount(form, cmd) {
	alert("WARNING:\n\nDeleting this transaction account will delete all associated transactions and cleared balance statistics irreversibly.");
    deleteEntity(form, cmd);
}

function deletePortfolio(form, cmd) {
	alert("WARNING:\n\nDeleting this portfolio will delete all associated holdings irreversibly.");
    deleteEntity(form, cmd);
}

function deleteEntity(form, cmd) {
    form.all['cmd'].value = cmd;
	form.submit();
}

function findElementByTagName(tagName, index) {
    var elementCol = document.documentElement.all;
    index = (index == null || index == undefined) ? 0 : index;
    var count = 0;
    
    for (var i = 0; i < elementCol.length; i++) {
        var elem = elementCol[i];
        if (elem.tagName == tagName) {
            if (count == index) {            	
            	return elem;
            }
            count++;            
        }
    }
    return null;
}

var LEGAL_DECIMALS 	= '0123456789.-';
var LEGAL_HEXADECIMALS 	= '0123456789ABCDEFabcdef';

function isValidDecimal(string) {
    return isValid(string, LEGAL_DECIMALS);
}

function isValid(string,allowed) {
    if (string == null || string == undefined || string == "") {
    	return false;
    }
    for (var i=0; i< string.length; i++) {
        if (allowed.indexOf(string.charAt(i)) == -1) {
            //alert('Invalid');
            return false;
        }
    }
    return true;
}

function isFilterAbsolute(filterCode) {
	return filterCode.indexOf("min") != -1 || filterCode.indexOf("max") != -1;
}

function isFilterRelative(filterCode) {
	return filterCode.indexOf("<") != -1 || filterCode.indexOf(">") != -1 || filterCode.indexOf("<>") != -1 ;
}


function formatFilter(filterCode, filterName) {

    var strValue = filterName;        
    var  parts = filterCode.split(" ");

    if (isFilterAbsolute(filterCode)) {

        var min = parts[1].substring(4);
        var max = parts[2].substring(4);

        if (min.length == 0 && max.length != 0) {
            strValue += " is less than or equal to " + max;
        } else if (min.length != 0 && max.length == 0) {
            strValue += " is greater than or equal to " + min;
        } else if (min.length != 0 && max.length != 0) {
            if (min != max) {
                strValue += " is between " + min + " and " + max;
            } else {
                strValue += " is equal to " + min;
            }
        }

    } else if (isFilterRelative(filterCode)) {

        var factor   = parts[1];
        var operator = parts[2];
        
        if (operator == "<=") {
            strValue += " is less than or equal to the reference avg." + ((factor != 0) ? (" + " + factor + "%") : "");
        } else if (operator == ">=") {
            strValue += " is greater than or equal to the reference avg." + ((factor != 0) ? (" - " + factor + "%") : "");
        } else if (operator == "<>") {
            strValue += " is " + ((factor != 0) ? "between" : "equal to") + " the reference avg." + ((factor != 0) ? (" +/- " + factor + "%") : "");
        }
    }
    return  strValue;
}

function urlEncodeFilter(filterCode) {

    var parts  = filterCode.split(" ");
    var code   = parts[0];
    
    if (isFilterAbsolute(filterCode)) {
    
        var min    = parts[1].substring(4);
        var max    = parts[2].substring(4);
        
        filterCode = code + " min%3D" + min + " max%3D" + max;
    } else if (isFilterRelative(filterCode)) {

        var factor   = parts[1];
        var operator = parts[2];

        if (operator == "<=") {
            filterCode = code + " " + factor + " %3C%3D";
        } else if (operator == ">=") {
            filterCode = code + " " + factor + " %3E%3D";
        } else if (operator == "<>") {
            filterCode = code + " " + factor + " %3C%3E";
        }
    }
    return  filterCode;
}



/* DIALOGS */

function showIssueDialog(issueID) {
	
	issueID = (issueID != null && issueID != undefined) ? issueID : "-1"
	var url = getRoot() + '/jsp/treasury/issues/wizard/index.jsp?issueid=' + issueID;	
	showWindow(url, "_blank", "700px", "400px");
}

function showDealOfferDialog(doID) {
	
	doID = (doID != null && doID != undefined) ? doID : "-1"
	var url = getRoot() + '/jsp/deals/offers/wizard/index.jsp?doid=' + doID;	
	showWindow(url, "_blank", "650px", "640px");
}

function showCreateDealBid(doID) {

	doID = (doID != null && doID != undefined) ? doID : "-1"
	var url = getRoot() + '/jsp/deals/bids/wizard/index.jsp?doid=' + doID;	
	showWindow(url, "_blank", "650px", "640px");
}

function showDealBidDialog(dbID) {
	
	dbID = (dbID != null && dbID != undefined) ? dbID : "-1"
	var url = getRoot() + '/jsp/deals/bids/wizard/index.jsp?dbid=' + dbID;	
	showWindow(url, "_blank", "650px", "640px");
}

function showDealContractDialog(dbID) {
	
	dbID = (dbID != null && dbID != undefined) ? dbID : "-1"
	var url = getRoot() + '/jsp/deals/contracts/wizard/index.jsp?dbid=' + dbID;	
	showWindow(url, "_blank", "650px", "640px");
}

function showDealSettlementDialog(dbID) {
	
	dbID = (dbID != null && dbID != undefined) ? dbID : "-1"
	var url = getRoot() + '/jsp/settlementcentre/contracts/wizard/index.jsp?dbid=' + dbID;	
	showWindow(url, "_blank", "650px", "640px");
}

function showAllotments(doID) {

	doID = (doID != null && doID != undefined) ? doID : "-1"
	var url = getRoot() + '/jsp/deals/allotment/wizard/index.jsp?doid=' + doID;	
	showWindow(url, "_blank", "700px", "400px");
}

function showIssueQuoteDialog(qID) {
	
	qID = (qID != null && qID != undefined) ? qID : "-1"
	var url = getRoot() + '/jsp/deals/quotes/wizard/index.jsp?qid=' + qID;	
	showWindow(url, "_blank", "650px", "600px");
}

function showEditTreasurerDialog() {
    var url = "/mmt/jsp/treasury/issuers/profile/editprofile.jsp";
    showWindow(url, '', '550px', '600px', true);
}

function onQuoteTypeChange(quotePrefix) {
	quotePrefix					= (quotePrefix != undefined) ? quotePrefix : "";
	
	var isRateBased				= getObject('ratequote', document).checked;
	var quoteValue				= getObject(quotePrefix + 'quotevalue', document);
	var quoteResultSPAN 		= getObject(quotePrefix + 'quoteresult', document);
	var quoteTypeNameSPAN 		= getObject(quotePrefix + 'quotetypename', document);
	var quoteValueNameSPAN 		= getObject(quotePrefix + 'quotevaluename', document);

	quoteValue.value			= "";
	quoteResultSPAN.innerText	= "---";

	//alert("isRateBased="+isRateBased);
	quoteTypeNameSPAN.innerText	= (isRateBased) ? "Rate of Return" : "Price";
	quoteValueNameSPAN.innerText= (isRateBased) ? "Price" : "Rate of Return";
}

function formatTenor(tenor) {        

	var tenorName;
    if (tenor < 0) {
    	return "Expired";
    }

    var numberOfYears = Math.floor(tenor / getDefaultDaysInYear());
    if (numberOfYears != 0) {
    	var numberOfDays = tenor - (numberOfYears * DEFAULT_DAYS_IN_YEAR); 
    	tenorName = numberOfYears + " yr";
    	if (numberOfDays == 0) {
    		// Do nothing
    	} else if (numberOfDays == 1) {
    		tenorName += "   1 day ";
    	} else if (numberOfDays < 10) {
    		tenorName += "   " + numberOfDays + " days";
    	} else {
    		tenorName += "  " + numberOfDays + " days";;
    	}
    } else {
   		if (tenor == 0) {
    		tenorName = "Open";
    	} else if (tenor == 1) {
   			tenorName = "Overnight";//"1 day";
    	} else {
   			tenorName = tenor + " days";
    	}
   	}
   	return tenorName;
}

