function format(n, d) {
  with (Math) {

    var sign  = (n < 0) ? "-" : "";
    var num  = abs(n);

	 num = floor((num * pow(10, d + 1) + 5) / 10) / pow(10, d);
	 var whole = floor(num).toString();
	 var frac  = round((num - whole) * pow(10, d)).toString();
  }

  for ( ; frac.length < d ; ) frac = "0" + frac;
  
  return sign + whole + "." + frac;
}

function setFocus(element) {
	if (!element.disabled) {
		try {
			element.focus();
			if (element.type == "text") {
				element.select();
			}
		} catch (e) {}
	}
}

function getSelectTextValue(list) {
	return list.options[list.selectedIndex].text;
}

function getSelectValue(list) {
	return list.options[list.selectedIndex].value;
}


function openWindow(page, pagename, width, height, windowfeatures) {
	if (windowfeatures != "") {
		//windowfeatures = "," + windowfeatures + ",status";
		windowfeatures = "," + windowfeatures;
	}
	
	var left = screen.availWidth/2 - width/2;	
	var top = screen.availHeight/2 - height/2;	
		
	pagename = pagename.toString().replace(/[\s-&.]/g, "");

	var w  = window.open(page, pagename,"LEFT=" + left + ",TOP=" + top + ",HEIGHT=" + height + ",WIDTH=" + width + windowfeatures);	

	try {
		if (windowfeatures.indexOf('maximized') != -1) {
			w.moveTo(0,0);
			if (document.all) {
				w.resizeTo(screen.availWidth,screen.availHeight);
			} else if (document.layers||document.getElementById) {
				if (w.outerHeight < screen.availHeight||w.outerWidth < screen.availWidth) {
					w.outerHeight = screen.availHeight;
					w.outerWidth = screen.availWidth;
				}					
			}		
		}
	} catch(e) {}	
	return w;
}
