<!--

function noenter() {
	return !(window.event && window.event.keyCode == 13); 
}

function clearcombo(el){
  // this routine clears out a listbox or combo box
  for (var i = el.options.length; i >= 0; i--){
    el.options[i] = null;
  }
  el.selectedIndex = -1;
}

function getcontacts(sCode){
  clearcombo(document.contactsForm.contacts);
  if (sCode == 'NONE' || sCode == ''){
    // if they click on an empty area in the imagemap
    addopt(0, 'Click on an organisation to view contacts');
  } else {
    // a non-empty area
    window.open("contacts/getContacts.php?orgcode=" + sCode, "gofetch", "toolbar=no,menubar=no,location=no,directories=no," + "resizeable=no,width=100,height=100,left=0,top=0");
    window.focus();
  }
}

function addopt(nValue, sText){
  // this routine adds a new item to our listbox
  document.contactsForm.contacts.options[document.contactsForm.contacts.options.length] = new Option(sText, nValue);
}


function clearOrgs(){
	var x = document.getElementById("organisations");
	clearcombo(x);
}

function getcontactinfo(cCode){
  //(document.contactsForm.contacts);
  if (cCode == 'NONE' || cCode == ''){
    // if they click on an empty area in the imagemap
    addopt(0, 'Click on a contact to view info');
  } else {
    // a non-empty area
    window.open("contacts/getContactInfo.php?contactID=" +
       cCode, "gofetch",
      "toolbar=no,menubar=no,location=no,directories=no," +
      "resizeable=no,width=100,height=100,left=0,top=0");
	window.focus();
  }
}

function getorginfo(cCode){
  clearcombo(document.contactsForm.contacts);
  if (cCode == 'NONE' || cCode == ''){
    // if they click on an empty area in the imagemap
    orgaddopt(0, 'Click on an org to view info');
  } else {
    // a non-empty area
    if(cCode.indexOf('<GROUP>') > 0){
      window.open("contacts/getGroupsContacts.php?orgcode=" +
         cCode, "gofetch",
        "toolbar=no,menubar=no,location=no,directories=no," +
        "resizeable=no,width=100,height=100,left=0,top=0");
    } else {
      window.open("contacts/getContacts.php?orgcode=" +
         cCode, "gofetch",
        "toolbar=no,menubar=no,location=no,directories=no," +
        "resizeable=no,width=100,height=100,left=0,top=0");
    }
    window.focus();
  }
}

function showAllOrganisations() {
  clearAll();
  window.open("contacts/getAllOrgs.php", "gofetch",
    "toolbar=no,menubar=no,location=no,directories=no," +
    "resizeable=no,width=100,height=100,left=0,top=0");
  window.focus();
}

function searchOrganisations() {
	var y = document.getElementById("searchorg");
	var searchwords = y.value;
  	clearAll();
	if (searchwords == 'NONE' || searchwords == ''){
		// if they send an empty string
		orgaddopt('', 'Enter a word to search');
	} else {
		// a non-empty string
		window.open("contacts/getOrganisations.php?keywords=" +
			 searchwords, "gofetch",
			"toolbar=no,menubar=no,location=no,directories=no," +
			"resizeable=no,width=100,height=100,left=0,top=0");
		window.focus();
  }
}

function orgaddopt(nValue, sText){
  // this routine adds a new item to our listbox
  var organisations = document.getElementById("organisations");
  organisations.options[organisations.options.length] = new Option(sText, nValue);
  //document.org_search.organisations.options[document.org_search.organisations.options.length] = new Option(sText, nValue);
}

function edit_interests(sCode){
  var contacts = document.getElementById('contacts');
  var contact_id = contacts.value;
  
  if (contact_id == 'NONE' || contact_id == '' || contact_id == null){
    alert('No Contact Selected!');
  } else {
    // a non-empty area
    window.open("contacts/interests_selector.php?contact_id=" + contact_id, "gofetch", "toolbar=no,menubar=no,location=no,directories=no," + "resizeable=no,width=650,height=600,left=0,top=0");
  }
}

function add_interest(nValue, sText){
  // this routine adds a new item to our listbox
  document.quickInfo.current_interests.options[document.quickInfo.current_interests.options.length] = new Option(sText, nValue);
}

function clear_interests(){
	var interests = document.getElementById("current_interests");
	clearcombo(interests);
}

function searchContacts() {
	var x = document.getElementById("contacts");
	clearcombo(x);
	var y = document.getElementById("searchcontacts");
	var searchwords = y.value;
	if (searchwords == 'NONE' || searchwords == ''){
		// if they send an empty string
		addopt('', 'Enter a word to search');
	} else {
		// a non-empty string
		window.open("contacts/getContacts.php?keywords=" +
			 searchwords, "gofetch",
			"toolbar=no,menubar=no,location=no,directories=no," +
			"resizeable=no,width=100,height=100,left=0,top=0");
		window.focus();
  }
}

function changeContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	contactName = x.options[x.selectedIndex].text;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		window.opener.changeToContact(contactID, contactName);
		self.close();
	}
}

function changeNARIContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
	  contactName = x.options[x.selectedIndex].text;
		window.opener.changeToContact(contactID, contactName);
		self.close();
	}
}

function changeClientContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	contactName = x.options[x.selectedIndex].text;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		window.opener.changeToClientContact(contactID, contactName);
		self.close();
	}
}

function editOrg() {
	var x = document.getElementById("organisations");
	orgCode = x.value;
  if(orgCode.indexOf('<GROUP>') > 0){
    alert("Cannot edit a <GROUP>");
  } else {
  	if (orgCode == 'NONE' || orgCode == ''){
  		// if they send an empty string
  		alert("no organisation selected");
  	} else {
  		var url = "organisations/organisationForm.php?id=" + orgCode;
  		window.location.href = url;
  	}
  }
}

function deleteOrg() {
	var x = document.getElementById("organisations");
	orgCode = x.value;
  if(orgCode.indexOf('<GROUP>') > 0){
    alert("Cannot delete a <GROUP>");
  } else {
    if (orgCode == 'NONE' || orgCode == ''){
  		// if they send an empty string
  		alert("no organisation selected");
  	} else {
  		var url = "organisations/deleteOrganisation.php?id=" + orgCode;
  		window.location.href = url;
  	}
  }
}

function editContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		var url = "contacts/contactForm.php?id=" + contactID;
		window.location.href = url;
	}
}

function deleteContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		var url = "contacts/deleteContact.php?id=" + contactID;
		window.location.href = url;
	}
}

function addContact() {
	var x = document.getElementById("organisations");
	orgCode = x.value;
	
	if(orgCode.indexOf('<GROUP>') > 0){
		alert("Cannot add contact to a <GROUP>, Please select an individual Organisation");
	} else {
		if (orgCode == 'NONE' || orgCode == ''){
			var url = "contacts/contactForm.php";
			window.location.href = url;
		} else {
			var url = "contacts/contactForm.php?org_id=" + orgCode;
			window.location.href = url;
		}
	}
}

function moveContact() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		var url = "organisations/organisations.php?action=addContactToOrganisation&contactID=" + contactID;
		window.location.href = url;
	}
}

function moveContactToNARI() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		var url = "contacts/moveToNARI.php?contactID=" + contactID;
		window.open(url, "gofetch",
			"toolbar=no,menubar=no,location=no,directories=no," +
			"resizeable=no,width=100,height=100,left=0,top=0");
		window.focus();
	}
}

function sendmail() {
	var x = document.getElementById("contacts");
	contactID = x.value;
	if (contactID == 'NONE' || contactID == ''){
		// if they send an empty string
		alert("no contact selected");
	} else {
		var url = "contacts/emailForm.php?contactID=" + contactID;
		window.location.href = url;
	}
}

function selectAllContacts(){
	var y = document.getElementById("contacts");
	for(i=0; i<y.length; i++) {
	  y.options[i].selected = true;
	}
}

function clearAll() {
	var x = document.getElementById("organisations");
	clearcombo(x);
	var y = document.getElementById("contacts");
	clearcombo(y);
	var z = document.getElementById("current_interests");
	clearcombo(z);

	var searchcontacts = document.getElementById("searchcontacts");
	searchcontacts.value = "";
	
	var searchorg = document.getElementById("searchorg");
	searchorg.value = "";

	document.quickInfo.contactID.value = "";
	document.quickInfo.firstname.value = "";
	document.quickInfo.lastname.value = "";
	document.quickInfo.position.value = "";
	document.quickInfo.phone.value = "";
	document.quickInfo.mobile.value = "";
	document.quickInfo.fax.value = "";
	document.quickInfo.notes.value = "";

	document.orgQuickInfo.orgcode.value = "";
	document.orgQuickInfo.orgname.value = "";
	document.orgQuickInfo.orgphone.value = "";
	document.orgQuickInfo.orgfax.value = "";
	document.orgQuickInfo.orgwebsite.value = "";
	document.orgQuickInfo.orgaddress1.value = "";
	document.orgQuickInfo.orgaddress2.value = "";
	document.orgQuickInfo.orgaddress3.value = "";
	document.orgQuickInfo.orgaddress4.value = "";
}

function selectContact() {
	var tmp_arr;
	var source_name;
	var source_element;
	var target_name;
	var target_element;
	var x;
	
	for (x in elements_array) {
		tmp_arr = elements_array[x].split("/");
		source_name = tmp_arr[0];
		target_name = tmp_arr[1];
		
		target_element = document.getElementById(target_name);
		source_element = window.opener.document.getElementById(source_name);
		
		source_element.value = target_element.value;		
	}
	
	window.close()
}

-->
