function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;                      
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}
function PersonTestNavigation() {
	var pageMem = 1;
	var pageCount = 0;
	this.naviInit = function(o) {
		this.wrapper = document.getElementById(o);
		this.children = this.wrapper.childNodes;
		for(var i = 0;i < this.children.length; i++) {
			if(this.children[i].id) {
				if(this.children[i].id.indexOf("qp") != -1) {
					pageCount++;	
				}
			}
		}
		document.getElementById('test_navi_total').innerHTML = pageCount;
	}
	this.setBox = function() {
		document.getElementById('test_navigation').style.display = "none";
		document.getElementById('test_navigation_submit').style.display = "block";
	}
	this.unSetBox = function() {
		document.getElementById('test_navigation').style.display = "block";
		document.getElementById('test_navigation_submit').style.display = "none";
	}
	this.nextPage = function() {
		this.page_id = "qp" + pageMem.toString();
		this.next_id = "qp" + (pageMem+1).toString();
		if((pageMem+1) == pageCount) {
			p_test_navi.setBox();
		} else if((pageMem+1) > pageCount) {
			return;
		}
		document.getElementById(this.page_id).style.display = "none";
		document.getElementById(this.next_id).style.display = "block";
		document.getElementById('test_navi_id').innerHTML = (pageMem+1).toString();
		pageMem++;
	}
	this.prevPage = function() {
		this.page_id = "qp" + pageMem.toString();
		this.next_id = "qp" + (pageMem-1).toString();
		if(pageMem == pageCount) {
			p_test_navi.unSetBox();
		}
		if((pageMem-1) < 1) {
			return;	
		}
		document.getElementById(this.page_id).style.display = "none";
		document.getElementById(this.next_id).style.display = "block";
		document.getElementById('test_navi_id').innerHTML = (pageMem-1).toString();
		pageMem--;
	}
}
function ExpandCollapse() {
	this.expandArea = function(o) {
		this.excol = document.getElementById(o.className + "_expand_collapse");
		this.wrapper = document.getElementById(o.className + "_wrapper");
		if(this.excol.style.display == "none") {
			this.wrapper.style.width = "auto";
			this.excol.style.display = "";
		} else {
			this.wrapper.style.width = this.excol.offsetWidth + "px";
			this.excol.style.display = "none";
		}
		
	}
}
function Menu() {
	this.menuFlip = function(o) {
		this.path = "/images/menu/";
		this.object = o;
		this.object.onmouseout = function() {
			menu.menuFlip(this);
		}
		this.source = this.object.src;
		this.source = this.source.substring(this.source.lastIndexOf("/")+1,this.source.length);
		this.source = this.source.replace(".gif","");
		this.splits = this.source.split("_");
		if(this.source.indexOf("_h") != -1) {
			this.object.src = this.path + this.splits[0] + "_" + this.splits[1] + ".gif";
		} else if(this.source.indexOf("_a") != -1) {
			return;
		} else {
			this.object.src = this.path + this.splits[0] + "_" + this.splits[1] + "_h.gif";
		}
	}
}
function MyBoxNavi() {
	var box;
	this.boxHovering = function(box_id) {
		this.box = document.getElementById(box_id);
		this.inner = getElementsByClassName(this.box, "div", "inner_content");
		this.childs = this.inner[0].childNodes;
		for(var i = 0;i < this.childs.length;i++) {
			if(this.childs[i].className) {
				if(this.childs[i].className.indexOf("row") != -1) {
					this.childs[i].onmouseover = function() {
						this.className = this.className + "_hover";
						this.onclick = function() {
							var inner = this.getElementsByTagName("a")[0];
							document.location.href = inner;
						}
						this.onmouseout = function() {
							var setback = this.className;
							setback = setback.substring(0,setback.lastIndexOf("_hover"));
							this.className = setback;
						}
					}
				}
			}
		}
	}
}
function NewsBoxNavi() {
	var box;
	this.boxHovering = function(box_id) {
		this.box = document.getElementById(box_id);
		this.inner = getElementsByClassName(this.box, "div", "inner_content");
		this.childs = this.inner[0].childNodes;
		for(var i = 0;i < this.childs.length;i++) {
			if(this.childs[i].className) {
				if(this.childs[i].className.indexOf("newsitem") != -1) {
					if(this.childs[i].className.indexOf("active") == -1) {
						this.childs[i].onmouseover = function() {
							this.className = this.className + " hover";
							this.onclick = function() {
								var inner = this.getElementsByTagName("a")[0];
								document.location.href = inner;
							}
						}
					}
					/*
					if(this.childs[i].className.indexOf("activated") != -1) {
						this.childs[i].onmouseover = function() {
							var this_inner = getElementsByClassName(this, "a", "url");
							this_inner = this_inner[0];
							this_inner.className = "url_active";
						}
					}
					*/
					if(this.childs[i].className.indexOf("active") == -1) {
						this.childs[i].onmouseout = function() {
							var setback = this.className;
							setback = setback.substring(0,setback.lastIndexOf(" hover"));
							this.className = setback;
						}
					}
				}
			}
		}
	}
}

