﻿var validEmail = true;
var validDOB = true;
var errors = new Array();

function Submitting(hide) {
    var btn = document.getElementById(btnRegisterID);
    var pSub = document.getElementById('pSubmitting');

    if (hide) {
        btn.style.display = 'none';
        pSub.style.display = '';
    }
    else {
        btn.style.display = '';
        pSub.style.display = 'none';
    }
}

function emailValidationResult(result) {
    var emailResult = result.split(',')[0];
    var dobResult = result.split(',')[1];

    if (emailResult == 'false') {
        document.getElementById(txtEmailID).className = 'val';
        validEmail = false;
    }
    else {
        validEmail = true;
    }

    if (dobResult == 'false') {
        validDOB = false;

       
    }
    else {
        validDOB = true;

    }

    ValidateRegistration2();
}


function dobValidationResult(result) {
    if (result == 'false') {
        validDOB = false;
    }
    else {
        validDOB = true;
    }
}

function validateRequiredFields() {
    var container = document.getElementById('registration');
    var inputControls = container.getElementsByTagName('input');
    var ddlControls = container.getElementsByTagName('select');
    var excludeIDs = new Array();
    var requiredMissing = false;

    //clear previous errors
    errors = new Array();
    excludeIDs[0] = txtHouseNoID;

    var isValid = true;

    for (var i = 0; i < inputControls.length; i++) {
        if (inputControls[i].id.indexOf('chk') == -1 && inputControls[i].value.length == 0) {

            var exempt = false;

            for (var ii = 0; ii < excludeIDs.length; ii++) {
                if (excludeIDs[ii] == inputControls[i].id) {
                    exempt = true;
                    break;
                }
            }
            if (!exempt && inputControls[i].style.display != 'none') {
                inputControls[i].className = 'val';
                isValid = false;
                requiredMissing = true;
            }
        }
        else inputControls[i].className = 'input';
    }

    for (var i = 0; i < ddlControls.length; i++) {
        var divContainer = $(ddlControls[i]).parent();
        if (ddlControls[i].value.length == 0) {
            divContainer.addClass("divVal");
            divContainer.width($(ddlControls[i]).width());
            isValid = false;
            requiredMissing = true;
        }
        else {
            //set correct class for birth ddls as we need to keep inline
            if (divContainer.attr("id").indexOf('Birth') > -1) {
                divContainer.addClass("dob");
            }
            else
                divContainer.removeClass("dob");
        }
    }

    if (requiredMissing) {
        //add to errors
        errors[errors.length] = "Please complete the missing details above";
    }
    return isValid;
}

function updateDisplay(control) {
    if (control.value.length > 0) {
        //if select remove class from container
        if (control.id.indexOf('ddl') > -1) {
            var divContainer = control.parentElement;
            if (divContainer.id.indexOf('Birth') > -1) {
                divContainer.className = 'dob';
            }
            else
                divContainer.className = '';
        }
        else
            control.className = 'input';
    }
}

function DisplayErrors() {
    if (errors.length > 0) {
        var containingDiv = document.getElementById('id1');
        var erContainer = document.getElementById('erContainer');

        if (erContainer != undefined) {
            //delete then rebuild
            containingDiv.removeChild(erContainer);
        }
        erContainer = document.createElement('ul');
        erContainer.setAttribute('id', 'erContainer');
        erContainer.className = 'errorList';

        for (var i = 0; i < errors.length; i++) {
            var li = document.createElement('li');
            $(li).text("! " + errors[i]);
            erContainer.appendChild(li);
        }
        containingDiv.appendChild(erContainer);
    }
    else {
        //remove if exists
        var containingDiv = document.getElementById('id1');
        var errorList = document.getElementById('erContainer');

        if (errorList != undefined)
            containingDiv.removeChild(errorList);
    }
}


function popupTerms() {
    var w = window.open('', 'prizeterms', 'width=700,height=400,resizeable=no', true);
    var d = w.document;


    d.write("<h1>£5 Reward Voucher Terms and Conditions</h1>");
    d.write("<ul style='list-style:none;padding:0;margin:15px 0;'>");
    d.write("<li>* The £5 reward for completing the questionnaire is in the form of an online reward voucher that can be redeemed at Foxy Bingo. </li>");
    d.write("<li>* There is no deposit required and you are not obliged to spend any money at any time with Foxy Bingo, Other offers may differ.</li>");
    d.write("<li>* Any winnings gained from use of your free £5 can be withdrawn in line with Foxy bingo withdrawal rules. Other sites may have different rules that apply. Please check their own Terms and Conditions.</li>");
    d.write("<li>* This reward is not available to existing Foxy bingo members. Other sites terms and conditions may vary. Please check with each site for their own terms and conditions.</li>");
    d.write("<li>* You must be 18 or over to participate in this promotion.</li>");
    d.write("<li>* No purchase required.</li>");
    d.write("</ul>");

    //newWindow.document.write(* The £5 reward for completing the questionnaire is in the form of an online reward voucher that can be redeemed at Foxy Bingo. 
    //newWindow.document.write(* There is no deposit required and you are not obliged to spend any money at any time with Foxy Bingo, Other offers may differ.
    //* Any winnings gained from use of your free £5 can be withdrawn in line with Foxy bingo withdrawal rules. Other sites may have different rules that apply. 
    //  Please check their own Terms and Conditions.
    //* This reward is not available to existing Foxy bingo members. Other sites terms and conditions may vary. Please check with each site for their own terms and conditions.
    //* You must be 18 or over to participate in this promotion.
    //* No purchase required."


}
