function MM_goToURL(obj) 
{
	params = obj.value;
	
	switch (obj.id)
	{
		case 'mnuDiscontinuedSeries': 
			url = 'tractorBySeriesDisc.php';
			paramID = 'c_ID';
			break;
		case 'mnuSeries': 
			url = 'tractorBySeriesDisc.php';
			paramID = 'c_ID';
			break;
		case 'mnuModels': 
			url = 'tractorDetails.php';
			paramID = 'p_ID';
			break;
		case 'mnuHP': 
			url = 'tractorByHP.php';
			paramID = 'hp';
			break;
		case 'btnGo': 
			url = 'tractorByHP.php';
			paramID = 'hp';
			param1 = document.getElementById('mnuFrom').value
			param2 = document.getElementById('mnuTo').value

			if ((param1 < 0) || (param2 < 0))
			{
            alert ("Please select both FROM HP and TO HP.")
			   return
			}
			else if (param1 > param2) 
			{
				alert ("The FROM HP cannot be more than the TO HP.")
				return
			}
			else
			{
				params = document.getElementById('mnuFrom').value
				params += "," + document.getElementById('mnuTo').value
			}
			break;
		case 'mnuPrice': 
			url = 'tractorByPrice.php';
			paramID = 'p_PRICE';
			break;
	}

	if (params == 'custom')
	{
		document.getElementById('customRange').style.display = 'block';
		document.getElementById('mnuHP').style.border="3px solid red";
		return;
	}
  else if (document.getElementById('customRange'))
	{
		document.getElementById('customRange').style.display = 'none';
		document.getElementById('mnuHP').style.border="";
		document.getElementById('mnuHP').selectedIndex = 0;
		document.getElementById('mnuFrom').selectedIndex = 0;
		document.getElementById('mnuTo').selectedIndex = 0;
	}

	if (params == 0) return;

	parent.location = url + "?" + paramID + "=" + params;
}

function addToList(list1, list2)
{	
	document.getElementById(list1).innerHTML = "";
	document.getElementById(list2).innerHTML = "";

	for (i=0; i<aryFeatures.length; i++)
	{
		ht1 = document.getElementById(list1).offsetHeight;
		ht2 = document.getElementById(list2).offsetHeight;

		str = "<li>" + aryFeatures[i] + "</li>"

		if (ht1 > ht2) list = list2; else list = list1;
		document.getElementById(list).innerHTML += str + "\n"
	}
}

function validateForm ()
{
	for (var i=0; i< document.forms.frmEmail.length; i++)
	{
		x = document.forms.frmEmail[i];
		x.onchange = changeToBlack;  // register event handler
		if ((x.name != "Email") && (x.name != "Name")) continue;  

		if ((x.value.length < 1) || (x.value == 'required field'))
		{
			alert ('The ' + x.name + ' field is required.');
			x.value = "required field";
			x.focus();
			x.select();
			x.style.color = 'red';
			return false;
		}
		
		if (x.name == "Telephone")
		{
			var str = x.value;
			    str = str.replace(/\D/g,'');
			var reg = /^[1]?[0-9]{10}$/
			var bool = reg.test(str);
			if (! bool) 
			{
				alert('The telephone number format is not correct.\nPlease use the following format: xxx-xxx-xxxx.');
				x.focus();
				x.select();
				x.style.color = 'red';
				return false;
			}
		}

		if (x.name == "Email")
		{
			var reg = /.+@.*\..+/;  //match emali address
			var bool = reg.test(x.value);
			if (! bool)
			{
				alert('The email address is not correct');
				x.focus();
				x.select();
				x.style.color = 'red';
				return false;
			}
		}
	}
}

function changeToBlack()
{
	this.style.color = 'black';
}

function getXMLHttpRequest()
{
  var page_request = false 

  if (window.XMLHttpRequest) 
  { // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
  }     
  else if (window.ActiveXObject)
  { // if IE 
    try         
    {           
      page_request = new ActiveXObject("Msxml2.XMLHTTP")
    }           
    catch (e)   
    {           
      try               
      {                 
        page_request = new ActiveXObject("Microsoft.XMLHTTP")
      }                 
      catch (e)         
      {                 
      }                 
    }           
  }     
  return page_request
}

function validateInquiryForm ()
{
	for (var i=0; i< document.forms.frmDealerInquiry.length; i++)
	{
		x = document.forms.frmDealerInquiry[i];
		x.onchange = changeToBlack;  // register event handler
		if ((x.name != "Contact") && (x.name != "Email") && (x.name != "Telephone") && (x.name != "State") && (x.name != "ZipCode")) continue;  

		if ((x.value.length < 1) || (x.value == 'required field'))
		{
			alert ('The ' + x.name + ' field is required.');
			x.value = "required field";
			x.focus();
			x.select();
			x.style.color = 'red';
			return false;
		}
		
		if (x.name == "Telephone")
		{
			var str = x.value;
			    str = str.replace(/\D/g,'');
			var reg = /^[1]?[0-9]{10}$/
			var bool = reg.test(str);
			if (! bool) 
			{
				alert('The telephone number format is not correct.\nPlease use the following format: xxx-xxx-xxxx.');
				x.focus();
				x.select();
				x.style.color = 'red';
				return false;
			}
		}

		if (x.name == "Email")
		{
			var reg = /.+@.*\..+/;  //match emali address
			var bool = reg.test(x.value);
			if (! bool)
			{
				alert('The email address is not correct');
				x.focus();
				x.select();
				x.style.color = 'red';
				return false;
			}
		}
	}
}
