
// ==============================================================
// telepark.contact

// This Software is copyright (c) 2007 by telepark, 
// Inh. Patrick Thomas, www.telepark.de. 
// All rights reserved. 

// You may not modify, extend, alter, reverse engineer or emulate
// the functionality, or create derivative works of the 
// Software in parts or it's entirety without the prior
// written consent of telepark.
// ==============================================================

var tags = '';
var search = '';
var tout = null;


// ######## INIT ########

// check browser
function Is(){
  this.agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  
  // DOM Support
  if(document.addEventListener && document.removeEventListener){this.dom2events = true;}
  if(document.getElementById){this.dom1getbyid = true;}
  
  // Opera
  this.opera = this.agent.indexOf('opera') != -1;
  if(this.opera){
    this.opera5 = (this.agent.indexOf('opera 5') != -1 || this.agent.indexOf('opera/5') != -1);
    this.opera6 = (this.agent.indexOf('opera 6') != -1 || this.agent.indexOf('opera/6') != -1);
    return;
  }

  // MSIE
  this.ie = this.agent.indexOf('msie') != -1;
  if (this.ie) {
    this.ie3 = this.major < 4;
    this.ie4 = (this.major == 4 && this.agent.indexOf('msie 5') == -1 && this.agent.indexOf('msie 6') == -1);
    this.ie4up = this.major >= 4;
    this.ie5 = (this.major == 4 && this.agent.indexOf('msie 5.0') != -1);
    this.ie5up = !this.ie3 && !this.ie4;
    this.ie6 = (this.major == 4 && this.agent.indexOf('msie 6.0') != -1);
    this.ie7 = (this.major == 4 && this.agent.indexOf('msie 7.0') != -1);
    return;
  }

  // Gecko, NN4+, and NS6
  this.gecko = this.agent.indexOf('gecko') != -1;
  this.nav = (this.agent.indexOf('mozilla') != -1 && this.agent.indexOf('spoofer') == -1 && this.agent.indexOf('compatible') == -1 && this.agent.indexOf('firefox') == -1);
  if (this.nav) {
    this.nav4  = this.major == 4;
    this.nav4up= this.major >= 4;
    this.nav5= this.major >= 5;
	return;
  }
  this.ff = (this.agent.indexOf('mozilla') != -1 && this.agent.indexOf('firefox') != -1);
  if (this.ff) {
  	this.firefox = this.major >= 5;
	return;
  }
}

// set method (post / get)
is = new Is(); 
if((is.ie5 || is.ie5up || is.ie6) && !is.ie7) { 
	var smethod = "POST";
}
else {
	var smethod = "GET";
}

// focus login field
function focusLogin() {
	try	{
		if (document.getElementById('tc_login').value=='')
			document.login.tc_username.focus();
		else document.login.tc_userpassword.focus();
	}catch(e)	{
	}
}

// resize window
function windowResize() {
	if (document.getElementById('mainBlock') && document.getElementById('mainBlock').style.height!=(document.body.clientHeight-110)) { 
		document.getElementById('mainBlock').style.height=(document.body.clientHeight-110);
	}
	if (document.getElementById('mainTable') && document.getElementById('mainTable').style.height!=(document.body.clientHeight-110)) { 
		document.getElementById('mainTable').style.height=(document.body.clientHeight-110);
	}
}

window.onresize = windowResize;

//show status of request on page
function loading(fl){
	var d = document.getElementById("loading");
	
	if(fl) {
		d.style.display = "block";
		//document.body.style.cursor = "url(images/anim-progress.gif)";
		document.body.style.cursor = "wait";
	}
	else {
		d.style.display = "none";
		document.body.style.cursor = "auto";
	}
}

function loading_2(fl){
	var d = parent.document.getElementById("loading");
	
	if(fl) {
		d.style.display = "block";
		//document.body.style.cursor = "url(images/anim-progress.gif)";
		parent.document.body.style.cursor = "wait";
	}
	else {
		d.style.display = "none";
		parent.document.body.style.cursor = "auto";
	}
}

