
//Javascript document

/**
*Checks for alphabetic characters
*/
function isLetter(c)
{
	//if the character passes the evaluation, it isn't a letter
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for alphabetic characters, hyphens and spaces
*/
function isAlpha(c)
{
	//if the character passes the evaluation, it is not a letter, hyphen or space
	if(((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && ((c != "-") && (c != " ")))
	{
		return false;
	}//end if
	return true;
}//end isAlpha()

/**
*Checks for numeric characters
*/
function isNumber(c)
{
	//if the character passes the evaluation it isn't a number
	if((c < "0") || (c > "9"))
	{
		return false;
	}//end if
	return true;
}//end isNumber

/**
*Checks for alphanumeric characters, spaces, hyphens, periods and pound
*/
function isAlphaNum(c)
{
	//if the character passes the evaluation, then it isn't an alphanumeric character, space, period or number sign
	if(((c < "0") || (c > "9")) && (((c < "a") || (c > "z")) && ((c < "A") || (c > "Z")) && (c != " ") && (c != "-") && (c != ".") && (c != "#")))
	{
		return false;
	}//end if
	return true;
}//end isAlphaNum()

function checkFullname()
{
	var fullname = document.form.full_name.value;
	
	if(fullname == null || fullname == "")
	{
		document.form.full_name.style.color = "FFFFFF";
		document.form.full_name.style.backgroundColor = "FF0000";
		return false;
	}//end if
	
	for(var i = 0; i < fullname.length; i+= 1)
	{
		var isGood = isAlpha(fullname.charAt(i));
		
		if(!isGood)
		{
			document.form.full_name.style.color = "FFFFFF";
			document.form.full_name.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	
	return true;
}//end checkFirst_name()

function checkAddress()
{
	var address = document.form.address.value;
	
	if(address == null || address == "")
	{
		document.form.address.style.color = "FFFFFF";
		document.form.address.style.backgroundColor = "FF0000";
		return false;
	}//end if
		
	return true;
}//end of function checkAddress()

function checkCity()
{
	var city = document.form.city.value;
	
	if(city == null || city == "")
	{
		document.form.city.style.color = "FFFFFF";
		document.form.city.style.backgroundColor = "FF0000";
		return false;
	}//end of if
	
	for( var i = 0; i< city.length; i+=1)
	{
		var isGood = isAlpha(city.charAt(i));
		
		if(!isGood)
		{
			document.form.city.style.color = "FFFFFF";
			document.form.city.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end of for
	return true;
}//end of function checkCity()

function checkCountry()
{
	var country =  document.form.country.options[document.form.country.selectedIndex].value;
	var province = document.form.province.options[document.form.province.selectedIndex].value;
	var zipCode = document.form.zipCode.value;//first textbox taking 3 values for postal code
    postalcode =zipCode.toUpperCase();
		
	if(country == null || country == 0) 
	{
		document.form.country.style.color = "FFFFFF";
		document.form.country.style.backgroundColor = "FF0000";
		return false;
	}//end if
	else if(country == "CA")
	{
		 var province = document.form.province.options[document.form.province.selectedIndex].value;
		 var finalPostalCodeEntered = postalcode;
		  var objRegExp = /^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/;
	
			if(province == null || province ==0)
			{
				document.form.province.style.color = "FFFFFF";
				document.form.province.style.backgroundColor = "FF0000";
				alert("Please select a province");
				return false;
			}//end if 
    		if(objRegExp.test(finalPostalCodeEntered))
			{		 	
				return true;
			}
			else
			{
				document.form.zipCode.style.color = "FFFFFF";
				document.form.zipCode.style.backgroundColor = "FF0000";
				alert("Invalid postal code!");
				return false;
			}
      //check for valid postal code
      // test is a funtion that will test the string sent as a parameter against
      // the regular expression that was written before.
      // Tests if the given string matches the objRegexp, and returns true if matching, false if not.
         return objRegExp.test(finalPostalCodeEntered);		
		
	}//end else if canada
	else if(country =="US")
	{
		
			if(province == 0)
			{
				document.form.province.style.color = "FFFFFF";
				document.form.province.style.backgroundColor = "FF0000";
				alert("Please select a state!");
				return false;
			}
			if(zipCode == null || zipCode == "")
			{
				document.form.zipCode.style.color = "FFFFFF";
				document.form.zipCode.style.backgroundColor = "FF0000";
				alert("Please enter your zip code!");
				return false;
			}//end if
			else if(zipCode.length != 5)
			{
				document.form.zipCode.style.color = "FFFFFF";
				document.form.zipCode.style.backgroundColor = "FF0000";
				alert("Please verified the length of your zip code!");
				return false;
			}//end else if
			else if(isNaN(zipCode))
			{
				document.form.zipCode.style.color = "FFFFFF";
				document.form.zipCode.style.backgroundColor = "FF0000";
				alert("Please enter only numbers into your zip code!");
				return false;
			}//end else if
			return true;
	}//end else if usa
		
	return true;
}//end of checkCountry()

function checkDateOfBirth()
{
	var day = document.form.day.options[document.form.day.selectedIndex].value;
	var month = document.form.month.options[document.form.month.selectedIndex].value;
	var year = document.form.year.value;
	
	if(day == null || day == 0)
	{
		document.form.day.style.color = "FFFFFF";
		document.form.day.style.backgroundColor = "FF0000";
		return false;		
	}//end if
	else if( month == null || month == 0)
	{
		document.form.month.style.color = "FFFFFF";
		document.form.month.style.backgroundColor = "FF0000";
		return false;		
	}//end else if()
	else if((year == null || year == "")||(year.length != 4) || (isNaN(year)))
	{
		document.form.year.style.color = "FFFFFF";
		document.form.year.style.backgroundColor = "FF0000";
		return false;		
				
	}//end else if()
	return true;
}//end checkDateOfBirth()

/**
 * Validation for the email.
 */
function checkEmail() 
{
	//obtain the value of the email field and use a regular expression to make sure the address is valid
	var email = document.form.email.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.ca)|(\..{2,2}))$)\b/gi);
	
	//if the address is valid, return true
	if (!email)
	{
		//set the text color to white and the background color to turquoise and return false
	   document.form.email.style.color = "FFFFFF";
	   document.form.email.style.backgroundColor = "FF0000";
	   return false;
	}//end else
	return true;
}//end checkEmail()

function checkHomePhone()
{
	var hPhone1 = document.form.hPhone1.value;
	var hPhone2 = document.form.hPhone2.value;
	var hPhone3 = document.form.hPhone3.value;
	
	if((hPhone1 == null || hPhone1 == "") || (hPhone1.length < 3)|| (isNaN(hPhone1)))
	{
		document.form.hPhone1.style.color = "FFFFFF";
		document.form.hPhone1.style.backgroundColor = "FF0000";
		return false;
	}//end if
	else if((hPhone2 == null || hPhone2 == "") || (hPhone2.length < 3) || (isNaN(hPhone2)))
	{
		document.form.hPhone2.style.color = "FFFFFF";
		document.form.hPhone2.style.backgroundColor = "FF0000";
		return false;
	}//end if
	else if((hPhone3 == null || hPhone3 == "") || (hPhone3.length < 4) || (isNaN(hPhone3)))
	{
		document.form.hPhone3.style.color = "FFFFFF";
		document.form.hPhone3.style.backgroundColor = "FF0000";
		return false;
	}//end if
	
	return true;
}//end checkHomePhone()

function checkSin()
{
	var socialNumber = document.form.socialNumber.value;
	
	if(isNaN(socialNumber))
	{
		document.form.socialNumber.style.color = "FFFFFF";
		document.form.socialNumber.style.backgroundColor = "FF0000";
		return false;
	}//end if
	
	return true;
}//end of function checkSin()

function checkSpouseName()
{
	var spousename = document.form.spouseName.value;
	
	
	for(var i = 0; i < spousename.length; i+=1)
	{
		var isGood = isAlpha(spousename.charAt(i));
		
		if(!isGood)
		{
			document.form.spousename.style.color = "FFFFFF";
			document.form.spousename.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	return true;
}//end checkSpouseName()

function checkDefendantNames()
{
	var txtDefendantName1 = document.form.txtDefendantName1.value;
	var txtDefendantName2 = document.form.txtDefendantName2.value;
	var txtDefendantName3 = document.form.txtDefendantName3.value;
	var txtDefendantName4 = document.form.txtDefendantName4.value;
	var txtDefendantName5 = document.form.txtDefendantName5.value;
	
	for(var i = 0; i<txtDefendantName1.length; i+=1)
	{
		var isGood = isAlpha(txtDefendantName1.charAt(i));
		
		if(!isGood)
		{
			document.form.txtDefendantName1.style.color = "FFFFFF";
			document.form.txtDefendantName1.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	
	for(var i = 0; i<txtDefendantName2.length; i+=1)
	{
		var isGood = isAlpha(txtDefendantName2.charAt(i));
		
		if(!isGood)
		{
			document.form.txtDefendantName2.style.color = "FFFFFF";
			document.form.txtDefendantName2.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	for(var i = 0; i<txtDefendantName3.length; i+=1)
	{
		var isGood = isAlpha(txtDefendantName3.charAt(i));
		
		if(!isGood)
		{
			document.form.txtDefendantName3.style.color = "FFFFFF";
			document.form.txtDefendantName3.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	for(var i = 0; i<txtDefendantName4.length; i+=1)
	{
		var isGood = isAlpha(txtDefendantName4.charAt(i));
		
		if(!isGood)
		{
			document.form.txtDefendantName4.style.color = "FFFFFF";
			document.form.txtDefendantName4.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	for(var i = 0; i<txtDefendantName5.length; i+=1)
	{
		var isGood = isAlpha(txtDefendantName5.charAt(i));
		
		if(!isGood)
		{
			document.form.txtDefendantName5.style.color = "FFFFFF";
			document.form.txtDefendantName5.style.backgroundColor = "FF0000";
			return false;
		}//end if
	}//end for
	return true;
}//checkDefendantNames()

function checkDefendantAge()
{
	var txtDefendantAge1 = document.form.txtDefendantAge1.value;
	var txtDefendantAge2 = document.form.txtDefendantAge2.value;
	var txtDefendantAge3 = document.form.txtDefendantAge3.value;
	var txtDefendantAge4 = document.form.txtDefendantAge4.value;
	var txtDefendantAge5 = document.form.txtDefendantAge5.value;
	
	if((isNaN(txtDefendantAge1)) || (isNaN(txtDefendantAge2)) || (isNaN(txtDefendantAge3)) || (isNaN(txtDefendantAge4)) || (isNaN(txtDefendantAge5)))
	{
		document.form.txtDefendantAge1.style.color = "FFFFFF";
		document.form.txtDefendantAge1.style.backgroundColor = "FF0000";
		document.form.txtDefendantAge2.style.color = "FFFFFF";
		document.form.txtDefendantAge2.style.backgroundColor = "FF0000";
		document.form.txtDefendantAge3.style.color = "FFFFFF";
		document.form.txtDefendantAge3.style.backgroundColor = "FF0000";
		document.form.txtDefendantAge4.style.color = "FFFFFF";
		document.form.txtDefendantAge4.style.backgroundColor = "FF0000";
		document.form.txtDefendantAge5.style.color = "FFFFFF";
		document.form.txtDefendantAge5.style.backgroundColor = "FF0000";
		return false;
	}//end if
	return true;
}//checkDefendantAge()


function checkAll()
{
	var fullname= checkFullname();
	var address= checkAddress();
	var city = checkCity();
	var country = checkCountry();
	var dob = checkDateOfBirth();
	var email = checkEmail();
	var homePhone = checkHomePhone();
	var sinNumber = checkSin();
	var spouse = checkSpouseName();
	var defendantName = checkDefendantNames();
	var defendantAge = checkDefendantAge();
		
	if(!fullname)
	{
		return false;
	}//end if
	
	if(!address)
	{
		return false;
	}//end if
	
	if(!city)
	{
		return false;
	}//end if
	
	if(!country)
	{
		return false;
	}//end if
	if(!dob)
	{
		return false;
	}//end if
	if(!email)
	{
		return false;
	}//end if
	if(!homePhone)
	{
		return false;
	}//end if
	
	if(!sinNumber)
	{
		return false;
	}//end if
	if(!spouse)
	{
		return false;
	}//end if
	if(!defendantName)
	{
		return false;
	}//end if
	if(!defendantAge)
	{
		return false;
	}//end if


	return true;
}//** END of Function **

function changeColor(c)
{
	c.style.color = "000000";
	c.style.backgroundColor = "FFFFFF";
}//end changeColor()