
var ajaxObjects = new Array();

	function addressPopup(id,e) {		
		
		var body = document.getElementById('body_tag');
		var tmpdiv = document.getElementById("div"+id);
		if(tmpdiv) {
			body.removeChild(tmpdiv);
		} else {
		
	 		if( document.all ) {
		  		x = window.event.x;
		  		y = window.event.y;
		  	} else {
		  		x = e.pageX;
		  		y = e.pageY;
		  	}
			var div = document.createElement("div");
			div.style.border = '1px solid #000';
			div.style.backgroundColor = '#fff';
			div.style.position = 'absolute';
			div.id = "div"+id;
			div.style.left = x+'px';
			div.style.top = y+'px';
			body.appendChild(div);
			if(div.style.display == 'none' || div.style.display == '') {
				var ajaxIndex = ajaxObjects.length;
				ajaxObjects[ajaxIndex] = new sack();
				var url = 'includes/ajax/showAddress.php?addressID=' + id;
				ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
				ajaxObjects[ajaxIndex].onCompletion = function() {
						 div.innerHTML = ajaxObjects[ajaxIndex].response;
						 } ;	// Specify function that will be executed after file has been found
				ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function		
				
				div.style.display = '';
				
			} else {
				body.removeChild
				div.style.display = 'none';
			}
		}
	}	
	function showTagList(tagtype,containerID) {
		if(document.getElementById('possible_tags_row').style.display == 'none') {
			var ajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			var url = 'includes/ajax/showTagList.php?tagType='+tagtype+'&containerID='+containerID;
			ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
			ajaxObjects[ajaxIndex].onCompletion = function() { 
									document.getElementById("tag_div").innerHTML = ajaxObjects[ajaxIndex].response; 
								 	document.getElementById('possible_tags_row').style.display = '';
								 	if(document.getElementById('possible_tags_row2') != null) {
										document.getElementById('possible_tags_row2').style.display = '';
									}
								 } ;	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function
		} else {
			document.getElementById('possible_tags_row').style.display = 'none';
			if(document.getElementById('possible_tags_row2') != null) {
				document.getElementById('possible_tags_row2').style.display = 'none';
			}
		}
	}
	
	
	function insertTag(tag) {
		var tagline = document.getElementById("tagline");
		
		var newtagline = "";
		
		if(tagline.value == "") {
			newtagline = tag;
		} else {
			newtagline = tag + ", "+tagline.value;
		}
		tagline.value = newtagline;
	}
		
	function searchtext(searchform) {
		var field = document.getElementById("searchstring");
		var error = "";
		if(field.value.length <= 2) {
			 error += "The search string must have 2 characters at least.";
		}
		
		if(field.value.match(/[^A-Z0-9: ]/gi)) {
			error += "Invalid search string";
		}
		if(field.value.indexOf(" ") > -1) {
			field.value = field.value.replace(/ /g,".");
		}
		
		
		if(error == "") {
			var searchform = document.getElementById("searchform"); 

			searchform.action = "?page[]=search&string="+field.value;

			searchform.submit();
			
			
		} else {
			alert(error);
		}
		
	}	
