$ = function(id) {
	return document.getElementById(id);
}
function targetBlank() {
	//links with class="external"
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		if (links[i].className.indexOf("external") > -1) {
			links[i].onclick = function() {
				window.open(this, Math.random());
				return false;
			}
		}
	}

	//links at portfolio page
	if ($("portfolioCompany")) {
		var portfolioLinks = $("portfolioCompany").getElementsByTagName("a");
		for (var i = 0; i < portfolioLinks.length; i++) {
			portfolioLinks[i].onclick = function() {
				window.open(this, Math.random());
				return false;
			}
		}
	}
}

menuHover = function() {
	var menuItems = $("menuMain").getElementsByTagName("li");
	for (var i =0; i < menuItems.length; i++) {
		if (menuItems[i].getElementsByTagName("div")[0]) {
			menuItems[i].onmouseover = function() {
				this.className = "hover";
			}
			menuItems[i].onmouseout = function() {
				this.className = "";
			}
		}
	}
}

function order() {
	$("message").value += "\n\nТелефон\t" + $("phone").value;
	$("message").value += "\n\nУслуга\t" + $("service").value;
	return true;
}

function orderInit() {
	if ($("txpCommentInputForm")) {
		$("txpCommentInputForm").onsubmit = function() {
			order();
		}
	}
}

window.onload = function() {
	menuHover();
	orderInit();
	targetBlank();
}

