//Pop-Up windows
function openWin(windowURL, windowName, windowFeatures) {
	window.open(windowURL, windowName, windowFeatures);
}

//this script only works in IE
var IE = (document.all) ? true : false;
function expandIt(whichEl,show){
   whichEl.style.display = (show == 'none' ) ? "none" : "";
}

function alternateAnyArea(area1id,area2id) {
	var area1 = document.getElementById(area1id);
	var area2 = document.getElementById(area2id);
	if(area1.style.display=='none') {
		area1.style.display='';
		area2.style.display='none';
	} else {
		area1.style.display = 'none';
		area2.style.display='';
	}
}

//Show/Hide Area
function toggleAnyArea(areaid) {
	for(var i=0; i<arguments.length; i++)
	{
		areaid = arguments[i];	
		var area = document.getElementById(areaid);
		if(area.style.display=='none') {
			area.style.display='';
		} else {
			area.style.display = 'none';
		}
	}
}
function toggleBio(idname,classname) {
	var area = document.getElementById(idname);
	if(area.style.display=='none') {
		show1area(idname,classname);
	} else {
		area.style.display = 'none';
	}
}


// function getElementsByClass has three arguments. Class name (first argument), DOM node (by default it's a document) and tag name (for selecting only <tag> elements with specific class). Last two arguments are optional.

//First, getElementsByClass function selects all tags (every tag '*' or tags with name 'tagName' specified by user). Afterwards, in for-loop our function checks if given class name is in the className property string. If it is, it copies found element to another array 'el' which is returned to user at the end of function. 

function getElementsByClass( searchClass, domNode, tagName) {
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var el = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " "+searchClass+" ";
	for(i=0,j=0; i<tags.length; i++) {
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			el[j++] = tags[i];
	}
	return el;
}

function show1area(idname,classname) 
{
	// hide every element with class 'classname' 
	var areas = getElementsByClass(classname);
	for(i=0; i<areas.length; i++)
		areas[i].style.display = 'none';
	// hide every element with class 'classname'		
 	// show element with given idname
	document.getElementById(idname).style.display='';
}

function DOMElement(el){
	this.label = "";
	if(arguments.length > 0){
		this.label=arguments[1];
	}
	for(i in el){
		eval("this['" + i + "']=" + "function(){ return el['" + i + "']}");
	}
	
}

DOMElement.prototype.setLabel = function(s){
	this.label = s;
}

DOMElement.prototype.getLabel = function(){
	return this.label;
}

function DuplicationListener(){
	this.order = new Array();
}

DuplicationListener.prototype.add = function(obj){
	this.order[this.order.length] = obj;
}

DuplicationListener.prototype.hasDuplicate = function(){
	for(var i=0; i<this.order.length; i++){
		iObj = this.order[i];
		iVal = iObj.value();
		for(var n=0; n<this.order.length; n++){
			nObj = this.order[n];
			nVal = nObj.value();
			if(( iObj != nObj) && iVal == nVal){
				alert("DUPLICATION ERROR\nThe following elements have duplicate values\n\n* " 
				+ iObj.getLabel() + "\n* " + nObj.getLabel()); 
				return false;
			}
		}
	}
	return true;
}
