﻿function init(page) {
    $('#nav #' + page).addClass('active');
    $('#center ul li:first').addClass('first');
    $('#center ul li:last').addClass('last');
    init_footer();
}

function init_footer() {
    $('#footer ul li:first').addClass('first');
    $('#footer ul li:last').addClass('last');
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function listStores() {
    $('ul.stores a.header').click(
        function() {
            if ($(this).parent().css('height') == '195px') {
                $(this).parent().css('height', '0px');
                $(this).parent().removeClass('active');
            }
            else {
                $(this).parent().css('height', '195px');
                $(this).parent().addClass('active');
            }
            return false;
        }
    );
}

function listContracts() {
        $('ul.contract a.header').click(
        function() {
        if ($(this).parent().css('height') == '55px') {
                $(this).parent().css('height', '0px');
                $(this).parent().removeClass('active');
            }
            else {
                $(this).parent().css('height', '55px');
                $(this).parent().addClass('active');
            }
            return false;
        }
    );
}

function isValid() {
    valid = true;
    $('.step input[type=text], .step textarea').each(function() {
    if (trim($(this).val()) == '' && !$(this).attr('disabled') && $(this).attr('required')) {
            $(this).addClass('required');
            valid = false;
        }
    });
    return valid;
}
