/*0 = add, 1 = edit*/
/*nextFunction is a string of a function to be eval'd, ran after this one is ran*/
function addEditModule(addEdit,nextFunction){
	
	if ( typeof(nextFunction) == "undefined" || nextFunction==null ) {
		var nextFunction = ''; 
	}
		
	/*check to see if our form has valid data*/
	var formCompleted = qFormAPI.validate("moduleForm");
		
	if(formCompleted){
		
		/*disable so they can't multi-click and screw things up*/
		document.getElementById("moduleAddEditBtn").disabled = true;
		
		var moduleAjax = ajaxObj();
						
		var requestParams = getRequestFields(addEdit,requestFields); 
		
		/*once the adding\editing is done notify the user*/
		moduleAjax.onreadystatechange=function(){
				if(moduleAjax.readyState==4){
					
					/*refresh the HTML in the button if it's IE, or the event won't register*/
					
					var newClick = 'addEditModule(1,"' + nextFunction + '")';
					if(document.all){
						document.getElementById("moduleAddEditBtn").onclick = newClick;
						document.getElementById("moduleAddEditBtn").outerHTML = document.getElementById("moduleAddEditBtn").outerHTML;
					}
					else if(document.getElementById){
						document.getElementById("moduleAddEditBtn").setAttribute('onclick',newClick);
					}
					
					xmlResponse = moduleAjax.responseText;
					
					if(addEdit == 0){
											
						document.getElementById("priKeyID").value = xmlResponse;
						document.getElementById("moduleAddEditBtn").value= "Edit " + moduleAlert;

						if(nextFunction.length > 0){
							eval(nextFunction + ";");
						}
						else{
							alert(moduleAlert + " has been added");
						}
						
					}
					/*if there is another js function to run after this one*/
					else{
						if(nextFunction.length > 0){
							eval(nextFunction + ";");
						}
						else{
							alert(moduleAlert + " has been updated");
						}
					}
					
					document.getElementById("moduleAddEditBtn").disabled = false;
				}
		}
		
		ajaxPost(moduleAjax,apiPath,requestParams);
	}
	
}