//***********************************************************************
//* APPLICATION	: WTO Web Site
//* COMPONENT	: 
//* PAGE		: 
//* CREATION	: 14/01/2002
//* AUTHOR		: Jane M Pickett
//* CONTENT		: Functions for cbt courses
//*		
//***********************************************************************
//* UPDATES		:
//*
//***********************************************************************

// Function to transform a bookmark to lowercase & replace accented characters with non-accented equivilent
function stripAccents(input_string)
{
	var output_string = "";
		output_string = input_string.toLowerCase();
	    output_string = output_string.replace(/á/g, "a");
        output_string = output_string.replace(/é/g, "e");
        output_string = output_string.replace(/í/g, "i");
        output_string = output_string.replace(/ó/g, "o");
        output_string = output_string.replace(/ú/g, "u");
        output_string = output_string.replace(/à/g, "a");
        output_string = output_string.replace(/è/g, "e");
        output_string = output_string.replace(/ñ/g, "n");
        output_string = output_string.replace(/ç/g, "c");
        output_string = output_string.replace(/ï/g, "i");
        output_string = output_string.replace(/â/g, "a");
        output_string = output_string.replace(/ê/g, "e");
        output_string = output_string.replace(/î/g, "i");
        output_string = output_string.replace(/ô/g, "o");
        output_string = output_string.replace(/û/g, "u");
        output_string = output_string.replace(/œ/g, "oe");
        output_string = output_string.replace(/'/g, "_");
		return output_string;
}

//***********************************************************************
// This funtion displays the date stored in the variable at the top of  
// this file on the html page
//***********************************************************************
function showUpdateDate(dsnumber) 
{		
	
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		document.write(getDateString(ds_array[dsnumber].update_date));
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


//***********************************************************************
// This function displays the short title for a dispute on the html 
// taking the text of the short title from ds_array. It needs to be 
// passed the number of the dispute as an argument
//***********************************************************************
function showShortTitle(dsnumber) 
{		
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		document.write(ds_array[dsnumber].short_title);
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


//UPDATED***********************************************************************
// This function displays the complainants for a dispute on the html 
// taking the names of the complainants from ds_array. It needs to be 
// passed the number of the dispute as an argument. Multiple complainants
// are separated by a comma
//***********************************************************************
function showComplainant(dsnumber) 
{		
	var complainant = "";
	var temp_country_array = new Array();
	var k = 0;
	
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		temp_country_array = ds_array[dsnumber].origin.split("#");
		for (k = 0; k < temp_country_array.length; k++)
		{
			if (temp_country_array[k] == "EEC")
			{
				if (ds_array[dsnumber].start_date >= "2009/12/01")
				{
					complainant += eec_new;
				}
				else
				{
					complainant += eec_old;
				}
			}
			else
			{
				complainant += getCountryName(temp_country_array[k]);
			}
			if (k < temp_country_array.length - 1)
			{
				complainant += "; ";
			}
		}
		document.write(complainant);
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


//UPDATED***********************************************************************
// This function displays the respondents for a dispute on the html 
// taking the names of the respondents from ds_array. It needs to be 
// passed the number of the dispute as an argument. Multiple respondents
// are separated by a semi colon
//***********************************************************************
function showRespondent(dsnumber) 
{		
	var respondent = "";
	var temp_country_array = new Array();
	var k = 0;
	
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		temp_country_array = ds_array[dsnumber].destination.split("#");
		for (k = 0; k < temp_country_array.length; k++)
		{
			if (temp_country_array[k] == "EEC")
			{
				if (ds_array[dsnumber].start_date >= "2009/12/01")
				{
					respondent += eec_new;
				}
				else
				{
					respondent += eec_old;
				}
			}
			else
			{
				respondent += getCountryName(temp_country_array[k]);
			}
			if (k < temp_country_array.length - 1)
			{
				respondent += "; ";
			}
		}
		document.write(respondent);
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


//UPDATED***********************************************************************
// This function displays the third parties for a dispute on the html 
// taking the names of the third parties from ds_array. It needs to be 
// passed the number of the dispute as an argument. Multiple third parties
// are separated by a semi colon
//***********************************************************************
function showThirdParty(dsnumber) 
{		
	var third_party = "";
	var temp_country_array = new Array();
	var k = 0;
	var l = 0;
	var eec_found = false;
	
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		temp_country_array = ds_array[dsnumber].third_party.split("#");
		for (k = 0; k < temp_country_array.length; k++)
		{
			if (temp_country_array[k] == "EEC")
			{
				for (l = 0; l < eec_exceptions.length; l++)
				{
					if (eec_exceptions[l] == temp_country_array[k])
					{
						third_party += eec_old;
						eec_found = true;
						break;
					}
				}
				if (eec_found == false)
				{
					third_party += eec_new;
				}
			}
			else
			{
				third_party += getCountryName(temp_country_array[k]);
			}
			if (k < temp_country_array.length - 1)
			{
				third_party += "; ";
			}
		}
		document.write(third_party);
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


//UPDATED ***********************************************************************
// This function displays the RFC date for a dispute on the html 
// taking the text of the RFC date from ds_array. It needs to be 
// passed the number of the dispute as an argument
//***********************************************************************
function showRFCDate(dsnumber) 
{		
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		document.write(getDateString(ds_array[dsnumber].start_date));
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			
}


// UPDATED ***********************************************************************
// This function displays a list of related links using the information
// stored in ds_array on the Complainant, Respondent and Subject for the
// dispute to generate links to the disputes by country and disputes by
// subject page at places with the same complainant, respondent and 
// subject. It needs to be passed the number of the dispute as an argument
//***********************************************************************
function seeAlsoLinks(dsnumber) 
{		
// Declare variables used by this function
	var i = 0;
	var j = 0;
	var subject_array = new Array();
	var agreement_array = new Array();
	var complainant_array = new Array();
	var respondent_array = new Array();
	var temp_array = new Array();
	var last_agreement = "";
	var last_subject = "";
// Check if a valid DS number	
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		document.write("<p class=\"parasmallcolourtext\" align=\"right\"><b>" + other_disputes + "</b>");
		subject_array = ds_array[dsnumber].subject.split("#");
// Loop through all subjects for the dispute
		for (i = 0; i < subject_array.length; i++)
		{
			if (subject_array[i] != " ")
			{
// Loop through subject list until matching subject found
				for (j = 0; j < ds_subject.length; j++)
				{
					if (ds_subject[j].subject_id == subject_array[i])
					{
// Output a link to subject index for that subject
						if (ds_subject[j].subject_name != last_subject)
						{
							document.writeln("<br>&gt;&nbsp;<a href=\"" + subject_index_url + subject_array[i] + "\" class=\"parasmallcolourtext\">" + ds_subject[j].subject_name + "</a>");
							last_subject = ds_subject[j].subject_name;
						}
						break;
					}
				}
			}
		}
		complainant_array = ds_array[dsnumber].origin.split("#");
// Loop through all complainants for the dispute
		for (i = 0; i < complainant_array.length; i++)
		{
// Loop through country list until matching country found
			for (j = 0; j < country.length; j++)
			{
// Output a link to the country index for that country
				if (country[j].code == complainant_array[i])
				{
					document.write("<br>&gt;&nbsp;<a href=\"" + dispu_by_country_url + complainant_array[i].toLowerCase() + "\" class=\"parasmallcolourtext\">");
					if (complainant_array[i] == "EEC")
					{
						document.writeln(eec_both + "</a>");
					}
					else
					{
					 	document.writeln(country[j].name + "</a>");
					}
					break;
				}
			}
		}
		respondent_array = ds_array[dsnumber].destination.split("#");
// Loop through all respondents for a dispute
		for (i = 0; i < respondent_array.length; i++)
		{
// Loop through country list until matching country found
			for (j = 0; j < country.length; j++)
			{
// Output a link to the country index for that country
				if (country[j].code == respondent_array[i])
				{
					document.write("<br>&gt;&nbsp;<a href=\"" + dispu_by_country_url + respondent_array[i].toLowerCase() + "\" class=\"parasmallcolourtext\">");
					if (respondent_array[i] == "EEC")
					{
						document.writeln(eec_both + "</a>");
					}
					else
					{
					 	document.writeln(country[j].name + "</a>");
					}
					break;
				}
			}
		}
		
		agreement_array = ds_array[dsnumber].agreement.split("#");
		for (i = 0; i < agreement_array.length; i++)
		{
			temp_array = agreement_array[i].split("_");
			for (j = 0; j < ds_agreement.length; j++)
			{
				if ((ds_agreement[j].agreement_id == temp_array[0]) && (temp_array[0] != last_agreement))
				{
					document.writeln("<br>&gt;&nbsp;<a href=\"" + agreement_index_url + temp_array[0] + "\" class=\"parasmallcolourtext\">" + ds_agreement[j].agreement_name + "</a>");
					last_agreement = temp_array[0];
					break;
				}
			}
		}
		document.writeln("</p>");
	}
	return false;	
}


// UPDATED***********************************************************************
// This function builds a form dropdown list of countries from the 
// countries in the newsvars array that are members.
// If a country name is passed to it as an argument then that country
// will be shown as selected when the list is displayed
//***********************************************************************
function bldDisputesCountryList(currentVal)
{
	var country_list_array = new Array();
	var h = 0;
	var i = 0;
	
// read the array record for each dispute
	for (h = 1; h < country.length; h++)
	{
		if (country[h].joindate != "")
		{
			if (country[h].code == "EEC")
			{
				country_list_array[i] = [eec_both, country[h].code];
			}
			else
			{
				country_list_array[i] = [country[h].name, country[h].code];
			}
			i += 1;
		}
	}
// sort the list of countries alphabetically
//	country_list_array.sort();
// write general options on page
	document.write("<option value=\"none\"");
	if (currentVal == "none")
	{
		 document.write(" selected");
	}
	document.writeln(">" + select_country[0] + "</option>");
	document.write("<option value=\"*\"");
	if (currentVal == "*")
	{
		 document.write(" selected");
	}
	document.writeln(">" + select_country[1] + "</option>");
// write option for each country in the list on the page			
	for ( i = 0; i < country_list_array.length; i++)
	{
		document.write("<option value=\"" + country_list_array[i][1] + "\"");
		if (currentVal == country_list_array[i][1])
		{
			 document.write(" selected");
		}
		document.writeln(">" + country_list_array[i][0] + "</option>");
	}
	return false;	 	
}

function bldDSNumberList(currentVal)
{
	var i = 0;
// write general options on page
	document.write("<option value=\"none\"");
	if (currentVal == "none")
	{
		 document.write(" selected");
	}
	document.writeln(">" + select_dispute[0] + "</option>");
	document.write("<option value=\"*\"");
	if (currentVal == "*")
	{
		 document.write(" selected");
	}
	document.writeln(">" + select_dispute[1] + "</option>");
	
	for (i = 1; i < ds_array.length; i++)
	{
		document.write("<option value=\"" + ds_array[i].code + "\"");
		if (currentVal == ds_array[i].code)
		{
			 document.write(" selected");
		}
		document.writeln(">" + ds_array[i].code + "</option>");
	}
	return false;
}


// UPDATED***********************************************************************
// This function builds a form dropdown list of subjects from the subject list.
// If a subject is passed to it as an argument then 
// that subject will be shown as selected when the list is displayed
//***********************************************************************
function bldDisputesSubjectList(currentVal)
{
	var subject_list_array = new Array();
	var h = 0;
	var i = 0;

// read each record of the subject array
	for (h = 1; h < ds_subject.length; h++)
	{
		subject_list_array[i] = [ds_subject[h].subject_name, ds_subject[h].subject_id];
		i += 1;
	}
// sort the list of subjects alphabetically
	subject_list_array.sort();
// write general options on page
	window.document.write("<option value=\"none\"");
	if ((currentVal == "none") || (currentVal == ""))
	{
		window.document.write(" selected");
	}
	window.document.writeln(">" + select_subject[0] + "</option>");
	window.document.writeln("<option value=\"*\"");
	if (currentVal == "*")
	{
		window.document.writeln(" selected");
	}
	window.document.writeln(">" + select_subject[1] + "</option>");
// write option for each subject in the list on the page			
	for ( i = 0; i < subject_list_array.length; i++)
	{
		if (subject_list_array[i][0] != " ")
		{
			window.document.write("<option value=\"" + subject_list_array[i][1] + "\"");
			if (currentVal == subject_list_array[i][1])
			{
				window.document.write(" selected");
			}
		 	window.document.writeln(">" + subject_list_array[i][0] + "</option>");
		}
	}
	return false;	 	
}

// NEW***********************************************************************
// This function builds a form dropdown list of agreements from the agreement list.
// If an agreement is passed to it as an argument then 
// that agreement will be shown as selected when the list is displayed
//***********************************************************************
function bldDisputesAgreementList(currentVal)
{
	var agreement_list_array = new Array();
	var h = 0;
	var i = 0;

// read each record of the subject array
	for (h = 1; h < ds_agreement.length; h++)
	{
		agreement_list_array[i] = [ds_agreement[h].agreement_short_name, ds_agreement[h].agreement_id];
		i += 1;
	}
// sort the list of agreementss alphabetically
	agreement_list_array.sort();
// write general options on page
	window.document.write("<option value=\"none\"");
	if ((currentVal == "none") || (currentVal == ""))
	{
		window.document.write(" selected");
	}
	window.document.writeln(">" + select_agreement[0] + "</option>");
	window.document.writeln("<option value=\"*\"");
	if (currentVal == "*")
	{
		window.document.writeln(" selected");
	}
	window.document.writeln(">" + select_agreement[1] + "</option>");
// write option for each subject in the list on the page			
	for ( i = 0; i < agreement_list_array.length; i++)
	{
		if (agreement_list_array[i][0] != " ")
		{
			window.document.write("<option value=\"" + agreement_list_array[i][1] + "\"");
			if (currentVal == agreement_list_array[i][1])
			{
				window.document.write(" selected");
			}
		 	window.document.writeln(">" + agreement_list_array[i][0] + "</option>");
		}
	}
	return false;	 	
}

// NEW***********************************************************************
// This function builds a form dropdown list of documents from the document list.
// If an agreement is passed to it as an argument then 
// that agreement will be shown as selected when the list is displayed
//***********************************************************************
function bldDisputesDocumentList(currentVal)
{
	var i = 0;
// write option for each document type in the list on the page			
	for (i = 0; i < ds_document.length; i++)
	{
			window.document.write("<option value=\"" + i + "\"");
			if (currentVal == i)
			{
				window.document.write(" selected");
			}
		 	window.document.writeln(">" + ds_document[i].document_menu + "</option>");
	}
	return false;	 	
}

//UPDATED***********************************************************************
// This function builds a form dropdown list of years since the WTO came
// into being. If a year is passed to it as an argument then 
// that year will be shown as selected when the list is displayed
//***********************************************************************
function bldDisputesYearList(currentVal) 
{
	var i = 0;                                
	var today = new Date();
	var thisYear = today.getFullYear();

// write general options on page
	document.write("<option value=\"none\"");
	if (currentVal == "none")
	{
		document.write(" selected");
	}
	document.writeln(">" + select_year[0] + "</option>");
	window.document.writeln("<option value=\"any\"");
	if (currentVal == "any")
	{
		window.document.writeln(" selected");
	}
	document.writeln(">" + select_year[1] + "</option>");

// write option for each year in the list on the page			
	for ( i = thisYear; i > 1994; i--)
	{
		document.write("<option value=\"" + i + "\"");
		if (currentVal == i)
		{
			document.write(" selected");
		}
		document.writeln(">" + i + "</option>");
	}
	return false;	 		
}




//UPDATED***********************************************************************
// This function uses the information entered into the form on the Find
// Disputes Documents page and uses it to select disputes matching these
// criteria in ds_array. It then formulates this information into a query 
// which it passes to Docsonline. It takes as an argument a number 
// corresponding to the language the Docsonline search is to be performed
// in. Before sending the searchstring to Docsonline it calculates its
// length so as not to generate an error
//***********************************************************************
function findDisputesDocuments(language)
{
	var disputes_array = new Array();
	var subjects_array = new Array();
	var member1_array = new Array();
	var member2_array = new Array();
	var agreement_array     = new Array();
	var split_agreement     = new Array();
	var temp_array          = new Array();
	var h = 0;
	var i = 1;
	var k = 0; 
	var l = 0;
	var m = 0;
	var j = 0;
	var n = 0;
	var lastDS = "";
	var searchString = "";
	var fullTextSearch = "";
	var endSearchString = "";
	var searchDate   = "";
	var matched      = 0;
	var searchAll    = 0;
// determine which options were selected on the form
	var documentType  = document.getElementById("doctype").value;	
	var disputeNumber = document.getElementById("dispute_number").value;	
	var agreement     = document.getElementById("agreement").value;
	var member1       = document.getElementById("member1").value;
	var member2       = document.getElementById("member2").value;
	var year          = document.getElementById("year").value;
	var subject       = document.getElementById("subject").value;
	var subjectName   = document.getElementById("subject").name;
	var complainant1  = document.getElementById("complainant1").checked;
	var complainant2  = document.getElementById("complainant2").checked;
	var respondent1   = document.getElementById("respondent1").checked;
	var respondent2   = document.getElementById("respondent2").checked;
	var thirdparty1   = document.getElementById("thirdparty1").checked;
	var thirdparty2   = document.getElementById("thirdparty2").checked;
//	var fulltext      = document.getElementById("fulltext").value;
// build a date substring if a year is specified
	if ((year != "any") && (year != "none"))
	{
		searchDate = " and (( @Doc_Date >= " + year + "/01/01 00:00:00 ) and ( @Doc_Date <= " + year + "/12/31 23:59:59 ))";
	}
// build a full text search string if text entered in full text field
//	if (fulltext != "")
//	{
//		fullTextSearch = " and (" + fulltext + ")";
//	}
// don't check for individual DS numbers if user has not specified a member or a subject
	if (((subject == "none") || (subject == "*")) && ((member1 == "none") || (member1 == "*")) && ((member2 == "none") || (member2 == "*")) && ((agreement == "none") || (agreement == "*")) && ((disputeNumber == "none") || (disputeNumber == "*")))
	{
		searchAll = 1;
		searchString = searchString + "@meta_Symbol (WT/DS*) ";
	}
	else if ((disputeNumber != "none") && (disputeNumber != "*"))
	{
		searchAll = 1;
		searchString = searchString + "@meta_Symbol (WT/" + disputeNumber + "/*) ";		
	}
	else
	{
// check each dispute in ds_array 
// read the array record for each dispute		
		for (j = 1; j < ds_array.length; j++)
		{
			matched = 0;
			agreement_matched = false;
			agreement_array = ds_array[j].agreement.split("#");
			for (n = 0; n < agreement_array.length; n++)
			{
				temp_agreement = agreement_array[n].split("_");
				{
					if ((agreement == "none") || (agreement == "*") || (agreement == temp_agreement[0]))
					{
						subjects_array = ds_array[j].subject.split("#");
// loop through each subject for the dispute
						for (h = 0; h < subjects_array.length; h++)
						{
// dispute falls into the subject criteria
							if ((subject == "none") || (subject == "*") || (subject == subjects_array[h]))
							{
								member1_array = ds_array[j].origin.split("#");
// loop through each complainant for the dispute
								for (k = 0; k < member1_array.length; k++)
								{
// dispute falls into the complainant criteria for the first member 
									if (((member1 == "none") || (member1 == "*") || ((member1 == member1_array[k]) && (complainant1 == true)) || ((member1 == member1_array[k]) && (complainant1 == false) && (respondent1 == false) && (thirdparty1 == false))) && (matched == 0))
									{
										member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
										for (l = 0; l < member2_array.length; l++)
										{
// dispute falls into complainant criteria for both members - update list of matched disputes
											if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (complainant2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
											{
												disputes_array[m] = j;
												m = m + 1;
												matched = 1;
												break;
											}
										}
// dispute not yet matched
										if (matched == 0)
										{
											member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
												if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (respondent2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
										}
// dispute not yet matched
										if (matched == 0)
										{
											member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
												if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (thirdparty2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
										}
									}
								}
// dispute not yet matched
								if (matched == 0)
								{
									member1_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
									for (k = 0; k < member1_array.length; k++)
									{
// dispute falls into the respondent criteria for the first member 
										if (((member1 == "none") || (member1 == "*") || ((member1 == member1_array[k]) && (respondent1 == true)) || ((member1 == member1_array[k]) && (complainant1 == false) && (respondent1 == false) && (thirdparty1 == false))) && (matched == 0))
										{
											member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute falls into complainant criteria for both members - update list of matched disputes
												if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (complainant2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
													if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (respondent2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
													if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (thirdparty2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
										}
									}
								}
// dispute not yet matched
								if (matched == 0)
								{
									member1_array = ds_array[j].third_party.split("#");
// loop through each THIRDPARTY for the dispute
									for (k = 0; k < member1_array.length; k++)
									{
// dispute falls into the thirdparty criteria for the first member 
										if (((member1 == "none") || (member1 == "*") || ((member1 == member1_array[k]) && (thirdparty1 == true)) || ((member1 == member1_array[k]) && (complainant1 == false) && (respondent1 == false) && (thirdparty1 == false))) && (matched == 0))
										{
											member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute falls into complainant criteria for both members - update list of matched disputes
												if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (complainant2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
													if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (respondent2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
													if (((member2 == "none") || (member2 == "*") || ((member2 == member2_array[l]) && (thirdparty2 == true)) || ((member2 == member2_array[l]) && (complainant2 == false) && (respondent2 == false) && (thirdparty2 == false))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
										}
									}
								}
								break; // subject matched
							}
						}
						break;  // agreement matched
					}
				}
			}
		}					
	}
// build search string from list of matching disputes & options selected
	if ((disputes_array.length > 0) || (searchAll == 1))
	{
// individual disputes exist matching search criteria
		if ((disputes_array.length > 0) && (disputes_array.length <= 85))
		{
			matched = 0;
			searchString = searchString + "@meta_Symbol (";
// loop through	each matched dispte and add it to the string if it is not already there
			for (k = 0; k < disputes_array.length; k++)
			{
				if (disputes_array[k] != lastDS)
				{
					if (matched != 0)
					{
						searchString = searchString + " or ";
					}
					else
					{
						matched = 1;
					}
					searchString = searchString + "WT/DS" + disputes_array[k] + "/*";
					lastDS = disputes_array[k];
				} 
			}
			searchString = searchString + ") "
		}
		else if (disputes_array.length > 85)
		{
			if ((agreement != "none") && (agreement != "*"))
			{
				for (k = 0; k < ds_agreement.length; k++)
				{
					if (ds_agreement[k].agreement_id == agreement)
					{
						searchString = searchString + "(@meta_Articles " + ds_agreement[k].agreement_dolcode + ")";
						break;
					}
				}
			}
			if ((subject != "none") && (subject != "*"))
			{
				searchString = searchString + "((@meta_Subjects " + subjectName + ") or (@meta_Products " + subjectName + ")) ";
			}
			if ((member1 != "none") && (member1 != "*"))
			{
				for (k = 0; k < country.length; k++)
				{
					if (country[k].code == member1)
					{
						if (complainant1 == true)
						{
							searchString = searchString + "(@meta_Countries " + country[k].dolsearch + ")  ";
						}
						if (respondent1 == true)
						{
							if (complainant1 == true)
							{
								searchString = searchString + " and ";
							}
							searchString = searchString + "((@meta_Countries " + country[k].dolsearch + ") and (@meta_Title " + country[k].dolsearch + " - ) and not (@meta_Title Request for Consultations by the " + country[k].dolsearch + ")) ";
						}
						break;
					}
				}
			}
			if ((member2 != "none") && (member2 != "*"))
			{
				for (k = 0; k < country.length; k++)
				{
					if (country[k].code == member2)
					{
						if ((member1 != "none") && (member1 != "*"))
						{
							searchString = searchString + " and ";
						}
						if (complainant2 == true)
						{
							searchString = searchString + "((@meta_Countries " + country[k].dolsearch + ")) ";
						}
						if (respondent2 == true)
						{
							if (complainant1 == true)
							{
								searchString = searchString + " and ";
							}
							searchString = searchString + "((@meta_Countries " + country[k].dolsearch + ") and (@meta_Title " + country[k].dolsearch + " - ) and not (@meta_Title Request for Consultations by the " + country[k].dolsearch + ")) ";
						}
						break;
					}
				}
			}

			if (searchString != "")
			{
				searchString = "@meta_Symbol (WT/DS*) and " + searchString;
			}	
			else
			{
				alert(too_many);
				return false;
			}
		}
			searchString = searchString + ds_document[documentType].document_dolstring + searchDate;
//			searchString = searchString + ds_document[documentType].document_dolstring + searchDate + fullTextSearch;
//			alert(searchString);
// submit the search string to DocsOnline
				f_submit(searchString, language);
		}
		else
// if no disputes meet search criteria display error message
		{
			alert(no_disputes);
		}
	return false;
}

// NEW ******************************************************************************
// This function displays a list of disputes ordered by short title name for those
// disputes that have a short title. Disputes having the same short title are grouped
// together
//***********************************************************************************
function showShortTitleList()
{
// declare variables used by this function
	var ds_temp_array = new Array();
	var country_temp_array = new Array();
	var country_list = "";
	var prev_title = ""
	var k = 0;
	var h = 0;
	var i = 0;
	var j = 0;
// check each dispute in ds_array
	for (h = 1; h < ds_array.length; h++)
	{
// if dispute has a short title add it to temporary array
		if ((ds_array[h].short_title != "") && (ds_array[h].short_title != " "))
		{
//			ds_temp_array[i] = [ds_array[h].destination, ds_array[h].short_title, ds_array[h].code, ds_array[h].origin, ds_array[h].start_date];
			ds_temp_array[i] = ["", ds_array[h].short_title, ds_array[h].code, ds_array[h].origin, ds_array[h].start_date];
			i += 1;
		}
	}
	
	if (ds_temp_array.length > 0)
	{
// sort short titles alphabetically 
		ds_temp_array.sort();
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
		
//		for (k = 0; k < country.length; k++)
//		{
//			if (country[k].status == "MBR")
//			{
// loop through temporary array
				for (i = 0; i < ds_temp_array.length; i++)
				{
//					if (ds_temp_array[i][0] == country[k].code)
//					{
// if short title has changed create a new table cell containing short title
						if (ds_temp_array[i][1] != prev_title)
						{
							if (prev_title != "")
							{
								document.writeln("</td></tr>");
							}
							document.writeln("<tr><td width=\"100%\" valign=\"top\" class=\"graytd\">");
							document.writeln("<span class=\"paracolourtext\">" + ds_temp_array[i][1] + "</span>");
							prev_title = ds_temp_array[i][1];
						}
						document.writeln("<span class=\"parasmalltext\"><br>&nbsp;&nbsp;&mdash;&nbsp;");
						country_temp_array = ds_temp_array[i][3].split("#");
						country_list = "";
// display list of complainants for dispute
						for (j = 0; j < country_temp_array.length; j++)
						{
							if (country_list != "")
							{
								country_list += "; ";
							}
							country_list += checkEECName(country_temp_array[j], ds_temp_array[i][4]);
						}
						if (country_temp_array.length > 1)
						{ 
							document.write(complainant_text[1]);
						}
						else
						{
							document.write(complainant_text[0]);
						}
// make link to summary page for dispute
						document.writeln(country_list + "&nbsp;<a href=\"" + cases_link + ds_temp_array[i][2].toLowerCase() + "_" + language_letter + ".htm\" class=\"parasmallcolourtext\" onmouseover=\"writetxt(\'" + show_details_callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_temp_array[i][2] + "</a>");
//					}
//				}
//			}
		}
		document.writeln("</span></td></tr></table>");
	}
}

// NEW*********************************************************************
// This function displays a list of the agreements and articles cited in
// the key facts section of a dispute
//*************************************************************************
function showAgreementCited(dsnumber)
{
// Declare variables used by this function
	var h = 0;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var temp_agreement_array = new Array();
	var temp_article_array = new Array();
	var split_sub_page_array = new Array();
	var temp_sub_page_array = new Array();
	var split_parts_array = new Array();
	var temp_parts_array = new Array();
	var parts_id_array = new Array();
	var parts_page_array = new Array();
	var bookmark_id_array = new Array();
	var page_array = new Array();
	var last_agreement = "";
	var needs_article = true;
	var is_part = false;
	var is_annexe = false;
	var output_text = "";
// Check a valid DS number specified
	if ((dsnumber > 0) && (dsnumber < ds_array.length) && (ds_array[dsnumber].agreement != ""))
	{
// Split articles and agreements cited into pairs
		temp_agreement_array = ds_array[dsnumber].agreement.split("#");
		for (i = 0; i < temp_agreement_array.length; i++)
		{
			temp_agreement_array.sort();
// Split each article agreement pair
			temp_article_array = temp_agreement_array[i].split("_");
// If agreement name changed put new agreement on a new line
			if (temp_article_array[0] != last_agreement)
			{
				needs_article = true;
				if (last_agreement != "")
				{
					output_text += "<br>";
				}
				for (j = 0; j < ds_agreement.length; j++)
				{
// Get details for specified agreement
					if (ds_agreement[j].agreement_id == temp_article_array[0])
					{
						split_sub_page_array = ds_agreement[j].agreement_sub_page.split("#");
						if (split_sub_page_array[0] != "")
						{
// If agreement has subpages get id of articles starting each page		
							for (h = 0; h < split_sub_page_array.length; h++)
							{
								temp_sub_page_array = split_sub_page_array[h].split("*");
								for (l = 0; l < ds_article.length; l++)
								{
									if (ds_article[l].article_name == temp_sub_page_array[1])
									{
										bookmark_id_array[h] = l;
										page_array[h] = temp_sub_page_array[0];
										break;
									}
								}
							}
						}
						split_parts_array = ds_agreement[j].agreement_parts.split("#");
						if (split_parts_array[0] != "")
						{
// If agreement has parts get id of parts starting each page		
							for (h = 0; h < split_parts_array.length; h++)
							{
								temp_parts_array = split_parts_array[h].split("*");
								for (l = 0; l < ds_article.length; l++)
								{
									if (ds_article[l].article_name == temp_parts_array[1])
									{
										parts_id_array[h] = l;
										parts_page_array[h] = temp_sub_page_array[0];
										break;
									}
								}
							}
						}
// Display agreement short name
						output_text += ds_agreement[j].agreement_short_name + ": ";
						last_agreement = temp_article_array[0];
						break;
					}
				}
			}
			else
			{
				output_text += ", ";
			}
// Loop through list of articles
			for (k = 0; k < ds_article.length; k++)
			{
// If article found check if it is an annex or a part
				if (ds_article[k].article_id == temp_article_array[1])
				{
					if (ds_article[k].article_name.indexOf(article_array[1]) == -1)
					{
						is_annexe = false;
					}
					else
					{
						is_annexe = true;
					}
					if (ds_article[k].article_name.indexOf(article_array[2]) == -1)
					{
						is_part = false;
					}
					else
					{
						is_part = true;
					}
// If first article for an agreement prefix with "Art"
					if ((needs_article == true) && (is_annexe == false) && (is_part == false))
					{
						if (ds_article[k].article_id != "0")
						{
							output_text += "Art. ";
						}
						needs_article = false;
					}
					if (ds_agreement[j].agreement_url != "")
					{
// Calculate page and bookmark for non part links				
					if (is_part == false)
					{
						if (ds_agreement[j].agreement_sub_page == "")
						{
							output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + ds_agreement[j].agreement_url + "#" + ds_article[k].article_bookmark + "\" >";
						}
						else
						{
							for (l = 0; l < bookmark_id_array.length; l++)
							{
								if ((l == 0) && (bookmark_id_array[l] > k))
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + ds_agreement[j].agreement_url + "#" + ds_article[k].article_bookmark + "\" >";
									break;
								}
								else if (bookmark_id_array[l] > k)
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + page_array[l - 1] + "#" + ds_article[k].article_bookmark + "\" >";
									break;
								}
								else if ((l == bookmark_id_array.length - 1) && (k >= bookmark_id_array[l]))
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + page_array[l] + "#" + ds_article[k].article_bookmark + "\" >";
									break;
								}
							}
						}
					}
					else
// Calculate page and bookmark for part links				
					{
						if (ds_agreement[j].agreement_sub_page == "")
						{
							output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + ds_agreement[j].agreement_url + "#" + ds_article[k].article_bookmark + "\" >";
						}
						else
						{
							for (l = 0; l < parts_id_array.length; l++)
							{
								if ((l == 0) && (parts_id_array[l] > k))
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + ds_agreement[j].agreement_url + "#" + ds_article[k].article_bookmark;
									break;
								}
								else if (parts_id_array[l] > k)
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + parts_page_array[l - 1] + "#" + ds_article[k].article_bookmark;
									break;
								}
								else if ((l == parts_id_array.length - 1) && (i >= parts_id_array[l]))
								{
									output_text += "<a class=\"paracolourtext\" href=\"" + legal_text_url + parts_page_array[l] + "#" + ds_article[k].article_bookmark;
									break;
								}
							}					
						}
					}
					}
					output_text += ds_article[k].article_name;
					if (ds_agreement[j].agreement_url != "")
					{
						output_text += "</a>";
					}
					break;
				}
			}
		}

		document.write(output_text);
	}
	return false;
}

//UPDATED***********************************************************************
// This function creates a table for the disputes by country page listing 
// for each country the disputes in which they have been involved
//***********************************************************************
function disputesByCountryTable()
{
// Declare variales used by this function
	var country_totals_array = new Array();
	var country_temp_array = new Array();
	var dispute_numbers_array = new Array();
	var otherparty = "";
	var dispute = "";
	var ds_link = "";
	var bookmark = "";
	var found = 0;
	var h = 0;
	var i = 0;
	var j = 0;
// check each dispute in ds_array
	for (h = 1; h < ds_array.length; h++)
	{
		ds_link = dsNumberLink(h);
		if ((ds_array[h].origin != "") && (ds_array[h].origin != " "))
		{
			country_temp_array = ds_array[h].origin.split("#");
// loop through each complainant for the dispute
			for (i = 0; i < country_temp_array.length; i++)
			{
				found = 0;
				dispute = "";
// loop through array of countries 
				for (j = 0; j < country_totals_array.length; j++)
				{
// if a record exists for the country as complainant update the counter and add the dispute number
					if (country_temp_array[i] == country_totals_array[j][7])
					{
						country_totals_array[j][1] = country_totals_array[j][1] + 1;
						if (country_totals_array[j][2] != "")
						{
							country_totals_array[j][2] = country_totals_array[j][2] + "#" + ds_link;
						}
						else
						{
							country_totals_array[j][2] = country_totals_array[j][2] + ds_link;
						}
						found = 1;
						break;
					}
				}
// if no record exists create one
				if (found == 0)
				{
					dispute = dispute + ds_link;
					country_totals_array[j] = [country_temp_array[i], 1, dispute, 0, "", 0, "", country_temp_array[i]];
				}
			}
		}
		if ((ds_array[h].destination != "") && (ds_array[h].destination != " "))
		{
			country_temp_array = ds_array[h].destination.split("#");
// loop through each respondent for the dispute
			for (i = 0; i < country_temp_array.length; i++)
			{
				found = 0;
				dispute = "";
// loop through array of countries
				for (j = 0; j < country_totals_array.length; j++)
				{
// if a record exists for the country as respondent update the counter and add the dispute number
					if (country_temp_array[i] == country_totals_array[j][7])
					{
						country_totals_array[j][3] = country_totals_array[j][3] + 1;
						if (country_totals_array[j][4] != "")
						{
							country_totals_array[j][4] = country_totals_array[j][4] + "#" + ds_link;
						}
						else
						{
							country_totals_array[j][4] = country_totals_array[j][4] + ds_link;
						}
						found = 1;
						break;
					}
				}
// if no record exists create one
				if (found == 0)
				{
					dispute = dispute + ds_link;
					country_totals_array[j] = [country_temp_array[i], 0, "", 1, dispute, 0, "", country_temp_array[i]];
				}
			}			
		}
		if ((ds_array[h].third_party != "") && (ds_array[h].third_party != " "))
		{
			country_temp_array = ds_array[h].third_party.split("#");
// loop through each third party for the dispute
			for (i = 0; i < country_temp_array.length; i++)
			{
				found = 0;
				dispute = "";
// loop through array of countries
				for (j = 0; j < country_totals_array.length; j++)
				{
// if a record exists for the country as third party update the counter and add the dispute number
					if (country_temp_array[i] == country_totals_array[j][7])
					{
						country_totals_array[j][5] = country_totals_array[j][5] + 1;
						if (country_totals_array[j][6] != "")
						{
							country_totals_array[j][6] = country_totals_array[j][6] + "#" + ds_link;
						}
						else
						{
							country_totals_array[j][6] = country_totals_array[j][6] + ds_link;
						}
						found = 1;
						break;
					}
				}
// if no record exists create one
				if (found == 0)
				{
					dispute = dispute + ds_link;
					country_totals_array[j] = [country_temp_array[i], 0, "", 0, "", 1, dispute, country_temp_array[i]];
				}
			}		
		}
	}
// if some countries have been found
	if (country_totals_array.length > 0)
	{
// sort the array of countries alphabetically
		country_totals_array.sort();
// create a table 
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
		document.writeln("<tr><td width=\"20%\" valign=\"top\" class=\"graytd\">&nbsp;</td><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_complainant + "</p></td>");
    	document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_respondent + "</p></td><td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_third_party + "</p></td></tr>");
// write a new row in the table for each country order by country table name
        for (j = 0; j < country.length; j++)
		{
			for (h = 0; h < country_totals_array.length; h++)
			{
				if (country[j].code == country_totals_array[h][0])
				{
					document.write("<tr><td width=\"20%\" valign=\"top\" class=\"graytd\"><p class=\"paranormaltext\"><a name=\"" + country_totals_array[h][7].toLowerCase() + "\"></a>");
					if (country_totals_array[h][0] == "EEC")
					{
						document.writeln(eec_both + "<br>");
					}
					else
					{
						document.writeln(country[j].name + "<br>");
					}
					document.writeln("<span class=\"parasmalltext\">&gt;&nbsp;<a class=\"parasmallcolourtext\" href=\"" + dispu_maps_url + country_totals_array[h][7] + "&sense=e\">" + disputes_map_link + "</a></span></p></td>");
					if (country_totals_array[h][1] > 0)
					{
						document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\"><span class=\"parasmalltext\">" + as_complainant + "&nbsp;&mdash;&nbsp;" + country_totals_array[h][1]  + cases + "</span><br>");
						dispute_numbers_array = country_totals_array[h][2].split("#");
						for (i = 0; i < dispute_numbers_array.length; i++)
						{
							if (i > 0)
							{
								document.write(", ");
							}					
							document.write(dispute_numbers_array[i]);
						}
						document.writeln("&nbsp;</p></td>");
					}
					else
					{				
						document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"parasmalltext\">&mdash;</p></td>");
					}
					if (country_totals_array[h][3] > 0)
					{
						document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\"><span class=\"parasmalltext\">" + as_respondent + "&nbsp;&mdash;&nbsp;" + country_totals_array[h][3]  + cases + "</span><br>");
						dispute_numbers_array = country_totals_array[h][4].split("#");
						for (i = 0; i < dispute_numbers_array.length; i++)
						{
							if (i > 0)
							{
								document.write(", ");
							}					
							document.write(dispute_numbers_array[i]);
						}
						document.writeln("&nbsp;</p></td>");
					}
					else
					{
						document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"parasmalltext\">&mdash;</p></td>");
					}
					if (country_totals_array[h][5] > 0)
					{
						document.writeln("<td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\"><span class=\"parasmalltext\">" + as_third_party + "&nbsp;&mdash;&nbsp;" + country_totals_array[h][5]  + cases + "<br>");
						dispute_numbers_array = country_totals_array[h][6].split("#");
						for (i = 0; i < dispute_numbers_array.length; i++)
						{
							if (i > 0)
							{
								document.write(", ");
							}					
							document.write(dispute_numbers_array[i]);
						}
						document.writeln("&nbsp;</p></td></tr>");
					}
					else
					{
						document.writeln("<td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"parasmalltext\">&mdash;</p></td></tr>");
					}
					//country_totals_array.splice(country_totals_array[h], 1);
					break;
				}
			}
		}
		document.writeln("</table>");
	}
	return false;
}


// UPDATED***********************************************************************
// This function creates table on the disputes by country page showing
// countries that have made complaints with the countries against which 
// the complaint is made and the dispute number
//***********************************************************************
function disputesComplainantVRespondentTable()
{
	var complainant_array     = new Array();
	var country_array     	  = country;
	var country_temp1_array   = new Array();
	var country_temp2_array   = new Array();
	var respondents_array     = new Array();
	var dispute_numbers_array = new Array();
	var ds_link = "";
	var dispute = "";
	var found1 = 0;
	var found2 = 0;
	var h = 0;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;

// check each dispute in ds_array
	for (h = 1; h < ds_array.length; h++)
	{
		ds_link = dsNumberLink(h);
		country_temp1_array = ds_array[h].origin.split("#");
// loop though each complainant for the dispute
		for (i = 0; i < country_temp1_array.length; i++)
		{
			country_temp2_array = ds_array[h].destination.split("#");
// loop through each respondent for the dispute
			for (j = 0; j < country_temp2_array.length; j++)
			{
				found1 = 0;
				dispute = "";
// loop through array of encountered combinations
				for (k = 0; k < respondents_array.length; k++)
				{
// combination already encountered - update with details for dispute 					
					if ((country_temp1_array[i] == respondents_array[k][0]) && (country_temp2_array[j] == respondents_array[k][1]))
					{
						respondents_array[k][2] = respondents_array[k][2] + 1;
						if (respondents_array[k][3] != "")
						{
							respondents_array[k][3] = respondents_array[k][3] + "#" + ds_link;
						}
						else
						{
							respondents_array[k][3] = respondents_array[k][3] + ds_link;
						}
						found1 = 1;
						break;
					}
				}
// combination not yet encountered - add it to list
				if (found1 == 0)
				{
					dispute = dispute + ds_link;
					respondents_array[k] = [country_temp1_array[i], country_temp2_array[j], 1, dispute];
					found2 = 0;
					for (l = 0; l < complainant_array.length; l++)
					{
						if (complainant_array[l][0] == country_temp1_array[i])
						{
							complainant_array[l][1] = complainant_array[l][1] + 1;
							found2 = 1;
							break;
						}
					}
					if (found2 == 0)
					{
						complainant_array[l] = [country_temp1_array[i], 1];
					}
				}
			}
		}
	}
	if (respondents_array.length > 0)
	{
// sort arrays of complainants & respondents
		complainant_array.sort();
		respondents_array.sort();
// display the arrays in a table
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
		document.writeln("<tr><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paraboldtext\">" + complainant_text[0] + "</p></td><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paraboldtext\">"  + respondent + "</p></td>");
        document.writeln("<td width=\"50%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + disputes_text + "</p></td></tr>");
		for (h = 0; h < country.length; h++)
		{
			if (country[h].status == "MBR")
			{
				found1 = false;
				for (i = 0; i < complainant_array.length; i++)
				{
					if (complainant_array[i][0] == country[h].code) 
					{
						found1 == true;
						document.write("<tr><td width=\"25%\" valign=\"top\" class=\"graytd\" rowspan=\"" + complainant_array[i][1] + "\"><p class=\"paranormaltext\">");
						if (country[h].code == "EEC")
						{
							document.write(eec_both + "</p></td>");
						}
						else
						{
							document.write(country[h].name + "</p></td>");
						}
						for (j = 0; j < country_array.length; j++)
						{
							if (country_array[j].status == "MBR")
							{
								found2 = false;
								for (k = 0; k < respondents_array.length; k++)
								{
									if ((respondents_array[k][0] == country[h].code) && (respondents_array[k][1] == country_array[j].code))
									{
										document.write("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paranormaltext\">");
										if (country_array[j].code == "EEC")
										{
											document.write(eec_both);
										}
										else
										{
											document.write(country_array[j].name);
										}
										document.write("</p></td><td width=\"50%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\"><span class=\"parasmalltext\">" + respondents_array[k][2] + cases + "</span><br>");
										dispute_numbers_array = respondents_array[k][3].split("#");
										for (l = 0; l < dispute_numbers_array.length; l++)
										{
											if (l > 0)
											{
												document.write(", ");
											}					
											document.write(dispute_numbers_array[l]);
										}
										document.writeln("</p></td></tr>");
										found2 = true;
									}
									if ((found2 == true) && (respondents_array[k][0] != country[h].code))
									{
										break;
									}
								}
							}
						}
					}
				}
				if ((found1 == true) && (complainant_array[i][0] != country[h].code))
				{
					break;
				}
			}
		}
		document.writeln("</table>");
	}
	return false;
}

//***
function checkCheckBoxes()
{
	if (selected_complainant1 == "true")
	{
		document.getElementById("complainant1").checked = true;
	}
	else
	{
		document.getElementById("complainant1").checked = false;
	}
	if (selected_complainant2 == "true")
	{
		document.getElementById("complainant2").checked = true;
	}
	else
	{
		document.getElementById("complainant2").checked = false;
	}
	if (selected_respondent1 == "true")
	{
		document.getElementById("respondent1").checked = true;
	}
	else
	{
		document.getElementById("respondent1").checked = false;
	}
	if (selected_respondent2 == "true")
	{
		document.getElementById("respondent2").checked = true;
	}
	else
	{
		document.getElementById("respondent2").checked = false;
	}
	if (selected_thirdparty1 == "true")
	{
		document.getElementById("thirdparty1").checked = true;
	}
	else
	{
		document.getElementById("thirdparty1").checked = false;
	}
	if (selected_thirdparty2 == "true")
	{
		document.getElementById("thirdparty2").checked = true;
	}
	else
	{
		document.getElementById("thirdparty2").checked = false;
	}
}

//***********************************************************************
// This function takes the details submitted in the form on the Find
// disputes by case page and writes them to url prarmenters before reloading the
// page so that the relevant records will be displayed
//***********************************************************************
function findDisputesCases()
{
	var parametersSelected = "";
	parametersSelected += "year=" + document.getElementById("year").value;
	parametersSelected += "&subject=" + document.getElementById("subject").value;
	parametersSelected += "&agreement=" + document.getElementById("agreement").value;
	parametersSelected += "&member1=" + document.getElementById("member1").value;
	parametersSelected += "&member2=" + document.getElementById("member2").value;
	parametersSelected += "&complainant1=" + document.getElementById("complainant1").checked;
	parametersSelected += "&complainant2=" + document.getElementById("complainant2").checked;
	parametersSelected += "&respondent1=" + document.getElementById("respondent1").checked;
	parametersSelected += "&respondent2=" + document.getElementById("respondent2").checked;
	parametersSelected += "&thirdparty1=" + document.getElementById("thirdparty1").checked;
	parametersSelected += "&thirdparty2=" + document.getElementById("thirdparty2").checked;
	window.location = window.location.pathname + "?" + parametersSelected;
}


//***********************************************************************
// This function displays a summary of the options selected in the form
// on the Find disputes cases page. It then lists in reverse
// chronological order the disputes which match those options
//***********************************************************************
function showDisputesCases(casesTable)
{
	var disputes_array      = new Array();
	var subjects_array      = new Array();
	var member1_array   	= new Array();
	var member2_array  		= new Array();
	var agreement_array     = new Array();
	var split_agreement     = new Array();
	var temp_array          = new Array();
	var respondent_array    = new Array();
	var respondent          = "";   
	var cases_table = "";
	var num_rows = 0;
	var showOr1 = "";
	var showOr2 = "";
	var optionsSelected = 0;
	var matched = 0;
	var dispute_found = false;
	var h = 0;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var m = 0;
	var n = 0;
	var optionsString = "";
	var total_cases;

// build string sumarizing the options selected
	if ((selected_year != "none") && (selected_year != "any"))
	{
		optionsString +=  brought_text + " <b>" + selected_year + "</b> ";
	}
	if ((selected_agreement != "none") && (selected_agreement != "*"))
	{
		optionsString += citing_text + "<b>" + getAgreementName(selected_agreement) + "</b> ";
	}
	if ((selected_subject != "none") && (selected_subject != "*"))
	{
		optionsString += about_text + " <b>" + getSubjectName(selected_subject) + "</b> ";
	}
	if ((selected_member1 != "none") && (selected_member1 != "*"))
	{
		if (selected_member1 == "EEC")
		{
			optionsString += with_text + " <b>" + eec_both + "</b> ";
		}
		else
		{
			optionsString += with_text + " <b>" + getCountryName(selected_member1) + "</b> ";
		}
		if (selected_complainant1 == "true")
		{
			optionsString += as_complainant;
			showOr1 = my_or;
		}
		if (selected_respondent1 == "true")
		{
			optionsString += showOr1 + as_respondent;
			showOr1 = my_or;
		}
		if (selected_thirdparty1 == "true")
		{
			optionsString += showOr1 + as_third_party;
		}
	}
	if ((selected_member1 != "none") && (selected_member1 != "*") && (selected_member2 != "none") && (selected_member2 != "*"))
	{
			optionsString += my_and;
	}
	if ((selected_member2 != "none") && (selected_member2 != "*"))
	{
		if (selected_member2 == "EEC")
		{
			optionsString += with_text + " <b>" + eec_both + "</b> ";
		}
		else
		{
			optionsString += with_text + " <b>" + getCountryName(selected_member2) + "</b> ";
		}
		if (selected_complainant2 == "true")
		{
			optionsString += as_complainant;
			showOr2 = my_or;
		}
		if (selected_respondent2 == "true")
		{
			optionsString += showOr2 + as_respondent;
				showOr2 = my_or;
		}
		if (selected_thirdparty2 == "true")
		{
			optionsString += showOr2 + as_third_party;
		}
	}	
//		alert(optionsString);
// display string sumarizing the options selected
	optionsString = selection + optionsString + "<br>&nbsp;<br>";
// read the array record for each dispute		
	for (j = 1; j < ds_array.length; j++)
	{
		matched = 0;
		agreement_matched = false;
// dispute falls into date criteria
		if ((selected_year == "none") || (selected_year == "any") || (selected_year == ds_array[j].start_date.substring(0, 4)))
		{
			agreement_array = ds_array[j].agreement.split("#");
			for (n = 0; n < agreement_array.length; n++)
			{
				temp_agreement = agreement_array[n].split("_");
				{
					if ((selected_agreement == "none") || (selected_agreement == "*") || (selected_agreement == temp_agreement[0]))
					{
						subjects_array = ds_array[j].subject.split("#");
// loop through each subject for the dispute
						for (h = 0; h < subjects_array.length; h++)
						{
// dispute falls into the subject criteria
							if ((selected_subject == "none") || (selected_subject == "*") || (selected_subject == subjects_array[h]))
							{
								member1_array = ds_array[j].origin.split("#");
// loop through each complainant for the dispute
								for (k = 0; k < member1_array.length; k++)
								{
// dispute falls into the complainant criteria for the first member 
									if (((selected_member1 == "none") || (selected_member1 == "*") || ((selected_member1 == member1_array[k]) && (selected_complainant1 == "true")) || ((selected_member1 == member1_array[k]) && (selected_complainant1 == "false") && (selected_respondent1 == "false") && (selected_thirdparty1 == "false"))) && (matched == 0))
									{
										member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
										for (l = 0; l < member2_array.length; l++)
										{
// dispute falls into complainant criteria for both members - update list of matched disputes
											if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
											{
												disputes_array[m] = j;
												m = m + 1;
												matched = 1;
												break;
											}
										}
// dispute not yet matched
										if (matched == 0)
										{
											member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
												if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_respondent2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
										}
// dispute not yet matched
										if (matched == 0)
										{
											member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
												if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_thirdparty2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
										}

									}
								}
// dispute not yet matched
								if (matched == 0)
								{
									member1_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
									for (k = 0; k < member1_array.length; k++)
									{
// dispute falls into the respondent criteria for the first member 
										if (((selected_member1 == "none") || (selected_member1 == "*") || ((selected_member1 == member1_array[k]) && (selected_respondent1 == "true")) || ((selected_member1 == member1_array[k]) && (selected_complainant1 == "false") && (selected_respondent1 == "false") && (selected_thirdparty1 == "false"))) && (matched == 0))
										{
											member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute falls into complainant criteria for both members - update list of matched disputes
												if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
													if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_respondent2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
													if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_thirdparty2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
										}
									}
								}
// dispute not yet matched
								if (matched == 0)
								{
									member1_array = ds_array[j].third_party.split("#");
// loop through each THIRDPARTY for the dispute
									for (k = 0; k < member1_array.length; k++)
									{
// dispute falls into the thirdparty criteria for the first member 
										if (((selected_member1 == "none") || (selected_member1 == "*") || ((selected_member1 == member1_array[k]) && (selected_thirdparty1 == "true")) || ((selected_member1 == member1_array[k]) && (selected_complainant1 == "false") && (selected_respondent1 == "false") && (selected_thirdparty1 == "false"))) && (matched == 0))
										{
											member2_array = ds_array[j].origin.split("#");
// loop through each complainant again for the dispute
											for (l = 0; l < member2_array.length; l++)
											{
// dispute falls into complainant criteria for both members - update list of matched disputes
												if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
												{
													disputes_array[m] = j;
													m = m + 1;
													matched = 1;
													break;
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].destination.split("#");
// loop through each respondent for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
													if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_respondent2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
// dispute not yet matched
											if (matched == 0)
											{
												member2_array = ds_array[j].third_party.split("#");
// loop through each thir dparty for the dispute
												for (l = 0; l < member2_array.length; l++)
												{
// dispute matches complainant criteria for member 1 & third party criteria for member 2 - update list of matched disputes
													if (((selected_member2 == "none") || (selected_member2 == "*") || ((selected_member2 == member2_array[l]) && (selected_thirdparty2 == "true")) || ((selected_member2 == member2_array[l]) && (selected_complainant2 == "false") && (selected_respondent2 == "false") && (selected_thirdparty2 == "false"))) && (matched == 0))
													{
														disputes_array[m] = j;
														m = m + 1;
														matched = 1;
														break;
													}
												}
											}
										}
									}
								}
								break; // subject matched
							}
						}
						break;  // agreement matched
					}
				}
			}
		}															 
	}
// display total number of matching disputes on page
//		document.writeln("<p class=\"paranormaltext\"><b>Total: " + disputes_array.length + " cases matching your search criteria.</b></p><p class=\"paranormaltext\"></p>");
// If table of disputes exists delete all rows in it
	cases_table = document.getElementById(casesTable);
	num_rows = cases_table.rows.length;
	if (num_rows > 0)
	{
		for (i = 1; i <= num_rows; i++)
		{
			cases_table.deleteRow(cases_table.rows.length - 1);
		}
	}
// Get subjects for each dispute
	for (i = 0; i < disputes_array.length; i++)
	{
// Calculate date
		rfc_date = getDateString(ds_array[disputes_array[i]].start_date);
// Get respondent and title
		respondent = "";
		if (ds_array[disputes_array[i]].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[disputes_array[i]].start_date);
			respondent_array = ds_array[disputes_array[i]].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[disputes_array[i]].destination);
		}		
		dispute_title = respondent + " &mdash; <span class=\"paracolourtext\">" + ds_array[disputes_array[i]].title + "</span> (";
// Get complainants
		temp_country_array = ds_array[disputes_array[i]].origin.split("#");
		if (temp_country_array.length > 1)
		{
			dispute_title += complainant_text[1];
		}
		else
		{
			dispute_title += complainant_text[0];
		}
		for (k = 0; k < temp_country_array.length; k++)
		{
			dispute_title += checkEECName(temp_country_array[k], ds_array[disputes_array[i]].start_date);
			if (k < temp_country_array.length - 1)
			{
				dispute_title += "; ";
			}
		}
		dispute_title += ")";
// Output details to new row in table
		table_row = cases_table.insertRow(cases_table.rows.length);
		table_cell = table_row.insertCell(table_row.cells.length);
		table_cell.className = "graytd";
		table_cell.vAlign = "top";
		table_cell.innerHTML = "<a href=\"" + cases_link + ds_array[disputes_array[i]].code.toLowerCase() + "_" + language_letter + ".htm\" name=\"" + disputes_array[i] + "\" class=\"paraboldcolourtext\" onmouseover=\"writetxt(\'" + show_details_callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_array[disputes_array[i]].code + "</a>";
		table_cell = table_row.insertCell(table_row.cells.length);
		table_cell.className = "graytd";
		table_cell.vAlign = "top";
		table_cell.innerHTML = dispute_title;			
		table_cell = table_row.insertCell(table_row.cells.length);
		table_cell.className = "graytd";
		table_cell.vAlign = "top";
		table_cell.align = "right";
		table_cell.innerHTML = rfc_date;
		dispute_found = true;
	}
//	}
// No disputes message
	if (parameters_exist == true)
	{
		if (dispute_found == false)
		{
			total_cases = document.getElementById("total_cases");
			total_cases.innerHTML = optionsString + no_disputes;
		}
		else
		{
			total_cases = document.getElementById("total_cases");
			total_cases.innerHTML = optionsString + num_cases.replace("<insert_number>", disputes_array.length);
		}
	}
// Jump to table of disputes
	location.hash = "results";
	return false;
}


// UPDATED***********************************************************************
// This function displays a table listing the disputes that a specified
// country has been involved in as complainant, respondent or third
// party. The name of the country must be passed to the function as a 
// parameter and it must be written the same as the country name in
// ds_array. The function is for use on the country pages
//***********************************************************************
function disputesForCountryTable(countryNum)
{
	var country_totals_array = new Array();
	var country_temp_array = new Array();
	var dispute_numbers_array = new Array();
	var dispute = "";
	var otherparty = "";
	var otherparty2 = "";
	var found = 0;
	var h = 0;
	var i = 0;
	var j = 0;
// read the array record for each dispute
	for (h = 1; h < ds_array.length; h++)
	{
		country_temp_array = ds_array[h].origin.split("#");
// loop through each complainant for the dispute
		for (i = 0; i < country_temp_array.length; i++)
		{
			dispute = "";
// complainant is for desired country
			if (country_temp_array[i] == country[countryNum].code)
			{
// record doesn't exist - create it
				if (found == 0)
				{
					dispute = dispute + h;
					country_totals_array = [country_temp_array[i], 1, dispute, 0, "", 0, ""];
					found = 1;
				}
				else
// record exists - update it
				{
					country_totals_array[1] = country_totals_array[1] + 1;
					if (country_totals_array[2] != "")
					{
						country_totals_array[2] = country_totals_array[2] + "#" + h;
					}
					else
					{
						country_totals_array[2] = country_totals_array[2] + h;
					}
				}
			}
		}
		country_temp_array = ds_array[h].destination.split("#");
// loop through each respondent for the dispute
		for (i = 0; i < country_temp_array.length; i++)
		{
			dispute = "";
// respondent is for desired country
			if (country_temp_array[i] == country[countryNum].code)
			{
// record doesn't exist - create it
				if (found == 0)
				{
					dispute = dispute + h;
					country_totals_array = [country_temp_array[i], 0, "", 1, dispute, 0, ""];
					found = 1;
				}
				else
// record exists - update it
				{
					country_totals_array[3] = country_totals_array[3] + 1;
					if (country_totals_array[4] != "")
					{
						country_totals_array[4] = country_totals_array[4] + "#" + h;
					}
					else
					{
						country_totals_array[4] = country_totals_array[4] + h;
					}
				}
			}			
		}		
		country_temp_array = ds_array[h].third_party.split("#");
// loop through each third party for the dispute
		for (i = 0; i < country_temp_array.length; i++)
		{
			dispute = "";
// third party is for desired country
			if (country_temp_array[i] == country[countryNum].code)
			{
// record doesn't exist - create it
				if (found == 0)
				{
					dispute = dispute + h;
					country_totals_array = [country_temp_array[i], 0, "", 0, "", 1, dispute];
					found = 1;
				}
				else
// record exists - update it
				{
					country_totals_array[5] = country_totals_array[5] + 1;
					if (country_totals_array[6] != "")
					{
						country_totals_array[6] = country_totals_array[6] + "#" + h;
					}
					else
					{
						country_totals_array[6] = country_totals_array[6] + h;
					}
				}
			}
		}
	}
// write the details of matching cases in a table
	document.writeln("<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
	document.writeln("<tr><td width=\"20%\" valign=\"top\" class=\"graytd\">&nbsp;</td><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_complainant + "</p></td>");
    document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_respondent + "</p></td><td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + as_third_party + "</p></td></tr>");
	document.write("<tr><td width=\"20%\" valign=\"top\" class=\"graytd\"><p class=\"strippednormaltext\">");
	if (country[countryNum].code == "EEC")
	{
		document.writeln(eec_both + "</p");
	}
	else
	{
		document.writeln(country[countryNum].name + "</p>");
	}
	document.writeln("<p class=\"smallgreaterlistitem\">&gt;&nbsp;<a class=\"parasmallcolourtext\" href=\"" + dispu_maps_url + country[countryNum].code + "&sense=e\">" + disputes_map_link + "</a></p></td>");
// details for country exist - write them
	if (country_totals_array.length > 0)
	{
		if (country_totals_array[1] > 0)
		{
			document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[1]  + cases + "<br>");
			dispute_numbers_array = country_totals_array[2].split("#");
			for (i = 0; i < dispute_numbers_array.length; i++)
			{
				if (i > 0)
				{
					document.write(", ");
				}					
				document.write(dsNumberLink(dispute_numbers_array[i]));
			}
			document.writeln("</p></td>");
		}
		else
		{				
			document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[1]  + cases + "</p></td>");
		}
		if (country_totals_array[3] > 0)
		{
			document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[3]  + cases + "<br>");
			dispute_numbers_array = country_totals_array[4].split("#");
			for (i = 0; i < dispute_numbers_array.length; i++)
			{
				if (i > 0)
				{
					document.write(", ");
				}					
				document.write(dsNumberLink(dispute_numbers_array[i]));
			}
			document.writeln("</p></td>");
		}
		else
		{
			document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[3]  + cases + "</p></td>");
		}
		if (country_totals_array[5] > 0)
		{
			document.writeln("<td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[5]  + cases + "<br>");
			dispute_numbers_array = country_totals_array[6].split("#");
			for (i = 0; i < dispute_numbers_array.length; i++)
			{
				if (i > 0)
				{
					document.write(", ");
				}					
				document.write(dsNumberLink(dispute_numbers_array[i]));
			}
			document.writeln("</p></td></tr>");
		}
		else
		{
			document.writeln("<td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">" + country_totals_array[5]  + cases + "</p></td></tr>");
		}
	}
	else 
// details don't exist - write blank record
	{
		document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">0" + cases + "</p></td>");
		document.writeln("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">0" + cases + "</p></td>");
		document.writeln("<td width=\"30%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\">0" + cases + "</p></td></tr>");
	}
	document.writeln("</table>");
	return false;
}

// UPDATED ***********************************************************************
// This function displays a table of countries against which a complaint
// has been made and the countries which made the complaint
//***********************************************************************
function disputesRespondentVComplainantTable()
{
	var complainant_array     = new Array();
	var country_array     = country;
	var country_temp1_array   = new Array();
	var country_temp2_array   = new Array();
	var respondents_array     = new Array();
	var dispute_numbers_array = new Array();
	var ds_link = "";
	var dispute = "";
	var found1 = 0;
	var found2 = 0;
	var h = 0;
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;

// check each dispute in ds_array
	for (h = 1; h < ds_array.length; h++)
	{
		ds_link = dsNumberLink(h);
		country_temp1_array = ds_array[h].destination.split("#");
// loop though each respondebnt for the dispute
		for (i = 0; i < country_temp1_array.length; i++)
		{
			country_temp2_array = ds_array[h].origin.split("#");
// loop through each complainant for the dispute
			for (j = 0; j < country_temp2_array.length; j++)
			{
				found1 = 0;
				dispute = "";
// loop through array of encountered combinations
				for (k = 0; k < complainant_array.length; k++)
				{
// combination already encountered - update with details for dispute 					
					if ((country_temp1_array[i] == complainant_array[k][0]) && (country_temp2_array[j] == complainant_array[k][1]))
					{
						complainant_array[k][2] = complainant_array[k][2] + 1;
						if (complainant_array[k][3] != "")
						{
							complainant_array[k][3] = complainant_array[k][3] + "#" + ds_link;
						}
						else
						{
							complainant_array[k][3] = complainant_array[k][3] + ds_link;
						}
						found1 = 1;
						break;
					}
				}
// combination not yet encountered - add it to list
				if (found1 == 0)
				{
					dispute = dispute + ds_link;
					complainant_array[k] = [country_temp1_array[i], country_temp2_array[j], 1, dispute];
					found2 = 0;
					for (l = 0; l < respondents_array.length; l++)
					{
						if (respondents_array[l][0] == country_temp1_array[i])
						{
							respondents_array[l][1] = respondents_array[l][1] + 1;
							found2 = 1;
							break;
						}
					}
					if (found2 == 0)
					{
						respondents_array[l] = [country_temp1_array[i], 1];
					}
				}
			}
		}
	}
	if (complainant_array.length > 0)
	{
// sort arrays of complainants & respondents
		complainant_array.sort();
		respondents_array.sort();
// display the arrays in a table
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">");
		document.writeln("<tr><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paraboldtext\">" + respondent + "</p></td><td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paraboldtext\">"  + complainant_text[0] + "</p></td>");
        document.writeln("<td width=\"50%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paraboldtext\">" + disputes_text + "</p></td></tr>");
		for (h = 0; h < country.length; h++)
		{
			if (country[h].status == "MBR")
			{
				found1 = false;
				for (i = 0; i < respondents_array.length; i++)
				{
					if (respondents_array[i][0] == country[h].code) 
					{
						found1 == true;
						document.write("<tr><td width=\"25%\" valign=\"top\" class=\"graytd\" rowspan=\"" + respondents_array[i][1] + "\"><p class=\"paranormaltext\">");
						if (country[h].code == "EEC")
						{
							document.writeln(eec_both + "</p></td>");
						}
						else
						{
							document.writeln(country[h].name + "</p></td>");
						}
						for (j = 0; j < country_array.length; j++)
						{
							if (country_array[j].status == "MBR")
							{
								found2 = false;
								for (k = 0; k < complainant_array.length; k++)
								{
									if ((complainant_array[k][0] == country[h].code) && (complainant_array[k][1] == country_array[j].code))
									{
										document.write("<td width=\"25%\" valign=\"top\" class=\"graytd\"><p align=\"left\" class=\"paranormaltext\">");
										if (country_array[j].code == "EEC")
										{
											document.write(eec_both);
										}
										else
										{
											document.write(country_array[j].name);
										}
										document.writeln("</p></td><td width=\"50%\" valign=\"top\" class=\"graytd\"><p align=\"right\" class=\"paranormaltext\"><span class=\"parasmalltext\">" + complainant_array[k][2] + cases + "</span><br>");
										dispute_numbers_array = complainant_array[k][3].split("#");
										for (l = 0; l < dispute_numbers_array.length; l++)
										{
											if (l > 0)
											{
												document.write(", ");
											}					
											document.write(dispute_numbers_array[l]);
										}
										document.writeln("</p></td></tr>");
										found2 = true;
									}
									if ((found2 == true) && (complainant_array[k][0] != country[h].code))
									{
										break;
									}
								}
							}
						}
					}
				}
				if ((found1 == true) && (respondents_array[i][0] != country[h].code))
				{
					break;
				}
			}
		}
		document.writeln("</table>");
	}
	return false;
}



//***********************************************************************
// This function lists the years from the beginning of the WTO to the
// present with the range of disputes for the year in question
//***********************************************************************
function listYears()
{
	var year_array = new Array();
	var lastYear = 0;
	var lastDS = "";
	var h = 0;
	var i = 0;
	var count = 0;
	
// for each dispute in ds_array
	for (h = 1; h < ds_array.length; h++)
	{
// year for dispute has changed from that for previous dispute
		if (ds_array[h].start_date.substring(ds_array[h].start_date.length - 4) != lastYear)
		{
// update array of years
			if (i != 0)
			{
				year_array[i][2] = lastDS;
			}
			i = i + 1;
			lastYear = ds_array[h].start_date.substring(ds_array[h].start_date.length - 4);
			year_array[i] = [lastYear, h, 0];
		}
			lastDS = h;
	}
	year_array[i][2] = lastDS;
	document.writeln('<table>') 
	count = 1;
// loop through array of years and write details on page
	for (h = year_array.length - 1; h > 0 ; h--)
	{
		if (count == 1)
		{
			document.writeln('<tr>');
		}
		document.writeln('<td class="paranormaltext">&gt;&nbsp;<a href="#yr' + year_array[h][0] + '" class="paracolourtext">' + year_array[h][0] + '</a>: cases ' + year_array[h][1] + '-' + year_array[h][2] + '&nbsp;&nbsp;&nbsp; </td>');
		if (count == 4)
		{
			document.writeln('</tr>');
			count = 1;
		}
		else
		{
			count = count + 1;
		}
		
	}
	if (count != 1)
	{
		for (i = count; i <= 4; i++)
		{
			document.writeln('<td class="paranormaltext">&nbsp; </td>');
		}
		document.writeln('</tr></table>');
	}
	else
	{
		document.writeln('</table>');
	}
	return false;
}

// UPDATED***********************************************************************
// This function shows the chronological list of disputes on the list of
// disputes page
//***********************************************************************
function showChronList()
{
	var complainant_array = new Array();
	var respondent_array = new Array();
	var complainant = "";
	var respondent = "";
	var i = 0;
	var j = 0;

	if (ds_array.length > 1)
	{
		document.writeln("<table align=\"center\" cellSpacing=\"1\" cellPadding=\"3\" width=\"100%\" border=\"0\">");
// display details of disputes in reverse order
		for (i = ds_array.length - 1; i > 0; i--)
		{
			complainant = ""; 
			respondent = "";
		if (ds_array[i].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[i].start_date);
			respondent_array = ds_array[i].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[i].destination);
		}
			document.write("<tr><td valign=\"top\" class=\"graytd\"><a href=\"" + cases_link + ds_array[i].code.toLowerCase() + "_" + language_letter + ".htm\" name=\"" + i + "\" class=\"paraboldcolourtext\" onmouseover=\"writetxt(\'" + show_details_callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_array[i].code + "</a></td><td valign=\"top\" class=\"graytd\">" + respondent + " &mdash; <span class=\"paracolourtext\">" + ds_array[i].title + "</span> ");
			complainant_array = ds_array[i].origin.split("#");
			if (complainant_array.length == 1)
			{
				document.write(" (" + complainant_text[0]);
			}
			else
			{
				document.write(" (" + complainant_text[1]);
			}
			for (j = 0; j < complainant_array.length; j++)
			{
				if (complainant != "")
				{
					complainant += "; ";
				}
				complainant += checkEECName(complainant_array[j], ds_array[i].start_date);
			}
			document.write(complainant);
			document.writeln(")</td><td valign=\"top\" align=\"right\" class=\"graytd\">" + getDateString(ds_array[i].start_date) + "</td></tr>");
		}
		document.writeln("</table>");
	}	
	return false;
}

// NEW ***********************************************************************
// This function displays tables of the subjects index grouped by subject
// type with links to click to see the disputes for that subject
//***********************************************************************
function showSubjectIndex(outputTableName, subject, bookmark, numCases)
{
// Declare variables used by this function
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var numPerCol = 0;
	var itemCnt = 0;
	var subject_temp_array = new Array();

// Display separate table for each subject type
	for (i = 0; i < ds_subject_type.length; i++)
	{
// Output subject type name and start of table
		document.writeln("<table  width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
		document.writeln("<tr><td width=\"20%\" class=\"cellheadingwhitetext\">&nbsp;" + ds_subject_type[i].subject_type_name.toUpperCase() + "&nbsp;</td>");
		document.writeln("<td class=\"cellheadingblacktext\">&nbsp;</td></tr></table>");
		document.writeln("<table  style=\"border-style:solid; border-color:#800000; border-width:1px; border-collapse:collapse\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" border=\"1\">");
		document.writeln("<tr><td width=\"100%\"><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr>");
		subject_temp_array = [];
		k = 0;
// Loop through each subject code
		for (j = 0; j < ds_subject.length; j++)
		{
// If subject code matches the subject type write to temporary file 
			if (ds_subject[j].subject_id.substr(0, 1) == ds_subject_type[i].subject_type_code)
			{
				subject_temp_array[k] = [ds_subject[j].subject_name, ds_subject[j].subject_id];
				k += 1;
			}
		}
// Sort matching subjects alphabetically
		subject_temp_array.sort();
// Calculate how many subjects per column
		numPerCol = Math.ceil(subject_temp_array.length / 4);
		if (numPerCol > 0)
		{
			itemCnt = 0;
// List subjects in 4 columns
			for (k = 0; k < subject_temp_array.length; k++)
			{
				if (itemCnt == 0)
				{
					document.writeln("<td valign=\"top\" width=\"25%\">");
				}
				document.writeln("<p class=\"smallgreaterlistitem\">&gt;&nbsp;<a href=\"\" onclick=\"javascript:showSubjectDisputes('" + subject_temp_array[k][1] + "', '" + subject + "', '" + outputTableName + "', '" + bookmark + "', '" + numCases + "');return false\" class=\"parasmallcolourtext\" name=\"" + subject_temp_array[k][0].toLowerCase() + "\">" + subject_temp_array[k][0] + "</a></p>");
				itemCnt += 1;
				if (itemCnt == numPerCol)
				{
					document.writeln("</td>");
					itemCnt = 0;
				}
			}
		}
		
// Output end of table
		document.writeln("</tr></table></td></tr></table>");
		document.writeln("<p class=\"paranormaltext\">&nbsp;</p>");
		
	}
}


//**************************************************************************
function checkEECName(countryId, dsStartDate)
{
// Declare variable used by this function
	var country_name = "";
	if (countryId == "EEC")
	{
		if (dsStartDate >= "2009/12/01")
		{
			country_name = eec_new;
		}
		else
		{
			country_name = eec_old;
		}
	}
	else
	{
		country_name = getCountryName(countryId);
	}
	return country_name;
}


// NEW ***********************************************************************
// This function returns a country name based on the ISO country code -
// it uses the newsvars arrays
//***********************************************************************

function getCountryName(countryId)
{
// Declare variable used by this function
	var country_name = "";
	var i = 0;
// Loop through the country codes array
	for (i = 0; i < country.length; i++)
	{
// If country has required code return country name
		if (country[i].code == countryId)
		{
			country_name = country[i].name;
			break;
		}
	}

	return country_name;
}

// NEW ***********************************************************************
// This function returns a subject name based on the subject code -
//***********************************************************************

function getSubjectName(subjectId)
{
// Declare variable used by this function
	var subject_name = "";
	var i = 0;

// Loop through the country codes array
	for (i = 0; i < ds_subject.length; i++)
	{
// If country has required code return country name
		if (ds_subject[i].subject_id == subjectId)
		{
			subject_name = ds_subject[i].subject_name;
			break;
		}
	}
	return subject_name;
}

// NEW ***********************************************************************
// This function returns an agreement name based on the agreement code -
//***********************************************************************

function getAgreementName(agreementId)
{
// Declare variable used by this function
	var agreement_name = "";
	var i = 0;

// Loop through the country codes array
	for (i = 0; i < ds_agreement.length; i++)
	{
// If country has required code return country name
		if (ds_agreement[i].agreement_id == agreementId)
		{
			agreement_name = ds_agreement[i].agreement_name;
			break;
		}
	}
	return agreement_name;
}


//NEW ****************************************************************
function getDateString(YMDDate)
{
// Declare variables used by this function
	var date_string = "";
// Convert date
	date_string = parseInt(YMDDate.substr(8, 2), 10) + "&nbsp;" + month_array[parseInt(YMDDate.substr(5, 2), 10)] + "&nbsp;" + YMDDate.substr(0, 4);
	return date_string;
}

// NEW ***********************************************************************
// This function displays a table listing the disputes for the specified  
// subject with links to the page for that dispute 
//***********************************************************************
function showSubjectDisputes(subjectCode, subject, tableName, bookmark, numCases)
{
// Declare variables used by this function
	var temp_subject_array = new Array();
	var temp_country_array = new Array();
	var respondent_array = new Array();
	var respondent = "";
	var subject_title;
	var subject_table;
	var total_cases; 
	var table_row;
	var table_cell;
	var rfc_date;
	var dispute_title;
	var dispute_found = false;
	var num_rows = 0;
	var num_disputes = 0;
	var i = 0;
	var j = 0;
	var k = 0;
	
// Update subject heading
	subject_title = document.getElementById(subject);
	for (i = 0; i < ds_subject.length; i++)
	{
		if (ds_subject[i].subject_id == subjectCode)
		{
			subject_title.innerHTML = ds_subject[i].subject_name + "&nbsp; <a href=\"top\" class=\"parasmallgreytext\">" + back_to_top + "</a>";
			break;
		}
	}
// If table of disputes exists delete all rows in it
	subject_table = document.getElementById(tableName);
	num_rows = subject_table.rows.length;
	if (num_rows > 0)
	{
		for (i = 1; i <= num_rows; i++)
		{
			subject_table.deleteRow(subject_table.rows.length - 1);
		}
	}
// Get subjects for each dispute
	for (i = 1; i < ds_array.length; i++)
	{
		temp_subject_array = ds_array[i].subject.split("#");
		for (j = 0; j < temp_subject_array.length; j++)
		{
// If dispute has required subject code
			if (temp_subject_array[j] == subjectCode)
			{
				num_disputes += 1;
// Calculate date
				rfc_date = getDateString(ds_array[i].start_date);
// Get respondent and title
		if (ds_array[i].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[i].start_date);
			respondent_array = ds_array[i].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[i].destination);
		}		


				dispute_title = respondent + " &mdash; <span class=\"paracolourtext\">" + ds_array[i].title + "</span> (";
// Get complainants
				temp_country_array = ds_array[i].origin.split("#");
				if (temp_country_array.length > 1)
				{
					dispute_title += complainant_text[1];
				}
				else
				{
					dispute_title += complainant_text[0];
				}
				for (k = 0; k < temp_country_array.length; k++)
				{
					dispute_title += checkEECName(temp_country_array[k], ds_array[i].start_date);
					if (k < temp_country_array.length - 1)
					{
						dispute_title += "; ";
					}
				}
				dispute_title += ")";
// Output details to new row in table
				table_row = subject_table.insertRow(subject_table.rows.length);
				table_cell = table_row.insertCell(table_row.cells.length);
				table_cell.className = "graytd";
				table_cell.vAlign = "top";
				table_cell.innerHTML = "<a href=\"" + cases_link + ds_array[i].code.toLowerCase() + "_" + language_letter + ".htm\" name=\"" + i + "\" class=\"paraboldcolourtext\" onmouseover=\"writetxt(\'" + show_details_callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_array[i].code + "</a>";
				table_cell = table_row.insertCell(table_row.cells.length);
				table_cell.className = "graytd";
				table_cell.vAlign = "top";
				table_cell.innerHTML = dispute_title;			
				table_cell = table_row.insertCell(table_row.cells.length);
				table_cell.className = "graytd";
				table_cell.vAlign = "top";
				table_cell.align = "right";
				table_cell.innerHTML = rfc_date;
				dispute_found = true;
				break;
			}
		}
	}
// No disputes message
	if (dispute_found == false)
	{
		total_cases = document.getElementById(numCases);
		total_cases.innerHTML = no_disputes;
	}
	else
	{
		total_cases = document.getElementById(numCases);
		total_cases.innerHTML = num_cases.replace("<insert_number>", num_disputes);
	}
// Jump to table of disputes
	location.hash = bookmark;
}

// NEW ***********************************************************************
// This function displays tables of the subjects index grouped by subject
// type with links to click to see the disputes for that subject
//***********************************************************************
function showAgreementIndex(outputTableName, agreement, bookmark, numCases, agreementLink)
{
// Declare variables used by this function
	var i = 0;

// Output subject type name and start of table
	document.writeln("<table  width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
	document.writeln("<tr><td width=\"20%\" class=\"cellheadingwhitetext\">&nbsp;" + agreement_text.toUpperCase() + "&nbsp;</td>");
	document.writeln("<td class=\"cellheadingblacktext\">&nbsp;</td></tr></table>");
	document.writeln("<table  style=\"border-style:solid; border-color:#800000; border-width:1px; border-collapse:collapse\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" border=\"1\">");
	document.writeln("<tr><td width=\"100%\"><table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\"><tr>");
	document.writeln("<td valign=\"top\" width=\"100%\">");
	for (i = 0; i < ds_agreement.length; i++)
	{
		document.writeln("<p class=\"smallgreaterlistitem\">&gt;&nbsp;<a href=\"" + agreement_index_url + ds_agreement[i].agreement_id + "\" class=\"parasmallcolourtext\" >" + ds_agreement[i].agreement_short_name + "</a></p>");
	}
	document.writeln("</td>");
		
// Output end of table
	document.writeln("</tr></table></td></tr></table>");
	document.writeln("<p class=\"paranormaltext\">&nbsp;</p>");
}

// NEW ***********************************
function dsNumberLink(dsNumber)
{
// declare variables used by this function
	var linkString = "";
	var callout = "";
	var temp_country_array = new Array();
	var respondent_array = new Array();
	var respondent = "";
	var k = 0;
		if (ds_array[dsNumber].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[dsNumber].start_date);
			respondent_array = ds_array[dsNumber].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
			}
		else
		{
			respondent = getCountryName(ds_array[dsNumber].destination);
		}		

	callout = respondent + " &mdash; " + ds_array[dsNumber].title + " (";
// Get complainants
	temp_country_array = ds_array[dsNumber].origin.split("#");
	if (temp_country_array.length > 1)
	{
		callout += complainant_text[1];
	}
	else
	{
		callout += complainant_text[0];
	}
	for (k = 0; k < temp_country_array.length; k++)
	{
		callout += checkEECName(temp_country_array[k], ds_array[dsNumber].start_date);
		if (k < temp_country_array.length - 1)
		{
			callout += "; ";
		}
	}
	callout += ")";
	if (ds_array[dsNumber].reports_adopted == "true")
	{
		linkString = "<a class=\"paraboldcolourtext\" ";
	}
	else
	{
		linkString = "<a class=\"paracolourtext\" ";
	}
	linkString += "href=\"" + cases_link + ds_array[dsNumber].code.toLowerCase() + "_" + language_letter + ".htm\" onmouseover=\"writetxt(\'" + callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_array[dsNumber].code + "</a>";
	return linkString;
}

// NEW ***********************************************************************
// This function displays a table listing the disputes for the specified  
// agreement with links to the page for that dispute 
//***********************************************************************
function showAgreementDisputes(agreementCode, agreement, tableName, bookmark, numCases, agreementLink)
{
// Declare variables used by this function
	var temp_agreement_array = new Array();
	var temp_country_array = new Array();
	var respondent_array = new Array();
	var split_agreement_array = new Array();
	var temp_article_array = new Array();
	var split_sub_page_array = new Array();
	var split_parts_array = new Array();
	var temp_sub_page_array = new Array();
	var temp_parts_array = new Array();
	var bookmark_id_array = new Array();
	var page_array = new Array();
	var parts_page_array = new Array();
	var parts_id_array = new Array();
	var respondent = "";
	var agreement_page = "";
	var disputes_list = "";
	var dispute_link = "";
	var ds_link = "";
	var article_link = "";
	var agreement_title;
	var agreement_table;
	var display_agreement;
	var total_cases; 
	var table_row;
	var table_cell;
	var rfc_date;
	var dispute_title;
	var dispute_found = false;
	var not_article = false;
	var is_part = false;
	var article_matched = false;
	var num_rows = 0;
	var num_disputes = 0;
	var num_distinct_disputes = 0;
	var distinct_dispute_found = false;
	var distinct_disputes_array = new Array();
	var h = 0
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var m = 0;
	for (h = 0; h < ds_agreement.length; h++)
	{
		if (ds_agreement[h].agreement_id == agreementCode)
		{
			split_sub_page_array = ds_agreement[h].agreement_sub_page.split("#");
			if (split_sub_page_array[0] != "")
			{
				for (j = 0; j < split_sub_page_array.length; j++)
				{
					temp_sub_page_array = split_sub_page_array[j].split("*");
					for (k = 0; k < ds_article.length; k++)
					{
						if (ds_article[k].article_name == temp_sub_page_array[1])
						{
							bookmark_id_array[j] = k;
							page_array[j] = temp_sub_page_array[0];
							break;
						}
					}
				}
			}
			split_parts_array = ds_agreement[h].agreement_parts.split("#");
			if (split_parts_array[0] != "")
			{
				for (j = 0; j < split_parts_array.length; j++)
				{
					temp_parts_array = split_parts_array[j].split("*");
					for (k = 0; k < ds_article.length; k++)
					{
						if (ds_article[k].article_name == temp_parts_array[1])
						{
							parts_id_array[j] = k;
							parts_page_array[j] = temp_sub_page_array[0];
							break;
						}
					}
				}
			}
			document.writeln("<p class=\"paraboldcolourtext\"><a name=\"selected_agreement\"></a>" + ds_agreement[h].agreement_short_name + "&nbsp; <a href=\"top\" class=\"parasmallgreytext\">" + back_to_top + "</a></p>");
// Put link to legal text for agreement
			agreement_page = ds_agreement[h].agreement_url;
			break;
		}
	}
// Get agreements and articles for each dispute
	k = 0;
	for (i = 1; i < ds_array.length; i++)
	{
		distinct_dispute_found = false;
		dispute_link = dsNumberLink(i);
		temp_agreement_array = ds_array[i].agreement.split("#");
		for (j = 0; j < temp_agreement_array.length; j++)
		{
			split_agreement_array = temp_agreement_array[j].split("_");
			if (split_agreement_array[0] == agreementCode)
			{
				temp_article_array[k] = [split_agreement_array[1], 10000 + i, dispute_link];
				k += 1;
				if (distinct_dispute_found == false)
				{
					num_distinct_disputes++;
					distinct_dispute_found = true;
					ds_link = "<a href=\"" + cases_link + ds_array[i].code.toLowerCase() + "_" + language_letter + ".htm\" name=\"" + i + "\" class=\"paraboldcolourtext\" onmouseover=\"writetxt(\'" + show_details_callout + "\')\" onmouseout=\"writetxt(0)\">" + ds_array[i].code + "</a>";
// Calculate date
					rfc_date = getDateString(ds_array[i].start_date);
// Get respondent and title
respondent = "";
		if (ds_array[i].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[i].start_date);
			respondent_array = ds_array[i].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[i].destination);
		}		


					dispute_title = respondent + " &mdash; <span class=\"paracolourtext\">" + ds_array[i].title + "</span> (";
// Get complainants
					temp_country_array = ds_array[i].origin.split("#");
					if (temp_country_array.length > 1)
					{
						dispute_title += complainant_text[1];
					}
					else
					{
						dispute_title += complainant_text[0];
					}
					for (m = 0; m < temp_country_array.length; m++)
					{
						dispute_title += checkEECName(temp_country_array[m], ds_array[i].start_date);
						if (m < temp_country_array.length - 1)
						{
						dispute_title += "; ";
						}
					}
					dispute_title += ")";
					distinct_disputes_array[distinct_disputes_array.length] = [10000 + i, dispute_title, rfc_date, ds_link];
				}
			}
		}
	}
	document.writeln("<p class=\"paraboldtext\">" + num_distinct_disputes + cite_agreeement_text + "</p>");
// Put link to legal text for agreement
	if (ds_agreement[h].agreement_url != "")
	{
		document.writeln("<p class=\"parasmalltext\" align=\"right\">&gt;&nbsp;<a href=\"" + legal_text_url + ds_agreement[h].agreement_url + "\" class=\"parasmallcolourtext\">" + agreement_link + "</a></p>");
	}
	if (num_distinct_disputes > 0)
	{
		distinct_disputes_array.sort();
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"3\" width=\"100%\" border=\"0\">");
// Loop through all the disputes for agreement
		for (i = distinct_disputes_array.length - 1; i >= 0; i--)
		{
			document.writeln("<tr><td class=\"graytd\" valign=\"top\" width=\"20%\">" + distinct_disputes_array[i][3] + "</td>");
			document.writeln("<td class=\"graytd\" valign=\"top\" >" + distinct_disputes_array[i][1] + "</td>");
			document.writeln("<td class=\"graytd\" valign=\"top\" >" + distinct_disputes_array[i][2] + "</td></tr>");	
		}
		document.writeln("</table>");
		document.writeln("<p class=\"paranormaltext\" >&nbsp;</p>");
		document.writeln("<p class=\"paraboldtext\" >" + agreement_details_title + "</p>");
		document.writeln("<p class=\"parasmalltext\" >" + agreement_details_intro + "</p>");
		temp_article_array.sort();
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"3\" width=\"100%\" border=\"0\">");
// Loop through all the articles
		for (i = 0; i < ds_article.length; i++)
		{
			disputes_list = "";
			num_disputes = 0;
// Loop through list of articles cited
			for (j = 0; j < temp_article_array.length; j++)
			{
// If an article has been cited add dispute details to list
				if (temp_article_array[j][0] == ds_article[i].article_id)
				{
					if (disputes_list != "")
					{
						disputes_list += ", ";
					}
					disputes_list += temp_article_array[j][2];
					num_disputes += 1;
				}
				else if (num_disputes > 0)
				{
					break;
				}
			}
// Output details to new row in table
			if (disputes_list != "")
			{
				for (k = 1; k < article_array.length; k++)
				{
					if (ds_article[i].article_name.indexOf(article_array[k]) != -1)
					{
						not_article = true;
						break;
					}
				}
				if (ds_article[i].article_name.indexOf(article_array[2]) != -1)
					{
					is_part = true;
				}
				if (agreement_page != "")
				{
				article_link = "<a class=\"paraboldcolourtext\" href=\"" + legal_text_url;
// Article is not a part	
				if (is_part == false)
				{
					if (split_sub_page_array[0] == "")
					{
						article_link += agreement_page + "#" + ds_article[i].article_bookmark;
					}
					else
					{
						for (l = 0; l < bookmark_id_array.length; l++)
						{
							if ((l == 0) && (bookmark_id_array[l] > i))
							{
								article_link += agreement_page + "#" + ds_article[i].article_bookmark;
								break;
							}
							else if (bookmark_id_array[l] > i)
							{
								article_link += page_array[l - 1] + "#" + ds_article[i].article_bookmark;
								break;
							}
							else if ((l == bookmark_id_array.length - 1) && (i >= bookmark_id_array[l]))
							{
								article_link += page_array[l] + "#" + ds_article[i].article_bookmark;
								break;
							}
						}
					
					}
				}
				else
// Article is a part
				{
					if (split_parts_array[0] == "")
					{
						article_link += agreement_page + "#" + ds_article[i].article_bookmark;
					}
					else
					{
						for (l = 0; l < parts_id_array.length; l++)
						{
							if ((l == 0) && (parts_id_array[l] > i))
							{
								article_link += agreement_page + "#" + ds_article[i].article_bookmark;
								break;
							}
							else if (parts_id_array[l] > i)
							{
								article_link += parts_page_array[l - 1] + "#" + ds_article[i].article_bookmark;
								break;
							}
							else if ((l == parts_id_array.length - 1) && (i >= parts_id_array[l]))
							{
								article_link += parts_page_array[l] + "#" + ds_article[i].article_bookmark;
								break;
							}
						}					
					}
				}
// Decide whether to display "Article" or not
				if (not_article == true)
				{	
					article_link += "\">" + ds_article[i].article_name + "</a>";
				}
				else
				{
					article_link += "\">" + article_array[0] + ds_article[i].article_name + "</a>";	
				}
				}
				else
				{
				if (not_article == true)
				{	
					article_link = ds_article[i].article_name;
				}
				else
				{
					article_link = article_array[0] + ds_article[i].article_name;	
				}
				}
				document.writeln("<tr><td class=\"graytd\" valign=\"top\" width=\"20%\">" + article_link + "</td>");
				document.writeln("<td class=\"graytd\" valign=\"top\">" + num_disputes + cases + "<br>" + disputes_list + "</td></tr>");
			}
		}
	}
	document.writeln("</table>");
