//condense the blank check with a function (check for null blank)
function check_for_nb(field,fieldname) {
if ((field === null) || (field.value == '')) {
alert("The " + fieldname + " field appears to be blank, this must be entered before proceeding");
field.focus();
return false;
}
return true;
}
function bleh() {
alert('test');
return false;
}

function ValidateUserForm(){
//alert(check_for_nb(document.getElementById('txtFirstname'),"txtFirstname"));
//check for blank fields
if (!check_for_nb(document.getElementById('txtEmail'),"Email")) return false;
if (!check_for_nb(document.getElementById('txtConfirmEmail'),"Email Confirmation")) return false;
if (!check_for_nb(document.getElementById('txtSurname'),"Surname")) return false;
if (!check_for_nb(document.getElementById('txtFirstname'),"First Name")) return false;
if (!check_for_nb(document.getElementById('txtAddress1'),"Address line 1")) return false;
if (!check_for_nb(document.getElementById('txtAddress2'),"Address line 2")) return false;
if (!check_for_nb(document.getElementById('txtAreaCode'),"Area Code")) return false;
if (!check_for_nb(document.getElementById('txtTelNo'),"Telephone Number")) return false;

var country = document.getElementById('selCountry');
if (country.style.display !='none' && ((country.value == "-----") || (country.value.substr(0,6) == "Select"))) {
alert("Please select a valid country from countries list.");
country.focus();
return false
}

var county = document.getElementById('selCounty');
if (county.style.display !='none' && ((county.value == "-----") || (county.value.substr(0,6) == "Select"))) {
alert("Please select a valid county from counties list.");
county.focus();
return false
}

var CorrDiff = document.getElementById('chkCorrAdd');

if (CorrDiff != null && CorrDiff.checked == true) {

if (!check_for_nb(document.getElementById('txtCorrAdd1'),"Correspondence Address line 1")) return false;
if (!check_for_nb(document.getElementById('txtCorrAdd2'),"Correspondence Address line 2")) return false;

var corrCountry = document.getElementById('selCorrCountry');
if (corrCountry.style.display !='none' && ((corrCountry.value == "-----") || (corrCountry.value.substr(0,6) == "Select"))) {
alert("Please select a valid country from the Correspondence countries list.");
corrCountry.focus();
return false;
}

var corrCounty = document.getElementById('selCorrCounty');
if (corrCounty.style.display !='none' && ((corrCounty.value == "-----") || (corrCounty.value.substr(0,6) == "Select"))) {
alert("Please select a valid county from the Correspondence counties list.");
corrCounty.focus();
return false;
}

}


var emaila = document.getElementById('txtEmail').value;
var emailb = document.getElementById('txtConfirmEmail').value;
if (emaila != emailb) {
alert ("Sorry but your email addresses did not match, please re-enter them and try again.");
document.getElementById('txtEmail').focus();
return false;
}

//check email
if(!CheckEmail(document.getElementById('txtEmail'))){
return false;
}

//check if passwords are the same and not blank
var passworda = document.getElementById('txtPassword');
var passwordb = document.getElementById('txtPasswordConfirm');
if (!ValidatePwd(passworda,passwordb)) {
return false;
passworda.focus();
}

//all is well
return true;
}

function ValidateMyAccount_pass() {
var oldpass = document.getElementById('txtOldPassword');
var newpass = document.getElementById('txtNewPassword');
var confpass = document.getElementById('txtConfirmPassword');

if (!check_for_nb(document.getElementById('txtOldPassword'),"Old Password")) return false;
if (!check_for_nb(document.getElementById('txtNewPassword'),"New Password")) return false;
if (!check_for_nb(document.getElementById('txtConfirmPassword'),"Confirm Password")) return false;

if (newpass.value !== confpass.value) {
alert("Your new password and confirmation password did not match!");
newpass.focus();
return false;
}
return true;
}

function ValidateMyAccount_email() {
var oldemail = document.getElementById('txtOldEmail');
var newemail = document.getElementById('txtNewEmail');
var confemail = document.getElementById('txtConfirmEmail');

if (!check_for_nb(document.getElementById('txtOldEmail'),"Old Email")) return false;
if (!check_for_nb(document.getElementById('txtNewEmail'),"New Email")) return false;
if (!check_for_nb(document.getElementById('txtConfirmEmail'),"Confirm Email")) return false;

//check email
if(!CheckEmail(document.getElementById('txtOldEmail'))) return false;
if(!CheckEmail(document.getElementById('txtNewEmail'))) return false;
if(!CheckEmail(document.getElementById('txtConfirmEmail'))) return false;

if (newemail.value !== confemail.value) {
alert("Your new Email and confirmation Email did not match!");
newemail.focus();
return false;
}
return true;
}

function ValidateMyAccount_info() {
if (!check_for_nb(document.getElementById('txtSurname'),"Surname")) return false;
if (!check_for_nb(document.getElementById('txtFirstname'),"First Name")) return false;
if (!check_for_nb(document.getElementById('txtAddress1'),"Address line 1")) return false;
if (!check_for_nb(document.getElementById('txtAddress2'),"Address line 2")) return false;
if (!check_for_nb(document.getElementById('txtAreaCode'),"Area Code")) return false;
if (!check_for_nb(document.getElementById('txtTelNo'),"Telephone Number")) return false;

var country = document.getElementById('selCountry');
if (country.style.display !='none' && ((country.value == "-----") || (country.value.substr(0,9) == "Roghnaigh"))) {
alert("Please select a valid country from countries list.");
country.focus();
return false
}

var county = document.getElementById('selCounty');
if (county.style.display !='none' && ((county.value == "-----") || (county.value.substr(0,9) == "Roghnaigh"))) {
alert("Please select a valid county from counties list.");
county.focus();
return false
}

var CorrDiff = document.getElementById('chkCorrAdd');

if (CorrDiff != null && CorrDiff.checked == true) {

if (!check_for_nb(document.getElementById('txtCorrAdd1'),"Correspondence Address line 1")) return false;
if (!check_for_nb(document.getElementById('txtCorrAdd2'),"Correspondence Address line 2")) return false;

var corrCountry = document.getElementById('selCorrCountry');
if (corrCountry.style.display !='none' && ((corrCountry.value == "-----") || (corrCountry.value.substr(0,9) == "Roghnaigh"))) {
alert("Please select a valid country from the Correspondence countries list.");
corrCountry.focus();
return false;
}

var corrCounty = document.getElementById('selCorrCounty');
if (corrCounty.style.display !='none' && ((corrCounty.value == "-----") || (corrCounty.value.substr(0,9) == "Roghnaigh"))) {
alert("Please select a valid county from the Correspondence counties list.");
corrCounty.focus();
return false;
}
}
return true;
}
