﻿function contactUsLoad()
{
    document.getElementById("customer-representatives").selectedIndex = 0;
    document.getElementById("accreditation-trainers").selectedIndex = 0;
}

function redirect(type)
{
    try
    {
        var customerRepresentatives = document.getElementById(type);
        var region = customerRepresentatives.options[customerRepresentatives.selectedIndex].text;
        
        if (type == "customer-representatives")
        {
            switch(region)
            {
                case "Western Australia and Northern Territory":
                    window.location = "contact-us/customer-representatives.html#western-australia-and-northern-territory";
                    break;
                case "South Australia":
                    window.location = "contact-us/customer-representatives.html#south-australia";
                    break;
                case "Victoria":
                    window.location = "contact-us/customer-representatives.html#victoria";
                    break;
                case "New South Wales":
                    window.location = "contact-us/customer-representatives.html#new-south-wales";
                    break;
                case "Australian Capital Territory":
                    window.location = "contact-us/customer-representatives.html#australian-capital-territory";
                    break;
                case "Queensland":
                    window.location = "contact-us/customer-representatives.html#queensland";
                    break;
                case "Tasmania":
                    window.location = "contact-us/customer-representatives.html#tasmania";
                    break;
                case "New Zealand":
                    window.location = "contact-us/customer-representatives.html#new-zealand";
                    break;
                case "Malaysia":
                    window.location = "contact-us/customer-representatives.html#malaysia";
                    break;
                case "India":
                    window.location = "contact-us/customer-representatives.html#india";
                    break;   
            }
        }
        else
        {
            switch(region)
            {
                case "Western Australia":
                    window.location = "contact-us/accreditation-trainers.html#western-australia";
                    break;
                case "Northern Territory":
                    window.location = "contact-us/accreditation-trainers.html#northern-territory";
                    break;
                case "South Australia":
                    window.location = "contact-us/accreditation-trainers.html#south-australia";
                    break;
                case "Victoria":
                    window.location = "contact-us/accreditation-trainers.html#victoria";
                    break;
                case "New South Wales":
                    window.location = "contact-us/accreditation-trainers.html#new-south-wales";
                    break;
                case "Australian Capital Territory":
                    window.location = "contact-us/accreditation-trainers.html#australian-capital-territory";
                    break;
                case "Queensland":
                    window.location = "contact-us/accreditation-trainers.html#queensland";
                    break;
                case "Tasmania":
                    window.location = "contact-us/accreditation-trainers.html#tasmania";
                    break;
                case "Australian Capital Territory":
                    window.location = "contact-us/accreditation-trainers.html#australian-capital-territory";
                    break;
                case "New Zealand":
                    window.location = "contact-us/accreditation-trainers.html#new-zealand";
                    break;
                case "Malaysia":
                    window.location = "contact-us/accreditation-trainers.html#malaysia";
                    break;
            }   
        }
    }
    catch(error)
    {
        window.location = "contact-us/central-office.html";
    }
}

function onlineFormLoad()
{
    document.getElementById("Name").focus();
}

function validateOnlineForm()
{
    try
    {
        var valid = true;
        var errorMessage = "Please enter in a value for:          \n\n";
        var errorFlag = false;
        var name = document.getElementById("Name");
        var email = document.getElementById("EMail");
        var message = document.getElementById("Body");
        
        if (name.value == null || name.value == "")
        {
            valid = false;
            errorMessage += "- Name\n";
            
            errorFlag = true;
            name.focus();
        }
        
        if (email.value == null || email.value == "")
        {
            valid = false;
            errorMessage += "- Email\n";
            
            if (!errorFlag)
            {
                errorFlag = true;
                email.focus();
            }
        }
        else
        {
            var AtPosition = email.value.indexOf("@");
            var LastDotPosition = email.value.lastIndexOf(".");
            var EmailLength = email.value.length;
            
            if (AtPosition < 1 || LastDotPosition - AtPosition < 2 || EmailLength - LastDotPosition < 2)
            {
                valid = false;
                errorMessage += "- Email (Email needs to be a correct email address)\n";
                
                if (!errorFlag)
                {
                    errorFlag = true;
                    email.focus();
                    email.select();
                }
            }
        }
        
        if (message.value == null || message.value == "")
        {
            valid = false;
            errorMessage += "- Message\n";
            
            if (!errorFlag)
            {
                message.focus();
            }
        }
        
        if (!valid)
        {
            window.alert(errorMessage);
            return false;
        }
        else
        {
            return true;
        }
    }
    catch(error)
    {
        window.location = "central-office.html";
    }
}