<!--

function isEmailAddr(email) {
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) {
		result = true;
		}
	}
	return result;
}
function isAlpha(obj) {
	var result = false;
	var inThere = obj.match(/\D/);
	if (inThere) {
		result = true;
	}
	return result;
}
function isAlphaNum(obj) {
	var result = false;
	var inThere = obj.match(/\w/);
	if (inThere) {
		result = true;
	}
	return result;
}
function isNotAlphaNum(obj) {
	var result = false;
	var inThere = obj.match(/[^\w\s]/);
	if (inThere) {
		result = true;
	}
	return result;
}

function isNum(obj) {
	var result = false;
	var inThere = obj.match(/\d/);
	if (inThere) {
		result = true;
	}
	return result;
}

function hasWhiteSpace(obj) {
	var result = false;
	var inThere = obj.match(/\s/);
	if (inThere) {
		result = true;
	}
	return result;
}

function isChecked(obj) {
	for (var i = 0; i < obj.length; i++) {
		if (obj[i].checked) {
			return "yes";
		}
	}
	return "no";
}

// Functions that validates the forms

function fvalid(FightYourCaseQuiz) {
	
	
	// State
	if (document.FightYourCaseQuiz.State.value == "") {
		alert("The \"State\" field cannot be left blank.");
		document.FightYourCaseQuiz.State.focus();
		return false;
	}
	
	if (document.FightYourCaseQuiz.County.value == "") {
		alert("The \"County\" field cannot be left blank.");
		document.FightYourCaseQuiz.County.focus();
		return false;
	}
	if (document.FightYourCaseQuiz.City.value == "") {
		alert("The \"City\" field cannot be left blank.");
		document.FightYourCaseQuiz.City.focus();
		return false;
	}
	if (document.FightYourCaseQuiz.First_Name.value != "") 
		{
		if (isNum(document.FightYourCaseQuiz.First_Name.value)) {
			alert("Numbers are not allowed in the \"First Name\" field.");
			document.FightYourCaseQuiz.First_Name.focus();
			return false;
		} 
		else if (isNotAlphaNum(document.FightYourCaseQuiz.First_Name.value)) 
		{
			alert("Special characters are not allowed in the \"First Name\" field.");
			document.FightYourCaseQuiz.First_Name.focus();
			return false;
		}
		} 
		else 
		{
		alert("The \"First Name\" field cannot be left blank.");
		document.FightYourCaseQuiz.First_Name.focus();
		return false;
		}
	
	if (document.FightYourCaseQuiz.Last_Name.value != "") {
		if (isNum(document.FightYourCaseQuiz.Last_Name.value)) {
			alert("Numbers are not allowed in the \"Last Name\" field.");
			document.FightYourCaseQuiz.Last_Name.focus();
			return false;
		} else if (isNotAlphaNum(document.FightYourCaseQuiz.Last_Name.value)) {
			alert("Special characters are not allowed in the \"Last Name\" field.");
			document.FightYourCaseQuiz.Last_Name.focus();
			return false;
		}
	} else {
		alert("The \"Last Name\" field cannot be left blank.");
		document.FightYourCaseQuiz.Last_Name.focus();
		return false;
	}
	
	// EmailAddr
	if (document.FightYourCaseQuiz.Email.value != "") {
		if (!isEmailAddr(document.FightYourCaseQuiz.Email.value)) {
			alert("Please enter a complete Email address in the form: yourname@yourdomain.com");
			document.FightYourCaseQuiz.Email.focus();
			return false;
		} else if (hasWhiteSpace(document.FightYourCaseQuiz.Email.value)) {
			alert("Your Email address cannot contain blank spaces.");
			document.FightYourCaseQuiz.Email.focus();
			return false;
		}
	} else {
		alert("The \"Email Address\" field cannot be left blank.");
		document.FightYourCaseQuiz.Email.focus();
		return false;
	}
	
	// Phone
	if (document.FightYourCaseQuiz.Phone.value != "") {
		if (isAlpha(document.FightYourCaseQuiz.Phone.value)) {
			alert("Only numbers are allowed in a Phone Number.");
			document.FightYourCaseQuiz.Phone.focus();
			return false;
		} else if (document.FightYourCaseQuiz.Phone.value.length < 10) {
			alert("This \"Phone Number\" field must have 10 characters.");
			document.FightYourCaseQuiz.Phone.focus();
			return false;
		}
	} else {
		alert("The \"Phone Number\" field cannot be left blank.");
		document.FightYourCaseQuiz.Phone.focus();
		return false;
	}	
		if (document.FightYourCaseQuiz.Comments.value != "") {
			if (document.FightYourCaseQuiz.Comments.value.indexOf("http") != -1)
		 	{
			alert("Please do not enter http in Description of DUI / DWI Legal Problem field");
			document.FightYourCaseQuiz.Comments.focus();
			return false;
			} 
	} else {
		alert("The \"Description of DUI / DWI Legal Problem\" field cannot be left blank.");
		document.FightYourCaseQuiz.Comments.focus();
		return false;
	}
	createCookie('stateName','WA','7')
}

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;
}

function setCounty() {
	if (document.FightYourCaseQuiz.County.value == "") {
		alert('Please select a County.');
		document.FightYourCaseQuiz.County.focus();
		return true;
	}
}


function createCookie(name,value1,days) {
var value = value1;
value = "";
value = ""+document.FightYourCaseQuiz.County.options[document.FightYourCaseQuiz.County.selectedIndex].value+"-"+document.FightYourCaseQuiz.State.options[document.FightYourCaseQuiz.State.selectedIndex].value;
	
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();

	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
	//alert(value);
}
//-->