// create http request
function createHttpRequest() {
	var xmlhttp;
 	try {
 		xmlhttp = new XMLHttpRequest();
 	} catch (e) {
  		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
  										'MSXML2.XMLHTTP.5.0',
  										'MSXML2.XMLHTTP.4.0',
  										'MSXML2.XMLHTTP.3.0',
  										'MSXML2.XMLHTTP',
  										'Microsoft.XMLHTP'
  										);
  		for (var i = 0; i<XmlHttpVersions.length && !xmlhttp; i++) {
  			try {
  				xmlhttp = new ActiveXObject(XmlHttpVersions[i]);
  			}
  			catch(e) {
  			}
  		}
 	}
 	if (!xmlhttp) {
 		alert('Error creating the XMLHttpRequest object.');
 	} else {
		return xmlhttp;
 	}
}

// ######## ADD / EDIT / DELETE CONTACT ########

// add contact
function addContact(referer) {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/addContact.php?referer=" + referer, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
			alert("Error");
		}
	  }
	}
	xmlhttp.send(null);
}
function addContact2(referer, name) 
{
	// determine if this is an existing contact
	// if exists, then view contact
	// else, create contact
	var data = "";
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "../includes/ajax/checkContactExists.php?email=" + referer, true);
	xmlhttp.onreadystatechange=function() 
	{
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) 
			{
				data = xmlhttp.responseText;
				if(data!=0){
					// existing
					window.open('../contactinfo.php?contactid=' + data,'contactinfo','resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=yes,width=500,height=600,status');
				} else {
					// new contact
					xmlhttp.open(smethod, "../includes/ajax/addContact_2.php?referer=" + referer + "&name=" + name, true);
					xmlhttp.onreadystatechange=function() {
					  // readyState==4 - meaning the load is complete
					  if (xmlhttp.readyState==4) {
						// only if "OK"
						var status = '';
						try {
							status = xmlhttp.status;
							if (status==200) {
								eval(xmlhttp.responseText);
							}
						}
						catch(e) {
							status = '';
							alert(e.description);
						}
					  }
					}
					xmlhttp.send(null);
				}
			}
		}
		catch(e) {
			status = '';
			alert(e.description);
		}
	  }
	}
	xmlhttp.send(null);
}


// edit contact
function editContact(contactid) {
	clearTimeout(tout);
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/editContact.php?contactid=" + contactid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// view contact
function contactInfo(contactid) {
	if (document.getElementById('conlink_' + contactid)) {
		var fenster = window.open('contactinfo.php?contactid=' + contactid,'contactinfo','resizable=yes,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=yes,width=500,height=600,status');
	}
}

// toggle contact details
function toggleContactDetails() {
	if (document.getElementById('contactDetailsCopy')) {
		// open field
		if (document.getElementById('contactDetailsCopy').style.display == "block") {
			document.getElementById('contactDetailsCopy').style.display = "none";
		} else if (document.getElementById('contactDetailsCopy').style.display == "none") {
			document.getElementById('contactDetailsCopy').style.display = "block";
			// copy to clipboard (IE)
	   		if (document.getElementById('contactdetails')) {
				document.getElementById('contactdetails').focus();
		    	document.getElementById('contactdetails').select();
				
		    	// IE
				if(document.all) {
				    Bereich = document.getElementById('contactdetails').createTextRange();
				    Bereich.execCommand("Copy");
				    alert("The text has been copied to the clipboard.");
				}
				// no IE
				else {
					alert("Please copy the text to the clipboard using CTRL + C");
				}
	   		}
		}
	}
}

// add section
function addSection(contactid) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/addSection.php?contactid=" + contactid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// add field
function addField(contactid,sectionid) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/addField.php?contactid=" + contactid + "&sectionid=" + sectionid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// save field
function saveField(key,value,contactid) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/saveField.php?key=" + encodeURI(key) + "&value=" + encodeURIComponent(value) + "&contactid=" + contactid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// remove section
function removeSection(id,conftext) {
	loading(true);
	var c = confirm(decodeURI(conftext));
	if (c == false) return;
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/removeSection.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// delete contacts
function deleteContacts() {
	loading(true);
	var c = confirm(str_DELETE_CONTACTS_CONFIRMATION);
	if (c == false) { 
		resetActions(); 
		return 
	}
	else {
		var xmlhttp = createHttpRequest();
		xmlhttp.open(smethod, "includes/ajax/deleteContacts.php", true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  if (xmlhttp.readyState==4) {
		  	// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				if (status==200) {
					//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					backToContactList('','',-1);
					//resetTags();
					loading();
				}
			}
			catch(e) {
				status = '';
			}
		  }
		}
		xmlhttp.send(null);
	}
}


