// JavaScript Document

function dismissMessage(id, subject, from) {
	var answer = confirm("Are you sure that you want to mark this message as READ?\n\n'" + subject + "' from '" + from + "'\n\n");
	if (answer) {
		window.location = "crm_viewmessages_dismiss.php?id=" + id;
		return true;
	} else {
		return false;
	}
}

function checkSendMessage() {
	var sendto = document.myform.sendto;
	var subject = document.myform.subject;
	var message = document.myform.message;
	
	if (sendto.selectedIndex == 0) {
		alert("Please select the person to send to");
		sendto.focus();
		return false;
	}
	if (subject.value == "") {
		alert("Please enter subject");
		subject.focus();
		return false;
	}
	if (subject.value.indexOf("'") != -1) {
		alert("Please remove the apostrophe/s (') from subject");
		subject.focus();
		return false;
	}
	if (subject.value.indexOf('"') != -1) {
		alert('Please remove the quotation mark/s (") from subject');
		subject.focus();
		return false;
	}
	if (message.value == "") {
		alert("Please enter message");
		message.focus();
		return false;
	}
	if (message.value.indexOf('"') != -1) {
		alert('Please remove the quotation mark/s (") from message');
		message.focus();
		return false;
	}
	document.myform.action = "crm_sendmessage.php";
	return true;
}

function checkCreateSubFolder() {
	var subfolder = document.subform.subfolder;
	var folder = document.subform.folder;
	
	if (subfolder.value == "") {
		alert("Please enter Sub-Folder Name");
		subfolder.focus();
		return false;
	}
	if (folder.selectedIndex == 0) {
		alert("Please select folder to create under");
		folder.focus();
		return false;
	}
	document.subform.action = "crm_manage_subfolder_create.php";
	return true;
}

function checkCreateSubFolderMy() {
	var newfolder = document.subform.newfolder;
	
	if (newfolder.value == "") {
		alert("Please enter Sub-Folder Name");
		newfolder.focus();
		return false;
	}
	document.subform.action = "crm_myfolders_subfolder_create.php";
	return true;
}

function checkMoveFile() {
	var movefolder = document.moveform.movefolder;
	if (movefolder.selectedIndex == 0) {
		alert("Please select the folder");
		movefolder.focus();
		return false;
	}
	document.moveform.action = "crm_manage_file_move.php";
	return true;
}

function checkMoveFileMy() {
	document.moveform.action = "crm_myfolders_file_move.php";
	return true;
}

function deleteFolder(str1, str2) {
	var answer = confirm("Are you sure you want to delete the following folder:\n\n\t'" + str2 + "'\n\nPLEASE NOTE: All files under this folder (if any) will also be removed.\n\n");
	if (answer) {
		window.location = "crm_manage_folder_rem.php?id=" + str1;
		return true;
	} else {
		return false;
	}
}

function deleteSubFolder(str1, str2) {
	var answer = confirm("Are you sure you want to delete the following sub-folder:\n\n\t'" + str2 + "'\n\nPLEASE NOTE: All files under this sub-folder (if any) will also be removed.\n\n");
	if (answer) {
		window.location = "crm_manage_subfolder_rem.php?id=" + str1;
		return true;
	} else {
		return false;
	}
}

function deleteSubFolderMy(str1, str2) {
	var answer = confirm("Are you sure you want to delete the following sub-folder:\n\n\t'" + str2 + "'\n\nPLEASE NOTE: All files under this sub-folder (if any) will also be removed.\n\n");
	if (answer) {
		window.location = "crm_myfolders_subfolder_rem.php?id=" + str1;
		return true;
	} else {
		return false;
	}
}

function deleteFile(str1, str2) {
	var answer = confirm("Are you sure you want to delete the following file:\n\n'" + str2 + "'\n\n");
	if (answer) {
		window.location = "crm_manage_file_rem.php?id=" + str1;
		return true;
	} else {
		return false;
	}
}

