if (!window.facesMessages) window.facesMessages={};
var vaClass= [
	/* dynamically set vertical align to middle for these classes */
	".logo_hdr dt img",
	".logo_hdr dd"
];

function vAlignCenter(selectors,height) {
    jQuery(selectors).each(function(i) {
        jQuery(this).css ({
            position:"relative",
            top:(height-jQuery(this).height())/2
        });
    });
}

function clearErrorClass() {
	jQuery(".error").removeClass("error");
}

/* perform onload tasks */
jQuery(document).ready(function() {
    vAlignCenter(vaClass.join(","),60);

    //set maxlength of textareas
    jQuery("textarea").keyup(function(event){
        textAreaMax(this);
    });
    jQuery("textarea").each(function(){
        textAreaMax(this);
    })

});

function textAreaMax(theTextarea) {
    var max = theTextarea.getAttribute("maxlength");
    if(max != null && theTextarea.value.length > max) {
        theTextarea.value = theTextarea.value.substr(0, max);
    }
    jQuery("#charsRemaining").html("You have " + (max - theTextarea.value.length) +  " characters remaining.");
}

jQuery.trim = function(value) {
    if(value) {
        value = value.replace(/^\s+/, '');
        for (var i = value.length - 1; i >= 0; i--) {
            if (/\S/.test(value.charAt(i))) {
                value = value.substring(0, i + 1);
                break;
            }
        }
    }
	return value;
}

function getDomain() {
    var domain = window.location.hostname;
    if(domain == "localhost") return null;
    if(domain.indexOf('www.') != -1) {
        domain = domain.replace(/^www\./,'');
    }
    return domain;
}
