// JavaScript Document

// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function toggleLayer2( whichLayer ){  
var vis;  

if( document.getElementById ) // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
else if( document.all ) // this is the way old msie versions work 
	elem = document.all[whichLayer];  
else if( document.layers ) // this is the way nn4 works 
	elem = document.layers[whichLayer];  
	
if (elem != null) {
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
}

function count_all(name, pTbx) {  
	var intCount;
	var obj = document.getElementById(pTbx);
	
	intCount = 0;
	
	for (i = 0; i < forminputs.length; i++) {  
		// regex here to check name attribute 
		var regex = new RegExp(name, "i"); 
		if (regex.test(forminputs[i].getAttribute('name'))) { 
			if (forminputs[i].checked == true) { 
				intCount++;
			} 
		} 
	}
	
	if ( intCount > 0) {
		obj.style.color = '#FF0000';
	} else {
		obj.style.color = '#000000';
	}
	
	obj.value = intCount;
}

function select_all(name, value) {  
	for (i = 0; i < forminputs.length; i++) {  
		// regex here to check name attribute 
		var regex = new RegExp(name, "i"); 
		if (regex.test(forminputs[i].getAttribute('name'))) { 
			if (value == '1') { 
				forminputs[i].checked = true;  
			} else {  
				forminputs[i].checked = false;
			}
		} 
	}
}

function checkAll(pForm, pCbx){
	for (var i=0;i<document.forms[0].elements.length;i++)
	{
		var e=document.forms[0].elements[i];
		if ((e.name = pCbx) && (e.type=='checkbox'))
		{
			e.checked=document.forms[0].a1.checked;
		}
	}
}


function togglePlusMinus( obj) {
var filter;

	filter = /\/images\/minus\.gif$/;
	obj.src = (filter.test(obj.src))?'/images/plus.gif':'/images/minus.gif';
}

function sortSelect(obj) {
	var o = new Array();
	if (!hasOptions(obj)) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}
	
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}
	
function ExpandOrCollapse(o,p,m){
	if (typeof(o.style)=='object'){
		if (o.style.display=='block') {
			p.style.display='inline';
			m.style.display='none';
			o.style.display='none';
		} else {
			if (o.style.display=='none' || o.style.display=='') {
				p.style.display='none';
				m.style.display='inline';
				o.style.display='block';
			}
		}
	}
}

function togglePlusMinus( obj) {
var filter;

	filter = /\/images\/minus\.gif$/;
	obj.src = (filter.test(obj.src))?'/images/plus.gif':'/images/minus.gif';
}

function ExpandOrCollapseAndShift(p,m){
	if (typeof(p.style)=='object' && typeof(m.style)=='object'){
		if (m.style.display=='block') {
			m.style.display='none';
			p.style.display='block';
			Bottom.style.posTop-=150;
		} else {
			p.style.display='none';
			m.style.display='block';
			Bottom.style.posTop+=150;
		}
	}
}

var elem;
var objPrevLayer;

function fCharacterPlus(whichLayer){
var vis;  

if ( objPrevLayer != null) {
		vis = objPrevLayer.style;
		vis.display = 'none';
}

if( document.getElementById ) { // this is the way the standards work    
	elem = document.getElementById( whichLayer );  
} else if( document.all ) { // this is the way old msie versions work 
	elem = document.all[whichLayer];  
} else if( document.layers ) {// this is the way nn4 works 
	elem = document.layers[whichLayer];  
}

objPrevLayer = elem;

if (elem != null) {
	vis = elem.style;  // if the style.display value is blank we try to figure it out here  
	vis.display = 'block';
}
}

var elem2;

function fCharacterPlus2(whichLayer){
var vis;  

if( document.getElementById ) { // this is the way the standards work    
	elem2 = document.getElementById( whichLayer );  
} else if( document.all ) { // this is the way old msie versions work 
	elem2 = document.all[whichLayer];  
} else if( document.layers ) {// this is the way nn4 works 
	elem2 = document.layers[whichLayer];  
}

if (elem2 != null) {
	vis = elem2.style;  // if the style.display value is blank we try to figure it out here  
	if (vis.display == 'block' | vis.display == '') {
		vis.display = 'none';
	} else {
		vis.display = 'block';
	}
}
}


function fCharToggle(d) {
	var img;
	
	if (typeof(d)=='object'){
		if (d.style.display=='block') {
			d.style.display='none';
			img = document.getElementById("image_" + d.id);
			img.src = '/images/plus.gif';
		} else {
			d.style.display='block';
			img = document.getElementById("image_" + d.id);
			img.src = '/images/minus.gif';
		}
		return false;
	}
}


function getObj(objId, formId) {
         var fullId = objId;
         if (formId != null && formId.length > 0) {
                 fullId = formId + ':' + objId;
         }
         //alert('getting object: ' + fullId);
         var elem = null;
         if (document.getElementById) {
                 elem = document.getElementById(fullId);
         } else if (document.all) {
                 elem = document.all[fullId];
         } else if (document.layers) {
                 elem = document.layers[fullId];
         }
         return elem;
}

function checkBoxArrayCnt(arrayId) {
	var x = 0;
	
         for (i = 0; ; i++) {
                 id = arrayId + '[' + i + ']';
                 elem = getObj(id);
                 if (elem == null) {
                         break;
                 } else {
					 if (elem.checked == true) {
						  x = x + 1;
					 }
                 }
         }
     return x;
 }
 
function checkbox_checker(pCBX)
{

//alert(pCBX);
// set var checkbox_choices to zero

var checkbox_choices = 0;
checkbox_choices = checkBoxArrayCnt(pCBX);


if (checkbox_choices > 1 )
{
// If there were more than three selections made display an alert box 
msg="You're limited to only one selection.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-1) + " selection(s)."
alert(msg)
return (false);
}


if (checkbox_choices < 1 )
{
// If there were less then selections made display an alert box 
alert("Please make one selections. \n" + checkbox_choices + " entered so far.")
return (false);
} else {
// If three were selected then display an alert box stating input was OK
//alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}

}
