/* basic mouseover code */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



/****************************************************************************************
****	Menu																		 ****
****************************************************************************************/
function bindMenuMouseOvers()
{
	var the_ul = document.getElementById('theMenu');
	if (the_ul == null || the_ul == undefined)
	{
		// can't find the menu, seems we're not done rendering... try again in a little bit
		setTimeout('bindMenuMouseOvers()', 250);
		return;
	}
	
	MM_preloadImages('images/sub-nav-bgd-over.gif');
	
	for (var x=0; x < the_ul.childNodes.length; x++)
	{
		try
		{
			// weed out the text nodes... if it has a tagName, then it's a list item
			if (the_ul.childNodes[x].tagName)
			{
				// IE doesn't handle :hover declarations unless it's an a tag, so do it thru javascript
				the_ul.childNodes[x].onmouseover = function () {
							this.className = 'highlight';
						};
				the_ul.childNodes[x].onmouseout = function () {
							this.className = '';
						};
				
				
				// find the link location, and send the browser there when you click on the li
				// also, disable the actual a tag... we only want one item responding to the click
				for (var y=0; y < the_ul.childNodes[x].childNodes.length; y++)
				{
					if (the_ul.childNodes[x].childNodes[y].tagName &&
						the_ul.childNodes[x].childNodes[y].tagName.toLowerCase() == 'a')
					{									
						the_ul.childNodes[x].childNodes[y].onclick = function () {
									return false;
								};

						break;
					}
				}
				
				the_ul.childNodes[x].onclick= vistLink;

			}
		}
		catch (err) { };
	}
}

function vistLink()
{
	for (var x=0; x < this.childNodes.length; x++)
	{
		if (this.childNodes[x].tagName)
		{
			location.href = this.childNodes[x].href;
			return;
		}
	}
}


/* Submit the form on the careers page */
function submitCareerForm()
{
	var theForm = document.getElementById('form1');
	var theElements = theForm.elements;
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errors = false;
	for (var x=0; x < theElements.length; x++)
	{
		if (theElements[x].id == 'how' || theElements[x].id == 'questions')
		{
			continue;
		}
	
		// trim leading and trailing spaces
		theElements[x].value = theElements[x].value.replace(/^[ ]+([^ ])/, '$1');
		theElements[x].value = theElements[x].value.replace(/([^ ])[ ]+$/, '$1');
		
		// prevent someone from entering in all spaces
		theElements[x].value = theElements[x].value.replace(/^[ ]+$/, '');
		
		if (
				(theElements[x].id == 'email' && filter.test(theElements[x].value) == false)
				|| (theElements[x].value.length == 0)
			)
		{
			theElements[x].className = 'error';
			errors = true;
		}
		else
		{
			theElements[x].className = '';
		}
	}
	
	if (errors)
	{
		document.getElementById('errMsg').className = '';
	}
	else
	{
		document.getElementById('button1').disabled = true;
		document.getElementById('button1').value = 'Submitting';
		
		theForm.action = "submit-form.php";
		theForm.submit();
	}
}


var directionsUsabilityText = 'Please enter an address';
function addressChanged()
{
	var selectBox = document.getElementById('from');
	var textBox = document.getElementById('textfield');
	if (selectBox == null || textBox == null)
		return;
	
	if (selectBox.value == '')
	{
		textBox.className = 'usability';
		textBox.value = directionsUsabilityText;
	}
	else
	{
		textBox.className = 'hide';
		textBox.value = '';
	}
}

function enterTextbox()
{
	var textBox = document.getElementById('textfield');
	textBox.className = '';
	if (textBox.value == directionsUsabilityText)
		textBox.value = '';
}

function exitTextbox()
{
	var textBox = document.getElementById('textfield');
	if (textBox.value == '')
	{
		textBox.value = directionsUsabilityText;
		textBox.className = 'usability';
	}
}


/* attach function to onload */
function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', fn, false);
  } else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  } else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  } else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    } else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}