var imgs = new Object();

function createimage(imgname, imgurl) {
	if ((imgs[imgname] == null)&&(imgname != '')&&(imgurl != '')) {
		imgs[imgname] = new Image();
		imgs[imgname].src = imgurl;
	}
}
if (document.images) {
	createimage("1", "images/tdfon1.gif");
	createimage("2", "images/tdfon2.gif");
	/*
	createimage("c11", "images/menu11.jpg");
	createimage("c12", "images/menu12.jpg");
	createimage("c21", "images/menu21.jpg");
	createimage("c22", "images/menu22.jpg");
	createimage("c31", "images/menu31.jpg");
	createimage("c32", "images/menu32.jpg");
	createimage("c41", "images/menu41.jpg");
	createimage("c42", "images/menu42.jpg");
	createimage("c51", "images/menu51.jpg");
	createimage("c52", "images/menu52.jpg");
	*/
	createimage("email1", "images/email.gif");
	createimage("email2", "images/email-on.gif");
	createimage("home1", "images/home-off.gif");
	createimage("home2", "images/home-on.gif");
	createimage("sitemap1", "images/sitemap-off.gif");
	createimage("sitemap2", "images/sitemap-on.gif");
	createimage("btnlmenu1", "images/link_off.gif");
	createimage("btnlmenu2", "images/link_on.gif");
}
function setimg(img, imgname, imgurl) {
	createimage(imgname, imgurl);
	img.src = imgs[imgname].src;
}
function printbtn(src, index, clr) {
	src.style.backgroundImage = "url('" + imgs[index].src + "')";
	if (index == 1) {
		//src.all.item(0).style.color = '2C4D94';
		src.all.item(0).style.color = clr;
		if (!src.contains(event.fromElement)) {
			src.style.cursor = 'hand';
		}
	} else {
		src.all.item(0).style.color = 'white';
		if (!src.contains(event.fromElement)) {
			src.style.cursor = 'default';
		}
	}
}
function printbtn1(src, imgname, index) {
	printbtn(src, index);
	setimg(src.all.item(0).all.item(0), imgname);
}
function blur_links() {
	this.blur();
}
onload = function() {
	items = document.getElementsByTagName("a");
	for (i = 0; i < items.length; i++) {
		items[i].onfocus = blur_links;
	}
	items = document.getElementsByTagName("button");
	for (i = 0; i < items.length; i++) {
		items[i].onfocus = blur_links;
	}
}
function rp_obor() {
	var tbody = document.getElementById("tblnewvp").getElementsByTagName("TBODY")[0];
	for (i = 1; i < tbody.rows.length - 1; i++) {
		tbody.rows[i].cells[1].all.item(0).name = "obor" + (i).toString() + "name";
		tbody.rows[i].cells[2].all.item(0).name = "obor" + (i).toString() + "count";
		tbody.rows[i].cells[0].innerHTML = (i).toString() + ".";
	}
	return true;
}
function add_obor() {
	var tbody = document.getElementById("tblnewvp").getElementsByTagName("TBODY")[0];
	
	var row = document.createElement("TR");
	row.className = "ztr1";

	tbody.insertBefore(row, tbody.rows[tbody.rows.length - 1]);
	
	var td = document.createElement("TD");
	td.className = "ztd1";
	td.style.fontFamily = "Courier New";
	td.innerHTML = (tbody.rows.length - 1 - 1).toString() + ".";
	row.appendChild(td);
	
	td = document.createElement("TD");
	td.className = "ztd2";
	td.innerHTML = "<input name='obor' type='text' size='45' value=''>";
	row.appendChild(td);

	td = document.createElement("TD");
	td.className = "ztd2";
	td.innerHTML = "<input name='obor' type='text' size='3' value='1'>";
	row.appendChild(td);
	
	td = document.createElement("TD");
	td.className = "ztd2";
	td.innerHTML = ""
		+ "<button onclick='del_obor(this); return false;' class='fc2' style='width: 100px;'>"
		+ "<img src='./img/delete.png' alt='' border='0' style='vertical-align: middle;'/>"
		+ "Удалить";
	row.appendChild(td);

	rp_obor();
	
	return true;
}
function del_obor(a) {
	var tbody = document.getElementById("tblnewvp").getElementsByTagName("TBODY")[0];
	if (tbody.rows.length <= 3) {
		return true;
	}
	
	var p = a.parentNode.parentNode.parentNode;
	p.removeChild(a.parentNode.parentNode);
	
	rp_obor();
	
	return true;
}
