function vote()
{
	var o=document.getElementById("val").value;
	var id=document.getElementById("url").value;
	var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", "/vote/"+id+"/"+o+".html",true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			if(xmlhttp.status!=200)
			{
				alert("Возникла ошибка при передаче данных. Попробуйте проголосовать позже.");
			}
			else
				alert(xmlhttp.responseText);
		}
	}
	xmlhttp.send(null);
}
function requestpassword()
{
	var id=document.getElementById("email").value;
	var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", "requestpassword.php?email="+id,true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			alert(xmlhttp.responseText);
		}
	}
	xmlhttp.send(null);
}
function showhide_regtype()
{
	document.getElementById("fizl").style.display=document.reg.typ[0].checked?"block":"none";
	document.getElementById("yurl").style.display=document.reg.typ[1].checked?"block":"none";
}
function isNotEmpty(elem)
{		
	var str=elem.value;
	var re=/.+/;
	return !str.match(re);
}
function isEmail(elem)
{
	var str=elem.value;
	var re=/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	return !str.match(re);
}

function validate_reg_form()
{
	if(!document.reg.typ[0].checked&&!document.reg.typ[1].checked)
	{
		alert("Выберите тип пользователя");
		return;
	}
	if(document.reg.typ[0].checked)
	{
		if(isNotEmpty(document.reg.fsurname))
		{
			alert("Укажите фамилию");
			document.reg.fsurname.focus();
			return;
		}
		if(isNotEmpty(document.reg.fname))
		{
			alert("Укажите имя");
			document.reg.fname.focus();
			return;
		}
		if(isEmail(document.reg.femail))
		{
			alert("Укажите e-mail");
			document.reg.femail.focus();
			return;
		}
		if(isNotEmpty(document.reg.fhomephone))
		{
			alert("Укажите домашний телефон");
			document.reg.fhometelephone.focus();
			return;
		}
	}
	if(document.reg.typ[1].checked)
	{
		if(document.reg.uopf.selectedIndex==0)
		{
			alert("Укажите ОПФ");
			document.reg.fopf.focus();
			return;
		}
		if(isNotEmpty(document.reg.ucompanyname))
		{
			alert("Укажите название компании");
			document.reg.ucompanyname.focus();
			return;
		}
		if(isNotEmpty(document.reg.usurname))
		{
			alert("Укажите фамилию");
			document.reg.usurname.focus();
			return;
		}
		if(isNotEmpty(document.reg.uname))
		{
			alert("Укажите имя");
			document.reg.uname.focus();
			return;
		}
		if(isEmail(document.reg.uemail))
		{
			alert("Укажите e-mail");
			document.reg.uemail.focus();
			return;
		}
		if(isNotEmpty(document.reg.uworkphone))
		{
			alert("Укажите рабочий телефон");
			document.reg.uworkphone.focus();
			return;
		}
	}
	if(isNotEmpty(document.reg.login))
	{
		alert("Укажите логин");
		document.reg.login.focus();
		return;
	}
	if(isNotEmpty(document.reg.password))
	{
		alert("Укажите пароль");
		document.reg.password.focus();
		return;
	}
	if(document.reg.password.value!=document.reg.password2.value)
	{
		alert("Пароли не совпадают");
		document.reg.password2.focus();
		return;
	}
	document.reg.submit();

}

