function chkData() {
	if (document.registrationForm.login.value == "") {
		alert("Необходимо указать логин!");
		document.registrationForm.login.focus();
		return false;
	}
	if (document.registrationForm.lastName.value == "") {
		alert("Необходимо указать фамилмю!");
		document.registrationForm.lastName.focus();
		return false;
	}
	if (document.registrationForm.firstName.value == "") {
		alert("Необходимо указать имя!");
		document.registrationForm.firstName.focus();
		return false;
	}
	if (document.registrationForm.email.value == "") {
		alert("Необходимо указать email!");
		document.registrationForm.email.focus();
		return false;
	}
	if (!isEmail(document.registrationForm.email.value)) {
		alert("Email некорректный!");
		document.registrationForm.email.focus();
		return false;
	}
	if (document.registrationForm.code.value == "") {
		alert("Необходимо указать кодовое слово!");
		document.registrationForm.code.focus();
		return false;
	}
	return true;
}

function checkGeography(f){
	var num0 = false;
	var thObj = document.addSite;
	for (i=0; i<thObj.geography.length; i++) {
		if (thObj.geography[i].checked) {
			num0 = true;
			break;
		}
	}
	if (num0) {return true;}
	else {
		alert("Укажите географическую привязку!");
		return false;
	}
}

function checkCategory(f){
	var getVar = document.getElementById('category').selectedIndex;
	if (getVar < 0) {
		alert("Укажите рубрику, в которой хотите разместить сайт!");
		return false;
	}
	return true;
}

function setCookie(name, value, expires) {
	document.cookie = name + "=" + escape(value)+"; path=/; "+((expires)?"":"expires=Thursday, 31-Dec-2020 23:59:59 GMT;");
}

function checkTypology(f){
	var num0 = false;
	var thObj = document.addSite;
	for (i=0; i<thObj.typology.length; i++) {
		if (thObj.typology[i].checked) {
			num0 = true;
			break;
		}
	}
	if (num0) {return true;}
	else {
		alert("Укажите метку для сайта!");
		return false;
	}
}

function chkData2() {
	if (document.feedbackForm.name.value == "") {
		alert("Необходимо указать имя!");
		document.feedbackForm.name.focus();
		return false;
	}
	if (document.feedbackForm.topic.value == "") {
		alert("Необходимо указать тему!");
		document.feedbackForm.topic.focus();
		return false;
	}
	if (document.feedbackForm.text.value == "") {
		alert("Необходимо указать текст сообщения!");
		document.feedbackForm.text.focus();
		return false;
	}
	if (document.feedbackForm.email.value == "") {
		alert("Необходимо указать email!");
		document.feedbackForm.email.focus();
		return false;
	}
	if (!isEmail(document.feedbackForm.email.value)) {
		alert("Email некорректный!");
		document.feedbackForm.email.focus();
		return false;
	}
	if (document.feedbackForm.code.value == "") {
		alert("Необходимо указать кодовое слово!");
		document.feedbackForm.code.focus();
		return false;
	}
	return true;
}

function chkData3(form) {
	if (form.title.value == "") {
		alert("Необходимо указать заголовок сообщения!");
		form.title.focus();
		return false;
	}
	if (form.message.value == "") {
		alert("Необходимо написать текст сообщения!");
		form.message.focus();
		return false;
	}
	return true;
}

