﻿function swap_content( span ) {
	displayType = ( document.getElementById( span ).style.display == 'none' ) ? '' : 'none';
	document.getElementById( span ).style.display = displayType;
	}
function swap_content_off( span ) {
	document.getElementById( span ).style.display = 'none';
	}
function swap_content_on( span ) {
	document.getElementById( span ).style.display = '';
	}

var newWindow
function popUp(template,properties,cent) {
	newWindow = window.open(template,"thewin",properties);
	newWindow.focus();
	
	if (cent){
	newWindow.window.moveTo(
		 ((screen.availWidth-newWindow.outerWidth)/2), ((screen.availHeight-newWindow.outerHeight)/2) 
		 );
	}
}

function ALLChoice(field, i) {
  var checkcount = 0;
  var loop;
  for (loop = 1; loop < field.length; loop++){
    if (i == 0){
      	field[loop].checked = field[0].checked;
    	}
    else{
     	if (field[loop].checked){
        	checkcount++;
      	}
  		field[0].checked = (checkcount == field.length-1);
    	}
  	}
}

function addEvent(obj, evType, fn){
if (obj.addEventListener){
	obj.addEventListener(evType, fn, false);
	return true;
} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
} else {
	return false;
}
}

function swapDisplayOnClass(declass){
	var hero = getElementsByClass(declass,document,'*');
  for (var i = 0; i < declass.length; i++) {
		try {hero[i].style.display = "";}
		catch(err){}
	}
}

function swapDisplayOffClass(declass){
	var hero = getElementsByClass(declass,document,'*');
  for (var i = 0; i < declass.length; i++) {
	try {hero[i].style.display = 'none';}
	catch(err){}
	}
}
function swapDisplayClass(declass){
	var hero = getElementsByClass(declass,document,'*');
  for (var i = 0; i < declass.length; i++) {	
		displayType = ( hero[i].style.display == 'none' ) ? '' : 'none';
		try {hero[i].style.display = displayType;}
		catch(err){}
  }
}
	
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}