function selectAll() {
	//Checks all checkboxes on page regardless of the amount of forms
	//Requires a checkbox with the name/id "select_all" to initiate this function on click
	var x = document.getElementsByTagName("input");
	for(i=0; i<x.length; i++) {
		if((x[i].type == "checkbox") && (x[i].name != "select_all")) {
			x[i].checked = (document.getElementById("select_all").checked == false) ? false : true;
		}
	}
}

function copyChecked() {
	//Grabs the value of all checked checkboxes, builds a comma seperated string and dumps the string into a hidden field
	var c = new Array();
	var z = 0; //A counter for assembling the array nicely
	var x = document.getElementsByTagName("input");
	for(i=0; i<x.length; i++) {
		if((x[i].type == "checkbox") && (x[i].name != "select_all")) {
			if(x[i].checked == true) {
				c[z] = x[i].value;
				z++;
			}
		}
	}
	document.getElementById("selected").value = c.join(",");
}

function requestForm(file,cmd,uID,targetDiv) {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get","fetch/"+file+".php?cmd="+cmd+"&id="+uID,false);
	oXmlHttp.onreadystatechange = function() {
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
				document.getElementById(targetDiv).innerHTML = oXmlHttp.responseText;
			} else {
				document.getElementById(targetDiv).innerHTML = "An error occured: "+oXmlHttp.statusText;
			}
		}
	};
	oXmlHttp.send(null);
}
	
function getRequestBody(oForm) {
	var aParams = new Array();
	for(i=0; i < oForm.elements.length; i++) {
		//Check to see if element is a checkbox, only include if selected.
		if(oForm.elements[i].type == "checkbox") {
			if(oForm.elements[i].checked == true) {
				var sParam = encodeURIComponent(oForm.elements[i].name);
				sParam += "=";
				sParam += encodeURIComponent(oForm.elements[i].value);
				aParams.push(sParam);
			}
		} else {
			var sParam = encodeURIComponent(oForm.elements[i].name);
			sParam += "=";
			sParam += encodeURIComponent(oForm.elements[i].value);
			aParams.push(sParam);
		}
	}
	return aParams.join("&");
}
	
function sendRequest(file,targetForm,targetDiv,refreshCmd,refreshTargetDiv,refreshParam) {
	var oForm = document.forms[targetForm];
	var sBody = getRequestBody(oForm);
	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post","insert/"+file+".php",true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function() {
		if(oXmlHttp.readyState == 4) {
			if(oXmlHttp.status == 200) {
				if(oXmlHttp.responseText.length > 0) {
					alert(oXmlHttp.responseText);
				} else {
//					showHide(file,0,targetDiv,0,0);
					if(refreshCmd != "") requestForm(file,refreshCmd,refreshParam,refreshTargetDiv);
				}
			} else {
				alert("An error occurred: "+oXmlHttp.statusText);
			}
		}
	};
	oXmlHttp.send(sBody);
}

function loadTool(tool,id) {
	switch(document.getElementById('tool_'+tool).style.display) {
		case "none":
			if(tool == "view") requestForm("sigs",id,1,"sigs");
			var x = document.getElementsByTagName('div');
			var r = /^tool_/;
			for(var i=0;i<x.length;i++)
				if(r.test(x[i].id) && x[i].id != "tool_"+tool && x[i].style.display != "none")
					x[i].style.display = "none";
			Effect.SlideDown(document.getElementById('tool_'+tool));
			break;
		default:
			Effect.SlideUp(document.getElementById('tool_'+tool));
			break;
	}
}

function addBookmark() {
	if(document.all) {
		window.external.AddFavorite(document.location.href,document.title);
	} else {
		alert("Press Ctrl+D to bookmark this page.");
	}
}

function loadMap(id) {
	window.open('/map.php?id='+id,'GoogleMap','width=500,height=300,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no')
}

function lightLogo(id) {
	document.getElementById("logo_"+id).src = "images/site/"+id+"/logo_s.png";
}

function darkLogo(id) {
	document.getElementById("logo_"+id).src = "images/site/"+id+"/logo_s_null.png";
}