﻿/// <reference path="jquery-1.4.3.js" />
function HideMap(e) {
    $('.USMap').slideUp();
    $('.foundLocations').show();
}

function ShowMap() {
    $('.USMap').slideDown();
    $('.foundLocations').hide();
}

function HideEmailAddressInfo() {
    $('.mainEmailAddressLbl').hide();
    $('.mainEmailAddressTextBox').hide();
    $('.mainSubmitBtn').hide();
}

function ShowThankYouInfo() {
    $('.mainEmailThanksLbl').show();
}

// Validation function for an email field
function ValidateEmail(sender, args) {
    var rege = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/gi;
    if (args.Value.length > 0) {
        args.IsValid = ValidateRegex(args.Value, rege);
    }
    else {
        args.IsValid = false;
    }
}

// Validation function for a zip code field
function ValidateZipCode(sender, args) {
    var rege = /^\d{5}$/gi;
    args.IsValid = ValidateRegex(args.Value, rege); ;
}

// Validation function for Hours Per Day
function ValidateHoursPerDay(sender, args) {    
    args.IsValid = ValidateIntRange(args.Value, 1, 24);
}

// Validation function for Days Per Week
function ValidateDaysPerWeek(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 1, 7);
}

// Validation function for Weeks Per Year
function ValidateWeeksPerYear(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 1, 52);
}

// Validation function for a Cost per hour
function ValidateCostPerHour(sender, args) {
    args.IsValid = ValidateFloatRange(args.Value, 1.0, 60000000.0);
}

// Validation function for Percent as a whole number
function ValidatePercent(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 0, 100);
}

// Validation function for Number of Employees
function ValidateNumEmployees(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 1, 5000000);
}

// Validation function for additional number of employees
function ValidateNumAdditionalEmployees(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 0, 5000000);
}

// Validation function for additional number of employee hours
function ValidateNumAdditionalEmployeeHours(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 0, 50000000);
}

// Validation function for equipment repair cost per event
function ValidateEquipRepairCost(sender, args) {
    args.IsValid = ValidateFloatRange(args.Value, 0, 1000000000);
}

// Validation function for annual gross revenue
function ValidateAnnualGrossRevenue(sender, args) {
    args.IsValid = ValidateFloatRange(args.Value, 0, 9999999999);
}

// Validation function for downtime hours last year
function ValidateDowntimeHours(sender, args) {
    args.IsValid = ValidateFloatRange(args.Value, 0, 8766);
}

// Validation function for the help desk code
function ValidateHelpDeskCode(sender, args) {
    args.IsValid = ValidateIntRange(args.Value, 0, 999999);
}

// Generic function to determine if a floating point number is within a specified range
function ValidateFloatRange(val, min, max) {
    var rege = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/gi;
    return ValidateNumRange(val, min, max, rege);
}

// Generic function to determine if an integer number is within a specified range
function ValidateIntRange(val, min, max) {
    var rege = /^\d+$/gi;
    return ValidateNumRange(val, min, max, rege);
}

// Generic function that takes in a value, min, max, and the regular expression 
// to check against in order to validate a number is a valid number and within a certain range
function ValidateNumRange(val, min, max, regexPattern) {
    var test = ValidateRegex(val, regexPattern);

    // it is a valid number based on the passed in regular expression
    if (test == true) {
        // make sure that it is within the range
        if (val >= min && val <= max) {
            return true;
        }
    }
    return false;
}

// Generic function used to validate expression against a value
function ValidateRegex(val, regexPattern) {
    var test = val.match(regexPattern);
    if (test != null) {
        return true;
    }
    return false;
}

// used to get to the smart parts web site
function submitForm() {
    document.forms[0].submit();
}



function slide() {

    // item width
    var item_width = $('#carousel_ul li').outerWidth();

    var left_indent = parseInt($('#carousel_ul').css('left')) - item_width;

    $('#carousel_ul:not(:animated)').animate({ 'left': left_indent }, 1000, function () {

        // put the first image after the last for both
        $('#carousel_ul li:last').after($('#carousel_ul li:first'));
        $('#carousel_ul_2 li:last').after($('#carousel_ul_2 li:first'));

        // default back to the regular indent
        $('#carousel_ul').css({ 'left': '-912px' });
        $('#carousel_ul_2').css({ 'left': '-912px' });
    });
}

function seeMore(show) {

    var main = $('#carousel_ul').css('zIndex');

    if (show == 1) {
        $('#carousel_ul_2').hide(function () {
            $('#carousel_ul_2').css('zIndex', main + 1);
            $('#carousel_ul_2').animate({ width: 'toggle' }, 1500, 'linear');
        });
    } else {
        $('#carousel_ul_2').animate({ width: 'toggle' }, 1000, function () {
            $('#carousel_ul_2').css('zIndex', main - 1);
        });
    }
}

$(document).ready(function () {
   
    $('.shadowbox').live('click', function (e) {
        Shadowbox.open(this);
        e.preventDefault();
    });

    $('#carousel_ul_2').hide();

    // 1 to autoslide
    var auto_slide = 1;

    // speed of auto slider   
    var auto_slide_miliseconds = 4000;

    // put the last image before the first one
    $('#carousel_ul li:first').before($('#carousel_ul li:last'));
    $('#carousel_ul_2 li:first').before($('#carousel_ul_2 li:last'));    

    if (auto_slide == 1) {
        // start the timer
        var timer = setInterval('slide()', auto_slide_miliseconds);
    }

    if ($('#carousel_ul').css('z-index') == 'auto') {
        $('#carousel_ul').css('z-index', 100);
        if ($('#carousel_ul_2').css('z-index') == 'auto') {
            $('#carousel_ul_2').css('z-index', 99);
        }
    }

    // click on the next arrow
    $('#carousel-next-area').click(function (e) {
        clearInterval(timer);
        //timer = setInterval('slide()', auto_slide_miliseconds);
        slide();
        e.preventDefault();
    });

    // click on the next arrow
    $('#carousel-next-area-wt').click(function (e) {
        clearInterval(timer);
        //timer = setInterval('slide()', auto_slide_miliseconds);
        slide();
        e.preventDefault();
    });

    // click on the see more area
    $('#carousel-seemore-area').click(function (e) {
        // stop the sliding
        clearInterval(timer);

        seeMore(1);

        e.preventDefault();
    });

    // click on the see more area
    $('#carousel-seemore-area-wt').click(function (e) {
        // stop the sliding
        clearInterval(timer);

        seeMore(1);

        e.preventDefault();
    });

    // click on the see more area
    $('#carousel-seemore-area-wt').click(function (e) {
        // stop the sliding
        clearInterval(timer);

        seeMore(1);

        e.preventDefault();
    });

    $('#carousel-hide-area').click(function (e) {
        // start the sliding again
        //timer = setInterval('slide()', auto_slide_miliseconds);

        seeMore(0);

        e.preventDefault();
    });

    $('#carousel-hide-area-wt').click(function (e) {
        // start the sliding again
        //timer = setInterval('slide()', auto_slide_miliseconds);

        seeMore(0);

        e.preventDefault();
    });
});
