function trim(string)
{
	return string.replace(/(^\s+)|(\s+$)/g, "");
}

function empty(elem)
{
	if (trim(document.getElementById(elem).value) == '') {		
		return true;
	} else {
		return false;
	}
}

function foc(elem)
{
	document.getElementById(elem).focus();
}

function setText(elem, text)
{
	document.getElementById(elem).innerHTML = text;
}

function setTextAr(ar, text)
{
	for (i=0; i<ar.length; i++) {
		document.getElementById(ar[i]).innerHTML = text;
	}
}

function inpVal(elem)
{
	return document.getElementById(elem).value;
}

function checkOrderForm()
{
	setTextAr(['topicerror', 'emailerror', 'fioerror', 'phoneerror', 'messageerror'], '');
	
	if (empty('topic')) {
		setText('topicerror', 'Введите тему');
		foc('topic');
		return false;
	}
	
	if (empty('email')) {
		setText('emailerror', 'Введите Ваш e-mail');
		foc('email');
		return false;
	}	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(inpVal('email'))){}else{
		setText('emailerror', 'Неверный e-mail');
		foc('email');		
		return false; 
	} 
	
	if (empty('fio')) {
		setText('fioerror', 'Введите Ваше имя');
		foc('fio');
		return false;
	}
	if (empty('phone')) {
		setText('phoneerror', 'Введите Ваш телефон');
		foc('phone');
		return false;
	}
	if (empty('address')) {
		setText('phoneerror', 'Введите Ваш адрес');
		foc('address');
		return false;
	}
	if (empty('message')) {
		setText('messageerror', 'Введите сообщение');
		foc('message');
		return false;
	}
	return true;
}

function checkSearchFaqForm()
{
	
	
	setTextAr(['keyworderror'], '');
	
	if (empty('keyword')) {
		setText('keyworderror', 'Введите ключевое слово');
		foc('keyword');
		return false;
	}	

	return true;
}
		
							 