// reset addContact
function resetAddContact() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/resetContact.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
				document.location.href = "index.php";
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}


// ######## SUB FUNCTIONS ########

// clear pages
function clearPages() {
	if (document.getElementById('pages')) document.getElementById('pages').innerHTML='';
}

function clearPages_2() {
	if (parent.document.getElementById('pages')) parent.document.getElementById('pages').innerHTML='';
}

// check contact mandatory
function checkContactMandatory(text,defBack) {
	if (document.getElementById('contact_name').value=='' || document.getElementById('contact_email')=='') {
		alert(text);
	}
	else {
		document.addcontact.submit();
		if (defBack == 'list') backToContactList('','',-1);
		else if (defBack == 'settings') settingsUser();
		else if (defBack == 'close') setTimeout('self.close()',500);
	}
}

// check mail mandatory
function checkMailMandatory(text) {
	var fields = new Array('mailing_subject','mailing_body','mailing_recipients');
	var error = false;
	
	for (var i=0; i<fields.length; i++) {
		if (document.getElementById(fields[i]).value=='') error = true;
	}
	
	if (error == true) {
		alert(text);
	}
	else {
		document.writemailing.submit();
	}
}

// check letter mandatory
function checkLetterMandatory(text) {
	var fields = new Array('letter_recipients');
	var error = false;
	
	for (var i=0; i<fields.length; i++) {
		if (document.getElementById(fields[i]).value=='') error = true;
	}
	
	if (error == true) {
		alert(text);
	}
	else {
		document.writeletter.submit();
	}
}

// check add user mandatory
function checkMandatoryAddUser(text) {
	if (document.getElementById('user_password').value=='') {
		alert(text);
		return false;
	}
	else {
		return true;
	}
}

// check import mandatory
function checkImportMandatory(text) {
	if (document.getElementById('import_file').value=='') {
		alert(text);
	}
	else {
		loading(true);
		document.importcontacts.submit();
	}
}

// reset actions select box
function resetActions() {
	var s = document.getElementById('action');
	if (s) {
		for (var i=0; i<s.options.length; i++) {
			s.options[i].selected = false;
		}
		s.options[0].selected = true;
		s.value='';
	}
}

function resetActions_2() {
	var s = parent.document.getElementById('action');
	if (s) {
		for (var i=0; i<s.options.length; i++) {
			s.options[i].selected = false;
		}
		s.options[0].selected = true;
		s.value='';
	}
}

// jump to page from select box
function applyAction(selectChoice) {
	tags = document.getElementById('tagsfield').value;
	search = document.getElementById('searchfield').value;
	checkChecked(selectChoice); 
}

function jumpTo(choice,check) {
	if (choice.indexOf('template_') == 0) {
		var templateid = choice.substr(9);
		choice = "template";
		document.getElementById('action').value = choice + "_" + templateid;
	}
	switch (choice) {
		case "mailing":  writeMailing(tags,search,0); break;
		case "excelexport": exportExcel(); break;
		case "vcardexport": exportContacts(); break;
		case "template":  writeLetter(tags,search,templateid,0); break;
		case "deletecontacts": deleteContacts(); break;
	}
}

// check if at least one contact is checked
function checkChecked(choice) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/checkChecked.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				//alert(check);
				if (check == false) {
					resetActions();
					alert(message);
				}
				else if (check == true) {
					jumpTo(choice);
				}
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}


