﻿//////////////////////////////////////////////////
//                                              //
// Filename: form.js                            //
// Purpose: Functions to validate form input    //
// Author: James Radford BSc                    //
// Creation date: 22/11/2007                    //
//                                              //
//////////////////////////////////////////////////


// page 1 validate

function ClientValidate_Page1(sender, args) {            
    args.IsValid = true;   
    x = document;
    
    CustomValidator1.innerHTML = "";
                
    if(args.IsValid == false) {  
        CustomValidator1.innerHTML += "";
    }
    if(x.getElementById('salutation_dropdown').value == 'Select') {
        CustomValidator1.innerHTML += "- Title Required<br />";
        args.IsValid = false;   
    }    
    if(x.getElementById('firstname').value == '') {
        CustomValidator1.innerHTML += "- Firstname Required<br />";                
        args.IsValid = false;   
    }    
    if(x.getElementById('lastname').value == '') {
        CustomValidator1.innerHTML += "- Lastname Required<br />";     
        args.IsValid = false;   
    }    
    if(x.getElementById('address1').value == '') {
        CustomValidator1.innerHTML += "- Address 1 Required<br />";   
        args.IsValid = false;   
    }    
    if(x.getElementById('town').value == '') {
        CustomValidator1.innerHTML += "- Town Required<br />";   
        args.IsValid = false;   
    }    
    if(x.getElementById('post').value == '') {
        CustomValidator1.innerHTML += "- Post Required<br />";  
        args.IsValid = false;   
    }    
    if(x.getElementById('gender_0').checked == false && x.getElementById('gender_1').checked == false) {
        CustomValidator1.innerHTML += "- Gender Required<br />";  
        args.IsValid = false;   
    }
    if(x.getElementById('country').value == 'Select') {
        CustomValidator1.innerHTML += "- Country Required<br />";  
        args.IsValid = false;   
    }    
    if(x.getElementById('days').value == 'DD') {
        CustomValidator1.innerHTML += "- DD Required<br />";  
        args.IsValid = false;   
    }    
    if(x.getElementById('months').value == 'MM') {
        CustomValidator1.innerHTML += "- MM Required<br />";  
        args.IsValid = false;   
    }    
    if(x.getElementById('years').value == 'YYYY') {
        CustomValidator1.innerHTML += "- YYYY Required<br />";  
        args.IsValid = false;   
    }    
    if(x.getElementById('email').value == '') {
        CustomValidator1.innerHTML += "- Email Required<br />";  
        args.IsValid = false;   
    }    
    if(args.IsValid == false) {               
        document.getElementById("error-box").style.backgroundColor="#33200a";
        document.getElementById("error-title").style.display="block";
    }
    else {
        document.getElementById("error-box").style.backgroundColor="#000";
        document.getElementById("error-title").style.display="none";
    }
}


// page 2 validate

function ClientValidate_Page2(sender, args) {       
    x = document;
    CustomValidator2.innerHTML = "";
    
    if(x.getElementById("purchase_location").value != "Select" && x.getElementById("biggest_factor").value != "Select" && x.getElementById("hear_about").value != "Select" && x.getElementById("terms").checked == true ) {
        // submit form        
        
        args.IsValid = true;   
        document.getElementById("error-box").style.backgroundColor="#000";
        document.getElementById("error-title").style.display="none";
    }
    else {
        // incomplete!        
                      
        document.getElementById("error-title").style.display = "block";
        document.getElementById("error-box").style.backgroundColor = "#32200a";
        args.IsValid = false;   
        
        if(x.getElementById("purchase_location").value == "Select") {
            CustomValidator2.innerHTML += "- Purchase location Required<br />";  
        }
        if(x.getElementById("biggest_factor").value == "Select") {
            CustomValidator2.innerHTML += "- Biggest factor Required<br />";  
        }
        if(x.getElementById("hear_about").value == "Select") {
            CustomValidator2.innerHTML += "- Hear about Required<br />";  
        }
        if(!x.getElementById("terms").checked) {
            CustomValidator2.innerHTML += "- Please agree to the terms<br />";  
        }
        args.IsValid = false;   
    }
}