var markerGroups = { "zrp_ununi": [], "cid": [], "cid_dom": [], "cio": [], "cio_dom": [], "civilian": [], "civilian_dom": [], "other": [], "zna": [], "zna_multi_dom": [], "zpf_multi": [], "zpf_supp": [], "zpf_wv": [], "zpf_yth": [], "zrp_multi_dom": [], "zrp_riot": [], "zrp_uni": [], "death_rip": [], "mdc_yth": []};

var mapTypes = [];
        mapTypes.push(G_NORMAL_MAP);
        mapTypes.push(G_HYBRID_MAP);
        mapTypes.push(G_SATELLITE_MAP);

function load(doc,prov) {
	var map = document.getElementById("map-pev");
	if (GBrowserIsCompatible()) {
		var gmap = new GMap2(map,{mapTypes:mapTypes});
        gmap.addControl(new GLargeMapControl());
        gmap.addControl(new GMapTypeControl());

     var province = prov;

if (province == "Harare") {
        gmap.setCenter(new GLatLng(-17.81210982075392,31.053543090820312), 11);
}
else if (province == "Bulawayo") {
        gmap.setCenter(new GLatLng(-20.164254834336596,28.590545654296875), 12);
}
else if (province == "Mashonaland Central") {
        gmap.setCenter(new GLatLng(-16.846605106396304,31.2890625), 9);
}
else if (province == "Manicaland") {
        gmap.setCenter(new GLatLng(-18.693082160033928,32.31353759765625), 9);
}
else if (province == "Mashonaland East") {
        gmap.setCenter(new GLatLng(-17.106667613984445,32.178955078125), 9);
}
else if (province == "Mashonaland West") {
        gmap.setCenter(new GLatLng(-16.71775457647648,29.88006591796875), 9);
}
else if (province == "Masvingo") {
        gmap.setCenter(new GLatLng(-20.122997556207757,30.82763671875), 9);
}
else if (province == "Midlands") {
        gmap.setCenter(new GLatLng(-18.161510984517324,29.7509765625), 8);
}
else if (province == "Matabeleland North") {
        gmap.setCenter(new GLatLng(-19.160735484156245,28.2733154296875), 8);
}
else if (province == "Matabeleland South") {
        gmap.setCenter(new GLatLng(-20.802336592979042,29.2950439453125), 8);
}

else {
        gmap.setCenter(new GLatLng(-18.594188856740413,29.33349609375), 7);
    }

     }

	var jsonData = eval("(" + doc + ")");
	for (var i = 0; i < jsonData.markers.length; i++) {
		var marker = createMarker(jsonData.markers[i]);
		gmap.addOverlay(marker);
	}

	if (document.getElementById("death_rip").checked==false)
  	{
	  	toggleGroup('death_rip');
  	}
	if (document.getElementById("zrp_ununi").checked==false)
  	{
	  	toggleGroup('zrp_ununi');
  	}
  	if (document.getElementById("cid").checked==false)
  	{
	  	toggleGroup('cid');
  	}
  	if (document.getElementById("cio").checked==false)
  	{
	  	toggleGroup('cio');
  	}
  	if (document.getElementById("cid_dom").checked==false)
  	{
	  	toggleGroup('cid_dom');
  	}
  	if (document.getElementById("cio_dom").checked==false)
  	{
	  	toggleGroup('cio_dom');
  	}
  //	if (document.getElementById("civilian").checked==false)
 // 	{
//	  	toggleGroup('civilian');
 // 	}
 // 	if (document.getElementById("civilian_dom").checked==false)
//  	{
//	  	toggleGroup('civilian_dom');
//  	}
  	if (document.getElementById("other").checked==false)
  	{
	  	toggleGroup('other');
  	}
	if (document.getElementById("zna_multi_dom").checked==false)
  	{
	  	toggleGroup('zna_multi_dom');
  	}
  	if (document.getElementById("zna").checked==false)
  	{
	  	toggleGroup('zna');
  	}
  	if (document.getElementById("zpf_multi").checked==false)
  	{
	  toggleGroup('zpf_multi');
  	}
  	if (document.getElementById("zpf_supp").checked==false)
  	{
	  	toggleGroup('zpf_supp');
  	}
  	if (document.getElementById("zpf_wv").checked==false)
  	{
	  	toggleGroup('zpf_wv');
  	}
  	if (document.getElementById("zpf_yth").checked==false)
  	{
	  toggleGroup('zpf_yth');
  	}
  		if (document.getElementById("zrp_multi_dom").checked==false)
  	{
	  	toggleGroup('zrp_multi_dom');
  	}
  	if (document.getElementById("zrp_riot").checked==false)
  	{
	  	toggleGroup('zrp_riot');
  	}
  	if (document.getElementById("zrp_uni").checked==false)
  	{
	  toggleGroup('zrp_uni');
  	}
  	if (document.getElementById("mdc_yth").checked==false)
  	{
	  toggleGroup('mdc_yth');
  	}


  	var province_markers = [];
    var k = 0;

  	function createMarker(inp){

	    //alert(inp.variable);
	    if (inp.icon =='zrp_ununi')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zrp_ununi.png";
	   	}
	   	if (inp.icon =='cid')
	    {
		    var iconLink="/files/images/markers/postelection_icons/cid.png";
	   	}
	   	if (inp.icon =='cid_dom')
	    {
		    var iconLink="/files/images/markers/postelection_icons/cid_dom.png";
	   	}
	   	if (inp.icon =='cio')
	    {
		    var iconLink="/files/images/markers/postelection_icons/cio.png";
	   	}
	   	if (inp.icon =='cio_dom')
	    {
		    var iconLink="/files/images/markers/postelection_icons/cio_dom.png";
	   	}
	   	if (inp.icon =='civilian')
	    {
		    var iconLink="/files/images/markers/postelection_icons/civilian.png";
	   	}
	   	if (inp.icon =='civilian_dom')
	    {
		    var iconLink="/files/images/markers/postelection_icons/civilian_dom.png";
	   	}
	    if (inp.icon =='other')
	    {
		    var iconLink="/files/images/markers/postelection_icons/other.png";
	   	}
	   	if (inp.icon =='zna')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zna.png";
	   	}
	   	if (inp.icon =='zna_multi_dom')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zna_multi_dom.png";
	   	}
	   	if (inp.icon =='zpf_multi')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zpf_multi.png";
	   	}
	   	if (inp.icon =='zpf_supp')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zpf_supp.png";
	   	}
	   	if (inp.icon =='zpf_wv')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zpf_wv.png";
	   	}
	   	if (inp.icon =='zpf_yth')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zpf_yth.png";
	   	}
	   	if (inp.icon =='zrp_multi_dom')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zrp_multi_dom.png";
	   	}
	   	if (inp.icon =='zrp_riot')
	    {
		    var iconLink="/files/images/markers/postelection_icons/zrp_riot.png";
	   	}
	   	if (inp.icon =='zrp_uni')
	   	{
		   	var iconLink="/files/images/markers/postelection_icons/zrp_uni.png";
	   	}
	   	if (inp.icon =='death_rip')
	   	{
		   	var iconLink="/files/images/markers/postelection_icons/cross/cross.png";
		   	var shadow_type = "cross";
	   	}
	   	if (inp.icon =='mdc_yth')
	   	{
		   	var iconLink="/files/images/markers/postelection_icons/mdc_yth.png";
	   	}

	   	//PERPETRATORS//
	   	var violatorlist = "";
	   	var check_marker = 0;

		if (inp.ZanuPF_youth == 1){

			if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zanu PF Youth/Militia";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zanu PF Youth/Militia";
			   	}

			   	check_marker = 1;
		   	}

	   	if (inp.ZNA == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zimbabwe National Army";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zimbabwe National Army";
			   	}
			check_marker = 1;
		   	}

		if (inp.ZanuPF_war_vets == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zanu PF War Veterans";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zanu PF War Veterans";
			   	}
			check_marker = 1;
		   	}

		if (inp.ZanuPF_suporters == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zanu PF supporters";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zanu PF supporters";
			   	}
			check_marker = 1;
		   	}
		if (inp.ZRP_uniformed == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zimbabwe Republic Police (uniformed)";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zimbabwe Republic Police (uniformed)";
			   	}
			check_marker = 1;
		   	}
		if (inp.ZRP_plainclothes == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zimbabwe Republic Police (plainclothes)";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zimbabwe Republic Police (plainclothes)";
			   	}
			check_marker = 1;
		   	}
		if (inp.ZRP_riot == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Zimbabwe Republic Riot Police";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Zimbabwe Republic Riot Police";
			   	}
			check_marker = 1;
		   	}
		if (inp.CID == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Police CID";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Police CID";
			   	}
			check_marker = 1;
		   	}
		if (inp.CIO == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "CIO";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />CIO";
			   	}
			check_marker = 1;
		   	}
		if (inp.UZ_security == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "University of Zimbabwe security";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />University of Zimbabwe security";
			   	}
			check_marker = 1;
		   	}
		if (inp.Civilian == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Civilian";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Civilian";
			   	}
			check_marker = 1;
		   	}
		if (inp.other_role == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "Unknown violator";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />Unknown violator";
			   	}
			check_marker = 1;
		   	}

		if (inp.mdc_youth == 1){
	   		if( check_marker == 0) {
				   	violatorlist = violatorlist + "MDC youth";
			   	}
		   	else {
				   	violatorlist = violatorlist + "<br />MDC youth";
			   	}
			check_marker = 1;
		   	}

		//Injuries sustained //

		var injurylist = "";
	   	var check_marker_injury = 0;

		if (inp.Intimidated == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Intimidated";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Intimidated";
			   	}

			   	check_marker_injury = 1;
		   	}
		 if (inp.Assaulted_with_hands_feet == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Assaulted with hands and feet";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Assaulted with hands and feet";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Assaulted_with_weapon == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Assaulted with weapon";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Assaulted with weapon";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Threatened == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Threatened";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Threatened";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Arrested == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Arrested";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Arrested";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Detained == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Detained";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Detained";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Blindfolded == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Blindfolded";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Blindfolded";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Abducted == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Abducted";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Abducted";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Falanga == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Falanga";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Falanga";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Submerged == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Submerged";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Submerged";
			   	}

			   	check_marker_injury = 1;
		   	}

		   		if (inp.Strangled == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Strangled";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Strangled";
			   	}

			   	check_marker_injury = 1;
		   	}

		   		if (inp.Burnt == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Burnt";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Burnt";
			   	}

			   	check_marker_injury = 1;
		   	}

		   		if (inp.Hung == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Hung";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Hung";
			   	}

			   	check_marker_injury = 1;
		   	}

		   	if (inp.Tortured == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Tortured";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Tortured";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Death_threats == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Death_threats";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Death_threats";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.homeless == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Displaced";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Displaced";
			   	}

			   	check_marker_injury = 1;
		   	}
		   	if (inp.Theft_distruction_property == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Destruction of home and/or theft";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Destruction of home and/or theft";
			   	}

			   	check_marker_injury = 1;
		   	}

		   		if (inp.other == 1){

			if( check_marker_injury == 0) {
				   	injurylist = injurylist + "Other violation";
			   	}
		   	else {
				   	injurylist = injurylist + "<br />Other violation";
			   	}

			   	check_marker_injury = 1;
		   	}


		var marker = new GMarker(new GLatLng(inp.latitude,inp.longtitude),makeIcon(iconLink,shadow_type));
		if (inp.icon!=null)
		{
			var type = inp.icon;

			//alert(type);
			markerGroups[type].push(marker)
	    }

	    if(inp.province == "Harare") {
    		var mapLink="<a href=\"/files/images/harare-constit.gif\" rel=\"lightbox\" title=\"Harare: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/harare_popup.gif\"></a>";
		}

		if(inp.province == "Bulawayo") {
    		var mapLink="<a href=\"/files/images/Bulawayo-constit.gif\" rel=\"lightbox\" title=\"Bulawayo: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/bulawayo_popup.gif\"></a>";
		}
		if(inp.province == "Mashonaland Central") {
    		var mapLink="<a href=\"/files/images/Mashonaland Central-constit.gif\" rel=\"lightbox\" title=\"Mashonaland Central: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/mashcentral_popup.gif\"></a>";
		}
		if(inp.province == "Mashonaland East") {
    		var mapLink="<a href=\"/files/images/Mashonaland East-constit.gif\" rel=\"lightbox\" title=\"Mashonaland East: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/masheast_popup.gif\"></a>";
		}
		if(inp.province == "Mashonaland West") {
    		var mapLink="<a href=\"/files/images/Mashonaland West-constit.gif\" rel=\"lightbox\" title=\"Mashonaland West: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/mashwest_popup.gif\"></a>";
		}
		if(inp.province == "Manicaland") {
    		var mapLink="<a href=\"/files/images/Manicaland-constit.gif\" rel=\"lightbox\" title=\"Manicaland: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/manicaland_popup.gif\"></a>";
		}
		if(inp.province == "Midlands") {
    		var mapLink="<a href=\"/files/images/Midlands-constit.gif\" rel=\"lightbox\" title=\"Midlands: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/midlands_popup.gif\"></a>";
		}
		if(inp.province == "Masvingo") {
    		var mapLink="<a href=\"/files/images/Masvingo-constit.gif\" rel=\"lightbox\" title=\"Masvingo: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/masvingo_popup.gif\"></a>";
		}
		if(inp.province == "Matabeleland North") {
    		var mapLink="<a href=\"/files/images/Matabeleland North-constit.gif\" rel=\"lightbox\" title=\"Matabeleland North: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/matnorth_popup.gif\"></a>";
		}
		if(inp.province == "Matabeleland South") {
    		var mapLink="<a href=\"/files/images/Matabeleland South-constit.gif\" rel=\"lightbox\" title=\"Matabeleland South: Map showing constituencies and wards for elections on March 29th 2008.\" target=\"_blank\"><img src=\"/files/images/matsouth_popup.gif\"></a>";
		}

	 //  var violators = "";
	 //   if (inp.violators_name != ""){

	//	    violators = "<p><b>Named Violator(s):</b><br />" + inp.violators_name + "</p>";
	//    }

	    var mdc_am = "";
	    if (inp.MDCAM > 1){

		    mdc_am = "MDC AM: " + inp.MDCAM;
	    }


		//var issueLink="\"http://www.sokwanele.com/zew/zew_byissue.php?issues="+inp.issue_no+"\"";

		GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowTabsHtml([new GInfoWindowTab("Summary","<div class=\"gmap_popup_viol\"><h2>"+inp.province+"</h2><h3>"+inp.constit_name+"</h3><p><br /><b>Violator Group(s):</b><br />"+violatorlist+"</p><p><b>Violation details: </b><br />"+injurylist+"</p></div>"), new GInfoWindowTab("Election","<div class=\"gmap_popup_viol\"><h2>Constituency Results March 29th</h2><h3>"+inp.constit_name+"</h3><p><br /><b>House of Assembly</b><br />MDC MT: "+inp.MDCMT+"<br />ZanuPF: "+inp.ZanuPF+"<br />"+mdc_am+"</p><p><b>Presidential</b><br />Morgan Tsvangirai: "+inp.MDCMT_pres+"<br />Robert Mugabe: "+inp.ZanuPF_pres+"<br />Simba Makoni: "+inp.MDCAM_pres+"</p><br /></div>"), new GInfoWindowTab("Maps","<div class=\"gmap_popup_viol\"><h2>Constituency Maps</h2><p><br />"+mapLink+"</p></div>")]);
		});
		return marker;
	}


	function makeIcon(image,shadowy){
		var tinyIcon = new GIcon();

		tinyIcon.image = image;
		var shadow_icon = shadowy;

		if (shadow_icon == "cross")
  		{
	  		tinyIcon.shadow = "/files/images/markers/postelection_icons/cross/shadow-cross.png";
  		}
  		else {
	  		tinyIcon.shadow = "/files/images/markers/postelection_icons/shadow.png";
		}

		tinyIcon.iconSize = new GSize(20, 20);
		tinyIcon.shadowSize = new GSize(30, 20);
  		tinyIcon.iconAnchor = new GPoint(10, 29);
		tinyIcon.infoWindowAnchor = new GPoint(5, 1);
		return tinyIcon;
	}
}

function toggleGroup(types) {
      for (var i = 0; i < markerGroups[types].length; i++) {
        var marker2 = markerGroups[types][i];
        if (marker2.isHidden()) {
          marker2.show();
        } else {
          marker2.hide();
        }
      }
}