/*
Author				: Billy Griffiths
Date				: 23-Apr-2006
Last Updated By		: Stefan Kruger
Last Updated		: 31-Aug-2011
*/

function uploadFile(){
	try {
		if (document.getElementById("targetuserid").value == ""){
			alert("Please select a user to import the contacts for.");
			document.getElementById("targetuserid").focus();
			return;
		}
		if (document.getElementById("description").value == ""){
			alert("Please enter a description of the file.");
			document.getElementById("description").focus();
			return;
		}
		if (document.getElementById("txtContactFile").value == ""){
			alert("Please select a file to upload.");
			document.getElementById("txtContactFile").focus();
			return;
		}
		if (document.getElementById("userid").value == ""){
			alert("Your session seems to have expired. Please refresh the page and try again.");
			return;
		}
		var path = (document.getElementById("txtContactFile").value.replace(/\\/g,"|"));
		var split = path.split("|");
		var filename = split[split.length-1];
		if (filename.match(/\.csv/i)||filename.match(/\.xls/i)) {
			document.getElementById("filename").value = filename;
			document.FileUpload.submit();
			document.FileUpload.reset();
		}
		else {
			alert("Only CSV and Excel files can be uploaded. Please select another file.");
		}
	}
	catch (ex) {
		alert("Error occured during file upload :\n" + ex.message);
	}
}
