logoIteration = 0;
function logo(object) {
	var logo = new Array();
	logo[0] = "/project/public/design/images/logos/logo0.png";
	logo[1] = "/project/public/design/images/logos/logo1.png";
	logo[2] = "/project/public/design/images/logos/logo2.png";
	logo[3] = "/project/public/design/images/logos/logo3.png";
	logo[4] = "/project/public/design/images/logos/logo4.png";
	logo[5] = "/project/public/design/images/logos/logo5.png";
	logo[6] = "/project/public/design/images/logos/logo6.png";
	logo[7] = "/project/public/design/images/logos/logo7.png";
	logo[8] = "/project/public/design/images/logos/logo8.png";
	logo[9] = "/project/public/design/images/logos/logo9.png";

	if (logoIteration >= logo.length) {
		logoIteration	=	0;
	}

	object.src = logo[logoIteration];
	logoIteration++;
}


function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}


function turnMenu() {
	if (document.getElementById("sitemenu").style.display == "") {
		tStyle	=	"none";
		tMargin	=	"0% 0% 0% 0%";
		tText	=	"<<";
		setCookie("turnMenu", "1", "Mon, 01-Jan-2020 00:00:00 GMT", "/");
	}
	else {
		tStyle	=	"";
		tMargin	=	"0% 26% 0% 0%";
		tText	=	">>";
		setCookie("turnMenu", "", "Mon, 01-Jan-2020 00:00:00 GMT", "/");
	}

	document.getElementById("container").style.margin	=	tMargin;
	document.getElementById("sitemenu").style.display	=	tStyle;
	document.getElementById("turnText").innerHTML		=	tText;
}

function getTurnMenu() {
	turnMenuSet = getCookie("turnMenu");
	if (turnMenuSet == "1") {
		tStyle	=	"none";
		tMargin	=	"0% 0% 0% 0%";
		tText	=	"<<";
	}
	else {
		tStyle	=	"";
		tMargin	=	"0% 26% 0% 0%";
		tText	=	">>";
	}

	document.getElementById("container").style.margin	=	tMargin;
	document.getElementById("sitemenu").style.display	=	tStyle;
	document.getElementById("turnText").innerHTML		=	tText;
}


function addCommentPhoto() {
	for (i = 1; i <= 5; i++) {
		if (document.getElementById("trPhoto"+i).style.display == "none") {
			document.getElementById("trPhoto"+i).style.display = "";
			break;
		}
	}
}

function showSearchForm() {
	if (document.getElementById("formSearcher").style.display == "none") {
		document.getElementById("formSearcher").style.display = "block";
	}
	else {		document.getElementById("formSearcher").style.display = "none";
	}
}

function editAnons() {
	if (document.getElementById("anonsContent").style.display == "none") {
    	document.getElementById("anonsContent").style.display	=	"block";
    	document.getElementById("anonsText").style.display		=	"none";
	}
	else {
    	document.getElementById("anonsContent").style.display	=	"none";
    	document.getElementById("anonsText").style.display		=	"block";
	}
}

function deleteCommentPhoto(id) {
	document.getElementById("trPhoto"+id).style.display = "none";
	document.getElementById("photo"+id).value = "";
}


function addNote() {
	if (document.getElementById("savenoteform").style.display == "none") {
		document.getElementById("infonotesucces").style.display	=	'none';
		document.getElementById("infonotefail").style.display	=	'none';

		document.getElementById("savenoteform").style.display = "block";
		document.getElementById("notetext").style.display = "none";
	}
	else {
		document.getElementById("savenoteform").style.display = "none";
		if (document.getElementById("notetext").innerHTML != "") {
			document.getElementById("notetext").style.display	=	"block";
		}
	}
}


function setBold() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("bold", null, "");
}
function setItal() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("italic", null, "");
}
function setUnder() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("underline", null, "");
}
function setStrike() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("strikethrough", null, "");
}

function setCenter() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("justifycenter", null, "");
}
function setLeft() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("justifyleft", null, "");
}
function setRight(frameWin) {
	mainContentWin.focus();
	mainContentWin.document.execCommand("justifyright", null, "");
}

function setUndo() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("undo", null, "");
}
function setRedo() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("redo", null, "");
}

function setLink() {
	var link = prompt("Укажите URL-адрес ссылки:", "http://");
	if (link != "http://" && link != "" && link) {
		mainContentWin.focus();
		mainContentWin.document.execCommand("createlink", null, link);
	}
}

function getTable() {
	if (document.getElementById("divTable").style.display == "block") {
		document.getElementById("divTable").style.display = "none";
	}
	else {
		document.getElementById("divTable").style.display = "block";
	}
}
function getImage() {
	if (document.getElementById("divImage").style.display == "block") {
		document.getElementById("divImage").style.display = "none";
	}
	else {
		document.getElementById("divImage").style.display = "block";
	}
}

function setFormat() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("removeformat", null, "");
}

function setH1() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("formatblock", null, "<h1>");
}
function setH2() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("formatblock", null, "<h2>");
}