// Jump to table of disputes
	location.hash = "selected_agreement";
}


// NEW ****************************************
function showDisputesForAgreement(agreementId)
{
	var temp_agreement_array = new Array();
	var split_agreement_array = new Array();
	var disputes_list = "";
	var num_cases = 0;
	var i = 0;
	var j = 0;
		
	for (i = 1; i < ds_array.length; i++)
	{
		temp_agreement_array = ds_array[i].agreement.split("#");
		for (j = 0; j < temp_agreement_array.length; j++)
		{
			split_agreement_array = temp_agreement_array[j].split("_");
			if (split_agreement_array[0] == ds_agreement[agreementId].agreement_id)
			{
				if (disputes_list != "")
				{
					disputes_list += ", ";
				}
				disputes_list += dsNumberLink(i);
				num_cases += 1;
				break;
			}
		}
	}
	if (disputes_list != "")
	{
		document.writeln("<p class=\"paranormaltext\">" + ds_intro + "</p>");
		document.writeln("<table cellSpacing=\"1\" cellPadding=\"3\" width=\"100%\" border=\"0\"><tr><td class=\"graytd\" valign=\"top\" width=\"20%\">" + num_cases + cases  + "</td><td class=\"graytd\" valign=\"top\">" + disputes_list + "</td></tr> </table>");
		document.writeln("<p class=\"parasmalltext\" align=\"right\">&gt;&nbsp;<a href=\"" + agreement_index_url + ds_agreement[agreementId].agreement_id + "\" class=\"parasmallcolourtext\">" + article_link + "</a></p>");
	}

}



