
var opened_m;
var opened_s;

function getObjectRef(id_submenu) {
    if(document.getElementById) return document.getElementById(id_submenu);
    else if(document.all) return document.all[id_submenu];
    else return null;
}

function display_block(id1,id2) {
    var elem_menu = id1+id2;
    var blockforopen;
    var blockforopen2;
    var blockforopen3;
    sub_id2 = 'sub'+id2;

    if (opened_m) {
        blockforopen = getObjectRef(opened_s);
        blockforopen.style.display = 'none';
        blockforopen3 = getObjectRef(opened_m);
        blockforopen3.style.color = '#f60';
        blockforopen3.style.background = 'none';
        blockforopen3.style.textDecoration = 'underline';
        blockforopen3.style.paddingLeft = '0';

        //blockforopen2 = getObjectRef(elem_menu);
        //blockforopen2.style.color = '#fff';
        //blockforopen2.style.background = 'none';
        //blockforopen2.style.textDecoration = 'underline';
    }

    blockforopen = getObjectRef(sub_id2);
    if (blockforopen) {
        blockforopen.style.display = 'block';
        opened_m = elem_menu;
        opened_s = sub_id2;
    }
    blockforopen2 = getObjectRef(elem_menu);
    blockforopen2.style.color = '#fff';
    blockforopen2.style.backgroundColor = '#390';
    blockforopen2.style.textDecoration = 'none';
    blockforopen2.style.paddingLeft = '10px';

}

function display_block_onload(id1,id2) {
    var elem_menu = id1+id2;
    var blockforopen;
    var blockforopen2;
    sub_id2 = 'sub'+id2;

    blockforopen = getObjectRef(sub_id2);
    blockforopen.style.display = 'block';
    opened_m = elem_menu;
    opened_s = sub_id2;

    blockforopen2 = getObjectRef(elem_menu);
    blockforopen2.style.color = '#069';
    blockforopen2.style.backgroundColor = '#e9f3fb';
    blockforopen2.style.textDecoration = 'none';

}

function update_form_adress(n,k){
	tmp_r=document.getElementById(n).sel_region;
	tmp_c=document.getElementById(n).sel_city;
	tmp_s=document.getElementById(n).sel_ship;
	cityname='';
	if(document.getElementById('inpcity').value!='Введите город, если нет в списке') cityname=document.getElementById('inpcity').value;

	region=tmp_r.options[tmp_r.selectedIndex].value;
	city=tmp_c.options[tmp_c.selectedIndex].value;
	method=tmp_s.options[tmp_s.selectedIndex].value;

	if(k==1){city='0';method='0';cityname='';}
	if(k==2){ method='0';}

	jQuery.post("/select_city.php",{region: region, city: city, method: method, count_tax:0, cityname: cityname  },
	function(result){
		a=document.getElementById("adress_shipping");
		a.innerHTML=result;
	 	return false;
	});
	jQuery.post("/select_city.php",{region: region, city: city, method: method,count_tax:1 },
	function(result){
		a=document.getElementById("shipping_total");
		a.innerHTML=result;
	 	return false;
	});
}

function update_form_shipping(n,region,city){
	tmp_s=document.getElementById(n).sel_ship;
	method=tmp_s.options[tmp_s.selectedIndex].value;
	jQuery.post("/select_city.php",{region: region, city: city, method: method,count_tax:1 },
	function(result){
		a=document.getElementById("shipping_total");
		a.innerHTML=result;
	 	return false;
	});
}


/*id="stateXML"*/
function form_city(n){
/*	tmp_r=document.getElementById(n).sel_region;
	tmp_c=document.getElementById(n).sel_city;
	tmp_s=document.getElementById(n).sel_ship;
	
	region=tmp_r.options[tmp_r.selectedIndex].value;
	city=tmp_c.options[tmp_c.selectedIndex].value;
	method=tmp_s.options[tmp_s.selectedIndex].value;

	if(k==1){city='';method='';}
	if(k==2){method='';} */
	region=0;
	city=0;
	method=0;
	jQuery.post("/select_city.php",{region: n, count_tax:2  },
	function(result){
		a=document.getElementById("stateXML");
		a.innerHTML=result;
	 	return false;
	});

	jQuery.post("/select_city.php",{region: n, count_tax:3 },
	function(result){
		a=document.getElementById("sel_city");
		a.innerHTML=result;
	 	return false;
	}); 
}


