var macstyleFormVisible = 0;
var waitFormVisible = 0;
var stayAlertWin = 0;
var waitWin = null;
// var emailRegExp = new RegExp("^[a-zA-Z0-9][a-zA-Z0-9_\.\-]+@([a-zA-Z0-9][a-zA-Z0-9_\-]+\.){1,10}[a-zA-Z]{2,6}$");
// var emailRegExp = new RegExp('^(("[\w-]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-]+")([\w-]+(?:\.[\w-]+)*))((@((\w[\w-]{0,66})\.)+([a-z]{2,6})$)|(@((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$))', 'i');
var emailRegExp = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$");
var wwwRegExp = new RegExp("^(ht|f)tps?:\/\/([a-zA-Z0-9][a-zA-Z0-9_\-]+[\.]{1})+[a-zA-Z]{2,6}$");


// =========================================
//     КОНСТРУКТОР ОБЪЕКТА         fadedWindow
// =========================================

function fadedWindow(id){
	this.id = (id ? id : 'fw' + Math.round(Math.random()*100000));
	this.zIndex = 3000;
	this.stayOnTop = false;
	this.text = '';
	this.title = '';
	this.footer = '';
	this.withTitleBar = true;
	this.notitle = false;
	this.nofooter = false;
	this.title_className = '';
	this.title_div = null;
	this.content_div = null;
	this.footer_div = null;
	this.transparency = false;
	this.buttons = new Array();
	this.butType = 'butNone';
	if(!isDefined(this.width)) this.width = 300;
	if(!isDefined(this.height)) this.height = 200;
	this.div = null;
}

