	if(unsavedData) unsavedHint();
	
	function unsavedHint(o) {
		var a = o;
		var arr = [];
		for(var n in a){
		  a = a.parentNode;
		  if(a.nodeName == 'BODY') // return if the element is the body element
		    break;
		  arr.push(a.id);
		}
		if(arr.indexOf("consultationNote") != -1){
			var saveButton = document.getElementById('saveDataButton');
			if(saveButton) {
				saveButton.style.border = '1px dashed red';
				saveButton.title = 'Save (form is modified)'
				if (document.title.lastIndexOf('(modified)') == -1) {
					document.title += " (modified)";
				}
			}
		}
	}
	function dataEntered(e) {
		var saveButton = document.getElementById('save');
		var saveButton1 = document.getElementById('saveDataButton');
		var blogSaveButton = document.getElementById('blogSave');
		
		if(saveButton || saveButton1 || blogSaveButton) {
			if(!e) {
				e = event;
			}
			var o = e.target || e.srcElement;
			var tagName =  o.tagName;

			if(tagName && ( tagName == "INPUT" || tagName == "TEXTAREA" || ((tagName ==  "SELECT" || tagName ==  "OPTION" ) && o.id!="patients" && o.parentNode.id!="patients"))){
				unsavedData = true;
				unsavedHint();
				if(o.id=="comments"){
					if (document.getElementById("commentAreaClickedId"))
						document.getElementById("commentAreaClickedId").value = true;
				}else  if (o.classList && o.classList.contains("noUnsavedWarning"))	{
					// console.log("don't show warning (template)");
				}else{
					unsavedData = true;
					unsavedHint(o);
					if (document.getElementById("unsaveButtonId"))
						document.getElementById("unsaveButtonId").value = true;
				}
			}else {
				var divName = o.innerHTML;
				var isSaveButton = divName.indexOf(saveButton);
				var isSaveButton1 = divName.indexOf(saveButton1);
				var parentNodeTagName;
				if(o.parentNode){
					parentNodeTagName =o.parentNode.tagName;
				}
				if(tagName && (tagName == "A" || parentNodeTagName == "A")){
					if(o.id!='saveDataButton' && o.id!='save' && o.parentNode.id!='save' &&  o.parentNode.id!='saveDataButton'){
						var r = dataGuard()
						if(r && o.id=="saveCommentsButton"){
							saveComments("1");
						}else if(r && o.id=="historyButton"){
							var formId=document.getElementById("formIdForHistory").value;
							var formName=document.getElementById("formNameForHistory").value;
							patientHistory(formId, formName);
						}else if(saveButton && unsavedData && r) {
							return true;
						}else if(r) {
						 	return true;
						}else if(!r){
							return false;
						}
					}else{
						if(o.id=="historyButton"){
							var formId=document.getElementById("formIdForHistory").value;
							var formName=document.getElementById("formNameForHistory").value;
							patientHistory(formId, formName);
						}else if(document.getElementById("commentAreaClickedId") && document.getElementById("commentAreaClickedId").value == 'true'){
							if(trimAll(document.getElementById('comments').value).length >0 && isSaveButton >= 0){
								var r = confirm("You have unsent comment.\n Ignore and Proceed?");
								return r;
							}
						}
					}
				}else if(tagName && (tagName == "DIV" || parentNodeTagName == "DIV")){
					if(o.id=="saveCommentsButton"){
						if(document.getElementById("unsaveButtonId") && document.getElementById("unsaveButtonId").value){
							var r = dataGuard();
							if(!r){
								return false;
							}
						}
					}else if(o.id=="historyButton"){
						if(document.getElementById("unsaveButtonId").value){
							var r = dataGuard();
							if(!r){
								return false;
							}
						}
						var formId=document.getElementById("formIdForHistory").value;
						var formName=document.getElementById("formNameForHistory").value;
						patientHistory(formId, formName);
					}
				}
			}
		}
	}

	
	function dataGuard() {
		var saveButton = document.getElementById('saveDataButton');
		var saveButton1 = document.getElementById('save');
		var blogSaveButton = document.getElementById('blogSave');

		if (((saveButton || saveButton1) && unsavedData) || (blogSaveButton && blogUnsavedFlag)) {
			return window.confirm("You may have changes that are not saved.\nMoving to a different page will discard your changes.\n\nProceed?");
		}
		return true;
	}
	
	
	