//UPDATED ***********************************************************************
// This function takes the dispute number a user has typed into a text 
// box, validates it, then opens the page for that dispute
//***********************************************************************
function showDispute()
{
	var totalDisputes = ds_array.length - 1;
	var disputeSelected = document.hiddenform.elements["dispute_number"].value;	
	if (disputeSelected == "")
	{
		alert(show_dispute_alert);
	}
	else
	{
		if ((parseInt(disputeSelected) <= 0) || (parseInt(disputeSelected) > totalDisputes) || (isNaN(disputeSelected)))
		{
			alert(show_dispute_error + totalDisputes);
		}
		else
		{
			window.location = cases_link + "ds" + parseInt(disputeSelected) + "_" + language_letter + ".htm";
		}
	}
}


//***********************************************************************
// This function builds a form dropdown list of disputes from the arrays
//***********************************************************************
function bldDisputesList(currentVal)
{
	var i = 0;
	var j = 0;
	var display_string = "";
	var respondent_array = new Array();
	var respondent = "";

// write general options on page
	window.document.write('<option value="none"');
	if (currentVal == "none")
	{
		window.document.write(' selected');
	}
	window.document.writeln('>' + select_dispute[0] + '</option>');
// write option for each subject in the list on the page			
	for ( i = 1; i < ds_array.length; i++)
	{
		if (ds_array[i].destination.indexOf("EEC") != -1)
		{
			respondent = checkEECName("EEC", ds_array[i].start_date);
			respondent_array = ds_array[i].destination.split("#");
			switch (respondent_array.length){
				case 1:
				break;
				case 2:
				respondent += eec_single_member;
				break;
				default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[i].destination);
		}
		display_string = ds_array[i].code + ': ' + respondent + ' &mdash; ' + ds_array[i].title;
		window.document.write('<option value="' + ds_array[i].code + '"');
		if (currentVal == ds_array[i].code)
		{
			window.document.write(' selected');
		}
		window.document.writeln('>' + display_string.slice(0, 150) + '</option>');
	}
	return false;	 	
}

