//Инициализация элементов страницы
function _SetupPage() {
	//document.getElementsByTagName("Button1");
	var pref1 = "td_hM_";
	var pref2 = "a_hM_";
	var pref3 = "tr_hM_";
	var pref4 = "td1_hM_";
	var pref5 = "td2_hM_";
	var pref6 = "td3_hM_";
	var pref7 = "td4_hM_";
	var pref8 = "td_vM_";
	var pref9 = "a_vM_";
	var pref13 = "Login_";
	var pref14 = "Password_";
	var pref15 = "EventPost_";
	var pref16 = "chkAuto_";
	var pref18 = "txtSearch_";
	
	var td_doc = document.getElementsByTagName("td");
	for (i = 0; i < (td_doc.length); i += 1) {
		var el = td_doc[i];
		if (el.id != null && el.id != "") {
			if (left(el.id, pref1.length) == pref1) {
				var index = el.id.substring(pref1.length);
				var popup = el.getAttribute("popup");
				var current = el.getAttribute("current") == "true" ? ", true" : "";
				el.onselectstart = new Function("return false");
				el.onmouseover = new Function("hMExp(\"" + index + "\", " + popup + ")");
				el.onmouseout = new Function("hMClose(\"" + index + "\"" + current + ")");
			} else if (left(el.id, pref4.length) == pref4 || left(el.id, pref5.length) == pref5 || left(el.id, pref6.length) == pref6) {
				el.className = "hMPC";
			} else if (left(el.id, pref7.length) == pref7) {
				el.style.verticalAlign = "top";
				el.className = "hMPC";
			} else if (left(el.id, pref8.length) == pref8) {
				var index = el.id.substring(pref8.length);
				var popup = el.getAttribute("popup");
				var click = el.getAttribute("click");
				el.onmouseover = new Function("vMExp(\"" + index + "\", " + popup + ")");
				el.onmouseout = new Function("vMClose(\"" + index + "\", " + popup + ")");
				el.onselectstart = new Function("return false");
				el.onclick = new Function(click + ";EvCancel();");
			}
		}
	}
	
	var tr_doc = document.getElementsByTagName("tr");
	for (i = 0; i < (tr_doc.length); i += 1) {
		var el = tr_doc[i];
		if (el.id != null && el.id != "") {
			if (left(el.id, pref3.length) == pref3) {
				var index = el.id.substring(pref3.length);
				var popup = el.getAttribute("popup");
				var click = el.getAttribute("click");
				el.onmouseover = new Function("hMIO(\"" + index + "\", " + popup + ")");
				el.onmouseout = new Function("hMIC(\"" + index + "\", " + popup + ")");
				el.onclick = new Function(click + ";EvCancel();");
			}
		}
	}
	
	var input_doc = document.getElementsByTagName("input");
	for (i = 0; i < (input_doc.length); i += 1) {
		var el = input_doc[i];
		if (el.id != null && el.id != "") {
			if (left(el.id, pref13.length) == pref13) {
				el.maxLength = 20;
				el.name = el.id;
				el.onfocus = new Function("Text_Focus(this, true)");
				el.onblur = new Function("Text_Focus(this, false)");
				el.onkeypress = new Function("Text_ProcessKeyPress(this)");
			} else if (left(el.id, pref14.length) == pref14) {
				el.maxLength = 32;
				el.name = el.id;
				el.onfocus = new Function("Text_Focus(this, true)");
				el.onblur = new Function("Text_Focus(this, false)");
				el.onkeypress = new Function("Text_ProcessKeyPress(this)");
			} else if (left(el.id, pref15.length) == pref15 || left(el.id, pref16.length) == pref16) {
				el.name = el.id;
			} else if (left(el.id, pref18.length) == pref18) {
				el.maxLength = 100;
				el.name = el.id;
				el.onfocus = new Function("Text_Focus(this, true, true)");
				el.onblur = new Function("Text_Focus(this, false, true)");
				el.onkeypress = new Function("Text_ProcessKeyPress(this, true)");
			}
		}
		if (el.type.toLowerCase() == "text" || el.type.toLowerCase() == "password") {
			el.style.backgroundImage = "url(../_images/txt-bg.gif)";
			el.style.border = "#8e8e8e 1px solid";
			el.style.backgroundRepeat = "no-repeat";
		}
	}

	var a_doc = document.getElementsByTagName("a");
	for (i = 0; i < (a_doc.length); i += 1) {
		var el = a_doc[i];
		if (el.getAttribute("antispam") != null) {
			var src = el.getAttribute("antispam").split(el.getAttribute("param")).join("");
			if (el.innerHTML == "mail[@]mail") el.innerHTML = src;
			el.href = "mailto:" + src;
		} else if (el.getAttribute("scripthref") != null) {
			el.href = el.getAttribute("scripthref");
		}
		if (el.id != null && el.id != "") {
			if (left(el.id, pref2.length) == pref2) {
				var index = el.id.substring(pref2.length);
				el.onclick = EvCancel;
			} else if (left(el.id, pref9.length) == pref9) {
				el.onclick = EvCancel;
			}
		}
	}
}

