// JScript source code
function checkPostCode(toCheck) {

    // Permitted letters depend upon their position in the postcode.
    var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
    var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
    var alpha3 = "[abcdefghjkstuw]";                                // Character 3
    var alpha4 = "[abehmnprvwxy]";                                  // Character 4
    var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5

    // Array holds the regular expressions for the valid postcodes
    var pcexp = new Array();

    // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
    pcexp.push(new RegExp("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

    // Expression for postcodes: ANA NAA
    pcexp.push(new RegExp("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

    // Expression for postcodes: AANA  NAA
    pcexp.push(new RegExp("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$", "i"));

    // Exception for the special postcode GIR 0AA
    pcexp.push(/^(GIR)(\s*)(0AA)$/i);

    // Standard BFPO numbers
    pcexp.push(/^(bfpo)(\s*)([0-9]{1,4})$/i);

    // c/o BFPO numbers
    pcexp.push(/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

    // Overseas Territories
    pcexp.push(/^([A-Z]{4})(\s*)(1ZZ)$/i);

    // Load up the string to check
    var postCode = toCheck;

    // Assume we're not going to find a valid postcode
    var valid = false;

    // Check the string against the types of post codes
    for (var i = 0; i < pcexp.length; i++) {
        if (pcexp[i].test(postCode)) {

            // The post code is valid - split the post code into component parts
            pcexp[i].exec(postCode);

            // Copy it back into the original string, converting it to uppercase and
            // inserting a space between the inward and outward codes
            postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();

            // If it is a BFPO c/o type postcode, tidy up the "c/o" part
            postCode = postCode.replace(/C\/O\s*/, "c/o ");

            // Load new postcode back into the form element
            valid = true;

            // Remember that we have found that the code is valid and break from loop
            break;
        }
    }

    // Return with either the reformatted valid postcode or the original invalid 
    // postcode
    if (valid) { return postCode; } else return false;
}

// JScript source code
// Date Validation
var dtCh = "/";
var minYear = 1900;
var maxYear = 2100;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        //alert("The date format should be : dd/mm/yyyy")
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
        //alert("Please enter a valid month")
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
        //alert("Please enter a valid day")
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
        //alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        return false;
    }
    else {
        return true;
    }
}

function isValidEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return true;
	}
	else {
		return false;
	}
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function checkenquiry(){
	var ftxt = '';

	if (document.enquiry.Name.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (document.enquiry.Company.value==''){
		ftxt += '\n- Please enter your Company.';
	}
	
	if (document.enquiry.Telephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.';
	}
	
	if (isValidEmail(document.enquiry.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.enquiry.subject.value==''){
		ftxt += '\n- Please select an enquiry Subject.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

// Text Size
function createCookie(name,value,days) {
      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=/";
}

function readCookie(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
}

function changeTextSize(size){
      var sitetext = document.getElementById('wrapper');  
      sitetext.style.fontSize = size + '%'; 
      createCookie('ipwfontsize',size,1)
}

function clearemailfield(fieldVal){
	if (isValidEmail(fieldVal)==false){
		document.newsletterform.email.value='';
	}
}

function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function mainmenu(){
	$(" #navlist ul ").css({display: "none"}); // Opera Fix
	$(" #navlist li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(0);
			},function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			});
	}

 $(document).ready(function(){					
	mainmenu()
});

/* Magazine Subscription */
function displayMagazineSectorOther(theVal) {
    var OtherField = document.getElementById("OtherField");

    if (theVal == '4') {
        OtherField.style.display = 'block';
    }
    else {
        OtherField.style.display = 'none';
    }
}

function checkmagazinesubscription() {
    var ftxt = '';

    if (document.subscriptionform.Title.value == '') {
        ftxt += '\n- Please select your Title.';
    }

    if (document.subscriptionform.FirstName.value == '' || document.subscriptionform.FirstName.value == 'Your first name') {
        ftxt += '\n- Please enter your First Name.';
    }

    if (document.subscriptionform.LastName.value == '' || document.subscriptionform.LastName.value == 'Your last name') {
        ftxt += '\n- Please enter your First Name.';
    }

    if (document.subscriptionform.Company.value == '' || document.subscriptionform.Company.value == 'Company') {
        ftxt += '\n- Please enter your Company Name.';
    }

    if (document.subscriptionform.Street.value == '' || document.subscriptionform.Street.value == 'Your street address') {
        ftxt += '\n- Please enter your Street Address.';
    }

    if (document.subscriptionform.Town.value == '' || document.subscriptionform.Town.value == 'Your town address') {
        ftxt += '\n- Please enter your Town Address.';
    }

    if (document.subscriptionform.County.value == '' || document.subscriptionform.County.value == 'Your county address') {
        ftxt += '\n- Please enter your County Address.';
    }

    if (checkPostCode(document.subscriptionform.Postcode.value) == false) {
        ftxt += '\n- Please enter your FULL Postcode.';
    }

    if (document.subscriptionform.TelephoneNumber.value == '' || document.subscriptionform.TelephoneNumber.value == 'Telephone number') {
        ftxt += '\n- Please enter your Telephone Number.';
    }

    if (isValidEmail(document.subscriptionform.EmailAddress.value)==false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (document.subscriptionform.Sector.value == '') {
        ftxt += '\n- Please select your Sector.';
    }
    else {
        if (document.subscriptionform.Sector.value == '4' && (document.subscriptionform.SectorOther.value == '' || document.subscriptionform.SectorOther.value == 'Other sector')) {
            ftxt += '\n- Please enter the Other sector.';
        }
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Quick Postcode Search */
function checkpostcodesearch() {
    if (checkPostCode(document.quickpostcode.Postcode.value) == false) {
        alert('Please enter FULL Postcode.');
        return false;
    }
    else {
        return true;
    }
}

/* Quick Keyword Search */
function checkquickkeyword() {
    if (checkPostCode(document.quickkeyword.Postcode.value) == false) {
        alert('Please enter FULL Postcode.');
        return false;
    }
    else {
        return true;
    }
}

/* Full Directory Search */
function checkfullsearch() {
    var errcount = 0;

    if (document.fullsearch.Name.value == '' || document.fullsearch.Name.value == 'Name') {
        errcount += 1;
    }

    if (document.fullsearch.KeywordID.value == '') {
        errcount += 1;
    }

    /*
    if (document.fullsearch.Keywords.value == '' || document.fullsearch.Keywords.value == 'Keywords') {
        errcount += 1;
    }

    if (document.fullsearch.Sector.value == '') {
        errcount += 1;
    }
    */

    if (checkPostCode(document.fullsearch.Postcode.value) == false) {
        errcount += 1;
    }

    if (document.fullsearch.Distance.value == 'NATIONAL') {
        errcount -= 1;
        //alert('going in');
    }

    //if (errcount == 4) {
    if (errcount == 3) {
        alert('Please specify your Search Criteria.');
        return false;
    }
    else {
        return true;
    }
}

/* Review Form Validation */
function checkreviewform(theId) {
    var ftxt = '';

    if (eval('document.directorysubmit' + theId + '.Member_PIN' + theId + '.value') == '' || eval('document.directorysubmit' + theId + '.Member_PIN' + theId + '.value') == 'Your PIN') {
        ftxt += '\n- Please enter a PIN Number.';
    }

    if (eval('document.directorysubmit' + theId + '.Name' + theId + '.value') == '' || eval('document.directorysubmit' + theId + '.Name' + theId + '.value') == 'Your name') {
        ftxt += '\n- Please enter Your Name.';
    }

    if (eval('document.directorysubmit' + theId + '.Location' + theId + '.value') == '' || eval('document.directorysubmit' + theId + '.Location' + theId + '.value') == 'Your location') {
        ftxt += '\n- Please enter Your Name.';
    }

    if (eval('document.directorysubmit' + theId + '.Review' + theId + '.value') == '' || eval('document.directorysubmit' + theId + '.Review' + theId + '.value') == 'Your review') {
        ftxt += '\n- Please enter Your Review.';
    }

    var starselected = false;
    for (var i = 0; i < 5; i++) {
        if (eval('document.directorysubmit' + theId + '.star' + theId + '[i].checked') == true) {
            starselected = true;
        }
    }

    if (starselected == false) {
        ftxt += '\n- Please select your Star Rating.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Standard Right Panel Enquiry Form */
function checkenquiryform() {
    var ftxt = '';

    if (document.quickcontactform.Name.value == '' || document.quickcontactform.Name.value == 'Your name') {
        ftxt += '\n- Please enter your Name.'
    }

    if (document.quickcontactform.Telephone.value == '' || document.quickcontactform.Telephone.value == 'Your telephone number') {
        ftxt += '\n- Please enter your Telephone Number.'
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Making a Will Form */
function checkmakingwillguideform() {
    var ftxt = '';

    if (document.makingwillguide.Name.value == '' || document.makingwillguide.Name.value == 'Please enter your name') {
        ftxt += '\n- Please enter your Name.';
    }

    if (isValidEmail(document.makingwillguide.Email.value) == false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (checkPostCode(document.makingwillguide.Postcode.value) == false) {
        ftxt += '\n- Please enter your FULL Postcode.';
    }

    var boption = false;
    for (var i = 0; i < 2; i++) {
        if (document.makingwillguide.Option[i].checked == true) {
            boption = true;
        }
    }

    if (boption == false) {
        ftxt += '\n- Pleae select an Option.';
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Quick Login */
function checkquicklogin() {
    var ftxt = '';

    if (document.quicklogin.Username.value == '' || document.quicklogin.Username.value == 'Username') {
        ftxt += '\n- Please enter your Username.';
    }

    if (document.quicklogin.Password.value == '' || document.quicklogin.Password.value == 'Password') {
        ftxt += '\n- Please enter your Password.';
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Main Login */
function checkmainloginform() {
    var ftxt = '';

    if (document.mainloginform.Username.value == '' || document.mainloginform.Username.value == 'Username') {
        ftxt += '\n- Please enter your Username.';
    }

    if (document.mainloginform.Password.value == '' || document.mainloginform.Password.value == 'Password') {
        ftxt += '\n- Please enter your Password.';
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Forgotten Password */
function checkforgottenform() {
    var ftxt = '';

    if (document.forgottenform.Username.value == '' || document.forgottenform.Username.value == 'Username') {
        ftxt += '\n- Please enter your Username.';
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Review Actions */
function confirmReviewAction(submitstring) {
    if (confirm('Are you sure you want to perform this action on the selected review?')) {
        location.href = submitstring;
    }
}

/* CPD Upload */
function checkcpdupload() {
    if (document.uploadcpd.CPDUPLOAD.value == '') {
        alert('Please select a CPD Certificate.');
        return false;
    }
    else {
        return true;
    }
}

/* CPD Notify */
function confirmCPDNotify(submitstring) {
    if (confirm('Are you sure you want to notify us that you will be sending your CPD Certificate?')) {
        location.href = submitstring;
    }
}

/* Renew Form */
function checkrenewal() {
    var counter = 0;

    if (document.renewform.Renew_DetailsCorrect.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_InstrictionsNotifications.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_NoInterestOtherCompany.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_InformationAccurate.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_PreviousDetailsSubmitCorrect.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_ReadCodeofPractice.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_OngoingAgree.checked) {
        counter += 1;
    }

    if (document.renewform.Renew_ComplaintsAgree.checked) {
        counter += 1;
    }

    if (counter < 8) {
        alert('You must tick and agree to all declarations before you can renew online.');
        return false;
    }
    else {
        return true;
    }
}

/* Upgrade */
function checkupgrade() {
    if (document.upgradeform.Agree.checked) {
        return true;
    }
    else {
        alert('You must agree to the Terms before you can upgrade your directory.');
        return false;
    }
}

/* Logout */
function confirmLogout() {
    if (confirm('Are you sure you want to logout?')) {
        location.href = '/login/dashboard/logout/';
    }
}

/* Reset PIN */
function resetPin() {
    if (confirm('Are you sure you want to reset the PIN number?')) {
        location.href = '/login/dashboard/resetpin/';
    }
}

/* Edit Profile */
function checkeditprofile() {
    var ftxt = '';

    if (document.editprofile.NewPassword.value !== document.editprofile.NewPasswordRepeat.value) {
        ftxt += '\n- Please ensure both New Password Match.';
    }

    if (document.editprofile.Title.value == '') {
        ftxt += '\n- Please enter a Title.';
    }

    if (document.editprofile.Street.value == '') {
        ftxt += '\n- Please enter a Street.';
    }

    if (document.editprofile.Town.value == '') {
        ftxt += '\n- Please enter a Town/City.';
    }

    if (document.editprofile.County.value == '') {
        ftxt += '\n- Please enter a County.';
    }

    if (checkPostCode(document.editprofile.Postcode.value) == false) {
        ftxt += '\n- Please enter a FULL Postcode.';
    }

    if (document.editprofile.TelNo.value == '') {
        ftxt += '\n- Please enter your Telephone Number.';
    }

    if (isValidEmail(document.editprofile.OrganisationsEmail.value) == false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Registration Form */
function notifyUpload(theVal) {             
    if (confirm('Are you sure you want to upload the selected file?')) {
        //alert('Thank you, this file will be uploaded when you submit your registration.');
        theVal.className = 'uploadbuttonsel';
    }
}

function manageFormFieldControl(theVal,checkedVal) {
    var thefield = document.getElementById(theVal);

    if (checkedVal) {
        thefield.disabled = false;
        thefield.className = 'maintextarea';
    }
    else {
        thefield.disabled = true;
        thefield.className = 'maintextarea disabled';
        thefield.value = '';
    }
}

function checkregister() {
    var ftxt = '';

    /* Personal */
    var ptxt = '';
    if (document.registerform.Title.value == '') {
        ptxt += '\n- Please enter your Title.';
    }

    if (document.registerform.Firstname.value == '') {
        ptxt += '\n- Please enter your First Name.';
    }

    if (document.registerform.Lastname.value == '') {
        ptxt += '\n- Please enter your Last Name.';
    }

    if (isDate(document.registerform.DateofBirth.value) == false) {
        ptxt += '\n- Please enter your Date of Birth (Format dd/mm/yyy).';
    }

    if (document.registerform.Home_Add1.value == '') {
        ptxt += '\n- Please enter your Address 1 / Building Name.';
    }

    if (document.registerform.Home_Add2.value == '') {
        ptxt += '\n- Please enter your Address 2 / Street.';
    }

    if (document.registerform.Home_Town.value == '') {
        ptxt += '\n- Please enter your Town/City.';
    }

    if (document.registerform.Home_County.value == '') {
        ptxt += '\n- Please enter your County.';
    }

    if (document.registerform.Home_Postcode.value == '') {
        ptxt += '\n- Please enter your Postcode.';
    }

    if (ptxt !== '') {
        ftxt += '\n** Personal Details **\n' + ptxt;
    }

    /* Business */
    var btxt = '';

    if (document.registerform.Name.value == '') {
        btxt += '\n- Please enter your Company Name.';
    }

    if (document.registerform.Street.value == '') {
        btxt += '\n- Please enter your Street.';
    }

    if (document.registerform.Town.value == '') {
        btxt += '\n- Please enter your Town/City.';
    }

    if (document.registerform.County.value == '') {
        btxt += '\n- Please enter your County.';
    }

    if (checkPostCode(document.registerform.Postcode.value) == false) {
        btxt += '\n- Please enter your FULL Postcode.';
    }

    if (document.registerform.TelNo.value == '') {
        btxt += '\n- Please enter your Telephone Number.';
    }

    if (isValidEmail(document.registerform.OrganisationsEmail.value) == false) {
        btxt += '\n- Please enter your Email Address.';
    }

    if (document.registerform.Employed_TakingInstructions.value == '') {
        btxt += '\n- Please advise how many people are employed for Taking Instructions.';
    }

    if (document.registerform.Employed_AdminOther.value == '') {
        btxt += '\n- Please advise how many people are employed for Admin/Other.';
    }

    var legalstatus = false;
    for (var i = 0; i < 4; i++) {
        if (document.registerform.Company_LegalStatus[i].checked) {
            legalstatus = true;
        }
    }
    if (legalstatus == false) {
        btxt += '\n- Please select what type of entity you are operating as.';
    }

    if (document.registerform.Willwriting_Occupation.value == '') {
        btxt += '\n- Please select your Willwriting Occupation.';
    }

    if (document.registerform.Willwriting_SystemInPlace.value == '') {
        btxt += '\n- Please select your Willwriting System in Place.';
    }
    
    /*
    if (document.registerform.PI_Insurer.value == '') {
        btxt += '\n- Please enter your Professional Indemnity Insurer.';
    } else {
         if (document.registerform.PI_FileName.value == '') {
            btxt += '\n- Please select your Professional Indemnity Insurance Certificate.';
        }
    }
    
    if (document.registerform.PL_Insurer.value == '') {
        btxt += '\n- Please enter your Public Liability Insurer.';
    }
    else {
        if (document.registerform.PL_FileName.value == '') {
            btxt += '\n- Please select your Public Liability Insurance Certificate.';
        }
    }
    */
    
    if (btxt !== '') {
        if (ftxt !== '') {
            ftxt += '\n';
        }
        ftxt += '\n** Business Details **\n' + btxt;
    }

    /* References */
    var rtxt = '';

    if (document.registerform.Ref1Name.value == '' || document.registerform.Ref1Address.value == '' || checkPostCode(document.registerform.Ref1Postcode.value) == false) {
        rtxt += '\n- Please enter a Reference 1 Name, Address & Postcode.';
    }

    if (document.registerform.Ref2Name.value == '' || document.registerform.Ref2Address.value == '' || checkPostCode(document.registerform.Ref2Postcode.value) == false) {
        rtxt += '\n- Please enter a Reference 2 Name, Address & Postcode.';
    }

    if (rtxt !== '') {
        if (ftxt !== '') {
            ftxt += '\n';
        }
        ftxt += '\n** References **\n' + rtxt;
    }

    /* Other */    
    var otxt = '';
    
    if (document.registerform.WhyBecomeMember_Details.value == '') {
        otxt += '\n- Please specify why you wish to become a member of IPW.';
    }

    if (document.registerform.CV_Attached.checked == false) {
        otxt += '\n- Please select that your CV is attached.';
    }
    else {
        if (document.registerform.CV_Upload.value == '') {
            otxt += '\n0 Please select a CV File.';
        }
    }

    if (otxt !== '') {
        if (ftxt !== '') {
            ftxt += '\n';
        }
        ftxt += '\n** Final Steps **\n' + otxt;
    }

    /* CAPTCHA Check */
    if (document.registerform.CaptchaEntry.value !== document.registerform.RandomCode.value) {
        ftxt += '\n- The Registration Code entered was not recognised. Please try again.';
    }
    

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        if (document.registerform.AgreedRegisterTerms.checked == false) {
            alert('You must agree to the Terms & Conditions to continue.');
            return false;
        }
        else {
            return true;
        }
    }
}

/* New Review Form */
function checknewreviewform() {
    var ftxt = '';

    //Q2
    var a = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.LettersEngagementInstructions[i].checked) {
            a = true;
        }
    }
    if (a == false) {
        ftxt += '\n- Please specify an answer for Question 2.';
    }

    //Q3
    var b = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.WrittenInformationInstructions[i].checked) {
            b = true;
        }
    }
    if (b == false) {
        ftxt += '\n- Please specify an answer for Question 3.';
    }

    //Q4
    var c = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.ProofofIdentity[i].checked) {
            c = true;
        }
    }
    if (c == false) {
        ftxt += '\n- Please specify an answer for Question 4.';
    }

    //Q5
    var d = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.DocumentsCompletedOnTime[i].checked) {
            d = true;
        }
    }
    if (d == false) {
        ftxt += '\n- Please specify an answer for Question 5.';
    }

    //Q6
    var e = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.SigningSupervised[i].checked) {
            e = true;
        }
    }
    if (e == false) {
        ftxt += '\n- Please specify an answer for Question 6.';
    }

    //Q7
    var f = false;
    for (var i = 0; i < 3; i++) {
        if (document.revform.OpportunitySignedSupervised[i].checked) {
            f = true;
        }
    }
    if (f == false) {
        ftxt += '\n- Please specify an answer for Question 7.';
    }

    //Q8
    var g = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.UnderstandDocuments[i].checked) {
            g = true;
        }
    }
    if (g == false) {
        ftxt += '\n- Please specify an answer for Question 8.';
    }

    //Q9
    var h = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.PayFeesBefore[i].checked) {
            h = true;
        }
    }
    if (h == false) {
        ftxt += '\n- Please specify an answer for Question 9.';
    }

    //Q10
    var j = false;
    for (var i = 0; i < 4; i++) {
        if (document.revform.PayFeesBeforeWhenMake[i].checked) {
            j = true;
        }
    }
    if (j == false) {
        ftxt += '\n- Please specify an answer for Question 10.';
    }

    //Q11
    var k = false;
    for (var i = 0; i < 5; i++) {
        if (document.revform.StarRating[i].checked) {
            k = true;
        }
    }
    if (k == false) {
        ftxt += '\n- Please specify an answer for Question 11.';
    }

    //Q12
    if (document.revform.Review.value == '') {
        ftxt += '\n- Please enter your Review.';
    }

    //Q13
    var l = false;
    for (var i = 0; i < 2; i++) {
        if (document.revform.RecommendService[i].checked) {
            l = true;
        }
    }
    if (l == false) {
        ftxt += '\n- Please specify an answer for Question 13.';
    }
    
    //Q13

    //Q14
    if (document.revform.Name.value == '') {
        ftxt += '\n- Please ente your Name.';
    }

    if (isValidEmail(document.revform.Email.value) == false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (document.revform.PINNumber.value == '') {
        ftxt += '\n- Please enter the PIN number you were supplied.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

function controlQ7(theVal) {
    if (theVal == 'True') {
        document.revform.OpportunitySignedSupervised[0].checked = true;
    }
}

function controlQ9(theVal) {
    if (theVal == 'False') {
        document.revform.PayFeesBeforeWhenMake[0].checked = true;
    }
}

/* No Group Scheme */
function marknogroupscheme() {
    var NumberSchemes = document.dashforms.NumberSchemes.value;
    
    if (document.dashforms.SchemeID[0].checked){
        for (var i = 1; i < (NumberSchemes+1); i++) {
            document.dashforms.SchemeID[i].checked = false;
        }
    }
}

function markgroupschemes() {
    document.dashforms.SchemeID[0].checked = false;
}
