﻿function getElementsByClassName(className, tag, elm){
    var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
    var tag = tag || "*";
    var elm = elm || document;
    var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
    var returnElements = [];
    var current;
    var length = elements.length; 
    for(var i=0; i<length; i++){
	    current = elements[i]; 
	    if(testClass.test(current.className)){
		    returnElements.push(current);
	    }
    }
    return returnElements;
}

function collectionToArray(col)
{
    a = new Array();
    for (i = 0; i < col.length; i++)
	    a[a.length] = col[i];
    return a;
}

function SwitchView(to, switchme)
{
    var els = getElementsByClassName("tabBlock","DIV", byId(switchme));
    var length = els.length;
    for(var i=0; i<length; i++){
        hideShow(els[i],true);
        byId('tab_' + els[i].id).className = "";
    }
    hideShow(byId(to),false);
    byId('tab_' + to).className = "active";
}

function toggleVis(el)
{
    (el.style.display == "none") ? hideShow(el,false) : hideShow(el,true);
}

function hideShow(el,hide)
{
    (hide) ? el.style.display = "none" : el.style.display = "block"
}

function clearForm(el)
{
    var elm;
    form = document.getElementById(el);
    elements = collectionToArray(form.getElementsByTagName('input'));
    selelements = collectionToArray(form.getElementsByTagName('select'));
    elements = elements.concat(selelements);
    for (i = 0; i < elements.length; i++)
    {
        elm = elements[i];
	    if (elm.getAttribute('type') == "hidden" || elm.getAttribute('type') == "text" || elm.getAttribute('type') == "file" || elm.type == "select-one")
	    {
		    elm.value = '';
	    }
	    else if (elm.getAttribute('type') == "checkbox")
	    {
	        elm.checked = false;
	    }
    }
}

function winPop(mypage, myname, w, h, scroll, tool, menu)
{
 var winl = (screen.width - w) / 7;
 var wint = (screen.height - h) / 7;
 winprops =  'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,toolbar='+tool+',menubar='+menu+',status=no,'
 win = window.open(mypage, myname, winprops)
 if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
 return false;
}

function launchWindow(mypage,myname,w,h,t,attribs) {		// myname cannot contain whitespace
	popblocked = false;
	win = this.window;
	if (myname == null) 	{ myname = 'newWindow';	}	
	if (w == null) 			{ w = 720;	}
	if (h == null) 			{ h = 500;	}
	if (t == null) 			{ t = 80;	}	
	if (attribs == null) 	{ attribs = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes'	}	
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var wint = t;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+attribs
	win = eval(window.open(mypage, myname, winprops));
	if (win == null) {
		popblocked = true;
		alert('Please disable your popup blocking software');
	}
	else {		
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	}
}