function isEmail(str)
{
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)")
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$")
	return (!r1.test(str) && r2.test(str))
}
function chkBookmarkData() {

	if (document.addBookmark.name.value == "") {
		alert("Необходимо указать имя закладки!");
		document.addBookmark.name.focus();
		return false;
	}
	if (document.addBookmark.url.value == "") {
		alert("Необходимо указать линк закладки!");
		document.addBookmark.url.focus();
		return false;
	}
	return true;
}
function chkReply() {
	if (document.addSite.site_url) {
		if (document.addSite.site_url.value == "") {
			alert("Необходимо указать адрес ресурса!");
			document.addSite.site_url.focus();
			return false;
		}
	}
	if (document.addSite.site_name) {
		if (document.addSite.site_name.value == "") {
			alert("Необходимо указать название ресурса!");
			document.addSite.site_name.focus();
			return false;
		}
	}
	if (document.addSite.site_description) {
		if (document.addSite.site_description.value == "") {
			alert("Напишите описание ресурса!");
			document.addSite.site_description.focus();
			return false;
		}
	}
	if (document.addSite.category) {
		if (document.addSite.category.value == "") {
			alert("Укажите категорию!");
			document.addSite.category.focus();
			return false;
		}
	}
	if (document.addSite.geography) {
		if (document.addSite.geography.value == "") {
			alert("Укажите регион!");
			document.addSite.geography.focus();
			return false;
		}
	}
	if (document.addSite.typology) {
		if (document.addSite.typology.value == "") {
			alert("Укажите тип ресурса!");
			document.addSite.typology.focus();
			return false;
		}
	}
	return true;
}


function cancel(id) {
	var element = document.getElementById(id);
	element.innerHTML = values[id];
}
function getElemText(node) {
	return node.text || node.textContent || (function(node) {
		var _result = "";
		if (node == null) {
			return _result;
		}
		var childrens = node.childNodes;
		var i = 0;
		while (i < childrens.length) {
			var child = childrens.item(i);
			switch (child.nodeType) {
				case 1: // ELEMENT_NODE
				case 5: // ENTITY_REFERENCE_NODE
					_result += arguments.callee(child);
					break;
				case 3: // TEXT_NODE
				case 2: // ATTRIBUTE_NODE
				case 4: // CDATA_SECTION_NODE
					_result += child.nodeValue;
					break;
				case 6: // ENTITY_NODE
				case 7: // PROCESSING_INSTRUCTION_NODE
				case 8: // COMMENT_NODE
				case 9: // DOCUMENT_NODE
				case 10: // DOCUMENT_TYPE_NODE
				case 11: // DOCUMENT_FRAGMENT_NODE
				case 12: // NOTATION_NODE
				// skip
					break;
			}
			i++;
		}
		return _result;
	}(node));
}
function makeBookmarkEditable(id) {
	var element = document.getElementById(id);
	values[id] = element.innerHTML;
	if (element != null) {
		var name = getElemText(document.getElementById("name" + id));
		var url = getElemText(document.getElementById("url" + id));
		var anchor = document.getElementById("picture" + id);
		var image = document.getElementById("image" + id);
		var select = document.getElementsByName("bookmarkCategoryId")[0];
		var description = getElemText(document.getElementById("description" + id));
		element.innerHTML = '<form accept-charset="UTF-8" method="post" action="editBookmark.do"><div class="item"><input name="name" value="' + name + '" class="edit_name" type="text"></div>\n' +
							'<div class="picture">\n' +
							'<img alt="' + name + '" src="' + image.getAttribute('src') + '" class="photo" height="155" width="206">\n' +
							'<div class="favorite"><div class="center"><input name="url" value="' + anchor + '" class="edit_url" type="text"></div></div>\n' +
							'</div>\n' +
							'<input value="' + id + '" name="id" type="hidden">' +
							'<div class="description"><p>\n' +
							'<textarea cols="36" name="description" rows="9" class="edit_desc">' + description + '</textarea>\n' +
							'</p></div>\n' +
							'<div class="item vcard">\n' +
							'<div class="adr">\n' +
							'<select name="bookmarkCategoryId" class="fav1">\n' +
							select.innerHTML +
							'</select>\n' +
							'&nbsp;&nbsp;&nbsp;<input value="Сохранить"  type="submit">\n' +

							'&nbsp;&nbsp;&nbsp;<a class="tools" href="javascript:cancel(' + id + ')">Отменить</a>\n' +
							'&nbsp;&nbsp;&nbsp;<a class="tools" href="removeBookmark.do?id=' + id + '">Удалить</a>\n' +
							'</div>\n' +
							'</div></form>';
	} else {
		alert('Element is null');
	}
}