fadedWindow.prototype.create = function(isrefresh){
	// if(!xGetElementById(this.div)){
		if(!this.div){
			this.div = new_DIV();
			var documentBody = document.getElementsByTagName('BODY')[0];
			documentBody.appendChild(this.div);
			this.div.id = this.id;
			if(!this.iframe){
				this.iframe = document.createElement('IFRAME');
				this.iframe.id = this.id + '_iframe';
			}
			this.iframe.className = 'fwIframe';
			this.div.appendChild(this.iframe);
			this.div.obj = this;
		}
		xZIndex(this.div, this.zIndex);
		this.div.className = 'fw';
		xWidth(this.div, xClientWidth());
		xHeight(this.div, xClientHeight());
		xHide(this.div);
		xDisplay(this.div, 'block');

		if(!this.sub_div){
			this.sub_div = new_DIV();
			this.div.appendChild(this.sub_div);
			this.sub_div.id = this.id+'_sub_div';
		}
		this.sub_div.className = 'fw_sub_div';
		// if(isMozilla) this.sub_div.style.position = 'fixed';
		xZIndex(this.sub_div, this.zIndex);

		if(!this.main_div){
			this.main_div = new_DIV();
			this.div.appendChild(this.main_div);
			this.main_div.id = this.id+'_main_div';
		}
		this.main_div.className = 'fw_main_div';
		// if(isMozilla) this.main_div.style.position = 'fixed';
		xWidth(this.main_div, this.width);
		xHeight(this.main_div, this.height);
		// this.main_div.style.marginLeft = '-'+(this.width/2)+'px';
		// this.main_div.style.marginLeft = '-'+(this.height/2)+'px';
		xMoveTo(this.main_div, (xClientWidth()-this.width)/2, (xClientHeight()-this.height)/2);
		xZIndex(this.main_div, this.zIndex+1);
		
		if(this.notitle!=true){
			if(!this.title_div){
				this.title_div = new_DIV();
				this.main_div.appendChild(this.title_div);
				this.title_div.id = this.id+'_title_div';
			}
			this.title_div.win = this.div;
			this.title_div.obj = this;
			this.title_div.className = ((this.title_className!='')?this.title_className:'fw_title_div');
			xWidth(this.title_div, this.width);
			xZIndex(this.title_div, this.zIndex+2);
			if(!this.titlebar){
				this.titlebar = new_DIV();
				this.title_div.appendChild(this.titlebar);
				this.titlebar.id = this.id+'_title';
			}
			this.titlebar.className = 'fw_title_content';
			xInnerHtml(this.titlebar, this.title);
			xMoveTo(this.title_div, xPageX(this.main_div), xPageY(this.main_div));

			if(!this.closebut){
				this.closebut = new_DIV();
				this.title_div.appendChild(this.closebut);
				this.closebut.id = this.id+'_closebut';
			}
			this.closebut.className = 'fwCloseBut';
			xZIndex(this.closebut, this.zIndex+3);
			xInnerHtml(this.closebut, '<img src='+htmlrootpath+'/images/close_but.gif width=14 height=14 border=0 vspace=0 hspace=0 />');
			xMoveTo(this.closebut, this.width-17, 3);
			this.closebut.obj = this;
			this.closebut.onmouseover = function(){
				xBackground(this, null, htmlrootpath+'/images/close_but_bg.gif');
			}
			this.closebut.onmouseout = function(){
				xBackground(this, null, '');
			}
			this.closebut.onclick = function(){
				xBackground(this, null, '');
				this.obj.hide();
			}
		}

		if(!this.content_div){
			this.content_div = new_DIV();
			this.main_div.appendChild(this.content_div);
			this.content_div.id = this.id+'_content_div';
		}
		this.content_div.className = 'fw_content_div';
		xWidth(this.content_div, this.width);
		xZIndex(this.title_div, this.zIndex+2);
		if(!this.content){
			this.content = new_DIV();
			this.content_div.appendChild(this.content);
			this.content.id = this.id+'_content';
		}
		this.content.className = 'fw_content';
		xInnerHtml(this.content, this.text);
		xMoveTo(this.content_div, xPageX(this.main_div), xPageY(this.main_div)+((this.notitle!=false)?xHeight(this.withTitleBar):0));
		
		if(this.nofooter!=true){
			if(!this.footer_div){
				this.footer_div = new_DIV();
				this.main_div.appendChild(this.footer_div);
				this.footer_div.id = this.id+'_footer_div';
			}
			this.footer_div.className = 'fw_footer_div';
			xWidth(this.footer_div, this.width);
			xZIndex(this.title_div, this.zIndex+2);
			xMoveTo(this.footer_div, xPageX(this.main_div), xPageY(this.main_div)+this.height-xHeight(this.footer_div));
			if(!this.butsbar){
				this.butsbar = new_DIV();
				this.footer_div.appendChild(this.butsbar);
				this.butsbar.id = this.id+'_buttons';
			}
			this.butsbar.className = 'fw_footer_content';

			if((this.butType && this.butType!='butNone') || isDefined(this.buttons)){
				this.refresh_buttons();
			}

		}

		xHeight(this.content_div, this.height-((this.notitle!=true)?xHeight(this.titlebar):0)-((this.nofooter!=true)?xHeight(this.footer_div):0));
		
		xShow(this.div);
		if(!isrefresh) xDisplay(this.div, 'none');
		
	// }

}
	
fadedWindow.prototype.show = function(){
	if(isSafari) hideFlashes();
	xDisplay(this.div, 'block');
	if(this.defaultButton) this.defaultButton.focus();
}

fadedWindow.prototype.hide = function(){
	if(isSafari) revertFlashes();
	xDisplay(this.div, 'none');
}

fadedWindow.prototype.refresh = function(){
	var curr_state = xDisplay(this.div);
	this.create(true);
	xDisplay(this.div, ((curr_state && curr_state!='')?curr_state:'block'));
}

fadedWindow.prototype.resizeTo = function(w, h){
	this.width = w;
	this.height = h;
	this.refresh();
}

fadedWindow.prototype.setText = function(text){
	this.text = text;
	xInnerHtml(this.content, this.text);
}

fadedWindow.prototype.refresh_buttons = function(){
	if(this.butType!='' || isDefined(this.buttons)){
		var butText = 'OK';
		var butAction = '';
		switch(this.butType) {
			case('butOK'):{
				butText = 'OK';
				break;
			}
			case('butClose'):{
				butText = 'Закрыть';
				break;
			}
			case('butNone'):{
				butText = '';
				break;
			}
		}
		if(butText!='' || isDefined(this.buttons)){
			
			while(this.butsbar.hasChildNodes())
				this.butsbar.removeChild(this.butsbar.firstChild);
			if(butText!=''){
				this.defaultButton = new_BUTTON(this.butsbar, butText, function(){this.obj.hide(); return false});
				this.defaultButton.obj = this;
				this.defaultButton.className = 'fwButton';
			}
			for(var i=0;i<this.buttons.length;i++){
				this.but = new_BUTTON(this.butsbar, this.buttons[i].title, new Function(this.buttons[i].action+'return false'));
				this.but.obj = this;
				this.but.className = 'fwButton';
				if(this.buttons[i].def) this.defaultButton = this.but;
			}

		}
	}
}

