﻿
function getbc(region,locationID)
{
	size=locationID.length
	for (x=0;x<size;x++)
		{
			locationID.remove(0);
		}
		
	locationID.length+=1; //add 1 to the length of array
	locationID.options[locationID.length-1].value='';
	locationID.options[locationID.length-1].text='Please select...';

	for (x=0;x<locationcomp.length;x++)
		{
			if (regioncomp[x]==form.region.value)
			{
				locationID.length+=1;
				locationID.options[locationID.length-1].value=locationcomp[x];
				locationID.options[locationID.length-1].text=locname[x];
			}
		}
}

/*
function validateData() {
	if (submitted)
	{
		alert('You may not submit this page more than once')
		return false;
	}
	if (form.firstname.value=='')
	{
		alert('Please fill in your first name.');
		form.firstname.focus();
		return false;
	}
	if (form.surname.value=='')
	{
		alert('Please fill in your surname.');
		form.surname.focus();
		return false;
	}
	if (form.email.value=='')
	{
		alert('Please fill in your email address.');
		form.email.focus();
		return false;
	}
	if (form.contact.value=='')
	{
		alert('Please fill in your office number.');
		form.contact.focus();
		return false;
	}
	if (form.region.value=='0')
	{
		alert('Please select your geographical region.');
		form.region.focus();
		return false;
	}
	if (form.locationID.value=='0' || form.locationID.value=='')
	{
		alert('Please select your local dealership.');
		form.locationID.focus();
		return false;
	}
	if (form.Model.selectedIndex=='0')
	{
		alert('Please select a model.');
		form.Model.focus();
		return false;
	}
	if (form.TypeOfPurchase.selectedIndex=='0')
	{
		alert('Please select your purchase type.');
		form.TypeOfPurchase.focus();
		return false;
	}
	submitted=true
	return true;
}
*/

function validateData() {

	var tradein_selected = getRadioValue("tradein");
	if (submitted)
	{
		alert('You may not submit this page more than once')
	}
	else if (document.forms[0].firstname.value=='')
	{
		alert('Please fill in your first name.');
		document.forms[0].firstname.focus();
	}
	else if (document.forms[0].surname.value=='')
	{
		alert('Please fill in your surname.');
		document.forms[0].surname.focus();
	}
	else if (document.forms[0].email.value=='')
	{
		alert('Please fill in your email address.');
		document.forms[0].email.focus();
	}
	else if (document.forms[0].contact.value=='' || document.forms[0].contact.value.length<10)
	{
		alert('Please fill in your 10 digit office number, including area code, with no spaces, eg: 0111234567.');
		document.forms[0].contact.focus();
	}
	else if (document.forms[0].cell.value=='' || document.forms[0].cell.value.length<10)
	{
		alert('Please fill in your 10 digit cell phone number with no spaces, eg: 0821234567.');
		document.forms[0].cell.focus();
	}
	else if (document.forms[0].region.selectedIndex==0)
	{
		alert('Please select your geographical region.');
		document.forms[0].region.focus();
	}
	else if (document.forms[0].dealerid.selectedIndex == 0 || document.forms[0].dealerid.value == '')
	{
		alert('Please select your local dealership.');
		document.forms[0].dealerid.focus();
	}
	else if (document.forms[0].Model.selectedIndex==0)
	{
		alert('Please select a model.');
		document.forms[0].Model.focus();
	}
	else if (document.forms[0].TypeOfPurchase.selectedIndex==0)
	{
		alert('Please select your purchase type.');
		document.forms[0].TypeOfPurchase.focus();
	}
	else if ( (tradein_selected==1) && (document.forms[0].tradein_year.selectedIndex==0) )
	{
		alert('Please select the year of your trade-in vehicle.');
		document.forms[0].tradein_year.focus();
	}
	else if ( (tradein_selected==1) && (document.forms[0].tradein_brand.selectedIndex==0) )
	{
		alert('Please select the make of your trade-in vehicle.');
		document.forms[0].tradein_brand.focus();
	}
	else if ( (tradein_selected==1) && (document.forms[0].tradein_model.selectedIndex==0) )
	{
		alert('Please specify the model of your trade-in vehicle.');
		document.forms[0].tradein_model.focus();
	}
	else if ( (tradein_selected==1) && (isNaN(parseInt(document.forms[0].tradein_value.value))) )
	{
		
		alert('Please fill in the estimated numerical value of your trade-in. (No spaces or commas!)');
		document.forms[0].tradein_value.focus();
	}
	else
	{
		submitted=true;
		document.forms[0].submit();
	}
}

function getRadioValue(radioName) 
{
  var collection;
  collection = document.all[radioName];
  for (i=0; i<collection.length; i++) 
  {
    if (collection[i].checked)
		return(collection[i].value);
  }
}

function ShowHideTradein(strValue)
{
	tr_Tradein.style.display=strValue;
}

function ShowHideDeposit(strValue)
{
	tr_deposit.style.display=strValue;
}