function validate_infochange_form()
{		
	if(document.reg.typ.value==0)
	{		
		if(isNotEmpty(document.reg.fsurname))
		{
			alert("Укажите фамилию");
			document.reg.fsurname.focus();
			return;
		}		
		if(isNotEmpty(document.reg.fname))
		{
			alert("Укажите имя");
			document.reg.fname.focus();
			return;
		}		
		if(isEmail(document.reg.femail))
		{
			alert("Укажите e-mail");
			document.reg.femail.focus();
			return;
		}		
		if(isNotEmpty(document.reg.fhometelephone))
		{
			alert("Укажите домашний телефон");
			document.reg.fhometelephone.focus();
			return;
		}		
	}
	else
	{		
		if(isNotEmpty(document.reg.ucompanyname))
		{
			alert("Укажите название компании");
			document.reg.ucompanyname.focus();
			return;
		}			
		if(isNotEmpty(document.reg.usurname))
		{
			alert("Укажите фамилию");
			document.reg.usurname.focus();
			return;
		}		
		if(isNotEmpty(document.reg.uname))
		{
			alert("Укажите имя");
			document.reg.uname.focus();
			return;
		}		
		if(isEmail(document.reg.uemail))
		{
			alert("Укажите e-mail");
			document.reg.uemail.focus();
			return;
		}		
		if(isNotEmpty(document.reg.uworkphone))
		{
			alert("Укажите рабочий телефон");
			document.reg.uworkphone.focus();
			return;
		}		
	}
	if(isNotEmpty(document.reg.password))
	{
		alert("Укажите пароль");
		document.reg.password.focus();
		return;
	}
	if(document.reg.password.value!=document.reg.password2.value)
	{
		alert("Пароли не соврадают");
		document.reg.password2.focus();
		return;
	}
	document.reg.submit();

}

function redirect(url){
	document.location.href=url
}

function timed_redirect(url,timeout){
	setTimeout(function() {redirect(url)},timeout);
} 

function checkQuestion()
{
	var re = /\S.*/m;
	if(document.questions.name_input)
	{
		var result = document.questions.name_input.value.match(re);
		if(result)
			document.questions.name_input.value = result;
		else
		{
			alert("Введите имя пожалуйста");
			return;
		}
	}
	result = document.questions.question_input.value.match(re);
	if(!result)
	{
		alert("Введите вопрос пожалуйста");
		return;
	}
	document.questions.submit();
}

// DHTMLapi3.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com).
// Release 3.0. Supports NN4, IE, and W3C DOMs.