function hidefadedWindow(id){
	xDisplay(id+'_div', 'none');
	if(isMSIE) xDisplay(id+'_divPNG', 'none');
	return false;
}

fadedWindow.prototype.moveOnTop = function(){
	var windows = xGetElementsByClassName('fadedWin');
	var z = highZ = 0;
	for(var i=0;i<windows.length;i++){
		z = xZIndex(windows[i]);
		if(highZ<z) highZ=z;
	}
	xZIndex(this.div, highZ+10);
	return false;
}

fadedWindow.prototype.die = function(){
	var documentBody = document.getElementsByTagName('BODY')[0];
	documentBody.removeChild(this.div);
	if(isMSIE) documentBody.removeChild(this.divPNG);
	return false;
	
	// не забывать что надо еще удалить сам объект  this  посредством присваивания его к  null  после вызова этого метода.
}

fadedWindow.prototype.repos = function(){
	reposFloatedWin(this.div, this.divPNG);
}

function myOnDragStart(ele, mx, my){
}
function myOnDrag(obj, mdx, mdy){
	if(isDefined(obj.win)) xMoveTo(obj.win, xLeft(obj.win) + mdx, xTop(obj.win) + mdy);
}
function myOnDragEnd(ele, mx, my){
}




// =========================================

// Три основных типа окна

var loginWindow = null;

function showAlert(text, butType) {
	if(!alertWindow){
		alertWindow = new fadedWindow();
		alertWindow.create();
	}
	if(xDef(butType) && butType!='') var oldButType = alertWindow.butType;
	alertWindow.setText(text);
	if(xDef(butType) && butType!='') alertWindow.butType = butType;
	alertWindow.show();
	if(xDef(butType) && butType!='') alertWindow.butType = oldButType;
}

function createCommonForm(w, h, ttl, message, buts, zIndex){
	var w = EmptyWin('', w, h, zIndex);
	var buttons = new Array();
	var buts_h = 0;
	var buts_div = '';
	if(buts!='nobuttons'){
		if(buts && (buts.length>0))
			for(var i=0; i<buts.length; i++){
				buttons.push("<button class="+(buts[i].className?buts[i].className:"phCancelButton")+" onclick=\""+buts[i].js+"return false\">"+buts[i].title+"</button>");
			}
		else {
			buttons.push("<button class="+(buts[i].className?buts[i].className:"phCancelButton")+" onclick=\"xGetElementById('"+w.id+"').obj.hide();return false\">"+unlanguage("OK###OK")+"</button>");
		}
		buts_h = 40;
		buts_div =
			"<div style='padding-top:10px; text-align:center;'>"+
				buttons.join("&nbsp;&nbsp;")+
			"</div>";
	}
	var html = 
		"<div style='height:27px; color:white; font-size: 12px; font-weight:bold; text-align:center; background:#7D8084;'><div style='padding-top:5px'>"+unlanguage(ttl)+"</div></div>"+
		"<div style='height:"+(h-27-2)+"px; border:1px solid #7D8084; overflow:auto'>"+
			"<div style='height:"+(h-27-2-buts_h)+"px; overflow:auto'>"+
				"<div style='padding:20px' id="+w.id+"_cont>"+
					message+
				"</div>"+
			"</div>"+
			buts_div+
		"</div>";
	w.create();
	w.main_div.style.padding = '0';
	w.content_div.style.padding = '0';
	w.content.style.padding = '0';
	w.content_div.style.overflow = 'hidden';
	w.text = html;
	w.refresh();
	return w;
}

