
function findPosition( oLink ) {  //positioning for use w/ menus
  if( oLink.offsetParent ) {
    for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
      posX += oLink.offsetLeft;
      posY += oLink.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ oLink.x, oLink.y ];
  }
}

function getPageScrollOffset(){
	var x,y;
	if (self.pageYOffset) {// all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	}else if (document.documentElement && document.documentElement.scrollTop){// Explorer 6 Strict
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}else if (document.body) {// all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return [x,y];
}
function getWindowSize(){
	var x,y;
	if (self.innerHeight){ // all except Explorer
		x = self.innerWidth;
		y = self.innerHeight;
	}else if (document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}else if (document.body){ // other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return [x,y];
}
function getPageSize(){
	var x,y;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2){ // all but Explorer Mac
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}else{ // Explorer Mac; would also work in Explorer 6 Strict, Mozilla and Safari
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	return [x,y];
}

function addCommas(nStr){ //add commas to a number
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function removeCommas(str) {
	var aNum = str;
	aNum=aNum.replace(/,/g,"");//remove any commas
	aNum=aNum.replace(/\s/g,"");//remove any spaces

	return aNum;
}

function ow(url,w,h,name) {
	window.open(url,name, "width="+w+", height="+h+", toolbar=no, location=no, directories=no,status=no, menubar=no, scrollbars=yes,resizable=yes");
}

function glossary(term,anchor) {
	ow('/glossary/'+term+'#'+anchor,469,400,'glossary');
}

function ci() {
  if (document.images) {
    for (var i=0; i<ci.arguments.length; i+=2) {
      document[ci.arguments[i]].src = eval(ci.arguments[i+1] + ".src");
    }
  }
}
function diapop(StockID,query) {
	var a = (query)? '&cert=1' : ''
	window.open ("/diamond/imagezoom/zoompic.pl?id="+StockID+""+a, "cert", "width=640,height=411,menubar=no,scrollbars=yes,resizable=yes");
}

//detect browser
var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
	dom = ( d.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( d.all && !op );
	ie4 = ( ie && !dom );
	ie5x = ( d.all && dom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
}

function disablefields(){
	for (var i=0; i<disablefields.arguments.length; i++) {
		var thingy = document.getElementById(disablefields.arguments[i]);
		thingy.disabled = true;
		thingy.style.backgroundColor = 'LightGrey';
		thingy.style.color = 'DarkGray';
    }
}

function enablefields(){
	for (var i=0; i<enablefields.arguments.length; i++) {
		var thingy = document.getElementById(enablefields.arguments[i]);
		thingy.disabled = false;
		thingy.style.backgroundColor = 'White';
		thingy.style.color = 'Black';
    }
}
function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}

function getStyleObject(objectId) {
  if (document.getElementById && document.getElementById(objectId)) {
    return document.getElementById(objectId).style;
  } else if (document.all && document.all(objectId)) {
    return document.all(objectId).style;
  } else {
    return false;
  }
}

