function go_back () {
	if (window.his_arr) {
		window.his_arr.pop();
		writeContent(window.his_arr[window.his_arr.length - 1]);
	}
	return false;
}
function showHide (cid) {
	for (var e in document.getElementsByTagName('div')) {
		if (!document.getElementsByTagName('div')[e].id)
			continue;
		if (document.getElementsByTagName('div')[e].id.indexOf('kat_') != -1) {
			if (document.getElementsByTagName('div')[e].alt != 'main')
				document.getElementsByTagName('div')[e].style.display = 'none';
		}
	}
	obj = document.getElementById('kat_' + cid);
	obj.style.display = (obj.style.display == 'none' ? 'block' : 'none');
	while (obj.id.indexOf('kat_') != -1) {
		obj.style.display = 'block';
		obj = obj.parentNode; 
	}
	
	document.getElementById('left_sub').style.height = '';
	
	matching_columns();
	return false; 
}

function match_columns (c1, c2) {
	var height1=document.getElementById(c1).offsetHeight;
	var height2=document.getElementById(c2).offsetHeight;
	if ((height1 - document.getElementById('pr_head').offsetHeight)> height2) {
		document.getElementById(c2).style.height= (height1 - document.getElementById('pr_head').offsetHeight) +'px';
	} else {
		document.getElementById(c1).style.height=height2+document.getElementById('pr_head').offsetHeight+'px';
	}
	matching_columns();
}

function matching_columns() {
	if (document.getElementById('left_sub')) {
		var height1 = document.getElementById('left_sub').offsetHeight;
	} 
	else if (document.getElementById('left')) {
		var height1 = document.getElementById('left').offsetHeight;
	}
			
	if (document.getElementById('pr_head')) {
		var height2 = document.getElementById('pr_head').offsetHeight + document.getElementById('pr_con').offsetHeight;
	}
	else {
		if (document.getElementById('prod_content')) {
			var height2= 0;
		} else if(document.getElementById('right')) {
			var height2 = document.getElementById('right').offsetHeight;
		}	
	}
	if (!height1)
		height1 = 0;
	if (!height2)
		height2 = 0		
	if (document.getElementById('news_right')) { 
		h_r = document.getElementById('news_right').offsetHeight;
		h_r2_1 = document.getElementById('news_promo_title').offsetHeight; 
		h_r2_2 = document.getElementById('news_promo_content').offsetHeight;
		h_n = document.getElementById('news_newsletter').offsetHeight; 
		h_h = document.getElementById('hasloDniaBox').offsetHeight; 
		h_c = document.getElementById('news_content').offsetHeight;  
		var_1 = h_h + h_c;
		var_2 =  h_r + h_r2_1 + h_r2_2 + h_n;
		//alert (var_1 + ' = '+ var_2);
		if (var_1 > var_2) {
			n_h = ((h_h + h_c) - (h_r + h_n + h_r2_1));
			//alert(n_h);
			document.getElementById('news_promo_content').style.height=n_h+'px';
			//alert(document.getElementById('news_right2').style.height);
		}
	}
	if (height1 > height2) {
		document.getElementById('right').style.height=height1+'px';
		if (document.getElementById('left_sub'))
			document.getElementById('left').style.height=height1+'px';
		
			
	} else {
		if (document.getElementById('left_sub'))
			document.getElementById('left_sub').style.height=height2+'px';
		if (document.getElementById('pr_head')) {
			document.getElementById('right').style.height=height2+'px';
		}
		
		if(document.getElementById('left')) {
			document.getElementById('left').style.height=height2+'px';
		}
	}
}

function showProd (pid) {
	if (!pid) {
		return;
	}
	cookie_lang = readCookie('id_lang');
	
	document.getElementById('right').style.height = '';
	document.getElementById('right').name = pid;
	ajax_setHtml('prod_content', 'ajax=ajax', 'index.php?area=' + cookie_lang +'&p=product&action=showdetails&only_prod=1&id=' + pid);
	return;
	
}

function showCat (cid) {
	if (!cid)
		return;
	if (cid == 18)
		cid = '18ws';
	obj = document.getElementById('kat_'+ cid);
	
	if (cid == 18) {
		obj.style.display = 'block';
		return;
	}
	while (obj.id.indexOf('kat_') != -1) {
		obj.style.display = 'block';
		obj = obj.parentNode; 
	}
	return;
}

function showShops (provid) {
	ajax_setHtml('right', 'ajax=ajax', 'index.php?area=1&p=distribution&ajx=1&province=' + provid);

	getObj('descr_div').innerHTML = 'Wybierz sklep/hurtownię z prawej strony aby wyświetlić szczegóły.';
}
function showShops2 (provid) {
	ajax_setHtml('right', 'ajax=ajax', 'index.php?area=2&p=distribution&ajx=1&province=' + provid);
}
function showShops3 (provid) {
	ajax_setHtml('right', 'ajax=ajax', 'index.php?area=3&p=distribution&ajx=1&province=' + provid);
}
// opis do sklepu
function showDescr(distid,provid,area) {
	ajax_setHtml('descr_div', 
	             'ajax=ajax',
				 'index.php?p=distribution&ajx2=1&ajx=1&distid=' 
				 + distid +'&province=' + provid + '&area=' + area);
}
