var mailReg = /^\w+[\w-\.]*@\w+[\w-\.]*\.[a-z]+$/;
var mailMinLength = 6;
var mailMaxLength = 255;

window.onload = function() {
	expandItem( expandedMenuItem);
	if (typeof pageOnload == 'function') {		pageOnload();
	}
}

function getCurrentMS() {
	cDate = new Date();
	return cDate.valueOf();
}

function doExec( itemId) {	if (itemId > 0) {
		if (itemId != expandedMenuItem) {			collapseItem( expandedMenuItem);
			expandItem( itemId);
			expandedMenuItem = itemId;
		} else {			if (ifCollapsed( itemId)) 	expandItem( itemId);
			else						collapseItem( itemId);
		}
	}
}

function ifCollapsed( itemId) {	return (document.getElementById( itemId).style.display == 'none') ? true : false;
}

function collapseItem( itemId) {	if (itemId > 0) {
		document.getElementById( itemId).style.display = 'none';
	}
}

function expandItem( itemId) {	if (itemId > 0) {
		document.getElementById( itemId).style.display = 'block';
	}
}

if ("undefined" == typeof String.prototype.trim) {
    String.prototype.trim = function() {
    	return this.replace(/^\s+/, "").replace(/\s+$/, "");
    }
}

function showMessage( msg) {	if (document.getElementById( 'error')) {		document.getElementById( 'error').innerHTML = msg;
		document.getElementById( 'error').style.color = 'red';
	}
}

function validateEmail( email) {	email.trim();	if (email.length < mailMinLength || email.length > mailMaxLength || !email.match( mailReg)) {		return false;
	} else {		return true;
	}
}

function ifEmpty( field) {	field.trim();
	return (field.length == 0) ? true : false;
}