function setSup() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("superscript", null, "");
}
function setSub() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("subscript", null, "");
}
function setHorizontLine() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("inserthorizontalrule", null, "");
}
function setList() {
	mainContentWin.focus();
	mainContentWin.document.execCommand("insertorderedlist", null, "");
}



function setTable() {
	var columns	= document.getElementById("tableColumns").value;
	var lines	= document.getElementById("tableLines").value;
	var border	= document.getElementById("tableBorder").value;
	var demo	= document.getElementById("tableDemo").checked;

	var tableText	=	"<table";
	if (border == "1") {
		tableText	+=	" style='border: #000000 1px solid;'";
	}
	tableText	+=	">";

	for (i = 1; i <= columns; i++) {
		tableText	+=	"<tr>";
		for (k = 1; k <= lines; k++) {
			tableText	+=	"<td";
			if (border == "1") {
				tableText	+=	" style='border: #000000 1px solid;'";
			}
			tableText	+=	">";

			if (demo == true) {
				tableText	+=	i+""+k;
			}

			tableText	+=	"</td>";
		}
		tableText	+=	"</tr>";
	}

	tableText	+=	"</table>";

	mainContentWin.focus();
	if (window.navigator.userAgent.indexOf("MSIE")!=-1) {
		var rng = mainContentWin.document.selection.createRange();
		rng.pasteHTML("" + tableText + "");
	}
	else {
 		mainContentWin.document.execCommand("inserthtml", false, tableText);
	}
	document.getElementById("divTable").style.display = "none";
}




function setImage(imgLink, align) {
	var talign = "";

	if (align == "1") {
		talign = ' style="float: left; margin-right: 20px; margin-bottom: 20px;"';
	}
	else if (align == "2") {
		talign = ' style="float: right; margin-left: 20px; margin-bottom: 20px;"';
	}
	else if (align == "3") {
		talign = ' style="display: block; margin: 0 auto;"';
	}

	imgText	=	"<img src='"+imgLink+"' border='0' "+talign+" />";

	mainContentWin.focus();
	if (window.navigator.userAgent.indexOf("MSIE")!=-1) {
		var rng = mainContentWin.document.selection.createRange();
		rng.pasteHTML("" + imgText + "");
	}
	else {
 		mainContentWin.document.execCommand("inserthtml", false, imgText);
	}
}



function resizeForm(element, type, size) {
	if (type == "1") {
		document.getElementById(element).style.height	=	(document.getElementById(element).offsetHeight+size)+"px";
	}
	else {
		document.getElementById(element).style.height	=	(document.getElementById(element).offsetHeight-size)+"px";
	}
}


function selectPharses(hash) {
	document.getElementById("searchPharses"+hash).style.display = "none";

	var content = "";

	if (/*@cc_on 1 | @*/ 0) {
		content = document.selection.createRange().text;
	}
	else {
		content	=	window.getSelection();
	}

	if (content != "") {
		document.getElementById("searchPharses"+hash).style.display = "";

		content	=	'"'+content+'"';
		content	=	encodeURIComponent(content);

		document.getElementById("yandexSearch"+hash).href	=	"http://yandex.ru/yandsearch?text="+content;
		document.getElementById("googleSearch"+hash).href	=	"http://www.google.com/search?hl=ru&q="+content;
		document.getElementById("yahooSearch"+hash).href		=	"http://ru.search.yahoo.com/bin/query?ei=UTF-8&p="+content;
	}
}





function checkedPharses(hash) {
	document.getElementById("searcher"+hash).style.display	=	"none";

	var pharse = "";
	var calculate = 0;

	if (document.getElementById("checked1"+hash).checked == true) {
		pharse	=	'"' + document.getElementById("checked1"+hash).value + '"';
		calculate++;
	}

	if (document.getElementById("checked2"+hash).checked == true) {
		if (calculate == 0) {
			pharse	=	'"' + document.getElementById("checked2"+hash).value + '"';
		}
		else {
			pharse	=	pharse + ' || "' + document.getElementById("checked2"+hash).value + '"';
		}
		calculate++;
	}

	if (document.getElementById("checked3"+hash).checked == true) {
		if (calculate == 0) {
			pharse	=	'"' + document.getElementById("checked3"+hash).value + '"';
		}
		else {
			pharse	=	pharse + ' || "' + document.getElementById("checked3"+hash).value + '"';
		}
		calculate++;
	}

	if (calculate != 0) {
		document.getElementById("searcher"+hash).style.display	=	"";

		pharse	=	encodeURIComponent(pharse);

		document.getElementById("yandexSearch"+hash).href	=	"http://yandex.ru/yandsearch?text="+pharse;
		document.getElementById("googleSearch"+hash).href	=	"http://www.google.com/search?hl=ru&q="+pharse;
		document.getElementById("yahooSearch"+hash).href	=	"http://ru.search.yahoo.com/bin/query?ei=UTF-8&p="+pharse;
	}
}


function showHider(object) {
	if (document.getElementById(object).style.display == "none") {
		document.getElementById(object).style.display = "";
	}
	else {
		document.getElementById(object).style.display = "none";
	}
}


function ms_open() {
	document.getElementById("mailus_form").style.display = "block";
}

function ms_close() {
	document.getElementById("mailus_form").style.display = "none";
}