// Function to insert a callout text from a variable
function doCallout(textToDisplay)
{
	writetxt(textToDisplay);
	return false;	 	
}

// function to display title for a ds number
function disputeTitle(dsNum)
{
	var dispute_temp_array = new Array();
	var respondent_array = new Array();
	dispute_temp_array = dsNum.split("_");
	var respondent = "";
	if (ds_array[dispute_temp_array[0]].destination.indexOf("EEC") != -1)
	{
		respondent = checkEECName("EEC", ds_array[dispute_temp_array[0]].start_date);
		respondent_array = ds_array[dispute_temp_array[0]].destination.split("#");
		switch (respondent_array.length){
			case 1:
				break;
			case 2:
				respondent += eec_single_member;
				break;
			default:
				respondent += eec_multiple_member;
				break;
			}
		}
		else
		{
			respondent = getCountryName(ds_array[dispute_temp_array[0]].destination);
		}		

//	window.document.writeln("<p class=\"paraboldcolourtext\">DS" + dsNum.replace(/_/g, ", DS") + ": " + checkEECName(ds_array[dispute_temp_array[0]].destination, ds_array[dispute_temp_array[0]].start_date) + " &mdash; " + ds_array[dispute_temp_array[0]].title + "</p>");
	window.document.writeln("<p class=\"paraboldcolourtext\">DS" + dsNum.replace(/_/g, ", DS") + ": " + respondent + " &mdash; " + ds_array[dispute_temp_array[0]].title + "</p>");
}


