//***********************************************************************
//* APPLICATION	: WTO Web Site
//* COMPONENT	: 
//* PAGE		: 
//* CREATION	: 03/09/2009
//* AUTHOR		: Jane M Pickett
//* CONTENT		: Functions for groupings functions
//*		
//***********************************************************************
//* UPDATES		:
//*
//***********************************************************************
//<!--

 function showGroups(subject) 
 {
	var grpNum = 0;
	var countryNum = 0;
	var loop = 0;

	for (grpNum = groups.length - 1; grpNum >= 0; grpNum--) 
	{ 
 		var output_array = new Array(3);
		var members_array = new Array();
		var subject_array = new Array();
		var observers_array = new Array();
		var other_array = new Array()
		var group_member_array = new Array();
		var description = "";
		var website = "";
		var issue = new Array();
		var include = false;
		
		if (subject == "ALL")
		{
			include = true;
		}
		else
		{
			subject_array = groups[grpNum].subject.split("#");
			for (loop = 0; loop < subject_array.length; loop++)
			{
				if (subject_array[loop] == subject)
				{
					include = true;
					break;
				}
			}
		}
		
		if (include == true)
		{
			output_array[0] = "<a name=\"" + groups[grpNum].code.toLowerCase() + "\"></a><b>" + groups[grpNum].title + "</b><br><span class=\"parasmalltext\">&gt;&nbsp;<a class=\"parasmallcolourtext\" href=\"" + group_maps_url + groups[grpNum].code + "\">" + group_map_link + "</a></span>";
			output_array[1] = groups[grpNum].description;
			if (groups[grpNum].issue != "")
			{
				output_array[1] += "<br><b>" + issue_text + ": </b>" + groups[grpNum].issue;
			}
			if (groups[grpNum].nature != "")
			{
				output_array[1] +=  "<br><b>" + nature_text + ": </b>" + groups[grpNum].nature;
			}
			if (groups[grpNum].website != "")
			{
				output_array[1] +=  "<br><b>" + website_text + ": </b><a target=\"_blank\" class=\"subnormalcolourtext\" onMouseOver=\"writetxt('" + new_window_text + "')\" onMouseOut=\"writetxt(0)\" href=\"" + groups[grpNum].website.replace("<br>", "") + "\">" + groups[grpNum].website + "</a>";
			}
			if (groups[grpNum].documents != "")
			{
				output_array[1] +=  "<br><b>" + documents_text + ": </b>" + groups[grpNum].documents;
			}
			group_member_array = groups[grpNum].members.split("#");
			for (loop = 0; loop < group_member_array.length; loop++)
			{
				for (countryNum = 0; countryNum < country.length; countryNum++)
				{
					if (country[countryNum].code == group_member_array[loop])
					{
						if (country[countryNum].status == "MBR")
						{
							members_array.push(country[countryNum].name);
						}
						else if (country[countryNum].status == "ACC")
						{
							observers_array.push(country[countryNum].name);
						}
						else if (country[countryNum].status == "OTH")
						{
							other_array.push(country[countryNum].name);
						}
						break;
					}	
				}
			}      
			output_array[2] = "<b>" + mbr_text + " (" + members_array.length + "): </b>" + members_array.sort().join(", ");
			if (observers_array.length > 0)
			{
				output_array[2] += "<br><b>" + acc_text + " (" + observers_array.length + "): </b>" + observers_array.sort().join(", ");
			}
			if (other_array.length > 0)
			{
				output_array[2] += "<br><b>" + oth_text + " (" + other_array.length + "): </b>" + other_array.sort().join(", ");
			}
			addrow("grouptable", output_array);
		}
    }
 }

function showCountries()
{
	var grpNum = 0;
	var countryNum = 0;
	var loop = 0;
	var cnt = 0;
	for (countryNum = 0; countryNum < country.length; countryNum++)
	{
		if (country[countryNum].status == "MBR")
		{
		 	var output_array = new Array(2);
			var group_member_array = new Array();
			var group_details = "";
			for (grpNum = groups.length - 1; grpNum >= 0; grpNum--) 
			{ 
				group_member_array = groups[grpNum].members.split("#");
				for (loop = 0; loop < group_member_array.length; loop++)
				{
					if (group_member_array[loop] == country[countryNum].code)
					{
						if (group_details != "")
						{
							group_details += ", ";
						}
						group_details += "<a href=\"" + group_page + groups[grpNum].code.toLowerCase() + "\" class=\"subnormalcolourtext\" onMouseOver=\"writetxt('" + groups[grpNum].description + "')\" onMouseOut=\"writetxt(0)\">" + groups[grpNum].title + "</a>";
						break;
					}
				}
			}
			if (group_details != "")
			{
				output_array = ["<a href=\"" + country[countryNum].page + "\" class=\"subnormalboldcolourtext\">" + country[countryNum].name + "</a>", group_details];
				addrow("grouptable", output_array);
			}
		}
	}
}
 