function deleteFileMy(fileid, filename, subfolder, subsubfolder) {
	var answer = confirm("Are you sure you want to delete the following file:\n\n'" + filename + "'\n\n");
	if (answer) {
		window.location = "crm_myfolders_rem.php?id=" + fileid + "&subfolder=" + subfolder + "&subsubfolder=" + subsubfolder;
		return true;
	} else {
		return false;
	}
}

function deleteFolderMy(folderid, foldername, subfolder) {
	var answer = confirm("Are you sure you want to delete the following sub-folder:\n\n'" + foldername + "'\n\nNOTE: All files and folders associated with this sub-folder will be deleted!");
	if (answer) {
		window.location = "crm_myfolders_remfolder.php?id=" + folderid + "&subfolder=" + subfolder;
		return true;
	} else {
		return false;
	}
}

function checkCreateFolder() {
	var foldername = document.myform.foldername;
	if (foldername.value == "") {
		alert("Please enter Folder Name");
		foldername.focus();
		return false;
	}
	if (foldername.value.indexOf(" ") != -1) {
		alert("Please replace the space in Folder Name with an underscore '_'");
		foldername.focus();
		return false;
	}
	document.myform.action = "crm_manage_folder_create.php";
	return true;
}

function checkUploadFile() {
	var foldername = document.myform2.foldername;
	if (foldername.selectedIndex == 0) {
		alert("Please select Folder to upload to");
		foldername.focus();
		return false;
	}
	document.myform2.action = "crm_manage_file_upload.php";
	return true;
}

function checkUploadFileMy() {
	document.myform2.action = "crm_myfolders_upload.php";
	return true;
}

function checkOrderViewItem() {
	if (document.myform.id.value == "") {
		alert("Please select an order to view");
		return false;
	} else {}
	document.myform.action = "admin_orders_view.php";
	return true;
}

function checkShopSignupForm() {
	var theform = document.shop_signupform;
	var firstname = theform.firstname.value;
	var lastname = theform.lastname.value;
	var email = theform.email.value;
	var confemail = theform.confemail.value;
	var password = theform.password.value;
	var confpassword = theform.confpassword.value;
	var contact = theform.contact.value;
	var theword = theform.theword.value;
	
	if (firstname == "") {			alert("Please enter First Name");						theform.firstname.focus();									return false;}
	if (lastname == "") {			alert("Please enter Last Name");						theform.lastname.focus();									return false;}
	if (email == "") {				alert("Please enter E-Mail Address");					theform.email.focus();										return false;}
	if (email.indexOf("@") == -1) { alert("Please enter Valid E-Mail Address");				theform.email.focus();										return false;}
	if (email.indexOf(".") == -1) { alert("Please enter Valid E-Mail Address");				theform.email.focus();										return false;}
	if (confemail == "") {			alert("Please confirm E-Mail Address");					theform.confemail.focus();									return false;}
	if (password == "") {			alert("Please enter Password");							theform.password.focus();									return false;}
	if (password.length < 6) {		alert("Password must have a minimum of 6 characters");	theform.password.focus();									return false;}
	if (confpassword == "") {		alert("Please confirm Password");						theform.confpassword.focus();								return false;}
	if (contact == "") {			alert("Please enter Contact Number");					theform.contact.focus();									return false;}
	if (theword == "") {			alert("Please enter Security Word");					theform.theword.focus();									return false;}
	if (email != confemail) {		alert("E-Mail Addresses do not match. Please re-type");
			theform.email.value = ""; theform.confemail.value = "";	theform.email.focus();	return false;}
	if (password != confpassword) {	alert("Passwords do not match. Please re-type");		
			theform.password.value = ""; theform.confpassword.value = ""; theform.password.focus();	return false;}
	if (theword != "wl54952.nt") {	alert("Security Word is incorrect. Please re-type");	theform.theword.value = ""; theform.theword.focus();		return false;}
	
	theform.action = "shop_signup_send.php";
}

function checkShopLoginForm() {
	var theform = document.shop_loginform;
	var username = theform.username.value;
	var password = theform.password.value;
	
	if (username == "") {	alert("Please enter Username");	theform.username.focus();	return false;}
	if (password == "") {	alert("Please enter Password");	theform.password.focus();	return false;}
	
	theform.action = "shop_validate.php";
}

