//var ROOT = "/riverside/website/v5"
var ROOT = ""

var ERR_MSG_CLASSNAME = "errmsg";
var ERR_INPUT_CLASSNAME = "error";


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('largeBoatImage');
	if(imageObj)
	{
		imageObj.src = ROOT + "/uploadedimages/large_" + newSrc;		
		imageObj.alt = newCaption;
	}
}

function changeNewBoatImage(newSrc, newCaption, boatPath)
{
	imageObj = document.getElementById('largeBoatImage');
	if(imageObj)
	{
		imageObj.src = ROOT + "/images/new-boats/" + boatPath + "/large_" + newSrc;		
		imageObj.alt = newCaption;
	}
}

function changeFunYakImage(newSrc, newCaption, boatPath)
{
	imageObj = document.getElementById('largeBoatImage');
	if(imageObj)
	{
		imageObj.src = ROOT + "/images/fun-yaks/" + boatPath + "/" + 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) {}
}
	
function showLoader(element, position) {
	
	if (!$(element)) { return false; }
	
	id = element.id + "_loader";
	
	if (!$(id)) {
	
		HTML = "\n<img src=\""+ROOT+"/images/loading.gif\" id=\""+id+"\" alt=\"Loading\" />\n";
		
		
		switch(position) {
			case "after":
				new Insertion.After(element, HTML);
				break;
			case "before":
				new Insertion.Before(element, HTML);
				break;
		}
	
	}
	
	if ($(id)) {
		return $(id);
	}
	else {
		return null;
	}
	
}

function removeLoader(element) {
	if (element) {
		new Effect.Fade(element, { afterFinish:function() { element.remove(); }});
	}
}

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 load() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(52.331071,-0.01700), 13);
          var latlng = new GLatLng(52.322071, -0.00700);
          map.addOverlay(new GMarker(latlng));	
  }
}