function showCountryGroups(countryNum)
{
	var grpNum = 0;
	var loop = 0;
	var output_array = new Array(1);
	var output = "";
	var country_group_text = "";

	for (grpNum = groups.length - 1; grpNum >= 0; grpNum--) 
	{ 
		var group_member_array = new Array();
		group_member_array = groups[grpNum].members.split("#");
		for (loop = 0; loop < group_member_array.length; loop++)
		{
			if (country[countryNum].code == group_member_array[loop])
			{
				output += "<p class=\"smalltabbedboxlist\">&gt;&nbsp;<a class=\"parasmallcolourtext\" href=\"" + group_page + groups[grpNum].code.toLowerCase() + "\"onMouseOver=\"writetxt('" + groups[grpNum].description + "')\" onMouseOut=\"writetxt(0)\">" + groups[grpNum].title + "</a></p>";
				break;
			}
		}      
	}
	if (output != "")
	{
		if ((country[countryNum].article == "les ") || (country[countryNum].article == "las ") || (country[countryNum].article == "los "))
		{
			country_group_text = country_group_text2;
		}
		else
		{
			country_group_text = country_group_text1;
		}
		output_array[0] = "<p class=\"smalltabbedboxtext\">" + country[countryNum].article.slice(0,1).toUpperCase() + country[countryNum].article.slice(1) + country[countryNum].name + country_group_text + "</p>" + output + "<p class=\"strippedsmalltext\">&nbsp;</p>";
		output = "<table width=\"200px\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td class=\"bluetabtl\"></td><td class=\"bluetabtop\"></td><td class=\"bluetabtr\"></td><td width=\"56px\"></td><td width=\"5px\"></td></tr><tr><td class=\"bluetableft\"></td><td class=\"bluetabcentre\" width=\"100px\">&nbsp;" + group_title + "&nbsp;</td><td class=\"bluetabright\"></td><td width=\"56px\"></td><td width=\"5px\"></td></tr><tr><td class=\"bluetabbl\"></td><td class=\"bluetabbot\"></td><td class=\"bluetabbr\"></td><td class=\"grey160tbltop\"></td><td class=\"grey160tbltr\"></td></tr><tr><td class=\"grey160tblleft\" ></td><td colspan=\"3\" width=\"191px\" class=\"greytblnarrowmiddle\">" + output_array[0] + "</td><td class=\"grey160tblright\"></td></tr><tr><td class=\"grey160tblbl\" ></td><td class=\"grey160tblbot\" colspan=\"3\"></td><td class=\"grey160tblbr\"></td></tr></table>";
		var grptbl = document.getElementById("grouptable");
		grptbl.innerHTML = output;
	}
}

function bldGroupList(currentVal)
{
	var i = 0;
	var sorted_groups = new Array();
// write general options on page
	document.write("<option value=\"none\"");
	if (currentVal == "none")
	{
		 document.write(" selected");
	}
	document.writeln(">" + select_group[0] + "</option>");
	for (i = 0; i < groups.length; i++)
	{
		sorted_groups[sorted_groups.length] = [groups[i].title, groups[i].code];
	}
	sorted_groups.sort();
	for (i = 1; i < sorted_groups.length; i++)
	{
		document.write("<option value=\"" + sorted_groups[i][1] + "\"");
		if (currentVal == sorted_groups[i][1])
		{
			 document.write(" selected");
		}
		document.writeln(">" + sorted_groups[i][0] + "</option>");
	}
	return false;
}

function showMap()
{
	var i = 0;
	var groupSelected  = document.hiddenform.elements['selectedGroup'].selectedIndex;	
	if (groupSelected == "1")
	{
		group_selected  = "none";
	}
	else
	{
		group_selected  = document.hiddenform.elements['selectedGroup'].options[groupSelected].value;	
	}
// reload the page with selected values on the url
//	window.location.search = "?group_selected=" + escape(group_selected);
//	alert(flashvars.maptype);
	flashvars.grouping  = group_selected;

	loadMap(flashvars);
	return false;

}

//***********************************************************************
// This funtion displays the date stored in the variable at the top of  
// this file on the html page
//***********************************************************************
function showUpdateDate() 
{		
	document.write(update_date);
	return false;			
}

   
function addrow(tablename, array) 
{
	var grptbl = document.getElementById(tablename);
	var lastRow = grptbl.rows.length;
	var grprow = grptbl.insertRow(lastRow);
   for (r = 0; r < array.length; r++) 
	{   
		var grpcell = grprow.insertCell(r);
        grpcell.innerHTML = array[r];
		grpcell.className = "subnormaltext";
		grpcell.vAlign = "top";
     }
 }

function loadMap(flashVars)
{
	var params = {
		  menu: "false",
		  wmode: "window",
		  allowScriptAccess: "always",
		  quality: "high",
		  pluginspage : "http://www.adobe.com/go/getflashplayer",
		  align : "top",
		  play: "true", 
		  loop : "true", 
		  scale: "noscale",
		  devicefont: "false", 
		  salign : "lt",
		  bgcolor: "#ffffff",
		  allowFullScreen: "false"
		};

	var attributes = {
		  id: "wtoMap",
		  name: "wtoMap"
		};
		swfobject.embedSWF("/library/maps/WTOMap.swf", "wtoMap", "100%", "100%", "9.0.0", 
			"/library/maps/expressInstall.swf", flashvars, params, attributes);
}
//-->