//***********************************************************************
// This function 
//***********************************************************************
function bldDispuMapForm()
{
// display the options to select
	document.writeln("<input name=\"arrowSense\" type=\"radio\" value=\"c\"");
	if (sense == "c")
	{
		document.write( " checked");
	}
	document.write(">&nbsp;" + as_complainant + "<br><input name=\"arrowSense\" type=\"radio\" value=\"r\"");
	if (sense == "r")
	{
		document.write(" checked");
	}
		document.write(">&nbsp;" + as_respondent + "<br><input name=\"arrowSense\" type=\"radio\" value=\"e\"");
	if (sense == "e")
	{
		document.write(" checked");
	}
	document.writeln(">&nbsp;" + as_either + "<br>");
	document.writeln("<input type=\"submit\" name=\"Submit\" value=\"Submit\" onClick=\"showMap();return false\" class=\"paraboldcolourtext\">");
}


function bldAdvancedDispuMapForm()
{
// display the options to select
	document.writeln("<input name=\"arrowSense\" type=\"radio\" value=\"c\"");
	if (sense == "c")
	{
		document.write( " checked");
	}
	document.write(">&nbsp;" + as_complainant + "<br><input name=\"arrowSense\" type=\"radio\" value=\"r\"");
	if (sense == "r")
	{
		document.write(" checked");
	}
		document.write(">&nbsp;" + as_respondent + "<br><input name=\"arrowSense\" type=\"radio\" value=\"e\"");
	if (sense == "e")
	{
		document.write(" checked");
	}
	document.writeln(">&nbsp;" + as_either + "<br>");
	document.writeln("<input type=\"submit\" name=\"Submit\" value=\"Submit\" onClick=\"showMap3();return false\" class=\"paraboldcolourtext\">");
}

