function myprintln(s) { 
	document.writeln(s); 
}  

function register() {
	if (document.registerForm.username.value != '' && document.registerForm.password.value != '' && document.registerForm.confirm_password.value != '' && document.registerForm.email.value != '' && document.registerForm.confirm_captcha.value != '') {
		if (document.registerForm.password.value != document.registerForm.confirm_password.value) {
			message_appear('The password confirmation does not match the password.', true);
			return false;
		}		
		document.registerForm.submit();
	} else {
		message_appear('Please fill all fields of the form.', true);
		return false;
	}
}

function login() {
	if (document.loginForm.username.value != '' && document.loginForm.password.value != '') {	
		document.loginForm.submit();
	} else {
		message_appear('Please fill all fields of the form.', true);
		return false;
	}
}

function continueLogin() {
	document.loginForm.submit();
}

function forgot() {
	if (document.forgotForm.forgotemail.value != '') {	
		document.forgotForm.submit();
	} else {
		message_appear('Please fill all fields of the form.', true);
		return false;
	}
}

function changePassword() {
	if (document.cpForm.password.value != '' && document.cpForm.confirm_password.value != '' && document.cpForm.confirm_captcha.value != '') {
		if (document.cpForm.password.value != document.cpForm.confirm_password.value) {
			message_appear('The password confirmation does not match the password.', true);
			return false;
		}		
		document.cpForm.submit();
	} else {
		message_appear('Please fill all fields of the form.', true);
		return false;
	}
}

function saveDocument() {
	document.theForm.operation.value = 'save';
	document.theForm.submit();
}

var message_opacity = 100;
var message_height = 20;

function message_appear(msg, err) {
	message_height = 20;
	message_opacity = 100;

	var ob = document.getElementById('msgBox');

	ob.innerHTML = msg;
	if (err) {
		ob.className = 'msgBoxError';
	} else {
		ob.className = 'msgBoxMessage';
	}

	ob.style.display = 'block';
	ob.style.height= '20px';
	
	if (ob.filters) {
		try {
			ob.filters.item("DXImageTransform.Microsoft.Alpha").opacity = message_opacity;
		} catch (e) {
			ob.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + message_opacity + ")";
		}
	} else {
		ob.style.opacity = message_opacity / 100;
	}	

	setTimeout('message_disappear(\'msgBox\')', 10000);	
}

function message_disappear() {
	var ob = document.getElementById('msgBox');
	var reduceOpacityBy = 20;
	var reduceHeightBy = 5;
	var rate = 30;	// 15 fps
	
	if (message_opacity > 0) {
		message_opacity -= reduceOpacityBy;
		if (message_opacity < 0) {
			message_opacity = 0;
		}

		if (ob.filters) {
			try {
				ob.filters.item("DXImageTransform.Microsoft.Alpha").opacity = message_opacity;
			} catch (e) {
				ob.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + message_opacity + ")";
			}
		} else {
			ob.style.opacity = message_opacity / 100;
		}
	}

	if (message_height > 0) {
		message_height -= reduceHeightBy;
		if (message_height < 0) {
			message_height = 0;
		}

		ob.style.height = message_height + "px";
	}
	if (message_height > 0 || message_opacity > 0) {
		setTimeout('message_disappear()', rate);
	} else {
		ob.style.display = "none";
	}
}

function saveFormulaire(deletefile) {
	document.theForm.deletefile.value = deletefile;
	document.theForm.operation.value = 'save';
	document.theForm.submit();
}

function sendFormulaire() {
	document.theForm.operation.value = 'send';
	document.theForm.submit();
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		document.getElementById(cntfield).innerHTML = maxlimit - field.value.length + ' de caractere ramase';
	}
}
