// dem 02/28/08


//privacy notice pop-up
function Pop1(page) {
OpenWin = this.open(page, "Pop1", "width=450,height=350,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
}

//check form for Locator function
function chkLocator(f) {
	if (f.VehiclePurchaseDate.selectedIndex == 0) {
		alert ("Please select - PURCHASE DATE");
		f.VehiclePurchaseDate.focus();
		return false;
	}		
	
	if  (!checkinteger(f.VehicleMinPrice.value)) {
    if  (!onError("Please enter [FROM Price] as a whole number!")) {
			f.VehicleMinPrice.focus();
			return false; 
		}
	}

	if  (!checkinteger(f.VehicleMaxPrice.value)) {
    if  (!onError("Please enter [TO Price] as a whole number!")) {
			f.VehicleMaxPrice.focus();
			return false; 
		}
	}

	if (f.FirstName.value == "") {
		alert ("Please enter - FIRST NAME");
		f.FirstName.focus();
		return false;
	}			

	if (f.LastName.value == "") {
		alert ("Please enter - LAST NAME");
		f.LastName.focus();
		return false;
	}			

	var itemchecked = false;
	for(var i = 0 ; i < f.ContactMethod.length ; ++i) {
		if(f.ContactMethod[i].checked) {
			itemchecked = true;
			break; }
	}
	if(!itemchecked) { 
		alert ("Please Select Contact Method");
		f.ContactMethod[0].focus();
		return false; }


	if(f.ContactMethod[0].checked) {
		if (f.HomePhone.value == "") {
			alert ("Please enter selected Contact Method - HOME PHONE");
			f.HomePhone.focus();
			return false;	}	
	}
	
	if(f.ContactMethod[1].checked) {
		if (f.WorkPhone.value == "") {
			alert ("Please enter selected Contact Method - WORK PHONE");
			f.WorkPhone.focus();
			return false;	}	
	}

	if(f.ContactMethod[2].checked) {
		if (f.CellPhone.value == "") {
			alert ("Please enter selected Contact Method - CELL PHONE");
			f.CellPhone.focus();
			return false;	}	
	}

	if(f.ContactMethod[3].checked) {
		if (f.Fax.value == "") {
			alert ("Please enter selected Contact Method - FAX");
			f.Fax.focus();
			return false;	}	
	}	

	if(f.ContactMethod[4].checked) {
		if (f.Email.value == "") {
			alert ("Please enter selected Contact Method - EMAIL ADDRESS");
			f.Email.focus();
			return false;	}	
			
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.Email.value)){
			return true
			}
		{
			alert("Please enter a valid - EMAIL ADDRESS");
			f.Email.focus();
			return false;
		}	
	}
}



//check form for Coupon function
function chkCoupon(f) {
	
	if (f.VehiclePurchaseDate.selectedIndex == 0) {
		alert ("Please select - PURCHASE DATE");
		f.VehiclePurchaseDate.focus();
		return false;
	}		
	
	if (f.FirstName.value == "") {
		alert ("Please enter - FIRST NAME");
		f.FirstName.focus();
		return false;
	}			

	if (f.LastName.value == "") {
		alert ("Please enter - LAST NAME");
		f.LastName.focus();
		return false;
	}
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.Email.value)){
		return true
		}
	{
		alert("Please enter a valid - EMAIL ADDRESS");
		f.Email.focus();
		return false;
	}
}


var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}



//check form for Request function
function chkRequest(f) {
	
	if (f.VehiclePurchaseDate.selectedIndex == 0) {
		alert ("Please select - PURCHASE DATE");
		f.VehiclePurchaseDate.focus();
		return false;
	}		
	
	if (f.FirstName.value == "") {
		alert ("Please enter - FIRST NAME");
		f.FirstName.focus();
		return false;
	}			

	if (f.LastName.value == "") {
		alert ("Please enter - LAST NAME");
		f.LastName.focus();
		return false;
	}

	if (f.Telephone1.value == "") {
		alert ("Please enter - TELEPHONE NUMBER AREA CODE");
		f.Telephone1.focus();
		return false;
	}
	
	if (f.Telephone2.value == "") {
		alert ("Please enter - TELEPHONE NUMBER");
		f.Telephone2.focus();
		return false;
	}
	
	if (f.Telephone3.value == "") {
		alert ("Please enter - TELEPHONE NUMBER");
		f.Telephone3.focus();
		return false;
	}
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(f.Email.value)){
		return true
		}
	{
		alert("Please enter a valid - EMAIL ADDRESS");
		f.Email.focus();
		return false;
	}	
}

//more photos function
function MorePhotos(page) {
OpenWin = this.open(page, "MorePhotos", "width=600,height=400,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
}




//integer validation for individual field
function validateinteger(field, message){
	if  (!checkinteger(field.value))
	{
    if  (!onError(message))
		{
		return false; 
		}
	}
}


//integer validation processing
function onError(error_message)
	{
	alert(error_message);
		return false;	
  }

function checkinteger(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	
	
	if (object_value.length == 0)
	return true;
	
	//Returns true if value is an integer defined as
	//   having an optional leading + or -.
	//   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

	//The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
	//Was it a decimal?
	if (check_char < 1)
		return checknumber(object_value);
	else
		return false;
}

function checknumber(object_value) {
	//Returns true if value is a number or is NULL
	//otherwise returns false	

	if (object_value.length == 0)
		return true;

	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " ,.0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
	//Was it a decimal?
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;

	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 2)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
		// ignore leading blanks

		}
	else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
	//All tests passed, so...
	return true
}

