﻿/**
 * @author Optima Technologies
 */
function reset(){
	document.getElementById('email').value='';
	document.getElementById('name').value='';
	document.getElementById('comment').value='';
	
}
function trim (str) {
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}
function validate(){
	
	var reMail = /^[A-Za-z0-9_.-]+@[A-Za-z0-9_.-]+\.[A-Za-z]{2,3}$/;
	
	if ((trim(document.mailF.email.value) == '') || !reMail.exec(document.mailF.email.value)){
		alert("Моля, въведете валиден E-mail!");
		document.mailF.email.focus();
		return false;
	} else if (trim(document.mailF.name.value) == '') {
		document.mailF.name.focus();
		alert("Моля, въведете вашето име!");
		return false;
	} else if (trim(document.mailF.comment.value) == '') {
		document.mailF.comment.focus();
		alert("Моля, въведете съобщение!");
		return false;
	}
		
	document.mailF.submit();
}
