function scrollTo(sElement) { $.scrollTo(sElement, 800); }

function getLoading() {	return $('loading').innerHTML; }
function getSubmitLoading() {	return $('submitLoading').innerHTML; }

function showElementInfos(elementId, sMessage, bAllowBlank) { 
	var oElement = $(elementId); 
	if (!oElement) { alert('element ' + elementId + ' undefined'); return; } 
	
    bAllowBlank = (bAllowBlank == 'false') ? false : true;
    
    if (sMessage != '') { 
    	$('#' + elementId).focus(function() {
    		$('#fieldInfosDialog').html("<div class=\"content\"><div class=\"message\">" + sMessage + "</div></div>");
    		var positionElement = $(this).offset();
    		var width = $(this).width() + 20;
    		$('#fieldInfosDialog').css('top', (positionElement.top - 6) + 'px');
    		$('#fieldInfosDialog').css('left', positionElement.left + width + 'px');
    		$('#fieldInfosDialog').fadeIn();
    	});
    }

    if (!bAllowBlank) { 
    	$('#' + elementId).blur(function() {
        	if ($('#' + elementId).val() == '') { 
        		$('#' + elementId).addClass('fieldError');
        	} else { 
        		$('#' + elementId).removeClass('fieldError'); 
        	}
        	$('#fieldInfosDialog').html('');
        	$('#fieldInfosDialog').hide();
    	});
    } else {
    	$('#' + elementId).blur(function() {
        	$('#fieldInfosDialog').html('');
        	$('#fieldInfosDialog').hide();
    	});    	
    }
}

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2 + $(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2 + $(window).scrollLeft() + "px");
    return this;
}


function initPopup(iWidth) {
	$('#page').animate({opacity:0.3});
	$('#preHeader').animate({opacity:0.3});
	
	var iBoxWidth = iWidth;
    var iTop = (($(window).height() - $('#popup').height()) / 2) + $(window).scrollTop() - 40;
	var iLeft = (($(window).width() - iWidth) / 2) + $(window).scrollLeft();
	
	$('#popup').css('width', iBoxWidth + 'px');
	$('#popup').css('top', iTop + 'px');
	$('#popup').css('left', iLeft + 'px');
	$('#popup').fadeIn();
}

function closePopup() { 
	$('#popup').slideUp('fast', function() { 
		$('#popupContent').html('');
		$('#page').animate({opacity:1.0});
		$('#preHeader').animate({opacity:1.0});
	}); 
}

function hideSubmitButton(sElementName) { 
	if ($('#' + sElementName)) { $(sElementName).html(getSubmitLoading()); } 
}

function acceptOnlyNumbers(event) {
	if (!event && window.event) {
		event = window.event;
	}
	// IE
	if(event.keyCode < 48 || event.keyCode > 57) {
		event.returnValue = false;
		event.cancelBubble = true;
	}

	if(event.which < 48 || event.which > 57) {
		event.preventDefault();
		event.stopPropagation();
	}
}
