var $browseCards = jQuery.noConflict();

// This is the height diff value that will be incrised to the card's register popup when to the new popup height
var heightDiff = 20;

/**
 * This function will check if there is no errors inside the popup form, and in case of true, hides the quick register popup.
 */
function checkIfCanHideQuickRegisterPopup() {
	var errorLabelsLength = 0;
	
	$browseCards('#registerCardWindow .red span .rich-message-label').each(function(i) {
		errorLabelsLength += $browseCards(this).html().length;
	});

	updateCardRegisterPopupHeightDinamicallyErrors();
	
	if(undefined == errorLabelsLength || errorLabelsLength == 0) {
		reloadPageAfterCardRegisterWithSuccess();
		Richfaces.hideModalPanel('quickRegisterPanel');
		
		return true;
	}

	return false;
}

/**
 * This funcion will update the card register popup's height dinamically when the user wants to add a new card.
 * @return
 */
function updateCardRegisterPopupHeightDinamically() {
	var newHeight = $browseCards('#quickRegisterPanelContainer .modalContent .colRight').height();
	
	$browseCards('#quickRegisterPanelContainer .modalContent').height(newHeight + heightDiff);
}
 
function updateCardRegisterPopupHeightDinamicallyErrors() {
	var actualHeight = $browseCards('#quickRegisterPanelContainer .modalContent').height();
	var newHeight = $browseCards('#quickRegisterPanelContainer .modalContent .colRight').height();

	$browseCards('#quickRegisterPanelContainer .modalContent').height(newHeight);
}