function GetFunctionCode(el, eventName) {
	var fun = "";
	if (el.getAttribute(eventName) != null && el.getAttribute(eventName) != "") {
		var f = el.getAttribute(eventName).toString();
		if (left(f, 20).toLowerCase() == "function anonymous()") {
			var j1 = f.indexOf("{") + 1;
			var j2 = f.lastIndexOf("}") - 1;
			f = trim(f.substring(j1, j2));
		}
		if (fun != "" && right(f, 1) != ";") f = f + ";";
		fun = f + fun;
	}
	return fun;
}


// для DropPanel
function WindowDocumentClick() {
	PanelDropWindowDocumentClick();
}


//открытие страницы через заданный интервал
function OpenPage(page) {
	window.setTimeout("window.location.replace('" + page + "')", 1000)
}

//Show Help Window
function ShowHelpWindow(url) {
	window.open(url, "HelpDoc", "toolbar=no,menubar=no,resizable=yes,scrollbars=yes,location=no,status=yes,width=" + (document.body.clientWidth / 2) + ",height=" + (document.body.clientHeight / 1.1) + ",top=5,left=5");
}


//вычисление позиции и размера элемента
function getElementPosition(elemId) {
	var elem = document.getElementById(elemId);
	var w = elem.offsetWidth;
	var h = elem.offsetHeight;
	var l = 0;
	var t = 0;
	while (elem) {
		l += elem.offsetLeft;
		t += elem.offsetTop;
		elem = elem.offsetParent;
	}
    return {"left":l, "top":t, "width": w, "height":h};
}

//прозрачность
function setOpacity(obj, value) {
	obj.style.opacity = value / 10;
	obj.style.filter = 'alpha(opacity=' + value * 10 + ')';
}

//отмена события
function EvCancel() {
	event.cancelBubble = true;
}


// Строковые функции
function trim(s) {
	return rtrim(ltrim(s));
}
function ltrim(s) {
	return s.replace(/^\s+/, ''); 
}
function rtrim(s) {
	return s.replace(/\s+$/, ''); 
}
function trimws(strString) {
	var intBegin, intEnd;
	var strResult;
	var chrChar;
	var flg;

	intEnd = strString.length - 1;
	intBegin = 0;
	flg = true;
	chrChar = strString.charAt(intBegin);
	while ((intBegin < intEnd) && ((chrChar == "\n") || (chrChar == "\r") || (chrChar == "\t") || (chrChar == " "))) {
		chrChar = strString.charAt(++intBegin);
	}
	chrChar = strString.charAt(intEnd);
	while ((intEnd >= 0) && ((chrChar == "\n") || (chrChar == "\r") || (chrChar == "\t") || (chrChar == " "))) {
		chrChar = strString.charAt(--intEnd);
	}
	if (intBegin <= intEnd) {
		strResult = strString.substr(intBegin, intEnd - intBegin + 1);
	}
	else {
		strResult = "";
	}
	return strResult;
}
function left(strString, length) {
	return strString.substring(0, length)
}
function right(strString, length) {
	return strString.substring(strString.length - length, strString.length)
}
function replace(strString, findString, repltextString) {
	if (strString == null || findString == null || findString == "") return strString;
	var index = strString.toLowerCase().indexOf(findString.toLowerCase());
	var text = strString;
	if (repltextString == null) repltextString = "";
	if (index != -1) {
		text = left(strString, index) + repltextString + strString.substring(index + findString.length);
	}
	return text;
}


