/********************************************************************
 * project:			OSCM
 * page name:		common.js (from common code)
 * date created:	2007-09
 * created by:		Pete Neale
 * description:		Common useful javascript routines
 * comments:		-
 * modifications:	none
 * date modified:	-
********************************************************************/

/*
 * General routine to issue a confirmation of deletion message, and if the 
 * user clicks OK to forward the user to a specified url
 * 
 * delete_item = the item to be deleted
 * forward_to = the page to be forwarded to if the user confirms OK
 * 
*/

function confirmDelete(delete_item,forward_to) {
	
	// issue the message and get the response.
	// result of true = OK
	var return_value = confirm('Are you sure you want to delete\n' + delete_item + '?');

	if (return_value == true) {
		// user clicked OK, so forward to the correct page
		window.location = forward_to;
	}
	
	return;
}

/*
 * Prompt the user to see if they want to replace a file before uploading it when
 * they are re-uploading a file to the user's library facility.  This is used as a client
 * side validation rule by Quickform.
 * file = the new filename they want to upload
 * oldfile = the old filename used on the library system
 * if the file names are the same, the user is just asked to 
 *   confirm he wants to replace the old file with the new
 * if the file names are different, the user is asked if he wants to replace one file
 *   with the other
 * returns true if the used confirms the replace, otherwise flase
 */
function checkFileReplace(element,file,oldfile) {
 	var return_value = true;
 	/* first remove and path information so we just have the new filename.ext */
 	file = file.replace(/\\/g,'/');
 	var newfile = file.split('/');
 	newfile = newfile[newfile.length-1];
	if (newfile==oldfile) {
		return_value = confirm('Are you sure you want to replace\n' + newfile + '?');
	} else {
		return_value = confirm('Are you sure you want to replace\n' + oldfile + ' with\n' + newfile + '?');
	}
	return return_value;
}

