reg_user = function() {
	JsHttpRequest.query('libraries/reg.lib.php',
		{reg_user: 1,
			login: $('login').value,
			email: $('email').value,
			password: $('password').value,
			password2: $('password2').value,
			metro: $('metro').value,
			street: $('street').value,
			house_num: $('house_num').value,
			house_case: $('house_case').value,
			house_name: $('house_name').value,
			agree: $('agree').checked
		},
		function(result, error) {
			 $('login_error').innerHTML = '';
			 $('email_error').innerHTML = '';
			 $('password_error').innerHTML = '';
			 $('metro_error').innerHTML = '';
			 $('street_error').innerHTML = '';
			if (result.error && result.error.fields) {
				if (result.error.fields.login) { $('login_error').innerHTML = result.error.fields.login; }
				if (result.error.fields.email) { $('email_error').innerHTML = result.error.fields.email; }
				if (result.error.fields.password) { $('password_error').innerHTML = result.error.fields.password; }
				if (result.error.fields.metro) { $('metro_error').innerHTML = result.error.fields.metro; }
				if (result.error.fields.street) { $('street_error').innerHTML = result.error.fields.street; }
				if (result.error.fields.house) { $('street_error').innerHTML = result.error.fields.house; }
				if (result.error.fields.agree) { $('agree_error').innerHTML = result.error.fields.agree; }
			}
			if (result.ok == 'ok') {
				alert('Спасибо за регистрацию. Вам на email было выслано письмо со ссылкой активации');
				window.location.replace('login.php');
	
			}
		},
		true);
}





function my_search( tofld, type, value ) {

//    document.getElementById('debug').innerHTML = "...";

if ( value == '' ) return;

    document.getElementById(tofld).style.display = 'block';

    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		var oList = document.getElementById(tofld);
		oList.length = 0;

		for ( i=0; i < req.responseJS.length; i++ ){
			c = req.responseJS[i];
			oList.options[i] = new Option(c.name, c.id, false, false);
//			if ( c.id > 0 ) oList.options[i].style.background = '#eee';
		}
		if ( i < 5 && i > 1 )
			document.getElementById(tofld).size=i;
		else 
			document.getElementById(tofld).size=5;
//            document.getElementById('debug').innerHTML = "!!!";
        }
    }

    req.open( null, '/libraries/search.lib.php', true );
    req.send( { search: value, type: type } );

}


function my_search_change ( from, to ){
	from = document.getElementById(from);
	to = document.getElementById(to);
	to.value = from.options[from.selectedIndex].text;
}

function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 1082 ) {
//      alert("В это поле можно вводить только цифры." + charCode);
        return false;
    }
    return true;
} 

function hint(){
 var obj = this;

 var elem = document.createElement("DIV");
 document.body.appendChild(elem);
 var attr = document.createAttribute('id'); attr.value = 'hint'; elem.setAttributeNode(attr);
 obj.hint_container = elem;

 this.show = function(message) {

  obj.hint_container.innerHTML=message;

  document.onmousemove = function (e){

   var ie = document.all ? true : false;
   var x = ie ? document.body.scrollLeft + window.event.clientX : e.pageX;
   var y = ie ? document.body.scrollTop + window.event.clientY : e.pageY;

   obj.hint_container.style.left = document.body.clientWidth - x >= obj.hint_container.clientWidth ? x : x-obj.hint_container.clientWidth + 16 ;
   obj.hint_container.style.top = y+20; //document.body.clientHeight - y >= obj.hint_container.clientHeight ? y+20 : y-obj.hint_container.clientHeight - 16;
  }

  obj.hint_container.style.display='block';
 }

 this.hide = function() {
  obj.hint_container.innerHTML='';
  obj.hint_container.style.display='none';
 }

};



function list_forums( tofld, type ) {

//    document.getElementById('debug').innerHTML = "...";

    document.getElementById(tofld).style.display = 'block';

    var req = new JsHttpRequest();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
		var oList = document.getElementById(tofld);
		oList.length = 0;

		for ( i=0; i < req.responseJS.length; i++ ){
			c = req.responseJS[i];
			oList.options[i] = new Option(c.name, c.name, false, false);
//			if ( c.id > 0 ) oList.options[i].style.background = '#eee';
		}
//            document.getElementById('debug').innerHTML = "!!!";
        }
    }

    req.open( null, '/libraries/list_forums.lib.php', true );
    req.send( { type: type } );

}


function addfirm_my_search_change ( from, to, to2, town ){
	from = document.getElementById(from);
	to = document.getElementById(to);
	to2 = document.getElementById(to2);
	to.value = from.options[from.selectedIndex].text;
	to2.value = town+", "+from.options[from.selectedIndex].text;
}

