 
		function setKommuner(typ, id) {
		var kommuner = "";
		if (typ == "lan") {
		    var kommun = "k" + lan[id][1];
			if(document.getElementById("l" + id).checked==true) {
			  addGlobalAreas(kommun);
			} else {
			  removeGlobalAreas(kommun);
			}
		} else if (typ == "landskap") {
		    var kommun = "k" + landskap[id][1];
			if(document.getElementById("ls" + id).checked==true) {
			  addGlobalAreas(kommun);
			} else {
			  removeGlobalAreas(kommun);
			}
		} else if (typ == "papers") {
		  kommuner = "";
		  for(var i = 1; i < tidning[id]['kommun'].length; i++) {
			  var kommun = "k" + tidning[id]['kommun'][i];
			  kommuner = kommuner + kommun + ",";
			  if(document.getElementById('paper' + id).checked == true) {
				 setcheck(kommun);
			  } else {
			     uncheck(kommun);
			  }
		  }
		  kommuner = kommuner.substr(0, (kommuner.length-1));
		  if(document.getElementById('paper' + id).checked == true) {
		    addLocation(kommuner);
		  } else {
		    removeLocation(kommuner);
		  }
		} else if (typ == "kommun") {
			if(document.getElementById("k" + id).checked==true) {
			  addGlobalAreas("k" + id);
			} else {
			  removeGlobalAreas("k" + id);
			}
		}
	}
	
		function setKommunerAndCampaign(typ, id, tid) {
           setKommuner(typ, id);
           delayGetCampaign(tid);
        }




// #################################################################################################################
		function addGlobalAreas(objName) { 
		    var foundlocation = "";
            // --------------------------------------------------------------------------------------------------------
			if (actualgeo == "lan") {
            // --------------------------------------------------------------------------------------------------------
			  for(i = 1; i < lan.length; i++) {
			    for(x = 1; x < lan[i].length; x++) {
				   if("k" + lan[i][x] == objName) {
				      foundlocation = i;
				   }
				}
			  }
			  var locations_to_set = "";
			  for(i = 1; i < lan[foundlocation].length; i++) {
				 if (document.getElementById("k" + lan[foundlocation][i]).checked == false) {
				   locations_to_set = locations_to_set + "k" + lan[foundlocation][i] + ",";
				   setcheck("k" + lan[foundlocation][i]);
				 }
			  }
			  locations_to_set = locations_to_set.substr(0, (locations_to_set.length-1));
			  addLocation(locations_to_set);
              setcheck("l" + foundlocation);
            // --------------------------------------------------------------------------------------------------------              
			} else if (actualgeo == "landskap") {
            // --------------------------------------------------------------------------------------------------------
			  for(i = 1; i < landskap.length; i++) {
			    for(x = 1; x < landskap[i].length; x++) {
				   if("k" + landskap[i][x] == objName) {
				      foundlocation = i;
				   }
				}
			  }
			  var locations_to_set = "";
			  for(i = 1; i < landskap[foundlocation].length; i++) {
				 if (document.getElementById("k" + landskap[foundlocation][i]).checked == false) {
				   locations_to_set = locations_to_set + "k" + landskap[foundlocation][i] + ",";
				   setcheck("k" + landskap[foundlocation][i]);
				 }
			  }
			  locations_to_set = locations_to_set.substr(0, (locations_to_set.length-1));
			  addLocation(locations_to_set);
              setcheck("ls" + foundlocation);
            // --------------------------------------------------------------------------------------------------------
			} else if (actualgeo == "kommuner") {
            // --------------------------------------------------------------------------------------------------------
              if (document.getElementById(objName).checked == false) {
             	  addLocation(objName);
                  setcheck(objName);
              }
            }
            
            // --------------------------------------------------------------------------------------------------------
            // Plocka fram tidningar:
			  setTimeout("getPapers(0)",600);
            // --------------------------------------------------------------------------------------------------------
         }
         
         
		function removeGlobalAreas(objName) { 
		    var foundlocation = "";
            // --------------------------------------------------------------------------------------------------------
			if (actualgeo == "lan") {
            // --------------------------------------------------------------------------------------------------------
			  for(i = 1; i < lan.length; i++) {
			    for(x = 1; x < lan[i].length; x++) {
				   if("k" + lan[i][x] == objName) {
				      foundlocation = i;
				   }
				}
			  }
			  for(i = 1; i < lan[foundlocation].length; i++) {
				 if (document.getElementById("k" + lan[foundlocation][i]).checked == true) {
				   removeLocation("k" + lan[foundlocation][i]);
				   uncheck("k" + lan[foundlocation][i]);
				 }
			  }
              uncheck("l" + foundlocation);
            // --------------------------------------------------------------------------------------------------------
			} else if (actualgeo == "landskap") {
            // --------------------------------------------------------------------------------------------------------
			  for(i = 1; i < landskap.length; i++) {
			    for(x = 1; x < landskap[i].length; x++) {
				   if("k" + landskap[i][x] == objName) {
				      foundlocation = i;
				   }
				}
			  }
			  for(i = 1; i < landskap[foundlocation].length; i++) {
				 if (document.getElementById("k" + landskap[foundlocation][i]).checked == true) {
				   removeLocation("k" + landskap[foundlocation][i]);
				   uncheck("k" + landskap[foundlocation][i]);
				 }
			  }
              uncheck("ls" + foundlocation);
            // --------------------------------------------------------------------------------------------------------
			} else if (actualgeo == "kommuner") {
            // --------------------------------------------------------------------------------------------------------
              if (document.getElementById(objName).checked == true) {
             	  removeLocation(objName);
                  uncheck(objName);
              }
			}
            // --------------------------------------------------------------------------------------------------------
            // Plocka fram tidningar;
			  setTimeout("getPapers(0)",600);
            // --------------------------------------------------------------------------------------------------------
         }
