$(function(){
    // validate the login form when it is submitted
    if ($("#loginform").length > 0) {
        $("#loginform").validate();
    }
    
    // validate the forgot your password form when it is submitted
    if ($("#forgotform").length > 0) {
        $("#forgotform").validate();
    }
    
    // validate the signup form when it is submitted
    if ($("#signupform").length > 0) {
        $("#signupform").validate();
    }
    
    // only add this rule if an email_confirm field exists on the page
    if ($("#emailconfirm").length > 0) {
        $("#emailconfirm").rules("add", {
            equalTo: "#email",
            messages: { equalTo: "Email fields must match" }
        });
    }

// validate the update profile form when it is submitted
    if ($("#updateform").length > 0) {
        $("#updateform").validate();
    }
    
    // focus on the first name field (if it exists)
    if ($("#firstname").length > 0) {
        $("#firstname").focus();
    
    } else if ($("#email").length > 0) {
        // otherwise focus on the email field (if it exists)
        $("#email").focus();
    }
    
    // open the forgot your password box
    if ($("#forgot-pw-link").length > 0) {
        $("#forgot-pw-link").colorbox({width:"440px", inline:true, href:"#forgot-pw-lightbox"});
    }

    if ($("#unsubscribe").length > 0) {
        $("#unsubscribe").colorbox({width:"440px", inline:true, href:"#unsubscribe-lightbox"});
    }

    if ($("#changepw").length > 0) {
        $("#changepw").colorbox({width:"440px", inline:true, href:"#change-pw-lightbox"});
    }

    if ($("#btnChangepw").length > 0) {
        $("#btnChangepw").colorbox({width:"440px", inline:true, href:"#change-pw-lightbox"});
    }

    // validate the change password form when it is submitted
    if ($("#changepwf").length > 0) {
        $("#changepwf").validate();
    }
    // only add this rule if an email_confirm field exists on the page
    if ($("#passwordconfirm").length > 0) {
        $("#passwordconfirm").rules("add", {
            equalTo: "#password",
            messages: { equalTo: "Password fields must match" }
        });
    }

$(".control a").click( function(){
        // if we're already open
        if( $(this).attr('class') == "open" ) {
            $(this).parent().parent().next(".content").hide();
            $(this).removeClass("open");
            $(this).blur();
        } else {
			// uncomment the next two lines to have system behave as true accordian
			// note: you should start the form with all accordians close or only one open for best results
			$('.content').hide();
			$('.control a').removeClass("open");
            // otherwise we're closed
            $(this).parent().parent().next(".content").show();
            $(this).addClass("open");
            $(this).blur();
        }
    });
});


function show_saved_text( divId ) {
	$('#' + divId).fadeIn().delay(2000).fadeOut('slow');
}