function isValidEmail(email) {
	return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}
function isValidHost(host) {
	return (/^([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(host);
}
function isValidUrl(url) {
	return (/^http:\/\/([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}[a-zA-Z_0-9:/.\-?&%=;]*$/i).test(url);
}

function GetForm() {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["FormPage"];
	} else {
		theform = document.FormPage;
	}
	return theform;
}

function GetDocument(id, name) {
	if (name == null) name = "";
	var param = new Array();
	param[0] = id;
	param[1] = name;
	res = Ajax("Library.ASPage", "GetDocument", param);
	if (res != false) {
		return AjaxGetResult(res);
	} else {
		return "";
	}
}

//ImageButton
function ButtonImage(id, over, idbutton) {
	var imgbtn1 = document.getElementById("imgbtn1_" + id);
	var imgbtn2 = document.getElementById("imgbtn2_" + id);
	var imgbtn3 = document.getElementById("imgbtn3_" + id);
	var imgbtn4 = document.getElementById("imgbtn4_" + id);
	var imgbutton = document.getElementById("imgbutton_" + id);
	var button = document.getElementById(idbutton);
	if (button.disabled) {
		imgbtn1.className = "btn_l3";
		imgbtn2.className = "btn_c3";
		imgbtn3.className = "btn_r3";
		if (imgbtn4 != null) {
			imgbtn4.className = "btn_c3";
			imgbutton.className = left(imgbutton.className, imgbutton.className.length - 1) + 1;
		}
	} else if (over) {
		imgbtn1.className = "btn_l2";
		imgbtn2.className = "btn_c2";
		imgbtn3.className = "btn_r2";
		if (imgbtn4 != null) {
			imgbtn4.className = "btn_c2";
			imgbutton.className = left(imgbutton.className, imgbutton.className.length - 1) + 2;
		}
	} else {
		imgbtn1.className = "btn_l1";
		imgbtn2.className = "btn_c1";
		imgbtn3.className = "btn_r1";
		if (imgbtn4 != null) {
			imgbtn4.className = "btn_c1";
			imgbutton.className = left(imgbutton.className, imgbutton.className.length - 1) + 1;
		}
	}
}
function ButtonImageDisabled(id, over, idbutton, disabled) {
	var button = document.getElementById(idbutton);
	if (disabled && !button.disabled) {
		button.disabled = true;
		ButtonImage(id, over, idbutton);
	} else if (!disabled && button.disabled) {
		button.disabled = false;
		ButtonImage(id, over, idbutton);
	}
}

//Rating-control
function RatingOver(index, id) {
	var el = RatingGetElements(id);
	var current = parseInt(el.hdnRating.value);
	if (index != 0) {
		for (i = 1; i < (index + 1); i += 1) {
			el.images[i - 1].className = "rating_Select";
		}
	}
	for (i = index + 1; i < (current + 1); i += 1) {
		el.images[i - 1].className = "rating_Set";
	}
	var last = index; if (last < current) last = current;
	for (i = last + 1; i < (6); i += 1) {
		el.images[i - 1].className = "rating_Null";
	}
}
function RatingClick(index, id) {
	var el = RatingGetElements(id);
	el.hdnRating.value = index;
	RatingOver(index, id);
	el.btnRating.disabled = false;
}
function RatingGetElements(id) {
	var o = new Object();
	o.Rating = document.getElementById("Rating_" + id);
	o.hdnRating = document.getElementById("hdnRating_" + id);
	var arr = new Array();
	arr[0] = document.getElementById("imgRating1_" + id);
	arr[1] = document.getElementById("imgRating2_" + id);
	arr[2] = document.getElementById("imgRating3_" + id);
	arr[3] = document.getElementById("imgRating4_" + id);
	arr[4] = document.getElementById("imgRating5_" + id);
	o.images = arr;
	o.btnRating = document.getElementById("btnRating_" + id);
	return o;
}

var ImageOpenZoomK = 8;
var ImageOpenZoomTime = 20;
var ImageOpenZoomBorderLine = 1;
var ImageOpenZoomBorderWidth = 20;
var ImageOpenZoomWidthMax;
var ImageOpenZoomHeightMax;
var ImageOpenZoomWidthMin;
var ImageOpenZoomHeightMin;
var ImageOpenZoomWidthCurrent;
var ImageOpenZoomSrc = "";
var ImageOpenZoom;
var ImageOpenZoomSmallLeft;
var ImageOpenZoomSmallTop;
var ImageOpenZoomKK;
var ImageOpenZoomKl;
var ImageOpenZoomKt;
var ImageOpenZoomLeftCurrent;
var ImageOpenZoomTopCurrent;
var ImageOpenZoomDiv;
var ImageOpenZoomImageLoad;
var flgImageOpenZoom = false;
var ImageOpenZoomFunctOpen;
var imgImageOpenZoom;
var ImageOpenZoomIconID;
function ImageOpen(img, smallImg, widthMax) {
	if (flgImageOpenZoom) return;
	flgImageOpenZoom = true;
	
	if (ImageOpenZoomDiv != null && ImageOpenZoomDiv.style.display != "none") {
		if (ImageOpenZoom != null & ImageOpenZoom.id == smallImg) {
			flgImageOpenZoom = false;
			return;
		} else {
			if (img != null) img = "'" + img + "'"; else img = "null";
			if (widthMax == null) widthMax = "null";
			ImageOpenZoomFunctOpen = "ImageOpen(" + img + ", \"" + smallImg + "\", " + widthMax + ")";
			flgImageOpenZoom = false;
			ImageOpen_Close();
			return;
		}
	}
	
	ImageOpenZoom = null;;
	ImageOpenZoomFunctOpen = null;
	
	var left = 200;
	var top = document.body.scrollTop + 120;

	var w = 800; if (widthMax != null) w = widthMax;
	var h = 520;
	
	ImageOpenZoomSrc = img;
	if (ImageOpenZoomSrc.indexOf("?") == -1) ImageOpenZoomSrc += "?"; else ImageOpenZoomSrc += "&";
	if (widthMax != null) ImageOpenZoomSrc += "w=" + widthMax + "&"; else ImageOpenZoomSrc += "w=" + w + "&";
	ImageOpenZoomSrc += "h=" + h;
	
	var imgFotoSmall = document.getElementById(smallImg);
	var posImg = getElementPosition(smallImg);
	left = posImg.left - ImageOpenZoomBorderWidth - 1;
	top = posImg.top - ImageOpenZoomBorderWidth - 1;

	if (ImageOpenZoomImageLoad == null) {
		ImageOpenZoomImageLoad = document.createElement("img");
		ImageOpenZoomImageLoad.id = "ImageOpenZoomImageLoad";
		ImageOpenZoomImageLoad.style.zIndex = 9999;
		ImageOpenZoomImageLoad.style.position = "absolute";
		setOpacity(ImageOpenZoomImageLoad, 4);
		ImageOpenZoomImageLoad.style.display = "none";
		document.body.appendChild(ImageOpenZoomImageLoad);
	}
	ImageOpenZoomImageLoad.src = null;
	ImageOpenZoomImageLoad.src = "../_images/imgload.gif";
	ImageOpenZoomImageLoad.style.left = posImg.left + "px";
	ImageOpenZoomImageLoad.style.top = posImg.top + "px";
	ImageOpenZoomImageLoad.width = imgFotoSmall.width;
	ImageOpenZoomImageLoad.height = imgFotoSmall.height;
	
	if (ImageOpenZoomDiv == null) {
		ImageOpenZoomDiv = document.createElement("div");
		ImageOpenZoomDiv.id = "divImageOpen";
		document.body.appendChild(ImageOpenZoomDiv);
		ImageOpenZoomDiv.style.background = "white";
		ImageOpenZoomDiv.style.zIndex = 10000;
		ImageOpenZoomDiv.style.border = "gray " + ImageOpenZoomBorderLine + "px solid";
		ImageOpenZoomDiv.style.position = "absolute";
		ImageOpenZoomDiv.style.display = "none";
		ImageOpenZoomDiv.innerHTML = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" +
			"<tr><td><img src=\"../_images/pic.gif\" width=\"" + ImageOpenZoomBorderWidth + "\" height=\"" + ImageOpenZoomBorderWidth + "\"></td><td>&nbsp;</td><td align=\"right\" valign=\"top\"><a href=\"\" onclick=\"ImageOpen_Close();return false;\"><img src=\"../_images/close.gif\" border=\"0\" width=\"13\" height=\"13\" style=\"margin-right: 2px; margin-top: 2px\"></a></td></tr>" +
			"<tr><td>&nbsp;</td><td align=\"center\" valign=\"center\"><a href=\"\" onclick=\"ImageOpen_Close();return false;\"><img id=\"imgImageOpenZoom\" src=\"" + ImageOpenZoomSrc + "\" border=\"0\"></a></td><td>&nbsp;</td></tr>" +
			"<tr><td>&nbsp;</td><td>&nbsp;</td><td><img src=\"../_images/pic.gif\" width=\"" + ImageOpenZoomBorderWidth + "\" height=\"" + ImageOpenZoomBorderWidth + "\"></td></tr>" +
			"</table>";
	}
	
	imgImageOpenZoom = document.getElementById("imgImageOpenZoom");
	imgImageOpenZoom.src = null;
	imgImageOpenZoom.onload = new Function("ImageOpen_Load(\"" + smallImg + "\", " + widthMax + ", " + w + ", " + h + ")");
	ImageOpenZoomImageLoad.style.display = "";
	imgImageOpenZoom.removeAttribute("width");
	imgImageOpenZoom.src = ImageOpenZoomSrc;
}
function ImageOpen_Load(smallImg, widthMax, w, h) {
	ImageOpenZoomImageLoad.style.display = "none";
	
	var posImg = getElementPosition(smallImg);
	var left = posImg.left - ImageOpenZoomBorderWidth - 1;
	var top = posImg.top - ImageOpenZoomBorderWidth - 1;

	ImageOpenZoomLeftCurrent = left;
	ImageOpenZoomTopCurrent = top;
	ImageOpenZoomSmallLeft = left - document.body.scrollLeft;
	ImageOpenZoomSmallTop = top - document.body.scrollTop;
	
	var imgFotoSmall = document.getElementById(smallImg);
	var imgTemp = new Image();
	imgTemp.src = imgImageOpenZoom.src;
	
	var heightMax;
	var imgWidth = "";
	
	var k;
	if (imgTemp.height < imgTemp.width) {
		k = imgTemp.width / w;
		if (parseInt(imgTemp.height / k) > h) {
			k = imgTemp.height / h;
			w = parseInt(imgTemp.width / k);
		} else {
			h = parseInt(imgTemp.height / k);
		}
	} else {
		k = imgTemp.height / h;
		if (parseInt(imgTemp.width / k) > w) {
			k = imgTemp.width / w;
			h = parseInt(imgTemp.height / k);
		} else {
			w = parseInt(imgTemp.width / k);
		}
	}
	widthMax = w;
	heightMax = h;
	
	imgTemp = null;
	
	imgImageOpenZoom.width = imgFotoSmall.width;

	ImageOpenZoomDiv.style.left = ImageOpenZoomLeftCurrent + "px";
	ImageOpenZoomDiv.style.top = ImageOpenZoomTopCurrent + "px";
	ImageOpenZoomDiv.style.display = "";
	
	ImageOpenZoomWidthMax = widthMax;
	ImageOpenZoomHeightMax = heightMax;
	ImageOpenZoomWidthMin = imgFotoSmall.width;
	ImageOpenZoomHeightMin = imgFotoSmall.height;
	ImageOpenZoomWidthCurrent = imgFotoSmall.width;
	ImageOpenZoom = imgFotoSmall;
	ImageOpenZoomKK = (ImageOpenZoomWidthMax - ImageOpenZoomWidthMin) / ImageOpenZoomK;
	ImageOpenZoomKl = (ImageOpenZoomSmallLeft - ((document.body.clientWidth - ImageOpenZoomWidthMax) / 2) + ImageOpenZoomBorderWidth + ImageOpenZoomBorderLine) / ImageOpenZoomK;
	ImageOpenZoomKt = (ImageOpenZoomSmallTop - ((document.body.clientHeight - ImageOpenZoomHeightMax) / 2) + ImageOpenZoomBorderWidth + ImageOpenZoomBorderLine) / ImageOpenZoomK;
	setOpacity(ImageOpenZoom, 3);
	ImageOpenZoomIconID = smallImg;
	window.setTimeout("ImageOpen_Zoom()", ImageOpenZoomTime);
}
function ImageOpen_Close() {
	if (flgImageOpenZoom) return;
	flgImageOpenZoom = true;
	
	var posImg = getElementPosition(ImageOpenZoomIconID);
	var left = posImg.left - ImageOpenZoomBorderWidth - 1;
	var top = posImg.top - ImageOpenZoomBorderWidth - 1;
	ImageOpenZoomSmallLeft = left;
	ImageOpenZoomSmallTop = top;
	ImageOpenZoomLeftCurrent = ImageOpenZoomDiv.offsetLeft;
	ImageOpenZoomTopCurrent = ImageOpenZoomDiv.offsetTop;
	ImageOpenZoomKl = (ImageOpenZoomSmallLeft - ImageOpenZoomLeftCurrent) / ImageOpenZoomK;
	ImageOpenZoomKt = (ImageOpenZoomSmallTop - ImageOpenZoomTopCurrent) / ImageOpenZoomK;

	window.setTimeout("ImageOpen_CloseZoom()", ImageOpenZoomTime);
}
function ImageOpen_Zoom() {
	if (ImageOpenZoomWidthCurrent + ImageOpenZoomKK >= ImageOpenZoomWidthMax) {
		ImageOpenZoomWidthCurrent = ImageOpenZoomWidthMax;
	} else {
		ImageOpenZoomWidthCurrent += ImageOpenZoomKK;
	}
	
	ImageOpenZoomLeftCurrent -= ImageOpenZoomKl;
	ImageOpenZoomTopCurrent -= ImageOpenZoomKt;
	ImageOpenZoomDiv.style.left = ImageOpenZoomLeftCurrent + "px";
	ImageOpenZoomDiv.style.top = ImageOpenZoomTopCurrent + "px";
	imgImageOpenZoom.width = ImageOpenZoomWidthCurrent;
	
	if (ImageOpenZoomWidthCurrent == ImageOpenZoomWidthMax) {
		flgImageOpenZoom = false;
	} else {
		window.setTimeout("ImageOpen_Zoom()", ImageOpenZoomTime);
	}
}
function ImageOpen_CloseZoom() {
	if (ImageOpenZoomWidthCurrent - ImageOpenZoomKK <= ImageOpenZoomWidthMin) {
		ImageOpenZoomWidthCurrent = ImageOpenZoomWidthMin;
	} else {
		ImageOpenZoomWidthCurrent -= ImageOpenZoomKK;
	}
	
	ImageOpenZoomLeftCurrent += ImageOpenZoomKl;
	ImageOpenZoomTopCurrent += ImageOpenZoomKt;
	ImageOpenZoomDiv.style.left = ImageOpenZoomLeftCurrent + "px";
	ImageOpenZoomDiv.style.top = ImageOpenZoomTopCurrent + "px";
	imgImageOpenZoom.width = ImageOpenZoomWidthCurrent;

	if (ImageOpenZoomWidthCurrent == ImageOpenZoomWidthMin) {
		ImageOpenZoomDiv.style.left = ImageOpenZoomSmallLeft - (ImageOpenZoomBorderWidth + ImageOpenZoomBorderLine) + document.body.scrollLeft + "px";
		ImageOpenZoomDiv.style.top = ImageOpenZoomSmallTop - (ImageOpenZoomBorderWidth + ImageOpenZoomBorderLine) + document.body.scrollTop + "px";
		ImageOpenZoomDiv.style.display = "none";
		setOpacity(ImageOpenZoom, 10);
		flgImageOpenZoom = false;
		if (ImageOpenZoomFunctOpen != null) window.setTimeout(ImageOpenZoomFunctOpen, ImageOpenZoomTime);
	} else {
		window.setTimeout("ImageOpen_CloseZoom()", ImageOpenZoomTime);
	}
}