var win= null;
function PopUpWindow(mypage,myname,w,h,scroll,resizeable){
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable='+resizeable+',';
  win=window.open(mypage,myname,settings);
  if (win.opener == null) {  // for Nav 2.0x
      win.opener = self  // this creates and sets a new property
   }
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function setClass (elementName, className) {
	var theElement = document.getElementById(elementName);
	theElement.className = className;
}

function getElementPageLeft(element, x) {
	var x, obj;
    obj = element;
    while (obj.offsetParent != null) {
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
    x += obj.offsetLeft;
    return x;
}

function getElementPageTop(element, y) {
	var y, obj;
    obj = element;
	while (obj.offsetParent != null) {
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
    y += obj.offsetTop;
    return y;
}

function showElement(elementName) {
	var theElement = document.getElementById('menuLayer' + elementName);
	if(theElement)
		theElement.style.display = "block";
}

function hideElement(elementName) {
	var theElement = document.getElementById('menuLayer' + elementName);
	if(theElement)
		theElement.style.display = "none";
}

function initMenu(elementName, x, y) {
	
	var img = document.getElementById("menuPlace" + elementName);
	
	x = getElementPageLeft(img, x);
	y = getElementPageTop(img, y);
	var menuLayer = document.getElementById("menuLayer" + elementName);
	if(menuLayer){

		x = x - 100;
		y = y + 46;
		menuLayer.style.left = x + "px";
		menuLayer.style.top = y + "px";
		
	}
}

function dynamicSelect()
{
	this.selects = new Array();
	
	this.addSelect = function(name)
	{
		this.selects[name] = new selectObj();
	}
	
	this.updateOptions = function(source, target)
		{
			var form = source.form;
			var target = form.elements[target];
			var value = source.options[source.selectedIndex].value;
			
			while(target.options.length) target.remove(0);
			
			if(!this.selects[source.name].options[value])
			{
				//alert('Invalid selection.'); //For debugging while you set it up
				return;
			}
			
			var data = this.selects[source.name].options[value].options;
			
			for(var x=0; x<data.length; x++)
			{
				try
				{
					target.add(data[x]);
				}
				catch(e)
				{
					target.add(data[x], null);
				}
			}
			
			target.selectedIndex = 0;
		}
	
	}

function selectObj()
{
	this.options = new Array();
	
	this.addOption = function(value)
	{
		this.options[value] = new optionObj();
	}
}

function optionObj()
{
	this.options = new Array();
	
	this.createOption = function(name, value)
	{
		this.options[this.options.length] = new Option(name, value);
	}
}