function id(id){
	return document.getElementById(id);
}

function tag(obj, tag){
	return obj.getElementsByTagName(tag);	
}

function changeLanguage(obj, path){
	document.location.href = '/' + obj.value + '/' + path;	
}

function findX(obj){
	var curleft = 0;
	if(obj.offsetParent){
		while(1){
			curleft += obj.offsetLeft;
			if(!obj.offsetParent){
				break;
			}
			obj = obj.offsetParent;
		}
	} else if(obj.x){
	    curleft += obj.x;
	}
	return curleft;
}

function findY(obj){
    var curtop = 0;
    if(obj.offsetParent){
        while(1){
          	curtop += obj.offsetTop;
          	if(!obj.offsetParent){
            	break;
        	}
          	obj = obj.offsetParent;
        }
    } else if(obj.y){
        curtop += obj.y;
    }
    return curtop;
}

function submenu(obj, mode){	
	var ml = -80;
	var ul = tag(obj, 'UL');	
	var a = tag(obj, 'A');
	var display = mode == 'over' ? 'inline' : 'none';
	var bg = mode == 'over' ? 'url(../images/graphics/arrow.png) no-repeat center bottom' : 'none';
	ul[0].style.display = display;
	a[0].style.background = bg;
	if(display == 'block'){
		width(ul[0]);
		ul[0].style.margin = '30px 0px 0px '+ml+'px';		
		var x = parseInt(findX(ul[0]));
		var w = parseInt(ul[0].offsetWidth);
		var r = parseInt(x + w);
		if(r > parseInt(document.body.scrollWidth)){
			var dif = r - parseInt(document.body.scrollWidth);			
			dif = ml - dif;
			ul[0].style.margin = '30px 0px 0px '+dif+'px';						
		}
	}
}

function width(ul){
	var li = tag(ul, 'LI');
	var w = 22;
	for(i=0; i<li.length; i++){
		w += parseInt(li[i].offsetWidth);
	}
	ul.style.width = w + 'px';
}

function setStep(mode){
	if(mode == 'send'){
		id('step').value = 'send';	
	} else {
		id('step').value = 'back';	
	}
	id('step').form.submit();
}

function resizeBody(){
	var headerHeight = parseInt(id('header').offsetHeight);
	var footerHeight = parseInt(id('footer').offsetHeight);
	var windowHeight = parseInt(document.body.clientHeight);
	var dif = parseInt(windowHeight - (headerHeight + footerHeight)) -1;
	id('body').style.height = dif + 'px';	
	var bodyHeight;
	var q = 0;
	while(parseInt(document.body.clientHeight) < parseInt(document.body.scrollHeight) && q < 1000){
		q++;
		bodyHeight = parseInt(id('body').offsetHeight);
		bodyHeight--;
		id('body').style.height = bodyHeight + 'px';
	}
}

window.onload = function(){
//	resizeBody();
}