var Core = {};

Core.getElementsByClass = function(theClass) {
    var elementArray = [];

    if (document.all)
    {
    elementArray = document.all;
    }
    else
    {
    elementArray = document.getElementsByTagName("*");
    }

    var matchedArray = [];
    var pattern = new RegExp("(^| )" + theClass + "( |$)");

    for (var i = 0; i < elementArray.length; i++)
    {
    if (pattern.test(elementArray[i].className))
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
    }

    return matchedArray;
};

function hideClass(classObj) {
    var list = Core.getElementsByClass(classObj);
    for (var i = 0; i < list.length; i++) {
    list[i].style.display = 'none';
    }
}

function showDiv(divObj,displayType) {
    if(displayType) { 
        if (displayType == 'table-row-group') {displayType = 'block'}
        document.getElementById(divObj).style.display=displayType;
    } else {
        document.getElementById(divObj).style.display='block';
    }
}

function hideDiv(divObj) {
    document.getElementById(divObj).style.display='none';
}

function revertClass(classObj) {
    var list = Core.getElementsByClass(classObj);
    for (var i = 0; i < list.length; i++) {
    list[i].className = classObj;
    }
}

function athletic(thid) {
	var tabs = Core.getElementsByClass('tab');
	var tabcon = Core.getElementsByClass('tabConHolder');
	for (var i = 0; i < tabs.length; i++) {
    	if (tabs[i] == thid) {
			tabs[i].className = 'tab tabActive';
			tabcon[i].className = 'tabConHolder tabConHolderActive';
		} else {
			tabs[i].className = 'tab';	
			tabcon[i].className = 'tabConHolder';
		}
    }
	
}

function showCon(elid) {
	var link01 = document.getElementById('link01');
	var link02 = document.getElementById('link02');
	link01.style.background = '#4c698a';
	link01.style.color = '#a6b3c2';
	link02.style.background = '#4c698a';
	link02.style.color = '#a6b3c2';
	elid.style.background = 'none';
	elid.style.color = '#fff';
	hideClass('homeBoxCon');
	document.getElementById(elid.id + 'Con').style.display = 'block';
}

function collapse() {
	if (document.getElementById('topAthleticColl')) {
		document.getElementById('topAthleticColl').style.height = '20px';
		document.getElementById('topAthleticColl').style.overflow = 'hidden';
		document.getElementById('topAthleticColl').id = 'topAthleticExp';
	} else {
		document.getElementById('topAthleticExp').style.height = 'auto';
		document.getElementById('topAthleticExp').id = 'topAthleticColl';		
	}
}

//start menu script
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	var sfElr = document.getElementById("navigationRight").getElementsByTagName("div");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	for (var i=0; i<sfElr.length; i++) {
		sfElr[i].onmouseover=function() {
			this.className+=" gfhover";
		}
		sfElr[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" gfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//end menu script


// for admin

function updateNavItem(navid){
    ColdFusion.Window.create('navManageWindow' + navid,'Nav Management','/admin/includes/popNavManage.cfm?navid=' + navid, {x:100,y:100,height:500,width:600,modal:true,closable:true,draggable:true,resizable:true,center:true,  initshow:false,minheight:200,minwidth:200,refreshOnShow:true});
    ColdFusion.Window.show("navManageWindow" + navid);
}

function resortNavGroup(parentid){
    ColdFusion.Window.create('navSortWindow' + parentid,'Sort Nav Group','/admin/includes/popNavSort.cfm?parentid=' + parentid, {x:100,y:100,height:500,width:600,modal:true,closable:true,draggable:true,resizable:true,center:true,  initshow:false,minheight:200,minwidth:200,refreshOnShow:true});
    ColdFusion.Window.show("navSortWindow" + parentid);
}

function valFilename(fname) {
var fnameVal = fname.fileName.value;
if (/^[A-Za-z0-9_]+$/.test(fnameVal))
     {
       return true;}
else
     {
       alert("A valid filename is required \n(alphanumeric characters and underscores only)");
       return false;
     }


}

// validate forms
function valFieldsNote() {

 valError1 = 0;
 eMsg="";
 revertClass('formField');


 if (document.noteForm.subject.value == "") {
    document.noteForm.subject.className =  "formField formFieldError";
    valError1 = 1;
 }

 if (document.noteForm.text.value == "") {
    document.noteForm.text.className =  "formField formFieldError";
    valError1 = 1;
  }

 if (valError1 == 1) {
    eMsg = eMsg + "Subject and Note are required";
 }

 if (eMsg != "") {
    document.getElementById('errorBlockNote').innerHTML = eMsg;
    showDiv('errorBlockNote');
 	return false;
 	}

 	 return true;


 }
