loaded_profiles = new Array;

function highlight_on (target, style) {
	document.getElementById("area_"+target).style['backgroundImage']="url(/img/"+(style=="striped" ? "area_striped" : "area_striped")+"/"+target+".png)";
	document.getElementById("area_name_"+target).className="selected";
};
function highlight_off (target) {
	document.getElementById("area_"+target).style['backgroundImage']="none";
	document.getElementById("area_name_"+target).className="";
	highlight_selected("on");
};
function highlight_selected (mod) {
	for (var i = 1; i <= criteria_ids.length; i++) {
		document.getElementById("criteria-"+criteria_ids[i-1]).checked = false;
	};
	if (mod == "on") {
		for (var i = 1; i <= highlight_area_ids.length; i++) {
			highlight_on(highlight_area_ids[i-1]);
		};
	} else {
		highlight_area_ids = [];
		for (var i = 1; i <= area_ids.length; i++) {
			highlight_off(area_ids[i-1]);
		};
	};
};
function check_criterias () {
	document.getElementById("loading").style.display = "block";
	var data = "";
	var comma = "";
	for (var i = 1; i <= criteria_ids.length; i++) {
		data = data + comma + criteria_ids[i-1] + ":" + document.getElementById("criteria-"+criteria_ids[i-1]).checked;
		comma = ",";
	};
	highlight_selected("off");
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			document.getElementById("loading").style.display = "none";
			highlight_area_ids = (req.responseJS.data.split (/_/));
			if (highlight_area_ids.length > 0) {highlight_selected("on")};
		}
	}
	req.open("GET", '/cgi-bin/match.pl', true);
	req.send( { "data" : data } );
};
function showPageOfProfile (target) {
	if (loaded_profiles[target]) {
		document.getElementById("profile_content").innerHTML = loaded_profiles[target];
		document.getElementById("page_of_map").style.display = "none";
		document.getElementById("page_of_profile").style.display = "block";
	} else {
		document.getElementById("loading").style.display = "block";
		var req = new JsHttpRequest();
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				document.getElementById("loading").style.display = "none";
				loaded_profiles[target] = req.responseJS.data;
				document.getElementById("profile_content").innerHTML = loaded_profiles[target];
				document.getElementById("page_of_map").style.display = "none";
       	        		document.getElementById("page_of_profile").style.display = "block";
			}
		}
		req.open("GET", '/cgi-bin/descr.pl', true);
		req.send( { "target" : target } );
	};
};
function hidePageOfProfile () {
      
     
     document.getElementById("page_of_map").style.display = "block";
     document.getElementById("page_of_profile").style.display = "none";
  
      
        

			
};
function getBounds(element) {
	var left = element.offsetLeft;
	var top = element.offsetTop;
	for (var parent = element.offsetParent; parent; parent = parent.offsetParent) {
		left += parent.offsetLeft;
		top += parent.offsetTop;
	}
	return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
};
function on_load() {
var db = document.getElementById("body_id");
var wr = document.getElementById("wrapper");
var bounds = getBounds(db);
wr.style.left = (bounds.width > 1002 ? Math.floor((bounds.width - 1000) / 2)+"px" : "0");
wr.style.top = "5px";
};

