$(document).ready(function(){

	// buyertag form validation for carchex
	$('#buyertag').submit(function(){
		var valid = true;
		$('input.lead-required').each(function(){
			$(this).css('border-color','');
			$(this).css('border-style','');
			if ($(this).val() == '' || ($(this).attr('id') == 'buyer-required-email' && !checkEmail($(this).val() ))) {
				$(this).css('border-color','red');
				$(this).css('border-style','solid');
				valid = false;
			}
		});
		if (valid == false) {
			$(window).scrollTop(540);
			alert('Please complete all fields outlined in red');
		}
		return valid;		
	});
});

function checkEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults=false
	}
	return (testresults)
}

