/*
	LIST OF COUNTRIES AND THEIR CODES
*/
var country_arr = new Array("Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua & Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia & Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Zaire", "Cook Islands", "Costa Rica", "Cote D'ivoire (Ivory Coast)", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "United Kingdom", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard & McDonald Islands", "Vatican City (Holy See)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea (North)", "Korea (South)", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "St. Helena", "Saint Kitts & Nevis", "Saint Lucia", "St. Pierre & Miquelon", "St. Vincent & the Grenadines", "Samoa", "San Marino", "Sao Tome & Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovak Republic", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "S.Georgia & S.Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard & Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Togo", "Tokelau", "Tonga", "Trinidad & Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks & Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Viet Nam", "Virgin Islands (British)", "Virgin Islands (U.S.)", "Wallis & Futuna Islands", "Western Sahara", "Yemen", "Yugoslavia", "Zambia", "Zimbabwe");
var country_code = new Array("AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "TP", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GB", "GR", "GL", "GD", "GP", "GU", "GT", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IL", "IT", "JM", "JP", "JO", "KZ", "KE", "KI", "KP", "KR", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "SH", "KN", "LC", "PM", "VC", "WS", "SM", "ST", "SA", "SN", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS", "ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "US", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "YU", "ZM", "ZW");

/*
	USE IN VIEWING AN ORGANISATION
		- GETS/SETS THE COUNTRY LIST
*/
function print_countries_view(TEXTAllCountries, country_id, value){
	// given the id of the <select> tag as function argument, it inserts <option> tags
	var option_str = document.getElementById(country_id);
	var x, i=0;
	for(x in country_arr){
		if(i==0){
			option_str.options[i++] = new Option(TEXTAllCountries,'ANY');
		}else{
			option_str.options[i++] = new Option(country_arr[x],country_code[x]);
		}
	}
	
	if(value != null)
	{
		setSelectedIndex(option_str, value);
	}
}

/*
	USE IN REGISTERING AN ORGANISATION
		- GETS/SETS THE COUNTRY LIST
*/
function print_countries_reg(TEXTSelectACountry, TEXTWorldBody, country_id, country_val)
{

	//country part
	var option_str = document.getElementById(country_id);
	var x, i=0;

	option_str.options[i++] = new Option(TEXTSelectACountry, 'NULL');
	
	option_str.options[i++] = new Option(TEXTWorldBody, 'world');

	for(x in country_arr){
		option_str.options[i++] = new Option(country_arr[x],country_code[x]);
	}

	//if we remember the users last choice, select it
	if(country_val != null)
	{
		setSelectedIndex(option_str, country_val);
	}

}

/*
	USE IN WRITING A MESSAGE
		- GETS/SETS THE COUNTRY LIST
*/
function print_countries_msg(TEXTSelectACountry, country_id, country_val)
{

	//country part
	var option_str = document.getElementById(country_id);
	var x, i=0;

	option_str.options[i++] = new Option(TEXTSelectACountry, 'NULL');

	for(x in country_arr){
		option_str.options[i++] = new Option(country_arr[x],country_code[x]);
	}

	//if we remember the users last choice, select it
	if(country_val != null)
	{
		setSelectedIndex(option_str, country_val);
	}

}

/*
	USE IN SETTING A REMEMBERED OPTION AS SELECTED
*/
function setSelectedIndex(s, v) {
    for ( var i = 0; i < s.options.length; i++ ) {
        if ( s.options[i].value == v ) {
            s.options[i].selected = true;
            return;
        }
    }
}

/*
	GET THE NUMBER OF CHARACTERS AND DISPLAY A STATUS MESSAGE
	ABOUT ITS LENGTH. THE MAXIMUM LENGTH IS 255 CHARS
*/
function get_chars_msg(TEXTcharacters, TEXTof, TEXTover, TEXTOK){

	var charcount = document.getElementById('chararea').value.length;
	
	var mystr = '';
	if(charcount>255)
		mystr = '<font color="red">' + ' ' + (charcount-255) + ' ' + TEXTover + '</font>';
	else
		mystr = '<font color="green"> '+TEXTOK+'</font>';
		
	document.getElementById('chars').innerHTML = charcount + ' ' + TEXTof + ' 255 ' + TEXTcharacters + mystr;
	
}

/*
	GET THE NUMBER OF CHARS
*/
function get_chars(TEXTcharacters){

	var charcount = document.getElementById('chararea').value.length;
	
	document.getElementById('chars').innerHTML = charcount + ' ' + TEXTcharacters;
	
}

/*
	DISPLAYS AND HIDES THE TEXT BOX FOR THE 'OTHER'
*/
function add_other(state_index, options){

	if(options[state_index].value == 'OTHER')
	{
		document.getElementById('otherop').style.display = "block";
	}else{
		document.getElementById('otherop').style.display = "none";
	}
	
}

/*
		
*/
function change_hear(state_index, options){
	
	document.getElementById('other').style.display = "none";

	if(options[state_index].value == 'OTHER')
	{
		document.getElementById('other').style.display = "inline";
		document.getElementById('other').style.verticalalign = "bottom";
	}
	
}

/*
	USED IN REGISTER FORM AND MESSAGE FORM
		value = organisation unique id
		state_id = id of select element to change (in functions as 'org')
*/
function select_org(value,state_id){

	var option_str = document.getElementById(state_id);
	if(value != null && value != '')
	{
		setSelectedIndex(option_str, value);
		/*
		disable the 'how did u hear?' boxes if the org was already selected in the bar (refered organisation)
		option_str.disabled=true; 
		document.getElementById('hear').disabled=true; 
		*/
	}
	
	
}

/*
	DESIGNED TO REPLACE SELECT ORG
		Used to place a value into any form element
		such as a drop down element or text area or input
		- check and radio are coming..
*/
function place_value(value,state_id){

	var elem = document.getElementById(state_id);
	if(value != null && value != '')
	{
		
		if(elem.nodeName == 'SELECT')
		{
			setSelectedIndex(elem, value);
		}else if(elem.nodeName == 'INPUT' || elem.nodeName == 'TEXTAREA' )
		{
			elem.value = value;
		}
		/*
		disable the 'how did u hear?' boxes if the org was already selected in the bar (refered organisation)
		option_str.disabled=true; 
		document.getElementById('hear').disabled=true; 
		*/
	}
}



