var mailReg = /^\w+[\w-\.]*@\w+[\w-\.]*\.[a-z]+$/;
var mailMinLength = 6;
var mailMaxLength = 255;

Event.observe( window, 'load', showButtonBlock, false);
/*
window.onload = function() {	//stuHover();
	if (typeof pageOnload == 'function') {		pageOnload();
	}
}
*/
function stuHover() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++) {
		if (typeof document.styleSheets[i].rules != 'undefined') {
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++) {
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1) {
				newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule( newSelector , cssRule.style.cssText);
			}
		}
		}
    }
	var getElm = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}

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;
}


function showFieldError( field, str) {
	if (document.getElementById( field + '_error'))	document.getElementById( field + '_error').innerHTML = '!&nbsp;' + str;
}

function hideFieldError( field) {
	if (document.getElementById( field + '_error'))		document.getElementById( field + '_error').innerHTML = '';
}

function setErrorColor( field) {
	if (document.getElementById( field))			document.getElementById( field).style.backgroundColor = 'FFEEFF';
}

function setDefaultColor( field) {
	if (document.getElementById( field))			document.getElementById( field).style.backgroundColor = 'FFFFFF';
}

function setStep( step) {
	document.forder.action = document.forder.action + step + '/';
 	document.forder.submit();
}

function resetError( field) {
	hideFieldError( field);
	setDefaultColor( field);
	hideFieldError( 'step');
}

function showButtonBlock() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var blockList = document.getElementsByTagName('div');
		for (i = 0; i < blockList.length; i++) {
			if (blockList[i].name == 'button_block') {
				blockList[i].style.display = 'block';
			}
		}

	} else {
		var blockList = document.getElementsByName('button_block');
		if (blockList.length > 0) {
		 	for (i = 0; i < blockList.length; i++) {
				blockList[i].style.display = 'block';
			}
		}
	}
}