var ROOT = "";
function addCommas(nStr)
{
	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 formatNo(obj)
{
	val = safeValue(obj.value);
	obj.value = addCommas(val);
}
function safeValue(units)
{
	units = units.replace(/[^0-9\.]/g,"");
	return (units == "") ? 0 : parseFloat(units);
}
function toggleDiv(divId, type)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		if(obj.style.display == type)
			obj.style.display = "none";
		else
			obj.style.display = type;
	}
}
function showDiv(divId, type)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		obj.style.display = type;
	}
}
function hideDiv(divId)
{
	obj = document.getElementById(divId);
	if(obj)
	{
		obj.style.display = "none";
	}
}
function toUpper(obj)
{
	obj.value = obj.value.toUpperCase();
}
function changePropertyImage(newSrc, newCaption)
{
	imageObj = document.getElementById('largePropertyImage');
	if(imageObj)
	{
		imageObj.src = ROOT + "/uploadedimages/large_" + newSrc;		
		imageObj.alt = newCaption;
	}
}
function moveUp(element) {
  for(i = 0; i < element.options.length; i++) {
    if(element.options[i].selected == true) {
      if(i != 0) {
        var temp = new Option(element.options[i-1].text,element.options[i-1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i-1] = temp2;
        element.options[i-1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function moveDown(element) {
  for(i = (element.options.length - 1); i >= 0; i--) {
    if(element.options[i].selected == true) {
      if(i != (element.options.length - 1)) {
        var temp = new Option(element.options[i+1].text,element.options[i+1].value);
        var temp2 = new Option(element.options[i].text,element.options[i].value);
        element.options[i+1] = temp2;
        element.options[i+1].selected = true;
        element.options[i] = temp;
      }
    }
  }
}
function updateList(list, textBox) {
  textBox.value = '';
  for(i = 0; i < list.options.length; i++) {
    if (i == 0) {
      textBox.value += list.options[i].value;
    } else {
      textBox.value += ',' + list.options[i].value;
    }
  }
}
function swap(list) {
  var j = 0;
  for(i = 0; i < list.options.length; i++) {
    if(list.options[i].selected == true) {
      j++;
      switch (j) {
        case 1:
        var i1 = i;
        var temp = new Option(list.options[i].text, list.options[i].value);
        break;
        case 2:
        var i2 = i;
        var temp2 = new Option(list.options[i].text, list.options[i].value);
        break;
      }
    }
  }
  if (j != 2) {
    alert('Only 2 items can be swapped');
  } else {
    list.options[i1] = temp2;
    list.options[i1].selected = true;
    list.options[i2] = temp;
    list.options[i2].selected = true;
  }
}

var win=null;
function newWindow(mypage,w,h)
{
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,"new",settings);
	return false;
}

if(document.all)
{
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}
}
	
// Replaces all instances of the given substring.
String.prototype.replaceAll = function(
	strTarget, // The substring you want to replace
	strSubString // The string you want to replace in.
){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
	
	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1){
		// Relace out the current instance.
		strText = strText.replace( strTarget, strSubString )
	
		// Get the index of any next matching substring.
		intIndexOfMatch = strText.indexOf( strTarget );
	}
// Return the updated string with ALL the target strings
// replaced out with the new substring.
	return( strText );
}

function urlEncode(str) {
		return str.replaceAll(' ', '%20');
}

/** 
Partial function set taken from:
http://developer.mozilla.org/en/docs/Whitespace_in_the_DOM
**/

function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}
	
function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}
	
function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}
	
function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