var DHTMLAPI = {
browserClass : new Object(),
		init : function () {
			this.browserClass.isCSS = ((document.body && document.body.style) ? true : false);
			this.browserClass.isW3C = ((this.browserClass.isCSS && document.getElementById) ? true : false),
				this.browserClass.isIE4 = ((this.browserClass.isCSS && document.all) ? true : false),
				this.browserClass.isNN4 = ((document.layers) ? true : false),
				this.browserClass.isIECSSCompat = ((document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false)
		},
    // Seek nested NN4 layer from string name
		seekLayer : function (doc, name) {
			var elem;
			for (var i = 0; i < doc.layers.length; i++) {
				if (doc.layers[i].name == name) {
					elem = doc.layers[i];
					break;
				}
            // dive into nested layers if necessary
				if (doc.layers[i].document.layers.length > 0) {
					elem = this.seekLayer(doc.layers[i].document, name);
					if (elem) {break;}
				}
			}
			return elem;
		},
		
    // Convert element name string or object reference
    // into a valid element object reference
		getRawObject : function (elemRef) {
			var elem;
			if (typeof elemRef == "string") {
				if (this.browserClass.isW3C) {
					elem = document.getElementById(elemRef);
				} else if (this.browserClass.isIE4) {
					elem = document.all(elemRef);
				} else if (this.browserClass.isNN4) {
					elem = this.seekLayer(document, elemRef);
				}
			} else {
            // pass through object reference
				elem = elemRef;
			}
			return elem;
		},
    // Convert element name string or object reference
    // into a valid style (or NN4 layer) object reference
		getStyleObject : function (elemRef) {
			var elem = this.getRawObject(elemRef);
			if (elem && this.browserClass.isCSS) {
				elem = elem.style;
			}
			return elem;
		},
		
    // Position an element at a specific pixel coordinate
		moveTo : function (elemRef, x, y) {
			var elem = this.getStyleObject(elemRef);
			if (elem) {
				if (this.browserClass.isCSS) {
                // equalize incorrect numeric value type
					var units = (typeof elem.left == "string") ? "px" : 0; 
					elem.left = x + units;
					elem.top = y + units;
				} else if (this.browserClass.isNN4) {
					elem.moveTo(x,y);
				}
			}
		},
		
    // Move an element by x and/or y pixels
		moveBy : function (elemRef, deltaX, deltaY) {
			var elem = this.getStyleObject(elemRef);
			if (elem) {
				if (this.browserClass.isCSS) {
                // equalize incorrect numeric value type
					var units = (typeof elem.left == "string") ? "px" : 0;
					if (!isNaN(this.getElementLeft(elemRef))) {
						elem.left = this.getElementLeft(elemRef) + deltaX + units;
						elem.top = this.getElementTop(elemRef) + deltaY + units;
					}
				} else if (this.browserClass.isNN4) {
					elem.moveBy(deltaX, deltaY);
				}
			}
		},
		
    // Set the z-order of an object
		setZIndex : function (obj, zOrder) {
			var elem = this.getStyleObject(obj);
			if (elem) {
				elem.zIndex = zOrder;
			}
		},
		
    // Set the background color of an object
		setBGColor : function (obj, color) {
			var elem = this.getStyleObject(obj);
			if (elem) {
				if (this.browserClass.isCSS) {
					elem.backgroundColor = color;
				} else if (this.browserClass.isNN4) {
					elem.bgColor = color;
				}
			}
		},
		
    // Set the visibility of an object to visible
		show : function (obj) {
			var elem = this.getStyleObject(obj);
			if (elem) {
				elem.visibility = "visible";
			}
		},
		
    // Set the visibility of an object to hidden
		hide : function (obj) {
			var elem = this.getStyleObject(obj);
			if (elem) {
				elem.visibility = "hidden";
			}
		},
		
    // return computed value for an element�s style property
		getComputedStyle : function (elemRef, CSSStyleProp) {
			var elem = this.getRawObject(elemRef);
			var styleValue, camel;
			if (elem) {
				if (document.defaultView && document.defaultView.getComputedStyle) {
                // W3C DOM version
					var compStyle = document.defaultView.getComputedStyle(elem, "");
					styleValue = compStyle.getPropertyValue(CSSStyleProp);
				} else if (elem.currentStyle) {
                // make IE style property camelCase name from CSS version
					var IEStyleProp = CSSStyleProp;
					var re = /-\D/;
					while (re.test(IEStyleProp)) {
						camel = IEStyleProp.match(re)[0].charAt(1).toUpperCase();
						IEStyleProp = IEStyleProp.replace(re, camel);
					}
					styleValue = elem.currentStyle[IEStyleProp];
				}
			}
			return (styleValue) ? styleValue : null;
		},
		
    // Retrieve the x coordinate of a positionable object
		getElementLeft : function (elemRef)  {
			var elem = this.getRawObject(elemRef);
			var result = null;
			if (this.browserClass.isCSS || this.browserClass.isW3C) {
				result = parseInt(this.getComputedStyle(elem, "left"));
			} else if (this.browserClass.isNN4) {
				result = elem.left;
			}
			return result;
		},
		
    // Retrieve the y coordinate of a positionable object
		getElementTop : function (elemRef)  {
			var elem = this.getRawObject(elemRef);
			var result = null;
			if (this.browserClass.isCSS || this.browserClass.isW3C) {
				result = parseInt(this.getComputedStyle(elem, "top"));
			} else if (this.browserClass.isNN4) {
				result = elem.top;
			}
			return result;
		},
		
    // Retrieve the rendered width of an element
		getElementWidth : function (elemRef)  {
			var result = null;
			var elem = this.getRawObject(elemRef);
			if (elem) {
				if (elem.offsetWidth) {
					if (elem.scrollWidth && (elem.offsetWidth != elem.scrollWidth)) {
						result = elem.scrollWidth;
					} else {
						result = elem.offsetWidth;
					}
				} else if (elem.clip && elem.clip.width) {
                // Netscape 4 positioned elements
					result = elem.clip.width;
				}
			}
			return result;
		},
		
    // Retrieve the rendered height of an element
		getElementHeight : function (elemRef)  {
			var result = null;
			var elem = this.getRawObject(elemRef);
			if (elem) {
				if (elem.offsetHeight) {
					result = elem.offsetHeight;
				} else if (elem.clip && elem.clip.height) {
					result = elem.clip.height;
				}
			}
			return result;
		},
		
    // Return the available content width space in browser window
		getInsideWindowWidth : function () {
			if (window.innerWidth) {
				return window.innerWidth;
			} else if (this.browserClass.isIECSSCompat) {
            // measure the html element's clientWidth
				return document.body.parentElement.clientWidth;
			} else if (document.body && document.body.clientWidth) {
				return document.body.clientWidth;
			}
			return null;
		},
		
    // Return the available content height space in browser window
		getInsideWindowHeight : function () {
			if (window.innerHeight) {
				return window.innerHeight;
			} else if (this.browserClass.isIECSSCompat) {
            // measure the html element's clientHeight
				return document.body.parentElement.clientHeight;
			} else if (document.body && document.body.clientHeight) {
				return document.body.clientHeight;
			}
			return null;
		}
}

addOnLoadEvent(function() {DHTMLAPI.init()});

// Center a positionable element whose ID is passed as 
// a parameter in the current window/frame, and show it 
function centerOnWindow(elemID) { 
    // 'obj' is the positionable object 
	var obj = DHTMLAPI.getRawObject(elemID); 
    // window scroll factors 
	var scrollX = 0, scrollY = 0; 
	if (document.body && typeof document.body.scrollTop != "undefined") { 
		scrollX += document.body.scrollLeft; 
		scrollY += document.body.scrollTop; 
		if (document.body.parentNode && 
			typeof document.body.parentNode.scrollTop != "undefined" && 
			(document.body.scrollTop != document.body.parentNode.scrollTop)) { 
				scrollX += document.body.parentNode.scrollLeft; 
				scrollY += document.body.parentNode.scrollTop; 
			} 
	} else if (typeof window.pageXOffset != "undefined") { 
		scrollX += window.pageXOffset; 
		scrollY += window.pageYOffset; 
	} 
	var x = Math.round((DHTMLAPI.getInsideWindowWidth()/2) - 
		(DHTMLAPI.getElementWidth(obj)/2)) + scrollX; 
	var y = Math.round((DHTMLAPI.getInsideWindowHeight()/2) - 
		(DHTMLAPI.getElementHeight(obj)/2)) + scrollY; 
	DHTMLAPI.moveTo(obj, x, y); 
	DHTMLAPI.show(obj); 
} 

function addEvent(elem, evtType, func, capture) {
	capture = (capture) ? capture : false;
	if (elem.addEventListener) {
		elem.addEventListener(evtType, func, capture);
	} else if (elem.attachEvent) {
		elem.attachEvent("on" + evtType, func);
	} else {
      // for IE/Mac, NN4, and older
		elem["on" + evtType] = func;
	}
}

function removeEvent(elem, evtType, func, capture) {
	capture = (capture) ? capture : false;
	if (elem.removeEventListener) {
		elem.removeEventListener(evtType, func, capture);
	} else if (elem.attachEvent) {
		elem.detachEvent("on" + evtType, func);
	} else {
      // for IE/Mac, NN4, and older
		elem["on" + evtType] = null;
	}
}

function addOnLoadEvent(func) {
	if (window.addEventListener || window.attachEvent) {
		addEvent(window,"load", func, false);
	} else {
		var oldQueue = (window.onload) ? window.onload : function() {};
		window.onload = function() {
			oldQueue();
			func();
		}
	}
}

function showeditbox(url)
{
	//	document.getElementById("editdiv").style.display="block";
	centerOnWindow("editdiv");
	//document.getElementById("editdiv").style.top=(window.pageYOffset+50)+"px";
	
	var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("editdiv").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
function hideeditbox()
{
	DHTMLAPI.hide("editdiv");
}

function show_desc_def_template()
{
	show_desc_def_template2(true);
}

function show_desc_def_template2(button)
{
	var id=document.getElementById("templateid").value;
	var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open("GET", "/itemeditor/template="+id+"/",true);
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4)
		{
			document.getElementById("template_form").innerHTML=xmlhttp.responseText+(button?"<input type='submit' value='добавить заполненные' />":"");
		}
	}
	xmlhttp.send(null);
}