// check/uncheck contact in the list
function checkContact(contactid,check) {
	loading(true);
	if (check == true) check = 'yes';
	else check = 'no';
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/checkContact.php?contactid=" + contactid + "&check=" + check, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}


// ######## TAGS ########

// select tag
function selectTags(tags,extratags,tagmode) {
	loading(true);
	resetActions();
	if (!(tags == "" || tags == null || tags == "undefined" || !tags)) {
		document.getElementById('searchfield').value = "";
		
		var xmlhttp = createHttpRequest();
		xmlhttp.open(smethod, "includes/ajax/selectTags.php?tags=" + encodeURI(tags) + "&extratags=" + encodeURI(extratags) + "&tagmode=" + tagmode, true);
		xmlhttp.onreadystatechange=function() {
		  // readyState==4 - meaning the load is complete
		  //alert(xmlhttp.readyState);
		  if (xmlhttp.readyState==4) {
		  	// only if "OK"
			var status = '';
			try {
				status = xmlhttp.status;
				//alert(status);
				if (status==200) {
					//alert(xmlhttp.responseText);
					eval(xmlhttp.responseText);
					loading();
				}
			}
			catch(e) {
				status = '';
			}
		  }
		}
		xmlhttp.send(null);
	} else {
		document.getElementById('extratagsfield').value='';
		loading();
	}
}

// submit tags input field with return key
function submitter_tags(tags, evt)	{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode == 13) {
  		selectTags(tags,'');
  	}
}

// submit tags input field with return key
function submitter_favorite(title, tags, extratags, evt)	{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode == 13) {
  		saveFavoriteTags(title,tags,extratags);
  	}
}

// submit "apply tag actions" input field with return key
function submitter_tagToSelected(tags, confirmtext, evt)	{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode == 13) {
  		addTagToSelected(tags,'add',confirmtext);
  	}
}

// get tag
function getTag(tag) {
	var s = document.getElementById('tagsfield').value;
	if (s != '') document.getElementById('tagsfield').value = s + " " + decodeURI(tag);
	else document.getElementById('tagsfield').value = decodeURI(tag);
	//selectTags(document.getElementById('tagsfield').value,'');
	//backToContactList('',document.getElementById('tagsfield').value,1);
}

