
function showDistricts(event) {
	if (event) e = event;
    else e = window.event;
    
    var x; 
    var y;
    
    if (e.pageX || e.pageY) { 
        x = e.pageX;
        y = e.pageY;
    } else {
        x = e.x;
        y = e.clientY + (document.documentElement.scrollTop ?
                            document.documentElement.scrollTop :
                            document.body.scrollTop);
    }
    
	var select = document.createElement("select");
	var option = null;
	
	var div = document.getElementById('selectDistr');
	div.style.left = 25+"px"
	div.style.top  = (y+20)+"px";
	if (div.style.display == 'none') div.style.display = 'block';
	else div.style.display = 'none';
}

function selectLocation(location){
	setCookieReklama('distr',location);
	var date = new Date();
	var newurl = window.location.href;
	newurl = newurl.replace(/tt=\d*/,'');
	if(newurl.match(/\?/)){
		if(newurl.substr(newurl.length-1) == '?' || 
					newurl.substr(newurl.length-1) == '&') 
			newurl += "tt="+date.getTime();
		else 
			newurl += "&tt="+date.getTime();
	}else 
		newurl += "?tt="+date.getTime();
	if(document.MoveForm)
		NewMoveList('table.html');
	else
		window.location.reload();
}

function selectDistrict(e,obj) {
	var div = document.getElementById('selectDistr');
	var div2 = document.getElementById('distrValue');
	var value = obj.id.substr(6);
	setCookieReklama('distr',value);
	div2.innerHTML =  obj.innerHTML;
	div.style.display = 'none';
	var date = new Date();
	var newurl = window.location.href;
	newurl = newurl.replace(/tt=\d*/,'');
	if (newurl.match(/\?/)) {
		if (newurl.substr(newurl.length-1) == '?' || 
		newurl.substr(newurl.length-1) == '&') newurl += "tt="+date.getTime();
		else newurl += "&tt="+date.getTime();
	}else newurl += "?tt="+date.getTime();
	if (document.MoveForm) {
		NewMoveList('table.html');
	} else window.location.href = newurl;
}

function getCookieReklama(cookieName) {
	var cookieValue = document.cookie;//alert(cookieValue);
	var cookieStartsAt = cookieValue.indexOf(" "+cookieName+"=");
			
	if (cookieStartsAt == -1) 
		cookieStartsAt = cookieValue.indexOf(cookieName+"=");
	if (cookieStartsAt == -1)
		cookieValue = null;
	else {
		cookieStartsAt = cookieValue.indexOf("=",cookieStartsAt)+1;
		var cookieEndsAt = cookieValue.indexOf(";", cookieStartsAt);
		if (cookieEndsAt == -1)
		 cookieEndsAt = cookieValue.length;
		 cookieValue = unescape(cookieValue.substring(cookieStartsAt,cookieEndsAt));
	} //alert(cookieName+" "+cookieValue);
	return cookieValue;
}
function setCookieReklama(cookieName, cookieValue, cookiePath, cookieExpires) {
		cookieValue = escape(cookieValue);
		if (cookieExpires == "") {
			var nowDate = new Date();
			nowDate.setDate(nowDate.getDate()+365);
			cookieExpires = nowDate.toGMTString();
		}
		if (cookiePath == "" || cookiePath == "undefined" || cookiePath == null) cookiePath = "/";
		cookiePath = ";Path="+cookiePath; //alert(cookieName+"="+cookieValue+". Expires "+cookieExpires+". Path "+cookiePath);
		document.cookie = cookieName+"="+cookieValue+cookiePath;
}

function goUrl_copy(url,mode,params) {
	if (!mode) mode = "self";
	if (!params) params = '';
	
	if (mode=='self') document.location.href = url;
	else  window.open(url,'_blank',params);
	
	return false;
}

function updateSearchGeo(event) {
	var e = (event ? event : window.event);
	var target = e.srcElement;
	
	if (e.target) target = e.target;
	else if (e.srcElement) target = e.srcElement;
	if (target.nodeType == 3) // defeat Safari bug
	target = target.parentNode;
	
	updateSearchGeo_(target);
}

function updateSearchGeo_(select) {
	var level = parseInt(select.id.substr(select.id.length-1));
	var curGeo = select.value;// alert(select.id.substr(select.id.length-1));
	if (curGeo>0) {
		document.getElementById('geokods').value=curGeo;
		var geoTree = geoPlace[curGeo];

		var newSelect = document.createElement('select');
		newSelect.name = "geoSelect"+(level+1);
		newSelect.id = "geoSelect"+(level+1);
		newSelect.onchange = updateSearchGeo;

		var option = document.createElement('option');
		option.value=0;
		option.innerHTML = CHOOSE_GEO;
		newSelect.appendChild(option);
		
		var added = 0;			
		for (var key in geoTree) {
			var place = geoTree[key];
			if (place['kods']>0) {
				var option = document.createElement('option');
				option.value=place['kods'];
				option.innerHTML = place['title'];
				newSelect.appendChild(option);
				added++;
			}
		}
		
		if (added) {
			var span = document.getElementById('geospan'+(level+1));
			span.innerHTML = '';
			span.appendChild(newSelect);
			span.style.display = 'inline';
			document.getElementById('geoimg'+(level+1)).style.display = 'inline';
		}
	} else level--;
	for (var j=level+2; j<4; j++) {
		document.getElementById('geospan'+j).innerHTML = '';
		document.getElementById('geospan'+j).style.display = 'none';
		document.getElementById('geoimg'+j).style.display = 'none';
	}
}