function checkForm(frm){
	var inputs = xGetElementsByClassName('inputs', frm);
	var errors = Array();
	for(var i=0; i<inputs.length; i++){
		// required attribute
		/*
		if(inputs[i].hasAttribute('required'))
			if(inputs[i].value==''){
				errors.push({obj:inputs[i], title:unlanguage('Обязатальное поле не заполнено.')});
			}
		if(inputs[i].hasAttribute('format')){
			var frmt = inputs[i].getAttribute('format');
			switch(frmt){
				case('email'):{
					if(!inputs[i].value.match(emailRegExp))
						errors.push({obj:inputs[i], title:unlanguage('Поле не соответствует формату e-mail.')});
					break;
				}
				case('www'):{
					if(!inputs[i].value.match(wwwRegExp))
						errors.push({obj:inputs[i], title:unlanguage('Поле не соответствует формату www-адреса.')});
					break;
				}
			}
		}
		*/
		if(inputs[i].error_div)
			xInnerHtml(inputs[i].error_div, '');
	}
	for(var i=0; i<errors.length; i++){
		if(!errors[i].obj.error_div){
			errors[i].obj.error_div = new_DIV();
			errors[i].obj.parentNode.insertBefore(errors[i].obj.error_div, errors[i].obj);
			errors[i].obj.parentNode.insertBefore(errors[i].obj, errors[i].obj.error_div);
			errors[i].obj.error_div.style.color = 'red';
			errors[i].obj.error_div.style.marginLeft = errors[i].obj.style.marginLeft;
		}
		var ih = xInnerHtml(errors[i].obj.error_div);
		xInnerHtml(errors[i].obj.error_div, ih+((ih!='')?'<br />':'')+errors[i].title);
	}
	return (errors.length==0);
}