// save Favorite Tags
function saveFavoriteTags(title,tags1,tags2) {
	loading(true);
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/saveFavoriteTags.php?title=" + encodeURI(title) + "&tags1=" + encodeURI(tags1) + "&tags2=" + encodeURI(tags2), true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				//backToContactList('','',0);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// search Favorite Tags
function searchFavoriteTags(id,closewin) {
	loading(true);
	resetActions();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/searchFavoriteTags.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				//backToContactList('','',0);
				loading();
				if (closewin == true) fenster.close();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// delete favorite tag
function delFavoriteTag(id) {
	//loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/delFavoriteTag.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				//backToContactList('','',0);
				//loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// reset tags
function resetTags() {
	loading(true);
	document.getElementById('tagsfield').value = "";
	document.getElementById('searchfield').value = "";
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/resetTags.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				backToContactList('','',0);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// list tags
function listTags() {
	var url = "taglist.php";
	var name = "taglist";
	var width = '300px';
	var height = '400px';
	
	fenster = window.open (
		url,
		name, 					// name
		"toolbar=0" 			// tool bar 
		+",location=0" 			// address bar
		+",directories=0" 		// additional bars
		+",status=1" 			// status bar
		+",menubar=0" 			// menu bar
		+",scrollbars=yes" 		// scroll bars
		+",resizable=1" 		// window resizable
		+",width=" + width 		// window width in pixels
		+",height=" + height 	// window height in pixels
	);
}

// list tags favorites
function listTagFavorites() {
	var url = "tagfavoriteslist.php";
	var name = "tagfavoriteslist";
	var width = '300px';
	var height = '400px';
	
	fenster = window.open (
		url,
		name, 					// name
		"toolbar=0" 			// tool bar 
		+",location=0" 			// address bar
		+",directories=0" 		// additional bars
		+",status=1" 			// status bar
		+",menubar=0" 			// menu bar
		+",scrollbars=yes" 		// scroll bars
		+",resizable=1" 		// window resizable
		+",width=" + width 		// window width in pixels
		+",height=" + height 	// window height in pixels
	);
}

// add tags to checked contacts
function addTagToSelected(tags,mode,confirmtext) {
	loading(true);
	
	if (confirm(confirmtext) == false) {
		loading();
		return false;
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/addTagToSelected.php?tags=" + encodeURI(tags) + "&mode=" + mode, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// ######## SEARCH ########

// search contact
function searchContacts(searchstring) {
	loading(true);
	document.getElementById('tagsfield').value = "";
	backToContactList(searchstring,'',1);
	loading();
	return;
}

// submit search input field with return key
function submitter_search(searchstring, evt)	{
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if (keyCode == 13) {
  		searchContacts(searchstring);
  	}
}

// search contact (user management)
function searchContactUser(searchstring) {
	loading(true);
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/searchContactUser.php?search=" + encodeURI(searchstring), true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}



// ######## CONTACT LIST ########

// reload contacts list
function reloadContactList(searchstring,tags,page) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/reloadContacts.php?sp=" + page + "&tags=" + encodeURI(tags) + "&search=" + encodeURI(searchstring), true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
				resetActions();
			}
		}
		catch(e) {
			status = '';
			loading();
		}
	  }
	}
	xmlhttp.send(null);
}

// reload (whole) contacts list
function backToContactList(searchstring,tags,page) {
	//loading(true);
	resetActions();
	//document.getElementById('messageContent').innerHTML='';
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/backToContacts.php?sp=" + page + "&tags=" + encodeURI(tags) + "&search=" + encodeURI(searchstring), true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				//alert(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	//loading();
}


// ######## IMPORT CONTACTS ########

// import contacts
function importContacts() {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/importContacts.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// ######## EXPORT CONTACTS ########

// export contacts
function exportContacts() {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/exportContacts.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// excel export
function exportExcel() {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/exportContactsExcel.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// ######## BULK MAIL ########

// write mailing
function writeMailing(tags, search, mailid) {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/writeMailing.php?tags=" + encodeURI(tags) + "&search=" + encodeURI(search) + "&mailid=" + mailid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// ######## CIRCULAR LETTER ########

// write mailing
function writeLetter(tags, search, templateid, letterid) {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/writeLetter.php?tags=" + encodeURI(tags) + "&search=" + encodeURI(search) + "&templateid=" + templateid + "&letterid=" + letterid, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				//alert(xmlhttp.responseText);
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// ######## SETTINGS ########

// go to custom settings
function goCustomSettings() {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/goCustomSettings.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// go to settings
function goSettings() {
	loading(true);
	clearPages();
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/goSettings.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				resetActions();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// manage API keys
function settingsKeys() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsAPIKeys.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// manage users
function settingsUser() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsUsermanagement.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// set admin email address
function settingsMail() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsAdminMail.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// set sort order
function settingsSortOrder() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsSortOrder.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// manage templates
function settingsTemplates() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsTemplates.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// manage excel export
function settingsExcelExport() {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsExcelExport.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// generate unique key
function APIGenerateKey(id,text) {
	loading(true);
	
	if (id!='new') {
		var c = confirm(text);
		if (c == false) return;
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsAPIGenerateKey.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// delete key
function APIdeleteKey(id,text) {
	loading(true);
	
	var c = confirm(text);
	if (c == false) return;
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/settingsAPIDeleteKey.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// close API
function closeAPI() {
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/closeAPI.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}


// ######## SETTINGS -> USER MANAGEMENT ########

// update user list
function updateUserList(id) {
	loading(true);

	if (id == 'undefined') return;
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/updateUserList.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// set user active / inactive
function UserActive(userid) {
	loading(true);
	
	if (userid == 'undefined') return;
	
	var c = document.getElementById('useractive_' + userid).checked;
	if (c==true) var active = 1;
	else var active = 0;
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/updateUserActive.php?userid=" + userid + "&active=" + active, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// new user
function newUser() {
	loading(true);

	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/newUser.php", true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// select user
function selectUser(id) {
	loading(true);
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/selectUser.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}

// delete user
function deleteUser(id,text) {
	loading(true);
	
	var c = confirm(text);
	if (c == false) {
		loading();
		return false;
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/deleteUser.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}

// ######## SETTINGS -> TEMPLATES ########

// delete template
function deleteTemplate(id,text) {
	loading(true);
	
	var c = confirm(text);
	if (c == false) {
		loading();
		return false;
	}
	
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/deleteTemplate.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				updateActionBox();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}

// edit template label
function editTemplateLabel(id) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/editTemplateLabel.php?id=" + id, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}

// save edited template label
function saveEditTemplate(label,id) {
	loading(true);
	var xmlhttp = createHttpRequest();
	xmlhttp.open(smethod, "includes/ajax/saveEditTemplateLabel.php?id=" + id + "&label=" + encodeURI(label), true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				updateActionBox();
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}

// submit input field with return key
function submitter_input(id, label, evt)	{
  var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
  if (keyCode == 13) {
  	saveEditTemplate(label,id);
  }
}

// update action select box
function updateActionBox() {
	loading(true);
	var xmlhttp = createHttpRequest();
	//var target = "includes/ajax/updateActionBox.php";
	var target = tcurl + "includes/ajax/updateActionBox.php";
	xmlhttp.open(smethod, target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
	return;
}


// toggle left window box
function toggleBox(box) {
	if (document.getElementById(box).style.display != 'none') {
		document.getElementById(box).style.display = "none";
		document.getElementById(box + '_img').src = "images/maximize.gif";
	}
	else if (document.getElementById(box).style.display == 'none') {
		document.getElementById(box).style.display = "block";
		document.getElementById(box + '_img').src = "images/minimize.gif";
	}
}

// set mail format (html / plain text)
function setMailFormat(format) {
	if (format == "html") {
		if (document.getElementById('altBodyCaption')) document.getElementById('altBodyCaption').style.display = "block";
		if (document.getElementById('altBody')) document.getElementById('altBody').style.display = "block";
		if (document.getElementById('altBodyTags')) document.getElementById('altBodyTags').style.display = "block";
	} else {
		if (document.getElementById('mailing_altbody')) document.getElementById('mailing_altbody').value="";
		if (document.getElementById('altBodyCaption')) document.getElementById('altBodyCaption').style.display = "none";
		if (document.getElementById('altBody')) document.getElementById('altBody').style.display = "none";
		if (document.getElementById('altBodyTags')) document.getElementById('altBodyTags').style.display = "none";
	}
}

// display tool tip
function toolTip(id) {
	loading(true);
	document.getElementById('tooltipdiv').innerHTML = "";
	var xmlhttp = createHttpRequest();
	var tooltip = "";
	
	var target = tcurl + "includes/ajax/contactDetailsTooltip.php?contactid=" + id;
	xmlhttp.open(smethod, target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				//TagToTip('tooltipdiv');
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	xmlhttp.send(null);
}

// check / uncheck all
function checkAll() {
	loading(true);
	var xmlhttp = createHttpRequest();
	
	if (document.getElementById('checkall').checked==true) {
		var check = 'yes';
		var cstatus = true;
	} else {
		var check = 'no';
		var cstatus = false;
	}
	
	var target = tcurl + "includes/ajax/checkAllContacts.php?check=" + check;
	xmlhttp.open(smethod, target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
				toggleMultipleCheckboxes('listcontacts','contact',cstatus);
				loading();
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	loading();
	xmlhttp.send(null);
}

// toggle multiple checkboxes state
function toggleMultipleCheckboxes(form_name,field_name,status) {
	var ml = document.forms[form_name];
  	var len = ml.elements.length;
	for (var i=0; i<len; i++) {
		var e = ml.elements[i];
		if (e.name.substr(0,e.name.indexOf('[')) == field_name) {
			e.checked = status;
		}
	}
}

// check / uncheck all
function setItemsPerPage(ipp) {
	loading(true);
	var xmlhttp = createHttpRequest();
	
	var target = tcurl + "includes/ajax/itemsPerPage.php?ipp=" + ipp;
	xmlhttp.open(smethod, target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				eval(xmlhttp.responseText);
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	loading();
	xmlhttp.send(null);
}

function loadWebMailer(path, acHash) 
{
	var url="http://" + path +"launch.php?mailto="+acHash;
	loading(true);
	document.getElementById('messageContent').innerHTML= 'Loading e-mails...';
	document.getElementById('mainContent').innerHTML= '<iframe class="webmailer_iframe" src="'+url+'" scrolling="no" frameborder="0" width="90%" height="800px" style="position:relative; top:0; left:0; height:800px; width:100%;"></iframe>';
	document.getElementById('messageContent').innerHTML= '';
	loading();
}

//gp-web
function loadWebMailerCalendar(path,acHash)
{
	var url_calendar="http://" + path +"launch.php?calendar=c";
	loading(true);
	document.getElementById('messageContent').innerHTML= 'Loading calendar...';
	document.getElementById('mainContent').innerHTML= '<iframe class="webmailer_iframe" src="'+url_calendar+'" scrolling="no" frameborder="0" width="90%" height="800px" style="position:relative; top:0; left:0; height:800px; width:100%;"></iframe>';
	document.getElementById('messageContent').innerHTML= '';
	loading();
}

function loadURL(url, targetOBJ) {
	loading(true);
	var xmlhttp = createHttpRequest();
	
	var target = url;
	xmlhttp.open(smethod, target, true);
	xmlhttp.onreadystatechange=function() {
	  // readyState==4 - meaning the load is complete
	  if (xmlhttp.readyState==4) {
	  	// only if "OK"
		var status = '';
		try {
			status = xmlhttp.status;
			if (status==200) {
				targetOBJ=document.getElementById(targetOBJ);
				targetOBJ.innerHTML=xmlhttp.responseText;
			}
		}
		catch(e) {
			status = '';
		}
	  }
	}
	loading();
	xmlhttp.send(null);
}

function loadAccountAddPanel(target, userID){
	var url="includes/ajax/customACMgr.php?m=show.add.panel&userID="+userID;
	loadURL(url, target);
}

function deleteAccount(obj, target){
	// use the selected value to delete via ajax
	// remove the item from the list.
	obj=document.getElementById(obj);
	var url="includes/ajax/customACMgr.php?m=delete.mail.ac&acID="+obj.value;
	loadURL(url, target);
	removeFromList(obj);
}

function displayAccount(obj, target, userID){
	obj=document.getElementById(obj);
	var url="includes/ajax/customACMgr.php?m=show.add.panel&acID="+obj.value+"&userID="+userID;
	loadURL(url, target);
}

function removeFromList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be removed!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be removed!");
      } else {  // Build arrays with the text and values to remain
         var replaceTextArray = new Array(listField.length-1);
         var replaceValueArray = new Array(listField.length-1);
         for (var i = 0; i < listField.length; i++) {
            // Put everything except the selected one into the array
            if ( i < selected) { replaceTextArray[i] = listField.options[i].text; }
            if ( i > selected ) { replaceTextArray[i-1] = listField.options[i].text; }
            if ( i < selected) { replaceValueArray[i] = listField.options[i].value; }
            if ( i > selected ) { replaceValueArray[i-1] = listField.options[i].value; }
         }
         listField.length = replaceTextArray.length;  // Shorten the input list
         for (i = 0; i < replaceTextArray.length; i++) { // Put the array back into the list
            listField.options[i].value = replaceValueArray[i];
            listField.options[i].text = replaceTextArray[i];
         }
      } // Ends the check to make sure something was selected
   } // Ends the check for there being none in the list
}