var currentZone = "" + document.location + "";
if (currentZone.indexOf('?zone=') != -1) {
	currentZone = getParameter("zone"); } 
else {
	currentZone = 0;
}

//Angivet vilken zon som har vilken underzon, 0 = ingen underzon, -1 = är en underzon
var subZones = new Array;
subZones[1] = 0;
subZones[2] = 3;
subZones[3] = -1;

//Angivet vilken zon som har vilken typ av varning, 0 = ingen varning, 1 = röd, 2 = gul, 9 = grön
var zoneWarnings = new Array;
zoneWarnings[1] = 0;
zoneWarnings[2] = 0;
zoneWarnings[3] = 0;

var areaHome = new Array;
areaHome[30] = 2;
areaHome[31] = 2;
areaHome[33] = 2;
areaHome[44] = 3;
areaHome[99] = 3;
areaHome[49] = 3;

var setWarnings = new Array;
var w = 362;
var h = 489;
var loopHtml = "";

function displayWarningAreas(theId, theZone, theCode, macFix) {
	var aHtml = "";
	var gifId = theId;
	if (gifId > 99 && gifId < 200) gifId -= 100;
	else if (gifId > 199 && gifId < 300) gifId -= 200;
	else if (gifId > 299) gifId -= 300;
	var aCode = theCode;
	if (theCode > 0 && theCode < 4) theCode = "red";
	else if (theCode == 8) theCode = "yellow";
	else if (theCode == 9) theCode = "green";

	if (theZone < 0) { //Varning loopade områden
		if (areaHome[theId] == currentZone) {
			if (aCode < setWarnings[gifId] || setWarnings[gifId] == null) {
				loopHtml += "<span class='absolute'" + macFix + "><img src='areas/malarenergi_" + theCode + theId + ".gif' width='" + w + "' height='" + h + "' alt='' border='1'></span>";
				setWarnings[gifId] = aCode;
			}
		}
		var theLoopArray = loopAreas[theId];
		var loopId;
		for (data in theLoopArray) {
			loopId = theLoopArray[data];
			if (loopId > 99 && loopId < 200) loopId -= 100;
			else if (loopId > 199) loopId -= 200;

			if (getZone(theLoopArray[data]) == currentZone || areaHome[loopId] == currentZone) {
				if (aCode < setWarnings[theLoopArray[data]] || setWarnings[theLoopArray[data]] == null) {
					loopHtml += "<span class='absolute'" + macFix + "><img src='areas/malarenergi_" + theCode + theLoopArray[data] + ".gif' width='" + w + "' height='" + h + "' alt='' border='1'></span>";
					setWarnings[loopId] = aCode;
				}
			}
		}
		return loopHtml;
	}
	else { //Vanliga varningar
		aHtml = "";
		if (theZone == currentZone) {
			if (aCode < setWarnings[theId] || setWarnings[theId] == null) {
				aHtml += "<span class='absolute'" + macFix + "><img src='areas/malarenergi_" + theCode + gifId + ".gif' width='" + w + "' height='" + h + "' alt='' border='1'></span>";
				return aHtml;
			}
		}
		else {
			return "";
		}
	}
}

function displayWarningZones(theZone, macFix, theImgMap, theCode, loopId) {
	var aHtml = "";
	var warningOk = false;
	var warningColor = "red";
	var tempZone = theZone;
	if (theCode == 3 || theCode == 2) theCode = 1;

	if (tempZone == 3 && currentZone == 0) tempZone = 2;

	if (theCode == 1 && zoneWarnings[tempZone] != 1) {
		zoneWarnings[tempZone] = 1;
		warningOk = true; }
	if (theCode == 8 && zoneWarnings[tempZone] != 1 && zoneWarnings[tempZone] != 8) {
		warningColor = "yellow";
		zoneWarnings[tempZone] = 8;
		warningOk = true; }
	if (theCode == 9 && zoneWarnings[tempZone] == 0) {
		warningColor = "green";
		zoneWarnings[tempZone] = 9;
		warningOk = true; }

	if (warningOk) {
		if (theZone > 0) {
			for (data in subZones) {
				if (subZones[data] == theZone) { 
					if (currentZone == 0) {
						aHtml += "<span class='absolute'" + macFix + "><img border='1' usemap='#" + theImgMap + "' src='areas/zone" + data + "_" + warningColor + ".gif' width='" + w + "' height='" + h + "' alt=''></span>";
						return aHtml; }
					else if (currentZone == data) {
						aHtml += "<span class='absolute'" + macFix + "><img border='1' usemap='#" + theImgMap + "' src='areas/zone" + subZones[data] + "_" +  warningColor + ".gif' width='" + w + "' height='" + h + "' alt=''></span>";
						return aHtml; }
				}
				else if (subZones[theZone] == 0 && currentZone == 0){ //Översiktsvarning
					aHtml += "<span class='absolute'" + macFix + "><img border='1' usemap='#" + theImgMap + "' src='areas/zone" + theZone + "_" +  warningColor + ".gif' width='" + w + "' height='" + h + "' alt=''></span>";
					return aHtml; }
				else if (subZones[theZone] > 0 && currentZone == 0){ //Översiktsvarning orsakad av underliggande zon
					aHtml += "<span class='absolute'" + macFix + "><img border='1' usemap='#" + theImgMap + "' src='areas/zone" + theZone + "_" +  warningColor + ".gif' width='" + w + "' height='" + h + "' alt=''></span>";
					return aHtml;
				}
			}
		}
	}
	return "";
}

