// начальные переменные
var modules_array=new Array;
modules_array[0]='barter';
modules_array[1]='board';
modules_array[2]='company';
modules_array[3]='news';
modules_array[4]='press';
modules_array[5]='price';
modules_array[6]='present';
modules_array[7]='tender';

fadeOpacity.addRule('oR1', 0, 1, 30);

function view_form(typeform){
	document.getElementById(typeform).style.display='block';
}

function close_form(typeform){
	document.getElementById(typeform).style.display='none';
}

function faq_error(info){
	var args='';
	for (i=0;i<info.length;i++){ args+=info[i]+'/'; }
	document.getElementById('erroriframe').src='/faq/'+args+'error.htm';
	view_form('error_block');
}

function popup(id, event, width, orientation){
  if (!event) event=window.event;
  var lay = document.getElementById("popup"+id);
  lay.style.display = 'block';
  lay.style.top=(event.clientY+document.body.scrollTop)+20;
  position_x = event.clientX
  if (orientation == 'left') position_x = event.clientX - width;
  lay.style.left=(position_x);
}

function hide(id){
  var lay = document.getElementById("popup"+id);
  lay.style.display = 'none';
}

function loaderimg(field){
msg='<img src=/images/ajax/loader.gif width=16 height=16>';
document.getElementById(field).innerHTML = msg;
}

function loadertext(field){
msg='идёт обработка запроса ...';
document.getElementById(field).innerHTML = msg;
}


function formauth_repass(type){
var form_auth='<form name="form_auth_repass" action="/users/auth.htm" method="post" onsubmit="if(this.login_auth.value.length<1 || this.password_auth.value.length<1) { alert("Укажите Ваш Логин и Пароль"); return false; } else {return true;}"><table cellpadding=1 cellspacing=1 border=0 align="center"><tr><td align=right><b>Ваш Логин : </b></td><td align=left>&nbsp;<input type="text" name="login_auth" size=26 maxlength=16 style="width:180px;"></td></tr><tr><td align=right><b>Ваш Пароль : </b></td><td align=left>&nbsp;<input type="password" name="password_auth" value="" size=26 maxlength=8 style="width:180px;"></td></tr><tr><td></td><td><input type=checkbox name="remember_auth" id="remember_auth">&nbsp;<label for="remember_auth">- запомнить меня</label></td></tr><tr><td colspan=2 align="center"><bR><input type="submit" value="войти"></td></tr></table></form><br><p align="right" style="margin-bottom: 5px;margin-right: 10px; padding: 0px;"><a href="javascript:formauth_repass(\'pass\');"><b>Забыли Ваш пароль ?</b></a></p><br>';
var form_repass='<form name="form_auth_repass" action="/users/repass.htm" method="post"><table cellpadding=1 cellspacing=1 border=0 align="center"><tr><td colspan=2>Уажите Ваш регистрационный E-mail.</td></tr><tr><td align=right><b>E-mail : </b></td><td align=left>&nbsp;<input type="text" name="email_repass" size=26 maxlength=250 style="width:180px;"></td></tr><tr><td colspan=2 align="center"><bR><input type="button" value="восстановить пароль" onclick="repass_action();"></td></tr></table></form><br><br><p align="right" style="margin-bottom: 5px;margin-right: 10px; padding: 0px;"><a href="javascript:formauth_repass(\'auth\');"><b>Форма авторизации</b></a></p><br>';
if (type == 'pass') { document.getElementById('content_forms_for_authpass').innerHTML = form_repass; }
if (type == 'auth') { document.getElementById('content_forms_for_authpass').innerHTML = form_auth; }
}

function repass_action(){
	var email = document.form_auth_repass.email_repass.value;
	if (!(/[^@]+@[^@]+/.test(email))) {
		alert ('Уажите E-mail !');
		return false;
	}
	document.form_auth_repass.submit();
}

function control_field_message(msg,type,field){
	var name_field = "result_" + field;
	if (type == 'error') {
		document.getElementById(field).style.backgroundColor='#ff5753';
		document.getElementById(name_field).style.fontWeight='bold';
		document.getElementById(name_field).style.fontSize='7pt';
		document.getElementById(name_field).style.color='#FF0000';
		//document.getElementById("button_send").disabled=true;
	}

	if (type == 'reset') {
		document.getElementById(field).style.backgroundColor='';
		msg = '';
	}

	if (type == 'ok') {
		document.getElementById(field).style.backgroundColor='';
		document.getElementById(name_field).style.color='#528352';
		document.getElementById(name_field).style.fontWeight='bold';
		document.getElementById(name_field).style.fontSize='7pt';
		document.getElementById("button_send").disabled='';
	}

	document.getElementById(name_field).innerHTML = msg;
}


function control_field_ajax(field,field_value){
	var container_ajax='/modules/users/users.ajax.php';
	var field_data=field;
	if (field == 'captcha') {
	var container_ajax='/modules/captcha/captcha.ajax.php';
	var field = document.getElementById('captcha_key');
	}
	JsHttpRequest.query( container_ajax, {'field' : field, 'field_value' : field_value },
 	function(result, errors) {
	document.getElementById('debug').innerHTML = errors;
	control_field_message(result["msg"],result["type"],field_data);
		if (result["type"] == 'ok' ) return true;
		if (result["type"] == 'error' ) {
		document.getElementById("button_send").disabled=true;
		return false;
		}
	}
	,true);
}

function panel_display(object){
if (document.getElementById(object).style.display == 'none'){
document.getElementById(object).style.display = 'block';
fadeOpacity(object, 'oR1');
}
}

function panel_display_none(object){
if (document.getElementById(object).style.display == 'block'){
	fadeOpacity.back(object);
	document.getElementById(object).style.display = 'none';
	}
}

function viewsub(id,prefix){
		var block_div = prefix+id;
		var block_img = prefix+'i'+id;
			control=document.getElementById(block_div).style.display;
				if (control == 'block'){
					document.getElementById(block_div).style.display='none';
					document.getElementById(block_img).src='/images/catalogue/plus.gif';
				} else {
					document.getElementById(block_div).style.display='block';
					document.getElementById(block_img).src='/images/catalogue/minus.gif';
				}

		}

function remove_option(obj){for (i=0; i < obj.options.length; i++){obj.options[i] = null;} if (obj.options.length>1) {remove_option(obj)} }

function go_url(url){
var t=window.open(url);
t.focus;
}
