﻿// JScript File

function IsValidEntry(sControl)
{
    with (sControl)
    {
        if (value=="" || value==null)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

function IsValidEmail(sControl)
{
    with (sControl)
    {
        iAtPos = value.indexOf("@");
        iLastAtPos = value.lastIndexOf("@");
        iLastDotPos = value.lastIndexOf(".");
        iLastChrPos = value.length - 1;
        if (iAtPos < 1 || iLastDotPos - iAtPos < 2 || iLastDotPos == iLastChrPos || iAtPos != iLastAtPos)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}

function CheckForm(frmForm, sAccessCode)
{
    with (frmForm)
    {
        bNameOk = IsValidEntry(txtName);
        if (bNameOk == false)
        {
            alert("Please enter your Name.");
            txtName.focus();
            return false;
        }
        else
        {
            bTelNoOk = IsValidEntry(txtTelNo);
            bEmailOk = IsValidEmail(txtEmail);
            if (bTelNoOk == false && bEmailOk == false)
            {
                alert("Please enter a valid Email address or Telephone number.");
                if (bEmailOk == false)
                {
                    txtEmail.focus();
                }
                else
                {
                    txtTelNo.focus();
                }
                return false;
            }
			else
			{
				bAccessCode = IsValidEntry(txtAccessCode);
				if (bAccessCode == false)
				{
					alert("Please enter the Access Code.");
					txtAccessCode.focus();
					return false;
				}
				else
				{
					if (txtAccessCode.value != sAccessCode)
					{
						alert("Invalid Access Code.");
						txtAccessCode.focus();
						return false;
					}
				}
			}
        }
    }
}
function CheckForm2(frmForm)
{
	sAccessCode = 'OWD';
    with (frmForm)
    {
        bNameOk = IsValidEntry(txtName);
        if (bNameOk == false)
        {
            alert("Please enter your Name.");
            txtName.focus();
            return false;
        }
        else
        {
            bTelNoOk = IsValidEntry(txtTelNo);
            bEmailOk = IsValidEmail(txtEmail);
            if (bTelNoOk == false && bEmailOk == false)
            {
                alert("Please enter a valid Email address or Telephone number.");
                if (bEmailOk == false)
                {
                    txtEmail.focus();
                }
                else
                {
                    txtTelNo.focus();
                }
                return false;
            }
			else
			{
				bAccessCode = IsValidEntry(txtAccessCode);
				if (bAccessCode == false)
				{
					alert("Please enter the Access Code.");
					txtAccessCode.focus();
					return false;
				}
				else
				{
					if (txtAccessCode.value != sAccessCode)
					{
						alert("Invalid Access Code.");
						txtAccessCode.focus();
						return false;
					}
				}
			}
        }
    }
}
function CheckForm3()
{
	frmForm = document.forms['contact'];
	sAccessCode = 'OWD';
    with (frmForm)
    {
        bNameOk = IsValidEntry(txtName);
        if (bNameOk == false)
        {
            alert("Please enter your Name.");
            txtName.focus();
            return false;
        }
        else
        {
            bTelNoOk = IsValidEntry(txtTelNo);
            bEmailOk = IsValidEmail(txtEmail);
            if (bTelNoOk == false && bEmailOk == false)
            {
                alert("Please enter a valid Email address or Telephone number.");
                if (bEmailOk == false)
                {
                    txtEmail.focus();
                }
                else
                {
                    txtTelNo.focus();
                }
                return false;
            }
			else
			{
				//bAccessCode = IsValidEntry(txtAccessCode);
				//if (bAccessCode == false)
				//{
				//	alert("Please enter the Access Code.");
				//	txtAccessCode.focus();
				//	return false;
				//}
				//else
				//{
				//	if (txtAccessCode.value != sAccessCode)
				//	{
				//		alert("Invalid Access Code.");
				//		txtAccessCode.focus();
				//		return false;
				//	}
				//}
				frmForm.submit();
			}
        }
    }
}