// #################################################################################################################
         
         
         
         
         
         
// #################################################################################################################
         // --------------------------------------------------------------------------------------------------------
         function addAllAreas() {
            document.selektering.areaevents.value="0";
            var addakommuner = "";
            var kommun = "";
            for(i = 1; i < lan.length; i++) {
              for(x = 1; x < lan[i].length; x++) {
                 kommun = "k" + lan[i][x] + ",";
              	 addakommuner = addakommuner + kommun;
                 setcheck("k" + lan[i][x]);
              }
            }
		    addakommuner = addakommuner.substr(0, (addakommuner.length-1));
            addLocation(addakommuner);
            setTimeout("resetAllAreas()", 900);
         }
         // --------------------------------------------------------------------------------------------------------
         function removeAllAreas(typ) {
            document.selektering.areaevents.value="0";
            var addakommuner = "";
            var kommun = "";
            for(i = 1; i < lan.length; i++) {
              for(x = 1; x < lan[i].length; x++) {
                 kommun = "k" + lan[i][x] + ",";
              	 addakommuner = addakommuner + kommun;
                 uncheck("k" + lan[i][x]);
              }
            }
		    addakommuner = addakommuner.substr(0, (addakommuner.length-1));
            removeLocation(addakommuner);
            setTimeout("resetAllAreas()", 900);
         }
         // --------------------------------------------------------------------------------------------------------
         function resetAllAreas() {
            document.selektering.areaevents.value="1";
            setTimeout("getPapers(0)", 100);
         }
         // --------------------------------------------------------------------------------------------------------
// #################################################################################################################







// #################################################################################################################
         // --------------------------------------------------------------------------------------------------------
         function addAllPapers() {
            document.selektering.areaevents.value="0";
            var addakommuner = "";
            var kommun = "";
            var aktuell_tidning = "0";
            for(i = 1; i < tidningar.length; i++) {

            if(document.getElementById('paper' + tidningar[i])) {
            if(document.getElementById('paper' + tidningar[i]).checked == true) {
            
              aktuell_tidning = tidningar[i];
              for(x = 1; x < tidning[aktuell_tidning]['kommun'].length; x++) {
                 kommun = "k" + tidning[aktuell_tidning]['kommun'][x] + ",";
              	 addakommuner = addakommuner + kommun;
                 setcheck("k" + tidning[aktuell_tidning]['kommun'][x]);
              }
              

            }
            }
            
            }
		    addakommuner = addakommuner.substr(0, (addakommuner.length-1));
            addLocation(addakommuner);
			document.selektering.areaevents.value = "1";
            delayGetCampaign('1200');
         }
         // --------------------------------------------------------------------------------------------------------
         function removeAllPapers() {
            document.selektering.areaevents.value="0";
            var addakommuner = "";
            var kommun = "";
            var aktuell_tidning = "0";
            for(i = 1; i < tidningar.length; i++) {
              aktuell_tidning = tidningar[i];
              if(document.getElementById('paper' + tidningar[i])) {
              if(document.getElementById('paper' + tidningar[i]).checked == false) {
            
              for(x = 1; x < tidning[aktuell_tidning]['kommun'].length; x++) {
                 kommun = "k" + tidning[aktuell_tidning]['kommun'][x] + ",";
              	 addakommuner = addakommuner + kommun;
                 uncheck("k" + tidning[aktuell_tidning]['kommun'][x]);
              }
              
              }
              }
            }
		    addakommuner = addakommuner.substr(0, (addakommuner.length-1));
            removeLocation(addakommuner);
			document.selektering.areaevents.value = "1";
            document.getElementById("summasummarum").innerHTML='Välj vart och i vilka tidningar du vill<br>annonsera i listorna till höger på sidan.';
         }
         // --------------------------------------------------------------------------------------------------------
// #################################################################################################################



         
// #################################################################################################################
         function delayGetCampaign(tid) {
			 document.getElementById("summasummarum").innerHTML='<img src="img/loading_bar.gif" alt="Laddar..." title="Laddar..." style="float: left; margin-right: 5px; width: 18px;"><p style="float: left;"><b>Laddar...</b><br>Beräknar kampanj. Vänligen vänta!</p><div style="clear: left;"></div>';
             setTimeout("getCampaign()", tid);
         }

         function selektera() {
			var tmp_loc = "";
			for (var i = 0; i < document.paperselect.elements.length; i++) { 
				var e = document.paperselect.elements[i]; 
				if ((e.name == 'papers[]') && (e.type == 'checkbox') && (e.checked == true)) { 
					tmp_loc = tmp_loc + e.value;
				}
			}
            if(tmp_loc.length > 1) {
	          delayGetCampaign('10');
            } else {
			  getPapers(0);
	          // delayGetCampaign('1200');
            }
         }
// #################################################################################################################




// #################################################################################################################
         // --------------------------------------------------------------------------------------------------------
         function setcheck(id) {
           document.getElementById(id).checked=true;
           switch(document.getElementById("tr" + id).className) {
             case "list1":
				document.getElementById("tr" + id).className="listx1";
                break;
             case "list2":
				document.getElementById("tr" + id).className="listx2";
                break;
           }
         }
         // --------------------------------------------------------------------------------------------------------
         function uncheck(id) {
           document.getElementById(id).checked=false;
           switch(document.getElementById("tr" + id).className) {
             case "listx1":
				document.getElementById("tr" + id).className="list1";
                break;
             case "listx2":
				document.getElementById("tr" + id).className="list2";
                break;
           }
         }
         // --------------------------------------------------------------------------------------------------------
// #################################################################################################################