function showMap()
{
	var i = 0;
	var countrySelected  = document.hiddenform.elements['selectedCountry'].selectedIndex;	
	if (countrySelected == "1")
	{
		country_selected  = "none";
	}
	else
	{
		country_selected  = document.hiddenform.elements['selectedCountry'].options[countrySelected].value;	
	}
// find which radio buttons are on
	for (i = 0; i < document.hiddenform.elements['arrowSense'].length; i++)
	{
		if (document.hiddenform.elements['arrowSense'][i].checked == true)
		{
			sense = document.hiddenform.elements['arrowSense'][i].value;
			break;
		}
	}
// reload the page with selected values on the url
	window.location.search = "?country_selected=" + escape(country_selected) + "&sense=" + sense;
	return false;

}

function showMap2()
{
	var i = 0;
	var dsSelected  = document.hiddenform.elements['selectedDispute'].selectedIndex;	
	if (dsSelected == "1")
	{
		dispute_selected  = "none";
	}
	else
	{
		dispute_selected  = document.hiddenform.elements['selectedDispute'].options[dsSelected].value;	
	}
// reload the page with selected values on the url
	window.location.search = "?dispute_selected=" + escape(dispute_selected);
	return false;

}

function showMap3()
{
	var i = 0;
	var yearSelected = document.hiddenform.elements['selectedYear'].selectedIndex;
	if (yearSelected == "1")
	{
		year_selected  = "none";
	}
	else
	{
		year_selected  = document.hiddenform.elements['selectedYear'].options[yearSelected].value;	
	}
	var agreementSelected = document.hiddenform.elements['selectedAgreement'].selectedIndex;
	if (agreementSelected == "1")
	{
		agreement_selected  = "none";
	}
	else
	{
		agreement_selected  = document.hiddenform.elements['selectedAgreement'].options[agreementSelected].value;	
	}
	var subjectSelected = document.hiddenform.elements['selectedSubject'].selectedIndex;
	if (subjectSelected == "1")
	{
		subject_selected  = "none";
	}
	else
	{
		subject_selected  = document.hiddenform.elements['selectedSubject'].options[subjectSelected].value;	
	}

	var countrySelected  = document.hiddenform.elements['selectedCountry'].selectedIndex;	
	if (countrySelected == "1")
	{
		country_selected  = "none";
	}
	else
	{
		country_selected  = document.hiddenform.elements['selectedCountry'].options[countrySelected].value;	
	}
// find which radio buttons are on
	for (i = 0; i < document.hiddenform.elements['arrowSense'].length; i++)
	{
		if (document.hiddenform.elements['arrowSense'][i].checked == true)
		{
			sense = document.hiddenform.elements['arrowSense'][i].value;
			break;
		}
	}
// reload the page with selected values on the url
	window.location.search = "?country_selected=" + escape(country_selected) + "&year_selected=" + escape(year_selected) + "&agreement_selected=" + escape(agreement_selected) + "&subject_selected=" + escape(subject_selected) + "&sense=" + sense;
	return false;

}
function buildSelectiveDisputesArray()
{
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var m = 0;
	var matched = false;
	var agreement_array = new Array();
	var temp_agreement = new Array();
	var subject_array =new Array();
	var member1_array = new Array();
	var member2_array = new Array();
	for (i = 0; i < matching_ds_array.length; i++)
	{
		matching_ds_array.pop();
	}
	matching_ds_array.push({ code: "", title: "", origin: "", destination: "", third_party: "", start_date: "", update_date: ""});
	for (i = 1; i < ds_array.length; i++)
	{
		matched = false;
		if ((year_selected == "none") || (ds_array[i].start_date.slice(0,4) == year_selected))
		{
			agreement_array = ds_array[i].agreement.split("#");
			for (j = 0; j < agreement_array.length; j++)
			{
				temp_agreement = agreement_array[j].split("_");
				{
					if ((agreement_selected == "none") || (agreement_selected == temp_agreement[0]))
					{
						subjects_array = ds_array[i].subject.split("#");
// loop through each subject for the dispute
						for (k = 0; k < subjects_array.length; k++)
						{
// dispute falls into the subject criteria
							if ((subject_selected == "none") || (subject_selected == subjects_array[k]))
							{
								member1_array = ds_array[i].origin.split("#");
// loop through each complainant for the dispute
								for (l = 0; l < member1_array.length; l++)
								{
// dispute falls into the complainant criteria for the first member 
									if ((country_selected == "none") || ((country_selected == member1_array[l]) && (sense == "c")) || ((country_selected == member1_array[l]) && (sense == "e")))
									{
										matching_ds_array.push({ code: ds_array[i].code, title: ds_array[i].title, origin: ds_array[i].origin, destination: ds_array[i].destination, third_party: ds_array[i].third_party, start_date: ds_array[i].start_date, update_date: ds_array[i].update_date});
										matched = true;
										break;
									}
								}
// dispute not yet matched
								if (matched == false)
								{
									member2_array = ds_array[i].destination.split("#");
// loop through each respondent for the dispute
									for (m = 0; m < member2_array.length; m++)
									{
// dispute matches complainant criteria for member 1 & repondent criteria for member 2 - update list of matched disputes
										if ((country_selected == "none") || ((country_selected == member2_array[m]) && (sense == "r")) || ((country_selected == member2_array[m]) && (sense == "e")))
										{
											matching_ds_array.push({ code: ds_array[i].code, title: ds_array[i].title, origin: ds_array[i].origin, destination: ds_array[i].destination, third_party: ds_array[i].third_party, start_date: ds_array[i].start_date, update_date: ds_array[i].update_date});
											matched = true;
											break;
										}
									}
								}
								break;
							}
						}
						break;
					}
				}
			}
//			break;
		}
	}
	//alert(matching_ds_array.length);

}

