var rh = $('.rotating-headline'),
    rhC = 0;

function rhTimer() {
    $(rh[rhC]).fadeOut(1000, function() {
        $(this).removeClass('active');
    });
    rhC++;
    if (rhC == rh.length) {
        rhC = 0;
    }
    $(rh[rhC]).fadeIn(1000, function() {
        $(this).addClass('active');
    });
}

// Login functions
function Trim(sValue) {
    var objRegExp = /^(\s*)$/;
    if(objRegExp.test(sValue)) {
        sValue = sValue.replace(objRegExp, '');
        if(sValue.length == 0) {
            return sValue;
        }
    }
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(sValue)) {
        sValue = sValue.replace(objRegExp, '$2');
    }
    return sValue;
}

function valid(f) {
    if (Trim(f.txtCustID.value) == "") {
        alert("Please enter your username and password.\n\n If you do not know your password, leave password blank\nand click on Submit.  We will immediately email your password\nto the email address that we have on file.");
        f.txtCustID.focus();
        return false;
    }
    if (Trim(f.txtCustPWD.value) == "") {
        f.hidFormName.value = "frmForgotCustPWD";
        f.action = "/login.asp";
        return true;
    }
    return true;
}

function UCase(oOBJ) {
    var sTemp = oOBJ.value;
    sTemp = sTemp.toUpperCase();
    oOBJ.value = sTemp;
}

$(function() {
    // External Links
    $('a[rel=external]').click(function (e) {
        e.preventDefault();
        window.open($(this).attr('href'));
    });
    
    // Main Menu
    $('.main-menu .wrapper>ul>li').hover(function() {
        if ($('ul', $(this)).length > 0) {
            $('ul', $(this)).show();
        }
    }, function() {
        if ($('ul', $(this)).length > 0) {
            $('ul', $(this)).hide();
        }
    });

    // Height
    var sloganH = parseInt($('.slogan').height()),
        contentH = parseInt($('.content').height()) - parseInt($('.content .wrapper').css('padding-bottom')),
        sbPlace = $('.sb-place'),
        sbPlaceH = parseInt(sbPlace.height()) + parseInt(sbPlace.css('padding-top')) + parseInt(sbPlace.css('padding-bottom')) + parseInt(sbPlace.css('top'));
    if (sbPlaceH > sloganH + contentH) {
        $('.content').height(sbPlaceH - sloganH + parseInt($('.content .wrapper').css('padding-bottom')));
    }
    
    // Rotating Headlines
    if (rh.length > 1) {
        setInterval('rhTimer()', 6000);
    }
    
    // Problems
    /*$('.hc-right a').click(function(e) {
        e.preventDefault();
        window.open('problems.aspx', 'POINTMANagement',
            'width=674, height=531, toolbar=no, location=no, directories=no, menubar=no, resizable=no, scrollbars=yes, status=no, fullscreen=no');
    });*/
    var pa = $('.problems a'),
        pas = $('.solutions .solution-item');
    pa.each(function(index, item) {
        $(item).click(function(e) {
            e.preventDefault();
            if (!$(this).hasClass('active')) {
                $('.solutions .solution-item.active').removeClass('active');
                $('.problems .active').removeClass('active');
                Cufon.replace('.problems li a', {
                    fontFamily: 'helvhv',
                    hover: true
                });
                $(pas[index]).addClass('active');
                $(pa[index]).parent().addClass('active');
            }
        });
    });
    
    // Login Link
    $('.login-link').click(function(e) {
        e.preventDefault();
        var form = $('#login-form');
        form.slideToggle(200);
        if ($('.header-phone').css('display') == 'none') {
            $('.header-phone').css('display', 'inline-block');
            $('.lf-note').css('display', 'none');
        }
        else {
            $('.header-phone').css('display', 'none');
            $('.lf-note').css('display', 'inline-block');
        }
    });
});



