function showNav(menu, on)
{
	menuDiv = document.getElementById(menu);
	container = document.getElementById('subnav_container');
	
	if(menuDiv == null)
		return;
	else if(on)
	{
		container.style.display = 'block';
		menuDiv.style.visibility = 'visible';
		rest = getElementsByClass('menu_item');
		
		for(i = 0; i < rest.length; i++)
		{
			if(rest[i] != menuDiv)
				rest[i].style.visibility = 'hidden';
		}
	}
	else
	{
		container.style.display = 'none';
		menuDiv.style.visibility = 'hidden';
	}
}

function hideNav()
{
	menu = document.getElementById('subnav_container');
	menu.style.display = 'none';
}

function eventRowHover(row, on)
{
	if(on)
		row.style.border = '2px black solid';
	else
		row.style.border = '0px';
}

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;
}

function checkamount(amount)
{
	if(amount.value.length == 0)
	{
		alert('Please enter a valid amount.');
		return false;
	}
	var validformat = RegExp('^-?[0-9]*(\.[0-9]{1,2})?$')
	var isvalid = validformat.test(amount.value);
	if(!isvalid)
	{
		amount.select();
		alert('Please enter a valid amount.');
	}
	return isvalid
}

function checkdate(input)
{
	if(!checkDateString(input.value))
	{
		input.select();
		return false;
	}
	
	return true;
}

function checkDateString(val)
{
	var validformat=/^[0-1]??[0-9]\/[0-3]??[0-9]\/\d{4}$/ 
	var returnval=false
	if (!validformat.test(val))
		alert('Invalid Date Format (mm/dd/yyyy). Please correct and submit again.')
	else
	{ 
		var monthfield=val.split('/')[0]
		var dayfield=val.split('/')[1]
		var yearfield=val.split('/')[2]
		var dayobj = new Date(yearfield, monthfield-1, dayfield)
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
			alert('Invalid Day, Month, or Year range detected. Please correct and submit again.')
		else
			returnval=true
	}
		
	return returnval
}

function checkdate2(month, day, year)
{
	var val = month + "/" + day + "/" + year;
	return checkDateString(val);
}

function checktime(input)
{
	var validformat = /^[0-1]??[0-9]:[0-5][0-9]$/
	var returnval = false
	if(!validformat.test(input.value))
		alert('Invalid time format (HH:mm). Please correct and submit again.');
	else
		returnval = true
		
	return returnval
}

function checkemail(input)
{
	if(input.value.length == 0 || (input.value.indexOf(".") < 2) || (input.value.indexOf("@") < 0))
		return false;
	else
		return true;
}

function loadXMLDoc(dname) 
{
	try //Internet Explorer
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  }
	catch(e)
	  {
	  try //Firefox, Mozilla, Opera, etc.
	    {
	    xmlDoc=document.implementation.createDocument("","",null);
	    }
	  catch(e) {alert(e.message)}
	  }
	try 
	  {
	  xmlDoc.async=false;
	  xmlDoc.load(dname);
	  return(xmlDoc);
	  }
	catch(e) {alert(e.message)}
	return(null);
}

var xmlHttp;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

function validateVote(numVotes, f)
{
	var options = f['option[]'];
	var counter = 0;
	
	for(i = 0; i < options.length; i++)
	{
		if(options[i].checked)
			counter++;
	}
	
	if(counter == 0)
	{
		alert("You must make a selection.");
		return false;
	}
	else if(counter > numVotes)
	{
		alert("You can only select " + numVotes + " choices. You selected " + counter + ".");
		return false;
	}
	
	return true;
}
