///// COMMON BEG ///////
function get(id){
return document.getElementById(id);
}
function aaa(x){
alert(x);
}
function b(x){
alert(x);
}
function sum(x){
var s=0;
for (var i in x){
	if (x[i]) {s+=x[i]};
	}
return s;
}
function aa_hash(hashh,mod){
var d='\n';
if (mod) {d=mod};
var rep='';
var k;
for (k in hashh) rep+=k + "':'" + hashh[k]+d;
return rep;
}
function aa_array(arrayy,mod){
var d='\n';
if (mod) {d=mod};
var rep='';
var k;
for (k in arrayy) rep+=k + "->" + arrayy[k]+d;
return rep;
}
function aa(arr,mod){
alert(aa_array(arr,mod));
}
function ah(arr,mod){
alert(aa_hash(arr,mod));
}
function show(x,st){
if (st){
	get(x).style.display=st;
	}else{
	get(x).style.display="inline";
	}
}
function hide(x){
get(x).style.display="none";
}
function show_hide(x){
if (get(x).style.display=="none"){
	get(x).style.display="inline";
	}else{
	get(x).style.display="none";
	}
}
function checkform(form_name,fields,note){
var nnote='Заполните необходимые поля!';
if (note) {nnote=note};
var e=document.forms[form_name].elements;
for (el in fields){
	if (!e[fields[el]].value) {alert(nnote);return (false);}
	}
return (true);
}
function fill_form(f){
//FOR: debug
//GET: form
//USE: <input type=button value='Fill form' onclick=fill_form(this.form)>
var e=f.elements;
var i=0;
while (e[i]){
	if ((e[i].type=='text')||(e[i].type=='textarea')){
		e[i].value=e[i].name;
		}
	i++;
	}
}
///// COMMON END ///////
///// VOLK BEG   ///////
function img_change(id){
// USE: <img src=img/logo_01.jpg id='img_1' onclick='img_change("logo_01.jpg")'>
var img_0=get('img_0');
var it=get(id);
img_0.src=img_0.src.replace(/[^/]+$/,id);
var ch=it.parentElement.parentElement.children;
var init_bg='#f2f2f3'; // see CSS img_block td
for (var tr=0; tr<ch.length; tr++){
	var chh=ch[tr].children;
	for (var td=0; td<chh.length; td++){
		chh[td].style.backgroundColor=init_bg;
		}
	}
it.style.backgroundColor='#aaaaaa';
}
function minigal(id){
// USE: <img src=img/logo_01.jpg id='img_1' onclick='img_change("logo_01.jpg")'>
var img_0=get('img0');
var it=get(id);
img_0.src='/gal/b/'+id+'.jpg';
var ch=it.parentElement.parentElement.children;
var init_bg='#f2f2f3'; // see CSS img_block td
for (var tr=0; tr<ch.length; tr++){
	var chh=ch[tr].children;
	for (var td=0; td<chh.length; td++){
		chh[td].style.backgroundColor=init_bg;
		}
	}
it.style.backgroundColor='#aaaaaa';
}

///// VOLK  END  ///////
function get_ancestors(c,cp){
var p=[];
while (cp[c]) {
	p.push(cp[c]);
	c=cp[c];
	}
p.reverse();
return p; // # TODO: add error handling - many roots, no root etc
}
function check_zakaz_form(form_name){
var fields=['org','fio','tel'];
return checkform(form_name,fields);
}
function format_number(x) {
x=String(x);
x=x.replace(/\s*/g,'');
var y=x.split("");
y.reverse();
x=y.join("");
x=x.replace(/(...)/g,'$1 ');
y=x.split("");
y.reverse();
x=y.join("");
x=x.replace(/^ /,'');
return x;
}
function format_num(x) {return format_number(x)}
function num(a,b){
return a - b;
}
function max(b){
var a=b;
a.sort(num);
return a[a.length-1];
}
function min(b){
var a=b;
a.sort(num);
return a[0];
}
function sq(x){
return x*x;
}


