var reg_url = '';
var rest_url = '';
function reg_block_init(){
	if(document.getElementById('reg_link1') && document.getElementById('reg_block')){
		reg_url = document.getElementById('reg_link1').href;
		document.getElementById('reg_link1').onclick = function(){reg_block_show(); return !frames_test();};
		if(document.getElementById('reg_link2')) document.getElementById('reg_link2').onclick = function(){auth_block_hide(); reg_block_show(); return !frames_test();};
	}
	if(document.getElementById('rest_link1') && document.getElementById('reg_block')){
		rest_url = document.getElementById('rest_link1').href;
		document.getElementById('rest_link1').onclick = function(){rest_block_show(); return !frames_test();};
		if(document.getElementById('rest_link2')) document.getElementById('rest_link2').onclick = function(){auth_block_hide(); rest_block_show(); return !frames_test();};
	}
}

function reg_block_show(){
	if(!frames_test()) return;
	document.getElementById('reg_block').style.display = 'block';
	reg_loading(1);
	document.getElementById('ajax_frame').src = reg_url + '?mode=1&hash=' + Math.random();
}

function rest_block_show(){
	if(!frames_test()) return;
	document.getElementById('reg_block').style.display = 'block';
	reg_loading(1);
	document.getElementById('ajax_frame').src = rest_url + '?mode=1&hash=' + Math.random();
}

function reg_loading(n){
	if(n == 0){
		// загрузка стоп
		document.getElementById('reg_block_loading').style.display = 'none';
		document.getElementById('reg_block_content').style.display = 'block';
    }else{
    	// загрузка старт
		document.getElementById('reg_block_loading').style.display = 'block';
		document.getElementById('reg_block_content').style.display = 'none';
		document.getElementById('reg_block_content').innerHTML = '';
    }
}

function reg_block_hide(){
	document.getElementById('reg_block').style.display = 'none';
}

function auth_block_hide(){
	document.getElementById('auth_block').style.display = 'none';
}

add_handler(window, 'load', function(){reg_block_init()});







// загрузка списка регионов для текущей страны
function load_regions_list(c_id){
	set_select_options(document.getElementById('region'), '0::Загрузка...');
	ajax_lookup('/LIBRARY/register/ajax/regions.php?country=' + c_id, show_regions_list)
}

function show_regions_list(res){
	var init = document.getElementById('region_init').value;
	set_select_options(document.getElementById('region'), res, init);
    load_cities_list(document.getElementById('region').value);
}

// загрузка списка городов для текущего региона
function load_cities_list(r_id){
	set_select_options(document.getElementById('city'), '0::Загрузка...');
	ajax_lookup('/LIBRARY/register/ajax/cities.php?region=' + r_id, show_cities_list)
}

function show_cities_list(res){
	var init = document.getElementById('city_init').value;
	set_select_options(document.getElementById('city'), res, init);
}