/*
Created By: Thennarasu J
Created On:03-Nov-06
Purpose: Modified the confirmation message for Lab Result Delete functionality
*/

var gpr = gpr || {};
gpr.data = {
	careDataSessionTimeOut: 5,
	gprsurl : '',	
	user: { loggedIn: false },	
	patients: {},	
	currentPatientID: 0,	
	getCurrentPatientCollection: function(collection)	
	{	var currentPatientCollection = [];	
		/*todo:this should be an array for easy sorting */		
		for(var id in this[collection])	
			{	//modified by deepak, Nous		
				if ( (this[collection][id] != null && this[collection][id].patientID == this.currentPatientID) || (gpr.data.patient != null && this[collection][id].patientID == gpr.data.patient.id) )	
						{				currentPatientCollection.push(this[collection][id]);			}	
			}		
		return currentPatientCollection;
	},	
	
	fetchedAppointment:false,
	fetchedAlerts:false,
	patientLRs : {}
};
gpr.deliveryTypes = { Vaginal:1, CSection:2, VBAC:3};
gpr.gender ={	Male: true,	Female: false};	
gpr.userRoles ={	None: 0,	Patient: 1};
gpr.paymentType ={	None: 0,	CreditCard: 1,	Check: 2,	Refer:3, Promotion:4};
gpr.chargeType ={	None: 0,	Registration:1,	Membership:2,MembershipRenewal:3,	RegistrationRenewal:4};
gpr.treatmentMethod={	Medication:0,	Diet:1,	Exercise:2,	Hospitalization:3,	Surgery:4,	Therapy:5};
gpr.menu = {}; 
gpr.MedicationType ={	Prescription:0, Non_Prescription:1};
gpr.FamilyHistorySelect ={	None:0, Yes:1, No:2, Unsure:3};
gpr.isMH = false;
gpr.controler = function(id, loginStatusId, workStatusId, workAreaId, sidebarId, patientsListId)
{	
		this.id = id;	
		gpr.registry.add(this);	
		this.login = function()	{ /*todo */	};	
		this.onLogin = function()	{		
				this.setWorkStatus();		
				var form = new gpr.forms.login(this.id + '.login', gpr.dispatcher.bindEx0(this, 'onLogin'), gpr.dispatcher.bindEx0(this, 'signup'), gpr.dispatcher.bindEx0(this, 'resetPassword'));	
				var body = form.getBody();
				if ( body )		{		
						this.setWorkStatus('Logging in ...');
						new gpr.ajax().post('/Login.aspx', body, gpr.dispatcher.bindEx0(this, 'onLoginComplete'))
				}		
			};
	this.onLoginComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			location.reload();
		}
	};

	this.logout = function()
	{
		this.setWorkArea();
		this.setWorkStatus('Logging out ...');
		if (objWin && !objWin.closed)
		{
			objWin.close();
		}
		if(objWinCPTCodes && !objWinCPTCodes.closed)
		{
			objWinCPTCodes.close();
		}
		if(objWinICDCodes && !objWinICDCodes.closed)
		{
			objWinICDCodes.close();
		}
		var body = "recordType=user&action=logout&ID=" + gpr.data.user.id +"&careDataUserID=0" + "&patientID=" + 0 ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body,gpr.dispatcher.bindEx0(this, 'onLogoutComplete'));
		
	};

	this.onLogoutComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			document.cookie = gpr.environment.sessionToken + '=; path=/; expires=' + new Date(1969, 2, 4).toUTCString();
			location.href = 'index.htm';
			
		}
	};
	
	//added by deepak, nous, 5-mar-2007, to resolve the issue of the user getting logged in bydefault when
	//the medical history page is opened and then GlobalPatientRecord.Handlers is accessed from the same page.
		
	this.logoutCDW = function()
	{
		//alert(gpr.data.currentPatientID);
		if(!gpr.data.currentPatientID && gpr.data.currentPatientID == 0)
		{
			this.setWorkArea();
			if (objWin && !objWin.closed)
			{
				objWin.close();
			}
			document.cookie = gpr.environment.sessionToken + '=; path=/; expires=' + new Date(1969, 2, 4).toUTCString();
			location.href = 'login.htm';
		}
	}

	this.signup = function()
	{
		this.setWorkStatus('Loading...');
		var form = new gpr.forms.signup(this.id + '.signup', gpr.dispatcher.bindEx0(this, 'onSignup'));
		this.setWorkArea(form.getHtml());
		this.setWorkStatus('');
		document.getElementById(this.id + '.signup.firstName').focus();
	};
	
	this.signout = function()
	{
		document.cookie = gpr.environment.sessionToken + '=; path=/; expires=' + new Date(1969, 2, 4).toUTCString();
	}
	
	this.onSignup = function()
	{
		var form = gpr.registry.get(this.id + '.signup');
		var body = gpr.data.user.id && gpr.data.user.paymentType != gpr.paymentType.Refer?  form.getPaymentBody() : form.getBody();
		if ( body )
		{
			this.setWorkStatus('Creating Account...Please Wait... This may take couple of minutes...');
			if( gpr.data.user.paymentType == gpr.paymentType.Refer)
			{
			var url = '/Signup.aspx';
			}
			else
			{
			var url = ( gpr.data.user.id ? '/AddPayment.aspx' : '/Signup.aspx')
			}
			body = body + '&repeatPasswordLimit=' + gpr.data.passwordSettings[1].repeatPasswordLimit
			new gpr.ajax().post(url, body, gpr.dispatcher.bindEx0(this, 'onSignupComplete'))
		}
	};

	this.onSignupComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			eval(ajax.responseText());
			this.setWorkStatus();
			this.initDashboard(new gpr.ui.Welcome());
		}
	};


	this.GetCareDataSessionTimeOutComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			eval(ajax.responseText());
			setTimeout(this.onCDWSessionExpire,gpr.data.careDataSessionTimeOut);
			this.setWorkStatus();
		}
	}

	this.showProviderAccessForm = function()
	{
		this.setWorkStatus('Loading...');
		var form = new gpr.forms.providerAccess(this.id + '.providerAccess', gpr.dispatcher.bindEx0(this, 'onProviderAccessForm'));
		this.setWorkArea(form.getHtml());
		this.setWorkStatus();
	};
	
	this.onProviderAccessForm  = function()
	{
		var form = gpr.registry.get(this.id + '.providerAccess');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Please Wait....Retrieving Patient\'s Record....');
			new gpr.ajax().post('/GetPatientRecordByID.aspx', body, gpr.dispatcher.bindEx1(this, 'onProviderAccessFormComplete', 1))
		}
	}
	
	this.getFullReport  = function(patientID,userID)
	{
		var body = 'patientID=' + encodeURIComponent(patientID) + '&userID=' + userID;
		this.setWorkStatus('Please Wait....Retrieving Patient\'s Record....');
		new gpr.ajax().post('/GetPatientRecord.aspx', body, gpr.dispatcher.bindEx1(this, 'onProviderAccessFormComplete', 0))
	}
	
	
	//added by Deepak, Nous 10-Jan-2007	
	this.displayFullReport  = function(patientID)
	{
		this.setWorkStatus('Please Wait....Retrieving Patient\'s Record....');
		document.write('<html><head><link rel="stylesheet" type="text/css" href="includes/master.css" />');
		document.write('<style media=print>.printdiv{display:none;}');
		document.writeln('.matterDiv{display:block;}');
		document.writeln('</style>');
		document.write('<script>var abc = "abc";'+
			'function hidenprint(){document.getElementById("printdiv").style.display = "none";window.print();}'+
			'function showlinks(){document.getElementById("printdiv").style.display = "block";}'+
			'function onbodyload(){document.getElementById("printdiv").style.display = "none";setTimeout( "showlinks()", 5000);}'+
			'</script>'+
			'</head><body onload="onbodyload()">');

		document.write(new gpr.reports.displayPatientRecord(this.id + '.displayFullReport', patientID, gpr.dispatcher.bindEx0(this, 'getFullReport')).getHtml());
		document.write('</body></html>');
		
		this.setWorkStatus();
	}

	this.onProviderAccessFormComplete = function(IsProviderAccess, ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			this.setWorkStatus();
			eval(ajax.responseText());
			//document.getElementById(sidebarId).parentNode.style.display = "none"; /* todo:move this to a method */
			this.setWorkArea((new gpr.reports.patientRecord(gpr.dispatcher.bindEx0(this, 'displayFullReport'), gpr.dispatcher.bindEx0(this, 'providerlogout'),IsProviderAccess)).getHtml());
		}
	}
	
	this.providerlogout = function(patientID,providerID)
	{
		this.setWorkArea();
		this.setWorkStatus('Logging out ...');
		if (objWin && !objWin.closed)
		{
			objWin.close();
		}
		var body = "recordType=ProviderLogin&action=logout&ID=" + patientID +"&careDataUserID=" + providerID  + "&patientID=" + patientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body);
		
		document.cookie = gpr.environment.sessionToken + '=; path=/; expires=' + new Date(1969, 2, 4).toUTCString();
		location.href = 'index.htm'
	}
	
	
	this.getIDCard  = function(patientID)
	{

		var body = 'patientID=' + encodeURIComponent(patientID)
		this.setWorkStatus('Please Wait....Retrieving Patient\'s Record....');
		new gpr.ajax().post('/GetPatientIDCard.aspx', body, gpr.dispatcher.bindEx0(this, 'onIDCardComplete'))
		var body = "recordType=IDCard&action=view&ID="+ patientID + "&careDataUserID=0"  + "&patientID=" + patientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)

	}
	
	this.onIDCardComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			this.setWorkStatus();
			eval(ajax.responseText());
			this.setWorkArea((new gpr.reports.PatientIDCard()).getHtml());
		}
	}


	this.resetPassword = function()
	{
		this.setWorkStatus('Loading...');
		var form = new gpr.forms.resetPassword(this.id + '.resetPassword', gpr.dispatcher.bindEx0(this, 'onResetPassword'));
		this.setWorkArea(form.getHtml());
		this.setWorkStatus();
		document.getElementById(this.id + '.resetPassword.userName').focus()
	};

	this.onResetPassword = function()
	{
		var form = gpr.registry.get(this.id + '.resetPassword');
		var body = form.getBody();
		if ( body )
		{
			body = body + '&repeatPasswordLimit=' + gpr.data.passwordSettings[1].repeatPasswordLimit
			if(form.isPasswordChange)
			{
				this.setWorkStatus('Reseting password ...');
				new gpr.ajax().post('/ResetPassword.aspx', body, gpr.dispatcher.bindEx0(this,'onPasswordChangeComplete'))
			}
			else
			{
				this.setWorkStatus('Processing ...');
				new gpr.ajax().post('/ResetPassword.aspx', body, gpr.dispatcher.bindEx0(this, (form.reset ? 'onResetPasswordComplete' : 'onResetPasswordQuestionComplete')))
			}
		}
	};
	
	this.onResetPasswordQuestionComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			this.setWorkStatus();
			var form = gpr.registry.get(this.id + '.resetPassword');
			this.setWorkArea(form.getHtml(ajax.responseText(),false));
		}
	};
		
	this.onResetPasswordComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			//this.setWorkStatus('Your new password has been emailed to you. Please check your email in few minutes ');
			//this.login();
			
			this.setWorkStatus();
			var form = gpr.registry.get(this.id + '.resetPassword');
			this.setWorkArea(form.getHtml(ajax.responseText(),true));
		}
	};

	this.onPasswordChangeComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			alert('Your password changed successfully.');
			//this.setWorkStatus('Your password changed successfully.');
			//this.onLogin();
			//location.href = 'index.htm';
			location.reload();
		}
	};
		
		
	this.editPatient = function(patientID)
	{
		this.setWorkStatus();
		var form = new gpr.forms.patient(this.id + '.edit-patient', gpr.data.patients[patientID || 0], gpr.dispatcher.bindEx0(this, 'onEditPatient'),0,gpr.dispatcher.bindEx0(this,'onClose'));
		this.setWorkArea(form.getHtml());
		if(patientID != 0)	
		{
			//Below lines added by manoj for Audit log
			var body = "recordType=PersonalInfo&action=view&ID=" + patientID + "&careDataUserID=0"  + "&patientID=" + patientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	};

	//added by deepak, nous, 22-feb-2007, enable add/edit option from medical history
	this.editCDWPatient = function(patientID)
	{
		this.setWorkStatus();
		var form = new gpr.forms.patient(this.id + '.ShowPatientReport', gpr.data.patients[patientID || 0], gpr.dispatcher.bindEx0(this, 'onEditCDWPatient'),0,gpr.dispatcher.bindEx0(this,'onCDWCancel'));
		this.setWorkArea(form.getHtml());
		if(patientID != 0)	
		{
			//Below lines added by manoj for Audit log
			if(document.getElementById('careDatauserID'))
				var careDatauserID = document.getElementById('careDatauserID').value;
			else
				var careDatauserID = '0';
			var body = "recordType=PersonalInfo&action=view&ID=" + patientID + "&careDataUserID=" + careDatauserID + "&patientID=" + patientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	};
	
	

	this.onEditPatient = function(isNew)
	{
		var form = gpr.registry.get(this.id + '.edit-patient');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus((isNew ? 'Creating Patient Record....' : 'Saving data ...'));
				//Below code is added by manoj to implement photo save 
			window.frames[0].document.forms[0].elements['hdnIsNewPatient'].value = (isNew ? "1" : "0");
			window.frames[0].document.forms[0].elements['hdnPatientDetails'].value = body;
			window.frames[0].document.forms[0].elements['hdnCareDataUserID'].value = '0';
			window.frames[0].document.getElementById('lnkAdd').click();
			this.setWorkStatus('');
			//belowline is commented by Manoj for photo upload feature. (refer . PatientPhoto.aspx.cs)
			/*
			var url = isNew ?  '/SignupPatient.aspx' : '/EditPatient.aspx'
			new gpr.ajax().post(url, body, gpr.dispatcher.bindEx0(this, 'onEditPatientComplete')) */
		}
	};

	//added by deepak, nous, 22-feb-2007, enable add/edit option from medical history
	this.onEditCDWPatient = function(isNew)
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if(document.getElementById('careDatauserID'))
				var careDatauserID = document.getElementById('careDatauserID').value;
			else
				var careDatauserID = '0';
		if ( body )
		{
			this.setWorkStatus((isNew ? 'Creating Patient Record....' : 'Saving data ...'));
			window.frames[0].document.forms[0].elements['hdnIsNewPatient'].value = (isNew ? "1" : "0");
			window.frames[0].document.forms[0].elements['hdnPatientDetails'].value = body;
			window.frames[0].document.forms[0].elements['hdnCareDataUserID'].value = careDatauserID;
			window.frames[0].document.getElementById('lnkAdd').click();
			this.setWorkStatus('');
		}
	};
	
	//Added By Manoj from PatinetDemographics page in CDW
	this.onCDWPatientDemographicsCancel = function()
	{
		//parent.refreshParentPage();
		parent.close();
	}
		
	this.onEditPatientComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			this.setWorkStatus()
			eval(ajax.responseText());
			
	
			if(gpr.data.patients[gpr.data.currentPatientID].suspended == true && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.CreditCard)
			{
				// the payment failed -- we need to ask user to submit credit card info again
				var msg = "Your Patient Record is created however your Credit Card didn't go through. Please correct the information and submit again"
				var form = new gpr.forms.paymentDue(this.id + '.paymentDue', gpr.dispatcher.bindEx0(this, 'onPaymentSubmit', 1), gpr.dispatcher.bindEx0(this, 'initDashboard'),  msg, gpr.chargeType.Membership, gpr.data.currentPatientID, (gpr.consts.memebershipFee))
				this.setWorkArea(form.getHtml());
			}
			else
			{	
				var customPortlet = gpr.data.patients[gpr.data.currentPatientID].suspended == true  && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.Check ? new gpr.ui.MemberCheckMsg() : null
				//this.initDashboard(customPortlet);
				gpr.dispatcher.call(this.id,'onPatientChange',gpr.data.currentPatientID);
			}
		}
	};
	
	//function Added By Manoj For Edit PatientChange
	this.onEditPatientCompleteNew = function()
	{
		if(gpr.data.patients[gpr.data.currentPatientID].suspended == true && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.CreditCard)
		{
			// the payment failed -- we need to ask user to submit credit card info again
			var msg = "Your Patient Record is created however your Credit Card didn't go through. Please correct the information and submit again"
			var form = new gpr.forms.paymentDue(this.id + '.paymentDue', gpr.dispatcher.bindEx0(this, 'onPaymentSubmit', 1), gpr.dispatcher.bindEx0(this, 'initDashboard'),  msg, gpr.chargeType.Membership, gpr.data.currentPatientID, (gpr.consts.memebershipFee))
			this.setWorkArea(form.getHtml());
		}
		else
		{	
			var customPortlet = gpr.data.patients[gpr.data.currentPatientID].suspended == true  && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.Check ? new gpr.ui.MemberCheckMsg() : null
			//this.initDashboard(customPortlet);
			gpr.dispatcher.call(this.id,'onPatientChange',gpr.data.currentPatientID);
		}
	}
			
	this.onEditPatientTimeStampError = function()
	{
		new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
	}

	//added by deepak, nous, 22-feb-2007, enable add/edit option from medical history
	this.onEditCDWPatientComplete = function()
	{
		try
		{
			this.onCDW();
			
		}
		catch(e)
		{
			this.setWorkStatus(e.message);
		}
	};
	
	this.onPersonalInfo = function()
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			this.editPatient(gpr.data.currentPatientID);
		}
	}
	
	//added by deepak, nous, 22-feb-2007, enable Add/Edit Option from medical History
	this.onCDWPersonalInfo = function()
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			this.editCDWPatient(gpr.data.patient.id);
		}
	}

	this.onSelectPatient = function(patientID)
	{
		
		gpr.data.currentPatientID = patientID
		this.refreshDashBoard() 
	};
	
	this.onPatientChange = function(patientID)
	{
	
		gpr.data.currentPatientID = patientID
		
		if (patientID != 0)
		{
		var customPortlet = gpr.data.patients[gpr.data.currentPatientID].suspended == true  && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.Check ? new gpr.ui.MemberCheckMsg() : null
		}
		else
		{
		var customPortlet = null;
		}
		this.initDashboard(customPortlet,0);
		var body = "patientID=" + encodeURIComponent(patientID);
		new gpr.ajax().post('/GetPatientAlerts.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetAlertsComplete', false))
		new gpr.ajax().post('/GetAppointments.aspx', body, gpr.dispatcher.bindEx1(this, 'onGetAppointmentsComplete', false))
		new gpr.ajax().post('/GetLabResults.aspx', body, gpr.dispatcher.bindEx1(this, 'onGetLabResultsComplete', false))
		new gpr.ajax().post('/GetPatientRemindersForToday.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetRemindersForTodayComplete', false))
		
	
	};
	
	this.load = function()
	{
		if ( gpr.data.user && gpr.data.user.loggedIn )
		{
			this.initDashboard();
			this.setupPing();
		}
		else
		{
			this.login();
		}
	};
	
	this.setupPing = function()
	{
		if ( this.pingIntervalID )
		{
			window.clearInterval(this.pingIntervalID);
		}
		if ( gpr.data.user && gpr.data.user.loggedIn )
		{
			this.pingIntervalID = window.setInterval(gpr.dispatcher.bindEx0(this, 'ping'), gpr.environment.ping * 1000 * 60)
		}
	};
	
	this.ping = function()
	{
		if ( gpr.data.user && gpr.data.user.loggedIn )
		{
			new gpr.ajax().post('/Ping.aspx');
		}
		else
		{
			window.clearInterval(this.pingIntervalID);
		}
	}
	
	this.manageAccount = function(option, menuItem)
	{
		gpr.menu.hideSection(menuItem.parentElement.id)
		this.setWorkStatus();
		var form;
		
		switch(option)
		{
			case 1:
			 form = new gpr.forms.user(this.id + '.user', gpr.data.user, gpr.dispatcher.bindEx0(this, 'onEditUser'), gpr.dispatcher.bindEx0(this, 'onSecurityInfo'),gpr.dispatcher.bindEx0(this,'onClose'));
			 break;
		    case 2:
			form = new gpr.forms.patient(this.id + '.edit-patient', null, gpr.dispatcher.bindEx0(this, 'onEditPatient', '1'),0,gpr.dispatcher.bindEx0(this,'onClose'));
			 break;
			case 3:
			 form = new gpr.forms.todo(this.id + '.splitaccount');
			 break;
			case 4:
				form = new gpr.forms.todo(this.id + '.renew-membership');
			//commented by Deepak, Nous 19-Jan-2007 - Error we should pass the patientId and it is passing the user id
			//form = new gpr.forms.patient(this.id + '.renew-membership', gpr.data.user, gpr.dispatcher.bindEx0(this, 'onEditUser','1'),0,gpr.dispatcher.bindEx0(this,'onClose'));
			
			//commented by Deepak, Nous 19-Jan-2007 - this can be enabled once the logic for the renew membership is planned
			//form = new gpr.forms.patient(this.id + '.renew-membership', gpr.data.patients[gpr.data.currentPatientID], gpr.dispatcher.bindEx0(this, 'onEditUser','1'),0,gpr.dispatcher.bindEx0(this,'onClose'));
			 break;
		}
		
		this.setWorkArea(form.getHtml());
		
		if(option == 1)
		{
			var body = "recordType=UserAccount&action=view&ID="+ gpr.data.user.id + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	};

	this.onSecurityInfo = function()
	{
		this.setWorkStatus('Loading security info ...');
		new gpr.ajax().post('/GetUser.aspx', null, gpr.dispatcher.bindEx0(this, 'onSecurityInfoComplete'))
	};
	
	this.onEditUser = function(option, id)
	{
		var form = null;
		if(id)
			form = gpr.registry.get(id);
		else
			form = gpr.registry.get(this.id + '.user');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			body = body + '&repeatPasswordLimit=' + gpr.data.passwordSettings[1].repeatPasswordLimit
			new gpr.ajax().post('/EditUser.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditUserComplete'))
		}
	};

	this.onEditUserComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			//location.reload(); // TODO handle refresh without reload line commented by Nous for main page change
			if (gpr.data.currentPatientID == 0)
			{
				var customPortlet = null;
			}
			else
			{
				eval(ajax.responseText());
				var customPortlet = gpr.data.patients[gpr.data.currentPatientID].suspended == true  && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.Check ? new gpr.ui.MemberCheckMsg() : null
			}
			
			this.initDashboard(customPortlet);
		}
	};
	
	this.onPaymentSubmit = function(isPatient)
	{
		var form = gpr.registry.get(this.id + '.paymentDue');
		var body = form.getBody();
		
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/AddPayment.aspx', body, gpr.dispatcher.bindEx0(this, (isPatient ? 'onEditPatientComplete': 'onSignupComplete')))
		}
	};
	
	this.initDashboard  = function(customPortlet,onclose)
	{
		//modifyed by prakash adding special condtion for caredata thru gprs 2/11/2008
		if(gpr.queryString('ptype')	 == gpr.paymentType.Refer)//if(gpr.data.user.suspended)
		{
				document.cookie = gpr.environment.sessionToken + '=; path=/; expires=' + new Date(1969, 2, 4).toUTCString();
				var form = new gpr.forms.paymentDue(this.id + '.paymentDue', gpr.dispatcher.bindEx0(this, 'onPaymentSubmit'), gpr.dispatcher.bindEx0(this, 'logout'), paymentMsg(), gpr.chargeType.Registration, gpr.data.currentPatientID, gpr.data.user.balance);
				this.setWorkArea(form.getHtml());
		}
		else
		{
			this.setWorkStatus('');
			this.createSideBar(this.id);
			//var patientsList = new gpr.ui.patientsList(this.id + '.list-patients', gpr.dispatcher.bindEx0(this, 'onSelectPatient'), patientsListId);
			var patientsList = new gpr.ui.patientsList(this.id + '.list-patients', gpr.dispatcher.bindEx0(this, 'onPatientChange'), patientsListId);
			patientsList.refresh();
			this.setWorkArea(this.Portlets(onclose,customPortlet))
			var form = new gpr.ui.loginStatus(this.id + '.loginStatus', gpr.data.user, gpr.dispatcher.bindEx0(this, 'logout'), gpr.dispatcher.bindEx0(this, 'manageAccount'), loginStatusId, gpr.dispatcher.bindEx0(this,'onClose') );
			form.refresh();
		}
	}
	
	this.refreshDashBoard = function(onClose)
	{
		this.setWorkArea(this.Portlets(onClose));
		this.setWorkStatus("");
	}
	
	this.onSecurityInfoComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				gpr.dispatcher.call(this.id + '.user', 'setSecurityInfo')
				this.setWorkStatus();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	};
	
	//Conditions module-
	
	this.onPatientConditions = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-conditions');
			if( ! form )
			{
				form = new gpr.forms.patientConditions(this.id + '.patient-conditions', gpr.dispatcher.bindEx0(this, 'onChangePatientCondition'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onViewPatientCondition'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientConditions')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientConditions&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}
		}
	}	

	//added by deepak, nous, 13-Feb-2007, implementation of add/edit condition from medical history
	this.onChangeCDWPatientCondition = function(patientConditionID)
	{
		var form ;//= gpr.registry.get(this.id + '.patient-condition');
		if( ! form )
		{
			form = new gpr.forms.patientCondition(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientCondition'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientConditionDeleteCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientConditions[patientConditionID]));
		
		//Below lines added by manoj for Audit log
		if(patientConditionID != 0)
		{
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientConditions&action=view&ID=" + patientConditionID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}

	}
	
	this.onChangeCDWPatientConditionHistory = function(patientConditionID)
	{
		var form; //= gpr.registry.get(this.id + '.patient-condition');
		if( ! form )
		{
			form = new gpr.forms.patientConditionView(this.id + '.ShowPatientReport',  gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientConditions[patientConditionID]));
		
		//Below lines added by manoj for Audit log
		if(patientConditionID != 0)
		{
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientConditions&action=view&ID=" + patientConditionID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}

	}

	this.onChangePatientCondition = function(patientConditionID)
	{
		var form = gpr.registry.get(this.id + '.patient-condition');
		if( ! form )
		{
			form = new gpr.forms.patientCondition(this.id + '.patient-condition', gpr.dispatcher.bindEx0(this, 'onEditPatientCondition'), gpr.dispatcher.bindEx0(this, 'onPatientConditions'), gpr.dispatcher.bindEx0(this, 'onPatientConditionDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientConditions[patientConditionID]));
		//Below lines added by manoj for Audit log
		if(patientConditionID != 0)
		{
			var body = "recordType=PatientConditions&action=view&ID=" + patientConditionID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by deepak, nous, 13-Feb-2007, implement add/edit conditions from medical history
	this.onEditCDWPatientCondition = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientCondition.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientConditionComplete'))
		}
	}

	
	this.onEditPatientCondition = function()
	{
		var form = gpr.registry.get(this.id + '.patient-condition');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientCondition.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientConditionComplete'))
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit condition from medical history
	this.onPatientConditionDeleteCDW = function(patientConditionID, patientID)
	{
		if(confirm("Are you sure you want to delete this Condition Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientConditions&id=" + patientConditionID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientConditionComplete'))
		}
	}
	
	this.onPatientConditionDelete = function(patientConditionID, patientID)
	{
		if(confirm("Are you sure you want to delete this Condition Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientConditions&id=" + patientConditionID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientConditionComplete'))
		}
	}

	//added by deepak, nous
	this.onEditCDWPatientConditionComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			//try
			//{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDWCancel();
			//}
			//catch(e)
			//{
				//this.setWorkStatus(e.message);
			//}
		}
	}

	this.onEditPatientConditionComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				//location.reload();//can we do without this - TA
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientConditions();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onViewPatientCondition = function(patientConditionID)
	{
		var form = gpr.registry.get(this.id + '.View_patient_condition');
		if( ! form )
		{
			form = new gpr.forms.patientConditionView(this.id + '.View_patient_condition', gpr.dispatcher.bindEx0(this, 'onPatientConditions'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientConditions[patientConditionID]));
		//Below lines added by manoj for Audit log
		if(patientConditionID != 0)
		{
			var body = "recordType=PatientConditions&action=view&ID=" + patientConditionID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	//Patient Condition End------
	//onPatientInsurances
	this.onPatientInsurances= function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-insurances');
			if( ! form )
			{
				form = new gpr.forms.patientInsurances(this.id + '.patient-insurances', gpr.dispatcher.bindEx0(this, 'onChangePatientInsurances'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onPatientDocuments'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientInsurances'),this.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),3)));
			document.getElementById(this.id + '.patient-insurances.AddIns').focus();
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientInsurances&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}

	//added by Deepak, Nous, 21-Feb-2007, Add Document (insurance) in Medical History
	this.onCDWPatientInsurances= function()
	{
		var form = gpr.registry.get(this.id + '.patient-insurances');
		if( ! form )
		{
			form = new gpr.forms.patientInsurances(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onChangeCDWPatientInsurances'),gpr.dispatcher.bindEx0(this,'onCDWCancel'),gpr.dispatcher.bindEx0(this,'onCDWPatientDocuments'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.getCurrentPatientCollection('patientInsurances'),this.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),3)));
		document.getElementById(this.id + '.ShowPatientReport.AddIns').focus();
		this.setWorkStatus("");
	}

	this.onChangePatientInsurances = function(patientInsuranceID)
	{
		var form = gpr.registry.get(this.id + '.patient-insurance');
		if( ! form )
		{
			form = new gpr.forms.patientInsurance(this.id + '.patient-insurance', gpr.dispatcher.bindEx0(this, 'onEditPatientInsurance'), gpr.dispatcher.bindEx0(this, 'onPatientInsurances'), gpr.dispatcher.bindEx0(this, 'onPatientInsuranceDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientInsurances[patientInsuranceID],3));
			//Below lines added by manoj for Audit log
		if(patientInsuranceID)
		{
			var body = "recordType=PatientInsurances&action=view&ID=" + patientInsuranceID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by Deepak, Nous, 20-Feb-2007, Edit Option from Medical History in CDW
	this.onChangeCDWPatientInsurances = function(patientInsuranceID)
	{
		var form = gpr.registry.get(this.id + '.patient-insurance');
		if( ! form )
		{
			form = new gpr.forms.patientInsurance(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientInsurance'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientInsuranceDeleteCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientInsurances[patientInsuranceID],3));
		//Below lines added by manoj for Audit log
		if(patientInsuranceID)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientInsurances&action=view&ID=" + patientInsuranceID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onEditPatientInsurance = function()
	{
		//debugger;
		var form = gpr.registry.get(this.id + '.patient-insurance');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			//window.frames[0].document.forms[0].elements['hdnInsuranceDetails'].value = body;
			//window.frames[0].document.getElementById('lnkAdd').click();
			this.setWorkStatus('');
			//below line commneted by nous (manoj) for implementing Add Document functionality.
			new gpr.ajax().post('/EditPatientInsurance.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientInsuranceComplete'))
		}
	}

	//added by Deepak, Nous, 20-Feb-2007, Edit Option from Medical History in CDW
	this.onEditCDWPatientInsurance = function()
	{
		//debugger;
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			this.setWorkStatus('');
			new gpr.ajax().post('/EditPatientInsurance.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientInsuranceComplete'))
		}
	}
		
	this.onPatientInsuranceDelete = function(patientInsuranceID, patientID)
	{
		//debugger;
		if(confirm("Are you sure you want to delete this Insurance Record ? "))
		{
			this.setWorkStatus('Deleting Record...');
			var body = "recordType=patientInsurances&id=" + patientInsuranceID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientInsuranceComplete'))
		}
	}

	//added by Deepak, Nous, 20-Feb-2007, Edit Option from Medical History in CDW
	this.onPatientInsuranceDeleteCDW = function(patientInsuranceID, patientID)
	{
		//debugger;
		if(confirm("Are you sure you want to delete this Insurance Record?"))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientInsurances&id=" + patientInsuranceID + "&patientID=" + patientID + "&CareDataUserID=" + careDatauserID;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientInsuranceComplete'))
		}
	}
	

	this.onPatientDocuments = function(recordID,documentTypeID,IsAudit)
	{
		//debugger;
		var form = gpr.registry.get(this.id + '.patient-insuranceDocuments');
		if( ! form )
		{
			form = new gpr.forms.patientInsuranceDocuments(this.id + '.patient-insurancesDocuments',gpr.dispatcher.bindEx0(this,'onPatientInsurances'));
		}
		
		//modified by deepak, nous, 19-feb-2007, Added more passing parameters, PatientInsurance, DocumentTypeID
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID,this.getInsuranceDocumentsById(gpr.data.getCurrentPatientCollection('patientDocuments'),documentTypeID,recordID),recordID,gpr.data.getCurrentPatientCollection('patientInsurances'),4));
		//Below lines added by manoj for Audit log
		if(IsAudit == 1)
		{		
			var body = "recordType=InsuranceDocument&action=listView&ID=" + recordID  + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
				
	}
	
	//added by Deepak, nous, 21-feb-2007, Add/Edit Documents (insurance) in Medical History
	this.onCDWPatientDocuments = function(recordID,documentTypeID,IsAudit)
	{
		var form = gpr.registry.get(this.id + '.patient-insuranceDocuments');
		if( ! form )
		{
			form = new gpr.forms.patientInsuranceDocuments(this.id + '.ShowPatientReport',gpr.dispatcher.bindEx0(this,'onCDWCancel'));
		}
		
		//modified by deepak, nous, 19-feb-2007, Added more passing parameters, PatientInsurance, DocumentTypeID
		this.setWorkArea(form.getHtml(gpr.data.patient.id,this.getInsuranceDocumentsById(gpr.data.getCurrentPatientCollection('patientDocuments'),documentTypeID,recordID),recordID,gpr.data.getCurrentPatientCollection('patientInsurances'),5));
		//Below lines added by manoj for Audit log
		if(IsAudit == 1)
		{		
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=InsuranceDocument&action=listView&ID="+ recordID + "&careDataUserID="+ careDatauserID + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.getInsuranceDocumentsById = function(patientDocuments,typeID,recordID)
	{
		var insurancedocuments = new Array();
		var x=0;
		for( var i = 0; i < patientDocuments.length; ++i)
		{
			var item = patientDocuments[i];
			if(item == null) continue;
			else if(item.documentTypeID == typeID && item.recordID == recordID)
			{
				insurancedocuments[x] = item;
				x++;
			}
		}
		return insurancedocuments;
	}
	
	this.getLabResultDocumentsById = function(labresultDocuments,recordID)
	{
		var labrltdocuments = new Array();
		var x=0;
		for( var i = 0; i < labresultDocuments.length; ++i)
		{
			var item = labresultDocuments[i];
			if(item == null) continue;
			else if(item.recordID == recordID)
			{
				labrltdocuments[x] = item;
				x++;
			}
		}
		return labrltdocuments;
	}

	
	this.onEditPatientInsuranceComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientInsurances();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	//added by Deepak, Nous, 20-Feb-2007, Edit Option from Medical History in CDW
	this.onEditCDWPatientInsuranceComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	//onPatientContacts
	this.onPatientContacts = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-contacts');
			if( ! form )
			{
				form = new gpr.forms.patientContacts(this.id + '.patient-contacts', gpr.dispatcher.bindEx0(this, 'onChangePatientContacts'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientContacts')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientContacts&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}

	this.onChangePatientContacts = function(patientContactID)
	{
		var form = gpr.registry.get(this.id + '.patient-contact');
		if( ! form )
		{
			form = new gpr.forms.patientContact(this.id + '.patient-contact', gpr.dispatcher.bindEx0(this, 'onEditPatientContact'), gpr.dispatcher.bindEx0(this, 'onPatientContacts'), gpr.dispatcher.bindEx0(this, 'onPatientContactDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientContacts[patientContactID]));
		//Below lines added by manoj for Audit log
		if(patientContactID != 0)
		{
			var body = "recordType=PatientContacts&action=view&ID=" + patientContactID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit emergency contacts from medical history
	this.onChangeCDWPatientContacts = function(patientContactID)
	{
		var form = gpr.registry.get(this.id + '.patient-contact');
		if( ! form )
		{
			form = new gpr.forms.patientContact(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientContact'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientContactDeleteCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientContacts[patientContactID]));
		//Below lines added by manoj for Audit log
		if(patientContactID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientContacts&action=view&ID=" + patientContactID + "&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onEditPatientContact = function()
	{
		var form = gpr.registry.get(this.id + '.patient-contact');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientContact.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientContactComplete'))
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit emergency contacts from medical history	
	this.onEditCDWPatientContact = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientContact.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientContactComplete'))
		}
	}

	this.onPatientContactDelete = function(patientContactID, patientID)
	{
		if(confirm("Are you sure you want to delete this Emergency Contact Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientContacts&id=" + patientContactID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientContactComplete'))
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit emergency contacts from medical history	
	this.onPatientContactDeleteCDW = function(patientContactID, patientID)
	{
		if(confirm("Are you sure you want to delete this Emergency Contact Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientContacts&id=" + patientContactID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value  ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientContactComplete'))
		}
	}

	this.onEditPatientContactComplete = function(ajax)
	{
	
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientContacts();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	//added by deepak, nous, 23-feb-2007, add/edit emergency contacts from medical history	
	this.onEditCDWPatientContactComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDWCancel();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit emergency contacts from medical history	
	this.onCDW = function()
	{
		
		try
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			this.setWorkStatus();
			this.setWorkArea(new gpr.reports.CDWPatientRecord(gpr.dispatcher.bindEx0(controler, 'onCDWChange'), gpr.dispatcher.bindEx0(controler, 'onCDWView'),gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientReminder'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientImmunizations'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientAllergy'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientCondition'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientSurgeries'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientFH'), gpr.dispatcher.bindEx0(controler, 'onChangeCDWPatientInsurances'),gpr.dispatcher.bindEx0(controler,'onCDWPatientDocuments'),gpr.dispatcher.bindEx0(controler,'onCDWPersonalInfo'),gpr.dispatcher.bindEx0(controler,'onEditCDWPatientIdentification'),gpr.dispatcher.bindEx0(controler,'onEditCDWPatientDocument'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientContacts'),gpr.dispatcher.bindEx0(controler,'onChangeCWDPatientBloodTest'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientUrineTest'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientSH'),gpr.dispatcher.bindEx0(controler,'onChangeCDWFHComment'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientPD'),gpr.dispatcher.bindEx0(controler,'onCDWEditPatientLegalDocs'),gpr.dispatcher.bindEx0(controler,'onchangeCDWPatientVitalSign'),gpr.dispatcher.bindEx0(controler,'onchangeCDWPatientEducation'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPracticeProcedure'),gpr.dispatcher.bindEx0(controler,'onReviewPatientAllergyList'),gpr.dispatcher.bindEx0(controler,'onCDWSaveCurrentMedicationStatus'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientPH'),gpr.dispatcher.bindEx0(controler,'onChangeCDWPatientLabResults'),gpr.dispatcher.bindEx0(controler,'editCDWPatientProvider'),gpr.dispatcher.bindEx0(controler,'onCDWLabResultDocuments'),gpr.dispatcher.bindEx0(controler,'onCDWAllergiesReviewHistory')).getHtml(careDatauserID));
		}
		catch(e)
		{
			this.setWorkStatus(e.message);
		}
	}
	
	this.onCDWCancel = function()
	{
		try
		{
			//document.CDWForm.action = "http://localhost/gprs/showPatientRecordByID.aspx";
			document.CDWForm.action = gpr.data.gprsurl;
			document.CDWForm.method="post";
			document.CDWForm.target="_self";
			document.CDWForm.submit();
		}
		catch(e)
		{
			this.setWorkStatus(e.message);
		}
	}

	//surgeries
	this.onPatientSurgeries = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-surgeries');
			if( ! form )
			{
				form = new gpr.forms.patientSurgeries(this.id + '.patient-surgeries', gpr.dispatcher.bindEx0(this, 'onChangePatientSurgeries'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientSurgeries')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientSurgeries&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit surgeries from medical history
	this.onChangeCDWPatientSurgeries = function(patientSurgeryID)
	{
		var form = gpr.registry.get(this.id + '.patient-surgery');
		if( ! form )
		{
			form = new gpr.forms.patientSurgery(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientSurgery'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientSurgeryDeleteCDW') );
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientSurgeries[patientSurgeryID]));
		//Below lines added by manoj for Audit log
		if(patientSurgeryID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientSurgeries&action=view&ID=" + patientSurgeryID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
		
	}

	this.onChangePatientSurgeries = function(patientSurgeryID)
	{
		var form = gpr.registry.get(this.id + '.patient-surgery');
		if( ! form )
		{
			form = new gpr.forms.patientSurgery(this.id + '.patient-surgery', gpr.dispatcher.bindEx0(this, 'onEditPatientSurgery'), gpr.dispatcher.bindEx0(this, 'onPatientSurgeries'), gpr.dispatcher.bindEx0(this, 'onPatientSurgeryDelete') );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientSurgeries[patientSurgeryID]));
		if(patientSurgeryID != 0)
		{
			var body = "recordType=PatientSurgeries&action=view&ID=" + patientSurgeryID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit surgeries from medical history
	this.onEditCDWPatientSurgery = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientSurgery.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientSurgeryComplete'))
		}
	}

	this.onEditPatientSurgery = function()
	{
		var form = gpr.registry.get(this.id + '.patient-surgery');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientSurgery.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientSurgeryComplete'))
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit surgeries from medical history
	this.onPatientSurgeryDeleteCDW = function(patientSurgeryID, patientID)
	{
		if(confirm("Are you sure you want to delete this Surgery/Procedure Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientSurgeries&id=" + patientSurgeryID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientSurgeryComplete'))
			
		}
	}
	
	this.onPatientSurgeryDelete = function(patientSurgeryID, patientID)
	{
		if(confirm("Are you sure you want to delete this Surgery/Procedure Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientSurgeries&id=" + patientSurgeryID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientSurgeryComplete'))
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit surgeries from medical history
	this.onEditCDWPatientSurgeryComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	this.onEditPatientSurgeryComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientSurgeries();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	//family history
	this.onPatientFH = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-FH');
			if( ! form )
			{
				form = new gpr.forms.patientFH(this.id + '.patient-FH', gpr.dispatcher.bindEx0(this, 'onChangePatientFH'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onChangeFHComment'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientFH')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientFH&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}
		}
	}


	//added by deepak, nous, 13-feb-2007, implement add/edit patient family history from medical history
	this.onChangeCDWPatientFH= function(patientID)
	{
		var form = gpr.registry.get(this.id + '.patient-FH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientFHEditCDW(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientFH'), gpr.dispatcher.bindEx0(this, 'onCDWCancel') );
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.getCurrentPatientCollection('patientFH')));
		//Below lines added by manoj for Audit log
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientFH&action=view&ID=" + gpr.data.patient.id +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
	}

	this.onChangePatientFH= function(patientID)
	{
		
		var form = gpr.registry.get(this.id + '.patient-FH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientFHEdit(this.id + '.patient-FH-edit', gpr.dispatcher.bindEx0(this, 'onEditPatientFH'), gpr.dispatcher.bindEx0(this, 'onPatientFH') );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientFH')));
		//Below lines added by manoj for Audit log
		var body = "recordType=PatientFH&action=view&ID=" + gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
	}
	
	

	//added by deepak, nous, 13-feb-2007, implement add/edit family history from medical history
	this.onEditCDWPatientFH= function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			//body = body + '&encounterID=' + document.getElementById('EncounterID').value + '&officeID=' + document.getElementById('OfficeID').value
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientFamilyHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientFHComplete'))
		}
	}

	this.onEditPatientFH= function()
	{
		var form = gpr.registry.get(this.id + '.patient-FH-edit');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientFamilyHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientFHComplete'))
		}
	}

	//added by deepak, nous, 13-feb-2007, implement add/edit family history from medical history	
	this.onEditCDWPatientFHComplete = function(ajax)
	{
	if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onEditPatientFHComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientFH();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onChangeFHComment = function(familyHistoryID)
	{	
		var form = gpr.registry.get(this.id + '.patient-FH-editComment');
		if( ! form )
		{
			form = new gpr.forms.patientFHEditComment(this.id + '.patient-FH-editComment', gpr.dispatcher.bindEx0(this, 'onEditPatientFHComment'), gpr.dispatcher.bindEx0(this, 'onPatientFH') );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientFH[familyHistoryID]));
		//Below lines added by manoj for Audit log
		var body = "recordType=FHComment&action=view&ID=" + familyHistoryID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)		
	}
	
	this.onEditPatientFHComment = function()
	{
		var form = gpr.registry.get(this.id + '.patient-FH-editComment');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientFamilyHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientFHComplete'))
		}
	}
	this.onChangeCDWFHComment = function(familyHistoryID)
	{	
		var form //= gpr.registry.get(this.id + '.patient-FH-editComment');
		if( ! form )
		{
			form = new gpr.forms.patientFHEditComment(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientFHComment'),gpr.dispatcher.bindEx0(this, 'onCDWCancel'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientFH[familyHistoryID]));
		//Below lines added by manoj for Audit log
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=FHComment&action=view&ID=" + familyHistoryID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		
	}
	
	this.onEditCDWPatientFHComment = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			//body = body + '&encounterID=' + document.getElementById('EncounterID').value + '&officeID=' + alert(document.getElementById('OfficeID').value)
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientFamilyHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientFHComplete'))
		}
	}
	
	//************* : SOCIAL HISTORY BEGIN :(Added by Nous (Manoj) *****************************
	
	this.onPatientSH = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-SH');
			if( ! form )
			{
				form = new gpr.forms.patientSH(this.id + '.patient-SH', gpr.dispatcher.bindEx0(this, 'onChangePatientSH'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientSH')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientSH&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}
	this.onChangePatientSH= function()
	{
	
		var form = gpr.registry.get(this.id + '.patient-SH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientSHEdit(this.id + '.patient-SH-edit', gpr.dispatcher.bindEx0(this, 'onEditPatientSH'), gpr.dispatcher.bindEx0(this, 'onPatientSH') );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientSH')));
		//Below lines added by manoj for Audit log
		var body = "recordType=PatientSH&action=view&ID=" + gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
	}
	
	this.onEditPatientSH= function()
	{
		var form = gpr.registry.get(this.id + '.patient-SH-edit');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientSocialHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientSHComplete'))
		}
	}
	
	this.onEditPatientSHComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientSH();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onChangeCDWPatientSH= function(patientID)
	{
		var form = gpr.registry.get(this.id + '.patient-SH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientSHEditCDW(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientSH'), gpr.dispatcher.bindEx0(this, 'onCDWCancel') );
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.getCurrentPatientCollection('patientSH')));
		//Below lines added by manoj for Audit log
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientSH&action=view&ID=" + gpr.data.patient.id +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
	}


	this.onEditCDWPatientSHComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onEditCDWPatientSH= function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientSocialHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientSHComplete'))
		}
	}
		
	//************* :  SOCIAL HISTORY END  : *****************************
	
	
	//pregnancy history
	this.onPatientPHs = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-PHs');
			if( ! form )
			{
				form = new gpr.forms.patientPHs(this.id + '.patient-PH', gpr.dispatcher.bindEx0(this, 'onChangePatientPH'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientPH')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientPHs&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}

	this.onChangePatientPH= function(patientPHID)
	{
	
		var form = gpr.registry.get(this.id + '.patient-PH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientPH(this.id + '.patient-PH-edit', gpr.dispatcher.bindEx0(this, 'onEditPatientPH'), gpr.dispatcher.bindEx0(this, 'onPatientPHs'), gpr.dispatcher.bindEx0(this, 'onPatientPHDelete')  );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientPH[patientPHID]));
		//Below lines added by manoj for Audit log
		if(patientPHID != 0)
		{
			var body = "recordType=PatientPHs&action=view&ID=" + patientPHID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onEditPatientPH= function()
	{
		var form = gpr.registry.get(this.id + '.patient-PH-edit');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientPH.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientPHComplete'))
		}
	}
	
	this.onEditPatientPHComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'));
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientPHs();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}


	this.onPatientPHDelete = function(patientPHID, patientID)
	{
		if(confirm("Are you sure you want to delete this Pregnancy Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientPH&id=" + patientPHID + "&patientID=" + patientID + "&CareDataUserID=0";
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientPHComplete'))
		}
	}
	
	//cdwPatient Pregnancy History
	this.onChangeCDWPatientPH= function(patientPHID)
	{
	
		var form ; //= gpr.registry.get(this.id + '.patient-PH-edit');
		if( ! form )
		{
			form = new gpr.forms.patientPH(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientPH'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientPHDelete')  );
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientPH[patientPHID]));
		if(patientPHID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientPHs&action=view&ID=" + patientPHID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)

		}
	}
	this.onEditCDWPatientPH = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientPH.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientPHComplete'))
		}
	}
	this.onEditCDWPatientPHComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{	
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}

	}
	this.onCDWPatientPHDelete = function(patientPHID, patientID)
	{
		if(confirm("Are you sure you want to delete this Pregnancy Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientPH&id=" + patientPHID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientPHComplete'))
		}
	}
	
	// ********************* : Pregnancy Details : (Added by Manoj (NOUS) : *******************************
	
	this.onPatientPDs = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-PDs');
			if( ! form )
			{
				form = new gpr.forms.patientPDs(this.id + '.patient-PDs', gpr.dispatcher.bindEx0(this, 'onChangePatientPD'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientPD')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientPDs&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}
	
	this.onChangePatientPD = function(partid)
	{
		var form = gpr.registry.get(this.id + '.patient-PD-edit');
		if( ! form )
		{
			form = new gpr.forms.patientPDEdit(this.id + '.patient-PD-edit', gpr.dispatcher.bindEx0(this, 'onEditPatientPD'), gpr.dispatcher.bindEx0(this, 'onPatientPDs') );
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientPD'),partid));
		document.getElementById(partid).style.display = 'none';
		document.body.scrollTop = 0;
		
		//Below lines added by manoj for Audit log
		var body = "recordType=PatientPDs&action=view&ID=" + gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		
	}	
	
	this.onEditPatientPD= function()
	{
		var form = gpr.registry.get(this.id + '.patient-PD-edit');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientPregnancyDetail.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientPDComplete'))
		}
	}
	
	this.onEditPatientPDComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientPDs();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	this.onChangeCDWPatientPD = function(partid)
	{
		var form; //= gpr.registry.get(this.id + '.patient-PD-edit');
		if( ! form )
		{
			form = new gpr.forms.patientPDEdit(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientPD'), gpr.dispatcher.bindEx0(this, 'onCDWCancel') );
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.getCurrentPatientCollection('patientPD'),partid));
		document.getElementById(partid).style.display = 'none';
		document.body.scrollTop = 0;
		//Below lines added by manoj for Audit log
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientPDs&action=view&ID=" + gpr.data.patient.id +"&careDataUserID=" + careDatauserID + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
	}	
	
	this.onEditCDWPatientPD = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientPregnancyDetail.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientPDComplete'))
		}
	}
	
	this.onEditCDWPatientPDComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	//********************** : Pregnancy Details End : ****************************************************
	// Blood Tests - Added By Manoj (Nous)
	
	this.onPatientBloodTests = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-BloodTests');
			if( ! form )
			{
				form = new gpr.forms.patientBloodTests(this.id + '.patient-BloodTests', gpr.dispatcher.bindEx0(this, 'onChangePatientBloodTest'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientBloodTests')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientBloodTests&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}
	
	this.onChangePatientBloodTest = function(patientBloodTestID)
	{
		var form = gpr.registry.get(this.id + '.patient-BloodTest');
		if( ! form )
		{
			form = new gpr.forms.patientBloodTest(this.id + '.patient-BloodTest', gpr.dispatcher.bindEx0(this, 'onEditPatientBloodTest'), gpr.dispatcher.bindEx0(this, 'onPatientBloodTests'), gpr.dispatcher.bindEx0(this, 'onPatientBloodTestDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientBloodTests[patientBloodTestID]));
		//Below lines added by manoj for Audit log
		if(patientBloodTestID != 0)
		{
			var body = "recordType=PatientBloodTests&action=view&ID=" + patientBloodTestID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	
	this.onChangeCWDPatientBloodTest = function(patientBloodTestID)
	{
		var form ;// = gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.patientBloodTest(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientBloodTest'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientBloodTestDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientBloodTests[patientBloodTestID]));
		//Below lines added by manoj for Audit log
		if(patientBloodTestID != 0)
		{	
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientBloodTests&action=view&ID=" + patientBloodTestID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	 
		
	this.onEditCDWPatientBloodTest = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientBloodTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onCDWEditPatientBloodTestComplete'))
		}
	}
	
	this.onEditPatientBloodTest = function()
	{
		var form = gpr.registry.get(this.id + '.patient-BloodTest');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientBloodTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientBloodTestComplete'))
		}
	}
	
	this.onCDWEditPatientBloodTestComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
		
	this.onEditPatientBloodTestComplete = function(ajax)
	{
		
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientBloodTests();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onPatientBloodTestDelete = function(patientBloodTestID, patientID)
	{
		if(confirm("Are you sure you want to delete this Blood test details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientBloodTests&id=" + patientBloodTestID + "&patientID=" + patientID + "&CareDataUserID=0";
			new gpr.ajax().post('/RecyclePatientTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientBloodTestComplete'))
		}
	}
	this.onCDWPatientBloodTestDelete = function(patientBloodTestID, patientID)
	{
		if(confirm("Are you sure you want to delete this Blood test details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientBloodTests&id=" + patientBloodTestID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecyclePatientTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onCDWEditPatientBloodTestComplete'))
		}
	}
	
	//Urine Test
	this.onPatientUrineTests = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-UrineTests');
			if( ! form )
			{
				form = new gpr.forms.patientUrineTests(this.id + '.patient-UrineTests', gpr.dispatcher.bindEx0(this, 'onChangePatientUrineTest'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientUrineTests')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientUrineTests&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}
	
	this.onChangePatientUrineTest = function(patientUrineTestID)
	{
		var form = gpr.registry.get(this.id + '.patient-UrineTest');
		if( ! form )
		{
			form = new gpr.forms.patientUrineTest(this.id + '.patient-UrineTest', gpr.dispatcher.bindEx0(this, 'onEditPatientUrineTest'), gpr.dispatcher.bindEx0(this, 'onPatientUrineTests'), gpr.dispatcher.bindEx0(this, 'onPatientUrineTestDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientUrineTests[patientUrineTestID]));
		//Below lines added by manoj for Audit log
		if(patientUrineTestID != 0)
		{
			var body = "recordType=PatientUrineTests&action=view&ID=" + patientUrineTestID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onChangeCDWPatientUrineTest = function(patientUrineTestID)
	{
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.patientUrineTest(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientUrineTest'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientUrineTestDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientUrineTests[patientUrineTestID]));
		//Below lines added by manoj for Audit log
		if(patientUrineTestID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientUrineTests&action=view&ID=" + patientUrineTestID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
		
	}
	
	this.onEditCDWPatientUrineTest = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientUrineTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientUrineTestComplete'))
		}
	}
	
	this.onEditCDWPatientUrineTestComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	
	this.onEditPatientUrineTest = function()
	{
		var form = gpr.registry.get(this.id + '.patient-UrineTest');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientUrineTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientUrineTestComplete'))
		}
	}
			
	
	this.onEditPatientUrineTestComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientUrineTests();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onPatientUrineTestDelete = function(patientUrineTestID, patientID)
	{
		if(confirm("Are you sure you want to delete this Urine test details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientUrineTests&id=" + patientUrineTestID + "&patientID=" + patientID +  "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecyclePatientTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientUrineTestComplete'))
		}
	}
	
	this.onCDWPatientUrineTestDelete = function(patientUrineTestID, patientID)
	{
		if(confirm("Are you sure you want to delete this Urine test details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientUrineTests&id=" + patientUrineTestID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecyclePatientTest.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientUrineTestComplete'))
		}
	}
	/***********************--PRACTICE PROCEDURES STARTS HERE--*******************************/
	
	this.onPracticeProcedures = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.Practice-Procedures');
			if( ! form )
			{
				form = new gpr.forms.practiceProcedures(this.id + '.Practice-Procedures', gpr.dispatcher.bindEx0(this, 'onChangePracticeProcedures'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientPracticeProcedures')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=practiceProcedures&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}
	
	this.onChangePracticeProcedures = function(practiceTestID)
	{
		var form = gpr.registry.get(this.id + '.practice-Procedure');
		if( ! form )
		{
			form = new gpr.forms.practiceProcedure(this.id + '.practice-Procedure', gpr.dispatcher.bindEx0(this, 'onEditPracticeProcedure'), gpr.dispatcher.bindEx0(this, 'onPracticeProcedures'), gpr.dispatcher.bindEx0(this, 'onPracticeProcedureDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientPracticeProcedures[practiceTestID]));
		
		//Below lines added by manoj for Audit log
		if(practiceTestID != 0)
		{
			var body = "recordType=practiceProcedures&action=view&ID=" + practiceTestID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onChangeCDWPracticeProcedure = function(practiceTestID)
	{
			
		
		
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		//var form = gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.practiceProcedure(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPracticeProcedure'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPracticeProcedureDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientPracticeProcedures[practiceTestID]));
		//Below lines added by manoj for Audit log
		if(practiceTestID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=practiceProcedures&action=view&ID=" + practiceTestID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
			
	}
	
	this.onEditPracticeProcedure = function()
	{
		var form = gpr.registry.get(this.id + '.practice-Procedure');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPracticeProcedure.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPracticeProcedureComplete'))
		}
	}
			
	this.onEditCDWPracticeProcedure = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPracticeProcedure.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPracticeProcedureComplete'))
		}
	}
	
	this.onEditPracticeProcedureComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPracticeProcedures();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onEditCDWPracticeProcedureComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onPracticeProcedureDelete = function(procedureID, patientID)
	{
		if(confirm("Are you sure you want to delete this procedure details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=practiceProcedures&id=" + procedureID + "&patientID=" + patientID +  "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecyclePracticeProcedure.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPracticeProcedureComplete'))
		}
	}
	
	this.onCDWPracticeProcedureDelete = function(procedureID, patientID)
	{
		if(confirm("Are you sure you want to delete this procedure details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=practiceProcedures&id=" + procedureID + "&patientID=" + patientID + "&CareDataUserID=" + document.getElementById('careDatauserID').value;
			new gpr.ajax().post('/RecyclePracticeProcedure.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPracticeProcedureComplete'))
		}
	}
	
	/***********************--PRACTICE PROCEDURES ENDS HERE--*******************************/
	
	//immunization
	
	this.onPatientImmunizations = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-immunizations');
			if( ! form )
			{
				form = new gpr.forms.patientImmunizations(this.id + '.patient-immunizations', gpr.dispatcher.bindEx0(this, 'onChangePatientImmunizations'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientImmunizations')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientImmunizations&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}

	this.onChangePatientImmunizations = function(patientImmunizationID)
	{
		var form = gpr.registry.get(this.id + '.patient-immunization');
		if( ! form )
		{
			form = new gpr.forms.patientImmunization(this.id + '.patient-immunization', gpr.dispatcher.bindEx0(this, 'onEditPatientImmunization'), gpr.dispatcher.bindEx0(this, 'onPatientImmunizations'), gpr.dispatcher.bindEx0(this, 'onPatientImmunizationDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientImmunizations[patientImmunizationID]));
		//Below lines added by manoj for Audit log
		if(patientImmunizationID != 0)
		{
			var body = "recordType=PatientImmunizations&action=view&ID=" + patientImmunizationID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onChangeCDWPatientImmunizations = function(patientImmunizationID)
	{
		var form = gpr.registry.get(this.id + '.patient-immunization');
		this.setWorkStatus();
		if( ! form )
		{
			form = new gpr.forms.patientImmunization(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientImmunization'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientImmunizationDeleteCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientImmunizations[patientImmunizationID]));
		//Below lines added by manoj for Audit log
		if(patientImmunizationID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientImmunizations&action=view&ID=" + patientImmunizationID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}

	}

	this.onEditCDWPatientImmunization = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientImmunization.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientImmunizationComplete'))
		}
	}

	this.onEditCDWPatientImmunizationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	//changes end

	this.onEditPatientImmunization = function()
	{
		var form = gpr.registry.get(this.id + '.patient-immunization');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientImmunization.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientImmunizationComplete'))
		}
	}
	

	this.onPatientImmunizationDelete = function(patientImmunizationID, patientID)
	{
		if(confirm("Are you sure you want to delete this Immunization Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientImmunizations&id=" + patientImmunizationID + "&patientID=" + patientID + "&CareDataUserID=0";
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientImmunizationComplete'))
		}
	}
	
	this.onPatientImmunizationDeleteCDW = function(patientImmunizationID, patientID)
	{
		if(confirm("Are you sure you want to delete this Immunization Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientImmunizations&id=" + patientImmunizationID + "&patientID=" + patientID + "&CareDataUserID=" + careDatauserID;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientImmunizationComplete'))
		}
	}
	
	this.onEditPatientImmunizationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientImmunizations();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	//medications module
	this.onPatientMedications = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-medications');
			if( ! form )
			{
				form = new gpr.forms.patientMedications(this.id + '.patient-medications', gpr.dispatcher.bindEx0(this, 'onChangePatientMedication'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onSaveCurrentMedicationStatus'),gpr.dispatcher.bindEx0(this,'onViewPatientMedication'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientMedications')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientMedications&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}
		}
	}
	
	//added by deepak, Nous
	this.onChangeCDWPatientMedication = function(patientMedicationID)
	{
		var form = gpr.registry.get(this.id + '.patient-medication');
		this.setWorkStatus();
		if( ! form )
		{
			form = new gpr.forms.patientMedication(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientmMedication'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientMedicationDeleteCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientMedications[patientMedicationID]));
		if(gpr.data.patientMedications[patientMedicationID])
		form.onMedicationTypeSelect(gpr.data.patientMedications[patientMedicationID].medicationType);
		//Below lines added by manoj for Audit log
		if(patientMedicationID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientMedications&action=view&ID=" + patientMedicationID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}


	}
/////////
	
	this.onChangePatientMedication = function(patientMedicationID)
	{
		var form = gpr.registry.get(this.id + '.patient-medication');
		if( ! form )
		{
			form = new gpr.forms.patientMedication(this.id + '.patient-medication', gpr.dispatcher.bindEx0(this, 'onEditPatientmMedication'), gpr.dispatcher.bindEx0(this, 'onPatientMedications'), gpr.dispatcher.bindEx0(this, 'onPatientMedicationDelete'));
		
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientMedications[patientMedicationID]));
		if(gpr.data.patientMedications[patientMedicationID])
			form.onMedicationTypeSelect(gpr.data.patientMedications[patientMedicationID].medicationType);
		//Below lines added by manoj for Audit log
		if(patientMedicationID != 0)
		{
			var body = "recordType=PatientMedications&action=view&ID=" + patientMedicationID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
		//added by deepak, nous
	this.onEditCDWPatientmMedication = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientMedication.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientMedicationComplete'))
		}
	}

///
	
	this.onEditPatientmMedication = function()
	{
		var form = gpr.registry.get(this.id + '.patient-medication');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientMedication.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientMedicationComplete'))
		}
	}
	
	//Added by manoj - for IsCurrentMedicationAvailable - Save
	this.onSaveCurrentMedicationStatus = function()
	{
		var form = gpr.registry.get(this.id + '.patient-medications');
		var body = form.getBody();
		if ( body )
		{	
			body = body + "&CareDataUserID=0";
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/SaveCurrentMedicationStatus.aspx', body, gpr.dispatcher.bindEx0(this,'onSaveCurrentMedicationStatusComplete'))
		}
	}
	
	//added by deepak, Nous 16-Jan-2007
	this.onPatientMedicationDeleteCDW = function(patientMedicationID, patientID)
	{
		var form = gpr.registry.get(this.id + '.patient-medication.delete')
		if(! form)
		{
			form =  new gpr.forms.patientMedicationDelete(this.id + '.ShowPatientReport.delete', patientMedicationID, gpr.dispatcher.bindEx0(this, 'patientMedicationDeleteCDW'))
		}
		
		form.display();
	}

	this.onPatientMedicationDelete = function(patientMedicationID, patientID)
	{
		var form = gpr.registry.get(this.id + '.patient-medication.delete')
		if(! form)
		{
			form =  new gpr.forms.patientMedicationDelete(this.id + '.patient-medication.delete', patientMedicationID, gpr.dispatcher.bindEx0(this, 'patientMedicationDelete'))
		}
		
		form.display();
		
		/*if(confirm("Are you sure you want to delete this Medication Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientMedications&id=" + patientMedicationID + "&patientID=" + patientID;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientMedicationComplete'))
		}*/
	}
	
	//added by deepak, Nous 16-Jan-2007
	this.patientMedicationDeleteCDW = function()
	{
		var form = gpr.registry.get(this.id + '.patient-medication.delete') || gpr.registry.get(this.id + '.ShowPatientReport.delete')
		var body = form.getBody()
		body = body + "&CareDataUserID=" + document.getElementById('careDatauserID').value;;
		new gpr.ajax().post('/recylemedication.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientMedicationComplete'))
	}

	this.patientMedicationDelete = function()
	{
		var form = gpr.registry.get(this.id + '.patient-medication.delete')
		var body = form.getBody()
		if ( body )
		{
			body = body + "&CareDataUserID=0"
			new gpr.ajax().post('/recylemedication.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientMedicationComplete'))
		}
	}
	//added by deepak, nous
	this.onEditCDWPatientMedicationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	//Added by manoj - for IsCurrentMedicationAvailable - Save
	this.onCDWSaveCurrentMedicationStatus = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getCurrentMedicationStatus();
		if ( body )
		{
			if(document.getElementById('careDatauserID'))
				var careDatauserID = document.getElementById('careDatauserID').value;
			else
				var careDatauserID = '0';
			body = body + "&CareDataUserID=" + careDatauserID
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/SaveCurrentMedicationStatus.aspx', body, gpr.dispatcher.bindEx0(this,'onCDWSaveCurrentMedicationStatusComplete'))
		}
	}
	
	this.onCDWSaveCurrentMedicationStatusComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
				alert("Medication status changed successfully.");
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onEditPatientMedicationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientMedications();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	
	this.onSaveCurrentMedicationStatusComplete = function(ajax)
	{
		if(ajax.error)
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus("Medication status saved successfully.");
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	
	this.onViewPatientMedication = function(PatientMedicationID)
	{
		var form = gpr.registry.get(this.id + '.View_patient_Medication');
		if( ! form )
		{
			form = new gpr.forms.patientMeidicationView(this.id + '.View_patient_Medication', gpr.dispatcher.bindEx0(this, 'onPatientMedications'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientMedications[PatientMedicationID]));
		//Below lines added by manoj for Audit log
		if(PatientMedicationID != 0)
		{
			var body = "recordType=PatientMedications&action=view&ID=" + PatientMedicationID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
/////////////ALLERGY REVIEW HISTORY MODULE CDW //////////////////////
	
	this.onCDWAllergiesReviewHistory = function()
	{
		var form ; //= gpr.registry.get(this.id + '.patient-allergies');
		if( ! form )
		{	
			form = new gpr.forms.patientAllergiesReviewHistory(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
	this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.getCurrentPatientCollection('patientAllergyReviewHistory')));

	}
//////////////ALLERGY REVIEW HISTORY END////////////////////////////////
	
	//Allergies module
	this.onPatientAllergies = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-allergies');
			if( ! form )
			{	
				//below line changed by nous by adding one more parameter 
				//( gpr.dispatcher.bindEx0(this,'onClose')- function pointer which get execute when user click on close button in allery page.
				form = new gpr.forms.patientAllergies(this.id + '.patient-allergies', gpr.dispatcher.bindEx0(this, 'onChangePatientAllergy'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onViewPatientAllergy'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientAllergies')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=patientAllergies&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}
		}
	}
	
	//onClose function added by nous to get execute when user click on close button.
	this.onClose = function()
	{
		if (gpr.data.currentPatientID == 0)
		{
		var customPortlet =  null
		}
		else
		{
		var customPortlet = gpr.data.patients[gpr.data.currentPatientID].suspended == true  && gpr.data.patients[gpr.data.currentPatientID].paymentType == gpr.paymentType.Check ? new gpr.ui.MemberCheckMsg() : null
		}
		
		this.initDashboard(customPortlet,1);
		
	}
	
	//added by deepak, Nous, 13-Feb-2007, Add/Edit Functionality in Medical History
	this.onChangeCDWPatientAllergy = function(patientAllergyID)
	{
		var form = gpr.registry.get(this.id + '.patient-allergy');
		//this.setWorkStatus();
		if( ! form )
		{
			form = new gpr.forms.patientAllergy(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientAllergy'), gpr.dispatcher.bindEx0(this, 'onCDW'), gpr.dispatcher.bindEx0(this, 'onPatientAllergyDeleteCDW'));
		}
		
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientAllergies[patientAllergyID]));
		
		//Below lines added by manoj for Audit log
		if(patientAllergyID != 0)
		{
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=patientAllergies&action=view&ID=" + patientAllergyID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}


	this.onChangePatientAllergy = function(patientAllergyID)
	{
		var form = gpr.registry.get(this.id + '.patient-allergy');
		if( ! form )
		{
			form = new gpr.forms.patientAllergy(this.id + '.patient-allergy', gpr.dispatcher.bindEx0(this, 'onEditPatientAllergy'), gpr.dispatcher.bindEx0(this, 'onPatientAllergies'), gpr.dispatcher.bindEx0(this, 'onPatientAllergyDelete'));
		}
		
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientAllergies[patientAllergyID]));
		
		//Below lines added by manoj for Audit log
		if(patientAllergyID != 0)
		{
			var body = "recordType=patientAllergies&action=view&ID=" + patientAllergyID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onViewPatientAllergy = function(patientAllergyID)
	{
	
		var form = gpr.registry.get(this.id + '.patient-allergyView');
		if( ! form )
		{
			form = new gpr.forms.patientAllergyView(this.id + '.patient-allergyView', gpr.dispatcher.bindEx0(this, 'onPatientAllergies'));
		}
		
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientAllergies[patientAllergyID]));
		
		//Below lines added by manoj for Audit log
		if(patientAllergyID != 0)
		{
			var body = "recordType=patientAllergies&action=view&ID=" + patientAllergyID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onViewCDWPatientAllergy = function(patientAllergyID)
	{
		var form ;
		if( ! form )
		{
			form = new gpr.forms.patientAllergyView(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
		
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientAllergies[patientAllergyID]));
		
		//Below lines added by manoj for Audit log
		if(patientAllergyID != 0)
		{
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=patientAllergies&action=view&ID=" + patientAllergyID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	
	//added by Deepak, Nous, 13-Feb-2007
	this.onEditCDWPatientAllergy = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientAllergy.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientAllergyComplete'))
		}
	}
	
	this.onEditPatientAllergy = function()
	{
		var form = gpr.registry.get(this.id + '.patient-allergy');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientAllergy.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientAllergyComplete'))
		}
	}

	//added by Deepak, Nous, 13-Feb-2007, Implementation of Add/Edit Allergies from Medical History
	this.onPatientAllergyDeleteCDW = function(patientAllergyID, patientID)
	{
		if(confirm("Are you sure you want to delete this Allergy Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientAllergies&id=" + patientAllergyID + "&patientID=" + patientID + "&CareDataUserID=" + careDatauserID;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientAllergyComplete'))
		}
	}

	
	this.onPatientAllergyDelete = function(patientAllergyID, patientID)
	{
		if(confirm("Are you sure you want to delete this Allergy Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientAllergies&id=" + patientAllergyID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientAllergyComplete'))
		}
	}

	//added by deepak, nous
	this.onEditCDWPatientAllergyComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDWCancel();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	this.onEditPatientAllergyComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientAllergies();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onReviewPatientAllergyList = function()
	{
		//alert('ok');
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		//this.setWorkStatus();
		if( ! form )
		{
			form = new gpr.forms.patientAllergyReviewHistory(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientAllergyReviewHistory'), gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id));
	}
	
	this.onEditCDWPatientAllergyReviewHistory = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if(body)
		{
			body = body + '&officeID=' + document.getElementById('OfficeID').value
			
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientAllergyReviewHistory.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientAllergyComplete'))
		}
	}
	
	//**** Patient Vital Signs Begins Here ......
	this.onPatientVitalSigns = function(isAudit)
	{
		if (this.CheckForPatient()) 
		{
			var form = gpr.registry.get(this.id + '.patient-VitalSigns');
			if( ! form )
			{
				form = new gpr.forms.patientVitalSigns(this.id + '.patient-VitalSigns', gpr.dispatcher.bindEx0(this, 'onChangePatientVitalSign'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onViewPatientVitalSign'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientVitalSigns')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=VitalSigns&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}
	
	
	this.onChangePatientVitalSign = function(patientVitalSignID)
	{
		var form = gpr.registry.get(this.id + '.patient-VitalSign');
		if( ! form )
		{
			form = new gpr.forms.patientVitalSign(this.id + '.patient-VitalSign', gpr.dispatcher.bindEx0(this, 'onEditPatientVitalSign'), gpr.dispatcher.bindEx0(this, 'onPatientVitalSigns'), gpr.dispatcher.bindEx0(this, 'onPatientVitalSignDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientVitalSigns[patientVitalSignID]));
		//Below lines added by manoj for Audit log
		if(patientVitalSignID != 0)
		{
			var body = "recordType=VitalSigns&action=view&ID=" + patientVitalSignID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onchangeCDWPatientVitalSign = function(patientVitalSignID)
	{
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.patientVitalSign(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientVitalSign'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientVitalSignDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientVitalSigns[patientVitalSignID]));
		//Below lines added by manoj for Audit log
		if(patientVitalSignID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=VitalSigns&action=view&ID=" + patientVitalSignID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}	
		
	this.onViewPatientVitalSign = function(patientVitalSignID)
	{
		var form = gpr.registry.get(this.id + '.View_patient-VitalSign');
		if( ! form )
		{
			form = new gpr.forms.patientVitalSignView(this.id + '.View_patient-VitalSign', gpr.dispatcher.bindEx0(this, 'onPatientVitalSigns'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientVitalSigns[patientVitalSignID]));
		//Below lines added by manoj for Audit log
		if(patientVitalSignID != 0)
		{
			var body = "recordType=VitalSigns&action=view&ID=" + patientVitalSignID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onviewCDWPatientVitalSign = function(patientVitalSignID)
	{
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.patientVitalSignView(this.id + '.ShowPatientReport',gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientVitalSigns[patientVitalSignID]));
		//Below lines added by manoj for Audit log
		if(patientVitalSignID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=VitalSigns&action=view&ID=" + patientVitalSignID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	
	}
	
		
	this.onEditPatientVitalSign = function()
	{
		var form = gpr.registry.get(this.id + '.patient-VitalSign');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientVitalSign.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientVitalSignComplete'))
		}
	}
	
	this.onEditCDWPatientVitalSign = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientVitalSign.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientVitalSignComplete'))
		}
	}
	
	this.onEditCDWPatientVitalSignComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
				
	this.onEditPatientVitalSignComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientVitalSigns();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onPatientVitalSignDelete = function(patientVitalSignID,patientID)
	{
		if(confirm("Are you sure you want to delete this vital sign details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientVitalSigns&id=" + patientVitalSignID + "&patientID=" + patientID +  "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecyclePatientVitalSign.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientVitalSignComplete'))
		}
	}
	
	this.onCDWPatientVitalSignDelete = function(patientVitalSignID,patientID)
	{
	
		if(confirm("Are you sure you want to delete this vital sign details ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientVitalSigns&id=" + patientVitalSignID + "&patientID=" + patientID +  "&CareDataUserID=" + document.getElementById('careDatauserID').value; ;
			new gpr.ajax().post('/RecyclePatientVitalSign.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientVitalSignComplete'))
		}
	}
//**** Patinet Vital Signs end...
		
// **** : Patient Education Documents  Begin : ****

	this.onPatientEducations = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patientEducations');
			if( ! form )
			{
				form = new gpr.forms.patientEducations(this.id + '.patientEducations',gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onChangePatientEducation'),gpr.dispatcher.bindEx0(this,'onViewPatientEducation'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientEducations')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=EducationDocuments&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}
	this.onChangePatientEducation= function(patientEducationID)
	{
		var form = gpr.registry.get(this.id + '.editpatient-Education');
		if( ! form )
		{
			form = new gpr.forms.editPatientEducation(this.id + '.editpatient-Education',gpr.dispatcher.bindEx0(this,'onPatientEducations'),gpr.dispatcher.bindEx0(this,'onEditPatientEducation'),gpr.dispatcher.bindEx0(this,'onPatientEducationDelete'));
		}
		
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientEducations[patientEducationID]));
		if(patientEducationID != 0)
		{
			var body = "recordType=EducationDocuments&action=view&ID=" + patientEducationID +"&careDataUserID=" + '0'  + "&patientID=" + gpr.data.currentPatientID;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onchangeCDWPatientEducation = function(patientEducationID)
	{
		var form ;//= gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			form = new gpr.forms.editPatientEducation(this.id + '.ShowPatientReport',gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onEditCDWPatientEducation'), gpr.dispatcher.bindEx0(this, 'onCDWPatientEducationDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientEducations[patientEducationID]));
		//Below lines added by manoj for Audit log
		if(patientEducationID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=EducationDocuments&action=view&ID=" + patientEducationID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}	
	
	
	this.onEditPatientEducation = function()
	{
		var form = gpr.registry.get(this.id + '.editpatient-Education');
		window.frames[0].document.getElementById('lnkAdd').click();
		this.setWorkStatus('');
	}
	
	this.onEditCDWPatientEducation = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		window.frames[0].document.getElementById('lnkAdd').click();
		this.setWorkStatus('');
	}
	
	this.onCDWPatientEducationDelete = function(PatientEducationID,PatientID)
	{
		if(confirm("Are you sure you want to delete this record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientEducations&id=" + PatientEducationID+ "&patientID=" + PatientID+ "&CareDataUserID=" + careDatauserID ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientEducationComplete'))
		}
	}
	
	this.onPatientEducationDelete = function(PatientEducationID,PatientID)
	{
		if(confirm("Are you sure you want to delete this record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientEducations&id=" + PatientEducationID+ "&patientID=" + PatientID+ "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientEducationComplete'))
		}
	}
	
	this.onEditPatientEducationComplete = function(ajax)
	{
		if ( ajax.error )
			{
				if(ajax.error == gpr.consts.timeStampErrorMessage)
				{
						new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
						this.setWorkStatus(ajax.error);
				}	
				else
				{
					this.setWorkStatus(ajax.error);
				}
		}
		else
		{
			try
			{
				//location.reload();//can we do without this - TA
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientEducations();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	this.onEditCDWPatientEducationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	this.onViewPatientEducation= function(patientEducationID)
	{
		var form = gpr.registry.get(this.id + '.viewpatient-Education');
		if( ! form )
		{
			form = new gpr.forms.viewPatientEducation(this.id + '.viewpatient-Education',gpr.dispatcher.bindEx0(this,'onPatientEducations'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientEducations[patientEducationID]));
		if(patientEducationID != 0)
		{
			var body = "recordType=EducationDocuments&action=view&ID=" + patientEducationID +"&careDataUserID=" + '0'  + "&patientID=" + gpr.data.currentPatientID;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onviewCDWPatientEducation = function(patientEducationID)
	{
		var form;// = gpr.registry.get(this.id + '.viewpatient-Education');
		if( ! form )
		{
			form = new gpr.forms.viewPatientEducation(this.id + '.ShowPatientReport',gpr.dispatcher.bindEx0(this, 'onCDW'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientEducations[patientEducationID]));
		if(patientEducationID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=EducationDocuments&action=view&ID=" + patientEducationID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	
	}
	
	//************** : Patient Education Document End : *******************	
	
	////**************** -:  Legal Doc Begin :- ******************************
	this.onPatientLegalDocs = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-legalDocs');
			if( ! form )
			{
				form = new gpr.forms.patientLegalDocs(this.id + '.patient-legalDocs', gpr.dispatcher.bindEx0(this, 'onEditPatientLegalDocs'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onEditPatientDocument'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID));
			document.getElementById(this.id + '.patient-legalDocs.ViewDoc').focus();
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var pld = gpr.data.patientLegalDocs[gpr.data.currentPatientID] ||   null;
				if(pld)
				{
					var id = pld.id
				}
				else
				{
					var id = 0;
				}
				var body = "recordType=PatientLegalDocs&action=listView&ID="+ id +"&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}

		
	this.onEditPatientLegalDocs = function(patientlegalDocID)
	{
		var form = gpr.registry.get(this.id + '.editpatient-LegalDocs');
		if( ! form )
		{
			form = new gpr.forms.editPatientLegalDocs(this.id + '.editpatient-LegalDocs', gpr.dispatcher.bindEx0(this, 'onSubmitPatientLegalDocs'),gpr.dispatcher.bindEx0(this,'onPatientLegalDocs'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID));
		
		//Below lines added by manoj for Audit log
		if(patientlegalDocID != 0)
		{
			var body = "recordType=PatientLegalDocs&action=view&ID=" + patientlegalDocID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onSubmitPatientLegalDocs = function()
	{
		var form = gpr.registry.get(this.id + '.editpatient-LegalDocs');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientLegalDocs.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientLegalDocsComplete'))
		}
	}
	
	this.onEditPatientLegalDocsComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientLegalDocs();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onCDWEditPatientLegalDocs = function(patientlegalDocID)
	{	
		var form ;//= gpr.registry.get(this.id + '.editpatient-LegalDocs');
		if( ! form )
		{
		 form = new gpr.forms.editPatientLegalDocs(this.id + '.showPatientReport', gpr.dispatcher.bindEx0(this, 'onCDWSubmitPatientLegalDocs'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id));
		
		var pld = gpr.data.patientLegalDocs[gpr.data.patient.id] ||    {id:0};
			if(pld)
				var id = pld.id;
			else
				var id = 0;
		//Below lines added by manoj for Audit log
		if(id != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientLegalDocs&action=view&ID=" + id + "&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id  ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
		
this.onCDWSubmitPatientLegalDocs = function()
{
	var form = gpr.registry.get(this.id + '.showPatientReport');
	var body = form.getBody();
	if ( body )
	{
		this.setWorkStatus('Saving data ...');
		new gpr.ajax().post('/EditPatientLegalDocs.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientLegalDocsComplete'))
	}
}



this.onEditCDWPatientLegalDocsComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	//**************** -:  Legal Doc End :- ******************************
	
	//Checking for a particular patient selected or not 
	//CheckForPatient - function added by nous (manoj) for main page change.
	this.CheckForPatient = function()
	{
		//added by deepak, nous, 22-Feb-2007, for checking the dependencies of Patients when accessed from Medical History
		var patientID = (gpr.data.currentPatientID || gpr.data.patient.id);
		//if (gpr.data.currentPatientID == 0)
		if (patientID == 0)
		{
			alert ("Select a particular patient from patient list");
			return false;
		}
		else
		{
			return true;
		}
	}
	
	//Identification
	this.onPatientIdentification = function(isAudit)
	{	
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-identification');
			if( ! form )
			{
				form = new gpr.forms.patientIdentification(this.id + '.patient-identification', gpr.dispatcher.bindEx0(this, 'onEditPatientIdentification'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'onEditPatientDocument'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID,1));
			document.getElementById(this.id + '.patient-identification.ViewDoc').focus();
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientIdentification&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	

		}
	}

	//added by Deepak, Nous, 23-Feb-2007, Add/Edit patient Identification from Medical History
	this.onCDWPatientIdentification = function()
	{	
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-identification');
			if( ! form )
			{
				form = new gpr.forms.patientIdentification(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientIdentification'),gpr.dispatcher.bindEx0(this,'onCDWCancel'),gpr.dispatcher.bindEx0(this,'onEditCDWPatientDocument'));
			}
			this.setWorkArea(form.getHtml(gpr.data.patient.id,1));
			document.getElementById(this.id + '.ShowPatientReport.ViewDoc').focus();
			this.setWorkStatus("");
		}
	}

//Function added for patient documents
	this.onEditPatientDocument = function(documentTypeID,IsAudit)
	{
		if (documentTypeID == 1)
		{
		var form = gpr.registry.get(this.id + '.patient_IdentificationDocument');		
		}
		else if (documentTypeID == 2)
		{
		var form = gpr.registry.get(this.id + '.patient_LegalDocument');
		}
	
		if (! form)
		{
			if (documentTypeID == 1)
			{
			form = new gpr.forms.patientDocument(this.id + '.patient_IdentificationDocument', gpr.dispatcher.bindEx0(this, 'onSubmitPatientDocument'),gpr.dispatcher.bindEx0(this,'onPatientIdentification'));
			}
			else if (documentTypeID == 2)
			{
			form = new gpr.forms.patientDocument(this.id + '.patient_LegalDocument', gpr.dispatcher.bindEx0(this, 'onSubmitPatientDocument'),gpr.dispatcher.bindEx0(this,'onPatientLegalDocs'));
			}
			
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, this.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),documentTypeID),documentTypeID,gpr.data.getCurrentPatientCollection('patientLegalDocAttachments')));
		//below lines added by manoj for Audit Log
		if(IsAudit == 1)
		{
			if(documentTypeID == 1)
				var body = "recordType=IdentificationDocument&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			else
				var body = "recordType=LegalDocument&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by deepak. nous, 23-feb-2007, add/edit patient document for identifications in medical history.	
	this.onEditCDWPatientDocument = function(documentTypeID,IsAudit)
	{
		
		if (documentTypeID == 1)
		{
			form = gpr.registry.get(this.id + '.patient_IdentificationDocument');
		}
		else if (documentTypeID == 2)
		{
			form = gpr.registry.get(this.id + '.patient_LegalDocument');
		}
		var form;
		if (! form)
		{
			if (documentTypeID == 1)
			{
				form = new gpr.forms.patientDocument(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onSubmitCDWPatientDocument'),gpr.dispatcher.bindEx0(this,'onCDWCancel'));
			}
			else if (documentTypeID == 2)
			{
				form = new gpr.forms.patientDocument(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onSubmitCDWPatientDocument'),gpr.dispatcher.bindEx0(this,'onCDWCancel'));//onCancelPateintIdentification
			}
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, this.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),documentTypeID),documentTypeID,gpr.data.getCurrentPatientCollection('patientLegalDocAttachments')));
		this.setWorkStatus("");
		//below lines added by manoj for Audit Log
		if(IsAudit == 1)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			if(documentTypeID == 1)
				var body = "recordType=IdentificationDocument&action=listView&ID=0&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			else
				var body = "recordType=LegalDocument&action=listView&ID=" + gpr.data.patient.id +"&careDataUserID="+ careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.getDocumentsByType = function(patientDocuments,typeID)
	{
		var documentsByID = new Array();
		var x=0;
		for( var i = 0; i < patientDocuments.length; ++i)
		{
			var item = patientDocuments[i];
			
			if(item == null) continue;
			else if(item.documentTypeID == typeID)
			{
				documentsByID[x] = item;
				x++;
			}
		}
		
		return documentsByID;
	
	}
	
		
	this.onEditPatientIdentification = function()
	{
		var form = gpr.registry.get(this.id + '.editpatient-identification');
		if( ! form )
		{
			form = new gpr.forms.editPatientIdentification(this.id + '.editpatient-identification', gpr.dispatcher.bindEx0(this, 'onSubmitPatientIdentification'),gpr.dispatcher.bindEx0(this,'onPatientIdentification'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID));
		
		//Below lines added by manoj for Audit log
		var body = "recordType=PatientIdentification&action=view&ID=" + gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		
	}

	//added by deepak, nous, 23-feb-2007, add/edit patient identification from medical history	
	this.onEditCDWPatientIdentification = function()
	{
		var form = gpr.registry.get(this.id + '.editpatient-identification');
		if( ! form )
		{
			form = new gpr.forms.editPatientIdentification(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onSubmitCDWPatientIdentification'),gpr.dispatcher.bindEx0(this,'onCDWCancel'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id));
		
		//Below lines added by manoj for Audit log
		var careDatauserID = document.getElementById('careDatauserID').value;
		var body = "recordType=PatientIdentification&action=view&ID=" + gpr.data.patient.id +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
		new gpr.ajax().post('/InsertAuditLog.aspx',body)
		
	}

	this.onSubmitPatientIdentification = function()
	{
		var form = gpr.registry.get(this.id + '.editpatient-identification');
		var body = form.getBody();
		if ( body )
		{	
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientIdentification.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientIdentificationComplete'))
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit patient identification from medical history	
	this.onSubmitCDWPatientIdentification = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientIdentification.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientIdentificationComplete'))
		}
	}

	this.onEditPatientIdentificationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientIdentification();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	this.onGetRecordsComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	//added by deepak, nous, 23-feb-2007, add/edit patient Identification
	this.onEditCDWPatientIdentificationComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	//Patient Providers
	
	this.onPatientProviders = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-providers');
			if( ! form )
			{
				form = new gpr.forms.patientProviders(this.id + '.patient-providers', gpr.dispatcher.bindEx0(this, 'onAddPatientProvider'), gpr.dispatcher.bindEx0(this, 'editProvider'),gpr.dispatcher.bindEx0(this,'onClose'),gpr.dispatcher.bindEx0(this,'addProvider'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientProviders')));;
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientProviders&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}

	}
	
	this.onAddPatientProvider = function()
	{
		var form = gpr.registry.get(this.id + '.search-provider');
		if( ! form )
		{
			form = new gpr.forms.searchProvider(this.id + '.search-provider', gpr.dispatcher.bindEx0(this, 'onSearchProvider'), gpr.dispatcher.bindEx0(this, 'addProvider'), gpr.dispatcher.bindEx0(this, 'onPatientProviders'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID));
	}

	this.onSearchProvider = function()
	{
		var form = gpr.registry.get(this.id + '.search-provider');
		var body = form.searchBody();
		if ( body )
		{
			this.setWorkStatus('Searching data ...');
			new gpr.ajax().post('/SearchProviders.aspx', body, gpr.dispatcher.bindEx0(this, 'onSearchProviderComplete'))
		}
	}
	
	this.onSearchProviderComplete  = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				var form = gpr.registry.get(this.id + '.search-provider');
				
				form.displayResult(gpr.data.providers)
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
		
	}
	
	
	this.addProvider = function(providerID)
	{
		var provider = providerID ? gpr.data.providers[providerID] : {id:0, careDataID:0,timeStamp:0}
		this.editPatientProvider({id:0, patientID:gpr.data.currentPatientID, provider:provider})
	}
	
	this.editProvider = function(patientProviderID)
	{
		this.editPatientProvider(gpr.data.patientProviders[patientProviderID])
	}

	
	this.editPatientProvider = function(patientProvider)
	{
		var form = gpr.registry.get(this.id + '.edit-provider');
		
		if( ! form )
		{
			form = new gpr.forms.editProvider(this.id + '.edit-provider', gpr.dispatcher.bindEx0(this, 'onEditPatientProvider'), gpr.dispatcher.bindEx0(this, 'onPatientProviders'), gpr.dispatcher.bindEx0(this, 'onPatientProviderDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, patientProvider ? patientProvider : gpr.data.patientProviders[gpr.data.currentPatientID]));
		//Below lines added by manoj for Audit log
		if(patientProvider.id != 0)
		{
			var body = "recordType=PatientProviders&action=view&ID=" + patientProvider.id + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
		

	}
	
	this.onEditPatientProvider = function()
	{
		var form = gpr.registry.get(this.id + '.edit-provider');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientProvider.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientProviderComplete'))
		}
	}

	this.onPatientProviderDelete = function(patientProviderID, patientID)
	{
		if(confirm("Are you sure you want to delete this Provider Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientProviders&id=" + patientProviderID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientProviderComplete'))
		}
	}
	this.onEditPatientProviderComplete  = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientProviders()
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
		
	}
	
	this.onDeleteComplete  = function(ajax,refreshMethod)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{
			try
			{	eval(ajax.responseText());
				this.setWorkStatus();
				eval(refreshMethod);
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
		
	}
	
	
	
	
	//******patient provider CDW Start here :- **********************
	
		this.editCDWPatientProvider = function(patientProviderID)
		{
		var form; // = gpr.registry.get(this.id + '.edit-provider');
		
		if( ! form )
		{
			form = new gpr.forms.editProvider(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientProvider'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientProviderDelete'));
		}

		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientProviders[patientProviderID]));

		//Below lines added by manoj for Audit log
		if(patientProviderID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientProviders&action=view&ID=" + gpr.data.patientProviders[patientProviderID].provider.id + "&careDataUserID="+ careDatauserID  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
		

	}

this.onEditCDWPatientProvider = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientProvider.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientProviderComplete'))
		}
	}
	
this.onCDWPatientProviderDelete = function(patientProviderID, patientID)
	{
		if(confirm("Are you sure you want to delete this Provider Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientProviders&id=" + patientProviderID + "&patientID=" + patientID + "&CareDataUserID="+careDatauserID  ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientProviderComplete'))
		}
	}

this.onEditCDWPatientProviderComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
			
		}
	}
	
	
	//Journals Start
	
	//Journal module

	this.onPatientJournals = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-journals');
			if( ! form )
			{
				form = new gpr.forms.patientJournals(this.id + '.patient-journals', gpr.dispatcher.bindEx0(this, 'onChangePatientJournal'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientJournals')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientJournals&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}
	
	this.onChangePatientJournal = function(patientJournalID)
	{
		var form = gpr.registry.get(this.id + '.patient-journal');
		if( ! form )
		{
			form = new gpr.forms.patientJournal(this.id + '.patient-journal', gpr.dispatcher.bindEx0(this, 'onEditPatientJournal'), gpr.dispatcher.bindEx0(this, 'onPatientJournals'), gpr.dispatcher.bindEx0(this, 'onPatientJournalDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientJournals[patientJournalID]),this.id + '.patient-journal.journalDate');
		document.getElementById(this.id + '.patient-journal.journalDate').focus();
		if(patientJournalID != 0)
		{
			//Below lines added by manoj for Audit log
			var body = "recordType=PatientJournals&action=view&ID=" + patientJournalID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onEditPatientJournal = function()
	{
	
		var form = gpr.registry.get(this.id + '.patient-journal');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientJournal.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientJournalComplete'))
		}
	}
	
	this.onPatientJournalDelete = function(patientJournalID, patientID)
	{
		if(confirm("Are you sure you want to delete this Journal Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientJournals&id=" + patientJournalID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientJournalComplete'))
		}
	}


	this.onEditPatientJournalComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientJournals();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	
	//Journals End
	
	//Reminders Module Begin 
	
	this.onPatientReminders = function(isAudit)
	{
		if (this.CheckForPatient()) // Added this if condition by nous.
		{
			var form = gpr.registry.get(this.id + '.patient-reminders');
			if( ! form )
			{
				form = new gpr.forms.patientReminders(this.id + '.patient-reminders', gpr.dispatcher.bindEx0(this, 'onChangePatientReminder'),gpr.dispatcher.bindEx0(this,'onClose'));
			}
			this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.getCurrentPatientCollection('patientReminders')));
			//Below lines added by manoj for Audit log
			if(isAudit == 1)
			{
				var body = "recordType=PatientReminders&action=listView&ID=0&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
				new gpr.ajax().post('/InsertAuditLog.aspx',body)
			}	
		}
	}
	
	this.onChangePatientReminder = function(patientReminderID)
	{
		var form = gpr.registry.get(this.id + '.patient-reminder');
		if( ! form )
		{
			form = new gpr.forms.patientReminder(this.id + '.patient-reminder', gpr.dispatcher.bindEx0(this, 'onEditPatientReminder'), gpr.dispatcher.bindEx0(this, 'onPatientReminders'), gpr.dispatcher.bindEx0(this, 'onPatientReminderDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientReminders[patientReminderID]),this.id + '.patient-reminder.reminderDate');
		document.getElementById(this.id + '.patient-reminder.reminderDate').focus();
		if(patientReminderID != 0)
		{
			//Below lines added by manoj for Audit log
			var body = "recordType=PatientReminders&action=view&ID=" + patientReminderID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	//added by deepak, nous
	this.onChangeCDWPatientReminder = function(patientReminderID)
	{
		var form = gpr.registry.get(this.id + '.patient-reminder');
		this.setWorkStatus();
		if( ! form )
		{
			form = new gpr.forms.patientReminder(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onEditCDWPatientReminder'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onPatientReminderDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, gpr.data.patientReminders[patientReminderID]),this.id + '.ShowPatientReport.reminderDate');
		document.getElementById(this.id + '.ShowPatientReport.reminderDate').focus();
		if(patientReminderID != 0)
		{
			//Below lines added by manoj for Audit log
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=PatientReminders&action=view&ID=" + patientReminderID +"&careDataUserID=" + careDatauserID  + "&patientID=" + gpr.data.patient.id ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	//added by deepak, nous
	this.onEditCDWPatientReminder = function()
	{
	
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientReminder.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWPatientReminderComplete'))
		}
	}
	this.onEditPatientReminder = function()
	{
	
		var form = gpr.registry.get(this.id + '.patient-reminder');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientReminder.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientReminderComplete'))
		}
	}
	
	this.onPatientReminderDelete = function(patientReminderID, patientID)
	{
		if(confirm("Are you sure you want to delete this reminder Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			if(document.getElementById('careDatauserID'))
				var careDatauserID = document.getElementById('careDatauserID').value;
			else
				var careDatauserID = '0';
			var body = "recordType=patientReminder&id=" + patientReminderID + "&patientID=" + patientID + +"&careDataUserID=" + careDatauserID ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditPatientReminderComplete'))
			
			
		}
	}
		//added by deepak, nous
	this.onEditCDWPatientReminderComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	this.onEditPatientReminderComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
					new gpr.ajax().post('/GetRecords.aspx', '',gpr.dispatcher.bindEx0(this, 'onGetRecordsComplete'))
					this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onPatientReminders();
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	
	//Reminder Module End
	
	
		
	this.setWorkStatus = function(statusText)
	{
		var obj = document.getElementById(workStatusId);
		//if condition added by deepak, nous 12-jan-2007
		if(obj)
		{
			obj.style.display = statusText ? "block" : "none";

			document.getElementById(workStatusId + "-message").innerHTML = gpr.htmlString(statusText) || '&nbsp;';
		}
				
	};
	
	this.setWorkArea = function(html,control)
	{
	
		document.getElementById(workStatusId).style.display = "none";
		//IF CONDITION ADDED BY DEEPAK
		if(document.getElementById('home-page'))
			document.getElementById('home-page').style.display = "none";
			//IF CONDITION ADDED BY DEEPAK
		if(document.getElementById('work-page'))
			document.getElementById('work-page').style.display  = "block";
			
		document.getElementById(workAreaId).innerHTML = html || '&nbsp;';
		if(control)
		{
		document.getElementById(control).focus();
		}
		if (document.getElementById('work-page'))
		{
			document.getElementById('work-page').scrollTop = 0;
		}
		//alert(window.frames.length);
		
	};
	
	this.Portlets = function(onClose,customPortlet)
	{
		if (gpr.data.currentPatientID != 0)
		{
			document.getElementById(this.id + '.sidebar.Pregnancies').disabled =  (gpr.data.patients[gpr.data.currentPatientID].gender == gpr.gender.Male)
			document.getElementById(this.id + '.sidebar.Pregnancy Details').disabled =  (gpr.data.patients[gpr.data.currentPatientID].gender == gpr.gender.Male)
		}
		var html = []
		
		html.push(customPortlet ? customPortlet.getHtml() : '');
		html.push(this.getCheckupAlertsHtml());
		html.push(this.getAppointmentHtml());
		html.push(this.getLabresultsHtml());
		html.push(this.getRemindersForTodayHtml());
		
		//Below lines added by manoj for Audit log
		//onClose is a new parameter too identify this function calls is when clicking on clode button or at login time.
		//if it is at login time onClose value is undefined and when user click on close the value will be '1' 
		if(onClose != 1)
		{
			//var body = "recordType=HomePage&action=view&ID=" + gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			var body = "recordType=HomePage&action=view&ID="+ gpr.data.currentPatientID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}	
		return html.join(' ')
		
	};
	
	this.getCheckupAlertsHtml = function()
	{
		var form = gpr.registry.get(this.id + '.checkupalerts');
		if( ! form )
		{
			form = new gpr.ui.Alerts(this.id + '.checkupalerts',  gpr.dispatcher.bindEx0(this, 'populateAlerts'), gpr.dispatcher.bindEx0(this, 'onAlertSnooze'),  gpr.dispatcher.bindEx0(this, 'onMoreAlerts'), gpr.dispatcher.bindEx0(this, 'refreshDashBoard'));
		}
		
		return form.getHtml();
	}
	
	this.populateAlerts = function()
	{
		//below line is added by nous to load only selected patient details in main page. passing current patientid with the request.
		var body = "patientID=" + encodeURIComponent(gpr.data.currentPatientID);
		//Changed by nous , the below line by passing 'body' as parameter before it was ''
		new gpr.ajax().post('/GetPatientAlerts.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetAlertsComplete', false))
	}
	
	this.onAlertSnooze = function(id, patientId, more)
	{
		if(confirm('Do you really want to snooze this Alert?'))
		{
			var body = "id=" +encodeURIComponent(id) + "&patientID=" + encodeURIComponent(patientId) 
			new gpr.ajax().post('/SnoozeAlert.aspx', body ,  gpr.dispatcher.bindEx1(this, 'onGetAlertsComplete', more))
		}

	}
	
	this.onMoreAlerts = function()
	{
		//
			var form = gpr.registry.get(this.id + '.checkupalerts');
			if(form)
			{
				this.setWorkArea(form.getMoreContentHtml()) ;
			}
	}
	
	this.onGetAlertsComplete   = function(more, ajax)
	{
		if ( ajax.error )
			{
				this.setWorkStatus(ajax.error);
			}
			else
			{
				try
				{
					eval(ajax.responseText());
					var form = gpr.registry.get(this.id + '.checkupalerts');
					if(form)
					{
						if(more) 
						{
							this.setWorkArea(form.getMoreContentHtml()) ;
						}
						else
						{
							document.getElementById(this.id +'.checkupalerts.portlet').innerHTML = form.getContentHtml(false );
							gpr.data.fetchedAlerts = true;
						}
					}
				}
				catch(e)
				{
					this.setWorkStatus(e.message);
				}
		}
	}
	
	this.getLabresultsHtml= function()
	{	
		//debugger;
		var form = gpr.registry.get(this.id + '.labresults');
		if( ! form )
		{
			form = new gpr.ui.labResults(this.id + '.labresults', gpr.dispatcher.bindEx0(this, 'onAddLabResult'), gpr.dispatcher.bindEx0(this, 'populateLabResults'), gpr.dispatcher.bindEx0(this, 'onLabResultdelete'),  gpr.dispatcher.bindEx0(this, 'onMoreLabResults'),   gpr.dispatcher.bindEx0(this, 'refreshDashBoard'),gpr.dispatcher.bindEx0(this,'onLabResultDocuments'));
		}
		return form.getHtml();
	}
	this.populateLabResults = function()
	{
	
		//below line is added by nous to load only selected patient details in main page. passing current patientid with the request.
		var body = "patientID=" + encodeURIComponent(gpr.data.currentPatientID);
		//Changed by nous , the below line by passing 'body' as parameter before it was ''
		new gpr.ajax().post('/GetLabResults.aspx', body, gpr.dispatcher.bindEx1(this, 'onGetLabResultsComplete', false))
	}
	
	this.onGetLabResultsComplete   = function(more, ajax)
	{
		if ( ajax.error )
			{
				this.setWorkStatus(ajax.error);
			}
			else
			{
				try
				{
					eval(ajax.responseText());
					var form = gpr.registry.get(this.id + '.labresults');
					if(form)
					{
						if(more)	{
							this.setWorkArea(form.getMoreContentHtml()) ;
						}	else {
							document.getElementById(this.id +'.labresults.portlet').innerHTML = form.getContentHtml(false );
							gpr.data.fetchedLabResults= true;
						}
					}
				}
				catch(e)
				{
					this.setWorkStatus(e.message);
				}
		}
	}
	this.onMoreLabResults = function()
	{
			var form = gpr.registry.get(this.id + '.labresults');
			if(form)
			{
				this.setWorkArea(form.getMoreContentHtml()) ;
			}
	}
	
	this.onPatientLabResultDelete = function(patientLRID, patientID,recordID)
	{
		if(confirm("Are you sure you want to delete this Lab Result/Visit Detail Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var body = "recordType=patientLabResults&id=" + patientLRID + "&patientID=" + patientID + "&CareDataUserID=0" ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx1(this, 'onPatientLabResultDeleteComplete', recordID))
					
		}
	}
	this.onPatientLabResultDeleteComplete = function(patientLRID, ajax)
	{
			if ( ajax.error )
			{
				this.setWorkStatus(ajax.error);
			}
			else
			{
				this.setWorkStatus();
				gpr.data.patientLRs[patientLRID] = null;
				this.refreshDashBoard(1);
				
			}
	}
	this.onAddLabResult = function(patientLabResultID)
	{
		var recordID = gpr.data.getCurrentPatientCollection('patientLRs').length
		var onAllSelect = false;
		if (gpr.data.currentPatientID == 0 &&  patientLabResultID == 0)
		{
			alert("Select a particular patient from patient list");
			return;
		}
		if (gpr.data.currentPatientID == 0 && patientLabResultID != 0)
			{
				gpr.data.currentPatientID =  gpr.data.patientLRs[patientLabResultID].patientID;
				onAllSelect = true;
			}
		var form = gpr.registry.get(this.id + '.labResult');
		if( ! form )
		{
			
			form = new gpr.forms.labResult(this.id + '.labResult', gpr.dispatcher.bindEx0(this, 'onSubmitLabResult'), gpr.dispatcher.bindEx0(this, 'refreshDashBoard'), gpr.dispatcher.bindEx0(this, 'onPatientLabResultDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, patientLabResultID ? gpr.data.patientLRs[patientLabResultID] : null,recordID));
		if(onAllSelect == true)
		{
			gpr.data.currentPatientID = 0;
		}
		//Below lines added by manoj for Audit log
		if(patientLabResultID != 0)
		{
			var body = "recordType=LabResult&action=view&ID=" + gpr.data.patientLRs[patientLabResultID].id + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onLabResultDocuments = function(itemID,recordID,IsAudit)
	{
		var onAllSelect = false;
		if (gpr.data.currentPatientID == 0 &&  itemID == 0)
		{
			alert("Select a particular patient from patient list");
			return;
		}
		if (gpr.data.currentPatientID == 0 && itemID != 0)
		{
			gpr.data.currentPatientID =  gpr.data.patientLRs[itemID].patientID;
			onAllSelect = true;
		}
		var form = gpr.registry.get(this.id + '.labResultDocuments');
		if( ! form )
		{
			form = new gpr.forms.labResultDocuments(this.id + '.labResultDocuments',gpr.dispatcher.bindEx0(this, 'refreshDashBoard'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, itemID ? gpr.data.patientLRs[itemID] : null,7,itemID,
		this.getLabResultDocumentsById(gpr.data.getCurrentPatientCollection('labResultDocument'),recordID)));
		if(IsAudit == 1)
		{		
			var body = "recordType=LabResultDocuments&action=listView&ID=" + recordID  + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
				
	}
	
	this.onCDWLabResultDocuments = function(itemID,recordID,IsAudit)
	{
		var form ; // = gpr.registry.get(this.id + '.labResultDocuments');
		if( ! form )
		{
			form = new gpr.forms.labResultDocuments(this.id + '.ShowPatientReport',gpr.dispatcher.bindEx0(this,'onCDWCancel'));
		}
		
		//modified by deepak, nous, 19-feb-2007, Added more passing parameters, PatientInsurance, DocumentTypeID
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, itemID ? gpr.data.patientLRs[itemID] : null,7,itemID,
		this.getLabResultDocumentsById(gpr.data.getCurrentPatientCollection('labResultDocument'),recordID)));
		//Below lines added by manoj for Audit log
		if(IsAudit == 1)
		{		
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=LabResultDocuments&action=listView&ID="+ recordID + "&careDataUserID="+ careDatauserID + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onSubmitLabResult = function()
	{
		var form = gpr.registry.get(this.id + '.labResult');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientLabResult.aspx', body, gpr.dispatcher.bindEx0(this, 'onLabResultComplete'))
		}
	}
	
	this.onLabResultComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{	try
			{
				eval(ajax.responseText());
				this.setWorkArea(this.Portlets())
				this.setWorkStatus('');
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}	
	
	
	
	//***** -: LAB RESULT CDW Part :- ********************
	
	this.onChangeCDWPatientLabResults = function(patientLabResultID)
	{
		var recordID = gpr.data.getCurrentPatientCollection('patientLRs').length
		var onAllSelect = false;
		
		var form; //= gpr.registry.get(this.id + '.labResult');
		if( ! form )
		{
			
			form = new gpr.forms.labResult(this.id + '.ShowPatientReport', gpr.dispatcher.bindEx0(this, 'onSubmitCDWLabResult'), gpr.dispatcher.bindEx0(this, 'onCDWCancel'), gpr.dispatcher.bindEx0(this, 'onCDWPatientLabResultDelete'),gpr.dispatcher.bindEx0(this,'onCDWLabResultDocuments'));
		}
		this.setWorkArea(form.getHtml(gpr.data.patient.id, patientLabResultID ? gpr.data.patientLRs[patientLabResultID] : null,recordID));

		//Below lines added by manoj for Audit log
		if(patientLabResultID != 0)
		{
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=LabResult&action=view&ID=" + gpr.data.patientLRs[patientLabResultID].id + "&careDataUserID="+ careDatauserID + "&patientID=" + gpr.data.patient.id;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}

	this.onSubmitCDWLabResult = function()
	{
		var form = gpr.registry.get(this.id + '.ShowPatientReport');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientLabResult.aspx', body, gpr.dispatcher.bindEx0(this, 'onEditCDWLabResultComplete'))
		}
	}
	
	this.onEditCDWLabResultComplete = function(ajax)
	{
		if ( ajax.error )
		{
			if(ajax.error == gpr.consts.timeStampErrorMessage)
			{
				this.setWorkStatus(ajax.error);
			}	
			else
			{
				this.setWorkStatus(ajax.error);
			}
		}
		else
		{
			try
			{
				eval(ajax.responseText());
				this.setWorkStatus();
				this.onCDW();
				
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}

	this.onCDWPatientLabResultDelete = function(patientLRID, patientID,recordID)
	{
		if(confirm("Are you sure you want to delete this Lab Result/Visit Detail Record ? "))
		{
			this.setWorkStatus('Deleting Record....');
			var careDatauserID = document.getElementById('careDatauserID').value;
			var body = "recordType=patientLabResults&id=" + patientLRID + "&patientID=" + gpr.data.patient.id + "&CareDataUserID="+careDatauserID ;
			new gpr.ajax().post('/RecycleRecord.aspx', body, gpr.dispatcher.bindEx1(this, 'onPatientCDWLabResultDeleteComplete', recordID))
					
		}
	}

	this.onPatientCDWLabResultDeleteComplete = function(patientLRID, ajax)
	{
			if ( ajax.error )
			{
				this.setWorkStatus(ajax.error);
			}
			else
			{
				this.setWorkStatus();
				gpr.data.patientLRs[patientLRID] = null;
				this.onCDW();
				
			}
	}
	
	////////////////////// - : LAB RESULT END : - ////////////////////////////////
	
	this.getAppointmentHtml = function()
	{	var form = gpr.registry.get(this.id + '.app');
		if( ! form )
		{
			form = new gpr.ui.Appointments(this.id + '.app', gpr.dispatcher.bindEx0(this, 'onAddApp'), gpr.dispatcher.bindEx0(this, 'populateAppointments'), gpr.dispatcher.bindEx0(this, 'onAppointmentCancel'),  gpr.dispatcher.bindEx0(this, 'onMoreAppointments'),   gpr.dispatcher.bindEx0(this, 'refreshDashBoard'));
		}
		return form.getHtml();
	}
	
	this.onAppointmentCancel = function(id, patientId, more)
	{
		if(confirm('Do you really want to cancel this appointment?'))
		{
			var body = "id=" +encodeURIComponent(id) + "&patientID=" + encodeURIComponent(patientId) + "&recordType=patientAppointments" + "&CareDataUserID=0" ;
			new gpr.ajax().post('/CancelAppointment.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetAppointmentsComplete', more))
		}
	}
	
	this.populateAppointments = function()
	{
			//below line is added by nous to load only selected patient details in main page. passing current patientid with the request.
			var body = "patientID=" + encodeURIComponent(gpr.data.currentPatientID);
			//Changed by nous , the below line by passing 'body' as parameter before it was ''
			new gpr.ajax().post('/GetAppointments.aspx', body, gpr.dispatcher.bindEx1(this, 'onGetAppointmentsComplete', false))
	}
	
	this.onGetAppointmentsComplete   = function(more, ajax)
	{
		if ( ajax.error )
			{
				this.setWorkStatus(ajax.error);
			}
			else
			{
				try
				{
					eval(ajax.responseText());
					var form = gpr.registry.get(this.id + '.app');
					if(form)
					{
						if(more) 
						{
							this.setWorkArea(form.getMoreContentHtml()) ;
						}
						else
						{
							document.getElementById(this.id +'.app.portlet').innerHTML = form.getContentHtml(false );
							gpr.data.fetchedAppointment = true;
						}
					}
				}
				catch(e)
				{
					this.setWorkStatus(e.message);
				}
		}
	}
	
	this.onMoreAppointments = function()
	{
			var form = gpr.registry.get(this.id + '.app');
			if(form)
			{
				this.setWorkArea(form.getMoreContentHtml()) ;
			}
	}
	
	this.onAddApp = function(patientAppointmentID)
	{
		if (gpr.data.currentPatientID == 0 )
		{
			alert("Select a particular patient from patient list");
			return;
		}
		var form = gpr.registry.get(this.id + '.appointment');
		if( ! form )
		{
			form = new gpr.forms.appointment(this.id + '.appointment', gpr.dispatcher.bindEx0(this, 'onSubmitAppointment'), gpr.dispatcher.bindEx0(this, 'refreshDashBoard'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, patientAppointmentID ? gpr.data.patientAppointments[patientAppointmentID] : null));
	}
	
	this.onSubmitAppointment = function()
	{
		var form = gpr.registry.get(this.id + '.appointment');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientAppointment.aspx', body, gpr.dispatcher.bindEx0(this, 'onAppointmentComplete'))
		}
	}
	
	this.onAppointmentComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{	try
			{
				eval(ajax.responseText());
				this.setWorkArea(this.Portlets())
				this.setWorkStatus('');
				this.refreshDashBoard(1);
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	//Todays Reminder Session Added BY Nous (Manoj)
	
	this.getRemindersForTodayHtml = function()
	{
	
		var form = gpr.registry.get(this.id + '.remindersfortoday');
		
		if( ! form )
		{
			form = new gpr.ui.reminderForToday(this.id + '.remindersfortoday', gpr.dispatcher.bindEx0(this, 'onAddReminder'), gpr.dispatcher.bindEx0(this, 'onAddReminder'),gpr.dispatcher.bindEx0(this, 'populateRemindersForToday'),gpr.dispatcher.bindEx0(this, 'onReminderCancel'), gpr.dispatcher.bindEx0(this, 'onReminderSnooze'),  gpr.dispatcher.bindEx0(this, 'onMoreReminders'), gpr.dispatcher.bindEx0(this, 'refreshDashBoard'));
		}
		
		return form.getHtml();
		
	}
	
	this.onAddReminder = function(reminderID)
	{
		if (gpr.data.currentPatientID == 0 )
		{
			alert("Select a particular patient from patient list");
			return;
		}
		
		var form = gpr.registry.get(this.id + '.patient-todayreminder');
		if( ! form )
		{
			form = new gpr.forms.patientReminder(this.id + '.patient-todayreminder', gpr.dispatcher.bindEx0(this, 'onEditTodaysReminder'),gpr.dispatcher.bindEx0(this, 'refreshDashBoard'), gpr.dispatcher.bindEx0(this, 'onPatientReminderDelete'));
		}
		this.setWorkArea(form.getHtml(gpr.data.currentPatientID, gpr.data.patientReminders[reminderID]),this.id + '.patient-todayreminder.reminderDate');
		document.getElementById(this.id + '.patient-todayreminder.reminderDate').focus();
		//Below lines added by manoj for Audit log
		if(reminderID != 0)
		{
			var body = "recordType=PatientReminders&action=view&ID=" + reminderID + "&careDataUserID=0"  + "&patientID=" + gpr.data.currentPatientID ;
			new gpr.ajax().post('/InsertAuditLog.aspx',body)
		}
	}
	
	this.onEditTodaysReminder = function()
	{
	
		var form = gpr.registry.get(this.id + '.patient-todayreminder');
		var body = form.getBody();
		if ( body )
		{
			this.setWorkStatus('Saving data ...');
			new gpr.ajax().post('/EditPatientReminder.aspx', body, gpr.dispatcher.bindEx0(this, 'onReminderTodayComplete'))
		}
	}
	
	this.onReminderCancel = function(id, patientId,reminderDate,more)
	{
		if(confirm('Do you really want to cancel this reminder?'))
		{
			var body = "id=" +encodeURIComponent(id) + "&patientID=" + encodeURIComponent(patientId) + "&reminderDate=" + reminderDate
			new gpr.ajax().post('/CancelReminder.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetRemindersForTodayComplete', more))
		}
	}
		
	this.populateRemindersForToday = function()
	{
		//below line is added by nous to load only selected patient details in main page. passing current patientid with the request.
		var body = "patientID=" + encodeURIComponent(gpr.data.currentPatientID);
		//Changed by nous , the below line by passing 'body' as parameter before it was ''
		new gpr.ajax().post('/GetPatientRemindersForToday.aspx', body , gpr.dispatcher.bindEx1(this, 'onGetRemindersForTodayComplete', false))
	}
	
	this.onReminderSnooze = function(id, patientId, more)
	{
		if(confirm('Do you really want to snooze this reminder by one day?'))
		{
			var body = "id=" +encodeURIComponent(id) + "&patientID=" + encodeURIComponent(patientId) 
			
			new gpr.ajax().post('/SnoozeReminder.aspx', body ,  gpr.dispatcher.bindEx1(this, 'onGetRemindersForTodayComplete', more))
		}

	}
	
	this.onMoreReminders = function()
	{
		//
			var form = gpr.registry.get(this.id + '.remindersfortoday');
		if(form)
		{
			this.setWorkArea(form.getMoreContentHtml()) ;
		}
	}

	this.onCDWSessionExpire = function()
	{
		var form;// = gpr.registry.get(this.id + '.ShowPatientReport');
		if( ! form )
		{
			location.replace('SessionExpired.aspx');
			//form = new gpr.ui.SessionExpiredForm(this.id + '.ShowPatientReport');
		}
		//this.setWorkArea(form.getHtml());
		
	}
	

this.onGetRemindersForTodayComplete   = function(more, ajax)
{
	if ( ajax.error )
	{
		this.setWorkStatus(ajax.error);
	}
	else
	{
		try
		{
			eval(ajax.responseText());
			var form = gpr.registry.get(this.id + '.remindersfortoday');
			if(form)
			{
				if(more) 
				{
					this.setWorkArea(form.getMoreContentHtml()) ;
					this.setWorkStatus('');
				}
				else
				{
					document.getElementById(this.id +'.remindersfortoday.portlet').innerHTML = form.getContentHtml(false );
					gpr.data.fetchedTodayReminders = true;
					this.setWorkStatus('');
				}
			}
		}
		catch(e)
		{
			this.setWorkStatus(e.message);
		}
	}
	
	this.onReminderTodayComplete = function(ajax)
	{
		if ( ajax.error )
		{
			this.setWorkStatus(ajax.error);
		}
		else
		{	try
			{
				eval(ajax.responseText());
				this.setWorkArea(this.Portlets())
				this.setWorkStatus('');
				this.refreshDashBoard(1) ;
			}
			catch(e)
			{
				this.setWorkStatus(e.message);
			}
		}
	}
	}
	
	this.onCDWChange = function(name, id)
	{
		if(name == 'Allergy')
			this.onViewCDWPatientAllergy(id);
		else if(name == 'Medication')
			this.onChangeCDWPatientMedication(id);
		else if(name == 'Condition')
			this.onChangeCDWPatientCondition(id);
		else if(name == 'Surgery')
			this.onChangeCDWPatientSurgeries(id);
		else if(name == 'Immunization')
			this.onChangeCDWPatientImmunizations(id);
		else if(name == 'Reminder')
			this.onChangeCDWPatientReminder(id);
		else if(name == 'FH')
			this.onChangeCDWPatientFH(id);
		else if(name == 'Insurance')
			this.onChangeCDWPatientInsurances(id);
		else if(name == 'BloodTests')
			this.onChangeCWDPatientBloodTest(id);
		else if(name == 'UrineTests')
			this.onChangeCDWPatientUrineTest(id);
		else if(name == 'SH')
			this.onChangeCDWPatientSH(id);
		else if(name == 'VitalSigns')
			this.onchangeCDWPatientVitalSign(id);
		else if(name == 'PatientEducation')
			this.onchangeCDWPatientEducation(id);
		else if(name == 'PracticeProcedure')
			this.onChangeCDWPracticeProcedure(id);
		else if(name == 'PPH')
			this.onChangeCDWPatientPH(id);
		else if(name == 'ConditionHistory')
			this.onChangeCDWPatientConditionHistory(id);
			
	}
	
	this.onCDWView = function(name, id)
	{
		if(name == 'VitalSigns')
			this.onviewCDWPatientVitalSign(id);
		else if(name == 'PatientEducation')
			this.onviewCDWPatientEducation(id);
	
	}
//end Todays Reminder Session.	

	
	this.createSideBar = function(id)
	{
		var html = [] 
		var sidebar = gpr.registry.get(this.id + '.sidebar');
				
		if ( ! sidebar )
		{
			var sidebar = new gpr.ui.sidebar(id + '.sidebar', sidebarId)

			sidebar.add(new gpr.ui.sidebarGroup('healthrecords.gif', 'Health Records'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Identification', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientIdentification\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Allergies', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientAllergies\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Conditions', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientConditions\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Medications', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientMedications\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Immunizations', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientImmunizations\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Surgeries/Procedures', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientSurgeries\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Family History', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientFH\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Social History', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientSH\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Pregnancies', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientPHs\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Pregnancy Details', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientPDs\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Vital Signs', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientVitalSigns\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Patient Education', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientEducations\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Blood Tests', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientBloodTests\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Urine Tests', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientUrineTests\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Practice Procedures', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPracticeProcedures\',1)'))

			sidebar.add(new gpr.ui.sidebarGroup('otherrecords.gif', ' Other Records'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Clinicians/Providers', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientProviders\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Insurance', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientInsurances\',1)'))
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Emergency Contacts', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientContacts\',1)'))

			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Advanced Directives', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientLegalDocs\',1)'));
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Personal Info', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPersonalInfo\'); return false;'));
			
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Diary/Personal Journal', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientJournals\',1)'));
			sidebar.add(new gpr.ui.sidebarItem(sidebar.id, 'Reminders', 'gpr.dispatcher.call(\'' + this.id + '\', \'onPatientReminders\',1)'));
				
		}
			
		sidebar.refresh();
	};
	
	var paymentMsg  = function()
	{
		var html
		//
		if(gpr.data.user.paymentType == gpr.paymentType.CreditCard)
		{
			html = 'Your account has been set up. However your CREDIT/DEBIT card did not go through. Please check following infromation and submit' +
				   ' again. You can also mail us the check' 
				   
		}
		else if (gpr.data.user.paymentType == gpr.paymentType.Check)
		{
			html = 'Your acount has been set up. Once your check is recieved and cleared. Your account will be activated. We will notify you via email. If you have not' +
					' not mailed the check and you would like to make a payment using debit/credit card, please use following form'
	
		}
		else if (gpr.data.user.paymentType == gpr.paymentType.Refer)
		{
				html = '<p>The patient acount has been set up. You should be able to see this patient record in CareData Web System. Please encourage your patient to register on GlobalPatientRecord.com. A registered patient can maintain personal and  family medical history, fill out reason to visit form and receives periodically check up alerts from globalpatientrecord.com.' //</p><br> <p> If you are the member and you want to activate your account, please make the payment using following form.'
		}
	
		return html
	}	

}
	
