function sendForm(form, field, value) {
	document.forms[form][field].value = value;
	document.forms[form].submit();
}

function refreshUserStatusBar() {
	new Ajax.Updater('user-status', '/?portalId=myprofile&action=myprofile&mode=showUserStatus', {
		method: "post",
		parameters: {
			template: template
		}
	});
}

function scrollElementToViewport(id, f, offset) {
	var vp = $(id).viewportOffset();
	var pos = $(id).cumulativeOffset();
	var viewportHeight = document.viewport.getHeight();
	var dim = $(id).getDimensions();
	
	if (dim.height > viewportHeight) new Effect.ScrollTo(id, {duration: 0.4});
	else if (vp.top + f * dim.height > viewportHeight) new Effect.ScrollTo(id, {offset: -(pos.top - (pos.top - viewportHeight) - f * dim.height) + offset, duration: 0.4});
}

function initTextAreasMaxLength() {
	var textAreas = document.getElementsByTagName("textarea");
	
	for (var i=0; i<textAreas.length; i++) {
		if (textAreas[i].getAttribute('maxlength')) {
			Event.observe(textAreas[i], 'keydown', checkMaxLength);
			Event.observe(textAreas[i], 'keyup', checkMaxLength);
			textAreas[i].checkMaxLength = checkMaxLength;
			textAreas[i].checkMaxLength();
		}
	}
}

function checkMaxLength() {
	var maxLength = parseInt(this.getAttribute('maxlength'));
	if(this.value.length > maxLength) this.value = this.value.substring(0, maxLength);
	
	var maxLengthInfo = this.getAttribute('maxlengthinfo');
	if (maxLengthInfo) $(maxLengthInfo).innerHTML = this.value.length + " / " + maxLength;
}

Event.observe(window, 'load', initTextAreasMaxLength);

function getMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function showContentTeaser(id) {
	$(id).removeClassName('content-teaser');
}

function number_format(number, decimals, dec_point, thousands_sep) {
	var exponent = "";
	var numberstr = number.toString ();
	var eindex = numberstr.indexOf ("e");
	
	if (eindex > -1) {
		exponent = numberstr.substring (eindex);
		number = parseFloat (numberstr.substring (0, eindex));
	}
	
	if (decimals != null) {
		var temp = Math.pow (10, decimals);
		number = Math.round (number * temp) / temp;
	}
	
	var sign = number < 0 ? "-" : "";
	var integer = (number > 0 ? Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
	
	var fractional = number.toString ().substring (integer.length + sign.length);
	dec_point = dec_point != null ? dec_point : ".";
	fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";
	
	if (decimals != null && decimals > 0) {
		for (i = fractional.length - 1, z = decimals; i < z; ++i)
			fractional += "0";
	}
	
	thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
	if (thousands_sep != null && thousands_sep != "") {
		for (i = integer.length - 3; i > 0; i -= 3)
			integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	}
	
	return sign + integer + fractional + exponent;
}