//
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') {
			if (typeof(p)=='object'){
				p.style.display='inline';
			}
			if (typeof(m)=='object'){
				m.style.display='none';
			}
			o.style.display='none';
		} else {
			if (o.style.display=='none' || o.style.display=='') {
				if (typeof(p)=='object'){
					p.style.display='none';
				}
				if (typeof(m)=='object'){
					m.style.display='inline';
				}
				o.style.display='block';
			}
		}
	}
}

var currentCharacter;

function fCharacterPlus(d){
	if (typeof(currentCharacter)=='object'){
		if (currentCharacter.style.display=='block') {
			currentCharacter.style.display='none';
		} else {
			currentCharacter.style.display='block';
		}
	}
	if (typeof(d)=='object'){
		if (d.style.display=='block') {
			d.style.display='none';
		} else {
			d.style.display='block';
		}
		currentCharacter = d;
		return false;
	}
}

function ExpandOrCollapseAndShift(p,m){
	if (typeof(p.style)=='object' && typeof(m.style)=='object'){
		if (m.style.display=='block') {
			if (typeof(m)=='object'){
				m.style.display='none';
			}
			if (typeof(p)=='object'){
				p.style.display='block';
			}
			Bottom.style.posTop-=150;
		} else {
			if (typeof(p)=='object'){
				p.style.display='none';
			}
			if (typeof(m)=='object'){
				m.style.display='block';
			}
			Bottom.style.posTop+=150;
		}
	}
}

function displaySubModels(modelCode) {
	var objBlock = document.getElementById(modelCode);
	if (objBlock.style.display == "inline") {
		objBlock.style.display = "none";
	} else {
		objBlock.style.display = "inline";
	}
};


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()
{

// set var checkbox_choices to zero

var checkbox_choices = 0;
checkbox_choices = checkBoxArrayCnt("optionid");


if (checkbox_choices > 3 )
{
// If there were more than three selections made display an alert box 
msg="You're limited to only three selections.\n"
msg=msg + "You have made " + checkbox_choices + " selections.\n"
msg=msg + "Please remove " + (checkbox_choices-3) + " selection(s)."
alert(msg)
return (false);
}


if (checkbox_choices < 3 )
{
// If there were less then selections made display an alert box 
alert("Please make three selections. \n" + checkbox_choices + " entered so far.")
return (false);
}

// If three were selected then display an alert box stating input was OK
//alert(" *** Valid input of three outfielders was entered. ***");
return (true);
}

var elem;

function toggleLayer( 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 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 togglePlusMinus( obj) {
var filter;

	filter = /\/images\/minus\.gif$/;
	obj.src = (filter.test(obj.src))?'/images/plus.gif':'/images/minus.gif';
}

/*Checks form*/
function checkrequired(which,placeHolderTxt) {
	var pass=true;
	if (document.images) {
	for (i=0;i<which.length;i++) {
	var tempobj=which.elements[i];
	if (tempobj.name.substring(0,8)=="email") {
	if (((tempobj.type=="text"||tempobj.type=="textarea")&&
	tempobj.value=='') || (tempobj.value==placeHolderTxt) ||(tempobj.type.toString().charAt(0)=="s"&&
	tempobj.selectedIndex==0)) {
	pass=false;
	break;
			 }
		  }
	   }
	}

	if (!pass) 
		{
		shortFieldName=tempobj.name.substring(8,30).toUpperCase();
		field_completed = 'Please make sure the E-mail Address field was properly completed.';
		if (field_completed != '')
			{
			alert(field_completed);
			}
		else
			{
			alert("Please make sure the E-mail Address field was properly completed.");
			}
		return false;
		}	
	else 
		{
		//noPopUp();
		return true;
		}
}
