﻿//*************************************************************************/
//
//  Master Page Functions
//
//
//*************************************************************************/

// opens the popup on the master page.
function showWin(win_index) {

    //Shows the specified window.

    var main_pop = ASPxClientPopupControl.Cast('c_popup');
    main_pop.ShowWindow(main_pop.GetWindow(win_index));

    return false;
}

//*************************************************************************/
//
//  Contact Form Animation Functions
//
//
//*************************************************************************/

function setupCfForm() {
    // Set initial focus.
    $('#txtFName').focus();

    //Add event handlers.

    var btnToOne = new Array
    btnToOne = $('.cfbtn_goto1');
    for (var i = 0; i < btnToOne.length; i++) {
        btnToOne.eq(i).click(function () {
            return goToStep(1);
        });
    }

    var btnToTwo = new Array
    btnToTwo = $('.cfbtn_goto2');
    for (var i = 0; i < btnToTwo.length; i++) {
        btnToTwo.eq(i).click(function () {
            return goToStep(2);
        });
    }

    var btnToThree = new Array
    btnToThree = $('.cfbtn_goto3');
    for (var i = 0; i < btnToThree.length; i++) {
        btnToThree.eq(i).click(function () {
            return goToStep(3);
        });
    }


    // Add necessary CSS properties.
    $('#cf_ContactForm').css('position', 'absolute');
    $('#cf_ContactForm').css('z-index', '2');
    $('#cf_ContactForm').css('overflow', 'hidden');
    $('#cf_Wrapper').css('position', 'absolute');
}
function goToStep(stepnum) {

    var wrapperX;

    switch (stepnum) {
        case 1:
            wrapperX = '0px';
            break;
        case 2:
            wrapperX = '-500px';
            break;
        case 3:
            wrapperX = '-1000px';

            break;
        default:
            return false;
    }
    $('#cf_Wrapper').animate({ left: wrapperX }, 1000, 'swing');
    return false;
}

//*************************************************************************/
//
//  Contact Form Validation Functions
//
//
//*************************************************************************/


function isValidForm() {
    var d = document;

    // Get all required text fields and test for empty..
    var fields = new Array('txtFName', 'txtLName', 'txtEmail', 'txtSubject', 'txtNarrative');
    var msgs = new Array('Please enter your first name.', 'Please enter your last name.', 'Please enter your email address.', 'Please enter a subject for your message.', 'Please enter a message.');

    for (var i = 0; i < fields.length; i++) {
        if (isEmpty(document.getElementById(fields[i]).value) == true) {
            requiredExc(fields[i], msgs[i], 1);
            return false;
        }
    }

    // Check email expression.
    if (isEmail(d.getElementById('txtEmail').value) == false) {
        alert('Please enter a valid email address.');
        goToStep(1);
        d.getElementById('txtEmail').focus();
        d.getElementById('txtEmail').select();
    }
    return true;
}
function isEmpty(str) {
    if (str == '' || str == null) {
        return true;
    } else {
        return false;
    }
}
function requiredExc(txtid, errmsg, senderstep) {
    goToStep(senderstep);
    document.getElementById(txtid).focus();
    alert(errmsg);
    return false;

}
function isEmail(str) {
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