function TableHighlighting() {
	var table;
	var mem;
	this.highlight_tr = function(table_id) {
		this.table = document.getElementById(table_id);
		for (i = 0; i < this.table.rows.length; i++) {
			this.table.rows[i].onmouseover = function() {
				if (this.className != "active" && this.className != "head") {
					this.mem = this.className;
					this.className = "highlight";
				}
			}
			this.table.rows[i].onmouseout = function() {
				if (this.className != "active" && this.className != "head") {
					this.className = this.mem;
				}
			}
			this.table.rows[i].onclick = function(e) {
				var targ;
				if (!e) var e = window.event;
				if (e.target) targ = e.target;
				else if (e.srcElement) targ = e.srcElement;
				if (targ.nodeType == 3)  { // defeat Safari bug
					targ = targ.parentNode;
				}
				if(targ.tagName == "TD") {
					var childs = this.childNodes;
					for(var i = 0;i < childs.length; i++) {
						if(childs[i].tagName == "TD") {
							var grandChild = childs[i].childNodes;
							for(var i2 = 0; i2 < grandChild.length; i2++) {
								if(grandChild[i2].type == "checkbox" && grandChild[i2].name.indexOf("check[") >= 0) {
									var checkbox = grandChild[i2];
									if(checkbox.checked) {
										checkbox.checked = false;
									} else {
										checkbox.checked = true;	
									}
									checkUser(checkbox);
								}
							}
						}
					}
				}
			}
		}
	}
}

function Buttons() {
	this.buttonHover = function(object) {
		for(var i=0;i<object.childNodes.length;i++) {
			if(object.childNodes[i].className == "button_left") {
				object.childNodes[i].childNodes[0].src = '../images/button_left_hover.gif';
			}
			if(object.childNodes[i].className == "button_right") {
				object.childNodes[i].childNodes[0].src = '../images/button_right_hover.gif';
			}
		}
		object.className = "button_hover";
		object.onmouseout = function() {
			this.className = "button";
			for(var i=0;i<this.childNodes.length;i++) {
				if(this.childNodes[i].className == "button_left") {
					this.childNodes[i].childNodes[0].src = '../images/button_left.gif';
				}
				if(this.childNodes[i].className == "button_right") {
					this.childNodes[i].childNodes[0].src = '../images/button_right.gif';
				}
			}
		}
	}
}

function Members() {
	this.changePersonality = function(object) {
		//alert(object[object.selectedIndex].value);
		document.getElementById('member_personality_image').src = '/images/person_' + object[object.selectedIndex].value + '.gif';
		//alert(document.getElementById('member_personality_image').src);
		
	}
}

var set_back_schema;

function EventSchemaNavigation() {
	this.initNavi = function(object) {
		this.schema = document.getElementById(object);
		this.inner = getElementsByClassName(this.schema, "div", "event_table");
		//alert(this.inner);
		for(var i = 0;i < this.inner.length;i++) {
			this.childs = this.inner[i].childNodes;
			for(var i_c = 0;i_c < this.childs.length;i_c++) {
				if(this.childs[i_c].className) {
					this.childs[i_c].onmouseover = function() { 
						set_back_schema = this.className;
						this.className = this.className + "_hover";
						this.onmouseout = function() {
							this.className = set_back_schema;
						}
					}
				}
				//alert(this.childs[i_c].className);
			}
		}
	}
}