function showLogin(ini_login, ini_password, referer) {

	var str = htmlrootpath+"/index.htm";
	if(referer)
		var ref = referer;
	else 
		var ref = document.location.href.replace(/^http:\/\//, '').replace(/^[^\/]+/, '');
	var sLs = '' +
		'<form name=auth action=' + ref + ' method=post>' +
		'<input type=hidden name=referer value="'+ref+'"><input type=hidden name=log_action value="commit">' +
		'<table width=100% border=0 cellspacing=5 cellpadding=0>' +
		'<tr valign=top><td style="padding:20px 0 30px 0" colspan=2>'+unlanguage('Войдите, используя Ваш аккаунт.')+'</td></tr>' +
		'<tr valign=top><td align=right style="padding-top:5px; width:1%; color:#333333">'+unlanguage('Имя&nbsp;пользователя###Member&nbsp;name')+':</td><td><input name=login required type=text id=authFormLogin value="'+(ini_login?ini_login:'')+'" size=20 class=inputs onKeyDown="if(event.keyCode==13)return checkAuth();" style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="padding-top:25px; color:#333333">'+unlanguage('Пароль###Password')+':</td><td style="padding-top:20px"><input name=password required type=password id=authFormPassword value="'+(ini_password?ini_password:'')+'" size=20 class=inputs onKeyDown="if(event.keyCode==13)return checkAuth();" style="background:#EFF9C8; height:20px; width:100%; margin:0 5px 0 5px" /></td></tr>' +
		'<tr><td align=right colspan=2>'+
			'<button class=phCancelButton onclick="loginWindow.hide(); return false">'+unlanguage('Oтмена###Cancel')+'</button>'+
			'&nbsp;&nbsp;'+
			'<button class=phOKButton onclick="if(checkForm(this.form)) {xajax__respondent(\'checkAuth\', xGetElementById(\'authFormLogin\').value, xGetElementById(\'authFormPassword\').value);} return false">'+unlanguage('Войти###Enter')+'</button>'+
		'</td></tr>' +
		'<tr>' +
			'<td colspan=2 style="padding-top:10px">' +
				// welcome_text() + '<br />' +
			'</td>' +
		'</tr>' +
		'</table>' +
		'</form>';

	if(!loginWindow){
		var html = '&nbsp;'
		
		loginWindow = createCommonForm(423, 346, unlanguage('Добро пожаловать###Welcome'), html, 'nobuttons', 350);
		loginWindow.show();
	}

	xInnerHtml(loginWindow.id+'_cont', sLs);

	loginWindow.waitIndicator = new_DIV();
	loginWindow.waitIndicator.className = 'authFormWaitInd';
	loginWindow.waitIndicator.id = loginWindow.id+'_waitIndicator';
	xZIndex(loginWindow.waitIndicator, loginWindow.zIndex+20);
	xDisplay(loginWindow.waitIndicator, 'none');
	loginWindow.content_div.appendChild(loginWindow.waitIndicator);

	loginWindow.show();
	xGetElementById('authFormLogin').focus();

	return false;
}


// Сопутствующие 

function showConfirm(text,yesAction,noAction){
	var sc_text="<table width=100% border=0 cellspacing=0 cellpadding=0><form name=confirm>" +
	"<tr valign=middle>" +
		"<td>"+text+"</td>" +
	"</tr>" +
	"<tr height=40 align=center valign=middle>" +
		"<td style=`padding-top:5px`>" +
			"<input type=`button` value=`Да` onClick=`"+yesAction.replace(/;$/,"")+((yesAction.replace(/;$/,"")=="")?"":";")+"if(!(stayAlertWin)) alertWindow.hide();return false`>" +
			"&nbsp;&nbsp;" +
			"<input type=`button` value=`Нет` onClick=`"+noAction.replace(/;$/,"")+((noAction.replace(/;$/,"")=="")?"":";")+"if(!(stayAlertWin)) alertWindow.hide();return false`>" +
		"</td>" +
	"</tr>" +
	"</form></table>";
	showAlert(sc_text,"butNone");
	return true;
}

function showConfirm2(text,okAction,cancelAction){
	var sc_text="<table width=100% border=0 cellspacing=0 cellpadding=0><form name=confirm2>" +
	"<tr valign=middle>" +
		"<td>"+text+"</td>" +
	"</tr>" +
	"<tr height=40 align=center valign=middle>" +
		"<td style=\"padding-top:5px\">" +
			"<input type='button' value='OK' onClick='"+okAction.replace(/;$/,"")+((okAction.replace(/;$/,"")=="")?"":";")+"confirmWindow.hide();return false'>" +
			"&nbsp;&nbsp;" +
			"<input type='button' value='Отмена' onClick='"+cancelAction.replace(/;$/,"")+((cancelAction.replace(/;$/,"")=="")?"":";")+"confirmWindow.hide();return false'>" +
		"</td>" +
	"</tr>" +
	"</form></table>";


	var tbl,tbody1,form,tr1,tr2,td1;
	
	tbody1 = new_TBODY();
	
	// form = new_FORM(tbody1, './', 'multipart/form-data', 'multipart/form-data', 'get', '', 'confirmFrm');
	// form.id = 'confirmFrm';

	tr1 = new_TR(tbody1);
	td1 = new_TDwWIDTH(tr1, '100%');
	td1.innerHTML = text;
	
	tr2 = new_TR(tbody1);
	tr2.height = 40;
	td1 = new_TDwWIDTH(tr2, '100%');
	with(td1) {
		height = 40;
		innerHTML = ''+
			'<input type="button" value="OK" onClick="'+okAction.replace(/;$/,"")+((okAction.replace(/;$/,"")=="")?"":";")+'confirmWindow.hide();return false">' +
			'&nbsp;&nbsp;' +
			'<input type="button" value="Отмена" onClick="'+cancelAction.replace(/;$/,"")+((cancelAction.replace(/;$/,"")=="")?"":";")+'confirmWindow.hide();return false">' +
			'';
	}

	tbl = new_TABLEw100(tbody1);
	
	confirmWindow.zIndex = alertWindow.zIndex+10;
	// confirmWindow.text = tbl.outerHTML;
	confirmWindow.show();
	confirmWindow.item.innerHTML = '';
	confirmWindow.item.appendChild(tbl);
}

function showConfirm(text,okAction,cancelAction){
	confirmWindow.text = text;
	confirmWindow.buttons[0].action = okAction.replace(/;$/,"")+((okAction.replace(/;$/,"")=="")?"":";")+'confirmWindow.hide();';
	confirmWindow.buttons[1].action = cancelAction.replace(/;$/,"")+((cancelAction.replace(/;$/,"")=="")?"":";")+'confirmWindow.hide();';
	confirmWindow.refresh();
	confirmWindow.show();
}

function showConfirm2(text,yesAction,noAction){
	
	var yesAct = yesAction.replace(/;$/,"")+((yesAction.replace(/;$/,"")=="")?"":";")+'confirmWindow2.hide();';
	var noAct = noAction.replace(/;$/,"")+((noAction.replace(/;$/,"")=="")?"":";")+'confirmWindow2.hide();';
	confirmWindow2.text = text;
	// confirmWindow2.buttons = Array({title:'".unlanguage("Да###Yes")."', action:yesAct},{title:'".unlanguage("Нет###No")."', action:noAct});
	confirmWindow2.buttons = Array({title:'Да', action:yesAct},{title:'Нет', action:noAct});
	confirmWindow2.refresh();
	confirmWindow2.show();

}

function showPrompt(text, okAction, cancelAction, defaultValue){
	var sp_text = '<table width=100% border=0 cellspacing=0 cellpadding=0>' +
	'<tr valign=middle>' +
		'<td>'+text+'</td>' +
	'</tr>' +
	'<tr valign=middle>' +
		'<td width=100%><input type=text name=win_prompt_text id=win_prompt_text value="'+(defaultValue?defaultValue:'')+'" style="width:100%"></td>' +
	'</tr>' +
	'</table>';
	var okAct = okAction.replace(/;$/,"")+((okAction.replace(/;$/,"")=="")?"":";")+'promptWindow.hide();';
	var cancelAct = cancelAction.replace(/;$/,"")+((cancelAction.replace(/;$/,"")=="")?"":";")+'promptWindow.hide();';
	promptWindow.text = sp_text;
	promptWindow.buttons = Array({title:'OK', action:okAct},{title:'Отмена', action:cancelAct});
	promptWindow.refresh();
	promptWindow.show();
}


function waitAlert(str){
	if (!waitFormVisible) showAlert("<center>"+((str!="")?str:"Подождите, осуществляется загрузка...")+"<br /><br /><img src="+htmlrootpath+"/images/progress_bar.gif width=154 height=18 border=0 style='margin-bottom:20px'></center>","butNone");
	waitFormVisible = 1;
	return false;
}

function errorAlert(str){
	showAlert("<font color=red>"+((str!="")?str:"Ошибка системы... Обратитесь к <a href=mailto:ewgeniy@onegin.com>администратору</a> с сообщением о случившемся.")+"</font>","butOK");
	return false;
}

function hideAlert(){
	stayAlertWin = 0;
	waitFormVisible = 0;
	alertWindow.hide();
}

function register_text(){
	return "<a href='"+htmlrootpath+"/registration/index.htm'>"+unlanguage('Зарегистрироваться###Register')+"</a>";
}

function checkAuth(){
	if(xGetElementById('authFormLogin') && xGetElementById('authFormPassword')){
		var ref = document.location.href.replace(/http:\/\//, '').replace(/[^\/]+/, '');
		var s = '';
		if(xGetElementById('authFormLogin').value=='')
			s += '<li>'+unlanguage('поле <b>Логин<' + '/b> пустое###field <b>Login<' + '/b> is empty')+'.';
		else
			if(xGetElementById('authFormLogin').value.match(/\\W/g)!=null)
				s += '<li>'+unlanguage('недопустимые символы в поле <b>Логин<' + '/b>###incorrect chars in <b>Login<' + '/b>')+'.';
		if(xGetElementById('authFormPassword').value=='')
			s += '<li>'+unlanguage('поле <b>Пароль<' + '/b> пустое###field <b>Password<' + '/b> is empty')+'.';
		if(s!=''){
			showAlert(unlanguage('ошибка:###error:')+'<ul>'+s+'</ul>');
			return false;
		}
		xDisplay(loginWindow.waitIndicator, 'block');
		xajax__respondent('checkAuth', xGetElementById('authFormLogin').value, xGetElementById('authFormPassword').value);
		// document.auth.submit();
		return false;
	} else {
		showAlert(unlanguage('Системная ошибка. Обратитесь к разработчикам сайта.###System error. Mail to site administrator.'));
		return false;
	}
}
function authResult(authenticated, auth_error){
	if(authenticated==0){
		xDisplay(loginWindow.waitIndicator, 'none');
		showAlert(auth_error);
	} else {
		document.location=document.location;
	}
}

function welcome_text(){
	return "<div style='text-align:left'>" +
		unlanguage(
			"Авторизуйтесь, пожалуйста. После авторизации у Вас появится возможность полноценной работы с сайтом.<br />"+
			"Если Вы еще не имеете имени пользователя и пароля, "+
			"<a href='"+htmlrootpath+"/registration/index.htm'>зарегистрируйтесь</a>"+
			" прямо сейчас."+
			"###"+
			"If you are already a registered user, please sign in now to be able to use the website features in their full capacity. "+
			"If you don't have a username and password yet, please, take a moment to fill out your <a href='"+htmlrootpath+"/registration/index.htm'>registration form</a>."
		)+
		"<br /><br />"+
		"<a href=./ onClick='showAlert(\""+registration_info+"\");return false'>"+unlanguage("Для чего нужна регистрация###Why register")+"</a>? "+
		unlanguage("Если у Вас есть вопросы, ###If you have any questions, ")+
		"<a href='"+htmlrootpath+"/contacts/index.htm'>"+unlanguage("свяжитесь с нами###please contact us")+"</a>." +
	"</div>";
}

function WaitWin(){
	var ww = new fadedWindow();
	ww.zIndex = 4000;
	ww.text = '<div class=waitWin><div>подождите</div></div>';
	ww.title = '';
	ww.footer = '';
	ww.withTitleBar = false;
	ww.notitle = true;
	ww.nofooter = true;
	ww.title_className = '';
	ww.buttons = [];
	ww.butType = 'butNone';
	ww.width = 200;
	ww.height = 200;
	ww.id = 'waitWin';
	return ww;
}

function EmptyWin(txt, w, h, zIndex){
	var ww = new fadedWindow();
	if(zIndex) ww.zIndex = zIndex;
	ww.text = '<div class=waitWin>'+txt+'</div>';
	ww.title = '';
	ww.footer = '';
	ww.withTitleBar = false;
	ww.notitle = true;
	ww.nofooter = true;
	ww.title_className = '';
	ww.buttons = [];
	ww.butType = 'butNone';
	ww.width = w;
	ww.height = h;
	return ww;
}


function reposFloatedWin(id_or_obj, id_or_obj_png){
	var obj = xGetElementById(id_or_obj);
	if(!obj) return;
	var clW = parseInt(xClientWidth());
	var clH = parseInt(xClientHeight());
	var layW = parseInt(xWidth(obj));
	var layH = parseInt(xHeight(obj));
	var l = (layW<=clW) ? parseInt(xScrollLeft() + (clW - layW)/2) : 0;
	var t = (layH<=clH) ? parseInt(xScrollTop() + (clH - layH)/2) : 0;
	if(obj){
		if(layW<=clW)
			xLeft(obj, l);
		if(layH<=clH)
			xTop(obj, t);
	}
	if(isMSIE){
		var obj = xGetElementById(id_or_obj_png);
		if(obj_png){
			if(layW<=clW)
				xLeft(obj_png, l + 15);
			if(layH<=clH)
				xTop(obj_png, t + 20);
		}
	}
}


function show_ask_question(ini_login, ini_password, referer) {

	var str = htmlrootpath+"/index.htm";
	if(referer)
		var ref = referer;
	else 
		var ref = document.location.href.replace(/^http:\/\//, '').replace(/^[^\/]+/, '');
	var sLs = '' +
		'<form name=auth action=' + ref + ' method=post>' +
		'<input type=hidden name=referer value="'+ref+'"><input type=hidden name=log_action value="commit">' +
		'<table width=100% border=0 cellspacing=0 cellpadding=5>' +
		'<tr valign=top><td style="padding:5px 0 5px 0" colspan=2>Поля, отмеченные звёздочкой, обязательны для заполнения</td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Имя*:</td><td><input name=name1 required type=text id=askFormName size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Email*:</td><td><input name=email1 required type=text id=askFormEmail size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Телефон:</td><td><input name=phone1  type=text id=askFormPhone size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Вопрос*:</td><td><textarea name=question1 required id=askFormQuestion size=20 style="background:#EFF9C8; width:100%; height:100px; margin:0 5px 0 5px"></textarea></td></tr>' +

		'<tr><td align=right colspan=2>'+
			'<button class=phCancelButton onclick="loginWindow.hide(); return false"> Oтмена </button>'+
			'&nbsp;&nbsp;'+
			'<button class=phOKButton onclick="xajax__respondent(\'ask_question\', escape(xGetElementById(\'askFormName\').value), xGetElementById(\'askFormEmail\').value, xGetElementById(\'askFormPhone\').value, escape(xGetElementById(\'askFormQuestion\').value)); return false"> Отправить </button>'+
		'</td></tr>' +
		'</table>' +
		'</form>';

	if(!loginWindow){
		var html = '&nbsp;'
		
		loginWindow = createCommonForm(423, 346, 'Задать вопрос', html, 'nobuttons', 350);
		loginWindow.show();
	}

	xInnerHtml(loginWindow.id+'_cont', sLs);

	loginWindow.waitIndicator = new_DIV();
	loginWindow.waitIndicator.className = 'authFormWaitInd';
	loginWindow.waitIndicator.id = loginWindow.id+'_waitIndicator';
	xZIndex(loginWindow.waitIndicator, loginWindow.zIndex+20);
	xDisplay(loginWindow.waitIndicator, 'none');
	loginWindow.content_div.appendChild(loginWindow.waitIndicator);

	loginWindow.show();
	//xGetElementById('askFormName').focus();

	return false;
}


function show_app_seminar(ini_login, ini_password, referer) {

	var str = htmlrootpath+"/index.htm";
	if(referer)
		var ref = referer;
	else 
		var ref = document.location.href.replace(/^http:\/\//, '').replace(/^[^\/]+/, '');
	var sLs = '' +
		'<form name=auth action=' + ref + ' method=post>' +
		'<input type=hidden name=referer value="'+ref+'"><input type=hidden name=log_action value="commit">' +
		'<table width=100% border=0 cellspacing=0 cellpadding=5>' +
		'<tr valign=top><td style="padding:5px 0 5px 0" colspan=2>Поля, отмеченные звёздочкой, обязательны для заполнения</td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Имя*:</td><td><input name=name1 required type=text id=askFormName size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Email*:</td><td><input name=email1 required type=text id=askFormEmail size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Телефон:</td><td><input name=phone1  type=text id=askFormPhone size=20 style="background:#EFF9C8; width:100%; height:20px; margin:0 5px 0 5px" /></td></tr>' +
		'<tr valign=top><td align=right style="width:1%; color:#333333">Вопрос*:</td><td><textarea name=question1 required id=askFormQuestion size=20 style="background:#EFF9C8; width:100%; height:100px; margin:0 5px 0 5px"></textarea></td></tr>' +

		'<tr><td align=right colspan=2>'+
			'<button class=phCancelButton onclick="loginWindow.hide(); return false"> Oтмена </button>'+
			'&nbsp;&nbsp;'+
			'<button class=phOKButton onclick="xajax__respondent(\'app_seminar\', escape(xGetElementById(\'askFormName\').value), xGetElementById(\'askFormEmail\').value, xGetElementById(\'askFormPhone\').value, escape(xGetElementById(\'askFormQuestion\').value)); return false"> Отправить </button>'+
		'</td></tr>' +
		'</table>' +
		'</form>';

	if(!loginWindow){
		var html = '&nbsp;'
		
		loginWindow = createCommonForm(423, 346, 'Заявка на участие', html, 'nobuttons', 350);
		loginWindow.show();
	}

	xInnerHtml(loginWindow.id+'_cont', sLs);

	loginWindow.waitIndicator = new_DIV();
	loginWindow.waitIndicator.className = 'authFormWaitInd';
	loginWindow.waitIndicator.id = loginWindow.id+'_waitIndicator';
	xZIndex(loginWindow.waitIndicator, loginWindow.zIndex+20);
	xDisplay(loginWindow.waitIndicator, 'none');
	loginWindow.content_div.appendChild(loginWindow.waitIndicator);

	loginWindow.show();
	//xGetElementById('askFormName').focus();

	return false;
}