function submitForm(formName, formAction) {
	if (!valid(formName)) return;
	//var form = dojo.byId(formName);	
	var form = document.getElementById(formName);
	form.action = formAction;
	form.method = "post";		
	form.submit();
}

function valid(f) {
	var formName = "fiche";
	if (f) {
		formName = f;
	}
	var form = dijit.byId(formName);
	if (!form.isValid()) {
		dojo.forEach(form.getDescendants(), function(input){
			if (input._onBlur) { 
				input._onBlur(); 
			}
		});
		return false;
	}
	return true;
}

function editPersonal() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "personal.php?cmd=edit&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("personal");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function editPassword() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "personal.php?cmd=editPassword&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("personal");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function savePersonal() {
	var form = document.getElementById("fiche");
	if (!valid()) return;
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "personal.php?cmd=save&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		preventCache: true,
		form: form,

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("personal");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function savePassword() {
	var form = document.getElementById("fiche");
	if (!valid()) return;
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "personal.php?cmd=savePassword&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		form: form,

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("personal");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function cancelPersonal() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "personal.php?ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("personal");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function editCompany() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "company.php?cmd=edit&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("company");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function saveCompany() {
	var form = document.getElementById("fiche");
	if (!valid()) return;
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "company.php?cmd=save&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		form: form,

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("company");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function cancelCompany() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "company.php?ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("company");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function editExtra() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "extra.php?cmd=edit&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("extra");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function saveExtra() {
	var form = document.getElementById("fiche");
	if (!valid()) return;
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "extra.php?cmd=save&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		form: form,

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("extra");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function cancelExtra() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "extra.php?ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		
		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("extra");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function addSkill() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "skill.php?ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("skills");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function editSkill(id) {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "skill.php?cmd=edit&msId=" + id + "&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("skills");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function saveSkill() {
	var form = document.getElementById("fiche");
	if (!valid()) return;
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "skill.php?cmd=save&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds
		form: form,

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("skills");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function deleteSkill(id) {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "skills.php?cmd=delete&msId=" + id + "&ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("skills");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function cancelSkill() {
	dojo.xhrGet( {
		// The following URL must match that used to test the server.
		url: "skills.php?ms=" + new Date().getTime(), 
		timeout: 5000, // Time in milliseconds

		// The LOAD function will be called on a successful response.
		load: function(response, ioArgs) { 
			var div = dijit.byId("skills");
			div.setContent(response);
			return response;
		},

		// The ERROR function will be called in an error case.
		error: function(response, ioArgs) {
			alert("HTTP status code: " + ioArgs.xhr.status);
			return response;
		}
	});
}

function toggleThirdParty() {
	var atThirdParty = dijit.byId("at_third_party");
	var thirdParty = dijit.byId("third_party");
	if (atThirdParty.checked) {
		thirdParty.setDisabled(false);	
	} else {
		thirdParty.setValue("");
		thirdParty.setDisabled(true);	
	}
}