function PopUps() {

	this.openWindow = function(url,w,h) {
		var posx = 50;
		var posy = 50;
		var winname = "external_url";
	
		var properties = ""; 
		properties = "resizable = 1, titlebar = 1, menubar = 1, scrollbars = 1, fullscreen = 0, toolbar = 1, location = 1, status = 1, "; 
		properties += "width = " + w + ", "; 
		properties += "height = " + h + ", ";
		properties += "left = " + posx + ", ";
		properties += "top = " + posy;
		
		window.open(url, winname, properties);
	}

	this.openPopup = function(url,w,h) {
		var posx = (screen.width - w) / 2;
		var posy = (screen.height - h) / 2;
		var winname = "external_url";
	
		var properties = ""; 
		properties = "resizable = 1, titlebar = 0, menubar = 0, scrollbars = 1, fullscreen = 0, toolbar = 0, location = 0, status = 0, "; 
		properties += "width = " + w + ", "; 
		properties += "height = " + h + ", ";
		properties += "left = " + posx + ", ";
		properties += "top = " + posy;
		
		window.open(url, winname, properties);
	}
	
	this.openDinnerPhotos = function(url) {
		var w = 400;
		var h = 510;
		var posx = (screen.width - w) / 2;
		var posy = (screen.height - h) / 2;
		var winname = "external_url";
		var properties = ""; 
		properties = "resizable = 0, titlebar = 0, menubar = 0, scrollbars = 0, fullscreen = 0, toolbar = 0, location = 0, status = 0, "; 
		properties += "width = " + w + ", "; 
		properties += "height = " + h + ", ";
		properties += "left = " + posx + ", ";
		properties += "top = " + posy;
		window.open(url, winname, properties);
	}

}

getAllPMObjects = function() {
	var objects = document.getElementsByTagName("div");
	for(var i = 0;i < objects.length;i++) {
		if(objects[i].id != "") {
			if(objects[i].id.indexOf("Obj") && !objects[i].id.indexOf("obj")) {
				objects[i].onmouseover=function() {
					this.style.background = "#DCF1F7";
					this.style.border = "1px solid #094E94";
				}
				objects[i].onmouseout=function() {
					this.style.background = "transparent";
					this.style.border = "1px solid white";
				}
			}
		}
	}
}
function returnHiddenInput(name,value){
	var elem = document.createElement("input");
	elem.type = "hidden";
	elem.name = name;
	elem.value = value;
	return elem;
}
function mkHiddenInput(form,name,value){
	var elem = returnHiddenInput(name,value);
	document.forms[form].appendChild(elem);
}

function actionSubmit(action,form,nosubmit){
	mkHiddenInput(form,'action',action);
	if(nosubmit !== 1)
		document.forms[form].submit();
}

function popupScroll(url, name, width, height) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  if (window.screen) {
    var ah = screen.availHeight - 30;
    var aw = screen.availWidth - 10;
    var xc = (aw - width) / 2;
    var yc = (ah - height) / 2;
    str += ",left=" + xc + ",screenX=" + xc;
    str += ",top=" + yc + ",screenY=" + yc;
    str += ",scrollbars=1";
  }
  window.open(url, name, str);
}

var newsboxnavi = new NewsBoxNavi();
var myboxnavi = new MyBoxNavi();
var buttons = new Buttons();
var members = new Members();
var excol = new ExpandCollapse();
var menu = new Menu();
var popups = new PopUps();
var eventschema = new EventSchemaNavigation();
var p_test_navi = new PersonTestNavigation();
var tablehilite = new TableHighlighting();

window.onload = function() {
	if(document.getElementById('pagemaker')) {
		getAllPMObjects();
	}	
	if(document.getElementById('members')) {
		tablehilite.highlight_tr('members');
	} 
	if(document.getElementById('member_signups')) {
		tablehilite.highlight_tr('member_signups');
	} 
	if(document.getElementById('newsbox')) {
		newsboxnavi.boxHovering('newsbox');
	}
	if(document.getElementById('pressbox')) {
		newsboxnavi.boxHovering('pressbox');
	}
	if(document.getElementById('mybox')) {
		myboxnavi.boxHovering('mybox');
	}
	if(document.getElementById('personality_test')) {
		p_test_navi.naviInit('personality_test');
	}
	if(document.getElementById('event_schema')) {
		eventschema.initNavi('event_schema');
	}	
}

function on(obj){ obj.style.backgroundColor="#c7e2f5"; }
function off(obj){ obj.style.backgroundColor="#eaeaea"; }

