
function isUSAZipCode(str) 
{
	return /^\d{5}(-\d{4})?$/.test(str);
}

function validatePhoneNumber(input_str)
{
	let re = /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/;
	return re.test(input_str);
}
function matchPassword()
{
	var pass = document.getElementById("password").value;
	var conPass = document.getElementById("repeatPassword").value;
	
	if(pass=="")
	{
		//document.getElementById("matchPasswordWM").innerHTML = "<p><i class='fa fa-warning'></i> Enter your password</p>";
		return false;
	}
	else if(pass.length<8)
	{
		document.getElementById("matchPasswordWM").innerHTML = "<p><i class='fa fa-warning'></i> Use 8 characters or more for your password but less than 50 characters.</p>";
		return false;
	}
	else if(conPass=="")
	{
		document.getElementById("matchPasswordWM").innerHTML = "<p><i class='fa fa-warning'></i> Confirm your password</p>";
		return false;
	}
	else if(pass!=conPass)
	{
		document.getElementById("matchPasswordWM").innerHTML = "<p><i class='fa fa-warning'></i> Those passwords didn\’t match. Try again.</p>";
		//document.getElementById("conpassword").value = "";
		return false;
	}
	else
	{ 
		var passw = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,50}$/;

		if(pass.match(passw))
		{
			document.getElementById("matchPasswordWM").innerHTML = "";
			return true;
		}
		else
		{
			document.getElementById("matchPasswordWM").innerHTML = "<p><i class='fa fa-warning'></i> Please choose a stronger password. Try a mix of letters, numbers, and symbols.</p>";
			return false;
		}
	}	
}
function validateForm()
{
	let username = document.getElementById("uname").value;
	let fname = document.getElementById("firstName").value;
	let lname = document.getElementById("lastName").value;
	let AddressLine1 = document.getElementById("AddressLine1").value;
	let AddressLine2 = document.getElementById("AddressLine2").value;
	let PhoneNumber = document.getElementById("PhoneNumber").value;
	let ZipCode = document.getElementById("ZipCode").value;
	
	if(username.length!=0)
	{
		if(username.length<6 || username.length>50)
		{
			document.getElementById("unameAlert").innerHTML = "<p><i class='fa fa-warning'></i>Username Max length 50 characters, minimum length 6 characters</p>";
		}
		else
		{
			document.getElementById("unameAlert").innerHTML = "";
		}
	}
	

	if(fname.length>50)
	{
		document.getElementById("firstNameAlert").innerHTML = "<p><i class='fa fa-warning'></i>First Name Max length 50 characters.</p>";
	}
	else
	{
		document.getElementById("firstNameAlert").innerHTML = "";
	}
	
	if(lname.length>50)
	{
		document.getElementById("lastNameAlert").innerHTML = "<p><i class='fa fa-warning'></i>Last Name Max length 50 characters.</p>";
	}
	else
	{
		document.getElementById("lastNameAlert").innerHTML = "";
	}
	
	matchPassword();
	
	if(AddressLine1.length>100)
	{
		document.getElementById("AddressLine1Wm").innerHTML = "<p><i class='fa fa-warning'></i>Address Line 1 - Max length 100 characters.</p>";
	}
	else
	{
		document.getElementById("AddressLine1Wm").innerHTML = "";
	}
	
	if(AddressLine2.length>100)
	{
		document.getElementById("AddressLine2Wm").innerHTML = "<p><i class='fa fa-warning'></i>Address Line 2 - Max length 100 characters.</p>";
	}
	else
	{
		document.getElementById("AddressLine2Wm").innerHTML = "";
	}
	
	if(ZipCode.length!=0)
	{
		if(ZipCode.length<5 || ZipCode.length>10)
		{
			document.getElementById("ZipCodeWm").innerHTML = "<p><i class='fa fa-warning'></i>Zip Code - Max length 10 characters, minimum length 5 digits.</p>";
		}
		else
		{
			let message = "";
			if (isUSAZipCode(ZipCode)) 
			{
				document.getElementById("ZipCodeWm").innerHTML = "";
			}
			else
			{
				document.getElementById("ZipCodeWm").innerHTML = "<p><i class='fa fa-warning'></i>Invalid Zip Code</p>";
			}
		}
	}
	
	if(PhoneNumber.length!=0)
	{
		if(PhoneNumber.length>12)
		{
			document.getElementById("PhoneNumberWm").innerHTML = "<p><i class='fa fa-warning'></i>Phone Number - Max length 12 characters</p>";
		}
		else
		{
			let message = "";
			if (validatePhoneNumber(PhoneNumber)) 
			{
				document.getElementById("PhoneNumberWm").innerHTML = "";
			}
			else
			{
				document.getElementById("PhoneNumberWm").innerHTML = "Invalid Phone Number.";
			}
		}
	}
}