// functiom to display the current status and date on which that status was achieved on the page for an individual case
function showCurrentStatus(dsnumber)
{
	var status_array = new Array();
	var status_split_array = new Array();
	if ((dsnumber > 0) && (dsnumber < ds_array.length))
	{
		status_array = ds_array[dsnumber].status.split("|");
		for (i = 0; i < status_array.length; i++)
		{
			status_split_array = status_array[i].split("#");
			for (j = 0; j < ds_status.length; j++)
			{
				if (ds_status[j].status_code == status_split_array[0])
				{
					document.write("<span class=\"paraboldcolourtext\">" + ds_status[j].status_name + "</span> ");
					if (status_split_array.length > 2)
					{
						document.write(status_split_array[2]);
					}
					document.write(on_text + "<b>" + getDateString(status_split_array[1]) + "</b> <img src=\"/images/img_navig/i_red.gif\"  onMouseOver=\"writetxt('" + ds_status[j].status_description + "')\" onMouseOut=\"writetxt(0)\"><br>");
					
				}
			}
		}
	}
	else
	{
		document.write("&nbsp;");
	}
	return false;			

}


// function to display a list of stati & all disputes for that status
//***********************************************************************
function showDisputeStatus(tablename)
{
	var i = 0;
	var j = 0;
	var k = 0;
	var l = 0;
	var m = 0;
	var total = 0;
	var found = false;
	var status_year = "";
	var country_temp_array = new Array();
	var status_array = new Array();
	var status_split_array = new Array();
	var output_array = new Array(2);
	var test_date = new Date(1995, 0, 1);
	var test_milliseconds = test_date.getTime();
	var now_date = new Date();
	
	if (periodSelected != "")
	{
		test_milliseconds = now_date.getTime() - (parseInt(periodSelected, 10) * 1000 * 60 * 60 * 24);	
	}
		var status_table = document.getElementById(tablename);
		var num_rows = status_table.rows.length;
		if (num_rows > 0)
		{
			for (i = 1; i <= num_rows; i++)
			{
				status_table.deleteRow(status_table.rows.length - 1);
			}
		}

	for (i = 0; i < ds_status.length; i++)
	{
		var count = 0;
		var output_text = "";
		var years_array = new Array();
		for (j = 1; j < ds_array.length; j++)
		{
			status_array = ds_array[j].status.split("|");
			for (k = 0; k < status_array.length; k++)
			{
				status_split_array = status_array[k].split("#");
				if (ds_status[i].status_code == status_split_array[0])
				{
					var countryOK = false;
					if ((countrySelected == "" ) || (countrySelected == "none"))
					{
						countryOK = true;
					}
					else
					{
						if (complainantSelected == true)
						{
							country_temp_array = ds_array[j].origin.split("#");
							for (m = 0; m < country_temp_array.length; m++)
							{
								if (country_temp_array[m] == countrySelected)
								{
									countryOK = true;
									break;
								}
							}
						}
						if (respondentSelected == true)
						{
							country_temp_array = ds_array[j].destination.split("#");
							for (m = 0; m < country_temp_array.length; m++)
							{
								if (country_temp_array[m] == countrySelected)
								{
									countryOK = true;
									break;
								}
							}
						}
						if (thirdpartySelected == true)
						{
							country_temp_array = ds_array[j].third_party.split("#");
							for (m = 0; m < country_temp_array.length; m++)
							{
								if (country_temp_array[m] == countrySelected)
								{
									countryOK = true;
									break;
								}
							}
						}
					}
					if (countryOK == true)
					{
					var compare_date = new Date(parseInt(status_split_array[1].substr(0,4), 10), parseInt(status_split_array[1].substr(5,2), 10) -1, parseInt(status_split_array[1].substr(8,2), 10));
					if (compare_date.getTime() >= test_milliseconds)
					{
						total++;
					count += 1;
						if (ds_status[i].status_code != "ST1")
						{
							if (output_text != "")
							{
								output_text += ", ";
							}
							output_text += dsNumberLink(j);
						}
						else
						{
							if (status_split_array.length > 1)
							{
								found = false;
								status_year = status_split_array[1].substring(0, 4);
								if (years_array.length > 0)
								{
									for (l = 0; l < years_array.length; l++)
									{
										if (status_year == years_array[l][0])
										{
											years_array[l][1] = years_array[l][1] + ", " + dsNumberLink(j);
											found = true;
											break;
										}
									}
								}
								if (found == false)
								{
									years_array[years_array.length] = [status_year, dsNumberLink(j)];
								}
							}
						}
						break;
					}
					}
				}
			}		
		}
		
		output_array[0] = "merge";
		output_array[1] = "<p class=\"paracolourtext\"><a name=\"#" + ds_status[i].status_code.toLowerCase() + "\"></a><span   onMouseOver=\"writetxt('" + ds_status[i].status_description + "')\" onMouseOut=\"writetxt(0)\"><b>" + ds_status[i].status_name + "</b>&nbsp; <img src=\"/images/img_navig/i_red.gif\"></span><br><a href=\"" + ds_status[i].status_link + "\" class=\"parasmallcolourtext\">" + explanation + "</a><br>" + count + cases + "</p>";
		addrow(tablename, output_array);
		if (ds_status[i].status_code != "ST1")
		{
			if (output_text != "")
			{
				output_array[1] = "<p class=\"paranormaltext\"><b>"+ cases_text + output_text + "</p>";
				addrow(tablename, output_array);
			}
		}
		else 
		{
			for (l = 0; l < years_array.length; l++)
			{
				output_array[0] = "<p class=\"paraboldtext\">" + since_text + years_array[l][0] + ":</p>";
				output_array[1] = years_array[l][1];
				addrow(tablename, output_array);
			}
		}
		output_array[0] = "merge";
		output_array[1] = "<p class=\"paranormaltext\">&nbsp;</p>";
		addrow(tablename, output_array);
	}
		var totaltext = document.getElementById("total");
		totaltext.innerHTML = total_cases.replace("<insert_number>", ds_array.length-1);
}

