﻿function checkForm()
{
    var intGSID = document.getElementById('intGSID').value
    var intGSIDConf = document.getElementById('intGSIDConf').value
    var ixSchoolID = document.getElementById('ixSchoolID').value
    var strEmailAddress = document.getElementById('strEmailAddress').value
    var strEmailAddressConf = document.getElementById('strEmailAddressConf').value
    var strUserName = document.getElementById('strUserNameReg').value
    var strPIN = document.getElementById('strPINReg').value
    var strPINConf = document.getElementById('strPINConf').value
    var strSecQuestion = document.getElementById('strSecQuestion').value
    var strAnswer = document.getElementById('strAnswer').value
    var strFirstName = document.getElementById('strFirstName').value
    var strLastName = document.getElementById('strLastName').value
 
    if (intGSID == '')
    {
        alert('Please enter a Card ID');
        return false;
    }
    if (intGSID != intGSIDConf)
    {
        alert('Please make sure your card number and confirmation card number match.');
        return false;
    }
    if (ixSchoolID == '0')
    {
        alert('Please select the school that you attend.');
        return false
    }
    /*if (strEmailAddress.length < 1) 
    {
        alert('Please enter an email address.');
        return false;
    }*/
   
    if (strEmailAddress.length > 0)
    {
        if (!checkEmailAddress(strEmailAddress))
        {
            alert('You have entered an invalid email address.');
            return false;
        }
        if (strEmailAddress != strEmailAddressConf)
        {
            alert('Please ensure that your email address and confirmation email address match.');
            return false;
        }
    }
    if (strUserName == '' || strUserName.length < 6)
    {
        alert('Please enter a valid username.\n\nUsernames must be 6 chararacters or longer.');
        return false;
    }
    if (strPIN != strPINConf || strPIN == '' || strPIN.length < 6)
    {
        alert('Please enter a valid password and ensure that the confirmation matches.\n\nPasswords must be 6 characters or longer.');
        return false;
    }
    if (strSecQuestion == '')
    {
        alert('Please enter a security question.\n\nWe will use this to reset your password should you forget.');
        return false;
    }
    if (strAnswer == '')
    {
        alert('Please enter an answer to your security question.');
        return false;
    }
    if (strFirstName == '')
    {
        alert('Please enter your first name.');
        return false;
    }
    if (strLastName == '')
    {
        alert('Please enter your last name.');
        return false;
    }
    return true;
}
function checkEmailAddress(emailstr)
{
	var emailFilter=/^(([a-zA-Z0-9_\-]+)|(([a-zA-Z0-9_\-]+)([\.]{1,1}[a-zA-Z0-9_\-]{1,}))+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!(emailFilter.test(emailstr))) 
		return false;
	return true;
}

function checkPW()
{
    var strAnswer = document.getElementById('strAnswer').value
    if (strAnswer == '')
    {
        alert('Please enter the answer to your security question');
        return false;
    }
    return true;
}

function checkNewPW()
{
    var strPINcurr = document.getElementById('strPINcurr').value
    var strPINnew = document.getElementById('strPINnew').value
    var strPINnewconf = document.getElementById('strPINnewconf').value
    if (strPINcurr.length < 6)
    {
        alert('Please enter your current password.');
        return false;
    }
    if (strPINnew != strPINnewconf || strPINnew == '' || strPINnew.length < 6)
    {
        alert('Please enter a valid password and ensure that the confirmation matches.\n\nPasswords must be 6 characters or longer.');
        return false;
    }
    return true;
}
 
function checkUN()
{
    var strUserName = document.getElementById('strUserNamePW').value
    if (strUserName == '' || strUserName.length < 6)
    {
        alert('Please enter a valid username.\n\nUsernames must be 6 chararacters or longer.');
        return false;
    }
    return true;
}

function checkMsg()
{
    var strMessage = document.getElementById('strMessage').value
    if (strMessage == '')
    {
        alert('Please enter a message before sending.');
        return false;
    }
    
    return true;
}

function checkClaimForm()
{
    var strAddress1 = document.getElementById('strAddress1').value
    var strAddress2 = document.getElementById('strAddress2').value
    var strAddress3 = document.getElementById('strAddress3').value
    var strPostCode = document.getElementById('strPostCode').value
    
    if (strAddress1 == '')
    {
        alert('Please enter the delivery address for your reward.');
        return false;
    }
    if (strPostCode == '')
    {
        alert('Please enter the delivery postcode into the box provided.');
        return false
    }
    return true;
}

function lunchOrYs()
{
    var objSchool = document.getElementById('ixSchoolID')
    var selSchool = new String(objSchool.options[objSchool.selectedIndex].text)
    //selSchool = selSchool.toLowerCase
    if (selSchool.indexOf('McLaren') == '-1')
        document.getElementById('ysid').innerHTML = ""
    else
        document.getElementById('ysid').innerHTML = "/Young Scot"
}