function checkShopEnquireForm() {
	var theform = document.shop_enquireform;
	var desc = theform.description.value;
	
	if (desc == "") {
		alert("Please enter the enquiry description");
		theform.description.focus();
		return false;
	}
	if (desc.indexOf("'") != -1) {
		alert("Please remove the apostrophe (') character/s from the description");
		theform.description.focus();
		return false;
	}
	if (desc.indexOf('"') != -1) {
		alert('Please remove the quotation (") character/s from the description');
		theform.description.focus();
		return false;
	}
	if (desc.indexOf("%") != -1) {
		alert("Please remove the percentage (%) character/s from the description");
		theform.description.focus();
		return false;
	}
	theform.action = "shop_enquire_send.php";
}

function checkPostArticleForm() {
	var theform = document.postarticle_form;
	var title = theform.title.value;
	var article = theform.article.value;
	
	if (title == "") {
		alert("Please enter a title for the article");
		theform.title.focus();
		return false;
	}
	if (article == "") {
		alert("Please enter information for the article");
		theform.article.focus();
		return false;
	}
	theform.action = "admin_postarticle_send.php";
}

function checkUpdateImage() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an image to update");
		return false;
	} else {
		document.myform.action = "admin_manageimages_upd.php";
	}
}

function checkDeleteImage() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an image to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_manageimages_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateSolo() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an photo to update");
		return false;
	} else {
		document.myform.action = "admin_managesolos_upd.php";
	}
}

function checkDeleteSolo() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an photo to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_managesolos_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateWings() {
	var id = document.myform2.id.value;
	if (id == "") {
		alert("Please select an photo to update");
		return false;
	} else {
		document.myform2.action = "admin_managesolos_upd.php";
	}
}

function checkDeleteWings() {
	var id = document.myform2.id.value;
	if (id == "") {
		alert("Please select an photo to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform2.action = "admin_managesolos_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateArticle() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an article to update");
		return false;
	} else {
		document.myform.action = "admin_managearticles_upd.php";
	}
}

function checkDeleteArticle() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an article to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_managearticles_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateBlog() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a blog entry to update");
		return false;
	} else {
		document.myform.action = "admin_charliemanage_upd.php";
	}
}

function checkDeleteBlog() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a blog entry to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_charliemanage_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateUpholstry() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to update");
		return false;
	} else {
		document.myform.action = "admin_manageupholstry_upd.php";
	}
}

function checkDeleteUpholstry() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
		if (answer){
			document.myform.action = "admin_manageupholstry_del.php";
			return true;
		}
		else {return false;}
	}
}

function checkUpdateItem() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to update");
		return false;
	} else {
		document.myform.action = "admin_manageitems_upd.php";
	}
}

function checkDeleteItem() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_manageitems_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateStudent() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a student to update");
		return false;
	} else {
		document.myform.action = "admin_managestudents_upd.php";
	}
}

function checkDeleteStudent() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a student to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_managestudents_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateStaff() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a staff profile to update");
		return false;
	} else {
		document.myform.action = "admin_managestaff_upd.php";
	}
}

function checkDeleteStaff() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select a staff profile to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
			if (answer){
				document.myform.action = "admin_managestaff_del.php";
				return true;
			}
			else {return false;}
	}
}

function checkUpdateSatellite() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to update");
		return false;
	} else {
		document.myform.action = "admin_managesatellite_upd.php";
	}
}

function checkDeleteSatellite() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
		if (answer){
			document.myform.action = "admin_managesatellite_del.php";
			return true;
		}
		else {return false;}
	}
}

function checkManageSatellite() {
	document.myform.action = "admin_photosatellite.php";
}

function checkDeletePhotoSatellite() {
	var id = document.myform.id.value;
	if (id == "") {
		alert("Please select an item to delete");
		return false;
	} else {
		var answer = confirm("Are you sure you want to delete this entry?")
		if (answer){
			document.myform.action = "admin_photosatellite_del.php";
			return true;
		}
		else {return false;}
	}
}