function statusLimitTimespan()
{
	periodSelected = document.getElementById("timespan").value;	

	showDisputeStatus("statustable");		
}

function statusLimitCountry()
{
	countrySelected = document.getElementById("member").value;	
	complainantSelected = document.getElementById("complainant").checked;	
	respondentSelected = document.getElementById("respondent").checked;	
	thirdpartySelected = document.getElementById("thirdparty").checked;	
	if ((countrySelected != "none") && (complainantSelected == false) && (respondentSelected == false) && (thirdpartySelected == false))
	{
		alert(status_alert);
	}
	else
	{
		showDisputeStatus("statustable");
	}
}


function addrow(tablename, array) 
{
	var colspan = 1;
	var r = 0;
	var grptbl = document.getElementById(tablename);
	var lastRow = grptbl.rows.length;
	var grprow = grptbl.insertRow(lastRow);
   for (r = 0; r < array.length; r++) 
	{   
		if (array[r] == "merge")
		{
			colspan += 1;
		}
		else
		{	
			var grpcell = grprow.insertCell(r - colspan + 1);
        	grpcell.innerHTML = array[r];
			grpcell.className = "subnormaltext";
			grpcell.vAlign = "top";
			if (colspan > 1)
			{
				grpcell.colSpan = colspan;
			}
			colspan = 1;
		}
     }
	
 }
//-->


