// JavaScript Document

function checkNewCustomerSignUp() {
	var valid = true;
	var why = "";
	
	/* Title */
	
	if (!document.NewCustomerSignUp.Title[0].checked && !document.NewCustomerSignUp.Title[1].checked && !document.NewCustomerSignUp.Title[2].checked) {
		document.getElementById("label_Title").style.color = "#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Title").style.color = "#000000";
	}
	
	/* First Name */
	
	if (document.NewCustomerSignUp.FirstName.value == "") {
		document.getElementById("label_FirstName").style.color = "#ff0000";
		document.NewCustomerSignUp.FirstName.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_FirstName").style.color = "#000000";
		document.NewCustomerSignUp.FirstName.style.borderColor="#b2b7b8";
	}
	
	/* Last Name */
	
	if (document.NewCustomerSignUp.LastName.value == "") {
		document.getElementById("label_LastName").style.color = "#ff0000";
		document.NewCustomerSignUp.LastName.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_LastName").style.color = "#000000";
		document.NewCustomerSignUp.LastName.style.borderColor="#b2b7b8";
	}

	/* Email */

	var EmailFilter=/.+@.+\..{2,3}$/;
	var illegalChars=/[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	
	if (!(EmailFilter.test(document.NewCustomerSignUp.Email.value)) || !(EmailFilter.test(document.NewCustomerSignUp.ConfirmEmail.value))) { 
		document.getElementById("label_Email").style.color = "#ff0000";
		document.getElementById("label_ConfirmEmail").style.color = "#ff0000";
		document.NewCustomerSignUp.Email.style.borderColor="#ff0000";
		document.NewCustomerSignUp.ConfirmEmail.style.borderColor="#ff0000";
		valid = false;
	} else if (document.NewCustomerSignUp.Email.value.match(illegalChars)) {
		document.getElementById("label_Email").style.color = "#ff0000";
		document.getElementById("label_ConfirmEmail").style.color = "#ff0000";
		document.NewCustomerSignUp.Email.style.borderColor="#ff0000";
		document.NewCustomerSignUp.ConfirmEmail.style.borderColor="#ff0000";
		valid = false;
	} else if (document.NewCustomerSignUp.Email.value != document.NewCustomerSignUp.ConfirmEmail.value) {
		document.getElementById("label_Email").style.color = "#ff0000";
		document.getElementById("label_ConfirmEmail").style.color = "#ff0000";
		document.NewCustomerSignUp.Email.style.borderColor="#ff0000";
		document.NewCustomerSignUp.ConfirmEmail.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Email").style.color = "#000000";
		document.getElementById("label_ConfirmEmail").style.color = "#000000";
		document.NewCustomerSignUp.Email.style.borderColor="#b2b7b8";
		document.NewCustomerSignUp.ConfirmEmail.style.borderColor="#b2b7b8";
	}
	
	/* Date of Birth */
	
	if (document.NewCustomerSignUp.BirthDay.value == "") {
		document.getElementById("label_DOB").style.color = "#ff0000";
		document.NewCustomerSignUp.BirthDay.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_DOB").style.color = "#000000";
		document.NewCustomerSignUp.BirthDay.style.borderColor="#b2b7b8";
	}
	
	if (document.NewCustomerSignUp.BirthMonth.value == "") {
		document.getElementById("label_DOB").style.color = "#ff0000";
		document.NewCustomerSignUp.BirthMonth.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_DOB").style.color = "#000000";
		document.NewCustomerSignUp.BirthMonth.style.borderColor="#b2b7b8";
	}
	
	if (document.NewCustomerSignUp.BirthYear.value == "") {
		document.getElementById("label_DOB").style.color = "#ff0000";
		document.NewCustomerSignUp.BirthYear.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_DOB").style.color = "#000000";
		document.NewCustomerSignUp.BirthYear.style.borderColor="#b2b7b8";
	}
	
	/* check for April, June, September, November (only 30 days) and February (leap year) */
	
	if (document.NewCustomerSignUp.BirthYear.value !== "" && document.NewCustomerSignUp.BirthMonth.value !== "" && document.NewCustomerSignUp.BirthDay.value !== "") {
	/* check for April, June, September, November (only 30 days) */
	
		if (document.NewCustomerSignUp.BirthMonth.options[4].selected || document.NewCustomerSignUp.BirthMonth.options[6].selected  || document.NewCustomerSignUp.BirthMonth.options[9].selected || document.NewCustomerSignUp.BirthMonth.options[11].selected){
		
			if (document.NewCustomerSignUp.BirthDay.options[31].selected) {
				document.getElementById("label_DOB").style.color = "#ff0000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#ff0000";		
			} else {
				document.getElementById("label_DOB").style.color = "#000000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#b2b7b8";				
			}
		
		}
		
		/* check for February (leap year) */
		
		var selectedYear = document.NewCustomerSignUp.BirthYear.value;
		leapYearCheck = selectedYear/4;
		var leapYearCheck = leapYearCheck.toString();
		if (leapYearCheck.indexOf(".") != -1) {
			if (document.NewCustomerSignUp.BirthDay.options[31].selected || document.NewCustomerSignUp.BirthDay.options[30].selected || document.NewCustomerSignUp.BirthDay.options[29].selected) {
				document.getElementById("label_DOB").style.color = "#ff0000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#ff0000";					
			} else {
				document.getElementById("label_DOB").style.color = "#000000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#b2b7b8";		
			}
		} else {
			if (document.NewCustomerSignUp.BirthDay.options[31].selected || document.NewCustomerSignUp.BirthDay.options[30].selected) {
				document.getElementById("label_DOB").style.color = "#ff0000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#ff0000";				
			} else {
				document.getElementById("label_DOB").style.color = "#000000";
				document.NewCustomerSignUp.BirthDay.style.borderColor="#b2b7b8";					
			}
		}		
		
	}
	
	/* Password */
	
	if (document.NewCustomerSignUp.Password.value == "" || document.NewCustomerSignUp.ConfirmPassword.value == "") {
		document.getElementById("label_Password").style.color = "#ff0000";
		document.getElementById("label_ConfirmPassword").style.color = "#ff0000";
		document.NewCustomerSignUp.Password.style.borderColor="#ff0000";
		document.NewCustomerSignUp.ConfirmPassword.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Password").style.color = "#000000";
		document.getElementById("label_ConfirmPassword").style.color = "#000000";		
		document.NewCustomerSignUp.Password.style.borderColor="#b2b7b8";
		document.NewCustomerSignUp.ConfirmPassword.style.borderColor="#b2b7b8";
	
		if (document.NewCustomerSignUp.Password.value != document.NewCustomerSignUp.ConfirmPassword.value) {
			document.getElementById("label_Password").style.color = "#ff0000";
			document.getElementById("label_ConfirmPassword").style.color = "#ff0000";
			document.NewCustomerSignUp.Password.style.borderColor="#ff0000";
			document.NewCustomerSignUp.ConfirmPassword.style.borderColor="#ff0000";
			valid = false;
		} else {
			document.getElementById("label_Password").style.color = "#000000";
			document.getElementById("label_ConfirmPassword").style.color = "#000000";			
			document.NewCustomerSignUp.Password.style.borderColor="#b2b7b8";
			document.NewCustomerSignUp.ConfirmPassword.style.borderColor="#b2b7b8";
		}
	}

	/* Address Line 1 */
		
	if (document.NewCustomerSignUp.Address1.value == "") {
		document.getElementById("label_Address1").style.color = "#ff0000";			
		document.NewCustomerSignUp.Address1.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Address1").style.color = "#000000";
		document.NewCustomerSignUp.Address1.style.borderColor="#b2b7b8";
	}
	
	/* Address Line 2 
	
	if (document.NewCustomerSignUp.Address2.value == "") {
		document.getElementById("label_Address2").style.color = "#ff0000";			
		document.NewCustomerSignUp.Address2.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Address2").style.color = "#000000";
		document.NewCustomerSignUp.Address2.style.borderColor="#b2b7b8";
	}*/

	/* City 
	
	if (document.NewCustomerSignUp.City.value == "") {
		document.getElementById("label_City").style.color = "#ff0000";			
		document.NewCustomerSignUp.City.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_City").style.color = "#000000";
		document.NewCustomerSignUp.City.style.borderColor="#b2b7b8";
	}*/
	
	/* Area */
	
	var Area_SelIndex = document.NewCustomerSignUp.Area.selectedIndex;
	var AreaValue = document.NewCustomerSignUp.Area.options[Area_SelIndex].value;	
	
	if (AreaValue == 0) {
		document.getElementById("label_Area").style.color = "#ff0000";			
		document.NewCustomerSignUp.Area.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Area").style.color = "#000000";
		document.NewCustomerSignUp.Area.style.borderColor="#b2b7b8";
	}	
	
	/* Country (Island) */
	
	if (!document.NewCustomerSignUp.Country[0].checked && !document.NewCustomerSignUp.Country[1].checked) {
		document.getElementById("label_Country").style.color = "#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Country").style.color = "#000000";
	}

	
	/* Country 
	
	if (document.NewCustomerSignUp.Country.value == "") {
		document.getElementById("label_Country").style.color = "#ff0000";			
		document.NewCustomerSignUp.Country.style.borderColor="#ff0000";
		valid = false;
	} else {
		document.getElementById("label_Country").style.color = "#000000";	
		document.NewCustomerSignUp.Country.style.borderColor="#b2b7b8";
	}*/
	
	var safePhoneChars = /^((\d[-. ]?)?((\(\d{3}\))|\d{3}))?[-. ]?\d{3}[-. ]?\d{4}$/
	
	/* Phone (Home) */

	if (document.NewCustomerSignUp.PhoneHome.value == "") {
		document.getElementById("label_PhoneHome").style.color = "#ff0000";
		document.NewCustomerSignUp.PhoneHome.style.borderColor="#ff0000";
		valid = false;		
	} else if (!safePhoneChars.test(document.NewCustomerSignUp.PhoneHome.value)) {
			document.getElementById("label_PhoneHome").style.color = "#ff0000";
			document.NewCustomerSignUp.PhoneHome.style.borderColor="#ff0000";
			valid = false;
	} else {	
		document.getElementById("label_PhoneHome").style.color = "#000000";
		document.NewCustomerSignUp.PhoneHome.style.borderColor="#b2b7b8";
	}
	
	/* Phone (Work) */

	if (document.NewCustomerSignUp.PhoneWork.value != "") {
		if (!safePhoneChars.test(document.NewCustomerSignUp.PhoneWork.value)) {
			document.getElementById("label_PhoneWork").style.color = "#ff0000";	
			document.NewCustomerSignUp.PhoneWork.style.borderColor="#ff0000";
			valid = false;
		} else {
			document.getElementById("label_PhoneWork").style.color = "#000000";
			document.NewCustomerSignUp.PhoneWork.style.borderColor="#b2b7b8";
		}
	} else {
			document.getElementById("label_PhoneWork").style.color = "#000000";
			document.NewCustomerSignUp.PhoneWork.style.borderColor="#b2b7b8";		
	}
	
	/* Phone (Mobile) */

	if (document.NewCustomerSignUp.PhoneMobile.value != ""){
		if (!safePhoneChars.test(document.NewCustomerSignUp.PhoneMobile.value)) {
			document.getElementById("label_PhoneMobile").style.color = "#ff0000";
			document.NewCustomerSignUp.PhoneMobile.style.borderColor="#ff0000";
			valid = false;
		} else {
			document.getElementById("label_PhoneMobile").style.color = "#000000";
			document.NewCustomerSignUp.PhoneMobile.style.borderColor="#b2b7b8";
		}
	} else {
			document.getElementById("label_PhoneMobile").style.color = "#000000";
			document.NewCustomerSignUp.PhoneMobile.style.borderColor="#b2b7b8";		
	}
	
	if (valid == false) {
		document.getElementById("errors").innerHTML = "There are errors on this Form (highlighted in red). Please scroll down the page and correct them.";
	}
	
	scrollTo(0,0);
	return valid;
	
}