/*

	delvalcremation.com Online Identification Service JavaScript library
	(c) 2007 Delaware Valley Cremation Service. All rights reserved (www.appware.biz)
	Developed by AppWare, LLC. (www.appware.biz)

*/




//	Returns string with leading and trailing spaces trimmed
	function trim(s) {
		return s.replace(/^\s*|\s*$/g,"");
	}
//	--------------------


//	Returns true if login form validates
	function frmLogin_IsValid() {

//		Initialize error message
		var ErrMsg = "";

//		Set form
		var f = document.frmLogin;

//		Trim text fields
		f.txtUserName.value = trim(f.txtUserName.value);
		f.txtPassword.value = trim(f.txtPassword.value);

//		Validate fields
		if ( !IsUserName(f.txtUserName.value) ) {
			ErrMsg = ErrMsg + "     - Your user name is missing or invalid\n";
		}
		if ( !IsPassword(f.txtPassword.value) ) {
			ErrMsg = ErrMsg + "     - Your password is missing or invalid\n";
		}

//		Did form validate?
		if ( ErrMsg.length > 0 ) {
			window.alert("The following error(s) occurred while processing your request:\n\n" + ErrMsg);
			f.txtUserName.focus()
			return false;
		}
		else {
			return true;
		}

	}
//	--------------------


//	Returns true if add client form validates
	function frmAddClient_IsValid() {

//		Initialize error message
		var ErrMsg = "";

//		Set form
		var f = document.frmAddClient;

//		Trim text fields
		f.txtDeceasedName.value = trim(f.txtDeceasedName.value);
		f.txtUserName.value = trim(f.txtUserName.value);
		f.txtPassword.value = trim(f.txtPassword.value);

//		Validate fields
		if ( f.txtDeceasedName.value.length == 0 ) {
			ErrMsg = ErrMsg + "     - You must enter the deceased's name\n";
		}
		if ( !IsUserName(f.txtUserName.value) ) {
			ErrMsg = ErrMsg + "     - The user name is missing or invalid\n";
		}
		if ( !IsPassword(f.txtPassword.value) ) {
			ErrMsg = ErrMsg + "     - The password is missing or invalid\n";
		}
		var s = trim(f.filPhotograph.value);
		if ( s.length == 0 ) {
			ErrMsg = ErrMsg + "     - You must select a photograph to upload\n";
		}
		else {
			if ( !IsFileType(s) ) {
				ErrMsg = ErrMsg + "     - The photograph file type is not valid\n";
			}
		}

//		Did form validate?
		if ( ErrMsg.length > 0 ) {
			window.alert("The following error(s) occurred while processing your request:\n\n" + ErrMsg);
			f.txtDeceasedName.focus()
			return false;
		}
		else {
			document.getElementById("btnAdd").disabled = true;
			var b = ShowProgress();
			return true;
		}

	}
//	--------------------


//	Returns true if client terms acceptance form validates
	function frmClientAccept_IsValid() {

//		Initialize error message
		var ErrMsg = "";

//		Set form
		var f = document.frmClientAccept;

//		Trim text fields
		f.txtApproverName.value = trim(f.txtApproverName.value);
		f.txtApproverRelationship.value = trim(f.txtApproverRelationship.value);

//		Validate fields
		if ( !f.chkAcceptTerms.checked ) {
			ErrMsg = ErrMsg + "     - You must accept the Terms and Conditions\n";
		}
		if ( f.txtApproverName.value.length == 0 ) {
			ErrMsg = ErrMsg + "     - You must enter your name\n";
		}
		if ( f.txtApproverRelationship.value.length == 0 ) {
			ErrMsg = ErrMsg + "     - You must enter your relationship\n";
		}

//		Did form validate?
		if ( ErrMsg.length > 0 ) {
			window.alert("The following error(s) occurred while processing your request:\n\n" + ErrMsg);
			f.chkAcceptTerms.focus()
			return false;
		}
		else {

//			Confirm submission
			if ( window.confirm("Are you sure you want to accept the Terms and Conditions?") ) {
				return true;
			}
			else {
				return false;
			}

		}

	}
//	--------------------


//	Returns true if client approval form validates
	function frmClientApproval_IsValid() {

//		Initialize error message
		var ErrMsg = "";

//		Set form
		var f = document.frmClientApproval;

//		Validate fields
		if ( f.optApprovePhoto[1].checked ) {

//			Confirm submission
			if ( window.confirm("Are you sure you want to approve this photograph?") ) {
				return true;
			}
			else {
				return false;
			}

		}
		else {

//			Confirm submission
			if ( window.confirm("Are you sure you do not want to approve this photograph?") ) {
				return true;
			}
			else {
				return false;
			}

		}

	}
//	--------------------


//	Returns true if user name validates
	function IsUserName(s) {

//		Set and test regular expression
		var oRX = /^\w{5,32}$/;
		if ( oRX.test(s) ) {
			return true;
		}
		return false;

	}
//	--------------------


//	Returns true if password validates
	function IsPassword(s) {

//		Set and test regular expression
		var oRX = /^\w{5,32}$/;
		if ( oRX.test(s) ) {
			return true;
		}
		return false;

	}
//	--------------------


//	Returns true if file name is allowable file type
	function IsFileType(sFileName) {


//		Set valid files types
		var sTypes = new Array("jpg"); // tiff and tif removed 4/16 - IE cannot render tif image

//		loop through valid file types
		var iMax = sTypes.length;
		var oRX;
		for ( var i=0; i<iMax; i++ ) {

//			Set and test regular expression
			var oRX = new RegExp("." + sTypes[i].toUpperCase() + "$");
			if ( oRX.test(sFileName.toUpperCase()) ) {
				return true;
			}
		}

//		Set default return value
		return false;

	}
//	--------------------

