
/*
Created On:03-Nov-06
Created By: Thennarasu J
Purpose: Modified the section titles
*/

var gpr = gpr || {};
gpr.forms = {};
gpr.Trim = function(value)
{
	if(value)
	{
		while(value.charAt(0) == ' ')
			value = value.substring(1,value.length);
		
		while(value.charAt(value.length-1) == ' ')
			value = value.substring(0,value.length-1);
	}
		
	return value
}
//Added By Venkat, Nous, 19-Feb-2007, format the phone

gpr.formatPhone = function(value)
{
	if(value)
	{
		if (value.length > 0 && value.charAt(0) != "(" && value.charAt(4) != ")" && value.charAt(8) != "-")
		{
			value = "(" + value.substring(0,3) + ")" + value.substring(3,6) + "-" + value.substring(6)
		}
	}
		return value
}

//Added By Shwetha Reddy N On 3rd DEC 2009. This code is added to sort the data in immunization table.
// Sorting Code Starts here
	//what type of data to be sorted.
var type;
//index of the column to be sorted.
var columnIndex,lastIndex,isDescending;
//varaiables for creating up arrow and down arrow.
var upArrow,downArrow;
function initSortArrows()
{
    //create a span element.
	upArrow = document.createElement("SPAN");
	var node6 = document.createTextNode("6");
	upArrow.appendChild(node6);
	//apply css class to show '5' as an arrow.
	upArrow.className = "arrow";
    
    //creating span tag for downArrow.
	downArrow = document.createElement("SPAN");
	var node5 = document.createTextNode("5");
	downArrow.appendChild(node5);
	downArrow.className = "arrow";
}
//function used for sorting table rows.
function  sortTable(eventclick,index)
{
	//debugger
    //if arrows are not created create it.
    if(upArrow==undefined)
        initSortArrows();
     //get the TD element. 
     var cell=eventclick.srcElement;
     //if the user clicks on the "SPAN" tag which was added dynamically.
     if(cell.tagName=="SPAN")
       cell=cell.parentElement;       
       else if (cell.type==undefined)
        type="String";
        else
            type=cell.type;
     //set the current index.
     index=cell.cellIndex;
     columnIndex=index;
     //get the head tag.
     var thead=cell.parentElement;
     var table=thead.parentElement.parentElement;
     //if clicked on span tag go one level up.
     if(!table.tBodies)
     {
        table=table.parentElement;  
        thead=thead.parentElement;  
     }
     var tblBody = table.tBodies[0];
     var tblRows = tblBody.rows;
     
     //set the direction.
     if(columnIndex==lastIndex)
     {
        if(isDescending==true)
            isDescending=false;
        else
            isDescending=true;
      }
      else 
        isDescending=true;
      //make the array of rows.
     var rowArray=new Array();
     
     //add each row to array.
         for(var i=2;i<tblRows.length;i++)
         {
           rowArray[i-2]=tblRows[i];
         }    
         //call the generic function to sort the array.
         //custom comare will return another function whih compares the value passed.
         rowArray.sort(customCompare(type,isDescending,columnIndex));
                 
         //append the sorted array to table.
         for(var i=0;i<rowArray.length;i++)
         {
            tblBody.appendChild(rowArray[i]);
         }
         //first time sorting.
         if(lastIndex==undefined)
         {
           
           cell.appendChild(downArrow.cloneNode(true));
           isDescending=true;
         }
         else if(index!=lastIndex)
         {
			 if(thead.cells[lastIndex].children.length>0)
			 {
				thead.cells[lastIndex].removeChild(thead.cells[lastIndex].children[0]);
				cell.appendChild(downArrow.cloneNode(true));
			 }
         }
         else if(index==lastIndex)
         {         
			if(cell.type!="undefined")
			{
			if(cell.children.length>0)
            cell.removeChild(cell.children[0]);
            if(isDescending==true)
             cell.appendChild(downArrow.cloneNode(true));
            else
             cell.appendChild(upArrow.cloneNode(true));
             }
         }
         //set the last sorted column index.
         lastIndex=columnIndex;
}
function toString(value)
 {
    return value.toUpperCase();
 }
 function toDate(value)
 {
   return Date.parse(value);  
 }
 function Custom(a,b)
    {
              
       if(a==undefined||b==undefined)
         return 0;
         
       var val1=a.children[columnIndex].innerText;
       var val2=b.children[columnIndex].innerText;
       
        var a1=val1.split('.');
        var b1=val2.split('.');
        //get the maximum length of array.
        var maxlength;
        if(a1.length>b1.length)
         maxlength=a1.length;
         else
         maxlength=b1.length;
         //iterate through array item to get individual order no .
         for(var i=0;i<maxlength;i++)
         {
         //if both order number is same conitue to next order.else return the difference
          if(a1[i]!=undefined && b1[i]!=undefined)
          {
              if(parseInt(a1[i])==parseInt(b1[i]))
              {
               continue;
              }
              else
              {
                if(parseInt(a1[i])<parseInt(b1[i]))
                    return isDescending?-1:+1;
               if(parseInt(a1[i])>parseInt(b1[i]))
                    return isDescending ?+1:-1;
                return 0;               
                
              }
          }
          //if one of the order does not exists,return 1 or -1.
          else
          {
            if(a1[i]==undefined)
              return -1;
            else
              return 1;
              
          }
          
         }
         
         return 0; 
    }
    //function returning another function.
function customCompare(type,isDescend,columnIndex)
{
    var TypeCast;
    //assign the typecast to point to the cast function.
    //if type is 'Custom' then return the Custom() function.
    if(type=="Number")
        TypeCast=Number;
        else if(type=="Date")
          TypeCast=toDate;
        else if(type=="Custom")
            return Custom;
           else
             TypeCast=toString;
             
        
       
 
 return function(row1,row2)
 {
   var val1,val2;
   
    val1=row1.children[columnIndex].innerText;
    val2=row2.children[columnIndex].innerText;
   if(TypeCast(val1)<TypeCast(val2))
     return isDescend ?-1:+1;
   if(TypeCast(val1)>TypeCast(val2))
     return isDescend ?+1:-1;
     return 0;
 } 
   
}	
//// Sorting Code Ends here

gpr.forms.todo = function(id){ this.getHtml = function()	{		return "<b> Not Implemented yet </td>";	}}; 
gpr.forms.login = function(id, onSubmit, onSignup, onResetPassword){	

this.id = id;	this.onSubmit = onSubmit;
this.onSignup = onSignup;	
this.onResetPassword = onResetPassword;	
gpr.registry.add(this);	
this.getHtml = function(){		
return (		 '<div id="' + this.id + '.form" class="gpr-forms-login">' +
				'<span class="gpr-forms-login-title">Login</span>' +	
							'<label for="' + this.id + '.userName" >User Name:</label>' +	
							'<input id="' + this.id + '.userName" type="text">' +	
							'<label for="' + this.id + '.password" >Password:</label>' +
							'<input id="' + this.id + '.password" type="password">' +
							'<div id="' + this.id + '.submit" class="gpr-forms-login-submit">' +
							'<a href="javascript:void(0)" ' +	' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;"' +
							'>' +	'Submit' +	'</a>' +	'</div>' +	'</div>' +	'<div id="' + this.id + '.submit" class="gpr-forms-login-signup">' +
							'<a href="javascript:void(0)" ' +		' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSignup\'); return false;"' +	'>' +	
							'Signup' +		'</a>' +	'</div>' +	'<div id="' + this.id + '.submit" class="gpr-forms-login-signup">' +	
							'<a href="javascript:void(0)" ' +		' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onResetPassword\'); return false;"' +	'>' +
							'Forgot Password' +	'</a>' +	'</div>'	);	};	
this.getBody = function(){	
		var userName = document.getElementById(this.id + '.userName').value || '';
		var password = document.getElementById(this.id + '.password').value || '';	
		if(!userName )
		{
		alert("Please enter a valid user id");
		document.getElementById(this.id + '.userName').focus();
		return;		
		}
		else if(!password)
		{
		alert("Please enter a valid password");
		document.getElementById(this.id + '.password').focus();
		return
		}
		return 'userName=' + encodeURIComponent(userName) + '&password=' + encodeURIComponent(password);
			};	
};

gpr.forms.ValidatePwd = function(str)
{
	if(str.length < 6)
	{
		alert('Password should contain both numbers and letters and be at least 6 characters in length');
		return false;
	}///[A-Z]/
	else if(!str.match(/[a-z]/) && !str.match(/[A-Z]/))
	{
		alert('Password should contain both numbers and letters and be at least 6 characters in length');
		return false;
	}
	else if(str.match(/\W+/))
	{
		alert('password must not include any special characters');
		return false;
	}
	else if(!str.match(/\d/))
	{
		alert('Password should contain both numbers and letters and be at least 6 characters in length');
		return false;
	}
	
	return true;
}
//below two methods added by venkat, nous 10-May-2007 to check for the number and numeric values
gpr.forms.CheckForNumber = function(str)
{
	var numberCheck=/(^[0-9]*$)/
	if (numberCheck.test(str))
		return true;
	else
		return false;
}
gpr.forms.CheckForNumeric = function(str)
{
	if (str == null || !str.toString().match(/^\d*\.?\d*$/)) return false;
    return true;
}
 gpr.forms.Checkemails = function(str)
 {
		str = gpr.Trim(str);
		var at = "@"
		var dot = "."
		var lat = str.indexOf(at)
		var lstr = str.length
		var ldot = str.indexOf(dot)
		
		if(str.length == 0)
		{
			return true;
		}
		if(str.indexOf(at) == -1)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
		if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
		if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}
		if(str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if(str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if(str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		if(str.indexOf(dot) != -1)
		{
			if(str.substring(str.indexOf(dot),str.length) == dot)
			{
				alert('Invalid E-mail ID')
				return false;
			}
		}
		
 		 return true
} 

gpr.forms.Checkemail = function(str)
 { 
var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at) == -1)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}
		if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true				
} 

gpr.forms.signup = function(id, onSubmit)
{
	this.id = id;	this.onSubmit = onSubmit;	
	gpr.registry.add(this);	
	user = {id: 0, gender: gpr.gender.Female};	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" ';	
	this.getHtml = function()	{		

		var html = [];
			if ( user.id == 0 )	{
			 		html.push(			
			 		'<br>' +	
			 			'<h3>New Registration</h3>' +	
			 					'<p>' +			'It takes only few minutes to register. Please fill out the form below and then ' +					'click on "Register me"  button' +				'</p> '			);		
		}
			
		html.push(
			'<span class="reg-required">*</span> denotes Required Fields ' +
			'<br>'+ 
			'<table class="gpr-panel" id="'+ this.id+  '.1">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Personal Information</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.firstName" >First<label>' +
								'</td>' +
								'<td>' +
									'<label for="' + this.id + '.middleName" >Middle</label></td>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.lastName" >Last</label>' +
								'</td>' +
								'<td>' +
									'<label for="' + this.id + '.suffix" >Suffix</label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
								'	<input type="text" id="' + this.id + '.firstName" size="25"  value="' + gpr.htmlString(user.firstName) + '" '+ focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
								'	<input type="text" id="' + this.id + '.middleName" size="5"  value="' + gpr.htmlString(user.middleName) + '" '+ focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.lastName" size="25"  value="' + gpr.htmlString(user.lastName) + '" '+ focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.suffix" size="5"  value="' + gpr.htmlString(user.suffix) + '" '+ focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				
				new gpr.forms.address(this.id + '.address').getHtml() + 

				'<tr>' +
					'<td>' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td><label for="' + this.id + '.homephone" >Home Phone</label></td>' +
								'<td><label for="' + this.id + '.workphone" >Work Phone</label></td>' +

								'<td><label for="' + this.id + '.cellphone" >Cell Phone</label></td>' +
								'<td><label for="' + this.id + '.fax" >Fax</label></td>' +
							'</tr>' +
							'<tr>' +
								'<td><input type="text" id="' + this.id + '.homephone"  value="' + gpr.htmlString(user.homephone) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  ' ></td>' +
								'<td><input type="text" id="' + this.id + '.workphone"  value="' + gpr.htmlString(user.workphone) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  '></td>' +
								'<td><input type="text" id="' + this.id + '.cellphone"  value="' + gpr.htmlString(user.cellphone) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  '</td>' +
								'<td><input type="text" id="' + this.id + '.fax" '+ focusClass + ' maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				
				'<tr>' +
					'<td><label for="' + this.id + '.email" >Email Address</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td><input type="text" id="' + this.id + '.email" size="50"  value="' + gpr.htmlString(user.email) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
					'<td><label for="' + this.id + '.confirmEmail" >Confirm Email Address</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td><input type="text" id="' + this.id + '.confirmEmail" size="50" value="' + gpr.htmlString(user.email) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
					'<td>&nbsp;</td>' +
				'</tr>' +
				
				'<tr>' +
					'<td class="gpr-panel-caption">Other Information</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<table class="gpr-panel-advanced-info">' +
							'<tr>' +
								'<!--td>Height</td>' +
								'<td>Weight</td-->' +
								'<td><label for="' + this.id + '.dob" ><span class="reg-required">*</span>Date Of Birth</label></td>' +
								'<td><label for="' + this.id + '.gender" >Gender</label></td>' +
								'<td><label for="' + this.id + '.father" >Father</label></td>' +
								'<td><label for="' + this.id + '.mother" >Mother</label></td>' +
							'</tr>' +
							'<tr>' +
								'<!--td><input type="text" id="' + this.id + '.height-ft" size="2" value="' + gpr.htmlString(user.height) + '">ft <input type="text" name="height-inch" size="2" value="' + gpr.htmlString(user.height) + '">inches <br></td>' +
								'<td><input type="text" id="' + this.id + '.weight" size="3" value="' + gpr.htmlString(user.weight) + '"><br>(lbs) </td-->' +
								'<td><input type="text" name="' + this.id + '.dob" id="' + this.id + '.dob" size="10" value="' + gpr.htmlString(user.dob) + '" '+ focusClass + ' maxlength="10"><a href="#" onclick="showCalendar(\'' + this.id + '.dob\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								'<br>(mm/dd/yyyy) </td>' +
								'<td>' +
									'<input name="' + this.id + '.gender" id="' + this.id + '.gender-female" type="radio" ' + 
										(user.gender == gpr.gender.Female ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-female" >Female</label>' +
									'<input name="' + this.id + '.gender" id="' + this.id + '.gender-male" type="radio" ' + 
										(user.gender == gpr.gender.Male ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-male" >Male</label>' +
									'<br>' +
								'</td>' +
								'<td><input type="text" name="' + this.id + '.fatherName" id="' + this.id + '.fatherName" size="25" value="' + gpr.htmlString(user.fatherName) + '" '+ focusClass + ' maxlength="100"></td>'+
								'<td><input type="text" name="' + this.id + '.motherName" id="' + this.id + '.motherName" size="25" value="' + gpr.htmlString(user.motherName) + '" '+ focusClass + ' maxlength="100"></td>'+
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				//added by venkat , nous 03-may-2007
				'<tr>' +
					'<td>&nbsp;</td>' +
				'</tr>' +
				
				'<tr>' +
					'<td class="gpr-panel-caption">OCCUPATIONAL INFORMATION</td>' +
				'</tr>' +
				//added by prakash ,nous 14-feb-2008
				'<tr>' +
					'<td>' +
					'<table>' +
					'<tr>' +
						'<td><label for="' + this.id + '.employer" >Employer</label></td>' +
						'<td><label for="' + this.id + '.occupation" >Occupation</label></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="text" id="' + this.id + '.employertxt" size="50" value="' + gpr.htmlString(user.employer) + '" '+ focusClass + ' maxlength="150"></td>' +
						'<td><input type="text" id="' + this.id + '.occupationNaturetxt" size="50" value="' + gpr.htmlString(user.occupation) + '" '+ focusClass + ' maxlength="50"></td>' +
					'</tr>' +
					'</table>'+
					'</td>' +
				'</tr>' +

				
				'<tr>' +
					'<td><label for="' + this.id + '.occupationNatureslbl" >Does Your Work Involve (check all that apply):</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td>');
					this.getOccupationNaturesList(html);
					this.setPaymentDisplayProperties(html)
				
		return html.join('');
		
	};
	
	//added by prakash  21-feb-12008
	this.setPaymentDisplayProperties = function(html)
	{
			html.push(
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td><hr></td>' +
				'</tr>'); 
		if (gpr.queryString('ptype')!= gpr.paymentType.Refer) 
		{
			html.push('<tr>' +
					'<td align="center">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'changePanel\', 2); return false;" ><a href="javascript:void(0)" ' +
						'> Next >></a></span>' +
						'<span class="dropshadow">' +
							'<a href="login.htm">Close</a></span>' +
					'</td>' +
					'</tr>' +	
					'</table>');
			html.push('<table class="gpr-panel" id="'+ this.id+  '.2" style="display:none" width="95%">' +
					'<tr>' +
						'<td class="gpr-panel-caption" colspan="2">Login Information</td>'+
					'</tr>' +
					'<tr><td><table>'+
					'<tr>' +
						'<td><span class="reg-required">*</span><label for="' + this.id + '.userName" >UserID</label></td>' +
						'<td rowspan="4" align="right" valign="top"><table cellpadding="0" cellspacing="0"><tr height="5"><td><b><u>Password Guidelines'+'</b></u></td></tr>'+
						'<tr>'+'<td>'+'Minimum Length : ' + gpr.data.passwordSettings[1].minLength + '</td></tr>');
						if(gpr.data.passwordSettings[1].noOfNumerics > 0)
						{
							html.push('<tr>'+'<td>'+'Min Number of Numeric Characters : ' + gpr.data.passwordSettings[1].noOfNumerics + '</td></tr>');
						}
						else if(gpr.data.passwordSettings[1].noOfNumerics == -1)
						{
							html.push('<tr>'+'<td>'+ ' Numeric Characters are not allowed.'+'</td></tr>');
						}
						if(gpr.data.passwordSettings[1].noOfAlphabets > 0)
						{
							html.push('<tr>'+'<td>'+'Min Number of Alphabets : ' + gpr.data.passwordSettings[1].noOfAlphabets + '</td></tr>');
						}
						else if(gpr.data.passwordSettings[1].noOfAlphabets == -1)
						{
							html.push('<tr>'+'<td>'+ ' Alphabets are not allowed.'+'</td></tr>');
						}

					
						html.push('</table></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="text" id="' + this.id + '.userName" maxlength="50" value="' + gpr.htmlString(user.userName) + '" '+ focusClass + '></td>' +
					'</tr>' +
					'<tr>' +
						'<td width="300"><span class="reg-required">*</span><label for="' + this.id + '.password" >Password</label></td>'+
					'</tr>' +
					'<tr>' +
						'<td><input type="password" id="' + this.id + '.password" '+ focusClass + ' maxlength="20"  onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');"  ></td>' +
					'</tr>' +
					'<tr>' +
						'<td><span class="reg-required">*</span><label for="' + this.id + '.confirmPassword" >Confirm Password</label></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="password" id="' + this.id + '.confirmPassword" '+ focusClass + ' maxlength="20"  onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');" ></td>' +
					'</tr>' +
					'</table></td></tr>'+
					'<tr>' +
						'<td colspan="2">' +
							'<table class="gpr-panel-section">' +
								'<tr>' +
									'<td><span class="reg-required">*</span><label for="' + this.id + '.secretq" >Secret Question</label></td>' +
									'<td><span class="reg-required">*</span><label for="' + this.id + '.secreta" >Answer</label></td>' +
								'</tr>' +
								'<tr>' +
									'<td>' +
										'<select id="' + this.id + '.secretQ" >' +
											'<option value=""></option>'
			);
									
			for( var i = 0; i < gpr.secretQuestions.length; ++i )
			{
				var q = gpr.htmlString(gpr.secretQuestions[i])
				html.push('<option value="' + q + '">' + q + '</option>');
			}
									
			html.push(
										'</select>' +
									' </td>' +
									'<td><input type="text" size="30" id="' + this.id + '.secretA" value="' + gpr.htmlString(user.secretA) + '" '+ focusClass + ' maxlength="250"></td>' +
									'</tr>' +
							'</table>' +
						'</td>' +
					'</tr>'  +
					'<input type="hidden" id="' + this.id + '.officeid" value="'+ (gpr.queryString('officeid',true) || '') + '">' +
					'<input type="hidden" id="' + this.id + '.providerid" value="' + (gpr.queryString('providerid',true) || '')+ '">'
					)
					
					html.push(new gpr.forms.payment(this.id + '.payment', gpr.consts.registrationFee, this.id + '.address').getHtml())
					
					html.push(
					'<tr>' +
						'<td colspan="2"><hr></td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2"><input type="checkbox" id="' + this.id + '.terms">I have read & understood the <a href="terms.htm" target="_blank">Terms & Conditions</a></td>' +
					'</tr>' +

					//added by Deepak, Nous 23-Jan-2007
					//Below lines changed by Manoj, Nous 16-April-2007
					
					'<tr>' +
						//'<td><input type="checkbox" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onTermSelect\')" id="' + this.id + '.terms1">As a member of GlobalPatient record, you have complete and total control of your medical information.  We do everything to keep your information safe and secure.  We use highly advanced encryption methods to ensure your information is kept secure and confidential.  You will be notified everytime someone accesses your records.  For additional protection please check all that apply:</td>' +
						'<td colspan="2"><input type="checkbox" id="' + this.id + '.terms1">As a member of GlobalPatient record, you have complete and total control of your medical information.  We do everything to keep your information safe and secure.  We use highly advanced encryption methods to ensure your information is kept secure and confidential.  You will be notified everytime someone accesses your records.  For additional protection please check all that apply:</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term1" >I give permission for CareData to act as an emergency backup contact in the case of an emergency</p></td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term2" >I give permission for any Hospital ER to gain access to my records in the case of an emergency</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term3" >I allow my data to be used for research purposes as long as all identifying data is stripped off (de-identified)</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term4" >Send me a notice anytime someone accesses my records</td>' +
					'</tr>' +
					
					// END
					'<tr>' +
						'<td colspan="2"><hr></td>' +
					'</tr>' +
					
					'<tr>' +
						'<td align="center" colspan="2">' +
							'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'changePanel\', 1); return false;" >' +
							'<a href="javascript:void(0)" ' +
								'><< Back</a></span>' +	
								'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a  href="javascript:void(0)" ' +
								'> Register me</a></span>' +
							'<span class="dropshadow">' +
								'<a href="login.htm">Cancel</a></span>' +
						'</td>' +
					'</tr>' +
			' </table> ' 
			);
		}
		else
		{
		
					
			html.push('<tr><td><table class="gpr-panel" id="'+ this.id+  '.2" style="display:none" width="95%">' +
					'<tr>' +
						'<td class="gpr-panel-caption" colspan="2">Login Information</td>'+
					'</tr>' +
					'<tr><td><table>'+
					'<tr>' +
						'<td><span class="reg-required">*</span><label for="' + this.id + '.userName" >UserID</label></td>' +
						'<td rowspan="4" align="right" valign="top"><table cellpadding="0" cellspacing="0"><tr height="5"><td><b><u>Password Guidelines'+'</b></u></td></tr>'+
						'<tr>'+'<td>'+'Minimum Length : ' + gpr.data.passwordSettings[1].minLength + '</td></tr>');
						if(gpr.data.passwordSettings[1].noOfNumerics > 0)
						{
							html.push('<tr>'+'<td>'+'Min Number of Numeric Characters : ' + gpr.data.passwordSettings[1].noOfNumerics + '</td></tr>');
						}
						else if(gpr.data.passwordSettings[1].noOfNumerics == -1)
						{
							html.push('<tr>'+'<td>'+ ' Numeric Characters are not allowed.'+'</td></tr>');
						}
						if(gpr.data.passwordSettings[1].noOfAlphabets > 0)
						{
							html.push('<tr>'+'<td>'+'Min Number of Alphabets : ' + gpr.data.passwordSettings[1].noOfAlphabets + '</td></tr>');
						}
						else if(gpr.data.passwordSettings[1].noOfAlphabets == -1)
						{
							html.push('<tr>'+'<td>'+ ' Alphabets are not allowed.'+'</td></tr>');
						}

					
						html.push('</table></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="text" id="' + this.id + '.userName" maxlength="50"></td>' +
					'</tr>' +
					'<tr>' +
						'<td width="300"><span class="reg-required">*</span><label for="' + this.id + '.password" >Password</label></td>'+
					'</tr>' +
					'<tr>' +
						'<td><input type="password" value="password9" id="' + this.id + '.password" '+ focusClass + ' maxlength="20"  onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');"  ></td>' +
					'</tr>' +
					'<tr>' +
						'<td><span class="reg-required">*</span><label for="' + this.id + '.confirmPassword" >Confirm Password</label></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="password" value="password9" id="' + this.id + '.confirmPassword" '+ focusClass + ' maxlength="20"  onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');" ></td>' +
					'</tr>' +
					'</table></td></tr>'+
					'<tr>' +
						'<td colspan="2">' +
							'<table class="gpr-panel-section">' +
								'<tr>' +
									'<td><span class="reg-required">*</span><label for="' + this.id + '.secretq" >Secret Question</label></td>' +
									'<td><span class="reg-required">*</span><label for="' + this.id + '.secreta" >Answer</label></td>' +
								'</tr>' +
								'<tr>' +
								'<td>' +
									'<select id="' + this.id + '.secretQ" >' 
			);
									
			for( var i = 0; i < gpr.secretQuestions.length; ++i )
			{
				var q = gpr.htmlString(gpr.secretQuestions[i])
				html.push('<option value="' + q + '">' + q + '</option>');
			}
									
			html.push(
					'</select>' +
					'</td>' +
					'<td><input type="text" size="30" id="' + this.id + '.secretA" value="dog" '+ focusClass + ' maxlength="250"></td>' +
					'</tr>' +
					'</table>' +
					'</td>' +
					'</tr>'  +
					'<input type="hidden" id="' + this.id + '.officeid" value="'+ (gpr.queryString('officeid',true) || '') + '">' +
					'<input type="hidden" id="' + this.id + '.providerid" value="' + (gpr.queryString('providerid',true) || '')+ '">'
					)
					html.push(
					'<tr>' +
						'<td colspan="2"><hr></td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2"><input type="checkbox" checked="true" id="' + this.id + '.terms">I have read & understood the <a href="terms.htm" target="_blank">Terms & Conditions</a></td>' +
					'</tr>' +

					//added by Deepak, Nous 23-Jan-2007
					//Below lines changed by Manoj, Nous 16-April-2007
					
					'<tr>' +
						//'<td><input type="checkbox" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onTermSelect\')" id="' + this.id + '.terms1">As a member of GlobalPatient record, you have complete and total control of your medical information.  We do everything to keep your information safe and secure.  We use highly advanced encryption methods to ensure your information is kept secure and confidential.  You will be notified everytime someone accesses your records.  For additional protection please check all that apply:</td>' +
						'<td colspan="2"><input type="checkbox" checked="true" id="' + this.id + '.terms1">As a member of GlobalPatient record, you have complete and total control of your medical information.  We do everything to keep your information safe and secure.  We use highly advanced encryption methods to ensure your information is kept secure and confidential.  You will be notified everytime someone accesses your records.  For additional protection please check all that apply:</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term1" >I give permission for CareData to act as an emergency backup contact in the case of an emergency</p></td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term2" >I give permission for any Hospital ER to gain access to my records in the case of an emergency</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term3" >I allow my data to be used for research purposes as long as all identifying data is stripped off (de-identified)</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2">&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="' + this.id + '.term4" >Send me a notice anytime someone accesses my records</td>' +
					'</tr>' +
					
					// END
				' </table></td></tr>' 
			); 
		   
		    html.push('<tr>' +
						'<td align="center">' +
							'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a  href="javascript:void(0)" ' +
								'> Register me</a></span>' +
							'<span class="dropshadow"  onclick="window.close(); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Close</a></span>' +
						'</td>' +
					'</tr></table>');
		}
	}
	
	
	
	
	// added by venkat, nous 03-may-2007
	this.getOccupationNaturesList  = function(html)
	{
		html.push('<table width="100%"><tr>')
		var ons = gpr.dictionaries.occupationNatures;
		
		for ( var on = 0; on < ons.length; ++on)
		{
			if (ons[on].active)
			{
				html.push('<td>')
				//html.push('<span style="white-space:">');
				html.push('<input type="checkbox" id="' + this.id + '.occupationNature.' + ons[on].id + '" ');
				html.push(' value="' + ons[on].id + '" ');
				/*if ( gpr.find(gpr.data.patients[gpr.data.currentPatientID].occupationNatureIDs, ons[on].id) )
				{
					html.push(' checked ');
				}*/
				html.push('>');
				html.push(' <label for="' + this.id + '.occupationNature.' + ons[on].id + '" >');
				html.push(gpr.htmlString(ons[on].name));
				html.push('</label>');
				html.push('</td>')
			}
			if((on+1) % 4 == 0)
			{
				html.push('</tr><tr>')
			}
		}	
		//html.push('</span>');
		html.push('</table>')
	}
	// added by venkat, nous 04-may-2007
	this.getOccupationNatureSelection = function()
	{
		var on = gpr.dictionaries.occupationNatures;
		var natures = [];
		for ( var a = 0; a < on.length; ++a)
		{
			nature = document.getElementById(this.id + '.occupationNature.' + on[a].id)
			if (nature != null && nature.checked )
			{
				natures.push(on[a].id)
			}
		}
	
		return natures;
	}
	//added by deepak, Nous 23-Jan-2007
	this.onTermSelect = function()
	{
	if (gpr.queryString('ptype')!= gpr.paymentType.Refer) 
		{
			var value = document.getElementById(this.id + '.terms1').checked;
		
			document.getElementById(this.id + '.term1').checked = value;
			document.getElementById(this.id + '.term2').checked = value;
			document.getElementById(this.id + '.term3').checked = value;
			document.getElementById(this.id + '.term4').checked = value;
		}
	}
	//end

	this.changePanel = function(panel)
	{
		
		if(panel == 2)
		{
			var firstName = gpr.Trim(document.getElementById(this.id + '.firstName').value || '');
			var	lastName = gpr.Trim(document.getElementById(this.id + '.lastName').value || '');
			var	dob = gpr.Trim(document.getElementById(this.id + '.dob').value || '');
			var email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
			var confirmEmail = gpr.Trim(document.getElementById(this.id + '.confirmEmail').value || '');
			var	homephone = gpr.Trim(document.getElementById(this.id + '.homephone').value || '');

			if ( !firstName )
			{
				alert('Please enter First Name.');
				document.getElementById(this.id + '.firstName').focus()
			}
			else if ( !lastName )
			{
				alert('Please enter Last Name.');
				document.getElementById(this.id + '.lastName').focus()
			}
			/*else if (!homephone)
			{
				alert('Please Enter Home Phone number.');
				document.getElementById(this.id + '.homePhone').focus()
			}
			else if (!email)
			{
				alert('Please enter Email.');
				document.getElementById(this.id + '.email').focus()
			}*/
			else if( email != '' && !gpr.forms.Checkemail(email))
			{
				document.getElementById(this.id + '.email').focus()
			}
			else if (email != confirmEmail)
			{
				alert('Confirm Email is different from Email.');
				document.getElementById(this.id + '.confirmEmail').focus()
			}
			else if(!dob)
			{
				alert('Please enter a date of birth');
				document.getElementById(this.id + '.dob').focus()
			}
			else if (!gpr.isDate(dob))
			{
				// the error message is displayed from gpr.isDate
				document.getElementById(this.id + '.dob').focus()
			}
			else
			{
				document.getElementById(this.id +".1").style.display =  "none" 
				document.getElementById(this.id +".2").style.display = "block"
				document.getElementById(this.id +".userName").focus()
			}
		}
		else
		{
				document.getElementById(this.id +".1").style.display =  "block" 
				document.getElementById(this.id +".2").style.display = "none"
				document.getElementById(this.id + ".firstName").focus()
		}
	}
	
	var getConfirmMsg = function()
	{
			return ('We are about to submit your informtion to the server.This may take couple of  minutes. Please DO NOT  hit back button or click ' +	
			'on "Register me" again.\n\n If you don\'t want to submit it then click on CANCEL button')
	}	
	
	this.getBody = function()
	{
	
		var firstName = gpr.Trim(document.getElementById(this.id + '.firstName').value || '');
		var	lastName = gpr.Trim(document.getElementById(this.id + '.lastName').value || '');
		var middleName = gpr.Trim(document.getElementById(this.id + '.middleName').value || '');
		var	suffix = gpr.Trim(document.getElementById(this.id + '.suffix').value || '');

		var	homephone = gpr.Trim(document.getElementById(this.id + '.homephone').value || '');
		var	 workphone = gpr.Trim(document.getElementById(this.id + '.workphone').value || '');

		var	cellphone = gpr.Trim(document.getElementById(this.id + '.cellphone').value || '');
		var	fax = gpr.Trim(document.getElementById(this.id + '.fax').value || '');
		
		var	dob = gpr.Trim(document.getElementById(this.id + '.dob').value || '');
		var	gender = document.getElementById(this.id + '.gender-male').checked || '';
		
		var fatherName = gpr.Trim(document.getElementById(this.id + '.fatherName').value || '');
		var motherName = gpr.Trim(document.getElementById(this.id + '.motherName').value || '');
		//below lines added by prakash 14-feb-2008
		var employer = gpr.Trim(document.getElementById(this.id + '.employertxt').value || '');
		//below 2 lines added by venkat for "occupation"
		var occupation = gpr.Trim(document.getElementById(this.id + '.occupationNaturetxt').value || '');
		var occupationNatureIDs = this.getOccupationNatureSelection().join(','); 
		
		var email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
		var confirmEmail = gpr.Trim(document.getElementById(this.id + '.confirmEmail').value || '');
		var userName = gpr.Trim(document.getElementById(this.id + '.userName').value || '');
		var password = gpr.Trim(document.getElementById(this.id + '.password').value || '');
		var confirmPassword = gpr.Trim(document.getElementById(this.id + '.confirmPassword').value || '');
		var secretQ = gpr.Trim(document.getElementById(this.id + '.secretQ').value || '');
		var secretA = gpr.Trim(document.getElementById(this.id + '.secretA').value || '');
		var readTerms = document.getElementById(this.id + '.terms').checked || false;
		var privacy = document.getElementById(this.id + '.terms1').checked || false;
		var officeID = gpr.Trim(document.getElementById(this.id + '.officeID').value || '');
		var providerID = gpr.Trim(document.getElementById(this.id + '.providerID').value || '');
		
		
		if ( !firstName )
		{
			alert('Please enter First Name.');
			document.getElementById(this.id + '.firstName').focus()
		}
		else if ( !lastName )
		{
			alert('Please enter Last Name.');
			document.getElementById(this.id + '.lastName').focus()
		}
		/*else if (!homephone)
		{
			alert('Please Enter Home Phone number.');
			document.getElementById(this.id + '.homePhone').focus()
		}
		else if (!email)
		{
			alert('Please enter Email.');
			document.getElementById(this.id + '.email').focus()
		}*/
		else if( email != '' && !gpr.forms.Checkemail(email))
		{
			document.getElementById(this.id + '.email').focus()
		}
		else if (email != confirmEmail)
		{
			alert('Confirm Email is different from Email.');
			document.getElementById(this.id + '.confirmEmail').focus()
		}
		else if ( (userName == '') && (gpr.queryString('ptype') != gpr.paymentType.Refer))
		{
			alert('UserID can not be empty');
			document.getElementById(this.id + '.userName').focus()
		}
		else if ( password == '')
		{
			alert('Password can not be empty');
			document.getElementById(this.id + '.password').focus()

		}
		/*else if(!gpr.forms.ValidatePwd(password)) //added by deepak, Nous for strong password implementation on 13-Feb-2007
		{
			//alerts are raised in the function itself.
			document.getElementById(this.id + '.password').focus()
		}*/
		else if ( password != confirmPassword)
		{
			alert('Confirm Password is different from Password.');
			document.getElementById(this.id + '.confirmPassword').focus()

		}
		else if (secretQ == '')
		{
			alert('Please select a secret Question')
			document.getElementById(this.id + '.secretQ').focus()
		}
		else if (secretA == '')
		{
			alert('Please enter a secret Answer')
			document.getElementById(this.id + '.secretA').focus()
		}
		else if (!readTerms)
		{
			alert('Please read the terms and condition and check the box');
			document.getElementById(this.id + '.terms').focus();
		}
                else if (!privacy)
                {
                        alert('Please read the privacy statement and check the box');
                        document.getElementById(this.id + '.terms1').focus();
                }
		else if(!dob)
		{
			alert('Please enter a date of birth');
			document.getElementById(this.id + '.dob').focus();
		}
		else if(!gpr.isDate(dob))
		{
			document.getElementById(this.id + '.dob').focus();
		}
		else
		{
			if(confirm(getConfirmMsg()))
			{
				//todo:document.getElementById(this.id +".2").style.filter = "progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=25);"

				return (
							'id=0' +
							'&firstName=' + encodeURIComponent(firstName) +
							'&lastName=' + encodeURIComponent(lastName) +
							(middleName ? '&middleName=' + encodeURIComponent(middleName) : '') +
							(suffix ? '&suffix=' + encodeURIComponent(suffix) : '') +
							(cellphone ? '&cellphone=' + encodeURIComponent(cellphone) : '') +
							(homephone ? '&homephone=' + encodeURIComponent(homephone) : '') + 
							(workphone ? '&workphone=' + encodeURIComponent(workphone) : '') + 
							(fax ? '&fax=' + encodeURIComponent(fax) : '') +
							'&dob=' + encodeURIComponent(dob) +
							'&gender=' + (gender ? "1" : "0") +
							(fatherName ? '&fatherName=' + encodeURIComponent(fatherName) : '') +
							(motherName ? '&motherName=' + encodeURIComponent(motherName) : '') +
							//below lines added by prakash for "employer" 14-feb-2008
							(employer ? '&employer=' + encodeURIComponent(employer) : '') +
							//below 2 lines added by venkat for "occupation"
							(occupation ? '&occupation=' + encodeURIComponent(occupation) : '') +						
							(occupationNatureIDs ? '&occupationNatureIDs=' + encodeURIComponent(occupationNatureIDs) : '') +
							'&email=' + encodeURIComponent(email) +
							'&userName=' + encodeURIComponent(userName) + 
							'&fullName=' + encodeURIComponent(firstName + ' ' + (middleName ? middleName + ' ' : '') + lastName) + 
							'&password=' + encodeURIComponent(password) +
							(secretQ ? '&secretQ=' + encodeURIComponent(secretQ) : '') +
							(secretA ? '&secretA=' + encodeURIComponent(secretA) : '') +
							(officeID ? '&officeID=' + officeID : '') +
							(providerID ? '&providerID=' + encodeURIComponent(providerID) : '') +
							'&timeStamp=0' + 
							'&' +
							gpr.registry.get(this.id + '.address').getBody()  +
							'&' +
							( gpr.queryString('ptype')	 == gpr.paymentType.Refer ? 'paymentType=' +  gpr.paymentType.Refer : gpr.registry.get(this.id + '.payment').getBody())
							
						);
			}
		}
	};
	
	this.getPaymentBody = function()
		{
			return 'id=' + gpr.data.user.id + "&" +
					gpr.registry.get(this.id + '.payment').getBody()

		}
};

gpr.forms.patientMedicationDelete = function(id, medicationID, onSubmit)
{
	this.id = id;
	this.medicationID = medicationID;
	this.onSubmit = onSubmit
	gpr.registry.add(this);
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.getCenterCordinates = function(Sr, Pl, Pw, Dw) 
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}
	
	this.getBody = function()
	{
		var reasonID = document.getElementById(this.id + '.reason').value || ''
		var comments = document.getElementById(this.id + '.comments').value || ''
		
		if(reasonID == 1 && comments.length == 0)
		{
			alert("Please enter comments.");
			document.getElementById(this.id + '.comments').focus();
		}
		else
		{
			return 'id=' + encodeURIComponent(this.medicationID) + '&reasonID=' + encodeURIComponent(reasonID) + '&inActiveComments=' + encodeURIComponent(comments)
		}
	}
	this.onReasonChange = function(selObj)
	{
		if(selObj.options[selObj.selectedIndex].value == 1)
		{
			document.getElementById(this.id + '.dvcomments').style.display= "block";
		}
		else
		{
			document.getElementById(this.id + '.dvcomments').style.display = "none";
		}

	}
	
	this.display = function()
	{
		var html = '<table  height="120"><tr height="1%"><td class="gpr-panel-caption">Delete Medication</td><td class="gpr-panel-caption"><a href="#" style="color:white" onClick="document.getElementById(\''+ this.id+ '\').style.display=\'none\'">X</td></tr>' +
			'<tr><td>Select Reason for Delete <select name="'+ this.id+ '.reason" onchange = "gpr.dispatcher.call(\'' + this.id + '\', \'onReasonChange\',this)"><option value="1">I am no longer taking this medicine</option><option value="2">I accidently entered this medicine</option></select></div></td></tr>' +
				'<tr><td><div id="'+ this.id + '.dvcomments"><span class="reg-required">*</span>Comments <input type="text" id="' + this.id + '.comments" size="50" ' + focusClass + 'maxlength="100"></td></tr>' +
			'<tr>' +
					'<td align="center" style="padding:10px">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\', ' + this.medicationID + '); return false;" >' +
						'<a href="javascript:void(0)" ' +
							'>OK</a></span>' +						'<span class="dropshadow">' +
						'<span class="dropshadow" onClick="document.getElementById(\''+this.id + '\').style.display=\'none\'"" >' +
							'<a href="#" >Cancel</a></span>' +
					'</td>' +
				'</tr>' +
				'</table>'
				
		var nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, 300) 

		var nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, 100)

		document.getElementById(this.id).innerHTML = html
		document.getElementById(this.id).style.display = 'block'
	}
}
gpr.forms.user = function(id, user, onSubmit, onSecurityInfo,onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onSecurityInfo = onSecurityInfo;
	this.onClose = onClose;
	
	gpr.registry.add(this);
	user = user || {id: 0,timeStamp:0};
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

	this.getHtml = function()
	{
		var html = [
			'<input id="' + this.id + '.id" type="hidden" value="' + gpr.htmlString(user.id) + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + user.timeStamp + '">' +
			'<input id="' + this.id + '.passwordChanged" type="hidden" value="' + (user.id ? '' : '1') + '">' +
			'<input id="' + this.id + '.securityInfo" type="hidden" value="' + (user.id ? '' : '1') + '">' +
			'<h3>Edit Account</h3>' +
			'<span class="reg-required">*</span> denotes Required Fields ' +
			'<br>' +
			'<table class="gpr-panel">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Login Information</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><span class="reg-required">*</span><label for="' + this.id + '.fullName" >Full Name</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><input type="text" id="' + this.id + '.fullName" size="50"  value="' + gpr.htmlString(user.fullName) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><span class="reg-required">*</span><label for="' + this.id + '.email" >Email Address</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><input type="text" id="' + this.id + '.email" size="50"  value="' + gpr.htmlString(user.email) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><span class="reg-required">*</span><label for="' + this.id + '.confirmEmail" >Confirm Email Address</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><input type="text" id="' + this.id + '.confirmEmail" size="50" value="' + gpr.htmlString(user.email) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr> '
			];

		if ( user.id )
		{
			html.push(
				'<tr>' +
					'<td colspan="2">' +
						'<a href="javascript:void(0)" id="' + this.id + '.security-info-btn"' +
							' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSecurityInfo\'); return false;"' +
						'>' +
							'Security Info >>' +
						'</a>' +
					'</td>' +
				'</tr>' +
				'<tbody id="' + this.id + '.security-info-form" style="display: none">'
			);
		}

		html.push(
				'<tr>' +
					'<td><span class="reg-required">*</span><label for="' + this.id + '.userName" >UserID</label></td>' +
					'<td rowspan="4" align="left" valign="top"><table cellpadding="0" cellspacing="0"><tr height="5"><td><b><u>Password Guidelines'+'</b></u></td></tr>'+
	'<tr>'+'<td>'+'Minimum Length : ' + gpr.data.passwordSettings[1].minLength + '</td></tr>');
	if(gpr.data.passwordSettings[1].noOfNumerics > 0)
	{
		html.push('<tr>'+'<td>'+'Min Number of Numeric Characters : ' + gpr.data.passwordSettings[1].noOfNumerics + '</td></tr>');
	}
	else if(gpr.data.passwordSettings[1].noOfNumerics == -1)
	{
		html.push('<tr>'+'<td>'+ ' Numeric Characters are not allowed.'+'</td></tr>');
	}
	if(gpr.data.passwordSettings[1].noOfAlphabets > 0)
	{
		html.push('<tr>'+'<td>'+'Min Number of Alphabets : ' + gpr.data.passwordSettings[1].noOfAlphabets + '</td></tr>');
	}
	else if(gpr.data.passwordSettings[1].noOfAlphabets == -1)
	{
		html.push('<tr>'+'<td>'+ ' Alphabets are not allowed.'+'</td></tr>');
	}
	html.push('</table></td>'+
				'</tr>' +
				'<tr>' +
					'<td><input type="text" id="' + this.id + '.userName" maxlength="50" readonly="readonly" class="readonlyTextBox" value="' + gpr.htmlString(user.userName) + '" '+ '' + '></td>' +
				'</tr>' +
				'<tr>' +
					'<td><span class="reg-required">*</span><label for="' + this.id + '.password" >Password</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td><input type="password" id="' + this.id + '.password" '+ focusClass + ' maxlength="20" onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');" onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onPasswordChange\');"></td>' +
				'</tr>' +
				'<tr>' +
					'<td><span class="reg-required">*</span><label for="' + this.id + '.confirmPassword" >Confirm Password</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td><input type="password" id="' + this.id + '.confirmPassword" '+ focusClass + ' maxlength="20" onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');"></td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td><span class="reg-required">*</span><label for="' + this.id + '.secretq" >Secret Question</label></td>' +
								'<td><span class="reg-required">*</span><label for="' + this.id + '.secreta" >Answer</label></td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<select id="' + this.id + '.secretQ" >' +
										'<option value=""></option>'
		);
								
					for( var i = 0; i < gpr.secretQuestions.length; ++i )
					{
						var q = gpr.htmlString(gpr.secretQuestions[i])
						html.push('<option value="' + q + '">' + q + '</option>');
					}
											
					html.push(
												'</select>' +
											' </td>' +
											'<td><input type="text" size="30" id="' + this.id + '.secretA" value="' + gpr.htmlString(user.secretA) + '" '+ focusClass + ' maxlength="250"></td>' +
										'</tr>' +
									'</table>' +
								'</td>' +
							'</tr> '
					);
				
					if ( user.id )
					{
						html.push(
							'</tbody>'
						);
					}
		
		html.push(
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center"  colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" ' + '>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Cancel</a>'*/
							'<a href="javascript:void(0)" ' +
							'>Close</a>'
							 +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'  	

		);	
		
		html.push	
		return html.join('');
	};

	this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '0');
		var passwordChanged = gpr.Trim(document.getElementById(this.id + '.passwordChanged').value || '');
		var securityInfo = gpr.Trim(document.getElementById(this.id + '.securityInfo').value || '');
		var fullName = gpr.Trim(document.getElementById(this.id + '.fullName').value || '');
		var email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
		var confirmEmail = gpr.Trim(document.getElementById(this.id + '.confirmEmail').value || '');
		var userName = gpr.Trim(document.getElementById(this.id + '.userName').value || '');
		var password = gpr.Trim(document.getElementById(this.id + '.password').value || '');
		var confirmPassword = gpr.Trim(document.getElementById(this.id + '.confirmPassword').value || '');
		var secretQ = gpr.Trim(document.getElementById(this.id + '.secretQ').value || '');
		var secretA = gpr.Trim(document.getElementById(this.id + '.secretA').value || '');
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		
		if ( ! fullName )
		{
			alert('Please enter Full Name.');
			document.getElementById(this.id + '.fullName').focus();
		}
		else if ( !email )
		{
			alert('Please enter Email.');
			document.getElementById(this.id + '.email').focus();
		}
		else if(!gpr.forms.Checkemail(email))
		{
			document.getElementById(this.id + '.email').focus()
		}
		else if (email != confirmEmail )
		{
			alert('Confirm Email is different from Email.');
			document.getElementById(this.id + '.confirmEmail').focus();
		}
		else if (securityInfo && !userName )
		{
			alert('Please enter User Name.');
			document.getElementById(this.id + '.userName').focus();
		}
		/*else if(securityInfo && !gpr.forms.ValidatePwd(password)) //added by deepak, Nous for strong password implementation on 28-Feb-2007
		{
			//alerts are raised in the function itself.
			document.getElementById(this.id + '.password').focus()
		}*/
		else if(securityInfo && !password)
		{
			alert('Please enter a password');
			document.getElementById(this.id + '.password').focus();
		}
		else if(securityInfo && password != confirmPassword)
		{
			alert('Confirm Password is different from Password.');
			document.getElementById(this.id + '.confirmPassword').focus();
		}
		else if ( securityInfo && passwordChanged && password != confirmPassword )
		{
			alert('Confirm Password is different from Password.');
			document.getElementById(this.id + '.confirmPassword').focus();
		}
		else
		{
			return (
				'id=' + id + 
				'&fullName=' + encodeURIComponent(fullName) +
				'&email=' + encodeURIComponent(email) +
				'&timeStamp=' + encodeURIComponent(timeStamp) +
				(securityInfo 
					?	('&securityInfo=1' +
						'&userName=' + encodeURIComponent(userName) + 
						(passwordChanged ? '&passwordChanged=' + passwordChanged : '') + 
						(passwordChanged ? '&password=' + encodeURIComponent(password) : '') +
						(secretQ ? '&secretQ=' + encodeURIComponent(secretQ) : '' )+
						(secretA ? '&secretA=' + encodeURIComponent(secretA) : ''))
						: ''
				)
			);
		} 
	};
	
	this.setSecurityInfo = function()
	{
		var securityInfo = gpr.data.user.securityInfo;
		if ( securityInfo )
		{
			document.getElementById(this.id + '.userName').value = securityInfo.userName;
			document.getElementById(this.id + '.secretQ').value = securityInfo.secretQ;
			document.getElementById(this.id + '.secretA').value = securityInfo.secretA;
			document.getElementById(this.id + '.securityInfo').value = 1;
		}
		document.getElementById(this.id + '.password').value = '********';
		document.getElementById(this.id + '.confirmPassword').value = '********';
		document.getElementById(this.id + '.security-info-btn').style.display = 'none';
		document.getElementById(this.id + '.security-info-form').style.display = 'block';
	};
	
	this.onPasswordChange = function()
	{
		document.getElementById(this.id + '.passwordChanged').value = '1';
	}
	
};

gpr.forms.providerAccess= function(id, onSubmit)
{
	this.id = id;
	this.onSubmit = onSubmit;
	gpr.registry.add(this);
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

	this.getHtml = function(secretQ)
	{
		/*5868f5a7-cdd7-4786-b1c5-49aad7b0a6f6*/
		var gprid =  gpr.queryString('gprid') == 'false' ? '' : gpr.queryString('gprid')  
		var upin =  gpr.queryString('upin') == 'false' ? '' : gpr.queryString('upin') 
		
		var html = [
			'<div id="' + this.id + '.form" class="gpr-panel">' +
				'<h3>Welcome to GlobalPatientRecord! </h3>' +
				'<p>Your patient has invited you to view their personal, confidential and secure electronic health record.  Their electronic medical record will assist you in providing better patient care.  The information you find herein, will allow you to: </p>'+ 
						'<ul><li>review medical and family history' +
						'<li>have accurate information ' +
						'<li>   make better decisions '+
						'<li>     have up-to-date medication, dosages and allergy information </li></ul>' +
				'<br><p> If you already have Patient\'s GPR-ID, please enter it below</p>' +
				'<br><table><tr><td><label for="' + this.id + '.userName" >GPR-ID:</label></td></tr><tr><td>' +
				'<input id="' + this.id + '.gprid" type="text" size="50" '+ focusClass + ' value="'+ gprid +'"></td></tr>' +
				'<tr><td><label for="' + this.id + '.upin" >UPIN:</label></td></tr><tr><td>' +
				'<input id="' + this.id + '.upin" type="text" size="50" '+ focusClass + ' value="'+ upin  +'"></td></tr>' 
				
		];
		html.push(	'<tr><td style="text-align:right;padding-top:5px"><span class="dropshadow" id="' + this.id + '.submit"><a href="javascript:void(0)" ' +
						' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">Submit</a></span> <span class="dropshadow">' +
							'<a href="login.htm">Cancel</a></span></td></tr></table>' 
		);
		
		html.push('<br><p>With GlobalPatientRecord, physicians and healthcare providers can expect an average savings of $20.00 per patient visit.  Patients are working with you to assume more responsibility in their own healthcare.  Satisfaction and communication increases while costs, liability and time decrease.  GlobalPatientRecord is HIPPA compliant and used by thousands of people throughout the world today.  For more information visit <a href="http://www.globalpatientrecord.com" target="_blank">www.globalpatientrecord.com</a> or <a href="http://www.caredata.med.pro/global.htm" target="_blank">www.caredata.med.pro/global.htm</a> ')
		html.push('<br><br>Have your patients to sign up today and take advantage of the many benefits it has to offer! ')
 		return html.join('');
	};
	
	this.getBody = function()
	{
		var gprid = document.getElementById(this.id + '.gprid').value || '';
		if(!gprid) return;
		var upin =  document.getElementById(this.id + '.upin').value || '' ;
	
		return (
			'gprid=' + encodeURIComponent(gprid) + 
			'&upin=' + encodeURIComponent(upin));
	};
};

gpr.forms.appointment = function (id, onSubmit, onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()

	
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
    //Add by Nous(Manoj) to convert UTC Time to get the startTimeSlot
	this.getDateTimeFromUTC = function(pUtcDate)
	{
		var startTime = String(pUtcDate);
		var prop = [];
		var mon = 0;
		var day = 0;
		var year = 0;
		var time;
		var times = [];
		var hr = 0;
		var weekday;
		
		prop = startTime.split(" ");
		weekday = prop[0];
		times = prop[3].split(':');
		hr = times[0];
	
		if(hr > 12)
		{
			hr -= 12;
			
			if (hr < 10)
			{
			hr = '0'+hr;
			}
			times[0] = hr;
			times[1] += " PM";
		}
		else if(hr == 12)
		{
			times[1] += " PM";
		}
		else
		{
			times[1] += " AM";
		}
		time = times[0] + ":" + times[1];
		return time;
	}
	
	// Add by Nous(Manoj) to get the position for pop-up window

	this.getWindowCenterElements = function(nWidth, nHeight)
	{
	
	var sFeatures
	var nLeft, nTop
	nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth - 15 + 20) 
	nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight - 1 + 60) 
	sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight 
	return sFeatures
	
	}
	
	// Add by Nous(Manoj) to get the center cordinates

	this.getCenterCordinates = function (Sr, Pl, Pw, Dw)
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}

	//Function Added by Nous (Manoj) To set all appointment values to appointmnet form from schedule pop up window.
	
	this.onAppointmentSelect = function(apptID, startTime,locationID,locationName,date,ScheduleAnyWay)
	{
		 var UtcTime = String(startTime);
		 var arrTime = [];
		 arrTime = UtcTime.split(" ");
		 var weekday = arrTime[0];
		 
 	 
		 var StartTime = this.getDateTimeFromUTC(startTime);
			 
		 document.getElementById(this.id + '.date').value = date;
		 document.getElementById(this.id + '.locationName').value = locationName;
		 document.getElementById(this.id + '.locationID').value = locationID;
		 document.getElementById(this.id + '.weekDay').value = weekday;
		 document.getElementById(this.id + '.startTimeSlotId').value = this.getTimeSlot(StartTime);
		 document.getElementById(this.id + '.ScheduleAnyWay').value = ScheduleAnyWay;
		  
		 if (StartTime == '11:45 PM')
		 {
		 document.getElementById(this.id + '.endTimeSlotId').value = 1;
		 }
		 else
		 {
		 document.getElementById(this.id + '.endTimeSlotId').value = this.getTimeSlot(StartTime) + 1;
		 }
			 
	}
	this.openpopupWindow = function()
	{
		var style = this.getWindowCenterElements(700,635) +  ", status=yes,resizable=no,scrollbars=no";
		//style = '\'' + style + '\''
		//alert(style);
		if (objWin && !objWin.closed)
		{
			objWin.focus();
		}
		else
		{
			objWin = window.open('Schedule/ProviderView.aspx?ProviderID=' + gpr.data.currentProviderID + '&Provider=' + gpr.data.currentProviderName + '&PatientID=' + gpr.data.currentPatientID + '&Date=' + document.getElementById(this.id + '.date').value , null, style)
		}
	}
	
	this.getScheduleLink = function()
	{
	
		
		var HTML
		//HTML = '<a style="display:none;padding-top:3" id="myDiv1" name="' + this.id + '.pickSlots" href="#" onclick="window.open(\'Schedule/ProviderView.aspx?ProviderID=\' + gpr.data.currentProviderID + \'&Provider=Dr.Taylor\', null, \'top=187.5,left=287.5,height=635,width=700,resizable=yes,toolbar=no,menubar=no,location=no\')">Pick the available slots</a>' 
		HTML = '<a style="display:none;padding-top:3" id="myDiv1" name="' + this.id + '.pickSlots" href="#" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'openpopupWindow\')">Pick the available slots</a>' 
		return HTML
	}
	
	//function changed by nous (Manoj) to hide the link accoring to provider select
	this.onChangeProvider = function(selObj)
	{
		var providerID = selObj.options[selObj.selectedIndex].value
		var careDataID = this.getProvider(providerID).careDataID
		document.getElementById(this.id + '.careDataID').value = careDataID
		gpr.data.currentProviderID = providerID
		gpr.data.currentProviderName = this.getProvider(providerID).firstName + ' ' + this.getProvider(providerID).lastName 
			
		if (providerID == 0)
		{
		document.getElementById(this.id + '.providerEmail').value = "";
		document.getElementById('myDiv1').style.display = 'none';
		//document.getElementById('lnkCalendar').style.display = 'none';
		}
		else
		{
			document.getElementById(this.id + '.providerEmail').value = this.getProvider(providerID).email
			if (careDataID != 0)
			{
				document.getElementById('myDiv1').style.display = 'block';
				document.getElementById('locspan').style.display = 'block';
				//document.getElementById('lnkCalendar').style.display = 'block';
			}
			else
			{
				document.getElementById('myDiv1').style.display = 'none';
				document.getElementById('locspan').style.display = 'none';
				//document.getElementById('lnkCalendar').style.display = 'none';
			}
		}
	}
	
	this.getProvider = function(id)
	{
		var pp = gpr.data.getCurrentPatientCollection('patientProviders');
		var emailId = ''
		for( var i = 0; i < pp.length; i++ )
		{							
			if(pp[i].provider.id  == id){ return 	pp[i].provider}
		}
		
		return { }
	};
	
	//Funtion getTimeSlot Added by Nous (Manoj) is used to get the time slot by passing time
	this.getTimeSlot = function(time)
	{
	
		var ts = gpr.dictionaries.timeSlots;
		for ( var i = 0; i < ts.length; ++i)
		{
			if(ts[i].slot == time)
			{
			return ts[i].id;
			}
		}
		return 0;
		
		
	}
	
	this.getCallBackNumber = function(pa, patientID)
	{
		var home  = gpr.findPatient(gpr.data.patients, patientID).homePhone;
		var work  = gpr.findPatient(gpr.data.patients, patientID).workPhone;
		var cell  = gpr.findPatient(gpr.data.patients, patientID).cellPhone;

		return  (	'<select id="'+ this.id + '.patientcontactNumber">' +
		'<option value="'+ home + '" ' + (pa.patientContactNumber == home ? 'selected' : '') + ' >'+ home +' (Home)</option>' +
		'<option value="'+ work + '" ' + (pa.patientContactNumber == work ? 'selected' : '') + '>'+ work +' (Work)</option>' +
		'<option value="'+ cell + '"  ' + (pa.patientContactNumber == cell ? 'selected' : '') + '>'+ cell+'(Cell)</option>' +
		'</select> (A number where provider can reach you in regards to this appointment)')

	
	}
	this.getHtml = function(patientID, pa)
	{
		pa = pa || {id:0, patientID:patientID, providerID:'', date:'', reasonToVisit:'', description:'', providerEmail:''};
		return  (	'<br>' +
				'<input type="hidden" name="' + this.id + '.patientID" value="' + pa.patientID + '">' +
				'<input type="hidden" name="' + this.id + '.id" value="' + pa.id + '">' +
				'<input type="hidden" name="' + this.id + '.careDataID" value="' + pa.careDataID + '">' +
				'<input type="hidden" name="' + this.id + '.locationID" value="">' +
				'<input type="hidden" name="' + this.id + '.weekDay" value="">' +
				'<input type="hidden" name="' + this.id + '.ScheduleAnyWay" value="0">'+
				 
				'<span class="reg-required">*</span> denotes Required Fields'+
				'<table class="gpr-panel">' +
					'<tr>' +
						'<td colspan="2" class="gpr-panel-caption">Appointments (' + gpr.data.patients[pa.patientID].firstName + ')</td>' +
					'</tr>' +
					'<tr>' +
						'<td colspan="2" align="left">'+
						'<table cellpadding="0" cellspacing="0"><tr><td width="101" align="left">'+
						'<label for="'+ this.id + '.providerID" align="left"><span class="reg-required">*</span>Select Provider</label></td>' +
						'<td valign="bottom">&nbsp;&nbsp;&nbsp;' +
							gpr.getProvidersList(this.id + '.providerID', pa.providerID, 'gpr.dispatcher.call(\'' + this.id + '\', \'onChangeProvider\', this); return false;') +
							'<td>'+							
							'<label for="'+ this.id + '.providerEmail">&nbsp;<span class="reg-required">*</span>Providers Email </label></td> '+
							'<td><input type="text" id="' + this.id + '.providerEmail" size="45" value="'+ pa.providerEmail + '" ' + focusClass + ' maxlength="50">' +
						'</td></tr></table>'+	
							
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td><label for="'+ this.id + '.date">&nbsp;<span class="reg-required">*</span>Date </label></td>' +
						'<td align="left"><table align="left" cellpadding="0" cellspacing="0"><tr><td align="left">' +
						'&nbsp;<input type="text" name="' + this.id + '.date" id="' + this.id + '.date" value="' + (gpr.isNullDate(pa.date) ? month + "/" + day + "/" + year : gpr.htmlString(pa.date)) + '" ' + focusClass + '>' +
							'<a href="#"  id="lnkCalendar" onclick="showCalendar(\'' + this.id + '.date\',\''+ gpr.consts.dateFormat +'\', false)"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
						' (mm/dd/yyyy)' +
						'</td><td valign=top>' +
						//'<a style="display:none;padding-top:3" id="myDiv1" name="' + this.id + '.pickSlots" href="#" onclick="window.open(\'Schedule/ProviderView.aspx?ProviderID=this.providerid + '\&Provider=Dr.Taylor\', null, \'top=187.5,left=287.5,height=635,width=700,resizable=yes,toolbar=no,menubar=no,location=no\')">Pick the available slots</a>' +
						this.getScheduleLink()
						+
						'</td></tr></table>' +
						'</td>' +
					'</tr>' +
					'<tr>'+
					'<td>'+
					'<label for="'+ this.id + '.startTime">&nbsp;<span class="reg-required">*</span>Start Time</label></td> '+
					'<td>&nbsp;&nbsp;' + this.getTimeSlotList(pa,'.startTimeSlotId',pa.startTime)+'</td>'
					+ '<tr>' + '<td>' +
					'<label for="'+ this.id + '.endTime">&nbsp;<span class="reg-required">*</span>End Time</label> </td> <td>&nbsp;&nbsp;'
					+ this.getTimeSlotList(pa,'.endTimeSlotId',pa.endTime) +
					'</td>'+
					'</tr>'+
					'<tr><td colspan="2" align="left">'+
					'<span id="locspan" style="display:none;padding-top:3">'+
					'<table align="left" cellpadding="0" cellspacing="0"><tr><td align="left" width="25%">'+
					'<label id="'+ this.id + '.location"><span class="reg-required">*</span>Location</label>'+
					'</td><td align="left" style="padding-left:3px">' +
					'<input type="text" id="' + this.id + '.locationName" readonly="readonly" class="readonlyTextBox" size="50" value="" '+ ' maxlength="75">'
					 +'</td> </tr></table> </span>'
					+'</td></tr>'+
					'<tr>' +
						'<td><label for="'+ this.id + '.reasontovisit">&nbsp;<span class="reg-required">*</span>Reason For Visit</label></td>' +
						'<td>' +
						'&nbsp;&nbsp;<input type="text" id="' + this.id + '.reasontovisit" size="79" value="' + gpr.htmlString(pa.reasonToVisit) + '"  ' + focusClass + ' maxlength="100">' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td>&nbsp;&nbsp;&nbsp;Comments</td>' +
						'<td>' +
						' &nbsp;&nbsp;<textarea  id="' + this.id + '.description" size="79" value=""  ' + focusClass + ' rows="5" cols="60">' + gpr.htmlString(pa.description) + '</textarea>' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td>&nbsp;&nbsp;&nbsp;Callback number</td>' +
						'<td>&nbsp;&nbsp;' +
							this.getCallBackNumber(pa, patientID) +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td> </td>' +
						'<td><br>' +
							'&nbsp;<input type="checkbox" id="' + this.id + '.recorduptodate">My Medical Record (Allergies, Medications, Identification, Surgeries and Insurance Record) is up to date. '  +
						'</td>' +
					'</tr>' +
						'<tr>' +
						'<td> </td>' +
						'<td><br>' +
							'&nbsp;<input type="checkbox" id="' + this.id + '.hipaa">I have read & understood the <a href="hipaa.htm" target="_blank">HIPAA Privacy Agreement<br></a> '+
							'<br></td>' +
					'</tr>' +
					'<tr>' +
						'<td align="center" colspan="2">' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
								'<a href="javascript:void(0)" ' +
								'>Submit</a>' +
							'</span>' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\',1); return false;" >' +
								'<a href="javascript:void(0)" ' +
								'>Cancel</a>' +
							'</span>' +
						'</td>' +
					'</tr>' +
				'</table>' )
	
			};
	
	this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '');
		var providerID = gpr.Trim(document.getElementById(this.id + '.providerID').value || '');
		var date =  gpr.Trim(document.getElementById(this.id + '.date').value || '');
		var reasontovisit = gpr.Trim(document.getElementById(this.id + '.reasontovisit').value || '');
		var description = gpr.Trim(document.getElementById(this.id + '.description').value || '');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value || '');
		var providerEmail = gpr.Trim(document.getElementById(this.id + '.providerEmail').value || '');
		var patientContactNumber = gpr.Trim(document.getElementById(this.id + '.patientContactNumber').value || '');
		var recorduptodate = document.getElementById(this.id + '.recorduptodate').checked ||  false;
		var hipaa = document.getElementById(this.id + '.hipaa').checked ||  false;
		var startTime = gpr.Trim(document.getElementById(this.id + '.startTimeSlotId').value || '');
		var endTime = gpr.Trim(document.getElementById(this.id + '.endTimeSlotId').value || '');
		var locationID = gpr.Trim(document.getElementById(this.id + '.locationID').value || '');
		var careDataID = gpr.Trim(document.getElementById(this.id + '.careDataID').value || '');
                var locationName = (!locationID)? gpr.Trim(document.getElementById(this.id + '.locationName').value || '') : '';
		var weekDay =  gpr.Trim(document.getElementById(this.id + '.weekDay').value)
		var ScheduleAnyWay = gpr.Trim(document.getElementById(this.id + '.ScheduleAnyWay').value);
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		
 	 	if(!providerID)
		{
			alert('Please select a Provider')
			document.getElementById(this.id + '.providerID').focus();
		}
		else if(!providerEmail)
		{
			alert('Provider\'s email is missing. Please enter the email address')
			document.getElementById(this.id + '.providerEmail').focus();
		}
		else if(providerEmail != "" && gpr.forms.Checkemail(providerEmail) == false)
		{
			document.getElementById(this.id + '.providerEmail').focus();
		}
		else if(!date)
		{
			alert('Please enter the appointment Date')
			document.getElementById(this.id + '.date').focus();
		}
		else if (! gpr.isDate(date))
		{
			document.getElementById(this.id + '.date').focus();
		}
		else if(!startTime || startTime == 0 )
		{
		alert('Please select a start time slot for appointment');
		document.getElementById(this.id + '.startTimeSlotId').focus();
		}
		else if (!endTime || endTime == 0 )
		{
		alert('Please select a end time slot for appointment');
		document.getElementById(this.id + '.endTimeSlotId').focus();
		}
		else if((startTime > endTime || startTime == endTime)&& endTime != 1 )
		{
		alert('Start time must be less than end time');
		document.getElementById(this.id + '.endTimeSlotId').focus();
		}
		else if(careDataID != 0 && !locationID )
		{
			alert ('For Care Data providers timing must select using scheduler.');
		}
		else if(!reasontovisit)
		{
			alert('Please enter reason for visit ')
			document.getElementById(this.id + '.reasontovisit').focus();
		}
		else if(description.length > 1000)
		{
			alert('Please enter comments with less than 1000 characters ')
			document.getElementById(this.id + '.description').focus();
		}
		else if(!recorduptodate)
		{
			alert('You cannot submit this form without completing your medical record. If you think your medical record is not update please update your medical record first and then fill out this form, otherwise click the medical record checkbox and submit again ')
			document.getElementById(this.id + '.recorduptodate').focus();
		}
		else if(!hipaa)
		{
			alert('Please read the HIPAA privacy agreement and provide your consent by checking the box')
			document.getElementById(this.id + '.hipaa').focus();
		}

		else
		{
			return (
				'id=' + encodeURIComponent(id) + 
				'&providerID=' + encodeURIComponent(providerID) + 
				'&date=' + encodeURIComponent(date) + 
				'&reasontovisit=' + encodeURIComponent(reasontovisit) + 
				'&description=' + encodeURIComponent(description) + 
				'&patientID=' + encodeURIComponent(patientID) + 
				'&providerEmail=' + encodeURIComponent(providerEmail) +
				'&providerlastname=' + encodeURIComponent(this.getProvider(providerID).lastName) +
				'&patientContactNumber=' + encodeURIComponent(patientContactNumber) +
				'&patientlastname=' + encodeURIComponent(gpr.findPatient(gpr.data.patients, patientID).firstName + ' ' + gpr.findPatient(gpr.data.patients, patientID).lastName)  +
				'&hipaa=' + (hipaa ? "1" : "0") +
				'&recorduptodate=' + (recorduptodate  ? "1" : "0") +
				'&startTime='+ encodeURIComponent(startTime)  +
				'&endTime='+ encodeURIComponent(endTime) +
				'&locationID='+ encodeURIComponent(locationID) +
				'&careDataID='+ encodeURIComponent(careDataID)+
				'&weekDay='+ encodeURIComponent(weekDay)+
				'&ScheduleAnyWay='+ encodeURIComponent(ScheduleAnyWay)+
				('&CareDataUserID=' + careDatauserID )
				);
			}
	};
	
	this.getTimeSlotList = function(patientAppointment,id,value)
	{
	
		var html = [];
	
		html.push(
			'<select id="' + this.id + id + '"' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectTimeSlot\', this); return false;">' +
				'<option value=""></option>'
		
			);
		
		var im = gpr.dictionaries.timeSlots;	
		
		for ( var i = 1; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == value)
			{
				html.push(' selected ');
			}
			else if (!value && im[i].slot == '09:00 AM')
			{
				html.push(' selected ');
			}
			else if (!value && im[i].slot == '09:15 AM' && id == '.endTimeSlotId')
			{
				html.push(' selected ');
			}
			
			html.push('>')
			html.push(gpr.htmlString(im[i].slot));
			html.push('\</option>');
		}
		
		html.push('</select>');
		return html.join('') 
		
	};
	
}


gpr.forms.labResult = function (id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete
	gpr.registry.add(this);
	

	// Add by Nous(Manoj) to get the position for pop-up window

	this.getWindowCenterElements = function(nWidth, nHeight)
	{
	
	var sFeatures
	var nLeft, nTop
	nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth - 15 + 20) 
	nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight - 1 + 60) 
	sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight 
	return sFeatures
	
	}
	
	// Add by Nous(Manoj) to get the center cordinates

	this.getCenterCordinates = function (Sr, Pl, Pw, Dw)
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.openpopupWindow = function()
	{
		var style = this.getWindowCenterElements(900,650) +  ", status=yes,resizable=no,scrollbars=yes"
		
		if (objWinCPTCodes && !objWinCPTCodes.closed)
		{
			objWinCPTCodes.focus();
		}
		else
		{
			objWinCPTCodes = window.open('CPTCodes/CPTCodeSearch.aspx?TestType=1',null,style )
		}
	}
	

	this.getProvider = function(id)
	{
		var pp = gpr.data.getCurrentPatientCollection('patientProviders');
		var emailId = ''
		for( var i = 0; i < pp.length; i++ )
		{							
			if(pp[i].provider.id  == id){ return 	pp[i].provider}
		}
		
		return { }
	};
	
	this.getHtml = function(patientID, pa,recordID)
	{
		var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	 
		if(patientID == 0)
		{
		patientID = pa.patientID;
		}
		pa = pa || {id:0, patientID:patientID, providerID:'', date:'', description:'',timeStamp:0};
		var isNew =  pa.id == 0
		var NewrecordID = pa.id == 0 ? recordID+1 : pa.recordID
		
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  pa.id + ',' + pa.patientID  + ',' + pa.recordID + '); return false;"' +
				'>Delete this Record?</a></span>'
				

		return  (	
		
                       (cdw ==  true ?  '<span style="float:right" class="text_basic_small">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\',1); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>' : '')+
        
        '<br>' +
				'<input type="hidden" name="' + this.id + '.CPTCode" value="' + pa.cptCode +'">'+	
				'<input type="hidden" name="' + this.id + '.recordID" value="' + NewrecordID + '">'+
				'<input id="' + this.id + '.timeStamp" type="hidden" value="' + pa.timeStamp + '">' +
				'<input type="hidden" name="' + this.id + '.patientID" value="' + pa.patientID + '">' +
				'<input type="hidden" name="' + this.id + '.id" value="' + pa.id + '">' +
				'<table class="gpr-panel">' +
					'<tr>' +
						'<td class="gpr-panel-caption">Lab Results / Visit Details (' + gpr.data.patients[pa.patientID].firstName + ')</td>' +
						'<td class="gpr-panel-caption" align="right">' + deleteHtml + ' </td>' +
					'</tr>' +
					'<tr><td colspan="2"><table cellspacing="5" cellpadding="5">'+
					'<tr>' +
						'<td><span class="reg-required">*</span>Description:</td>' +
						'<td>' +
						'<span id="' + this.id + '.description"' + '>' + gpr.htmlString(pa.description)+ '</span>' +
						'&nbsp;&nbsp;&nbsp;&nbsp;<a id="myDiv1" name="' + this.id + '.selectTestDescription" href="javascript:void(0)" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'openpopupWindow\')">Select a Lab Test</a>' 
						+'</td>' +
					'</tr>' +
						'<tr>' +
						'<td><label for="'+ this.id + '.date"><span class="reg-required">*</span>Date</label></td>' +
						'<td>' +
							'<input type="text" name="' + this.id + '.date" id="' + this.id + '.date" value="' + gpr.htmlString(pa.date) + '" ' + focusClass + ' maxlength="10">' +
							'<a href="#" onclick="showCalendar(\'' + this.id + '.date\',\''+ gpr.consts.dateFormat +'\', false)"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
						' (mm/dd/yyyy)' +
						'</td>' +
					'</tr>' +
							'<tr valign="top">' +
								'<td>' +
									'<label for="' + this.id + '.providerID" ><span class="reg-required">*</span>Provider<label>' +
								'</td>' +
								'<td colspan="3">' +
									gpr.getProvidersList(this.id + '.providerID', pa.providerID) +
									'(If the provider is not listed, enter the provider\'s name below)' +
								'</td>' +
							'<tr><td>' +
									'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<input type="text" id="' + this.id + '.providerName" size="79" value="' + gpr.htmlString(pa.providerName) + '"  ' + focusClass + ' maxlength="100">' +
								'</td>' +
					'</tr>' +
					'<tr>' +
						'<td><label for="'+ this.id + '.result">Location</label></td>' +
						'<td>' +
						'<input type="text" id="' + this.id + '.location" size="79" value="' + gpr.htmlString(pa.location) + '"  ' + focusClass + ' maxlength="50">' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td><label for="'+ this.id + '.result">Result</label></td>' +
						'<td>' +
						'<input type="text" id="' + this.id + '.result" size="79" value="' + gpr.htmlString(pa.result) + '"  ' + focusClass + ' maxlength="50">' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td> Comments</td>' +
						'<td>' +
						'<textarea  id="' + this.id + '.comments" size="79" value=""  ' + focusClass + ' rows="3" cols="60">' + gpr.htmlString(pa.comments) + '</textarea>' +
						'</td>' +
					'</tr>' +
					'<tr>' +
						'<td align="center" colspan="2">' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
								'<a href="javascript:void(0)" ' +'>Submit</a>' +
							'</span>' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\',1); return false;">' +
								'<a href="javascript:void(0)" ' +'>Cancel</a>' +
							'</span>' +
						'</td>' +
					'</tr>' +
				'</table></td></tr></table>' )
	
			};
	
	this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '');
		var providerID = gpr.Trim(document.getElementById(this.id + '.providerID').value || '');
                var providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';

		var date =  gpr.Trim(document.getElementById(this.id + '.date').value || '');
		var result = gpr.Trim(document.getElementById(this.id + '.result').value || '');
		var description = gpr.Trim(document.getElementById(this.id + '.description').innerText || '');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value || '');
		var comments = gpr.Trim(document.getElementById(this.id + '.comments').value || '');
		var location = gpr.Trim(document.getElementById(this.id + '.location').value || '');
		var recordID = gpr.Trim(document.getElementById(this.id + '.recordID').value || '');
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var cptCode =  gpr.Trim(document.getElementById(this.id + '.CPTCode').value);
		 var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'

		
		if(!description)
		{
			alert('Please enter a Description')
			document.getElementById(this.id + '.description').focus();
		}
                else if(description && description > 255)
                {
                        alert('Description cannot exceed 255 characters');
                        document.getElementById(this.id + '.description').focus();
                }
		else if(!date)
		{
			alert('Please enter a Date')
			document.getElementById(this.id + '.date').focus();
		}
		else if(!gpr.isDate(date))
		{
			document.getElementById(this.id + '.date').focus();
		}
		else if(!providerID && !providerName)
		{
			alert('Please select a Provider')
			document.getElementById(this.id + '.providerID').focus();
		}
		else if(comments && comments.length > 2000)
		{
			alert('Comments cannot exceed 2000 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		else
		{
			
			return (
				'id=' + encodeURIComponent(id) + 
				'&providerID=' + encodeURIComponent(providerID) + 
				'&providerName=' + encodeURIComponent(providerName) + 
				'&date=' + encodeURIComponent(date) + 
				'&result=' + encodeURIComponent(result) + 
				'&description=' + encodeURIComponent(description) + 
				'&patientID=' + encodeURIComponent(patientID)  +
				'&comments=' + encodeURIComponent(comments)  +
				'&location=' + encodeURIComponent(location) +
				'&recordID='+ encodeURIComponent(recordID) + 
				'&cptCode=' + encodeURIComponent(cptCode) +
				('&CareDataUserID=' + careDatauserID ) +
				'&timeStamp=' + encodeURIComponent(timeStamp) 

				);
			}
	};
	
	this.setCPTCodeValues = function(CPTCode,CPTDescription)
	{
		document.getElementById(this.id + '.description').innerText = CPTDescription;
		document.getElementById(this.id + '.CPTCode').value = gpr.htmlString(CPTCode);
	}
}










gpr.forms.resetPassword = function(id, onSubmit)
{
	this.id = id;
	this.onSubmit = onSubmit;
	gpr.registry.add(this);
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

	this.getHtml = function(secretQ,isPasswordChange)
	{
		this.reset = false;
		this.isPasswordChange = false;
		
		var html = [
				'<br><div id="' + this.id + '.form" class="gpr-panel">' +
				'<br> <h3>Forgot Password?</h3>' +
				//'<p> Please provide your UserID. If your UserID and secret question matches we will send you a new password via email. After you log in, you can always change that password to something you can remember  </p>' +
				'<table>'];
				
		if ( !this.userName )
		{
			html.push('<tr><td><label for="' + this.id + '.userName" >Please enter user name:</label></td></tr><tr><td>' +
			'<input id="' + this.id + '.userName" type="text" value="' + gpr.htmlString(this.userName ? this.userName : document.getElementById('controler.login.userName').value) + '" size="50" '+ focusClass + '></td></tr>');
		}
		
		if ( this.userName && !isPasswordChange)
		{
			this.reset = true;
			html.push(
				'<tr><td><input id="' + this.id + '.reset" type="hidden" value="1">' +
				'<input id="' + this.id + '.secretQ" type="hidden" value='+ secretQ +'>'+
				''+'<table cellspacing="5"><tr>' +
				'<td><label for="' + this.id + '.secretq" >Please select your secret question</label></td>' +
				'<td>&nbsp;&nbsp;&nbsp;&nbsp;<select id="' + this.id + '.secretQues" >' +
										'<option value=""></option>'
				);
			for( var i = 0; i < gpr.secretQuestions.length; ++i )
			{
				var q = gpr.htmlString(gpr.secretQuestions[i])
				html.push('<option value="' + q + '"'+ (isPasswordChange && this.secretQues == q ? 'Selected' : '' ) + '>' + q + '</option>');
			}
			html.push(
									'</select>' +
								' </td>' +
								'</tr>' +
							'<tr>' +
								'<td>'+
								'<label for="' + this.id + '.secreta" >Please enter your secret answer</label>'
							 + '</td>'+
						
								'<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" size="30" id="' + this.id + '.secretA" value="' + (isPasswordChange ? this.secretA : '') + '" '+ focusClass + ' maxlength="250"></td>' +
								'</tr></table></td></tr>' 
			);
			
			/*html.push(
				'<tr><td><input id="' + this.id + '.reset" type="hidden" value="1">' +
				
				'<br><label for="' + this.id + '.secretA" >' + gpr.htmlString(secretQ ? secretQ : 'Password Reset Answer:') + '</label></td></tr>' +
				'<tr><td><input id="' + this.id + '.secretA" type="text" size="50" maxlength="250"></td></tr>'
			);*/
		}
		if(isPasswordChange)
		{
			/*alert(this.secretQues);
			alert(this.secretA); */
			this.isPasswordChange = true;
			html.push('<tr><td colspan="2"><table cellpadding="0" cellspacing="0"><tr height="5"><td><b><u>Password Guidelines'+'</b></u></td></tr>'+
					'<tr>'+'<td>'+'Minimum Length : ' + gpr.data.passwordSettings[1].minLength + '</td></tr>');
					if(gpr.data.passwordSettings[1].noOfNumerics > 0)
					{
						html.push('<tr>'+'<td>'+'Min Number of Numeric Characters : ' + gpr.data.passwordSettings[1].noOfNumerics + '</td></tr>');
					}
					else if(gpr.data.passwordSettings[1].noOfNumerics == -1)
					{
						html.push('<tr>'+'<td>'+ ' Numeric Characters are not allowed.'+'</td></tr>');
					}
					if(gpr.data.passwordSettings[1].noOfAlphabets > 0)
					{
						html.push('<tr>'+'<td>'+'Min Number of Alphabets : ' + gpr.data.passwordSettings[1].noOfAlphabets + '</td></tr>');
					}
					else if(gpr.data.passwordSettings[1].noOfAlphabets == -1)
					{
						html.push('<tr>'+'<td>'+ ' Alphabets are not allowed.'+'</td></tr>');
					}
			html.push('</table></td></tr>');
			html.push('<tr><td colspan="2" height="10"></td></tr>' );
			html.push('<tr><td colspan="2"><b><u>Change Password</u><b></td></tr>' );
			html.push('<tr><td colspan="2"><span class="reg-required">*</span> denotes Required Fields</td></tr>'+
				'<tr>' +
				'<td><input id="' + this.id + '.isPasswordChange" type="hidden" value="1"><span class="reg-required">*</span><label for="' + this.id + '.password" >Password</label></td>' +
				'<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="password" id="' + this.id + '.password" '+ focusClass + ' maxlength="20" onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');" onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onPasswordChange\');"></td>'
				+'</tr>' +
				'<tr>' +
				'</tr>' +
				'<tr>' +
					'<td><span class="reg-required">*</span><label for="' + this.id + '.confirmPassword" >Confirm Password</label></td>' +
					'<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="password" id="' + this.id + '.confirmPassword" '+ focusClass + ' maxlength="20" onkeyDown="gpr.onKeyDown();" onkeyPress="gpr.validatePassword(\'this\',\'this.event\');"></td>' +
				'</tr>' +
				'<tr>'+
				'</tr>' );
		
		}
		
		html.push(	'<tr><td style="text-align:center;padding-top:5px" colspan="2"><span class="dropshadow" id="' + this.id + '.submit"><a href="javascript:void(0)" ' +
						' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">Submit</a></span> <span class="dropshadow">' +
							'<a href="login.htm">Cancel</a></span></td></tr></table>' 
		);
		return html.join('');
	};
	
	this.getBody = function()
	{
		if(document.getElementById(this.id + '.userName'))
		{
		var userName = document.getElementById(this.id + '.userName').value || '';
		}
		else
		{
		var userName = this.userName;
		}
		if(!userName)
		{
			alert("Please enter a valid User Name");
			document.getElementById(this.id + '.userName').focus();
			return;
		}
		
		var reset = this.reset ? document.getElementById(this.id + '.reset').value || '' : '';
		//var secretA = this.reset ? document.getElementById(this.id + '.secretA').value || '' : '';
		var secretQues = this.reset ? gpr.Trim(document.getElementById(this.id + '.secretQues').value || '') : '';
		var secretA = this.reset ? gpr.Trim(document.getElementById(this.id + '.secretA').value || '') : '';
		
		var isPasswordChange  = this.isPasswordChange ? document.getElementById(this.id + '.isPasswordChange').value || '' : '';
		var password = this.isPasswordChange ? gpr.Trim(document.getElementById(this.id + '.password').value || ''):'';
		var confirmPassword = this.isPasswordChange ? gpr.Trim(document.getElementById(this.id + '.confirmPassword').value || ''):'';
		
		if (reset == '1' && secretQues == '')
		{
			alert('Please select a secret Question')
			document.getElementById(this.id + '.secretQues').focus()
			return;
		}
		else if (reset == '1' && secretA == '')
		{
			alert('Please enter a secret Answer')
			document.getElementById(this.id + '.secretA').focus()
			return;
		}
		
		if(isPasswordChange == '1' && !password)
		{
			alert('Please enter a password');
			document.getElementById(this.id + '.password').focus();
			return;
		}
		else if(isPasswordChange == '1' && password != confirmPassword)
		{
			alert('Confirm Password is different from Password.');
			document.getElementById(this.id + '.confirmPassword').focus();
			return;
		}
		else if ( isPasswordChange == '1' && password != confirmPassword )
		{
			alert('Confirm Password is different from Password.');
			document.getElementById(this.id + '.confirmPassword').focus();
			return;
		}
		
		if(isPasswordChange == '1')
		{
			reset = 0;
		}
		
		this.userName = userName;
		this.secretQues = secretQues;
		this.secretA = secretA;
		
		return	(
					'userName=' + encodeURIComponent(userName) + 
					(reset == '1' ? '&reset=1' : '') + 
					(secretQues ? '&secretQ=' + encodeURIComponent(secretQues) : '')+
					(secretA ? '&secretA=' + encodeURIComponent(secretA) : '')+
					(isPasswordChange == '1' ? '&isPasswordChange=1' : '') + 
					(password ? '&password=' + encodeURIComponent(password) : '') + 
					(confirmPassword ? '&confirmPassword=' + encodeURIComponent(confirmPassword) : '')
				);
	};
};
//modifyied by prakash commented code 8-2-2008
gpr.forms.paymentDue = function(id, onSubmit, onCancel,  msg, chargeType, patientId, balance)
{	
	//debugger;
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.chargeType = chargeType;
	this.patientId = patientId;

	gpr.registry.add(this);
	
	this.getHtml = function()
	{
		var html = []
		
			
		html.push('<table class="gpr-panel"><tr>' +
							'<td class="gpr-panel-caption">Welcome  ' + gpr.data.user.fullName + '</td>' +
						'</tr> <tr><td')
				html.push('<span style="color:red">' + (msg  || '' ) + '</span>')

	
		html.push('</td></tr>')
			
	if(gpr.queryString('ptype')	 == gpr.paymentType.Refer)
		{	
			//html.push((new gpr.forms.payment(this.id + '.payment', balance).getHtml()) +
			html.push('<tr>' +
						'<td align="center">' +
							'<span class="dropshadow"  onclick="window.close(); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Close</a></span>' +
			//				'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
			//					'<a href="javascript:void(0)" ' +
			//					'>Cancel</a></span>' +
						'</td>' +
					'</tr>' )
		}
		return html.join(' ');	
	}
 
 this.getBody = function()
 {
 
	if(gpr.getRadioGroupValue('controler.paymentDue.payment.paymentType') == 4 && document.getElementById('controler.paymentDue.payment.promotionCode').value == '' )
	{
		alert('Please enter promotion code details');
		document.getElementById('controler.paymentDue.payment.promotionCode').focus();
		return;
	}
	else if(gpr.getRadioGroupValue('controler.paymentDue.payment.paymentType') == 1 && (document.getElementById('controler.paymentDue.payment.name').value == '' || document.getElementById('controler.paymentDue.payment.type').value == 'B' || document.getElementById('controler.paymentDue.payment.number').value == '' || document.getElementById('controler.paymentDue.payment.month').value == '' || document.getElementById('controler.paymentDue.payment.year').value == '') )
	{
		alert('Please enter credit card details');
		return;
	}
	
			return 'id=' + gpr.data.user.id + '&' +
					'chargeType=' + this.chargeType  + '&' +
					'patientId = ' + this.patientId + '&' +
					gpr.registry.get(this.id + '.payment').getBody()
 }
 
}

gpr.forms.payment = function(id, amount, mailingAddressId)
{
	this.mailingAddressId = mailingAddressId
	this.id = id;
	this.amount = amount;
	gpr.registry.add(this);
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	this.fillAddress =  function(obj)
	{
		if(obj.checked)
		{
		  document.getElementById(this.id + ".address.line1").value = document.getElementById(this.mailingAddressId  + ".line1").value
		  document.getElementById(this.id + ".address.line2").value = document.getElementById(this.mailingAddressId  + ".line2").value
		  document.getElementById(this.id + ".address.city").value = document.getElementById(this.mailingAddressId  + ".city").value
		  document.getElementById(this.id + ".address.state").selectedIndex = document.getElementById(this.mailingAddressId  + ".state").selectedIndex
		  document.getElementById(this.id + ".address.country").selectedIndex = document.getElementById(this.mailingAddressId  + ".country").selectedIndex
		  document.getElementById(this.id + ".address.zip").value = document.getElementById(this.mailingAddressId  + ".zip").value
		  
		  document.getElementById(this.id + ".address.line1").disabled = true
		  document.getElementById(this.id + ".address.line2").disabled =  true
		  document.getElementById(this.id + ".address.city").disabled =true
		  document.getElementById(this.id + ".address.state").disabled = true
		  document.getElementById(this.id + ".address.country").disabled = true
		  document.getElementById(this.id + ".address.zip").disabled = true
		}
		else
		{
		  document.getElementById(this.id + ".address.line1").disabled = false
		  document.getElementById(this.id + ".address.line2").disabled =  false
		  document.getElementById(this.id + ".address.city").disabled =false
		  document.getElementById(this.id + ".address.state").disabled = false
		  document.getElementById(this.id + ".address.country").disabled = false
		  document.getElementById(this.id + ".address.zip").disabled = false
		}
	}
	//modified by prakash for hiding payment options 2-feb-2008
	this.getHtml = function()
	{
		var html = []
			  html.push( '<tr>' +
					'<td colspan="2">&nbsp;</td>' +
				'</tr>' +
				'<tr style="DISPLAY: none">' +
					'<td colspan="2" class="gpr-panel-caption">Payment - <a href="help.htm#fees" target="_blank" style="color:white">Registration and Membership fees explanation</a></td>' +
				'</tr>' +
				'<tr style="DISPLAY: none">' +
					'<td colspan="2" >' +
                                                '<input type="radio" name="' + this.id + '.paymentType" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onPaymentSelect\',4)"  id="' + this.id + '.paymentType-pc" ' + focusClass + ' value="' + gpr.paymentType.Promotion + '" checked>' +
                                                '<b>By Promotion Code </b>' +
                                        '</td>' +
                                        '</tr>' +
                                        '<tr style="DISPLAY: none">' +
                                        '<td colspan="2"><table><tr><td valign="top">' +
                                                'Promotion Code : ' + 
                                                //'<input type="text" style="background-color:#d3d3d3" name="' + this.id + '.promotionCode" id="' + this.id + '.promotionCode" ' +  focusClass + ' value="" disabled >' +
                                                '<input type="text" name="' + this.id + '.promotionCode" id="' + this.id + '.promotionCode" ' +  focusClass + ' value="Promo2008">' +
                                                //'</td><td valign1="top"><span  id="' + this.id + '.applybutton" style="visibility:hidden"  class="dropshadow" valign="middle">' +
                                                '</td><td valign1="top"><span  id="' + this.id + '.applybutton" class="dropshadow" valign="middle">' +
                                                        '<a href="javascript:void(0)" ' +
                                                                ' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onApplyCode\'); return false;"' +
                                                        '>Apply</a>' +
                                                '</span></td><td id="' + this.id + '.promotion-status" class="error-msg"></td></tr></table>' +
                                        '</td>' +
                                '</tr>' +
                                '<tr style="DISPLAY: none">' +
                                        '<td colspan="2"><hr></td>' +
                                '</tr>' +
                                '<tr style="DISPLAY: none">' +
                                        '<td colspan="2">' +
						'<span>' +
                                                        '<input type="radio" name="' + this.id + '.paymentType" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onPaymentSelect\',1)" id="' + this.id + '.paymentType-cc" ' + focusClass + ' value="' + gpr.paymentType.CreditCard + '">' + 
							'<b>Credit/Debit Card <img valign="absmiddle" src="images/creditcards.gif">' + 
						'</span>' +
					'<table class="gpr-panel-section">' +
						'<tr><td>Type</td><td>Number</td><td>Expiry Date</td><td>Amount</td></tr>' +
                                                '<tr><td><select id="' + this.id + '.type" disabled>' +
							'<option value="B">Select card</option>' +
							'<option value="V">Visa</option> ' +
							'<option value="M">MasterCard</option> ' +
							'<option value="A">American Express</option> ' +
							'<option value="S">Discover</option> </select>' +
						 '</td>' +
                                                 '<td><input type="text" style="background-color:#d3d3d3" size="20" id="' + this.id + '.number"  '+ focusClass + ' disabled></td>' +
						 '<td colspan="2">' +
						 gpr.monthControl(this.id+".month") +
						 gpr.yearControl(this.id+".year") +
						'</td><td><input type=hidden id="' + this.id + '.amount" value="'+ (this.amount * -1) +'"><span id="' + this.id +'.displayamt">' + gpr.formatCurrency(this.amount * -1) + '</span></td>' +						
						'</tr>' +
				'<tr><td colspan="3"> Card Holder Name </td></tr>' +
				'<tr>' +
								'<td colspan="3">' +
                                        '       <input type="text" style="background-color:#d3d3d3" id="' + this.id + '.name" size="50"  value="" '+ focusClass + ' maxlength="100" disabled>' +
								'</td>' +
				'</tr>' +
                                '</table>' + (mailingAddressId ?        '<input type=checkbox id="' + this.id + '.autofill"  name="autofill" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'fillAddress\', this);" disabled>Same as Mailing Address?' : '') +
				'</td>' +
				 '</tr>' +
				 //'<table class="gpr-panel-section">' +	
                                //new gpr.forms.addresses(this.id + '.address').getHtml() +
				//'</table>'+
				'<tr>' +
					'<td colspan="2" style="DISPLAY: none"><hr></td>' +
				'</tr>' +
				'<tr style="DISPLAY: none">' +
					'<td colspan="2">' +
						'<input type="radio" name="' + this.id + '.paymentType" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onPaymentSelect\',2)"  id="' + this.id + '.paymentType-ch" ' + focusClass + ' value="' + gpr.paymentType.Check + '">' +
						'<b>By Check </b>' +
					'</td>' +
				'</tr>' +
				'<tr style="DISPLAY: none">' +
					'<td colspan="2">' +
						'<center>' +
						'Please send your check of ' + gpr.formatCurrency(this.amount * -1) + ' to the following address. The check should be payable to:' +
							'<br> "CareData Patient Tracking Systems Corporation"' +
							'<br>Attn: GlobalPatientRecord ' +
							' <br>70 West Madison,  Suite 1400 ' +
							' <br>Chicago, Illinois 60602' +
						'</center>' +
					'</td>' +
                                '</tr>' /*+
				'<tr>' +
					'<td><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<input type="radio" name="' + this.id + '.paymentType" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onPaymentSelect\',4)"  id="' + this.id + '.paymentType-pc" ' + focusClass + ' value="' + gpr.paymentType.Promotion + '">' +
						'<b>By Promotion Code </b>' +
					'</td>' +
					'</tr>' +
					'<tr>' +
					'<td><table><tr><td valign="top">' +
						'Promotion Code : ' + 
						'<input type="text" style="background-color:#d3d3d3" name="' + this.id + '.promotionCode" id="' + this.id + '.promotionCode" ' +  focusClass + ' value="" disabled >' +
						'</td><td valign1="top"><span  id="' + this.id + '.applybutton" style="visibility:hidden"  class="dropshadow" valign="middle">' +
							'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onApplyCode\'); return false;"' +
							'>Apply</a>' +
						'</span></td><td id="' + this.id + '.promotion-status" class="error-msg"></td></tr></table>' +
					'</td>' +
                                '</tr>' */
				)  
			return html.join('  ') ;
	};
	
/* Function Added By Nous (Manoj) to enable/diable controls according to selected payment type */	

	this.onPaymentSelect = function(paymentMode)
	{
	
		if (paymentMode == 1)
		{
			document.getElementById(this.id + '.type').disabled = false;
			document.getElementById(this.id + '.number').disabled = false;
			document.getElementById(this.id + '.number').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.month').disabled = false;
			document.getElementById(this.id + '.year').disabled = false;
			document.getElementById(this.id + '.name').disabled = false;
			document.getElementById(this.id + '.name').style.backgroundColor ="#ffffff";
			if (document.getElementById(this.id + '.autofill'))
			{
			document.getElementById(this.id + '.autofill').disabled = false;
			}
			document.getElementById(this.id + '.address.line1').disabled = false;
			document.getElementById(this.id + '.address.line1').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.address.line2').disabled = false;
			document.getElementById(this.id + '.address.line2').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.address.city').disabled = false;
			document.getElementById(this.id + '.address.city').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.address.zip').disabled = false;
			document.getElementById(this.id + '.address.zip').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.address.state').disabled = false;
			document.getElementById(this.id + '.address.country').disabled = false;
			
			document.getElementById(this.id + '.promotionCode').disabled = true;
			document.getElementById(this.id + '.promotionCode').style.backgroundColor = "#d3d3d3";
			
			document.getElementById(this.id + '.applybutton').style.visibility="hidden" ;
			document.getElementById(this.id + '.type').focus();
			
		
		}
		else if (paymentMode == 2)
		{
		
			document.getElementById(this.id + '.type').disabled = true;
			document.getElementById(this.id + '.number').disabled = true;
			document.getElementById(this.id + '.number').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.month').disabled = true;
			document.getElementById(this.id + '.year').disabled = true;
			document.getElementById(this.id + '.name').disabled = true;
			document.getElementById(this.id + '.name').style.backgroundColor = "#d3d3d3";
			if (document.getElementById(this.id + '.autofill'))
			{
			document.getElementById(this.id + '.autofill').disabled = true;
			}
			document.getElementById(this.id + '.address.line1').disabled = true;
			document.getElementById(this.id + '.address.line1').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.line2').disabled = true;
			document.getElementById(this.id + '.address.line2').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.city').disabled = true;
			document.getElementById(this.id + '.address.city').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.zip').disabled = true;
			document.getElementById(this.id + '.address.zip').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.state').disabled = true;
			document.getElementById(this.id + '.address.country').disabled = true;
			
			
			document.getElementById(this.id + '.promotionCode').disabled = true;
			document.getElementById(this.id + '.promotionCode').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.applybutton').style.visibility="hidden" ;
			
			
		}
		else if (paymentMode == 4)
		{
			document.getElementById(this.id + '.type').disabled = true;
			document.getElementById(this.id + '.number').disabled = true;
			document.getElementById(this.id + '.number').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.month').disabled = true;
			document.getElementById(this.id + '.year').disabled = true;
			document.getElementById(this.id + '.name').disabled = true;
			document.getElementById(this.id + '.name').style.backgroundColor = "#d3d3d3";
			if (document.getElementById(this.id + '.autofill'))
			{
				document.getElementById(this.id + '.autofill').disabled = true;
			}
			document.getElementById(this.id + '.address.line1').disabled = true;
			document.getElementById(this.id + '.address.line1').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.line2').disabled = true;
			document.getElementById(this.id + '.address.line2').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.city').disabled = true;
			document.getElementById(this.id + '.address.city').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.zip').disabled = true;
			document.getElementById(this.id + '.address.zip').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.address.state').disabled = true;
			document.getElementById(this.id + '.address.country').disabled = true;
			
			document.getElementById(this.id + '.promotionCode').disabled = false;
			document.getElementById(this.id + '.promotionCode').style.backgroundColor = "#ffffff";
			document.getElementById(this.id + '.applybutton').style.visibility="visible"
			document.getElementById(this.id + '.promotionCode').focus();
		}
	
		//alert(paymentMode);
	}
	
	this.onApplyCode = function()
	{
		var body = 'code=' + encodeURIComponent(document.getElementById(this.id + '.promotionCode').value || ' ');
		new gpr.ajax().post('/promotioncode.aspx', body, gpr.dispatcher.bindEx0(this, 'applyCodeComplete'))

	}
	
	this.applyCodeComplete = function(ajax)
	{
		if ( ajax.error )
		{
			document.getElementById(this.id+'.promotion-status').innerHTML = ajax.error;

		}
		else
		{
			eval(ajax.responseText());
			
			document.getElementById(this.id+'.displayamt').innerHTML=  gpr.data.promotionCode.amount > 0 ? this.amount  + gpr.data.promotionCode.amount : document.getElementById(this.id+'.displayamt').innerHTML;
			document.getElementById(this.id+'.promotion-status').innerHTML = gpr.data.promotionCode.amount > 0 ? 'Discount applied' : ' Error in Promotion Code';
		}
	}
	
	this.getBody = function()
	{
		var paymentType = gpr.getRadioGroupValue(this.id + '.paymentType') || gpr.paymentType.None;
		var cardHolderName = document.getElementById(this.id + '.name').value || '';
		var cardType = document.getElementById(this.id + '.type').value || '0';
		var cardNumber = document.getElementById(this.id + '.number').value || '';
		var expiryMonth = document.getElementById(this.id + '.month').value || '';
		var expiryYear= document.getElementById(this.id + '.year').value || '';
		var amount= document.getElementById(this.id + '.amount').value || '0';
		var promotionCode= document.getElementById(this.id + '.promotionCode').value || ' ';
		
		//Modified by prakash (Comments lines are  modified)
		return ('paymentType=' + paymentType + 
			( paymentType == gpr.paymentType.CreditCard || paymentType == gpr.paymentType.Promotion
				?	('&cardholderName=' + encodeURIComponent(cardHolderName) + 
					(cardType ? '&cardType=' + encodeURIComponent(cardType) : '') +
					(cardNumber ? '&cardNumber=' + encodeURIComponent(cardNumber) : '') +
					(expiryMonth ? '&expiryMonth=' + encodeURIComponent(expiryMonth) : '') +
					(expiryYear ? '&expiryYear=' + encodeURIComponent(expiryYear) : '' ) +
					(amount ? '&amount=' + encodeURIComponent(amount) : '' ) +
					(promotionCode ? '&promotionCode=' + encodeURIComponent(promotionCode) : '' ) //+	'&' + 
					//gpr.registry.get(this.id + '.address').getBody('payment')
					 )
				:	''
			)
		);
	};
}

gpr.forms.address = function(id, address, showCopyAddress)
{
	this.id = id;
	gpr.registry.add(this);
	address = address || {};
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.fillAddress = function()
	{
		var address = gpr.data.patients[gpr.data.currentPatientID].address
		  document.getElementById(this.id + ".id").value = address.id
		  document.getElementById(this.id + ".line1").value = address.line1
		  document.getElementById(this.id + ".line2").value = address.line2
		  document.getElementById(this.id + ".city").value = address.city
		  for(var i=0; i <   document.getElementById(this.id + ".state").options.length; i ++)
		  {
			if(document.getElementById(this.id + ".state").options[i].value == address.state)
			{
				document.getElementById(this.id + ".state").selectedIndex = i;
			}
		  }
		  document.getElementById(this.id + ".country").selectedIndex = 0; /*todo: implement countrylist */
		  document.getElementById(this.id + ".zip").value = address.zip
	}
	
	this.getHtml = function()
	{
		return (
			'<input id="' + this.id + '.id" type="hidden" value="' + address.id + '">' +
			'<tr>' +
				'<td colspan="2">' +
					'<table class="gpr-panel-section">' +
					'<tr><td colspan="3">'+
						(showCopyAddress ? '<span><input type="checkbox" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'fillAddress\', this);"><b>Copy address from ' + gpr.data.user.fullName +'</b></span>' : '')+
						'</td><tr>'+
						'<tr>' +
							'<td><label for="' + this.id + '.line1" >Street Address</label></td>' +
							'<td><label for="' + this.id + '.line2" >Apt/Unit #</label></td>' +
							'<td>' + '</td>' +

						'</tr>' +
						'<tr>' +
							'<td><input type="text" id="' + this.id + '.line1" size="35"  value="' + gpr.htmlString(address.line1) + '" '+ focusClass + ' maxlength="100"></td>' +
							'<td><input type="text" id="' + this.id + '.line2" size="35"  value="' + gpr.htmlString(address.line2) + '" '+ focusClass + ' maxlength="100"></td>' +
						'</tr>' +
					'</table>' +
				'</td>' +
			'</tr>' +
			'<tr>' +
				'<td >' +
					'<table class="gpr-panel-section">' +
						'<tr>' +
							'<td><label for="' + this.id + '.city" >City</label></td>' +
							'<td><label for="' + this.id + '.state" >State</label></td>' +
							'<td><label for="' + this.id + '.zip" >ZipCode</label></td>' +
							'<td><label for="' + this.id + '.country" >Country</label></td>' +
						'</tr>' +
						'<tr>' +
							'<td>' +
								'<input type="text" id="' + this.id + '.city" size="10" value="' + gpr.htmlString(address.city) + '" '+ focusClass + ' maxlength="50">' +
							'</td>' +
							'<td>' + 
								gpr.stateControl(this.id + '.state', address.state) +
							'</td>' +
							'<td>' +
								'<input type="text" id="' + this.id + '.zip" size="10" value="' + gpr.htmlString(address.zip) + '" '+ focusClass + ' maxlength="10">' +
							'</td>' +
							'<td>' + 
								gpr.countryControl(this.id+'.country', address.country) + 
							'</td>' +
						'</tr>' +
					'</table>' +
				'</td>' +
			'</tr>'
		);
	};

	this.getBody = function(prefix)
	{
		var prefix = prefix || 'address';

		var id = document.getElementById(this.id + '.id').value || '0';
		var line1 = gpr.Trim(document.getElementById(this.id + '.line1').value) || '';
		var line2 = gpr.Trim(document.getElementById(this.id + '.line2').value) || '';
		var city = gpr.Trim(document.getElementById(this.id + '.city').value) || '';
		var state = gpr.Trim(document.getElementById(this.id + '.state').value) || '';
		var zip = gpr.Trim(document.getElementById(this.id + '.zip').value) || '';
		var country = gpr.Trim(document.getElementById(this.id + '.country').value) || '';

		return (
			prefix + '-id=' + id + 
			'&' + prefix + '-line1=' + encodeURIComponent(line1) + 
			(line2 ? '&' + prefix + '-line2=' + encodeURIComponent(line2) : '') +
			(city ? '&' + prefix + '-city=' + encodeURIComponent(city) : '') +
			(state ? '&' + prefix + '-state=' + encodeURIComponent(state) : '') +
			(zip ? '&' + prefix + '-zip=' + encodeURIComponent(zip) : '' )+
			(country ? '&' + prefix + '-country=' + encodeURIComponent(country) : ''));
	};
};
	
gpr.forms.addresses = function(id, address, showCopyAddress)
{
        this.id = id;
        gpr.registry.add(this);
        address = address || {};
        var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
        
        this.fillAddress = function()
        {
                var address = gpr.data.patients[gpr.data.currentPatientID].address
                  document.getElementById(this.id + ".line1").value = address.line1
                  document.getElementById(this.id + ".line2").value = address.line2
                  document.getElementById(this.id + ".city").value = address.city
                  for(var i=0; i <   document.getElementById(this.id + ".state").options.length; i ++)
                  {
                        if(document.getElementById(this.id + ".state").options[i].value == address.state)
                        {
                                document.getElementById(this.id + ".state").selectedIndex = i;
                        }
                  }
                  document.getElementById(this.id + ".country").selectedIndex = 0; /*todo: implement countrylist */
                  document.getElementById(this.id + ".zip").value = address.zip
        }
        
        this.getHtml = function()
        {
                return (
                        '<input id="' + this.id + '.id" type="hidden" value="' + gpr.htmlString(address.id) + '">' +
                        '<tr>' +
                                '<td colspan="2">' +
                                        '<table class="gpr-panel-section">' +
                                                '<tr>' +
                                                        '<td><label for="' + this.id + '.line1" >Street Address</label></td>' +
                                                        '<td><label for="' + this.id + '.line2" >Apt/Unit #</label></td>' +
                                                        '<td>' + (showCopyAddress ? '<span><input type="checkbox" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'fillAddress\', this);" disabled><b>Copy address from ' + gpr.data.user.fullName +'</b></span>' : '') + '</td>' +

                                                '</tr>' +
                                                '<tr>' +
                                                        '<td><input style="background-color:#d3d3d3" type="text" id="' + this.id + '.line1" size="35"  value="' + gpr.htmlString(address.line1) + '" '+ focusClass + ' maxlength="100" disabled></td>' +
                                                        '<td><input style="background-color:#d3d3d3" type="text" id="' + this.id + '.line2" size="35"  value="' + gpr.htmlString(address.line2) + '" '+ focusClass + ' maxlength="100" disabled></td>' +
                                                '</tr>' +
                                        '</table>' +
                                '</td>' +
                        '</tr>' +
                        '<tr>' +
                                '<td>' +
                                        '<table class="gpr-panel-section">' +
                                                '<tr>' +
                                                        '<td><label for="' + this.id + '.city" >City</label></td>' +
                                                        '<td><label for="' + this.id + '.state" >State</label></td>' +
                                                        '<td><label for="' + this.id + '.zip" >ZipCode</label></td>' +
                                                        '<td><label for="' + this.id + '.country" >Country</label></td>' +
                                                '</tr>' +
                                                '<tr>' +
                                                        '<td>' +
                                                                '<input style="background-color:#d3d3d3" type="text" id="' + this.id + '.city" size="10" value="' + gpr.htmlString(address.city) + '" '+ focusClass + ' maxlength="50" disabled>' +
                                                        '</td>' +
                                                        '<td>' + 
                                                                gpr.stateControls(this.id + '.state', address.state) +
                                                        '</td>' +
                                                        '<td>' +
                                                                '<input style="background-color:#d3d3d3" type="text" id="' + this.id + '.zip" size="10" value="' + gpr.htmlString(address.zip) + '" '+ focusClass + ' maxlength="10" disabled>' +
                                                        '</td>' +
                                                        '<td>' + 
                                                                gpr.countryControls(this.id+'.country', address.country) + 
                                                        '</td>' +
                                                '</tr>' +
                                        '</table>' +
                                '</td>' +
                        '</tr>'
                );
        };

        this.getBody = function(prefix)
        {
                var prefix = prefix || 'address';

                var id = document.getElementById(this.id + '.id').value || '0';
                var line1 = document.getElementById(this.id + '.line1').value || '';
                var line2 = document.getElementById(this.id + '.line2').value || '';
                var city = document.getElementById(this.id + '.city').value || '';
                var state = document.getElementById(this.id + '.state').value || '';
                var zip = document.getElementById(this.id + '.zip').value || '';
                var country = document.getElementById(this.id + '.country').value || '';

                return (
                        prefix + '-id=' + id + 
                        '&' + prefix + '-line1=' + encodeURIComponent(line1) + 
                        (line2 ? '&' + prefix + '-line2=' + encodeURIComponent(line2) : '') +
                        (city ? '&' + prefix + '-city=' + encodeURIComponent(city) : '') +
                        (state ? '&' + prefix + '-state=' + encodeURIComponent(state) : '') +
                        (zip ? '&' + prefix + '-zip=' + encodeURIComponent(zip) : '' )+
                        (country ? '&' + prefix + '-country=' + encodeURIComponent(country) : ''));
        };
};

gpr.forms.patient = function(id, patient, onSubmit, isNew, onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onClose = onClose;
	
	gpr.registry.add(this);
	patient = patient || {id: 0, gender: gpr.gender.Female,timeStamp:0,address: {}};
	
    var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
		
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	var isNew = patient.id == 0;
	
	this.getHtml = function()
	{
		var PatientID = ( isNew ? 0 : (gpr.data.currentPatientID || gpr.data.patient.id))
		var html = [];
		
		//Below IF Condition added by deepak, Nous 09-Jan-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right" class="text_basic_small">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\',1); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
        
		html.push (
			(isNew ? "<h3>Add a New Member</h3>" : "<h3> " + (cdw?'':gpr.htmlString(patient.firstName)) + "</h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patient.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patient.timeStamp + '">' +
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<table class="gpr-panel">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Personal Information</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<table class="gpr-panel-section" >' +
							'<tr>' +
								'<td width="50">' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.firstName" >First<label></td>' +
								'<td width="10">' +
									'<label for="' + this.id + '.middleName" >Middle</label></td>' +
								'<td width="50">' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.lastName" >Last</label></td>' +
								'<td width="10">' +
									'<label for="' + this.id + '.suffix" >Suffix</label>' +
								'</td>' +
								'<td rowspan="4" valign="top" align="left" height="100%"><table><tr><td>'+
							'<iframe frameborder="0" Id="patientPhotofrm" src ="PatientPhoto.aspx?PatientID=' + PatientID +'&cdw=' + cdw + '"  width="100%"  height="130%">' + '</iframe>' +
							'</td></tr></table><br></td>'+
							'</tr>' +
							'<tr>' +
								'<td>' +
								'	<input type="text" id="' + this.id + '.firstName" size="25"  value="' + gpr.htmlString(patient.firstName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
								'	<input type="text" id="' + this.id + '.middleName" size="5"  value="' + gpr.htmlString(patient.middleName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.lastName" size="25"  value="' + gpr.htmlString(patient.lastName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.suffix" size="5"  value="' + gpr.htmlString(patient.suffix) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
							'<tr><td colspan="4"><table>'+
				new gpr.forms.address(this.id + '.address', patient.address, (patient.address.id  ? false : true)).getHtml() + 
				'</table></td></tr>'+
				'<tr>' +
					'<td colspan="4">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td><label for="' + this.id + '.homephone" >Home Phone</label></td>' +
								'<td><label for="' + this.id + '.workphone" >Work Phone</label></td>' +
									'</tr>' +
							'<tr>' +
								'<td><input type="text" id="' + this.id + '.homephone"  value="' + gpr.htmlString(gpr.formatPhone(patient.homePhone)) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  ' ></td>' + 
								'<td><input type="text" id="' + this.id + '.workphone"  value="' + gpr.htmlString(gpr.formatPhone(patient.workPhone)) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  '>  (###)###-####</td>' +
							'</tr>' +
							'<tr>' +
								'<td><label for="' + this.id + '.cellphone" >Cell Phone</label></td>' +
								'<td><label for="' + this.id + '.fax" >Fax</label></td>' +
							'</tr>' +
							'<tr>' +
								'<td><input type="text" id="' + this.id + '.cellphone"  value="' + gpr.htmlString(gpr.formatPhone(patient.cellPhone)) + '" '+ focusClass + ' maxlength="14" ' + pNformatString +  '></td>' +
								'<td><input type="text" id="' + this.id + '.fax" '+ focusClass + ' value="' + gpr.htmlString(gpr.formatPhone(patient.fax)) + '" ' + pNformatString +  ' maxlength="14"> (###)###-####</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
							'<td  colspan="5"><label for="' + this.id + '.email" >Email Address</label></td>' +
				'</tr>' +
				'<tr>' +
							'<td  colspan="5"><input type="text" id="' + this.id + '.email" size="50"  value="' + gpr.htmlString(patient.email) + '" '+ focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
							'<td class="gpr-panel-caption"  colspan="6">Other Information</td>' +
				'</tr>' +
				'<tr>' +
						'<td  colspan="5" height="100%" width="100">' +
							'<table class="gpr-panel-advanced-info" height="100%" width="100">' +
							'<tr>' +
								'<td><span class="reg-required">*</span><label for="' + this.id + '.dob" >Date Of Birth</label></td>' +
								'<td><label for="' + this.id + '.gender" >Gender</label></td>' +
								'<td><label for="' + this.id + '.father" >Father</label></td>' +
								'<td><label for="' + this.id + '.mother" >Mother</label></td>' +								
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.dob" id="' + this.id + '.dob" size="10" value="' + gpr.htmlString(patient.dob) + '" '+ focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.dob\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
									'<br>(mm/dd/yyyy)' +
								'</td>' +
								'<td>' +
									'<input name="' + this.id + '.gender" id="' + this.id + '.gender-female" type="radio" ' + 
										(patient.gender == gpr.gender.Female ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-male" >Female</label>' +
									'<input name="' + this.id + '.gender" id="' + this.id + '.gender-male" type="radio" ' + 
										(patient.gender == gpr.gender.Male ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-male" >Male</label>' +
									'<br>' +
								'</td>' +
								'<td><input type="text" name="' + this.id + '.fatherName" id="' + this.id + '.fatherName" size="25" value="' + gpr.htmlString(patient.fatherName) + '" '+ focusClass + ' maxlength="100"></td>'+
								'<td><input type="text" name="' + this.id + '.motherName" id="' + this.id + '.motherName" size="25" value="' + gpr.htmlString(patient.motherName) + '" '+ focusClass + ' maxlength="100"></td>'+
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
								//added by venkat , nous 04-may-2007
				'<tr>' +
					'<td>&nbsp;</td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption">OCCUPATIONAL INFORMATION</td>' +
				'</tr>' +
				//added by prakash 14-feb-2008
				'<tr>' +
					'<td>' +
					'<table>' +
					'<tr>' +
						'<td><label for="' + this.id + '.employer" >Employer</label></td>' +
						'<td><label for="' + this.id + '.occupation" >Occupation</label></td>' +
					'</tr>' +
					'<tr>' +
						'<td><input type="text" id="' + this.id + '.employertxt" size="50" value="' + gpr.htmlString(patient.employer) + '" '+ focusClass + ' maxlength="150"></td>' +
						'<td><input type="text" id="' + this.id + '.occupationNaturetxt" size="50" value="' + gpr.htmlString(patient.occupation) + '" '+ focusClass + ' maxlength="50"></td>' +
					'</tr>' +
					'</table>'+
					'</td>' +
				'</tr>' +
				
				
				'<tr>' +
					'<td><label for="' + this.id + '.occupationNatureslbl" >Does Your Work Involve (check all that apply):</label></td>' +
				'</tr>' +
				'<tr>' +
					'<td>');
					this.getOccupationNaturesList(html,PatientID);
				html.push(
					'</td>' +
				'</tr>' +
				
				
				(isNew ? new gpr.forms.payment(this.id + '.payment', gpr.consts.memebershipFee, this.id + '.address').getHtml() : '')+
				'<tr>' +
					'<td><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\', ' + isNew + '); return false;">' +
						'<a href="javascript:void(0)" ' + '> Submit</a></span>' + ' ' 
							+'<span class="dropshadow" id="spanCancel" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a href="javascript:void(0)" ' +'>Cancel</a> </span>'
							+
					'</td>' +
				'</tr>' +
			'</table> ' 
		);
		
		return html.join('');
	};
// added by venkat, nous 04-may-2007
	this.getOccupationNaturesList  = function(html,PatientID)
	{
		html.push('<table width="100%"><tr>')
		var ons = gpr.dictionaries.occupationNatures;
		if (PatientID == "0")
		{ 
			for ( var on = 0; on < ons.length; ++on)
			{
				if (ons[on].active)
				{
					html.push('<td>')
					html.push('<input type="checkbox" id="' + this.id + '.occupationNature.' + ons[on].id + '" ');
					html.push(' value="' + ons[on].id + '" ');
					html.push('>');
					html.push(' <label for="' + this.id + '.occupationNature.' + ons[on].id + '" >');
					html.push(gpr.htmlString(ons[on].name));
					html.push('</label>');
					html.push('</td>')
				}
				if((on+1) % 4 == 0)
				{
					html.push('</tr><tr>')
				}
			}
		}
		else
		{
			for ( var on = 0; on < ons.length; ++on)
			{
				if (ons[on].active)
				{
					html.push('<td>')
					//html.push('<span style="white-space:">');
					html.push('<input type="checkbox" id="' + this.id + '.occupationNature.' + ons[on].id + '" ');
					html.push(' value="' + ons[on].id + '" ');
					if (gpr.data.patients[PatientID].occupationNatureIDs)
					{
						if ( gpr.find(gpr.data.patients[PatientID].occupationNatureIDs, ons[on].id) )
						{
							html.push(' checked ');
						}
					}
					html.push('>');
					html.push(' <label for="' + this.id + '.occupationNature.' + ons[on].id + '" >');
					html.push(gpr.htmlString(ons[on].name));
					html.push('</label>');
					html.push('</td>')
				}
				else
				{
					if ( gpr.data.patients[PatientID].occupationNatureIDs && gpr.find(gpr.data.patients[PatientID].occupationNatureIDs, ons[on].id) )
					{
						html.push('<td>')
						//html.push('<span style="white-space:">');
						html.push('<input type="checkbox" id="' + this.id + '.occupationNature.' + ons[on].id + '" ');
						html.push(' value="' + ons[on].id + '" ');
						html.push(' checked ');
						html.push('>');
						html.push(' <label for="' + this.id + '.occupationNature.' + ons[on].id + '" >');
						html.push(gpr.htmlString(ons[on].name));
						html.push('</label>');
						html.push('</td>')
					}
				}
				if((on+1) % 4 == 0)
				{
					html.push('</tr><tr>')
				}
			}
		}		
		//html.push('</span>');
		html.push('</table>')
	}
	// added by venkat, nous 04-may-2007
	this.getOccupationNatureSelection = function()
	{
		var on = gpr.dictionaries.occupationNatures;
		var natures = [];
		for ( var a = 0; a < on.length; ++a)
		{
			nature = document.getElementById(this.id + '.occupationNature.' + on[a].id)
			if (nature != null && nature.checked )
			{
				natures.push(on[a].id)
			}
		}
	
		return natures;
	}
	this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '0');
		var firstName = gpr.Trim(document.getElementById(this.id + '.firstName').value || '');
		var middleName = gpr.Trim(document.getElementById(this.id + '.middleName').value || '');
		var lastName = gpr.Trim(document.getElementById(this.id + '.lastName').value || '');
		var suffix = gpr.Trim(document.getElementById(this.id + '.suffix').value || '');
		var dob = gpr.Trim(document.getElementById(this.id + '.dob').value || '');
		var gender = document.getElementById(this.id + '.gender-male').checked;
		
		var fatherName = gpr.Trim(document.getElementById(this.id + '.fatherName').value || '');
		var motherName = gpr.Trim(document.getElementById(this.id + '.motherName').value || '');
		//below lines added by prakash for "employer" 14-feb-2008
		var employer = gpr.Trim(document.getElementById(this.id + '.employertxt').value || '');
		//below 2 lines added by venkat for "occupation"
		var occupation = gpr.Trim(document.getElementById(this.id + '.occupationNaturetxt').value || '');
		var occupationNatureIDs = this.getOccupationNatureSelection().join(',');
		
		//var ssn = document.getElementById(this.id + '.ssn').value || '';
		//var title = document.getElementById(this.id + '.title').value || '';
		var	homephone = gpr.Trim(document.getElementById(this.id + '.homephone').value || '');
		var workphone = gpr.Trim(document.getElementById(this.id + '.workphone').value || '');
		var	cellphone = gpr.Trim(document.getElementById(this.id + '.cellphone').value || '');
		var	fax = gpr.Trim(document.getElementById(this.id + '.fax').value || '');
		var	email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'

		if (!firstName)
		{
			alert('Please enter First Name.');
			document.getElementById(this.id + '.firstName').focus();
		}
		else if (!lastName)
		{
			alert('Please enter Last Name.');
			document.getElementById(this.id + '.lastName').focus();
		}
		else if (!dob || dob == NaN )
		{
			alert('Please enter Date of Birth.');
			document.getElementById(this.id + '.dob').focus();
		}
		else if (! gpr.isDate(dob))
		{
			document.getElementById(this.id + '.dob').focus();
		}
		/*else if(fatherName)
		{
			if(fatherName.length > 100)
			{alert('Father Name cannot be greater than 100 Characters.');document.getElementById(this.id + '.fatherName').focus();}
		}
		else if(motherName)		
		{
			if(motherName.length > 100)
			{alert('Mother Name cannot be greater than 100 Characters.');document.getElementById(this.id + '.motherName').focus();}
		}*/
		else
		{
			return (
				'id=' + id + 
				'&firstName=' + encodeURIComponent(firstName) + 
				'&lastName=' + encodeURIComponent(lastName) + 
				(middleName ? '&middleName=' + encodeURIComponent(middleName) : '')+
				(suffix ? '&suffix=' + encodeURIComponent(suffix) : '')+
				'&dob=' + encodeURIComponent(dob) +
				'&gender=' + (gender ? "1" : "0") +
				(fatherName ? '&fatherName=' + encodeURIComponent(fatherName) : '') +
				(motherName ? '&motherName=' + encodeURIComponent(motherName) : '') +
				//below lines added by prakash for "employer" 14-feb-2008
				(employer ? '&employer=' + encodeURIComponent(employer) : '') +	
				//below 2 lines added by venkat for "occupation"
				(occupation ? '&occupation=' + encodeURIComponent(occupation) : '') +						
				(occupationNatureIDs ? '&occupationNatureIDs=' + encodeURIComponent(occupationNatureIDs) : '') +
			//	(ssn ? '&ssn=' + encodeURIComponent(ssn) : '') +
			//	(title ? '&title=' + encodeURIComponent(title) : '')+
				(cellphone ? '&cellphone=' + encodeURIComponent(cellphone) : '') +
				(workphone ? '&workphone=' + encodeURIComponent(workphone) : '') + 
				(homephone ? '&homephone=' + encodeURIComponent(homephone) : '') + 
				(fax ? '&fax=' + encodeURIComponent(fax) : '') +
				(email ? '&email=' + encodeURIComponent(email) : '') +
				'&timeStamp=' + encodeURIComponent(timeStamp) +
				'&' +
				gpr.registry.get(this.id + '.address').getBody() + 
				(isNew ? '&' + gpr.registry.get(this.id + '.payment').getBody() : '')
				 );
		} 
	};
}

gpr.forms.patientLegalDocs = function(id, onEdit,onClose,onAddEditDocuments)
{
	this.id = id;
	this.onEdit = onEdit;
	this.onClose = onClose;
	this.onAddEditDocuments = onAddEditDocuments
	gpr.registry.add(this);
		
	this.getHtml = function(patientID)
	{
			var pld = gpr.data.patientLegalDocs[patientID] ||   null;
			
			if(pld)
			{
				var id = pld.id
				var logdate = pld.logDate;
			}
			else
			{
				var id = 0;
				var logdate = '--';
			}
				
			
			 
			var html = [];
			html.push ( '' +
	 		'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
	 		'Last reviewed on : ' + logdate + 
	 		'<table class="gpr-panel " width="90%">' +
	 		'<tr>' +
	 		'<td class="gpr-panel-caption" colspan1="2">ADVANCED DIRECTIVES ('+ gpr.data.patients[patientID].firstName +')</td>' +
	 		'<td class="gpr-panel-caption" align="right">');
	 		
	 		if (controler.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),2).length != 0)
	 		{
	 		html.push ('<img align="absmiddle" src="images/attach.ico" border="0">');
	 		}
	 		
	 		html.push('<span class="panel-button" > <a href="javascript:void(0)"  id="'+ this.id + '.ViewDoc" '  +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAddEditDocuments\',2,1); return false;"' +
				'>Add/View Documents</a></span>' + '&nbsp;&nbsp;' + '<span class="panel-button" > <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onEdit\','+ id +'); return false;"' +
				'>Edit</a></span></td>' +
	 		'</tr>' );
	 		
	 		if(!pld)
	 		{
	 			html.push('<tr><td colspan="2" align="center">No Information found. Click on "EDIT" button above to update your Advanced Directives </td></tr></table>')
	 			return html.join(' ')

	 		}
	 		if(pld.organDonor)
	 		{
	 		 		
	 			html.push('<tr>' +
	 				'<td width="15%" class="gpr-panel-alternate"> Organ Donor:  </td>' +
	 				'<td class="gpr-panel-alternate"> YES </td></tr>' +
	 				'<tr>' +
	 				'<td class="gpr-panel-alternate">Date Signed:</td>' +
	 				'<td class="gpr-panel-alternate">' +
		 				gpr.htmlString(gpr.Trim(pld.organDonorDate)!= '1/1/0001' ? pld.organDonorDate:'--') +
	 				'</td></tr>' +
	 				'<tr>' +
	 				'<td class="gpr-panel-alternate">Location</td>' +
	 				'<td class="gpr-panel-alternate">' +
		 				gpr.htmlString(gpr.Trim(pld.organDonorLocation)?pld.organDonorLocation:'--') +
	 				'</td></tr>'			)
	 		}
	 		else
	 		{
	 			html.push('<tr>' +
	 				'<td width="15%" class="gpr-panel-alternate"> Organ Donor:  </td>' +
	 				'<td class="gpr-panel-alternate"> NO  </td></tr>')
	 		}

	 		if(pld.mpoa)
	 		{
	 			html.push('<tr>' +
	 				'<td width="15%"> Medical Power Of Attorney:  </td>' +
	 				'<td> YES </td></tr>' +
	 				'<tr>' +
	 				'<td>Date Signed:</td>' +
	 				'<td>' +
		 			gpr.htmlString(gpr.Trim(pld.mpoaDate)!= '1/1/0001'?pld.mpoaDate:'--') +
	 				'</td></tr>' +
	 				'<tr>' +
	 				'<td>Location</td>' +
	 				'<td>' +
		 				gpr.htmlString(gpr.Trim(pld.mpoaLocation) != '1/1/0001'?pld.mpoaLocation:'--') +
	 				'</td></tr>'
	 			)
	 		}
	 		else
	 		{
	 			html.push('<tr>' +
	 				'<td width="15%"> Medical Power Of Attorney:  </td>' +
	 				'<td> NO  </td></tr>')
	 		}
	 		if(pld.livingWill)
	 		{
	 			html.push('<tr>' +
	 				'<td width="15%" class="gpr-panel-alternate"> Living Will:  </td>' +
	 				'<td class="gpr-panel-alternate"> YES </td></tr>' +
	 				'<tr>' +
	 				'<td class="gpr-panel-alternate">Date Signed:</td>' +
	 				'<td class="gpr-panel-alternate" colspan="2">' +
		 			gpr.htmlString(gpr.Trim(pld.livingWillDate)!= '1/1/0001'?pld.livingWillDate:'--') +
	 				'</td></tr>' +
	 				'<tr>' +
	 				'<td class="gpr-panel-alternate">Location</td>' +
	 				'<td class="gpr-panel-alternate">' +
		 				gpr.htmlString(gpr.Trim(pld.livingWillLocation) != '1/1/0001'?pld.livingWillLocation:'--') +
	 				'</td></tr>'
	 			)
	 		}
	 		else
	 		{
	 			html.push('<tr>' +
	 				'<td width="15%" class="gpr-panel-alternate"> Living Will  </td>' +
	 				'<td class="gpr-panel-alternate"> NO  </td></tr>')
	 		}
	 		
	 		html.push('<tr>' +
	 		'<td width="15%" > Attorney Name:  </td>' +
	 		'<td>'+ gpr.htmlString(gpr.Trim(pld.attorneyName)?pld.attorneyName:'--') +' </td></tr>' +
	 		'<tr>' +
	 		'<td >Phone:</td>' +
	 		'<td>' +
		 	gpr.htmlString(gpr.Trim(pld.attorneyPhone)?pld.attorneyPhone:'--') +
	 		'</td></tr>' +
	 		'<tr>' +
	 		'<td>Comments:</td>' +
	 		'<td >' +
		 		gpr.htmlString(gpr.Trim(pld.comments)?pld.comments:'--') +
	 		'</td></tr>'			)	
	 		html.push(
			'</table>' +
			'<div style="width:90%;text-align:center;padding:10px">' +
			'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
				/*'<a href="login.htm">Close</a>'*/ 
				'<a href="javascript:void(0)" ' +'>Close</a>'
				 +
			'</span>' +
			'</div>' )
			
		return html.join('')
	
	}
	
}

gpr.forms.editPatientLegalDocs = function(id, onSubmit,onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onClose = onClose;
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	gpr.registry.add(this);


	this.getBody = function()
	{
	
		var Id = document.getElementById(this.id + ".id").value || '0'
		var patientId = document.getElementById(this.id + ".patientid").value || '0'
		var organDonor = document.getElementById(this.id + ".organdonor-yes").checked || ''
		var organDonorDate = document.getElementById(this.id + ".organDonorDate").value || ''
		var organDonorLocation = document.getElementById(this.id + ".organDonorLocation").value || ''
		var livingWill = document.getElementById(this.id + ".livingWill-yes").checked || ''
		var livingWillDate = document.getElementById(this.id + ".livingWillDate").value || ''
		var livingWillLocation = document.getElementById(this.id + ".livingWillLocation").value || ''
		var mpoa = document.getElementById(this.id + ".mpoa-yes").checked || ''
		var mpoaDate = document.getElementById(this.id + ".mpoaDate").value || ''
		var mpoalocation = document.getElementById(this.id + ".mpoalocation").value || ''
		var attorneyName = document.getElementById(this.id + ".attorneyName").value || ''
		var attorneyPhone = gpr.Trim(document.getElementById(this.id + ".attorneyPhone").value || '');
        var comments = gpr.Trim(document.getElementById(this.id + ".comments").value || '');
        var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
        var logDate = document.getElementById(this.id + ".logDate").value || ''
        
        
       if(logDate == '--')
       {
		logDate = '';
       }
        if(document.getElementById('careDatauserID')) // for AuditLog when it come from CDW Medical History.
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';

		
                //added by deepak nous 19-jan-2007
                if(comments && comments.length > 1000)
                {
                        alert('Comments cannot exceed 1000 characters');
                        document.getElementById(this.id + '.comments').focus();
                }
		return "patientId=" + encodeURIComponent(patientId) +
			   "&organDonor=" + (organDonor ? '1' : '0') +
			   "&organDonorDate=" + encodeURIComponent(organDonorDate)  +
			   "&organDonorLocation=" + encodeURIComponent(organDonorLocation) +
			   "&livingWill=" + (livingWill ? '1': '0') + 
			   "&livingWillDate=" + encodeURIComponent(livingWillDate) +
			   "&livingWillLocation=" + encodeURIComponent(livingWillLocation) +
			   "&mpoa=" + (mpoa ? '1' :'0') +
			   "&mpoaDate=" + encodeURIComponent(mpoaDate) +
			   "&mpoalocation=" + encodeURIComponent(mpoalocation) +
			    "&attorneyName=" + encodeURIComponent(attorneyName) +
			   "&attorneyPhone=" + encodeURIComponent(attorneyPhone) +
	 		   "&comments=" + encodeURIComponent(comments) +
	 		   "&ID=" + encodeURIComponent(Id) +
	 		  ("&CareDataUserID=" + careDatauserID )+
	 		  "&timeStamp=" + encodeURIComponent(timeStamp)+
	 		  "&logDate=" + encodeURIComponent(logDate) 
	 		   
	 		   
	}
	 var cdw = (id.indexOf('showPatientReport') > 0)?true:false;
	
	this.getHtml = function(patientID)
	{
			var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

			var pld = gpr.data.patientLegalDocs[patientID] ||    {id:0, patientID:patientID, eyeColorID:0, maritalStatusID:0, raceID:0,timeStamp:0,logDate:''};
			if(pld)
				var id = pld.id;
			else
				var id = 0;
				
			if(pld)
			{
				var id = pld.id
				var logdate = pld.logDate;
			
			}
			else
			{
				var id = 0;
				var logdate = '';
			}
			
			var html = [];
			var orgdate;
			var mpoDate;
			var LivingDate;
			if(pld.organDonorDate && pld.organDonorDate != '1/1/0001' )
			{
				orgdate = gpr.htmlString(gpr.Trim(pld.organDonorDate));
			}
			else
			{
				orgdate = ''
			}
			
			if(pld.mpoaDate && pld.mpoaDate != '1/1/0001' )
			{
				mpoDate = gpr.htmlString(gpr.Trim(pld.mpoaDate));
			}
			else
			{
				mpoDate = ''
			}
			if(pld.livingWillDate && pld.livingWillDate != '1/1/0001' )
			{
				LivingDate = gpr.htmlString(gpr.Trim(pld.livingWillDate));
			}
			else
			{
				LivingDate = ''
			}
			
			if(cdw == true)
			{
               html.push(
                       '<span style="float:right;">' +
                       '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\',1); return false;">' + 
					   '<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                       '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                       '</span>' +
                       '<table align="center">' +
						'<tr>' +
							'<td classl="gpr-panel-caption" colspan="2">' +
								'<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                            '</td>' +
                        '</tr></table>');
			}
			html.push ( '' +
	 		'<input id="' + this.id + '.id" type="hidden" value="' + id + '">' +
	 		'<input id="' + this.id + '.timeStamp" type="hidden" value="' + pld.timeStamp + '">' +
	 		'<input id="' + this.id + '.patientid" type="hidden" value="' + patientID + '">' +
	 		'<input id="' + this.id + '.logDate" type="hidden" value="' + logdate + '">' +
	 		
	 		'<table class="gpr-panel" width="90%">' +
	 		'<tr>' +
	 		'<td class="gpr-panel-caption" colspan="2">Advanced Directives</td>' +
	 		'</tr>' +
			'<tr>' +
	 		'<td width="15%" class="gpr-panel-alternate"> Organ Donor:  </td>' +
	 		'<td class="gpr-panel-alternate"><input ' + focusClass + ' name="' + this.id + '.organdonor" id="' + this.id + '.organdonor-yes" type="radio" ' + 
				(pld.organDonor ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.organdonor-yes" >YES</label>' +
			'&nbsp;&nbsp;&nbsp;&nbsp;<input name="' + this.id + '.organdonor" id="' + this.id + '.organdonor-no" type="radio" ' + 
				(!pld.organDonor ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.organdonor-no" >NO</label>' +
	 		
	 		 ' </td></tr>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-alternate">Date Signed:</td>' +
	 		'<td class="gpr-panel-alternate">' +
		 	'<input ' + focusClass + ' type="text" id="'+ this.id +'.organDonorDate" value="' + orgdate + '" maxlength="10" >' +
	 		'<a href="#" onclick="showCalendar(\'' + this.id + '.organDonorDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>(mm/dd/yyyy)</td></tr>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-alternate">Location</td>' +
	 		'<td class="gpr-panel-alternate">' +
		 		'<textarea ' + focusClass + ' type="text" id="' +this.id +'.organDonorLocation" cols="50">' + (pld.organDonorLocation || '' )+ '</textarea>' +
	 		'</td></tr>'	+
	 		'<tr>' +
	 		'<td width="15%" >Medical Power Of Attorney:  </td>' +
	 		'<td><input ' + focusClass + ' name="' + this.id + '.mpoa" id="' + this.id + '.mpoa-yes" type="radio" ' + 
				(pld.mpoa ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.mpoa-yes" >YES</label>' +
			'&nbsp;&nbsp;&nbsp;&nbsp;<input name="' + this.id + '.mpoa" id="' + this.id + '.mpoa-no" type="radio" ' + 
				(!pld.mpoa ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.mpoa-no" >NO</label>' +
	 		
	 		 ' </td></tr>' +
	 		'<tr>' +
	 		'<td>Date Signed:</td>' +
	 		'<td >' +
		 	'<input ' + focusClass + ' type="text" id="'+ this.id +'.mpoaDate" value="' + mpoDate + '" maxlength="10" >' +
		 	'<a href="#" onclick="showCalendar(\'' + this.id + '.mpoaDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a> (mm/dd/yyyy)</td></tr>' +
	 		'<tr>' +
	 		'<td >Location</td>' +
	 		'<td >' +
		 		'<textarea ' + focusClass + ' type="text" id="' +this.id +'.mpoaLocation" cols="50">' + (pld.mpoaLocation || '' )+ '</textarea>' +
	 		'</td></tr>'	+
	 		'<tr>' +
	 		'<td width="15%" class="gpr-panel-alternate"> Living Will:  </td>' +
	 		'<td class="gpr-panel-alternate"><input name="' + this.id + '.livingWill" id="' + this.id + '.livingWill-yes" type="radio" ' + 
				(pld.livingWill ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.livingWill-yes" >YES</label>' +
			'&nbsp;&nbsp;&nbsp;&nbsp;<input name="' + this.id + '.livingWill" id="' + this.id + '.livingWill-no" type="radio" ' + 
				(!pld.livingWill ? 'checked' : '' ) + 
			'>' +
			'<label for="' + this.id + '.livingWill-no" >NO</label>' +
	 		
	 		 ' </td></tr>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-alternate">Date Signed:</td>' +
	 		'<td class="gpr-panel-alternate">' +
		 	'<input ' + focusClass + ' type="text" id="'+ this.id +'.livingWillDate" value="' +  LivingDate + '" maxlength="10">' +
	 		'<a href="#" onclick="showCalendar(\'' + this.id + '.livingWillDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a> (mm/dd/yyyy)</td></tr>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-alternate">Location</td>' +
	 		'<td class="gpr-panel-alternate">' +
		 		'<textarea ' + focusClass + ' type="text" id="' +this.id +'.livingWillLocation" cols="50">' + (pld.livingWillLocation || '' )+ '</textarea>' +
	 		'</td></tr>'	+
	 	 		'<tr>' +
	 		'<td width="15%" >Attorney Name  </td>' +
	 		'<td>' +
	 		'<input ' + focusClass + ' type="text" id="'+ this.id +'.attorneyName" value="' + (pld.attorneyName || '') + '" size="50" maxlength="100">' +

	 		 ' </td></tr>' +
	 		'<tr>' +
	 		'<td>Phone:</td>' +
	 		'<td >' +
		 	'<input ' + focusClass + ' type="text" id="'+ this.id +'.attorneyPhone" value="' + (pld.attorneyPhone || '') + '" ' + pNformatString +  ' maxlength="14" > (###)###-####' +
	 		'</td></tr>' +
	 		'<tr>' +
	 		'<td >Comments</td>' +
	 		'<td >' +
		 		'<textarea ' + focusClass + ' type="text" id="' +this.id +'.comments" cols="50">' + (pld.comments || '' )+ '</textarea>' +
	 		'</td></tr>'	+
			'<tr>' +
				'<td colspan="2"><hr></td>' +
			'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2" id="' + this.id + '.submitpanel">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +' > Submit</a></span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a></span>' */
							'<a href="javascript:void(0)" ' +'>Close</a></span>'
							
							+
					'</td>' +
				'</tr>' +
			'</table>')
			
		return html.join('')
	}
		
	
}

//function Added by Nous for patient Documents(for Identifications & Advanced Directives(Legal Documnets))
gpr.forms.patientDocument = function(id,onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
			
		// Add by Nous(Manoj) to get the position for pop-up window

	this.getWindowCenterElements = function(nWidth, nHeight)
	{
	
	var sFeatures
	var nLeft, nTop
	nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth - 15 + 20) 
	nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight - 1 + 60) 
	sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight 
	return sFeatures
	
	}
	
	// Add by Nous(Manoj) to get the center cordinates

	this.getCenterCordinates = function (Sr, Pl, Pw, Dw)
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}
	
	var style = this.getWindowCenterElements(700,635) +  ", menubar=1,status=yes,resizable=yes,scrollbars=no";
	style = '\'' + style + '\''
	
	this.getHtml = function(patientID,patientDocuments,DocumentTypeID,patientLegalDocAttachments)
	{
	
	var html = [];
	
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ (cdw?'Width="100%"':'') +'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
                              var careDatauserID = document.getElementById('careDatauserID').value;
        }
        //changes end

	html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" cellpadding="0" cellspacing="0" width="'+ (cdw?'800':'90%') + '">' +
			 ' <tr>');
			 if (DocumentTypeID == 1)
			 {
				html.push('<td colspan="5" class="gpr-panel-caption">IDENTIFICATIONS - Document List ('+ gpr.data.patients[patientID].firstName +')</td>');
			 }
			 else if(DocumentTypeID == 2)
			 {
				html.push('<td colspan="6" class="gpr-panel-caption">ADVANCED DIRECTIVES - Document List ('+ gpr.data.patients[patientID].firstName +')</td>');
			 }
			 html.push('</tr>');
		if(DocumentTypeID == 1 && patientDocuments.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add documents  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Browse" button select your document and click "Add" button </td></tr>')	
		}
		else if(DocumentTypeID == 2 && patientLegalDocAttachments.length == 0)
		{
		html.push('<tr><td colspan="4" align="center">To add documents  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Browse" button select your document and click "Add" button </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td width="5%" id="' + this.id + '.date" class="panel-column-header">Sl.No</td>'+
					'<td width="13%" id="' + this.id + '.date" class="panel-column-header">' +
						'Date' +
					'</td>' +
					'<td width="20%" id="' + this.id + '.documentTitle" class="panel-column-header">' +
						'Document Title' +
					'</td>' +
					'<td width="25%" id="' + this.id + '.documentName" class="panel-column-header">' +
						'Document Name' +
					'</td>' +
					'<td id="' + this.id + '.documentDescription" class="panel-column-header">' +
						'Description' +
					'</td>');
					if(DocumentTypeID == 2)
					 {
					html.push('<td id="' + this.id + '.documentCategory" class="panel-column-header">' +
						'Category' +
					'</td>');
					 }
				html.push('</tr>' )
		}
		if(DocumentTypeID != 2)
		{
		for( var i = 0; i < patientDocuments.length; ++i)
		{
			var item = patientDocuments[i];
			var slNo = i + 1 ;
			if(item == null) continue;
			html.push(
				'<tr>' +
					'<td valign="top">'+ slNo +'</td>'+
					'<td valign="top">'+
					
						'<a href="#" onclick="window.open(\'PatientDocument/DisplayPatientDocument.aspx?ID='+ item.id + '&typeID=' + DocumentTypeID + '&userID=' + (cdw ? careDatauserID : gpr.data.user.id) + '&userType=' + (cdw ? '1' : '0') + '\' ,null,'+ style + ')"> '+ gpr.htmlString(item.documentDate)+ '</a>' 
					+ '</td>' +
					'<td valign="top">'+ gpr.htmlString(item.documentTitle) + '</td>' + 
					'<td valign="top">'+ gpr.htmlString(item.documentName) + '</td>' + 
					'<td valign="top">'+ gpr.htmlString(item.documentDescription == ''? '--' : item.documentDescription) + '</td>' + 
				'</tr>'
			);
		}
		}
		else if(DocumentTypeID == 2)
		{
			for( var i = 0; i < patientLegalDocAttachments.length; ++i)
			{
				var item = patientLegalDocAttachments[i];
				var slNo = i + 1 ;
				if(item == null) continue;
				html.push(
					'<tr>' +
						'<td valign="top">'+ slNo +'</td>'+
						'<td valign="top">'+
								'<a href="#" onclick="window.open(\'PatientDocument/DisplayPatientDocument.aspx?ID='+ item.id + '&typeID=' + DocumentTypeID + '&userID=' + (cdw ? careDatauserID : gpr.data.user.id) + '&userType=' + (cdw ? '1' : '0') + '\' ,null,'+ style + ')"> '+ gpr.htmlString(item.documentDate)+ '</a>' 
						+ '</td>' +
						'<td valign="top">'+ gpr.htmlString(item.documentTitle) + '</td>' + 
						'<td valign="top">'+ gpr.htmlString(item.documentName) + '</td>' + 
						'<td valign="top">'+ gpr.htmlString(item.documentDescription == ''? '--' : item.documentDescription) + '</td>' + 
						'<td valign="top">'+ gpr.htmlString(item.docCategoryID ? gpr.findID(gpr.dictionaries.documentCategories, item.docCategoryID, {name:''}).name : '') + '</td>' + 
					'</tr>'
				);
		}
		
		}
		
		
		var docType = (DocumentTypeID == 1 && this.id.indexOf('ShowPatientReport')>-1)?6:DocumentTypeID;
		html.push(
			'<tr>'+ 
			'<td colspan="6"  height="345" width="100%" align="left">'+'<BR>'+
			//'<iframe frameborder="0" src ="PatientDocument/AddPatientDocument.aspx?patientID=' + (gpr.data.currentPatientID || gpr.data.patient.id) + '&DocumentTypeID=' + DocumentTypeID  + '"  height="100%"  width="100%">' + '</iframe>' + '</td></tr>'
			'<iframe frameborder="0" src ="PatientDocument/AddPatientDocument.aspx?patientID=' + (gpr.data.currentPatientID || gpr.data.patient.id) + '&DocumentTypeID=' + docType  +  '&UserID='+  (cdw ? careDatauserID : gpr.data.user.id)  +  '&UserType='+  (cdw ? 1 : 0) +'"  height="100%"  width="100%">' + '</iframe>' + '</td></tr>'
		 );
		 
		 html.push(
		 '<tr><td colspan="6" align="center" valign="bottom">'+'<BR>'+
		 '<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
					'<a href="javascript:void(0)" ' +'>Close</a>' +
				'</span></td></tr>' 
		 );
		
		return html.join('') 
	}

};


gpr.forms.patientIdentification = function(id, onEdit,onClose,onAddEditDocuments)
{
	this.id = id;
	this.onEdit = onEdit;
	this.onClose = onClose;
	this.onAddEditDocuments = onAddEditDocuments
	gpr.registry.add(this);

	this.getHtml = function(patientID)
	{
			var pid = gpr.data.patientIdentifications[patientID] ||   null;
			var html = [];
			html.push ( '' +
	 		'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
	 		'<table class="gpr-panel" width="90%">' +
	 		'<tr>' +
	 		'<td class="gpr-panel-caption" colspan="2">IDENTIFICATIONS ('+ gpr.data.patients[patientID].firstName +')</td>' +
	 		'<td class="gpr-panel-caption" align="right">');
	 		if (controler.getDocumentsByType(gpr.data.getCurrentPatientCollection('patientDocuments'),1).length != 0)
	 		{
	 		html.push ('<img align="absmiddle" src="images/attach.ico" border="0">');
	 		}
	 		
	 		html.push ('<span class="panel-button"> <a href="javascript:void(0)" id="'+ this.id + '.ViewDoc" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAddEditDocuments\', 1,1); return false;"' +
				'>Add/View Documents</a></span>' + '&nbsp;&nbsp;' +
	 		'<span class="panel-button" > <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onEdit\', 0); return false;"' +
				'>Edit</a></span></td>' +
	 		'</tr>' );
	 		
	 		if(!pid)
	 		{
	 			html.push('<tr><td colspan="3" align="center">No Information found. Click on "EDIT" button above to update your Identification information </td></tr></table>')
	 			return html.join(' ')

	 		}
	 		
	 		html.push('<tr>' +
	 		'<td width="15%"> Race:  </td>' +
	 		'<td>' +
	 			(gpr.Trim(this.getValFromList(gpr.dictionaries.races, pid.raceID))?this.getValFromList(gpr.dictionaries.races, pid.raceID):'--') +
	 		'</td></tr>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-alternate"> Language:  </td>' +
	 		'<td class="gpr-panel-alternate" colspan="3">' +
	 		
	 			(gpr.Trim(this.getValFromList(gpr.dictionaries.languages, pid.languageID))?this.getValFromList(gpr.dictionaries.languages, pid.languageID):'--') +

	 		'</td></tr>' +
	 		'<tr><td>' +
	 		'Blood Group : ' + 
	 		'</td><td>' +
	 		
	 			(gpr.Trim(this.getValFromList(gpr.dictionaries.bloodTypes, pid.bloodTypeID))?this.getValFromList(gpr.dictionaries.bloodTypes, pid.bloodTypeID):'--') +

	 		'</td></tr>' +
	 		'<tr><td class="gpr-panel-alternate" >' +
	 		
	 		//addded by prakash 13/mar/2008
			//Birth Height1
			'Birth Height : ' +
			'</td><td class="gpr-panel-alternate" colspan="3">' + 
			(pid.birthHeight_Unit == '0' ?(pid.birthHeight == '0'?'--':pid.birthHeight) + ' (ft)' + ' '+ 
					(pid.birthHeight_Decimal == '0' ? '--':pid.birthHeight_Decimal) + ' (inches)': pid.birthHeight +' (cms)') + 
			'</td></tr>' +
	 		'<tr><td >' +
	 		
	 		'Height : ' +
			'</td><td  colspan="3">' + 	
			(pid.height_Unit=='0' ?(pid.height== '0'?'--':pid.height) + ' (ft)' + ' '+ 
					(pid.height_Decimal== '0' ? '--':pid.height_Decimal) + ' (inches)': pid.height +' (cms)') +  
					
			'</td></tr>' +
			
			'<tr><td class="gpr-panel-alternate">' +
			'Birth Weight : ' +
			'</td><td class="gpr-panel-alternate" colspan="3">' + 
			(pid.birthWeight_Unit == '0' ?(pid.birthWeight == '0' ? '--': pid.birthWeight)+ ' (lbs)' + ' ' +  
					(pid.birthWeight_Decimal == '0' ? '--':pid.birthWeight_Decimal) + ' (oz)': pid.birthWeight  +' (kg)') + 
		 	
		 	'</td></tr>' +
	 		
	 		
	 		'<tr><td>' +
	 		'Weight : ' +
			'</td><td>' + 
			(pid.weight_Unit == '0' ?(pid.weight == '0' ? '--': pid.weight)+ ' (lbs)' + ' ' +  
			(pid.weight_Decimal == '0' ? '--':pid.weight_Decimal) + ' (oz)': pid.weight  +' (kg)') + 
		 	
		 	'</td></tr>' +
	 		'<tr><td class="gpr-panel-alternate">' +
			'Eye Color : ' +
			'</td><td class="gpr-panel-alternate" colspan="3">' +
			
			(gpr.Trim(this.getValFromList(gpr.dictionaries.eyeColors, pid.eyeColorID))?this.getValFromList(gpr.dictionaries.eyeColors, pid.eyeColorID):'--')  +
			'</td></tr>' +
	 		'<tr><td>' +
			'Maritial Status : ' +
			'</td><td>'+

	 		(gpr.Trim(this.getValFromList(gpr.dictionaries.maritalStatuses, pid.maritalStatusID))?this.getValFromList(gpr.dictionaries.maritalStatuses, pid.maritalStatusID):'--')  +

		 	'</td></tr>' +
	 		'<tr><td class="gpr-panel-alternate">' +
			'Number of Children : ' +
			'</td><td class="gpr-panel-alternate" colspan="3">' + 
			 (pid.children?pid.children:'--') + // || '--') + 
			'</td></tr>' +
			'<tr><td>' +
			'Comments : ' +
			'</td><td>' +  (pid.comments?pid.comments:'--') + // || '') +
			'</td></tr>' +
			'</table>' +
			'<div style="width:90%;text-align:center;padding:10px">' +
			'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
			 /*'<a href="login.htm">Close</a>'  */
			'<a href="javascript:void(0)" ' + '>Close</a>'
				+
			'</span>' +
			'</div>' )
		return html.join('')
	}
	
	this.getValFromList = function(list, itemID)
	{
		for( i in list)
		{
			if (list[i].id == itemID)
			 {
				return list[i].name
			 }
		}
		return ''
	}
}

gpr.forms.editPatientIdentification = function(id, onSubmit,onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onClose = onClose;
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	gpr.registry.add(this);


	this.getBody = function()
	{
		var Id = document.getElementById(this.id + ".id").value || '0'
		var patientId = document.getElementById(this.id + ".patientID").value || '0'
		var raceId = document.getElementById(this.id + ".raceId").value || '0'
		var languageId = document.getElementById(this.id + ".languageId").value || '0'
		var bloodTypeId = document.getElementById(this.id + ".bloodTypeId").value || '0'
		var eyeColorId = document.getElementById(this.id + ".eyeColorId").value || '0'		
		var height = document.getElementById(this.id + ".height").value || '0'
		//below line is added by venkat, nous 09-May-2007 to get the inches value of height
		var inchheight = document.getElementById(this.id + ".inchheight").value || '0'
		var weight = document.getElementById(this.id + ".weight").value || '0'
		var weight_Decimal = document.getElementById(this.id + ".weight_Decimal").value || '0'
		var children = document.getElementById(this.id + ".children").value || '0'
		var maritalStatusId = document.getElementById(this.id + ".maritalStatusId").value || '0'
        var comments = gpr.Trim(document.getElementById(this.id + ".comments").value || '');
        var birthWeight_Decimal = document.getElementById(this.id + ".birthWeight_Decimal").value || '0'
		var birthHeight_Decimal = document.getElementById(this.id + ".birthHeight_Decimal").value || '0'
        var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
        
        var birthHeight = document.getElementById(this.id + ".birthHeight").value || '0'
		var birthHeightInCms = document.getElementById(this.id + ".birthHeightInCms").value || '0'
		var heightInCms = document.getElementById(this.id + ".heightInCms").value || '0'
		var birthWeight = document.getElementById(this.id + ".birthWeight").value || '0'
        var birthWeightInKg = document.getElementById(this.id + ".birthWeightInKg").value || '0'
        var weightInKg = document.getElementById(this.id + ".weightInKg").value || '0'
        
        var isbirthHightInFeetInch = document.getElementById(this.id + ".isbirthHightInFeetInch")
		var isbirthHightInCms = document.getElementById(this.id + ".isbirthHightInCms")
		var isHightInFeetInch = document.getElementById(this.id + ".isHightInFeetInch")
		var isHightInCms = document.getElementById(this.id + ".isHightInCms")
		var isBirthWeightInlbs = document.getElementById(this.id + ".isBirthWeightInlbs")
		var isWeightInlbs = document.getElementById(this.id + ".isWeightInlbs")
		var isBirthWeightInKgs = document.getElementById(this.id + ".isBirthWeightInKgs")
		var isWeightInKgs = document.getElementById(this.id + ".isWeightInKgs")
		
        var height_Unit,weight_Unit,birthHeight_Unit,birthWeight_Unit 
        
        
        if(isbirthHightInFeetInch.checked)
        {
			birthHeight_Unit='0';
        }
         if(isbirthHightInCms.checked)
        {
			birthHeight_Unit='1';
        }
         if(isHightInFeetInch.checked)
        {
			height_Unit='0'
        }
         if(isHightInCms.checked)
        {
			height_Unit='1'
        }
         if(isBirthWeightInlbs.checked)
        {
			birthWeight_Unit='0'
        }
         if(isBirthWeightInKgs.checked)
        {
			birthWeight_Unit='1'
        }
         if(isWeightInlbs.checked)
        {
			weight_Unit='0'
        }
         if(isWeightInKgs.checked)
        {
			weight_Unit='1'
        }
        
        
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
	
        if(comments && comments.length > 4000)
         {
			alert('Comments cannot exceed more than 4000 characters');
            document.getElementById(this.id + '.comments').focus();
         }
        if (!gpr.forms.CheckForNumber(birthHeight))
        {        
			alert('Please enter valid birth height');
			document.getElementById(this.id + '.birthHeight').focus()
			return false;
        }
        if (!gpr.forms.CheckForNumber(birthHeightInCms))
        {        
			alert('Please enter valid birth height');
			document.getElementById(this.id + '.birthHeightInCms').focus()
			return false;
        }else if(birthHeightInCms > 350 )
        {
			alert('Please enter valid height');
			document.getElementById(this.id + '.birthHeightInCms').focus()
			return false;
        }
        if (!gpr.forms.CheckForNumber(heightInCms))
        {        
			alert('Please enter valid height');
			document.getElementById(this.id + '.heightInCms').focus()
			return false;
        }else if(heightInCms > 350 )
        {
			alert('Please enter valid height');
			document.getElementById(this.id + '.heightInCms').focus()
			return false;
        }
        if (!gpr.forms.CheckForNumeric(birthHeight_Decimal))
        {
			alert('Please enter valid birth height');
			document.getElementById(this.id + '.birthHeight_Decimal').focus()
			return false;
        }
        if (gpr.forms.CheckForNumeric(birthHeight_Decimal) && parseFloat(birthHeight_Decimal) >= 12)
        {
			alert('Please enter valid birth height');
			document.getElementById(this.id + '.birthHeight_Decimal').focus()
			return false;
        }
        
        // below validation added by venkat, nous 10-May-2007
        if (!gpr.forms.CheckForNumber(height))
        {        
			alert('Please enter valid height');
			document.getElementById(this.id + '.height').focus()
			return false;
        }
        if (!gpr.forms.CheckForNumeric(inchheight))
        {
			alert('Please enter valid height');
			document.getElementById(this.id + '.inchheight').focus()
			return false;
        }
        
        if (gpr.forms.CheckForNumeric(inchheight) && parseFloat(inchheight) >= 12)
        {
			alert('Please enter valid height');
			document.getElementById(this.id + '.inchheight').focus()
			return false;
        }
        
         if(isNaN(parseInt(birthWeight)))
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight').focus()
			return false;
        }
        
        if(birthWeight.length > 3 && birthWeight.indexOf(".") == -1)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight').focus()
			return false;
        }
        if(birthWeight.indexOf(".") != -1)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight').focus()
			return false;
        }
        if(isNaN(parseInt(birthWeight_Decimal)))
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight_Decimal').focus()
			return false;
		 }
		if(birthWeight_Decimal.length > 3 && birthWeight_Decimal.indexOf(".") == -1)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight').focus()
			return false;
        }
        if (gpr.forms.CheckForNumeric(birthWeight_Decimal) && parseFloat(birthWeight_Decimal) >= 16)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeight_Decimal').focus()
			return false;
        }
	   if(isNaN(parseInt(weight)))
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight').focus()
			return false;
        }
        if(weight.length > 3 && weight.indexOf(".") == -1)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight').focus()
			return false;
        }
        if(weight.indexOf(".") != -1)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight').focus()
			return false;
        }
        if(isNaN(parseInt(birthWeightInKg)))
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeightInKg').focus()
			return false;
		 }
		if(birthWeightInKg.length > 3 && birthWeightInKg.indexOf(".") == -1)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeightInKg').focus()
			return false;
        }
        if (gpr.forms.CheckForNumeric(birthWeightInKg) && parseFloat(birthWeightInKg) > 99)
        {
			alert('Please enter valid birth weight');
			document.getElementById(this.id + '.birthWeightInKg').focus()
			return false;
        }
		if(isNaN(parseInt(weightInKg)))
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weightInKg').focus()
			return false;
		 }
		if(weightInKg.length > 3 && weightInKg.indexOf(".") == -1)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weightInKg').focus()
			return false;
        }
        if (gpr.forms.CheckForNumeric(weightInKg) && parseFloat(weightInKg) > 99)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weightInKg').focus()
			return false;
        }		
        if(isNaN(parseInt(weight_Decimal)))
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight_Decimal').focus()
			return false;
		 }
		  if(weight_Decimal.length > 3 && weight_Decimal.indexOf(".") == -1)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight_Decimal').focus()
			return false;
        }
         if (gpr.forms.CheckForNumeric(weight_Decimal) && parseFloat(weight_Decimal) >= 16)
        {
			alert('Please enter valid weight');
			document.getElementById(this.id + '.weight_Decimal').focus()
			return false;
        }
        
        if (!gpr.forms.CheckForNumber(children))
        {        
			alert('Please enter valid no.of children');
			document.getElementById(this.id + '.children').focus()
			return false;
        }
        // below line is added by venkat, nous 09-May-2007 to get the height by combining feet and inches
		//height = parseInt(height.toString())+"."+Math.round(parseFloat(inchheight.toString()))
		
		var arr= "patientId=" + encodeURIComponent(patientId) +
			   "&raceId=" + encodeURIComponent(raceId) +
			   "&languageId=" + encodeURIComponent(languageId)  +
			   "&bloodTypeId=" + encodeURIComponent(bloodTypeId) +
			   "&eyeColorId=" + encodeURIComponent(eyeColorId) + 
			   "&height=" + (height_Unit == '0' ? encodeURIComponent(height): encodeURIComponent(heightInCms)) +
			   "&inchheight=" + encodeURIComponent(inchheight) +
			   "&weight=" + (height_Unit == '0' ? encodeURIComponent(weight): encodeURIComponent(weightInKg)) +
			   "&weight_Decimal=" + encodeURIComponent(weight_Decimal) +
			   "&birthHeight=" + (birthWeight_Unit == '0' ? encodeURIComponent(birthHeight): encodeURIComponent(birthHeightInCms)) +
			   "&birthHeight_Decimal=" + encodeURIComponent(birthHeight_Decimal) +
			   "&birthWeight=" + (birthWeight_Unit == '0' ? encodeURIComponent(birthWeight): encodeURIComponent(birthWeightInKg)) + 
			   "&birthWeight_Decimal=" + encodeURIComponent(birthWeight_Decimal) +
			   "&children=" + encodeURIComponent(children) +
			   "&maritalStatusId=" + encodeURIComponent(maritalStatusId) +
	 		   "&comments=" + encodeURIComponent(comments)+ 
	 		   "&id=" + encodeURIComponent(Id) +
	 		   "&timeStamp=" + encodeURIComponent(timeStamp) +
	 		   "&height_Unit="+ encodeURIComponent(height_Unit) +	
			   "&weight_Unit="+ encodeURIComponent(weight_Unit) +	
			   "&birthHeight_Unit="+ encodeURIComponent(birthHeight_Unit) +	
			   "&birthWeight_Unit="+ encodeURIComponent(birthWeight_Unit) +	 		    
	 		   "&CareDataUserID=" + careDatauserID 
	 		   
		
		return "patientId=" + encodeURIComponent(patientId) +
			   "&raceId=" + encodeURIComponent(raceId) +
			   "&languageId=" + encodeURIComponent(languageId)  +
			   "&bloodTypeId=" + encodeURIComponent(bloodTypeId) +
			   "&eyeColorId=" + encodeURIComponent(eyeColorId) + 
			   "&height=" + (height_Unit == '0' ? encodeURIComponent(height): encodeURIComponent(heightInCms)) +
			   "&inchheight=" + encodeURIComponent(inchheight) +
			   "&weight=" + (weight_Unit == '0' ? encodeURIComponent(weight): encodeURIComponent(weightInKg)) +
			   "&weight_Decimal=" + encodeURIComponent(weight_Decimal) +
			   "&birthHeight=" + (birthHeight_Unit == '0' ? encodeURIComponent(birthHeight): encodeURIComponent(birthHeightInCms)) +
			   "&birthHeight_Decimal=" + encodeURIComponent(birthHeight_Decimal) +
			   "&birthWeight=" + (birthWeight_Unit == '0' ? encodeURIComponent(birthWeight): encodeURIComponent(birthWeightInKg)) + 
			   "&birthWeight_Decimal=" + encodeURIComponent(birthWeight_Decimal) +
			   "&children=" + encodeURIComponent(children) +
			   "&maritalStatusId=" + encodeURIComponent(maritalStatusId) +
	 		   "&comments=" + encodeURIComponent(comments)+ 
	 		   "&id=" + encodeURIComponent(Id) +
	 		   "&timeStamp=" + encodeURIComponent(timeStamp) +
	 		   "&height_Unit="+ encodeURIComponent(height_Unit) +	
			   "&weight_Unit="+ encodeURIComponent(weight_Unit) +	
			   "&birthHeight_Unit="+ encodeURIComponent(birthHeight_Unit) +	
			   "&birthWeight_Unit="+ encodeURIComponent(birthWeight_Unit) +	 		    
	 		   "&CareDataUserID=" + careDatauserID 
	 		   
	 		   	 		   
	}
	
	this.onActiveSelect = function(obj)
	{
		var txtBirthFeet,txtBirthInch,txtBirthCms,lblBirthfeet,lblBirthinches,lblBirthcms;
		txtBirthFeet = document.getElementById(this.id + '.birthHeight');
		txtBirthInch = document.getElementById(this.id + '.birthHeight_Decimal');
		txtBirthCms = document.getElementById(this.id + '.birthHeightInCms');
		lblBirthfeet = document.getElementById(this.id + '.Birthfeet');
		lblBirthinches = document.getElementById(this.id + '.Birthinches');
		lblBirthcms = document.getElementById(this.id + '.Birthcms');
			var txtFeet,txtInch,txtCms,lblfeet,lblinches,lblcms;
		txtFeet = document.getElementById(this.id + '.height');
		txtInch = document.getElementById(this.id + '.inchheight');
		txtCms = document.getElementById(this.id + '.heightInCms');
		lblfeet = document.getElementById(this.id + '.feet');
		lblinches = document.getElementById(this.id + '.inches');
		lblcms = document.getElementById(this.id + '.cms');
			var txtWeight,txtWeightDecimal,txtWeightInKg,lblLbs,lblOz,lblKg
		txtWeight = document.getElementById(this.id + '.weight');
		txtWeightDecimal = document.getElementById(this.id + '.weight_Decimal');
		txtWeightInKg = document.getElementById(this.id + '.weightInKg');
		lblLbs = document.getElementById(this.id + '.lbs');
		lblOz = document.getElementById(this.id + '.oz');
		lblKg = document.getElementById(this.id + '.kg');
			var txtBirthWeight,txtBirthWeightDecimal,txtBirthWeightInKg,lblBirthLbs,lblBirthOz,lblBirthKg
		txtBirthWeight = document.getElementById(this.id + '.birthWeight');
		txtBirthWeightDecimal = document.getElementById(this.id + '.birthWeight_Decimal');
		txtBirthWeightInKg = document.getElementById(this.id + '.birthWeightInKg');
		lblBirthLbs = document.getElementById(this.id + '.birthLbs');
		lblBirthOz = document.getElementById(this.id + '.birthOz');
		lblBirthKg = document.getElementById(this.id + '.birthKg');
		
		if(obj=="isbirthHightInFeetInch")
		{
			txtBirthCms.value='';txtBirthCms.disabled = true;txtBirthFeet.disabled = false;txtBirthInch.disabled = false;lblBirthfeet.disabled = false;lblBirthinches.disabled = false;lblBirthcms.disabled = true;			
		}
		else if(obj=="isbirthHightInCms")
		{
			txtBirthFeet.value='';txtBirthInch.value='';txtBirthFeet.disabled = true;txtBirthInch.disabled = true;txtBirthCms.disabled = false;lblBirthfeet.disabled = true;lblBirthinches.disabled = true;lblBirthcms.disabled = false;
		}
		if(obj=="isHightInFeetInch")
		{
			txtCms.value='';
			txtCms.disabled = true;
			txtFeet.disabled = false;
			txtInch.disabled = false;
			lblfeet.disabled = false;
			lblinches.disabled = false;
			lblcms.disabled = true;			
		}
		else if(obj=="isHightInCms")
		{
			txtFeet.value='';
			txtInch.value='';
			txtFeet.disabled = true;
			txtInch.disabled = true;
			txtCms.disabled = false;
			lblfeet.disabled = true;
			lblinches.disabled = true;
			lblcms.disabled = false;
		}else if(obj=="isWeightInlbs")
		{
			txtWeightInKg.value='';
			txtWeightInKg.disabled = true;
			txtWeight.disabled = false;
			txtWeightDecimal.disabled = false;
			lblLbs.disabled = false;
			lblOz.disabled = false;
			lblKg.disabled = true;			
		}
		else if(obj=="isWeightInKgs")
		{
			txtWeight.value='';
			txtWeightDecimal.value='';
			txtWeightInKg.disabled = false;
			txtWeight.disabled = true;
			txtWeightDecimal.disabled = true;
			lblLbs.disabled = true;
			lblOz.disabled = true;
			lblKg.disabled = false;	
		}else if(obj=="isBirthWeightInlbs")
		{
			txtBirthWeightInKg.value='';
			txtBirthWeightInKg.disabled = true;
			txtBirthWeight.disabled = false;
			txtBirthWeightDecimal.disabled = false;
			lblBirthLbs.disabled = false;
			lblBirthOz.disabled = false;
			lblBirthKg.disabled = true;			
		}else if(obj=="isBirthWeightInKgs")
		{
			txtBirthWeight.value='';
			txtBirthWeightDecimal.value='';
			txtBirthWeightInKg.disabled = false;
			txtBirthWeight.disabled = true;
			txtBirthWeightDecimal.disabled = true;
			lblBirthLbs.disabled = true;
			lblBirthOz.disabled = true;
			lblBirthKg.disabled = false;	
		}
	}
	
	
	this.getHtml = function(patientID)
	{
			//debugger;
			var pid = gpr.data.patientIdentifications[patientID] ||    {id :0,patientID:patientID, eyeColorID:0, maritalStatusID:0, raceID:0,timeStamp:0 };
			var html = [];
			if(pid.id == 0)
			{
				var id = pid.id
				pid.birthHeight_Unit=0;
				pid.height_Unit=0;
				pid.birthWeight_Unit =0;
				pid.weight_Unit=0;
			}
			else
			{
				var id = patientID
			}	
				
			// below 2 lines added by venkat, nous 09-May-2007 to split the height into two fields
			/*var splitheight = [];
			if(pid.height != null)
			splitheight =  pid.height.toString().split("."); */
		//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center"' + (cdw?'width="100%"':'') + '>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
			html.push ( '' +
	 		'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
	 		'<input id="' + this.id + '.timeStamp" type="hidden" value="' + pid.timeStamp + '">' +
	 		'<input id="' + this.id + '.id" type="hidden" value="' + id + '">' +
	 		'<table class="gpr-panel" '+ (cdw?'Width="800"':'width="90%"') +'>' +
	 		'<tr>' +
	 		'<td class="gpr-panel-caption" colspan="2">IDENTIFICATIONS</td>' +
	 		'</tr>' +
	 		'<tr>' +
	 		'<td width="20%"> Race :</td>' +
	 		'<td>' )
	 		gpr.getList(html, gpr.dictionaries.races, pid.raceID, this.id + ".raceId") 
	 		html.push('</td></tr>' +
	 		'<tr>' +
	 		'<td width="20%"> Language:  </td>' +
	 		'<td>' )
	 		
	 		gpr.getList(html, gpr.dictionaries.languages, pid.languageID, this.id +".languageId") 

	 		html.push('</td></tr>' +
	 		'<tr><td>' +
	 		'Blood Group : ' + 
	 		'</td><td>' )
	 		
	 		gpr.getList(html, gpr.dictionaries.bloodTypes, pid.bloodTypeID, this.id +".bloodTypeId") 
	 		
			html.push('</td></tr>' +
	 		'<tr><td>' +
			'Birth Height : ' +
			'</td><td>' + 
			// added by prakash 12-mar-2008
			'<input name="' + this.id + '.birthHightMeasurements" id="' + this.id + '.isbirthHightInFeetInch" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isbirthHightInFeetInch\')"  ' + 
										(pid.birthHeight_Unit == '0' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input type="text" name="'+ this.id + '.birthHeight" value="'+ (pid.birthHeight_Unit == '0' ?(pid.birthHeight || ''):'') +'" '+ focusClass +' maxlength="2" size="1" '+
										(pid.birthHeight_Unit == '0' ? '' : 'disabled' ) + ' >' +
			'<span id="' + this.id	+ '.Birthfeet"' + (pid.birthHeight_Unit == '0' ? '' : 'disabled' ) + ' >(feet)</span>' +
			'<input type="text" name="'+ this.id + '.birthHeight_Decimal" value="'+ (pid.birthHeight_Unit == '0' ?(pid.birthHeight_Decimal || ''):'') +'" '+ focusClass +' maxlength="4" size="5" '+
										(pid.birthHeight_Unit == '0' ? '' : 'disabled' ) + '>' + 
			'<span id="' + this.id	+ '.Birthinches"' + (pid.birthHeight_Unit == '0' ? '' : 'disabled' ) + ' >(inches)</span>' +
										 
			'&nbsp;&nbsp;<input name="' + this.id + '.birthHightMeasurements" id="' + this.id + '.isbirthHightInCms" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isbirthHightInCms\')"  ' + 
										(pid.birthHeight_Unit == '1' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input type="text" name="'+ this.id + '.birthHeightInCms" value="'+ (pid.birthHeight_Unit == '1' ?(pid.birthHeight || ''):'') +'" '+ focusClass +' maxlength="6" size="5" ' +
										(pid.birthHeight_Unit == '0' ? 'disabled' : '' ) + '> ' +
			'<span id="' + this.id	+ '.Birthcms"' + (pid.birthHeight_Unit == '0' ? 'disabled' : '' ) + ' >(cms)</span>' +
			'</td></tr>' );
			
			html.push('</tr>' +
	 		'<tr><td>' +
			'Height : ' +
			'</td><td>' + 
			//// below line is modified by venkat, nous 09-May-2007 to enter feet of height
			'<input name="' + this.id + '.HightMeasurements" id="' + this.id + '.isHightInFeetInch" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isHightInFeetInch\')"  ' + 
										(pid.height_Unit == '0' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input type="text" name="'+ this.id + '.height" value="'+ (pid.height_Unit == '0' ?(pid.height || ''):'') +'" '+ focusClass +' maxlength="2" size="1"' +
										(pid.height_Unit == '0' ? '' : 'disabled' ) + ' >' +
			'<span id="' + this.id	+ '.feet"' + (pid.height_Unit == '0' ? '' : 'disabled' ) + ' >(feet)</span>' +
			'<input type="text" name="'+ this.id + '.inchheight" value="'+ (pid.height_Unit == '0' ?(pid.height_Decimal || ''):'') +'" '+ focusClass +' maxlength="4" size="5"' +
										(pid.height_Unit == '0' ? '' : 'disabled' ) + '>' + 
			'<span id="' + this.id	+ '.inches"' + (pid.height_Unit == '0' ? '' : 'disabled' ) + ' >(inches)</span>' +
			'&nbsp;&nbsp;<input name="' + this.id + '.HightMeasurements" id="' + this.id + '.isHightInCms" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isHightInCms\')"  ' + 
										(pid.height_Unit == '1' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input type="text" name="'+ this.id + '.heightInCms" value="'+ (pid.height_Unit == '1' ?(pid.height || ''):'') +'" '+ focusClass +' maxlength="6" size="5" ' +
										(pid.height_Unit == '0' ? 'disabled' : '' ) + '> ' +
			'<span id="' + this.id	+ '.cms"' + (pid.height_Unit == '0' ? 'disabled' : '' ) + ' >(cms)</span>' +
			'</td></tr>' );
			
			
			html.push('<tr><td>' +
			//Birth Weight5
			'Birth Weight : ' +
			'</td><td>' + 
			'<input name="' + this.id + '.birthWeightMeasurements" id="' + this.id + '.isBirthWeightInlbs" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isBirthWeightInlbs\')"  ' + 
										(pid.birthWeight_Unit == '0' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input  type="text" name="' + this.id + '.birthWeight" value="'+ (pid.birthWeight_Unit == '0' ?(pid.birthWeight || ''):'') +'" '+ focusClass +' maxlength="4" size="3" '+ 
										(pid.birthWeight_Unit == '0' ? '' : 'disabled' ) + ' >' +
			'<span id="' + this.id	+ '.birthLbs"' + (pid.birthWeight_Unit == '0' ? '' : 'disabled' ) + ' >(lbs)</span>' +' '+
			'<input  type="text" name="' + this.id + '.birthWeight_Decimal" value="'+ (pid.birthWeight_Unit == '0' ?(pid.birthWeight_Decimal || ''):'') +'" '+ focusClass +' maxlength="4" size="3" ' +
		 								(pid.birthWeight_Unit == '0' ? '' : 'disabled' ) + ' >' +
		 	'<span id="' + this.id	+ '.birthOz"' + (pid.birthWeight_Unit == '0' ? '' : 'disabled' ) + ' >(oz)</span>' +' '+
		 	'&nbsp;&nbsp;<input name="' + this.id + '.birthWeightMeasurements" id="' + this.id + '.isBirthWeightInKgs" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isBirthWeightInKgs\')"  ' + 
										(pid.birthWeight_Unit == '1' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
		 	'<input type="text" name="'+ this.id + '.birthWeightInKg" value="'+ (pid.birthWeight_Unit == '1' ?(pid.birthWeight || ''):'') +'" '+ focusClass +' maxlength="5" size="5" ' +
										(pid.birthWeight_Unit == '0' ? 'disabled' : '' ) + '> ' +
			'<span id="' + this.id	+ '.birthKg"' + (pid.birthWeight_Unit == '0' ? 'disabled' : '' ) + ' >(kg)</span>' +
		 	
		 	
		 	
		 	
		 	
		 	'</td></tr>' );
		 	
		 	
	 		html.push('<tr><td>' +
			'Weight : ' +
			'</td><td>' + 
			'<input name="' + this.id + '.weightMeasurements" id="' + this.id + '.isWeightInlbs" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isWeightInlbs\')"  ' + 
										(pid.weight_Unit == '0' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
			'<input  type="text" name="' + this.id + '.weight" value="'+ (pid.weight_Unit == '0' ?(pid.weight || ''):'') +'" '+ focusClass +' maxlength="4" size="3"' + 
									(pid.weight_Unit == '0' ? '' : 'disabled' ) + ' >' +
			'<span id="' + this.id	+ '.lbs"' + (pid.weight_Unit == '0' ? '' : 'disabled' ) + ' >(lbs)</span>' +' '+
			'<input  type="text" name="' + this.id + '.weight_Decimal" value="'+ (pid.weight_Unit == '0' ?(pid.weight_Decimal || ''):'') +'" '+ focusClass +' maxlength="4" size="3"' +
									(pid.weight_Unit == '0' ? '' : 'disabled' ) + ' >' +
			'<span id="' + this.id	+ '.oz"' + (pid.weight_Unit == '0' ? '' : 'disabled' ) + ' >(oz)</span>' +' '+
			'&nbsp;&nbsp;<input name="' + this.id + '.weightMeasurements" id="' + this.id + '.isWeightInKgs" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',\'isWeightInKgs\')"  ' + 
										(pid.weight_Unit == '1' ? 'checked' : '' ) + '>&nbsp;&nbsp;' +
		 	'<input type="text" name="'+ this.id + '.weightInKg" value="'+ (pid.weight_Unit == '1' ?(pid.weight || ''):'') +'" '+ focusClass +' maxlength="5" size="5" ' +
										(pid.weight_Unit == '0' ? 'disabled' : '' ) + '> ' +
			'<span id="' + this.id	+ '.kg"' + (pid.weight_Unit == '0' ? 'disabled' : '' ) + ' >(kg)</span>' +
		 	
			
			
		 	'</td></tr>' +
	 		'<tr><td>' +
			'Eye Color : ' +
			'</td><td>' )
			
			gpr.getList(html, gpr.dictionaries.eyeColors, pid.eyeColorID, this.id +".eyeColorId") 

 		
	 		html.push('</td></tr>' +
	 		'<tr><td>' +
			'Maritial Status : ' +
			'</td><td>')
	 		
	 		gpr.getList(html, gpr.dictionaries.maritalStatuses, pid.maritalStatusID, this.id +".maritalStatusId") 

		 	html.push('</td></tr>' +
	 		'<tr><td>' +
			'Number of Children : ' +
			'</td><td>' + 
			'<input  type="text" name="' + this.id + '.children" value="'+ (pid.children | '') + '" '+ focusClass +' size="2" maxlength="2">' +
			'</td></tr>' +
			'<tr><td  valign="top">' +
			'Comments : ' +
			'</td><td>' + 
			'<textarea  name="' + this.id + '.comments" '+ focusClass +' maxlength="1000" rows="4" cols="30">' + (pid.comments || '') +'</textarea>' +
			'</td></tr>' +
			'<tr>' +
				'<td colspan="2"><hr></td>' +
			'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2" id="' + this.id + '.submitpanel">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +
							' > Submit</a></span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
							/*'<a href="login.htm">Close</a></span>'*/
							'<a href="javascript:void(0)" '+'>Close</a></span>' 
							+
					'</td>' +
				'</tr>' +
			'</table>')
			
		return html.join('')
	}
		
	
}

gpr.forms.patientImmunizations = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientImmunizations)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="2" class="gpr-panel-caption">IMMUNIZATIONS ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Immunization</a></span></td></tr>' 

		);
		
		if(patientImmunizations.length == 0)
		{
			html.push('<tr><td colspan="3" align="center">To add current or past immunization record  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Immunization" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'immunization" class="panel-column-header" onclick=sortTable(event,1) type="String">' +
						'Immunization' +
					'</td>' +
					'<td id="' + this.id + '.mostRecentDate" class="panel-column-header" onclick=sortTable(event,2) type="Date">' +
						'Immunization Date' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientImmunizations.length; ++i)
		{
			var item = patientImmunizations[i];
			html.push(
				'<tr>' +
					'<td width="50%">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +

						(gpr.Trim(gpr.htmlString(item.immunizationID ? gpr.findID(gpr.dictionaries.immunizations, item.immunizationID, {name:''}).name : item.immunizationName))?gpr.htmlString(item.immunizationID ? gpr.findID(gpr.dictionaries.immunizations, item.immunizationID, {name:''}).name : item.immunizationName):'--') +
					'</a></td>' +
					'<td>' +
						(gpr.Trim((gpr.isNullDate(item.immunizationDate) ? '' : gpr.htmlString(item.immunizationDate)))?(gpr.isNullDate(item.immunizationDate) ? '' : gpr.htmlString(item.immunizationDate)):'--') +
					'</td>' +
					'<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
							/*'<a href="login.htm">Close</a>'*/
							'<a href="javascript:void(0)" ' + '>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientImmunization = function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

        //Below line Added by Deepak, Nous 09-Jan-2007
        var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.getHtml = function(patientID, patientImmunization)
	{
		patientImmunization = patientImmunization || {id:0, patientID:patientID,timeStamp:0};
		var isNew = patientImmunization.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientImmunization.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
		var html = [];

	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink"  href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end

		html.push(
			(isNew ? "<h3>Add an Immunization</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientImmunization.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientImmunization.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientImmunization.patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Immunization</td>' +
					'<td class="gpr-panel-caption" align="right">'+ deleteHtml +'</td>' +

				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.immunizationID" >Select from the list<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>'
		);

		this.getImmunizationList(html, patientImmunization);		

		html.push(
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.immunizationName" >Other Immunization<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.immunizationName" style="width:100%"  value="' + gpr.htmlString(patientImmunization.immunizationName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span><label for="' + this.id + '.immunizationDate" >Immunization Date<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.immunizationDate" id="' + this.id + '.immunizationDate" value="' + (gpr.isNullDate(patientImmunization.immunizationDate) ? '' : gpr.htmlString(patientImmunization.immunizationDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.immunizationDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr valign="top">' +
								'<td>' +
									'<label for="' + this.id + '.providerID" >Provider where you got this immunization<label>' +
								'</td>' +
								'<td colspan="3">' +
									gpr.getProvidersList(this.id + '.providerID', patientImmunization.providerID) +
									'(If the provider is not listed, enter the provider\'s name below)' +
								'</td>' +
							'<tr><td>' +
									'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<input type="text" id="' + this.id + '.providerName" size="79" value="' + gpr.htmlString(patientImmunization.providerName) + '"  ' + focusClass + ' maxlength="100">' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<textarea id="' + this.id + '.comments" cols="60"  ' + focusClass + ' maxlength="2000">' +
										gpr.htmlString(patientImmunization.comments) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'
		);
			
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '0');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value);
		var immunizationID = gpr.Trim(document.getElementById(this.id + '.immunizationID').value || '');
        //modified by deepak nous - to take only the id or the name
        var immunizationName = (!immunizationID)? gpr.Trim(document.getElementById(this.id + '.immunizationName').value || '') : '';
		var immunizationDate = gpr.Trim(document.getElementById(this.id + '.immunizationDate').value || '');
		var	providerID = gpr.Trim(document.getElementById(this.id + '.providerID').value || '');
        var providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';
		var	comments = gpr.Trim(document.getElementById(this.id + '.comments').value || '');
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'

		if ( !immunizationID && !immunizationName)
		{
			alert('Please select Immunization.');
			document.getElementById(this.id + '.immunizationID').focus();
		}
		else if(!immunizationDate)
		{
			alert('Please enter a immunization date');
			document.getElementById(this.id + '.immunizationDate').focus();
		}
		else if (!gpr.isDate(immunizationDate))
		{
			document.getElementById(this.id + '.immunizationDate').focus();
		}
		else if (new Date(immunizationDate) < new Date(gpr.data.patients[patientID].dob))
		{
				alert('Immunization Date can not be less than  Birth Date!');
				document.getElementById(this.id + '.immunizationDate').focus();
		}
		else if(comments && comments.length > 2000)
		{
			alert('Comments cannot exceed more than 2000 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		/*else if ( ! providerID && ! providerName )
		{
			alert('Please select a Provider from the list or enter the name of the provider if you dont find the provider in the list.');
		}*/
		else
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(immunizationID ? '&immunizationID=' + immunizationID : '' )+
				(immunizationName ? '&immunizationName=' + encodeURIComponent(immunizationName) : '' )+
				(immunizationDate ? '&immunizationDate=' + encodeURIComponent(immunizationDate) : '') +
				(providerID ? '&providerID=' + providerID : '') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '') + 
				'&timeStamp=' + encodeURIComponent(timeStamp) +
				('&CareDataUserID=' + careDatauserID )
			);
		} 
	};

	this.getImmunizationList = function(html, patientImmunization)
	{
		html.push(
			'<select id="' + this.id + '.immunizationID" ' + focusClass + '>' +
				'<option value=""></option>'
		);
		
		var im = gpr.dictionaries.immunizations;

		for ( var i = 0; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientImmunization.immunizationID )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push(gpr.htmlString(im[i].name));
			html.push('</option>');
			
		}
		
		html.push('</select>');
	};
};

gpr.forms.patientContacts = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientContacts)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">EMERGENCY CONTACTS('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right" ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Contact</a></span></td></tr>' 

		);
		
		if(patientContacts.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add an Emergency contact  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Contact" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + '.name" class="panel-column-header">' +
						'Name' +
					'</td>' +
					'<td id="' + this.id + '.relationship" class="panel-column-header">' +
						'Relationship' +
					'</td>' +
					'<td id="' + this.id + '.phone" class="panel-column-header">' +
						'Phone' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientContacts.length; ++i)
		{
			var item = patientContacts[i];
			html.push(
				'<tr>' +
					'<td width="50%">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +

						(gpr.Trim(gpr.htmlString((item.firstName || '')  + ' ' + (item.lastName || '')))?gpr.htmlString((item.firstName || '')  + ' ' + (item.lastName || '')):'--') +
					'</a></td>' +
					'<td>' +
						(gpr.Trim(gpr.htmlString(item.relationshipID ? gpr.findID(gpr.dictionaries.relationships, item.relationshipID, {name:''}).name : ''))?gpr.htmlString(item.relationshipID ? gpr.findID(gpr.dictionaries.relationships, item.relationshipID, {name:''}).name : ''):'--') +
					'</td>' +
					'<td>' +
						(gpr.Trim((item.homePhone ?  gpr.htmlString(item.homePhone + ' (Home)') : '' )  + (item.cellPhone ?  '<br>' + gpr.htmlString(item.cellPhone + ' (Cell)') : '') + (item.workPhone ? '<br>' + gpr.htmlString(item.workPhone + ' (Work)') : ''))?(item.homePhone ?  gpr.htmlString(item.homePhone + ' (Home)') : '' )  + (item.cellPhone ?  '<br>' + gpr.htmlString(item.cellPhone + ' (Cell)') : '') + (item.workPhone ? '<br>' + gpr.htmlString(item.workPhone + ' (Work)') : ''):'--')  +
					'</td>' +					
					'<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>'*/
							'<a href="javascript:void(0)" ' +'>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientContact = function(id,onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

	this.getHtml = function(patientID, pp)
	{
		pp = pp || {id:0, patientID:patientID,timeStamp:0};
		var isNew = pp.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
			' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  pp.id + ',' + patientID  + '); return false;"' +
		'>Delete this Record?</a></span>'
		//var disabled = pp.provider.careDataID == 0 ? '' : 'disabled';

		var html = [];
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ (cdw?'Width="100%"':'') +'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" align="center" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
		html.push(
			(isNew ? "<h3>Add Emergency Contact</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + pp.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + pp.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + pp.patientID + '">' +
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="'+ ((cdw)?'800':'90%') +'">' + //90%
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Contact</td>' +
					'<td class="gpr-panel-caption" align="right">'+ deleteHtml +'</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"><span class="reg-required">*</span></td><td style="padding-left:0px;width:100px">First Name</td>' +
				'<td><input type="text" name="' + this.id + '.firstName" maxlength="50" value="' + (pp.firstName || '') + '" '+  focusClass + ' style="width:50%"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"></td><td style="padding-left:0px;width:100px">Last Name</td>' +
				'<td><input type="text" name="' + this.id + '.lastName" maxlength="50" value="' + (pp.lastName || '') + '" '+  focusClass + ' style="width:50%"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">Address</td>' +
				'<td><input type="text" name="' + this.id + '.line1" value="' + (pp.line1 || '') + '" ' +  focusClass + ' style="width:50%" maxlength="100"></td>' +
				'</tr>' +
				'<tr>' +
				'<td colspan="2">&nbsp;</td>' +
				'<td><input type="text" name="' + this.id + '.line2" value="' + (pp.line2 || '') + '" '  +  focusClass + ' style="width:50%" maxlength="100"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">City</td>' +
				'<td><input type="text" name="' + this.id + '.city" value="' + (pp.city || '') + '" ' +  focusClass + ' style="width:50%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">State</td>' +
				'<td>'+ gpr.stateControl(this.id + '.state', pp.state) +'</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">Zip</td>' +
				'<td><input type="text" name="' + this.id + '.zip" maxlength="50" value="' + (pp.zip || '') + '" '  +  focusClass + ' style="width:50%"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"></td><td style="padding-left:0px;width:100px">Home Phone</td>' +
				'<td><input type="text" name="' + this.id + '.homePhone" value="' + (pp.homePhone || '') + '" ' +  focusClass + ' style="width:50%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"></td><td style="padding-left:0px;width:100px">Work Phone</td>' +
				'<td><input type="text" name="' + this.id + '.workPhone" value="' + (pp.workPhone || '') + '" ' +  focusClass + ' style="width:50%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"></td><td style="padding-left:0px;width:100px">Cell Phone</td>' +
				'<td><input type="text" name="' + this.id + '.cellphone" value="' + (pp.cellPhone || '') + '" ' +  focusClass + ' style="width:50%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"><span class="reg-required"></span></td><td style="padding-left:0px;width:100px">Pager</td>' +
				'<td><input type="text" name="' + this.id + '.pager" value="' + (pp.pager || '') + '" ' +  focusClass + ' style="width:50%" maxlength="14" ' + pNformatString +  ' > (###)###-####</td>' +
				'</tr>' +

				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">Fax</td>' +
				'<td><input type="text" name="' + this.id + '.fax" value="' + (pp.fax || '') + '" '  +  focusClass + ' style="width:50%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">Email</td>' +
				'<td><input type="text" maxlength="50" name="' + this.id + '.email" value="' + (pp.email || '') + '" '  +  focusClass + ' style="width:50%"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;width:100px">Relationship</td>' +
				'<td>')
		 		gpr.getList(html, gpr.dictionaries.relationships, pp.relationshipID, this.id + ".relationshipID") 
				html.push('</td>' +
				'</tr>' +
				'<tr><td colspan="3"><hr></td></tr>' +
				'<tr>' +
					'<td align="center" colspan="3">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
				)
			return html.join(' ')
		
	}
	
	this.getBody = function()
	{
		
		var ID = gpr.Trim(document.getElementById(this.id + '.ID').value || '0');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value || '0');
		var firstName = gpr.Trim(document.getElementById(this.id + '.firstName').value);
		var lastName = gpr.Trim(document.getElementById(this.id + '.lastName').value || '');
		var line1 = gpr.Trim(document.getElementById(this.id + '.line1').value || '');
		var line2 = gpr.Trim(document.getElementById(this.id + '.line2').value || '');
		var relationshipID = gpr.Trim(document.getElementById(this.id + '.relationshipID').value || '');
		var city = gpr.Trim(document.getElementById(this.id + '.city').value || '');
 		var state = gpr.Trim(document.getElementById(this.id + '.state').value || '');
		var zip = gpr.Trim(document.getElementById(this.id + '.zip').value || '');
		var homePhone = gpr.Trim(document.getElementById(this.id + '.homephone').value || '');
		var workPhone = gpr.Trim(document.getElementById(this.id + '.workphone').value || '');
		var cellPhone = gpr.Trim(document.getElementById(this.id + '.cellphone').value || '');
		var pager = gpr.Trim(document.getElementById(this.id + '.pager').value || '');

		var	fax = gpr.Trim(document.getElementById(this.id + '.fax').value || '');
		var	email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
		
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		 
		//Below lines added by manoj for Audit log
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';

		if ( !firstName)
		{
			alert('Please enter the first name ');
			document.getElementById(this.id + '.firstName').focus();
		}
		/*else if (!lastName)
		{
			alert('Please enter the last name ');
			document.getElementById(this.id + '.lastName').focus();
		}
		else if (!phone)
		{
			alert('Please enter the phone number');
			document.getElementById(this.id + '.phone').focus();
		}
		else if(phone && phone.length != 13)
		{
			alert('Please enter a valid phone number');
			document.getElementById(this.id + '.phone').focus();
		}*/
		/*
		else if ( !homePhone)
		{
			alert('Please enter the home phone number ');
			document.getElementById(this.id + '.homephone').focus();
		}*/
		else if(homePhone && homePhone.length != 13)
		{
			alert('Please enter a valid home phone number');
			document.getElementById(this.id + '.homephone').focus();
		}
		/*
		else if ( !workPhone)
		{
			alert('Please enter the work phone number ');
			document.getElementById(this.id + '.workphone').focus();
		} */
		else if(workPhone && workPhone.length != 13)
		{
			alert('Please enter a valid work phone number');
			document.getElementById(this.id + '.workphone').focus();
		}
		/*
		else if ( !cellPhone)
		{
			alert('Please enter the cell phone number ');
			document.getElementById(this.id + '.cellphone').focus();
		}*/
		else if(cellPhone && cellPhone.length != 13)
		{
			alert('Please enter a valid cell phone number');
			document.getElementById(this.id + '.cellphone').focus();
		}
		/*else if ( ! gpr.Trim(pager))
		{
			alert('Please enter the pager number ');
			document.getElementById(this.id + '.pager').focus();
		}*/
		else 
		{
			return ( 
				'id=' + ID +
				'&patientID=' + patientID +
				(firstName ? '&firstName=' + encodeURIComponent(firstName) : '' )+
				(lastName ? '&lastName=' + encodeURIComponent(lastName) : '' )+
				(relationshipID ? '&relationshipID=' + encodeURIComponent(relationshipID) : '') +
				(line1 ? '&line1=' + encodeURIComponent(line1) : '') +
				(line2 ? '&line2=' + encodeURIComponent(line2) : '') +
				(city ? '&city=' + encodeURIComponent(city) : '') +
				(state ? '&state=' + encodeURIComponent(state) : '') +
				(zip ? '&zip=' + encodeURIComponent(zip) : '' ) +
				(homePhone ? '&homephone=' + encodeURIComponent(homePhone) : '' ) +
				(workPhone ? '&workphone=' + encodeURIComponent(workPhone) : '' ) +
				(cellPhone ? '&cellPhone=' + encodeURIComponent(cellPhone) : '' ) +
				(pager ? '&pager=' + encodeURIComponent(pager) : '' ) +
				(fax ? '&fax=' + encodeURIComponent(fax) : '' ) +
				(email ? '&email=' + encodeURIComponent(email) : '' ) +
				('&CareDataUserID=' + careDatauserID )+
				'&timeStamp=' + encodeURIComponent(timeStamp)
				);
		} 

		
	}
	
}
//Patient Journals

gpr.forms.patientJournals = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);


	this.getHtml = function(patientID, patientJournals)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="75%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">Diary/Personal Journal ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Journal </a></span></td></tr>' 

		);
		
		if(patientJournals.length == 0)
		{
			html.push('<tr><td colspan="3" align="center">To add Diary/Personal Journal for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Journal" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'date" class="panel-column-header">' +
						'Date' +
					'</td>' +
					'<td id="' + this.id + 'time" class="panel-column-header">' +
						'Time' +
					'</td>' +
					'<td id="' + this.id + 'journal" class="panel-column-header" width="50%">' +
						'Notes' +
					'</td>' +
					'<td class="panel-column-header" width="20%">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = patientJournals.length - 1; i >= 0 ; --i)
		{
			var item = patientJournals[i];
			var notes;
			
			if ( gpr.htmlString(gpr.Trim(item.journalNote)).length > 47 )
			{
				notes = gpr.htmlString(item.journalNote).substring(0,47)+'...';
			}
			else
			{
				notes = gpr.htmlString(gpr.Trim(item.journalNote)?item.journalNote:'--')
			}
						
			if(item == null) continue;
			html.push(
				'<tr>' +
					'<td>' +
						gpr.htmlString(gpr.Trim(item.journalDate)?item.journalDate:'--') +
					'</td>' +
										
					'<td>' +
					gpr.htmlString(gpr.Trim(item.journalTime) ? gpr.findID(gpr.dictionaries.timeSlots,item.journalTime, {slot:''}).slot : '--')
						 +
					'</td>' +

					'<td>' +
						notes +
					'</a></td>' +
					'<td style="padding-top:2px;"  align="center" >' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;" >' +
							'<a href="javascript:void(0)" ' + '>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
		/*+ *(
		'<br><small>TODO:<ul>' +
			'<li>add some default width to the table' +
			'<li>fix Add  New and Edit buttons' +
			'<li>add edit date column' +
			'<li>implement column sorting' +
		'</ul></small>');*/
		}
	};

gpr.forms.patientJournal = function(id, onSubmit, onCancel, onDelete)
{
	
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);
	
		
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	


	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" ';	
	
	this.getHtml = function(patientID, patientJournal)
	{
		patientJournal = patientJournal || {id:0, patientID:patientID,timeStamp:0};
		var isNew = patientJournal.id == 0;
		/*var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientJournal.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>' */

		var html = [];
		html.push(
			(isNew ? "<h3>Add a Diary/Personal Journal</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientJournal.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientJournal.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientJournal.patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
	'<table class="gpr-panel" width="90%">' +
		'<tr>' +
			'<td class="gpr-panel-caption">Journal</td>' +
			'<td  class="gpr-panel-caption" align="right" >' + /*deleteHtml*/'' + '</td>' +
		'</tr>' +
		'<tr>'+
			'<td colspan="2">' +
				'<table class="gpr-panel-section" width="100%">' +
					'<tr>' +
						'<td width="10%" >' +'<span class="reg-required">*</span>'+
							'<label for="' + this.id + '.journalDate" >Date<label>' +
						'</td>' +
						'<td>' +
							'<input type="text" id="'+this.id+ '.journalDate" name="'+this.id+'.journalDate" value="' + (gpr.isNullDate(patientJournal.journalDate) ? month + "/" + day + "/" + year : gpr.htmlString(patientJournal.journalDate)) + '" ' + focusClass + ' maxlength="10">' +
							
							'<a href="#" onclick="showCalendar(\'' + this.id + '.journalDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' + 
						' (mm/dd/yyyy) </td>' + 
					'</tr>' +
					'<tr>' +
					'<td>' +
					'<span class="reg-required">*</span>'+
					 '<label for="' + this.id + '.journalTime" >Time<label>' + '</td>' +
						'<td>'
						);

		this.getTimeSlotList(html, patientJournal);		

		html.push(
			 
			 	  	'</td>' +
					'</tr>' +
					'<tr>' +
						'<td  valign="top">' +
						'<span class="reg-required">&nbsp;</span>'+
						 '<label for="' + this.id + '.journalNote"> Notes<label>' + '</td>' +
						'<td>' + '<textarea id="' + this.id + '.journalNote" cols="55" rows="6"  ' + focusClass + ' maxlength="4000">' +
								gpr.htmlString(patientJournal.journalNote)
								+ '</textarea>' +
						'</td>' +
					'</tr>' +
				'</table>' +
			'</td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="2"><hr></td>' +
		'</tr>' +
		'<tr>' +
			'<td align="center" colspan="2">' +
				'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
					'<a href="javascript:void(0)" ' + '>Submit</a>' +
				'</span>' +
				'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
					'<a href="javascript:void(0)" ' +'>Cancel</a>' +
				'</span>' +
			'</td>' +
		'</tr>' +
	'</table>'

		);
	
		return html.join(''); 
		}	
	

this.getBody = function()
	{
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '0');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value);
		
		var journalDate = gpr.Trim(document.getElementById(this.id + '.journalDate').value || '');
		var journalTime = gpr.Trim(document.getElementById(this.id + '.journalTime').value || '');
		var journalNote = gpr.Trim(document.getElementById(this.id + '.journalNote').value || '');
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		
		if ( !journalDate)
		{
			document.getElementById(this.id + '.journalDate').focus();
			alert('Please enter journal date.');
		}
		else if(!gpr.isDate(journalDate))
		{
			document.getElementById(this.id + '.journalDate').focus();
			alert('Please enter a valid journal date.');
		}
		else if ( !journalTime)
		{
			document.getElementById(this.id + '.journalTime').focus();
			alert('Please enter Journal Time');
		}		
		else if (journalNote && journalNote.length > 4000)
		{
			document.getElementById(this.id + '.journalNote').focus();
			alert('Note cannot be more than 4000 characters.');
		}
		else
		{		
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(journalDate  ? '&journalDate=' + encodeURIComponent(journalDate ):'') +
				(journalTime ? '&timeSlotID=' + encodeURIComponent(journalTime):'') +
				(journalNote ? '&journalNote=' + encodeURIComponent(journalNote):'')+
				('&CareDataUserID=' + careDatauserID )+
				'&timeStamp=' + encodeURIComponent(timeStamp) 
			);
		}
		
	};
	
	this.getTimeSlotList = function(html, patientJournal)
	{
		html.push(
			'<select id="' + this.id + '.journalTime" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectTimeSlot\', this); return false;">' +
				'<option value=""></option>'
		);
		
		var im = gpr.dictionaries.timeSlots;	
		
		for ( var i = 1; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientJournal.journalTime )
			{
				html.push(' selected ');
			}
			else if (!patientJournal.journalTime && im[i].slot == '09:00 AM')
			{
				html.push(' selected ');
			}
			
			html.push('>')
			html.push(gpr.htmlString(im[i].slot));
			html.push('</option>');
		}
		
		html.push('</select>');
	};
	
	};

this.onSelectTimeSlot = function(select)
	{
		if ( ! select.options[select.selectedIndex].value )
		{
			select.selectedIndex = 0;
		}
	}


//END OF Patient Journals



//Begin Patient 


gpr.forms.patientReminders=function(id, onChange,onClose)
{

this.id = id;
this.onChange = onChange;
this.onClose = onClose;
gpr.registry.add(this);


	this.getHtml = function(patientID, patientReminders)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="4" class="gpr-panel-caption" width="85%">Reminders ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Reminder </a></span></td></tr>' 

		);
		
		if(patientReminders.length == 0)
		{
			html.push('<tr><td colspan="5" align="center">To add Reminders for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Reminder" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'date" class="panel-column-header">' +
						'Date' +
					'</td>' +
					'<td id="' + this.id + 'Desc" class="panel-column-header">' +
						'Description' +
					'</td>' +
					'<td id="' + this.id + 'SetBy" class="panel-column-header">' +
						'Set By' +
					'</td>' +
					'<td id="' + this.id + 'Frequency" class="panel-column-header">' +
						'Frequency' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = patientReminders.length - 1; i >= 0 ; --i)
		{
			var item = patientReminders[i];
			var description;
			var SetBy;
			var Frequency;
			Frequency = '';
				
			if ( gpr.htmlString(gpr.Trim(item.description)).length > 47 )
			{
				description = gpr.htmlString(item.description).substring(0,47)+'...';
			}
			else
			{
				description = gpr.htmlString(item.description);
				description = gpr.Trim(description)?description:'--';
			}
			if (item.reminderType == 1)
			{
				SetBy = gpr.Trim(gpr.data.user.fullName)?gpr.data.user.fullName:'--';
			}
			else if(item.reminderType == 2)
			{
				SetBy = 'Provider';
			}
			else if (item.reminderType == 3)
			{
				SetBy = 'System';
			}
			if(item.frequencyMonth == 0)
			{
				Frequency = 'Only Once';
			}
			else
			{
				Frequency = gpr.htmlString(gpr.findID(gpr.dictionaries.monthFrequency,item.frequencyMonth,{name:''}).name)+'/'
				//+ gpr.htmlString(gpr.findID(gpr.dictionaries.yearFrequency,item.frequencyYear,{name:''}).name);
				
				if(item.frequencyYear == 0)
				{
				Frequency = Frequency + 'Every Year'
				}
				else
				{
				Frequency = Frequency  +  gpr.htmlString(gpr.findID(gpr.dictionaries.yearFrequency,item.frequencyYear,{name:''}).name);
				}
				
				
				Frequency = gpr.Trim(Frequency)?Frequency:'--';
			}
					
			if(item == null) continue;
			html.push(
				'<tr>' +
					'<td class="' + (item.active == true?  '' : 'gpr-disable-row' ) + '">'+
						gpr.htmlString(gpr.Trim(item.reminderDate)?item.reminderDate:'--') +
					'</td>' +
					'<td class="' + (item.active == true ?  '' : 'gpr-disable-row' ) + '">'+
						description +
					'</td>'+
					'<td class="' + (item.active == true ?  '' : 'gpr-disable-row' ) + '">'+
						SetBy + 
					'</td>'+
					'<td class="' + (item.active == true ?  '' : 'gpr-disable-row' ) + '">' +
					gpr.htmlString(Frequency) +
					'</td>' +
					'<td style="padding-top:2px;"  align="center" >' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\',1); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
	
		return html.join('') 
		/*+ *(
		'<br><small>TODO:<ul>' +
			'<li>add some default width to the table' +
			'<li>fix Add  New and Edit buttons' +
			'<li>add edit date column' +
			'<li>implement column sorting' +
		'</ul></small>');*/
		}

};

gpr.forms.patientReminder  = function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" ';	
	
	this.getHtml = function(patientID, patientReminder)
	{
	
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	
	
		patientReminder = patientReminder || {id:0, patientID:patientID,timeStamp:0};
		var isNew = patientReminder.id == 0;
		/*var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientReminder.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'*/

		var html = [];
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ (cdw?'width="100%"':'') +'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
		html.push(
			(isNew ? "<h3>Add a Reminder</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientReminder.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientReminder.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientReminder.patientID + '">' +
			'<input id="' + this.id + '.frequencyMonthValue" type="hidden" value="' + patientReminder.frequencyMonth + '">' +
			'<input id="' + this.id + '.frequencyYearValue" type="hidden" value="' + patientReminder.frequencyYear + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
	'<table class="gpr-panel" width="80%">' +
		'<tr>' +
			'<td class="gpr-panel-caption">Reminder</td>' +
			'<td  class="gpr-panel-caption" align="right" >' +/* deleteHtml +*/ '</td>' +
		'</tr>' +
		'<tr>'+
			'<td colspan="2">' +
				'<table class="gpr-panel-section" ' + (cdw?'width="800"':'width="100%"') + '>' +
					'<tr>' +
						'<td width="18%" >' +'<span class="reg-required">*</span>'+
							'<label for="' + this.id + '.reminderDate" >Reminder Date<label>' +
						'</td>' +
						'<td>' +
							'<input type="text" id="'+this.id+ '.reminderDate" name="'+this.id+'.reminderDate" value="' + (gpr.isNullDate(patientReminder.reminderDate) ? month + "/" + day + "/" + year : gpr.htmlString(patientReminder.reminderDate)) + '" ' + focusClass + ' maxlength="10">' +
							
							'<a href="#" onclick="showCalendar(\'' + this.id + '.reminderDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' + 
						' (mm/dd/yyyy) </td>' + 
					'</tr>' +
					'<tr>' +
						'<td  valign="top">' +
						'<span class="reg-required">&nbsp;</span>'+
						 '<label for="' + this.id + '.description"> Description<label>' + '</td>' +
						'<td>' + '<textarea id="' + this.id + '.description" cols="55" rows="6"  ' + focusClass + ' maxlength="100">' +
								gpr.htmlString(patientReminder.description)
								+ '</textarea>' +
						'</td>' +
					'</tr>' );
					if(cdw == true)
					{
						var provRemID = '';
						for(i in gpr.data.patientProviders)
						{
							if(gpr.data.patientProviders[i].patientID == patientID)
							{
								provRemID = gpr.data.patientProviders[i].provider.id;
								break;
							}
						}

						html.push('<tr>' +
							'<td><label for="'+ this.id + '.providerID"><span class="reg-required">*</span>Select Provider</label></td>' +
							'<td valign="top"> '+
							gpr.getProvidersList(this.id + '.providerID', provRemID, 'gpr.dispatcher.call(\'' + this.id + '\', \'onChangeProvider\', this); return false;') +
							'</td></tr>');
					}
				if(isNew)
				{
					html.push('<tr>'+
						'<td>'+'<span class="reg-required">*</span>'+
						'<label for="' + this.id + '.frequency" >Frequency<label>' +				
						'</td>'+
						'<td>'+
						'<table><tr><td width="75%">'+
						'<label for="' + this.id + '.month" >Month<label>'+
						'</td><td>'+
						'<label for="' + this.id + '.year" >Year<label>'+
						'</td></tr></table>'+
						'</td>'+
						'</tr>'+
					'<tr><td></td>'+
					'<td><table><tr><td>');
					this.getMonthFrequencies(html,patientReminder);
					html.push('</td><td>');
						this.getYearFrequencies(html,patientReminder);
					html.push('</td></tr></table></td></tr>');
				
				}	
				else
				{
				
						html.push('<tr><td>&nbsp;'+
						'InActive' + 
						'</td><td align="left">'+
						'<input type="checkbox" id="' + this.id + '.isActive"' + 
								(patientReminder.active == true ? '' : 'checked') +  '	>'	+
						'</td>'+
						'</tr>');
				
				}
						html.push('<tr>' +
							'<td colspan="2"><hr></td>' +
						'</tr>' +
						'<tr>' +
							'<td align="center" colspan="2">' +
								'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
								'<a href="javascript:void(0)" ' +'>Submit</a>' +
								'</span>' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
				'</span>' +
			'</td>' +
		'</tr>' +
	'</table>'
		);
	
		return html.join(''); 
		}	
		
	this.getBody = function()
	{
			var currentTime = new Date()
			var month = currentTime.getMonth() + 1
			var day = currentTime.getDate()
			var year = currentTime.getFullYear()
			var CurrentDate = month+'/'+day+'/'+year;
			var frequencyMonth;
			var frequencyYear;
		var id = gpr.Trim(document.getElementById(this.id + '.id').value || '0');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value);
		var reminderDate = gpr.Trim(document.getElementById(this.id + '.reminderDate').value || '');
		//modified by deepak, Nous, to check if the reminder is modified/updated by the patient or the provider, 1: patient, 2: provider
		var reminderType = (this.id.indexOf('ShowPatientReport') > 0)?2:1;
		var provider; 
		if(reminderType == 2){provider = document.getElementById(this.id + '.providerID').value;}
		
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';	
		 var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		
		if(id == 0)
		{
		 frequencyMonth =gpr.Trim(document.getElementById(this.id + '.frequencyMonth').value || ''); 
		 frequencyYear = gpr.Trim(document.getElementById(this.id + '.frequencyYear').value || '');
		}
		else
		{
		 frequencyMonth =gpr.Trim(document.getElementById(this.id + '.frequencyMonthValue').value || ''); 
		 frequencyYear = gpr.Trim(document.getElementById(this.id + '.frequencyYearValue').value || '');
		}
		
		var description = gpr.Trim(document.getElementById(this.id + '.description').value || '');
		if (id != 0)
		{
		var isActive = document.getElementById(this.id + '.isActive').checked ? 'false' : 'true'
		}
		else
		{
		var isActive = 'true';
		}
		
				
		if (!reminderDate)
		{
			document.getElementById(this.id + '.reminderDate').focus();
			alert('Please enter reminder date.');
		}
		else if(!gpr.isDate(reminderDate))
		{
			document.getElementById(this.id + '.reminderDate').focus();
		}
		/*else if (new Date(reminderDate) < new Date(CurrentDate))
		{
			document.getElementById(this.id + '.reminderDate').focus();
			alert("Reminder date should be greater than or equal to today's date");
		}*/
		else if (description && description.length > 100)
		{
			document.getElementById(this.id + '.description').focus();
			alert('Description cannot be more than 100 characters.');
		}
		//added by deepak, nous, to validate provider
		else if(reminderType == 2 && gpr.Trim(document.getElementById(this.id + '.providerID').value) == '')
		{
			document.getElementById(this.id + '.providerID').focus();
			alert('Please select a provider.');
		}
		else
		{	
		var temp;
			temp = (reminderType == 2)?provider:gpr.data.user.id;	
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(reminderDate  ? '&reminderDate=' + encodeURIComponent(reminderDate ):'') +
				(frequencyMonth ? '&frequencyMonth=' + encodeURIComponent(frequencyMonth):'') +
				(frequencyYear ? '&frequencyYear=' + encodeURIComponent(frequencyYear):'')+
				(description ? '&description=' + encodeURIComponent(description):'')+
				'&isActive='+ encodeURIComponent(isActive)+
				'&userID='+ temp + 
				'&reminderType=' + reminderType  +
				('&CareDataUserID=' + careDatauserID )+
				'&timeStamp=' + encodeURIComponent(timeStamp) 
			);
		}
		
	}
	
		
	this.getMonthFrequencies = function(html, patientReminder)
	{
		html.push(
		'<select id="' + this.id + '.frequencyMonth" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectFrequency\', this); return false;">' 
		);
		
		var im = gpr.dictionaries.monthFrequency;	
		
		for ( var i = 0; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientReminder.frequencyMonth)
			{
				html.push(' selected ');
			}
			else if (!patientReminder.frequencyMonth && im[i].id == 0)
			{
				html.push(' selected ');
			}
			
			html.push('>')
			html.push(gpr.htmlString(im[i].name));
			html.push('</option>');
		}
		
		html.push('</select>');
	};
	
	
	this.getYearFrequencies = function(html, patientReminder)
	{
		html.push(
		'<select id="' + this.id + '.frequencyYear" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectFrequency\', this); return false;">' 
		
		);
		
		var im = gpr.dictionaries.yearFrequency;	
		
		for ( var i = 0; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientReminder.frequencyYear)
			{
				html.push(' selected ');
			}
			else if (!patientReminder.frequencyYear && im[i].id == 0)
			{
				html.push(' selected ');
			}
			
			html.push('>')
			html.push(gpr.htmlString(im[i].name));
			html.push('</option>');
		}
		
		html.push('</select>');
	};
	
};

this.onSelectFrequency = function(select)
	{
		if ( ! select.options[select.selectedIndex].value )
		{
			select.selectedIndex = 0;
		}
	}

//End Patient Reminders
gpr.forms.patientInsurances = function(id, onChange,onClose,onViewDocuments)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	this.onViewDocuments = onViewDocuments;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientInsurances,patientDocuments)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">INSURANCE('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right" ><span class="panel-button"> <a href="javascript:void(0)"  id="'+ this.id + '.AddIns"' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Insurance</a></span></td></tr>' 

		);
		
		if(patientInsurances.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add an Insurance record  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Insurance" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + '.name" class="panel-column-header">' +
						'Name' +
					'</td>' +
					'<td id="' + this.id + '.policyno" class="panel-column-header">' +
						'GroupID' +
					'</td>' +
					'<td id="' + this.id + '.phone" class="panel-column-header">' +
						'Member ID' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientInsurances.length; ++i)
		{
			var item = patientInsurances[i];
			html.push(
				'<tr>' +
					'<td width="45%">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +

						gpr.htmlString(gpr.Trim(item.companyName) || '--' ) +
					'</a></td>' +
					'<td>' +
						gpr.htmlString(gpr.Trim(item.groupID) || '--' ) +
					'</td>' +
					'<td>' +
						gpr.htmlString(gpr.Trim(item.memberID)  || '--') +
					'</td>' +					
					'<td style="padding-top:2px;">' +
						'<span class="dropshadows" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>&nbsp;&nbsp;' );
						//if ( this.isDocumentAttached(patientDocuments,item.id) == true)
						//{
						html.push('<span class="large-dropshadows">' +
							'<a  align="left" href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onViewDocuments\', ' + item.id + ',3,1); return false;"' +
							'>Add/View Document</a>' +
						'</span>' );
						/*}
						else
						{
						html.push('<span class="large-disableshadows">' +
							'<a align="center" href="javascript:void(0)" ' +					
							'>Add/View Documents</a>' +
						'</span>' );
						}*/
											
					html.push( '</td>'+ '</tr>' );
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	}
	
	this.isDocumentAttached = function(patientDocuments,recordID)
	{
		if (patientDocuments.length == 0)
		{
			return false;
		}
		for( var i = 0; i < patientDocuments.length; ++i)
		{
			var item = patientDocuments[i];
			if (item.recordID == recordID)
			{
				return true;
			}
		}
		return false;
	}
	
};

gpr.forms.patientInsurance = function(id,onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '

	this.getHtml = function(patientID, pi,DocumentTypeID)
	{
		pi = pi || {id:0, patientID:patientID,timeStamp:0,insuranceCoverageTypeID:0};
		var isNew = pi.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  pi.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
		
		var pNformatString = 'onkeydown="javascript:validator.backspacerDOWN(this, event);" onkeyup="javascript:validator.backspacerUP(this, event);" '
		
		var html = [];
		
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" ' + (cdw?'width="100%"':'') + '>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end

		html.push(
			(isNew ? "<h3>Add an Insurance Contact</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + pi.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + pi.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + pi.patientID + '">' +
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" ' + (cdw?'width="800"':'width="90%"') + '>' +
				'<tr>' +
					'<td class="gpr-panel-caption">&nbsp;</td>'+
					'<td class="gpr-panel-caption" colspan="3">Insurance</td>' +
					'<td class="gpr-panel-caption" align="right">'+ deleteHtml +'</td>' +

				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"><span class="reg-required">*</span></td><td style="padding-left:0px;width:100px"><label for="'+ this.id + '.companyName">Company Name</label></td>' +
				'<td colspan="3"><input type="text" id="' + this.id + '.companyName" value="' + (pi.companyName || '') + '" '+  focusClass + ' style="width:90%"  maxlength="150"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"><span class="reg-required">*</span></td><td style="padding-left:0px;"><label for="'+ this.id + '.phone">Phone</label></td>' +
				'<td><input type="text" name="' + this.id + '.phone" value="' + (pi.phone || '') + '" ' +  focusClass + '  maxlength="14" size="14" ' + pNformatString +  '> (###)###-####</td>' +
				'<td><label for="'+ this.id + '.fax">Fax</label></td>' +
				'<td><input type="text" name="' + this.id + '.fax" value="' + (pi.fax || '') + '" '  +  focusClass + '  maxlength="14" size="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.email">Email</label></td>' +
				'<td colspan="3"><input type="text" name="' + this.id + '.email" value="' + (pi.email || '') + '" '  +  focusClass + ' style="width:90%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px"></td><td style="padding-left:0px;" ><label for="'+ this.id + '.firstName">Primary Subscriber</label></td>' +
				'<td><label for="'+ this.id + '.firstName">First Name </label><br><input type="text" name="' + this.id + '.firstName" value="' + (pi.firstName || '') + '" '+  focusClass + ' maxlength="50"></td>' +
				'<td colspan="2"><label for="'+ this.id + '.lastName">Last Name</label><br><input type="text" name="' + this.id + '.lastName" value="' + (pi.lastName || '') + '" '+  focusClass + ' maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" >Relationship</td>' +
				'<td colspan="3">')
		 		gpr.getList(html, gpr.dictionaries.relationships, pi.relationshipID, this.id + ".relationshipID") 
				html.push('</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.planName">Insurance Plan Name</label></td>' +
				'<td colspan="3"><input type="text" name="' + this.id + '.planname" value="' + (pi.planName || '') + '" '  +  focusClass + ' style="width:90%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.planName">Coverage Type</label></td><td>' );
				gpr.getList(html, gpr.dictionaries.insuranceCoverageTypes, pi.insuranceCoverageTypeID, this.id + ".insuranceCoverageTypeID") 
				html.push('<td></tr>' +
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.groupID">Group ID</label></td>' +
				'<td colspan="3"><input type="text" name="' + this.id + '.groupID" value="' + (pi.groupID || '') + '" '  +  focusClass + ' style="width:90%" maxlength="50"></td>' +
				'</tr>' +	
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.memberID">Member ID</label> </td>' +
				'<td colspan="3"><input type="text" name="' + this.id + '.memberID" value="' + (pi.memberID || '') + '" '  +  focusClass + ' style="width:90%" maxlength="50"></td>' +
				'</tr>' +	
				
				//Added By prakash feb-18-2007
								
				'<tr><td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.effectiveDate">Effective Date</label> </td>' +
				'<td><input type="text" name="' + this.id + '.effectiveDate" id="' + this.id + '.effectiveDate" size="10" value="'+ (gpr.isNullDate(pi.effectiveDate) ? '' : gpr.htmlString(pi.effectiveDate)) + '" '+ focusClass + ' maxlength="10">' +
				'<a href="#" onclick="showCalendar(\'' + this.id + '.effectiveDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
				'(mm/dd/yyyy)'+	'</td></tr>' +
					
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.prescriptionNumber">Prescription Benefit Number</label></td>' +
				'<td colspan="3"><input type="text" name="' + this.id + '.prescriptionPlanName" value="' + (pi.prescriptionPlanName || '') + '" '  +  focusClass + ' style="width:90%" maxlength="50"></td>' +
				'</tr>' +				
				
				
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px">&nbsp;</td><td style="padding-left:0px;" ><label for="'+ this.id + '.comments">Comments</label></td>' +
				'<td colspan="3">' +
				'<textarea  id="' + this.id + '.comments" style="width:90%" value=""  ' + focusClass + ' rows="3" cols="60">' + gpr.htmlString(pi.comments) + '</textarea>' +
				'</td>' +
				'</tr>' +
			
				
				
				//below lines commented by Deepak, Nous, 20-Feb-2007, for un-implementing the Add Document Functionality	
					
				//'<tr height="290" width="100%"><td colspan="4">' +
				//'<iframe frameborder="0" src ="PatientDocument/AddPatientDocument.aspx?patientID=' + gpr.data.currentPatientID + '&DocumentTypeID=' + DocumentTypeID  + '&RecordID=' + pi.id + '"  height="100%"  width="100%">' + '</iframe>' +
				//	+'</td></tr>'+
						
				'<tr><td colspan="5"><hr></td></tr>' +
				'<tr>' +
					'<td align="center" colspan="5">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
				)
				
				/*html.push(
				'<table width="87%" height="290"><tr><td>' +
				'<iframe frameborder="0" src ="PatientDocument/AddPatientDocument.aspx?patientID=' + gpr.data.currentPatientID + '&DocumentTypeID=' + DocumentTypeID  + '&RecordID=' + pi.id + '"  height="100%"  width="100%">' + '</iframe>' +
					+'</td></tr></table>'
				
				);*/
				
			return html.join(' ')
		
	}
	
	this.getBody = function()
	{
		
		var ID = document.getElementById(this.id + '.ID').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value || '0';
		var firstName = document.getElementById(this.id + '.firstName').value;
		var lastName = document.getElementById(this.id + '.lastName').value || '';
		var groupID = document.getElementById(this.id + '.groupID').value || '';
		var planName = document.getElementById(this.id + '.planName').value || '';
		var relationshipID = document.getElementById(this.id + '.relationshipID').value || '';
		var companyName = document.getElementById(this.id + '.companyName').value || '';
 		var	memberID = document.getElementById(this.id + '.memberID').value || '';
		var	prescriptionPlanName = document.getElementById(this.id + '.prescriptionPlanName').value || '';
		var	phone = gpr.Trim(document.getElementById(this.id + '.phone').value || '');
		var	fax = gpr.Trim(document.getElementById(this.id + '.fax').value || '');
		var	email = document.getElementById(this.id + '.email').value || '';
		var insuranceCoverageTypeID =  document.getElementById(this.id + '.insuranceCoverageTypeID').value || '';
		
		//added by prakash 18/feb/2008
		var comments=document.getElementById(this.id + '.comments').value || '';
		var effectiveDate=document.getElementById(this.id + '.effectiveDate').value || '';
		
		var insuranceCoverageTypeError = false;		
		var patientInsurances = gpr.data.getCurrentPatientCollection('patientInsurances');
		
		
		for( var i = 0; i < patientInsurances.length; ++i)
		{
			var pi = patientInsurances[i];
			
			if(pi.patientID == patientID  && pi.insuranceCoverageTypeID == insuranceCoverageTypeID &&  pi.id != ID)
			{
				insuranceCoverageTypeError = true;
				break;
			}
		}
		
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		
		if ( !gpr.Trim(companyName) )
		{
			alert('Please enter the Insurance company Name');
			document.getElementById(this.id + '.companyName').focus();
		}
		else if (!phone)
		{
			alert('Please enter the phone number');
			document.getElementById(this.id + '.phone').focus();
		}
		else if(phone && phone.length != 13)
		{
			alert('Please enter a valid phone number');
			document.getElementById(this.id + '.phone').focus();
		}
		else if(fax && fax.length != 13)
		{
			alert('Please enter a valid fax number');
			document.getElementById(this.id + '.fax').focus();
		}
		else if(!gpr.forms.Checkemails(email))
		{
			document.getElementById(this.id + '.email').focus();
		}
		else if(insuranceCoverageTypeError == true)
		{
			alert('You have already assigned another one insurance plan as your ' + 	gpr.htmlString(pi.insuranceCoverageTypeID ? gpr.findID(gpr.dictionaries.insuranceCoverageTypes, pi.insuranceCoverageTypeID, {name:'--'}).name : '--') + ' coverage type.');
			document.getElementById(this.id + '.insuranceCoverageTypeID').focus();
		}
		//added by prakash 20/2/2008
		else if(comments && comments.length > 1000)
		{
			alert('Comments cannot exceed more than 1000 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		else 
		{
			return ( 
				'id=' + ID +
				'&patientID=' + patientID +
				(firstName ? '&firstName=' + encodeURIComponent(firstName) : '' )+
				(lastName ? '&lastName=' + encodeURIComponent(lastName) : '' )+
				(relationshipID ? '&relationshipID=' + encodeURIComponent(relationshipID) : '') +
				(companyName ? '&companyName=' + encodeURIComponent(companyName) : '') +
				(planName ? '&planName=' + encodeURIComponent(planName) : '') +
				(memberID ? '&memberID=' + encodeURIComponent(memberID) : '') +
				(groupID ? '&groupID=' + encodeURIComponent(groupID) : '') +
				(prescriptionPlanName ? '&prescriptionPlanName=' + encodeURIComponent(prescriptionPlanName) : '' ) +
				(phone ? '&phone=' + encodeURIComponent(phone) : '' ) +
				(fax ? '&fax=' + encodeURIComponent(fax) : '' ) +
				(email ? '&email=' + encodeURIComponent(email) : '' ) +
				('&CareDataUserID=' + careDatauserID )+
				(insuranceCoverageTypeID ? '&insuranceCoverageTypeID=' + encodeURIComponent(insuranceCoverageTypeID) : '') +
				('&timeStamp=' + encodeURIComponent(timeStamp)) +
				//added by prakash 18/feb/2008
				(effectiveDate ? '&effectiveDate=' + encodeURIComponent(effectiveDate) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '')				
				);
		} 

		
	}
	
}


//Function Added by Nous(Manoj) to display document list attched to a particular Insurance record.

gpr.forms.patientInsuranceDocuments = function(id,onClose)
{
	this.id = id;
	this.onClose = onClose;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;

		// Add by Nous(Manoj) to get the position for pop-up window

	this.getWindowCenterElements = function(nWidth, nHeight)
	{
	
	var sFeatures
	var nLeft, nTop
	nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth - 15 + 20) 
	nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight - 1 + 60) 
	sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight 
	return sFeatures
	
	}
	
	// Add by Nous(Manoj) to get the center cordinates

	this.getCenterCordinates = function (Sr, Pl, Pw, Dw)
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}
	
	var style = this.getWindowCenterElements(700,635) +  ", menubar=1,status=yes,resizable=yes,scrollbars=no";
	style = '\'' + style + '\''
	
	//modified by deepak, nous, 19-feb-2007, to receive pi and documentypeid
	this.getHtml = function(patientID,patientDocuments,recordID,pi,DocumentTypeID)
	{
		pi = {id:0, patientID:patientID}; //added by deepak, nous, 19-feb-2007, to assign new value to pi
		
		var html = [];

	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
			  var careDatauserID = document.getElementById('careDatauserID').value;
        }
        //changes end
		
		html.push(
			'<table class="gpr-panel panel-border" width="' + (cdw?'600':'90%') + '">' +
				' <tr><td colspan="5" class="gpr-panel-caption">INSURANCE('+ gpr.data.patients[patientID].firstName +') - Document List1 ('+ gpr.data.patientInsurances[recordID].companyName +')</td>' +
					'</tr>'
		);
		
		if(patientDocuments.length == 0)
		{
			html.push('<tr><td colspan="5" align="center">No documents attached to this Insurance - <b>' + gpr.data.patientInsurances[recordID].companyName + ' </b> </td></tr>');
		}
		else
		{
		  html.push('<tr>' +
					'<td width="5%" id="' + this.id + '.date" class="panel-column-header">Sl.No</td>'+
					'<td width="13%" id="' + this.id + '.date" class="panel-column-header">' +
						'Date' +
					'</td>' +
					'<td width="20%" id="' + this.id + '.documentTitle" class="panel-column-header">' +
						'Document Title' +
					'</td>' +
					'<td width="25%" id="' + this.id + '.documentName" class="panel-column-header">' +
						'Document Name' +
					'</td>' +
					'<td id="' + this.id + '.documentDescription" class="panel-column-header">' +
						'Description' +
					'</td>' +
				'</tr>' );
		}
		
		for( var i = 0; i < patientDocuments.length; ++i)
		{
			var item = patientDocuments[i];
			var x = i + 1 ;
			if(item == null) continue;
			html.push(
				'<tr>' +
					'<td>'+ x +'</td>'+
					'<td>'+
					'<a href="#" onclick="window.open(\'PatientDocument/DisplayPatientDocument.aspx?ID='+ item.id + '&typeID=' + 3 + '&userID=' + (cdw ? careDatauserID : gpr.data.user.id) + '&userType=' + (cdw ? '1' : '0') + '\' , null,'+ style + ')"> '+ gpr.htmlString(item.documentDate)+ '</a>' 
					+ '</td>' +
					'<td>'+ gpr.htmlString(item.documentTitle) + '</td>' + 
					'<td>'+ gpr.htmlString(item.documentName) + '</td>' + 
					'<td>'+ gpr.htmlString(item.documentDescription == '' ? '--' : item.documentDescription) + '</td>' + 
				'</tr>'
			);
		}
		
		//below html.push added by deepak, nous, 19-feb-2007, to show the add document frame.
		html.push(
			'<tr height="325" width="100%"><td colspan="5"><br>' +
			'<iframe frameborder="0" src ="PatientDocument/AddPatientDocument.aspx?patientID=' + (gpr.data.currentPatientID || gpr.data.patient.id) + '&DocumentTypeID=' + DocumentTypeID  + '&RecordID=' + recordID + '&UserID='+  (cdw ? careDatauserID : gpr.data.user.id)  +  '&UserType='+  (cdw ? 1 : 0) +'"  height="100%"  width="100%">' + '</iframe>' +
				+'</td></tr>');

		html.push(
		 '<tr><td colspan="5" align="center" valign="bottom">'+'<BR>'+
		 '<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
					'<a href="javascript:void(0)" ' +'>Close</a>' +
				'</span></td></tr>' 
		 );
		
		return html.join('') 
	}
}

gpr.forms.patientFHEdit = function(id, onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);

	this.findRow = function(conditionID, patientFH)
	{
	 
		var row = {id :0, conditionID:0,grandParents:false, parents:false,siblings:false,children:false,timeStamp:0}
		for(var i=0; i < patientFH.length; i++)
		{
			if(patientFH[i].conditionID == conditionID)
			{
			  row = patientFH[i]
			  break;
			}
		}
		return row;
	}
	
	this.getHtml = function(patientID, patientFH)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="panel-border" width="90%">' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Family History ('+ gpr.data.patients[patientID].firstName +')</td>' +
				'</tr>' 

		);

		   html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header">' +
						'Disease' +
					'</td>' +
					'<td align="center" id="' + this.id + '.isActive" class="panel-column-header">' +
						'Grand Parents' +
					'</td>' +
					'<td align="center" id="' + this.id + '.isActive" class="panel-column-header">' +
						'Parents' +
					'</td>' +
					'<td align="center"  id="' + this.id + '.isActive" class="panel-column-header">' +
						'Siblings' +
					'</td>' +
					'<td align="center" id="' + this.id + '.isActive" class="panel-column-header">' +
						'Children'  +
					'</td>' +
				'</tr>' 
				+
				'<tr><td>'+'&nbsp;'+'</td><td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ '</tr>'
				)
		
		
		for( var i = 0; i < gpr.dictionaries.conditions.length; ++i)
		{
			if(gpr.dictionaries.conditions[i].hereditary)
			{
				var condition = gpr.dictionaries.conditions[i];
				var row = this.findRow(condition.id, patientFH)
				html.push(
					'<tr>' +
						'<td>' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.id"  value="' + (row.id) +  '">' +
						  '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.timestamp"  value="' + (row.timeStamp) +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.gpComments"  value="' + (row.gpComments ? row.gpComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.pComments"  value="' + (row.pComments ? row.pComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.sComments"  value="' + (row.sComments ? row.sComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.cComments"  value="' + (row.cComments ? row.cComments : '') +  '">' +
						'<input type="hidden" name="' +  this.id + condition.id + '.condition" id="' +  this.id + condition.id + '.conditionID"  value="' + (condition.id) +  '">' +
							gpr.htmlString(condition.name) +
						'</td>' +
						
						'<td align="center">' +
							 //'<input type="checkbox" name="' +  this.id + condition.id + '.g" id="' +  this.id + condition.id + '.g" ' + (row.grandParents ? 'checked' : '') +  '>' +
						'<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_Yes" ' + (row.grandParents == 1 ? 'checked' : '') + ' value="' + 1 + '">'+ '&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_No"  ' + (row.grandParents == 2 ? 'checked' : '') + ' value="' + 2 + '">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_Unsure"  ' + (row.grandParents != 1 && row.grandParents != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
						'</td>' +
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.p" id="' +  this.id + condition.id + '.p" ' + (row.parents ? 'checked' : '') +  '>' +
							'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_Yes"  ' + (row.parents == 1 ? 'checked' : '') + ' value="' + 1 + '">'+ '&nbsp;&nbsp;'+
										
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_No"  ' + (row.parents == 2 ? 'checked' : '') + ' value="' + 2 + '">'+'&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_Unsure"  ' + (row.parents != 1 && row.parents != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
											 
						'</td>' +
						
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.s" id="' +  this.id + condition.id + '.s" ' + (row.siblings ? 'checked' : '') +  '>' +
							'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_Yes"  ' + (row.siblings == 1 ? 'checked' : '') + ' value="' + 1 + '">'+'&nbsp;&nbsp;'+
										
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_No"  ' + (row.siblings == 2 ? 'checked' : '') + ' value="' + 2 + '">'+'&nbsp;&nbsp;'+
						
											 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_Unsure"  ' +(row.siblings != 1 && row.siblings != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
							 
							
						'</td>' +
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.c" id="' +  this.id + condition.id + '.c" ' + (row.children ? 'checked' : '') +  '>' +
								'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_Yes"  ' + (row.children == 1 ? 'checked' : '') + ' value="' + 1 + '">'+'&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_No"  ' + (row.children == 2 ? 'checked' : '') + ' value="' + 2 + '">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_Unsure"  ' + (row.children != 1 && row.children != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
						'</td>' +
					'</tr>'
				);
			}
		}
		
		
		html.push(		
						'<tr>' +
					'<td align="center" colspan="5">' +
						'<br><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
			) 
		
		return html.join('') 
	};
	
this.getBody = function()
{
	var body = ''
	var patientID =  document.getElementById(this.id + '.patientID').value || '0';
	body += 'patientID=' + patientID
	var ctr = 0;
	for( var i = 0; i < gpr.dictionaries.conditions.length; ++i)
	{
			if(gpr.dictionaries.conditions[i].hereditary)
			{
				var cdtn = gpr.dictionaries.conditions[i]
				var id = document.getElementById(this.id + cdtn.id +  '.id').value || '0';
				var conditionID = document.getElementById(this.id + cdtn.id + '.conditionID').value || '0';
				//var grandparents = document.getElementById(this.id + cdtn.id + '.g').checked ? '1' : '0';
				//var parents = document.getElementById(this.id + cdtn.id + '.p').checked ? '1' : '0';
				//var siblings = document.getElementById(this.id + cdtn.id + '.s').checked ? '1' : '0';
				//var children = document.getElementById(this.id + cdtn.id + '.c').checked ? '1' : '0';
				var grandparents = gpr.getRadioGroupValue(this.id + cdtn.id + '.g') || gpr.FamilyHistorySelect.None;
				var parents = gpr.getRadioGroupValue(this.id + cdtn.id + '.p') || gpr.FamilyHistorySelect.None;
				var siblings = gpr.getRadioGroupValue(this.id + cdtn.id + '.s') || gpr.FamilyHistorySelect.None;
				var children = gpr.getRadioGroupValue(this.id + cdtn.id + '.c') || gpr.FamilyHistorySelect.None;
				var gpComments = document.getElementById(this.id + cdtn.id +  '.gpComments').value || '';
				var pComments = document.getElementById(this.id + cdtn.id +  '.pComments').value || '';
				var sComments = document.getElementById(this.id + cdtn.id +  '.sComments').value || '';
				var cComments = document.getElementById(this.id + cdtn.id +  '.cComments').value || '';
				var timeStamp = document.getElementById(this.id + cdtn.id +  '.timestamp').value || '0';
				
				if(cdtn.id == conditionID)
				{
					var conditionName = cdtn.name;	
				}
				if (id!= '0' || (grandparents != '3' ||  parents != '3' ||  siblings != '3' || children != '3'))
				{
				  body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + conditionID + ',' +  grandparents + ',' + parents + ',' + siblings + ',' + children + ',' + gpComments + ',' + pComments + ',' + sComments + ',' + cComments + ',' + timeStamp + ','+conditionName)
				}
			}
	}
	body += '&rowcount=' + ctr + '&commentEdit=0' 
	return body
}

};


gpr.forms.patientFHEditCDW = function(id, onSubmit, onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onClose = onClose;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;

	this.findRow = function(conditionID, patientFH)
	{
	 
		var row = {id :0, conditionID:0,grandParents:false, parents:false,siblings:false,children:false,timeStamp:0}
		for(var i=0; i < patientFH.length; i++)
		{
			if(patientFH[i].conditionID == conditionID)
			{
			  row = patientFH[i]
			  break;
			}
		}
		return row;
	}
	
	this.getHtml = function(patientID, patientFH)
	{
		var html = [];
		
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ (cdw?'width="100%"':'') +'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end

		html.push(
			'' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" '+ (cdw?'width="800"':'width="90%"') + '>' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Family History ('+ gpr.data.patients[patientID].firstName +')</td>' +
				'</tr>' 

		);

		   html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header">' +
						'Disease' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Grand Parents' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Parents' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Siblings' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Children'  +
					'</td>' +
				'</tr>'
				+
				'<tr><td>'+'&nbsp;'+'</td><td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
					'<td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ '</tr>'
				)
		
		
		for( var i = 0; i < gpr.dictionaries.conditions.length; ++i)
		{
			if(gpr.dictionaries.conditions[i].hereditary)
			{
				var condition = gpr.dictionaries.conditions[i];
				var row = this.findRow(condition.id, patientFH)
				html.push(
					'<tr>' +
						'<td>' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.id"  value="' + (row.id) +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.timestamp"  value="' + (row.timeStamp) +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.gpComments"  value="' + (row.gpComments  ? row.gpComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.pComments"  value="' + (row.pComments  ? row.pComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.sComments"  value="' + (row.sComments  ? row.sComments : '') +  '">' +
						 '<input type="hidden" name="' +  this.id + condition.id + '.id" id="' +  this.id + condition.id + '.cComments"  value="' + (row.cComments  ? row.cComments : '') +  '">' +
						'<input type="hidden" name="' +  this.id + condition.id + '.condition" id="' +  this.id + condition.id + '.conditionID"  value="' + (condition.id) +  '">' +
							gpr.htmlString(condition.name) +
						'</td>' +
						
						'<td align="center">' +
							 //'<input type="checkbox" name="' +  this.id + condition.id + '.g" id="' +  this.id + condition.id + '.g" ' + (row.grandParents ? 'checked' : '') +  '>' +
						'<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_Yes" ' + (row.grandParents == 1 ? 'checked' : '') + ' value="' + 1 + '">'+ '&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_No"  ' + (row.grandParents == 2 ? 'checked' : '') + ' value="' + 2 + '">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + condition.id + '.g"  id="' + this.id + condition.id + '.g_Unsure"  ' + (row.grandParents != 1 && row.grandParents != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
						'</td>' +
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.p" id="' +  this.id + condition.id + '.p" ' + (row.parents ? 'checked' : '') +  '>' +
							'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_Yes"  ' + (row.parents == 1 ? 'checked' : '') + ' value="' + 1 + '">'+ '&nbsp;&nbsp;'+
										
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_No"  ' + (row.parents == 2 ? 'checked' : '') + ' value="' + 2 + '">'+'&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.p"  id="' + this.id + condition.id + '.p_Unsure"  ' + (row.parents != 1 && row.parents != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
											 
						'</td>' +
						
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.s" id="' +  this.id + condition.id + '.s" ' + (row.siblings ? 'checked' : '') +  '>' +
							'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_Yes"  ' + (row.siblings == 1 ? 'checked' : '') + ' value="' + 1 + '">'+'&nbsp;&nbsp;'+
										
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_No"  ' + (row.siblings == 2 ? 'checked' : '') + ' value="' + 2 + '">'+'&nbsp;&nbsp;'+
						
											 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.s"  id="' + this.id + condition.id + '.s_Unsure"  ' +(row.siblings != 1 && row.siblings != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
							 
							
						'</td>' +
						'<td align="center">' +
							// '<input type="checkbox" name="' +  this.id + condition.id + '.c" id="' +  this.id + condition.id + '.c" ' + (row.children ? 'checked' : '') +  '>' +
								'<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_Yes"  ' + (row.children == 1 ? 'checked' : '') + ' value="' + 1 + '">'+'&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_No"  ' + (row.children == 2 ? 'checked' : '') + ' value="' + 2 + '">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input style="width:12px" type="radio" name="' + this.id + condition.id + '.c"  id="' + this.id + condition.id + '.c_Unsure"  ' + (row.children != 1 && row.children != 2 ? 'checked' : '') + ' value="' + 3 + '">'+
							 
						'</td>' +
					'</tr>'
				);
			}
		}
		
		
		html.push(
						'<tr>' +
					'<td align="center" colspan="5">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							'<a href="javascript:void(0)">Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
			) 
		
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var body = ''
		var patientID =  document.getElementById(this.id + '.patientID').value || '0';
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		
		body += 'patientID=' + patientID
		body += '&CareDataUserID=' + careDatauserID
		var ctr = 0;
		for( var i = 0; i < gpr.dictionaries.conditions.length; ++i)
		{
				if(gpr.dictionaries.conditions[i].hereditary)
				{
					var cdtn = gpr.dictionaries.conditions[i]
					var id = document.getElementById(this.id + cdtn.id +  '.id').value || '0';
					var conditionID = document.getElementById(this.id + cdtn.id + '.conditionID').value || '0';
					/*var grandparents = document.getElementById(this.id + cdtn.id + '.g').checked ? '1' : '0';
					var parents = document.getElementById(this.id + cdtn.id + '.p').checked ? '1' : '0';
					var siblings = document.getElementById(this.id + cdtn.id + '.s').checked ? '1' : '0';
					var children = document.getElementById(this.id + cdtn.id + '.c').checked ? '1' : '0'; */
					var grandparents = gpr.getRadioGroupValue(this.id + cdtn.id + '.g') || gpr.FamilyHistorySelect.None;
					var parents = gpr.getRadioGroupValue(this.id + cdtn.id + '.p') || gpr.FamilyHistorySelect.None;
					var siblings = gpr.getRadioGroupValue(this.id + cdtn.id + '.s') || gpr.FamilyHistorySelect.None;
					var children = gpr.getRadioGroupValue(this.id + cdtn.id + '.c') || gpr.FamilyHistorySelect.None;
					var gpComments = document.getElementById(this.id + cdtn.id +  '.gpComments').value || '';
					var pComments = document.getElementById(this.id + cdtn.id +  '.pComments').value || '';
					var sComments = document.getElementById(this.id + cdtn.id +  '.sComments').value || '';
					var cComments = document.getElementById(this.id + cdtn.id +  '.cComments').value || '';
					var timeStamp = document.getElementById(this.id + cdtn.id +  '.timestamp').value || '0';
					if(cdtn.id == conditionID)
					{
						var conditionName = cdtn.name;	
					}
					if (id!= '0' || (grandparents != '3' ||  parents != '3' ||  siblings != '3' || children != '3'))
					{
						body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + conditionID + ',' +  grandparents + ',' + parents + ',' + siblings + ',' + children + ',' + gpComments + ',' + pComments + ',' + sComments + ',' + cComments + ',' + timeStamp + ','+conditionName)
					}
				}
		}
		body += '&rowcount=' + ctr + '&commentEdit=0' 
		return body
	}

};

gpr.forms.patientFH = function(id, onChange,onClose,onEditComment)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	this.onEditComment = onEditComment;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientFH)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Family History ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Edit</a></span></td></tr>' 

		);
		if(patientFH.length == 0)
		{
			html.push('<tr><td colspan="5" align="center">To add Family History  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header" >' +
						'Disease' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header" align="center">' +
						'Grand Parents' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header" align="center">' +
						'Parents' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header" align="center">' +
						'Siblings' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header" align="center">' +
						'Children'  +
					'</td>' +
					'<td id="' + this.id + '.comments" class="panel-column-header" align="center">' +
						'Comments'  +
					'</td>' +

				'</tr>')
		}
		for( var i = 0; i < patientFH.length; ++i)
		{
			var item = patientFH[i];
			if( item.grandParents || item.parents || item.siblings || item.children ) {
			html.push(
				'<tr>' +
					'<td width="45%">' +
						gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : '') +
					'</td>' +
					'<td align="center" ' +
						(item.grandParents == 1 ? '><img src="images/yes.gif">' : (item.grandParents == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center"' +
						(item.parents == 1 ? '><img src="images/yes.gif">' : (item.parents == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center" ' +
						(item.siblings == 1 ? '><img src="images/yes.gif">' : (item.siblings == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center"' +
						(item.children == 1 ? '><img src="images/yes.gif">' : (item.children == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center" style="padding-top:2px;">' +
					'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onEditComment\',' + item.id + '); return false;">'+
					'<a href="javascript:void(0)" ' + '>'+ 'Add/View' +'</a></span>'+
					'</td>' +
				'</tr>'
			);
			}
		}
		
		
		html.push(
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'+
						'</span>' +
				'</div>' 
	
		) 
		
		return html.join('') 
	};
};


gpr.forms.patientFHEditComment = function (id,onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	
	this.getHtml = function(patientID, patientFamilyHistory)
	{
		var html = [];
		var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
		
		if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        
		html.push(
			'<input id="' + this.id + '.id" type="hidden" value="' + patientFamilyHistory.id + '">' +
			'<input id="' + this.id + '.conditionID" type="hidden" value="' + patientFamilyHistory.conditionID + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientFamilyHistory.patientID + '">' +
			'<input id="' + this.id + '.grandParent" type="hidden" value="' + patientFamilyHistory.grandParents + '">'+
			'<input id="' + this.id + '.parent" type="hidden" value="' + patientFamilyHistory.parents + '">'+
			'<input id="' + this.id + '.sibling" type="hidden" value="' + patientFamilyHistory.siblings  + '">'+
			'<input id="' + this.id + '.children" type="hidden" value="' + patientFamilyHistory.children + '">'+
			'<input id="' + this.id + '.timestamp" type="hidden" value="' + patientFamilyHistory.timeStamp + '">'+
			'<br><br>'+
			'<table class="gpr-panel">' +
			'<tr>' +
				'<td class="gpr-panel-caption">Family History ('+ (cdw ? gpr.htmlString(gpr.data.patient.firstName):gpr.htmlString(gpr.data.patients[patientID].firstName)) +') - Comments</td>' +
				'<td class="gpr-panel-caption" align="right" >'+'</td>' +
			'</tr>' +
			'<tr>' +
				'<td style="padding-bottom:5px" colspan="2">' +
					'<table class="gpr-panel-section" width="100%">' +
					
					'<tr>'+
					'<td colspan="2" align="center">'+
						'<table width="100%" class="gpr-panel panel-border"><tr><td align="center" class="panel-column-header">Grandparents</td><td align="center"  class="panel-column-header">Parents</td><td align="center" class="panel-column-header">Siblings</td><td  align="center" class="panel-column-header">Children</td></tr>'+
						'<tr>'+
						'<td align="center" ' +
						(patientFamilyHistory.grandParents == 1 ? '><img src="images/yes.gif">' : (patientFamilyHistory.grandParents == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center"' +
						(patientFamilyHistory.parents == 1 ? '><img src="images/yes.gif">' : (patientFamilyHistory.parents == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center" ' +
						(patientFamilyHistory.siblings == 1 ? '><img src="images/yes.gif">' : (patientFamilyHistory.siblings == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="center"' +
						(patientFamilyHistory.children == 1 ? '><img src="images/yes.gif">' : (patientFamilyHistory.children == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
						'</tr></table>'+
					'</td>'+
					'</tr>'+
					
					'<tr height="25px">' +
					'<td>' +
						'<label for="' + this.id + '.conditionName" >Disease <label>' +
					'</td>' +
					'<td>' +
					'<label for="' + this.id + '.conditionName" >'+
					'<b>'+gpr.htmlString(patientFamilyHistory.conditionID ? gpr.findID(gpr.dictionaries.conditions, patientFamilyHistory.conditionID,{name:''}).name : '') + '</b>'+
					'<label>' +
					'</td>' +
					'</tr>' +
					
					'<tr>' +
					'<td>'+
						'<label for="' + this.id + '.gParent" >Grandparents<label>' +
						
					'</td>' +
					'<td> <textarea id="' + this.id + '.gpComments"  cols="60" maxlength="100" ' + focusClass + '>' +
						patientFamilyHistory.gpComments +
					'</textarea></td>' +
					'</tr>' +

					'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.Parent" >Parents<label>' +
						
					'</td>' +
					'<td> <textarea id="' + this.id + '.pComments"  cols="60" maxlength="100" ' + focusClass + '>' +
					gpr.htmlString(patientFamilyHistory.pComments) +
					'</textarea></td>' +
					'</tr>' +

					'<tr>' +
					'<td>'+
						'<label for="' + this.id + '.sib" >Siblings<label>' +
						
					'</td>' +
					'<td> <textarea id="' + this.id + '.sComments"  cols="60" maxlength="100" ' + focusClass + '>' +
					gpr.htmlString(patientFamilyHistory.sComments) +
					'</textarea></td>' +
					'</tr>' +
					'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.Childrens" >Children<label>' +
						
					'</td>' +
					'<td> <textarea id="' + this.id + '.cComments"  cols="60" maxlength="100" ' + focusClass + '>' +
					gpr.htmlString(patientFamilyHistory.cComments) +
					'</textarea></td>' +
					'</tr>' +
					'</table>' +
					'</td>' +
				'</tr>' +
				
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' 							+
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
						'</td>' +
				'</tr>' +
			'</table>'
		);
			
		return html.join(''); 
		};
		
	this.getBody = function()
	{
		var body = ''
		var patientID =  document.getElementById(this.id + '.patientID').value || '0';
		body += 'patientID=' + patientID
		var ctr = 0;
		var id = document.getElementById(this.id + '.id').value || '0';
		var conditionID = document.getElementById(this.id + '.conditionID').value || '0';
		var grandparents =  document.getElementById(this.id + '.grandParent').value || gpr.FamilyHistorySelect.None;
		var parents =  document.getElementById(this.id + '.parent').value || gpr.FamilyHistorySelect.None;
		var siblings = document.getElementById(this.id + '.sibling').value || gpr.FamilyHistorySelect.None;
		var children =  document.getElementById(this.id + '.children').value || gpr.FamilyHistorySelect.None;
		var gpComment = document.getElementById(this.id + '.gpComments').value || ''
		var pComment  = document.getElementById(this.id + '.pComments').value || ''
		var sComment = document.getElementById(this.id + '.sComments').value || ''
		var cComment = document.getElementById(this.id + '.cComments').value || ''
		var timeStamp = document.getElementById(this.id + '.timestamp').value || '0';
		var conditionName;	
			
		for( var i = 0; i < gpr.dictionaries.conditions.length; ++i)
		{
			var cdtn = gpr.dictionaries.conditions[i]
			if(cdtn.id == conditionID)
			{
				conditionName = cdtn.name;	
				break;
			}
		}	
	
		if(gpComment.length > 100)
		{	
			alert('Please enter comment with less than 100 characters ');
			document.getElementById(this.id + '.gpComments').focus();	
		}
		else if (pComment.length > 100)
		{
			
			alert('Please enter comment with less than 100 characters');
			document.getElementById(this.id + '.pComments').focus();	
		}
		else if(sComment.length > 500)
		{
			alert('Please enter comment with less than 100 characters');
			document.getElementById(this.id + '.sComments').focus();
		}
		else if(cComment.length > 500)
		{
			alert('Please enter comment with less than 100 characters');
			document.getElementById(this.id + '.cComment').focus();
		}
		else 
		{
			body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + conditionID + ',' +  grandparents + ',' + parents + ',' + siblings + ',' + children+ ',' +  gpComment + ',' + pComment + ',' + sComment + ',' + cComment+ ',' + timeStamp+','+conditionName)
		}
		body += '&rowcount=' + ctr + '&commentEdit=1' 
		return body;
	}
	

	
}

// **************************** : SOCIAL HISTORY Begin (Added by Nous (Manoj) ): ***************************


gpr.forms.patientSH = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientSH)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="2" class="gpr-panel-caption">Social History ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Edit</a></span></td></tr>' 

		);
		if(patientSH.length == 0)
		{
			html.push('<tr><td colspan="3" align="center">To add Social History  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header" width="40%" >' +
						'Social Habit' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header" align="center"  width="15%">' +
						'Status' +
					'</td>' +
					'<td id="' + this.id + '.comments" class="panel-column-header" align="left"  width="45%">' +
						'Comments' +
					'</td>' +
					'</tr>')
		}
		for( var i = 0; i < patientSH.length; ++i)
		{
			var item = patientSH[i];
			html.push(
				'<tr>' +
					'<td width="50%">' +
						gpr.htmlString(item.socialHabitID ? gpr.findID(gpr.dictionaries.socialHabits, item.socialHabitID, {name:''}).name : '') +
					'</td>' +
					'<td align="center" ' +
						(item.status == 1 ? '><img src="images/yes.gif">' : (item.status == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="left">&nbsp; ' +
						gpr.htmlString(item.comments) +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'+
						'</span>' +
				'</div>' 
	
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientSHEdit = function(id, onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.findSocialHistory = function(socialHabitID, patientSHs)
	{
		//var row = {id :0, conditionID:0,grandParents:false, parents:false,siblings:false,children:false}
		var row = {id :0, socialHabitID:0,patientID:0,status:3,socialHabitType:'',socialHabitFrequency:'',comments:'',timeStamp:0}
		for(var i=0; i < patientSHs.length; i++)
		{
			if(patientSHs[i].socialHabitID == socialHabitID)
			{
				row = patientSHs[i]
				//return patientSH[i];
				break;
			}
		}
		return row;
	}
	
	this.hideQuestion = function(id,YesNo)
	{
		if(document.getElementById(this.id + id + '.div'))
		{
			if(YesNo == 1)
			{
				document.getElementById(this.id + id + '.div').style.display = 'block';
				if(document.getElementById(this.id + id +'.type'))
				{
				document.getElementById(this.id + id +'.type').focus();
				}
				else
				{
				document.getElementById(this.id + id +'.howmuch').focus();
				}
			}
			else
			{
				document.getElementById(this.id + id + '.div').style.display = 'none';
		}	}			
	}	
	
	
	this.getHtml = function(patientID, patientSHs)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Social History ('+ gpr.data.patients[patientID].firstName +')</td>' +
				'</tr>' 

		);

		   html.push('<tr>' +
					'<td id="' + this.id + 'socialHabit" class="panel-column-header">' +
						'Social Habit' +
					'</td>' +
					'<td align="center" id="' + this.id + '.status" class="panel-column-header">' +
						'Status' +
					'</td>' +
					'<td align="center" id="' + this.id + '.providerID" class="panel-column-header">' +
						'Comments' +
					'</td>' +
				'</tr>' 
				+
				'<tr><td>'+'&nbsp;'+'</td><td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
				'</tr>'
			)
		for( var i = 0; i < gpr.dictionaries.socialHabits.length; ++i)
		{
			var socialHabit = gpr.dictionaries.socialHabits[i];
			var patientSH = this.findSocialHistory(socialHabit.id, patientSHs)
			html.push(
					'<tr>' +
						'<td align="left" valign="top">' +
						 '<input type="hidden" name="' +  this.id + socialHabit.id + '.id" id="' +  this.id + socialHabit.id + '.id"  value="' + (patientSH.id) +  '">' +
						 '<input type="hidden" name="' +  this.id + socialHabit.id + '.id" id="' +  this.id + socialHabit.id + '.timestamp"  value="' + (patientSH.timeStamp) +  '">' +
						'<input type="hidden" name="' +  this.id + socialHabit.id + '.habitID" id="' +  this.id + socialHabit.id + '.habitID"  value="' + (socialHabit.id) +  '">' +
							gpr.htmlString(socialHabit.name) );
						html.push('</td>' +
						
						'<td align="center" valign="top">' +
							 //'<input type="checkbox" name="' +  this.id + condition.id + '.g" id="' +  this.id + condition.id + '.g" ' + (row.grandParents ? 'checked' : '') +  '>' +
						'<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._Yes" ' + (patientSH.status == 1 ? 'checked' : '') + ' value="' + 1 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 1  + ')">'+ '&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._No"  ' + (patientSH.status == 2 ? 'checked' : '') + ' value="' + 2 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 2  + ')">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._Unsure"  ' + (patientSH.status != 1 && patientSH.status != 2 ? 'checked' : '') + ' value="' + 3 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 3  + ')">'+
						
						'</td>'+'<td>');
						//if(socialHabit.id == 2)
						if(gpr.Trim(socialHabit.name) == 'Do you require a special diet?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;What type?&nbsp;&nbsp;&nbsp;'+
								'<input type="text" id="' + this.id + socialHabit.id +'.type" size="15"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="100"></span>')
							}
							//if(socialHabit.id == 3)
							if(gpr.Trim(socialHabit.name) == 'Do you smoke?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;How much per day? &nbsp;&nbsp;&nbsp;  '+
								'<input type="text" id="' + this.id + socialHabit.id +'.howmuch" size="8"  value="' + gpr.htmlString(patientSH.socialHabitFrequency) + '" ' + focusClass + ' maxlength="50"></span>')
							}
							//if(socialHabit.id == 4 || socialHabit.id == 5 )
							if(gpr.Trim(socialHabit.name) == 'Do you drink alcoholic beverages?' || gpr.Trim(socialHabit.name) == 'Do you use street drugs?' )
							{
							
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
																			
								html.push('<span '+ style + ' id="' +  this.id + socialHabit.id + '.div"><table style="border: 2px solid #ffffff"><tr style="border: 2px solid #ffffff"><td style="border: 2px solid #ffffff">What type?</td>'+
								'<td ><input type="text" id="' + this.id + socialHabit.id +'.type" size="15"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="100"></td></tr><tr><td >'+
								'How much per day?</td>'+
								'<td style="border: 2px solid #ffffff"><input type="text" id="' + this.id + socialHabit.id +'.howmuch" size="15"  value="' + gpr.htmlString(patientSH.socialHabitFrequency) + '" ' + focusClass + ' maxlength="50"></td></tr></table>'+
								'</span>'
								)
							}
							//if(socialHabit.id == 11)
							if(gpr.Trim(socialHabit.name) == 'Would you like information about Social Services to help you as a new parent?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;What help do you need? &nbsp;&nbsp;&nbsp;  '+
								'<input type="text" id="' + this.id + socialHabit.id +'.type" size="25"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="50"></span>')
							}
						html.push('<textarea id="' + this.id + socialHabit.id + '.comments" cols="40" rows="2" ' + focusClass + ' maxlength="500">' +
										gpr.htmlString(patientSH.comments) +
									'</textarea>'
						+'</td>' +
						
					'</tr>'
				);
			}
		
		html.push(		
						'<tr>' +
					'<td align="center" colspan="4">' +
						'<br><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
			) 
		
		return html.join('') 
	};
	
this.getBody = function()
{
	var body = ''
	var patientID =  document.getElementById(this.id + '.patientID').value || '0';
	body += 'patientID=' + patientID
	var ctr = 0;
	var blnResult = true;
	for( var i = 0; i < gpr.dictionaries.socialHabits.length; ++i)
	{
		var socialHabit = gpr.dictionaries.socialHabits[i]
		var id = document.getElementById(this.id + socialHabit.id +  '.id').value || '0';
		var habitID = document.getElementById(this.id + socialHabit.id + '.habitID').value || '0';
		var status = gpr.getRadioGroupValue(this.id + socialHabit.id + '.status') || '0';
		var comments = document.getElementById(this.id + socialHabit.id + '.comments').value || '';
		var timeStamp = document.getElementById(this.id + socialHabit.id +  '.timestamp').value || '0';
		var socialHabitType = '';
		var socialHabitFrequency = '';
		if(socialHabit.id == habitID)
		{
		var socialHabits = socialHabit.name;
		}
		
		if(document.getElementById(this.id + socialHabit.id + '.type'))
		{
			socialHabitType = document.getElementById(this.id + socialHabit.id + '.type').value;
		}
		if(document.getElementById(this.id + socialHabit.id + '.howmuch'))
		{
			socialHabitFrequency = document.getElementById(this.id + socialHabit.id + '.howmuch').value;
		}
		
		if(socialHabitType.length > 100)
		{	
			blnResult = false;
			alert('Please enter type with less than 100 characters ')
			document.getElementById(this.id + socialHabit.id + '.type').focus();	
		}
		else if (socialHabitFrequency.length > 50)
		{
			blnResult = false;
			alert('Please enter frequency with less than 50 characters ')
			document.getElementById(this.id + socialHabit.id + '.howmuch').focus();	
		}
		else if(comments.length > 500)
		{
			blnResult = false;
			alert('Please enter comments with less than 500 characters ')
			document.getElementById(this.id + socialHabit.id + '.comments').focus();
		}
		
		else if (id!= '0' || status != '3' ||  comments != '')
		{
		  body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + habitID + ',' +  status + ',' + socialHabitType + ',' + socialHabitFrequency + ',' + comments + ',' + timeStamp + ',' + socialHabits)
		}		
	}
	if(blnResult == true)
	{
	body += '&rowcount=' + ctr
	return body
	}
}

};




gpr.forms.patientSHEditCDW = function(id, onSubmit,onClose)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onClose = onClose;
	gpr.registry.add(this);

	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;

	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.findSocialHistory = function(socialHabitID, patientSHs)
	{
		//var row = {id :0, conditionID:0,grandParents:false, parents:false,siblings:false,children:false}
		var row = {id :0, socialHabitID:0,patientID:0,status:3,socialHabitType:'',socialHabitFrequency:'',comments:'',timeStamp:0}
		for(var i=0; i < patientSHs.length; i++)
		{
			if(patientSHs[i].socialHabitID == socialHabitID)
			{
				row = patientSHs[i]
				//return patientSH[i];
				break;
			}
		}
		return row;
	}
	
	this.hideQuestion = function(id,YesNo)
	{
		if(document.getElementById(this.id + id + '.div'))
		{
			if(YesNo == 1)
			{
				document.getElementById(this.id + id + '.div').style.display = 'block';
				if(document.getElementById(this.id + id +'.type'))
				{
				document.getElementById(this.id + id +'.type').focus();
				}
				else
				{
				document.getElementById(this.id + id +'.howmuch').focus();
				}
			}
			else
			{
				document.getElementById(this.id + id + '.div').style.display = 'none';
		}	}			
	}	
	
	
	this.getHtml = function(patientID, patientSHs)
	{
		var html = [];

		if(cdw == true)
	        {	
        	        html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ (cdw?'width="100%"':'') +'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
	        }

		
		html.push(
			'' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Social History ('+ gpr.data.patients[patientID].firstName +')</td>' +
				'</tr>' 

		);

		   html.push('<tr>' +
					'<td id="' + this.id + 'socialHabit" class="panel-column-header">' +
						'Social Habit' +
					'</td>' +
					'<td align="center" id="' + this.id + '.status" class="panel-column-header">' +
						'Status' +
					'</td>' +
					'<td align="center" id="' + this.id + '.providerID" class="panel-column-header">' +
						'Comments' +
					'</td>' +
				'</tr>' 
				+
				'<tr><td>'+'&nbsp;'+'</td><td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
				'</tr>'
			)
		for( var i = 0; i < gpr.dictionaries.socialHabits.length; ++i)
		{
			var socialHabit = gpr.dictionaries.socialHabits[i];
			var patientSH = this.findSocialHistory(socialHabit.id, patientSHs)
			html.push(
					'<tr>' +
						'<td align="left">' +
						 '<input type="hidden" name="' +  this.id + socialHabit.id + '.id" id="' +  this.id + socialHabit.id + '.id"  value="' + (patientSH.id) +  '">' +
						  '<input type="hidden" name="' +  this.id + socialHabit.id + '.id" id="' +  this.id + socialHabit.id + '.timestamp"  value="' + (patientSH.timeStamp) +  '">' +
						'<input type="hidden" name="' +  this.id + socialHabit.id + '.habitID" id="' +  this.id + socialHabit.id + '.habitID"  value="' + (socialHabit.id) +  '">' +
							gpr.htmlString(socialHabit.name) );
						html.push('</td>' +
						'<td align="center">' +
							 //'<input type="checkbox" name="' +  this.id + condition.id + '.g" id="' +  this.id + condition.id + '.g" ' + (row.grandParents ? 'checked' : '') +  '>' +
						'<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._Yes" ' + (patientSH.status == 1 ? 'checked' : '') + ' value="' + 1 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 1  + ')">'+ '&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._No"  ' + (patientSH.status == 2 ? 'checked' : '') + ' value="' + 2 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 2  + ')">'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + socialHabit.id + '.status"  id="' + this.id + socialHabit.id + '._Unsure"  ' + (patientSH.status != 1 && patientSH.status != 2 ? 'checked' : '') + ' value="' + 3 + '" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'hideQuestion\','+ socialHabit.id +  ',' + 3  + ')">'+
						
						'</td>'+'<td>');
						//if(socialHabit.id == 2)
						if(gpr.Trim(socialHabit.name) == 'Do you require a special diet?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;What type?&nbsp;&nbsp;&nbsp;'+
								'<input type="text" id="' + this.id + socialHabit.id +'.type" size="15"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="100"></span>')
							}
							//if(socialHabit.id == 3)
							if(gpr.Trim(socialHabit.name) == 'Do you smoke?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;How much per day? &nbsp;&nbsp;&nbsp;  '+
								'<input type="text" id="' + this.id + socialHabit.id +'.howmuch" size="8"  value="' + gpr.htmlString(patientSH.socialHabitFrequency) + '" ' + focusClass + ' maxlength="50"></span>')
							}
							//if(socialHabit.id == 4 || socialHabit.id == 5 )
							if(gpr.Trim(socialHabit.name) == 'Do you drink alcoholic beverages?' || gpr.Trim(socialHabit.name) == 'Do you use street drugs?' )
							{
							
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
																			
								html.push('<span '+ style + ' id="' +  this.id + socialHabit.id + '.div"><table style="border: 2px solid #ffffff"><tr style="border: 2px solid #ffffff"><td style="border: 2px solid #ffffff">What type?</td>'+
								'<td ><input type="text" id="' + this.id + socialHabit.id +'.type" size="15"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="100"></td></tr><tr><td >'+
								'How much per day?</td>'+
								'<td style="border: 2px solid #ffffff"><input type="text" id="' + this.id + socialHabit.id +'.howmuch" size="15"  value="' + gpr.htmlString(patientSH.socialHabitFrequency) + '" ' + focusClass + ' maxlength="50"></td></tr></table>'+
								'</span>'
								)
							}
							//if(socialHabit.id == 11)
							if(gpr.Trim(socialHabit.name) == 'Would you like information about Social Services to help you as a new parent?')
							{
								var style = "style=\"" + (patientSH.status == 1 ? "display:block" : "display:none") + "\"";
								html.push('<span ' + style + ' id="' +  this.id + socialHabit.id + '.div" >&nbsp;What help do you need? &nbsp;&nbsp;&nbsp;  '+
								'<input type="text" id="' + this.id + socialHabit.id +'.type" size="25"  value="' + gpr.htmlString(patientSH.socialHabitType) + '" ' + focusClass + ' maxlength="50"></span>')
							}
						html.push('<textarea id="' + this.id + socialHabit.id + '.comments" cols="40" rows="2" ' + focusClass + ' maxlength="500">' +
										gpr.htmlString(patientSH.comments) +
									'</textarea>'
						+'</td>' +
						
					'</tr>'
				);
			}
		
		html.push(		
						'<tr>' +
					'<td align="center" colspan="4">' +
						'<br><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
			) 
		
		return html.join('') 
	};
	
this.getBody = function()
{
	var body = ''
	var patientID =  document.getElementById(this.id + '.patientID').value || '0';
	if(document.getElementById('careDatauserID'))
		var careDatauserID = document.getElementById('careDatauserID').value;
	else
		var careDatauserID = '0';
		
	body += 'patientID=' + patientID
	body += '&careDataUserID=' + careDatauserID;
	
	var ctr = 0;
	var blnResult = true;
	for( var i = 0; i < gpr.dictionaries.socialHabits.length; ++i)
	{
		var socialHabit = gpr.dictionaries.socialHabits[i]
		var id = document.getElementById(this.id + socialHabit.id +  '.id').value || '0';
		var habitID = document.getElementById(this.id + socialHabit.id + '.habitID').value || '0';
		var status = gpr.getRadioGroupValue(this.id + socialHabit.id + '.status') || '0';
		var comments = document.getElementById(this.id + socialHabit.id + '.comments').value || '';
		var timeStamp = document.getElementById(this.id + socialHabit.id +  '.timestamp').value || '0';
		if(socialHabit.id == habitID)
		{
		var socialHabits = socialHabit.name;
		}
		var socialHabitType = '';
		var socialHabitFrequency = '';
		if(document.getElementById(this.id + socialHabit.id + '.type'))
		{
			socialHabitType = document.getElementById(this.id + socialHabit.id + '.type').value;
		}
		if(document.getElementById(this.id + socialHabit.id + '.howmuch'))
		{
			socialHabitFrequency = document.getElementById(this.id + socialHabit.id + '.howmuch').value;
		}
		
		if(socialHabitType.length > 100)
		{	
			blnResult = false;
			alert('Please enter type with less than 100 characters ')
			document.getElementById(this.id + socialHabit.id + '.type').focus();	
		}
		else if (socialHabitFrequency.length > 50)
		{
			blnResult = false;
			alert('Please enter frequency with less than 50 characters ')
			document.getElementById(this.id + socialHabit.id + '.howmuch').focus();	
		}
		else if(comments.length > 500)
		{
			blnResult = false;
			alert('Please enter comments with less than 500 characters ')
			document.getElementById(this.id + socialHabit.id + '.comments').focus();
		}
		
		else if (id!= '0' || status != '3' ||  comments != '')
		{
		  body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + habitID + ',' +  status + ',' + socialHabitType + ',' + socialHabitFrequency + ',' + comments + ',' + timeStamp+ ',' + socialHabits)
		}
		
	}
	if(blnResult == true)
	{
		body += '&rowcount=' + ctr 
	return body
	}
}

};


// **************************** : SOCIAL HISTORY END : *************************************
gpr.forms.patientPHs = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);
	
	this.getHtml = function(patientID, patientPHs)
	{
		var html = [];
						
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">PREGNANCIES ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Pregnancy</a></span></td></tr>' 

		);
		
		if(patientPHs.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add current or past pregnancies record  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Pregnancy" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
				'<td id="' + this.id + '.surgeryDate" class="panel-column-header">' +
						'Infant-Sex' +
					'</td>' +
					'<td id="' + this.id + '.delivarydate" class="panel-column-header">' +
						'Delivery Date' +
					'</td>' +
					'<td id="' + this.id + '.surgeryResult" class="panel-column-header">' +
						' Type of Delivery' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientPHs.length; ++i)
		{
			var item = patientPHs[i];
			html.push(
				'<tr>' +
					'<td>' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +
						(gpr.Trim((item.infantSex ==  gpr.gender.Male ? 'Boy' : 'Girl' ))?(item.infantSex ==  gpr.gender.Male ? 'Boy' : 'Girl' ):'--') +
					'</a></td>' +
					'<td>' +
						gpr.htmlString(gpr.Trim(item.dob)?item.dob:'--') +
						
					'</td>' +
					'<td>' +
						 (gpr.Trim(gpr.htmlString(item.deliveryTypeId == gpr.deliveryTypes.Vaginal ? 'Vaginal' : item.deliveryTypeId == gpr.deliveryTypes.CSection? 'C-Section' : 'VBAC' ))?gpr.htmlString(item.deliveryTypeId == gpr.deliveryTypes.Vaginal ? 'Vaginal' : item.deliveryTypeId == gpr.deliveryTypes.CSection? 'C-Section' : 'VBAC' ):'--') +
					'</td>' +					
					'<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' + '>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' + '>Close</a>'
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientPH= function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	 
	this.getHtml = function(patientID, patientPH)
	{
		var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
		patientPH = patientPH || {id:0, patientID:patientID,timeStamp:0};
		var isNew = patientPH.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientPH.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
		var html = [];
		
		if(cdw == true)
			{
	           html.push(
                       '<span style="float:right;">' +
                       '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\',1); return false;">' + 
					   '<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                       '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                       '</span>' +
                       '<table align="center">' +
						'<tr>' +
							'<td classl="gpr-panel-caption" colspan="2">' +
								'<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                            '</td>' +
                        '</tr></table>');
			}
			
		html.push(
			(isNew ? "<h3>Add a Pregnancy Record</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientPH.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientPH.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientPH.patientID + '">' +
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Pregnancy</td>' +
					'<td class="gpr-panel-caption" align="right" >'+ deleteHtml + '</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.deliveryDate" >Date Of Delivery<label>' +
								'</td>' +
								'<td>' +
								'<input type="text" id="'+ this.id+ '.deliveryDate" value="' + gpr.htmlString(patientPH.dob) + '" ' + focusClass + ' maxlength="10"/>' +
								'<a href="#" onclick="showCalendar(\'' + this.id + '.deliveryDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a> (mm/dd/yyyy)' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span><label for="' + this.id + '.duration" >Pregnancy Duration<label>' +
								'</td>' +
								'<td>' +
								'<input type="text" id="'+ this.id+ '.duration" value="' + gpr.htmlString(patientPH.duration) + '" ' + focusClass + ' maxlength="2"/>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span><label for="' + this.id + '.infantsex" >Infant Sex<label>' +
								'</td>' +
								'<td>' +
								'<input name="' + this.id + '.infantsex" id="' + this.id + '.gender-female" type="radio" ' + 
										(patientPH.infantSex == gpr.gender.Female ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-female" >Girl</label>' +
									'<input name="' + this.id + '.infantSex" id="' + this.id + '.gender-male" type="radio" ' + 
										(patientPH.infantSex == gpr.gender.Male ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.gender-male" >Boy</label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.infantWeight" >Infant Weight<label>' +
								'</td>' +
								'<td>' +
								'<input type="text" id="'+ this.id+ '.infantweight" value="' + gpr.htmlString(patientPH.infantWeight) + '"  ' + focusClass + ' maxlength="7"/>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.laborlength" >Labor Length<label>' +
								'</td>' +
								'<td>' +
								'<input type="text" id="'+ this.id+ '.laborlength" value="' + gpr.htmlString(patientPH.laborLength) + '" ' + focusClass + ' maxlength="2"/>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span><label for="' + this.id + '.duration" >Delivery Type<label>' +
								'</td>' +
								'<td>' +
								'<input name="' + this.id + '.deliveryTypeId" id="' + this.id + '.delivery-vaginal" type="radio" ' + 
										(patientPH.deliveryTypeId == gpr.deliveryTypes.Vaginal ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.delivery-vaginal" >Vaginal</label>' +
									'<input name="' + this.id + '.deliveryTypeId" id="' + this.id + '.delivery-csection" type="radio" ' + 
										(patientPH.deliveryTypeId == gpr.deliveryTypes.CSection ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + 'delivery-csection" >C Section</label>' +
									'<input name="' + this.id + '.deliveryTypeId" id="' + this.id + '.delivery-vbac" type="radio" ' + 
										(patientPH.deliveryTypeId == gpr.deliveryTypes.VBAC ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.delivery-vbac" >VBAC</label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.complications" >Complications<label>' +
								'</td>' +
								'<td>' +
								'<textarea  cols="50" id="'+ this.id+ '.complications" ' + focusClass + '>'+ gpr.htmlString(patientPH.complications) + ' </textarea>' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' + '>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'
		);
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var id = document.getElementById(this.id + '.id').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value || '0';
		var dob = document.getElementById(this.id + '.deliveryDate').value || '';
		var duration = document.getElementById(this.id + '.duration').value || '';
		var infantSex = document.getElementById(this.id + '.gender-male').checked || false;
		var	infantWeight = document.getElementById(this.id + '.infantweight').value || '';
		var	laborLength = document.getElementById(this.id + '.laborLength').value || '';
		var	complications = gpr.Trim(document.getElementById(this.id + '.complications').value) || '';
		var	delvaginal = document.getElementById(this.id + '.delivery-vaginal').checked || false;
		var	delcsection = document.getElementById(this.id + '.delivery-csection').checked || false;
		var deliveryTypeId = gpr.deliveryTypes.VBAC;
		if(delvaginal) 
			deliveryTypeId = gpr.deliveryTypes.Vaginal;
		else if(delcsection)
			deliveryTypeId = gpr.deliveryTypes.CSection;
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		
		if ( !gpr.Trim(dob) )
		{
			alert('Please enter Delivery Date.');
			document.getElementById(this.id + '.deliveryDate').focus();
		}
		else if(!gpr.isDate(dob))
		{
			document.getElementById(this.id + '.deliveryDate').focus();
		}
		else if (!gpr.Trim(duration))
		{
			alert('Please enter Pregnanacy Duration.');
			document.getElementById(this.id + '.duration').focus();
		}
		else if ( ! document.getElementById(this.id + '.gender-male').checked && ! document.getElementById(this.id + '.gender-female').checked )
		{
			alert('Please select infant sex.');
			document.getElementById(this.id + '.gender-female').focus();
		}
		else if(!gpr.forms.CheckForNumeric(infantWeight))
		{
			alert('please enter a valid infant weight');
			document.getElementById(this.id + '.infantweight').focus();
		}
		else if(!gpr.forms.CheckForNumber(laborLength))
		{
			alert('please enter a valid labour length.');
			document.getElementById(this.id + '.laborLength').focus();
		}
		else if (!document.getElementById(this.id + '.delivery-vaginal').checked && ! document.getElementById(this.id + '.delivery-csection').checked  && ! document.getElementById(this.id + '.delivery-vbac').checked )
		{
			alert('Please select one  Delivery Type.');
			document.getElementById(this.id + '.delivery-vaginal').focus();
		}
		else if ( new Date(dob) < new Date(gpr.data.patients[patientID].dob))
		{
			alert('Infant Date can not be less than  PatientsBirth Date!');
			document.getElementById(this.id + '.deliveryDate').focus();
		}
		else if(gpr.Trim(complications) && complications.length > 4000)
		{
			alert('Complications cannot exceed 4000 characters');
			document.getElementById(this.id + '.complications').focus();
		}		
		else
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(dob ? '&dob=' + encodeURIComponent(dob) : '' )+
				(duration ? '&duration=' + encodeURIComponent(duration) : '' )+
				 '&infantSex=' + (infantSex ?  '1' : '0') +
				(infantWeight ? '&infantweight=' + encodeURIComponent(infantWeight) : '') +
				(laborLength ? '&laborLength=' + encodeURIComponent(laborLength) : '') +
				(deliveryTypeId ? '&deliveryTypeId=' + encodeURIComponent(deliveryTypeId) : '') +
				(complications ? '&complications=' + encodeURIComponent(complications) : '&complications=') + 
				'&timeStamp=' + encodeURIComponent(timeStamp) +
				('&CareDataUserID=' + careDatauserID )
			);
		} 
	};

};

//******************** Pregnancy Details section Added by Manoj (Nous) : ******************
gpr.forms.patientPDs = function(id,onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);
	
	this.getHtml = function(patientID, patientPD)
	{
		var html = [];
		
		if(patientPD.length == 0)
		{
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="2" class="gpr-panel-caption">Pregnancy Details ('+ gpr.data.patients[patientID].firstName +') Part A</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', \'partB\'); return false;"' +
				'>Edit</a></span></td></tr>' );
				html.push('<tr><td colspan="3" align="center">To add Pregnancy Details - Part A  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit" button above </td></tr></table><br>')	
			html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="2" class="gpr-panel-caption">Pregnancy Details ('+ gpr.data.patients[patientID].firstName +') Part B</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', \'partA\'); return false;"' +
				'>Edit</a></span></td></tr>' );
				html.push('<tr><td colspan="3" align="center">To add Pregnancy Details - Part B  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit" button above </td></tr>')	
	
		}
		else
		{			
			html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="2" class="gpr-panel-caption">Pregnancy Details ('+ gpr.data.patients[patientID].firstName +') Part A</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\',\'partA\'); return false;"' +
				'>Edit</a></span></td></tr>' );
		var partA = true;			 
		for( var i = 0; i < patientPD.length; ++i)
		{
			var item = patientPD[i];
			if(item.type == 0)
			{
				if(partA)
				{
				partA = false;
				html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header" width="35%" >' +
						'Pregnancy Detail' +
					'</td>' +
					'<td id="' + this.id + '.response" class="panel-column-header" align="left"  width="20%">' +
						'Response' +
					'</td>' +
					'<td id="' + this.id + '.comments" class="panel-column-header" align="left"  width="45%">' +
						'Comments' +
					'</td>' +
					'</tr>')
				}
			html.push(
				'<tr>' +
					'<td width="35%">' +
						gpr.htmlString(item.pregnancyDetailID ? gpr.findID(gpr.dictionaries.pregnancyDetails, item.pregnancyDetailID, {name:''}).name : '') +
					'</td>' +
					'<td align="left" width="30%">&nbsp;' +
						gpr.htmlString(item.response) +
					'</td>' +
					'<td align="left" width="35%" cellpadding="5px">');
					if(gpr.htmlString(item.comments).length > 47)
						html.push( gpr.htmlString(item.comments).substring(0,47)+'...');
					else
						html.push(gpr.htmlString(gpr.Trim(item.comments)?item.comments:'--'));
							
					html.push('</td>' +
				'</tr>'
			);
			}
		}
		if(partA)
			{
				html.push('<tr><td colspan="3" align="center">To add Pregnancy Details - Part A  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit" button above </td></tr>')	
			}
		html.push('</table><br>');
		html.push('<table class="gpr-panel panel-border" width="90%"><tr><td colspan="2" class="gpr-panel-caption">Pregnancy Details ('+ gpr.data.patients[patientID].firstName +')  Part B</td>'+ '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\',\'partB\'); return false;"' +
				'>Edit</a></span></td></tr>');
				
		var first = true;
		for( var i = 0; i < patientPD.length; ++i)
		{
			var item = patientPD[i];
			
			if(item.type == 1)
			{	if(first)
				{
				first = false;
				 html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header" width="40%" >' +
						'Pregnancy Detail' +
					'</td>' +
					'<td id="' + this.id + '.status" class="panel-column-header" align="center"  width="15%">' +
						'Status' +
					'</td>' +
					'<td id="' + this.id + '.comments" class="panel-column-header" align="left"  width="45%">' +
						'Comments' +
					'</td>' +
					'</tr>')
				}
			html.push(
				'<tr>' +
					'<td width="50%">' +
						gpr.htmlString(item.pregnancyDetailID ? gpr.findID(gpr.dictionaries.pregnancyDetails, item.pregnancyDetailID, {name:''}).name : '') +
					'</td>' +
					'<td align="center" ' +
						(item.status == 1 ? '><img src="images/yes.gif">' : (item.status == 2 ? '><img src="images/new_no.gif">' : ' class="gpr-no">' )) +
					'</td>' +
					'<td align="left" cellpadding="5px">');
						if(gpr.htmlString(item.comments).length > 47)
							html.push(gpr.htmlString(item.comments).substring(0,47)+'...');
						else
							html.push(gpr.htmlString(gpr.Trim(item.comments)?item.comments:'--'));
					html.push('</td>' +
				'</tr>'
			);
			}
		}
			if(first)
			{
				html.push('<tr><td colspan="3" align="center">To add Pregnancy Details - Part B  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Edit" button above </td></tr>')	
			}
		}//ELSE CLOSE
				
		html.push(
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>'+
						'</span>' +
				'</div>' 
	
		) 
		
		return html.join('') 
	};
}

gpr.forms.patientPDEdit = function(id,onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	
	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	
	this.findPregnancyDetail = function(pregnancyDetailID, patientPDs)
	{
		//var row = {id :0, conditionID:0,grandParents:false, parents:false,siblings:false,children:false}
		var row = {id :0, pregnancyDetailID:0,patientID:0,status:3,response:'',otherDetails:'',comments:'',timeStamp:0}
		for(var i=0; i < patientPDs.length; i++)
		{
			if(patientPDs[i].pregnancyDetailID == pregnancyDetailID)
			{
				row = patientPDs[i]
				//return patientSH[i];
				break;
			}
		}
		return row;
	}
	
	this.getHtml = function(patientID, patientPDs,type)
	{
		
		var html = [];
		if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
		
		html.push(
			'' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			'<input id="' + this.id + '.type" type="hidden" value="' + type + '">' +
			'<br>' +
			'<Div id="partB"><table class="gpr-panel panel-border" width="95%">' +
			 ' <tr><td colspan="5" class="gpr-panel-caption">Pregnancy Details ('+ (cdw ? gpr.htmlString(gpr.data.patient.firstName):gpr.htmlString(gpr.data.patients[patientID].firstName)) +') Part A</td>' +
				'</tr>' 

		);
		

		   html.push('<tr>' +
					'<td id="' + this.id + '.pregnancyDetail" class="panel-column-header">' +
						'Pregnancy Detail' +
					'</td>' +
					'<td align="center" id="' + this.id + '.response" class="panel-column-header">' +
						'Response' +
					'</td>' +
					'<td align="center" id="' + this.id + '.comments" class="panel-column-header">' +
						'Comments' +
					'</td>' +
				'</tr>' 
				)
		for( var i = 0; i < gpr.dictionaries.pregnancyDetails.length; ++i)
		{
			var pregnancyDetail = gpr.dictionaries.pregnancyDetails[i];
			var patientPD = this.findPregnancyDetail(pregnancyDetail.id, patientPDs)
			if(pregnancyDetail.type == 0)
			{
			html.push(
					'<tr>' +
						'<td align="left" valign="top" width="41%">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.id" id="' +  this.id + pregnancyDetail.id + '.id"  value="' + (patientPD.id) +  '">' +
						 '<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.timestamp" id="' +  this.id + pregnancyDetail.id + '.timestamp"  value="' + (patientPD.timeStamp) +  '">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.pregnancyDetailID" id="' +  this.id + pregnancyDetail.id + '.pregnancyDetailID"  value="' + (pregnancyDetail.id) +  '">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.type" id="' +  this.id + pregnancyDetail.id + '.type"  value="' + (pregnancyDetail.type) +  '">' +
							pregnancyDetail.name );
						html.push('</td>' +
							'<td valign="top" width="18%">' +
							'<div style="padding-top: 3px" ><input type="text" id="' + this.id + pregnancyDetail.id +'.response" size="17"  value="' + gpr.htmlString(patientPD.response) + '" ' + focusClass + ' maxlength="50">');
						html.push('</input></div></td><td width="41%">');
						//if(pregnancyDetail.id == 3 || pregnancyDetail.id == 5 )
						if(gpr.Trim(pregnancyDetail.name) == 'Number of miscarriages' || gpr.Trim(pregnancyDetail.name) == 'Number of premature deliveries')
							{
							html.push('If yes, how far along were you? &nbsp;&nbsp;' + '<input type="text" id="' + this.id + pregnancyDetail.id +'.otherDetails" size="13"  value="' + gpr.htmlString(patientPD.otherDetails) + '" ' + focusClass + ' maxlength="100"><br>');
							}
						html.push('<textarea id="' + this.id + pregnancyDetail.id + '.comments" cols="35" rows="2" ' + focusClass + ' maxlength="150">' +
							gpr.htmlString(patientPD.comments) +
						'</textarea>'
						+'</td>' +
						
					'</tr>'
				);
			 }
			}
			html.push('<tr>' +
					'<td align="center" colspan="4">' +
						'<br><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table></table></div>') 
		html.push('<Div id="partA"><table class="gpr-panel panel-border" width="95%"> <tr><td colspan="5" class="gpr-panel-caption">Pregnancy Details ('+ (cdw ? gpr.htmlString(gpr.data.patient.firstName):gpr.htmlString(gpr.data.patients[patientID].firstName)) +') Part B</td>' +
				'</tr>');
		 html.push('<tr>' +
					'<td id="' + this.id + '.pregnancyDetail" class="panel-column-header">' +
						'Pregnancy History' +
					'</td>' +
					'<td align="center" id="' + this.id + '.status" class="panel-column-header">' +
						'Status' +
					'</td>' +
					'<td align="center" id="' + this.id + '.comments" class="panel-column-header">' +
						'Comments' +
					'</td>' +
				'</tr>' +
				'<tr><td>'+'&nbsp;'+'</td><td align="center">'+ '<font size="1"><b>' + '&nbsp;Yes'+ '</b></font>'+ '&nbsp;&nbsp;&nbsp;' + '<font size="1"><b>'+ 'No'+ '</b></font>'+ '&nbsp;&nbsp;'+ '<font size="1"><b>'+'Unsure'+ '</b></font>'+'</td>'+ 
				'<td>&nbsp;</td></tr>'
				)		
		
		for( var i = 0; i < gpr.dictionaries.pregnancyDetails.length; ++i)
		{
			var pregnancyDetail = gpr.dictionaries.pregnancyDetails[i];
			var patientPD = this.findPregnancyDetail(pregnancyDetail.id, patientPDs)
			if(pregnancyDetail.type == 1)
			{
			html.push(
					'<tr>' +
						'<td align="left">' +
						 '<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.id" id="' +  this.id + pregnancyDetail.id + '.id"  value="' + (patientPD.id) +  '">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.pregnancyDetailID" id="' +  this.id + pregnancyDetail.id + '.pregnancyDetailID"  value="' + (pregnancyDetail.id) +  '">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.timestamp" id="' +  this.id + pregnancyDetail.id + '.timestamp"  value="' + (patientPD.timeStamp) +  '">' +
						'<input type="hidden" name="' +  this.id + pregnancyDetail.id + '.type" id="' +  this.id + pregnancyDetail.id + '.type"  value="' + (pregnancyDetail.type) +  '">' +
							pregnancyDetail.name );
							html.push('</td>' +
						'</td>' +
						
						'<td align="center">' +
						'<input type="radio" style="width:12px" name="' + this.id + pregnancyDetail.id + '.status"  id="' + this.id + pregnancyDetail.id + '._Yes" ' + (patientPD.status == 1 ? 'checked' : '') + ' value="' + 1 + '" >'+ '&nbsp;&nbsp;'+
						
						'&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + pregnancyDetail.id + '.status"  id="' + this.id + pregnancyDetail.id + '._No"  ' + (patientPD.status == 2 ? 'checked' : '') + ' value="' + 2 + '" >'+ '&nbsp;&nbsp;'+
												 
						'&nbsp;&nbsp;&nbsp;<input type="radio" style="width:12px" name="' + this.id + pregnancyDetail.id + '.status"  id="' + this.id + pregnancyDetail.id + '._Unsure"  ' + (patientPD.status != 1 && patientPD.status != 2 ? 'checked' : '') + ' value="' + 3 + '" >'+
						
						'</td>'+'<td>'+
						'<textarea id="' + this.id + pregnancyDetail.id + '.comments" cols="35" rows="2" ' + focusClass + ' maxlength="150">' +
							gpr.htmlString(patientPD.comments) +
						'</textarea>'
						+'</td>' +
						
					'</tr>'
				);
			 }
		}
		
		html.push(		
						'<tr>' +
					'<td align="center" colspan="4">' +
						'<br><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Save</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table></Div>' 
			) 
		
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var body = ''
		var patientID =  document.getElementById(this.id + '.patientID').value || '0';
		var type =  (document.getElementById(this.id + '.type').value == 'partA' ? '0' : '1' );
		
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
			
		body += 'patientID=' + patientID
		body += '&careDatauserID=' + careDatauserID
		body += '&type=' + type
					
		var ctr = 0;
		var blnResult = true;
		
		for( var i = 0; i < gpr.dictionaries.pregnancyDetails.length; ++i)
		{
			var pregnancyDetail = gpr.dictionaries.pregnancyDetails[i]
			var id = document.getElementById(this.id + pregnancyDetail.id +  '.id').value || '0';
			var pregnancyDetailID = document.getElementById(this.id + pregnancyDetail.id + '.pregnancyDetailID').value || '0';
			var status = gpr.getRadioGroupValue(this.id + pregnancyDetail.id + '.status') || '3';
			var comments = document.getElementById(this.id + pregnancyDetail.id + '.comments').value || '';
			var response = ''
			var otherDetails = ''
			var type = document.getElementById(this.id + pregnancyDetail.id + '.type').value;
			var timeStamp = document.getElementById(this.id + pregnancyDetail.id +  '.timestamp').value || '0';
			
			if(pregnancyDetail.id == pregnancyDetailID)
			{
				var PrenancyDetails = pregnancyDetail.name;
			}
			
			if(document.getElementById(this.id + pregnancyDetail.id + '.response'))
			{
				response = document.getElementById(this.id + pregnancyDetail.id + '.response').value || '';
			}
			if(document.getElementById(this.id + pregnancyDetail.id + '.otherDetails'))
			{
				otherDetails = document.getElementById(this.id + pregnancyDetail.id + '.otherDetails').value || '';
			}
					
			if(response.length > 50)
			{	
				blnResult = false;
				alert('Please enter response with less than 50 characters ')
				document.getElementById(this.id + pregnancyDetail.id + '.response').focus();	
			}
			else if (otherDetails > 100)
			{
				blnResult = false;
				alert('Please enter other details with less than 100 characters ')
				document.getElementById(this.id + pregnancyDetail.id + '.otherDetails').focus();	
			}
			else if (comments.length > 150)
			{
				blnResult = false;
				alert('Please enter comments with less than 150 characters ')
				document.getElementById(this.id + pregnancyDetail.id + '.comments').focus();	
			}
			else if (id!= '0' || status != '3' ||  comments != '' || response != '')
			{
				body += '&row' + ctr++ + '=' +encodeURIComponent(id + ',' + pregnancyDetailID + ',' +  status + ',' + response + ',' + otherDetails + ',' + comments + ',' + type + ',' + timeStamp + ',' + PrenancyDetails)
			}
			
		}
		if(blnResult == true)
		{
		body += '&rowcount=' + ctr
		return body
	}
}

}

//******************** Pregnancy Details Section End : ******************

gpr.forms.patientSurgeries = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientSurgeries)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">SURGERIES/PROCEDURES ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Surgery</a></span></td></tr>' 

		);
		
		if(patientSurgeries.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add current or past surgery record  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Surgery" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + '.surgery" class="panel-column-header">' +
						'Surgery/Procedure' +
					'</td>' +
					'<td id="' + this.id + '.surgeryDate" class="panel-column-header">' +
						'Surgery Date' +
					'</td>' +
					'<td id="' + this.id + '.surgeryResult" class="panel-column-header">' +
						' Result' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientSurgeries.length; ++i)
		{
			var item = patientSurgeries[i];
			html.push(
				'<tr>' +
					'<td width="50%">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +

						(gpr.Trim(gpr.htmlString(item.surgeryID ? gpr.findID(gpr.dictionaries.surgeries, item.surgeryID, {name:''}).name : item.surgeryName))?gpr.htmlString(item.surgeryID ? gpr.findID(gpr.dictionaries.surgeries, item.surgeryID, {name:''}).name : item.surgeryName):'--') +
					'</a></td>' +
					'<td>' +
						(gpr.Trim((gpr.isNullDate(item.surgeryDate) ? '' : gpr.htmlString(item.surgeryDate)))?(gpr.isNullDate(item.surgeryDate) ? '' : gpr.htmlString(item.surgeryDate)):'--') +
					'</td>' +
					'<td>' +
						 gpr.htmlString(gpr.Trim(item.result)  || '--') +
					'</td>' +					
					'<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;" >' +
						/*'<a href="login.htm">Close</a>' */
						'<a href="javascript:void(0)" ' +'>Close</a>' +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientSurgery= function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;
	
	this.getHtml = function(patientID, patientSurgery)
	{
		patientSurgery = patientSurgery || {id:0, patientID:patientID,timeStamp:0};
		
		var isNew = patientSurgery.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientSurgery.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
				
		var html = [];
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
		html.push(
			(isNew ? "<h3>Add a Surgery</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientSurgery.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientSurgery.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientSurgery.patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Surgery</td>' +
					'<td class="gpr-panel-caption" align="right" >'+ deleteHtml + '</td>' +

				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.patientSurgeryD" >Select from the list<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>'
		);

		this.getSurgeryList(html, patientSurgery);		

		html.push(
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.patientSurgeryName" >Other Surgery<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.surgeryName" style="width:100%"  value="' + gpr.htmlString(patientSurgery.surgeryName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2">' +
						'<table class="gpr-panel-section" width="100%">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.surgeryDate" >Surgery Date<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.surgeryDate" id="' + this.id + '.surgeryDate" value="' + (gpr.isNullDate(patientSurgery.surgeryDate) ? '' : gpr.htmlString(patientSurgery.surgeryDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.surgeryDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.location" >Surgery Location<label>' +
								'</td>' +
								'<td>' +
									'<textarea id="' + this.id + '.location" cols="60"  ' + focusClass + '>' +
										gpr.htmlString(patientSurgery.location) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.surgeryResult" >Surgery Result<label>' +
								'</td>' +
								'<td>' +
									'<textarea id="' + this.id + '.result" cols="60"  ' + focusClass + ' maxlength="1000">' +
										gpr.htmlString(patientSurgery.result) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
							'<tr valign="top">' +
								'<td>' +
									'<label for="' + this.id + '.providerID" >Provider who performed this Surgery<label>' +
								'</td>' +
								'<td colspan="3">' +
								gpr.getProvidersList(this.id + '.providerID', patientSurgery.providerID) +
								' (If the provider is not listed, enter the provider\'s name below)' +
								'</td>' +
							'<tr><td>' +
									'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<input type="text" id="' + this.id + '.providerName" size="79" value="' + gpr.htmlString(patientSurgery.providerName) + '"  ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<textarea id="' + this.id + '.comments" cols="60"  ' + focusClass + ' maxlength="2000">' +
										gpr.htmlString(patientSurgery.comments) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" '+'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'
		);
			
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var id = document.getElementById(this.id + '.id').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value;
		var surgeryID = document.getElementById(this.id + '.surgeryID').value || '';
                var surgeryName = (!surgeryID)? gpr.Trim(document.getElementById(this.id + '.surgeryName').value || '') : '';
		var surgeryDate = document.getElementById(this.id + '.surgeryDate').value || '';
		var	providerID = document.getElementById(this.id + '.providerID').value || '';
                var     providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';
		var	comments = document.getElementById(this.id + '.comments').value || '';
		var	result = document.getElementById(this.id + '.result').value || '';
		var	location = document.getElementById(this.id + '.location').value || '';
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'

		if ( ! surgeryID && ! gpr.Trim(surgeryName) )
		{
			alert('Please select Surgery from the list or enter the name.');
			document.getElementById(this.id + '.surgeryID').focus();
		}
		else if(!gpr.Trim(surgeryDate))
		{
			alert('Please enter a Surgery Date')
			document.getElementById(this.id + '.surgeryDate').focus();
		}
		else if (! gpr.isDate(surgeryDate))
		{
			document.getElementById(this.id + '.surgeryDate').focus();
		}
		else if (new Date(surgeryDate) < new Date(gpr.data.patients[patientID].dob)) //surgeryDate &&  gpr.isDate(surgeryDate) && 
		{
				alert('Surgery Date can not be less than Birth Date!');
				document.getElementById(this.id + '.surgeryDate').focus();
		}
		else if(gpr.Trim(location) && location.length > 1000)
		{
			alert('Surgery location cannot exceed 1000 characters');
			document.getElementById(this.id + '.location').focus();
		}
		else if(gpr.Trim(result) && result.length > 1000)
		{
			alert('Surgery result cannot exceed 1000 characters');
			document.getElementById(this.id + '.result').focus();
		}
		else if(gpr.Trim(comments) && comments.length > 2000)
		{
			alert('Comments cannot exceed more than 2000 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		/*else if ( ! providerID && ! providerName )
		{
			alert('Please select a Provider from the list or enter the name of the provider if you dont find the provider in the list.');
		}*/
		else
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(surgeryID ? '&surgeryID=' + surgeryID : '' )+
				(surgeryName ? '&surgeryName=' + encodeURIComponent(surgeryName) : '' )+
				(surgeryDate ? '&surgeryDate=' + encodeURIComponent(surgeryDate) : '') +
				(providerID ? '&providerID=' + providerID : '') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '') +
				(location ? '&location=' + encodeURIComponent(location) : '') +
				(result ? '&result=' + encodeURIComponent(result) : '') + 
				'&timeStamp=' + encodeURIComponent(timeStamp) +
				('&CareDataUserID=' + careDatauserID )

			);
		} 
	};

	this.getSurgeryList = function(html, patientSurgery)
	{
		html.push(
			'<select id="' + this.id + '.surgeryID" ' + focusClass + '>' +
				'<option value=""></option>'
		);
		
		var im = gpr.dictionaries.surgeries;

		for ( var i = 0; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientSurgery.surgeryID )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push(gpr.htmlString(im[i].name));
			html.push('</option>');
			
		}
		
		html.push('</select>');
	};
};

gpr.forms.patientProviders = function(id, onAdd, onEdit,onClose,onAddNONCareDataProvider)
{
	this.id = id;
	this.onAdd = onAdd;
	this.onEdit = onEdit;
	this.onClose = onClose;
	this.onAddNONCareDataProvider = onAddNONCareDataProvider;

	gpr.registry.add(this);

	this.getHtml = function(patientID, patientProviders)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'* denotes Primary Care Provider'+
			'<table border = "0" width="90%">' +
			 ' <tr><td colspan="4" class="gpr-panel-caption">PROVIDERS/CLINICIANS ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAddNONCareDataProvider\', 0); return false;"' +
				'>Add Provider</a></span>&nbsp;&nbsp;<span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAdd\', 0); return false;"' +
				'>Search CareData Provider</a></span></td></tr></table><table class="gpr-panel panel-border" width="90%">' 

		);
		
		if(patientProviders.length == 0)
		{
			html.push('<tr><td colspan="5" align="center">To add a provider  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Provider" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + '.provider" class="panel-column-header">' +
						'Provider' +
					'</td>' +
					'<td id="' + this.id + '.phone" class="panel-column-header">' +
						'Phone' +
					'</td>' +
					'<td id="' + this.id + '.fax" class="panel-column-header">' +
						'Fax' +
					'</td>' +
					'<td id="' + this.id + '.expiryDate" class="panel-column-header">' +
						'Expiry Date' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientProviders.length; ++i)
		{
			var item = patientProviders[i];
			html.push(
				'<tr>' +
					'<td width="40%">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onEdit\', ' + item.id + '); return false;"' +
							'>' +

						(gpr.Trim(gpr.htmlString(item.provider.firstName + " " + item.provider.lastName))?gpr.htmlString(item.provider.firstName + " " + item.provider.lastName):'--') +
						(item.isPrimaryCareProvider == true ? '&nbsp;*' : '')+
					'</a></td>' +
					'<td>' + // modified by venkat, 28-02-2007, to format the phonenumber
						 gpr.htmlString(gpr.formatPhone(gpr.Trim(item.provider.phone)) || '--') +
					'</td>' +
					'<td>' +// modified by venkat, 28-02-2007, to format the fax
						 gpr.htmlString(gpr.formatPhone(gpr.Trim(item.provider.fax)) || '--') +
					'</td>' +					
					'<td>' +
						(gpr.isNullDate(item.expiryDate) ? '--' : gpr.htmlString(item.expiryDate) == '12/31/9999' ? 'N/A' :  gpr.htmlString(item.expiryDate) ) +
					'</td>' +
					'<td style="padding-top:2px;">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onEdit\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
	
		
		html.push(
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>' +
						'</span>' +
				'</div>' 
		
		) 
		
		return html.join('') 
	};
};

gpr.forms.searchProvider= function(id, onSearch, onAdd, onCancel)
{
	this.id = id;
	this.onSearch = onSearch;
	this.onAdd = onAdd;
	this.onCancel = onCancel;

	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	this.getHtml = function(patientID, patientProvider)
	{
		patientProvider = patientProvider || {id:0, patientID:patientID};
		var isNew = patientProvider.id == 0;

		var html = [];
		html.push(
			(isNew ? "<h3>Search a Provider</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientProvider.patientID + '">' +
			' You must search a provider in our network first. You can search a provider in a city or under a zipcode. If you don\'t find your provider in our network, in next screen you will be given a option to add your provider to your record' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="4">Search Provider</td>' +
				'</tr>' +
				'<tr><td> First Name </td> <td> Last Name </td> <td> Speciality </td> </tr>' +
				'<tr>' +
				'<td><input type="text" id="' + this.id + '.firstName" name="' + this.id + '.firstName" ' + focusClass + ' maxlength="50"> </td>' +
				'<td><input type="text" id="' + this.id + '.lastName" name="' + this.id + '.lastName" ' + focusClass + ' maxlength="50"> </td>' +
				'<td>')
				this.getSpecialityList(html) 
			html.push('</td>' +
				'</tr>' +
				'<tr>' +
                                '<tr><td> City </td> <td> State </td> <td> Zip </td> </tr>' +
				'<tr>' +
				'<td><input type="text" id="' + this.id + '.city" name="' + this.id + '.city"  ' + focusClass + ' maxlength="50"> </td>' +
				'<td>' +
				gpr.stateControl(this.id + '.state') +
				'</td>'+
				'<td><input type="text" id="' + this.id + '.zip" name="' + this.id + '.zip" ' + focusClass + ' maxlength="10"></td>' +
						'<td><span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSearch\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Search</a>' +
						'</span>' +
				'</td>' +
				'</tr>' +
			'</table>' +
			'<div id="' + this.id + '.result" ></div>' +
			'<br><center><span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">'+
			'<a href="javascript:void(0)" ' +'>Close</a></span></center>' );
		return html.join('') 
		
	};
	
	this.searchBody = function()
	{
		var firstName = document.getElementById(this.id + '.firstName').value;
		var lastName = document.getElementById(this.id + '.lastName').value || '';
		var specialityID = document.getElementById(this.id + '.specialityID').value || '';
		var city = document.getElementById(this.id + '.city').value || '';
		var	state = document.getElementById(this.id + '.state').value || '';
		var	zip = document.getElementById(this.id + '.zip').value || '';

		if ( ! gpr.Trim(city) && ! gpr.Trim(zip) )
		{
			alert('Please enter the city name or the zip code.');
			document.getElementById(this.id + '.city').focus();
		}
		else
		{
			return ( 
				(firstName ? 'firstName=' + encodeURIComponent(firstName) : '' )+
				(lastName ? '&lastName=' + encodeURIComponent(lastName) : '' )+
				(specialityID ? '&specialityID=' + encodeURIComponent(specialityID) : '') +
				(city ? '&city=' + encodeURIComponent(city) : '') +
				(state ? '&state=' + encodeURIComponent(state) : '') +
				(zip ? '&zip=' + encodeURIComponent(zip) : '' )
				);
		} 
	}
	
	this.displayResult = function(providers, onEdit)
	{
		var html = []
			html.push('<br><table class="gpr-panel panel-border" width="90%">' +
				'<tr><td colspan="3" class="gpr-panel-caption">Result</td></tr>')
				
			if(providers.length == 0)
			{
				html.push('<tr><td colspan="3" style="text-align:center;padding-top:5px">	No providers found for your critera.You can either change the critera and search again or you can ' +
				'<a href="javascript:void(0)" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAdd\'); return false;"' +
				'>Add a new provider</a></td></tr>')
				html.push('<tr>')
			}
			else
			{
				html.push('<tr><td colspan="3" style="text-align:center;padding-top:5px">	Do you find your provider below? If so, click the corresponding "Add this provider" button. Or you can ' +
				'<a href="javascript:void(0)" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAdd\'); return false;"' +
				'> Add a new provider</a></td></tr>')
				html.push('<tr>')

			}

		for( var i = 0; i < providers.length; ++i)
		{
			var provider = providers[i];
			
			html.push('<td>' +
					'<div>'+ provider.firstName + ' ' + provider.lastName + '</div>' +
					'<div>' + provider.line1 + '</div>' +
					'<div>' + provider.line2 + '</div>' +
					'<div>' + provider.city + ', ' + provider.state + ' ' + provider.zip + '</div>' +
					'<span class="dropshadow"  style="width:160px">' +
							'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onAdd\',\''+ i + '\'); return false;"' +
							'>Add this Provider</a>' +
						'</span>' +
					'</td>') 
			if( ((i+1) %  3)== 0)
			{
				html.push('</tr><tr>')
			}
		}
		
		html.push('</tr></table>')
		var result = document.getElementById(id + '.result')
		result.innerHTML  = html.join(' ')
	}
	
	this.onSelect = function(providerID)
	{
		this.onAdd(gpr.data.providers[providerID])
	}
	
	this.getSpecialityList = function(html, specialityID)
	{
		html.push(
			'<select id="' + this.id + '.specialityID" ' + focusClass + '>' +
				'<option value=""></option>'
		);
		
		var sp = gpr.dictionaries.specialities;

		for ( var i = 0; i < sp.length; ++i)
		{
			html.push('<option value="' + sp[i].id + '"');
			if ( sp[i].id == specialityID )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push(gpr.htmlString(sp[i].name));
			html.push('</option>');
			
		}
		
		html.push('</select>');
	};
}

gpr.forms.editProvider= function(id,onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);
	
	var focusClass = 'onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
 var cdw = (id.indexOf('ShowPatientReport') > 0)?true:false;
	this.getHtml = function(patientID, pp)
	{
		pp = pp || {id:0, patientID:patientID,timeStamp:0,provider:{id:0, careDataID:0, firstName:'', lastName:'', line1:'', line2:'', city:'',state:'', zip:'', specialityID:0,timeStamp:0}};
		var isNew = pp.id == 0;
		 var focusClass = pp.provider.careDataID == 0 ?  'onfocus="this.className = \'focus\'" onblur="this.className = \'\'" ' : '';
		var disabled = pp.provider.careDataID == 0 ? '' : 'class="readonlyTextBox" readonly="readonly"';
		if(cdw != true)
		{
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  pp.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
		}
		else
		{
		var deleteHtml  = '';
		}
		var html = [];
		if(cdw == true)
        {
                html.push(
                        '<span style="float:right" class="text_basic_small">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\',1); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
		html.push(
			(isNew ? "<h3>Add a Provider</h3>" : "<h3></h3>" )+
			
			'<input id="' + this.id + '.id" type="hidden" value="' + pp.id + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + pp.patientID + '">' +
			'<input id="' + this.id + '.ProvidertimeStamp" type="hidden" value="' + (pp.provider.timeStamp||'0') + '">' +
			'<input id="' + this.id + '.PPtimeStamp" type="hidden" value="' + (pp.timeStamp||'0') + '">' +
			'<input id="' + this.id + '.careDataID" type="hidden" value="' + pp.provider.careDataID + '">' +
			'<input id="' + this.id + '.providerID" type="hidden" value="' + pp.provider.id + '">' +
			'<input id="' + this.id + '.officeID" type="hidden" value="' + (pp.provider.OfficeID || pp.provider.officeID || '0') + '">' +
			
	
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">PROVIDER</td>' +
					'<td class="gpr-panel-caption" align="right">' + deleteHtml +'</td>' +
				'</tr>' +
				
				'<tr>' +
				'<td style="padding-right:0px;width:1px;top:0px;"><span class="reg-required">*</span></td><td style="padding-left:0px;" width="80px">First Name</td>' +
				'<td><input type="text" name="' + this.id + '.firstName" value="' + (pp.provider.firstName || '') + '" ' + disabled +  focusClass + '  style="width:40%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;"><span class="reg-required">*</span></td><td style="padding-left:0px;">Last Name</td>' +
				'<td><input type="text" name="' + this.id + '.lastName" value="' + (pp.provider.lastName || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Address</td>' +
				'<td><input type="text" name="' + this.id + '.line1" value="' + (pp.provider.line1 || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="100"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;"></td><td style="padding-left:0px;"></td>' +
				'<td><input type="text" name="' + this.id + '.line2" value="' + (pp.provider.line2 || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="100"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;"><span class="reg-required">*</span></td><td style="padding-left:0px;">City</td>' +
				'<td><input type="text" name="' + this.id + '.city" value="' + (pp.provider.city || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="50"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">State</td>' +
				'<td>'+ gpr.stateControl(this.id + '.state', pp.provider.state,  (disabled != ''?'disabled style="background-color:#d3d3d3;"':'')) +'</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Zip</td>' +
				'<td><input type="text" name="' + this.id + '.zip" value="' + (pp.provider.zip || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="10"></td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Phone</td>' +
				// modified by venkat, 28-02-2007, to format the phonenumber
				'<td><input type="text" name="' + this.id + '.phone" value="' + (gpr.formatPhone(gpr.Trim(pp.provider.phone)) || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Fax</td>' +
				// modified by venkat, 28-02-2007, to format the phonenumber
				'<td><input type="text" name="' + this.id + '.fax" value="' + (gpr.formatPhone(gpr.Trim(pp.provider.fax)) || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="14" ' + pNformatString +  '> (###)###-####</td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-right:0px;top:0px;"><span class="reg-required">*</span></td><td style="padding-left:0px;">Email</td>' +
				'<td><input type="text" name="' + this.id + '.email" value="' + (pp.provider.email || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="50"></td>' +
				'</tr>' );
				
				if(pp.provider.careDataID == '0')
				{
					html.push('<tr>' +
					'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;" valign="top">UPIN</td>' +
					'<td><input type="text" name="' + this.id + '.upin" value="' + (pp.provider.upin || '') + '" ' + disabled +  focusClass + ' style="width:40%" maxlength="50"> <br>(You can get this UPIN from your physican.If you don\'t provide the Provider\'s UPIN, your provider will not be able to access your record)</td>' +
					'</tr>' );
				}
				else
				{
					html.push('<tr><td colspan="2">'+
					'<input id="' + this.id + '.upin" type="hidden" value="' + (pp.provider.upin || '') + '">' +
					'</td></tr>');
				}

				html.push('<tr>' +
				'<td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Speciality</td>' +
				'<td>')
				this.getSpecialityList(html, pp.provider.specialityID, (disabled != ''?'disabled style="background-color:#d3d3d3;"':''))
				html.push('</td>' +
				'</tr>')// +
				
				if(pp.provider.careDataID == 0)
				{
					html.push(
					'<tr><td style="padding-right:0px;top:0px;" valign="top"><span class="reg-required">*</span></td><td style="padding-left:0px;" valign="top">Access Level</td>' +
					'<td><input type="radio" id="' + this.id + '.access.open" name="' + this.id + '.access" ' +focusClass + (pp.expiryDate == gpr.consts.maxDate ? ' checked' : '') + '>Always <br>' +
					'<input type="radio"  name="' + this.id + '.access" '+ focusClass + (pp.expiryDate == gpr.consts.maxDate ? '' : ' checked') +'> Until <input type="text" maxlength="10" name="'+ this.id + '.expirydate"' +  focusClass + (pp.expiryDate == gpr.consts.maxDate ? '' : 'value="' + (pp.expiryDate || '') + '"') +'>' +
					'<a href="#" onclick="showCalendar(\'' + this.id + '.expiryDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>  ' +									
					' (After this date, a Provider will not be able to access your medical record) ' +
					'<br> (mm/dd/yyyy)</td></tr>')// +
				}
				
				html.push(
				'<tr><td style="padding-right:0px;top:0px;">&nbsp;</td><td style="padding-left:0px;">Primary CareData Provider</td>'+
				'<td>'+ 
				'<input type="checkbox" id="' + this.id + '.isPCP"' + 
							(isNew ?'':(pp.isPrimaryCareProvider == false ? '' : 'checked')) +  '	>'				
				+'</td></tr>'
				);
				html.push(
				'<tr><td colspan="3"><hr></td></tr>' +
				'<tr>' +
					'<td align="center" colspan="3">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>' 
				)
			return html.join(' ')
		
	}
	
	this.getBody = function()
	{
	
		var ID = gpr.Trim(document.getElementById(this.id + '.ID').value || '0');
		var patientID = gpr.Trim(document.getElementById(this.id + '.patientID').value || '0');
		var careDataID = gpr.Trim(document.getElementById(this.id + '.careDataID').value || '0');
		var providerID = gpr.Trim(document.getElementById(this.id + '.providerID').value || '0');
		var officeID = gpr.Trim(document.getElementById(this.id + '.officeID').value || '0');
		var firstName = gpr.Trim(document.getElementById(this.id + '.firstName').value);
		var lastName = gpr.Trim(document.getElementById(this.id + '.lastName').value || '');
		var line1 = gpr.Trim(document.getElementById(this.id + '.line1').value || '');
		var line2 = gpr.Trim(document.getElementById(this.id + '.line2').value || '');
		var specialityID = gpr.Trim(document.getElementById(this.id + '.specialityID').value || '');
		var city = gpr.Trim(document.getElementById(this.id + '.city').value || '');
 		var	state = gpr.Trim(document.getElementById(this.id + '.state').value || '');
		var	zip = gpr.Trim(document.getElementById(this.id + '.zip').value || '');
		var	phone = gpr.Trim(document.getElementById(this.id + '.phone').value || '');
		var	fax = gpr.Trim(document.getElementById(this.id + '.fax').value || '');
		var	email = gpr.Trim(document.getElementById(this.id + '.email').value || '');
		var	upin = gpr.Trim(document.getElementById(this.id + '.upin').value || '');
		var isPCP = gpr.Trim(document.getElementById(this.id + '.isPCP').checked ? 'true' : 'false')
		var providertimeStamp = gpr.Trim(document.getElementById(this.id + ".ProvidertimeStamp").value || '0');
		var pptimeStamp = gpr.Trim(document.getElementById(this.id + ".PPtimeStamp").value || '0');
	
		
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		
		var	expiryDate;
		var	openAccess;
		
		var PrimaryCareProviderErr  = false;
		var pcprecordID = 0;
		var patientProviders = gpr.data.getCurrentPatientCollection('patientProviders');

		for( var i = 0; i < patientProviders.length; ++i)
		{
			if(patientProviders[i].patientID == patientID && patientProviders[i].isPrimaryCareProvider == true)
			{
				PrimaryCareProviderErr = true;
				pcprecordID = patientProviders[i].id;
				break;
			}
		}
		
		if(document.getElementById(this.id + '.access.open'))
		{
			expiryDate	 = document.getElementById(this.id + '.expiryDate').value || '';
			openAccess	 = document.getElementById(this.id + '.access.open').checked || false;
		}

		if(!gpr.Trim(firstName))
		{
			alert('Please enter a provider first name');
			document.getElementById(this.id + '.firstName').focus();
		}
		else if(!gpr.Trim(lastName))
		{
			alert('Please enter a provider last name');
			document.getElementById(this.id +'.lastName').focus();
		}
		else if ( ! gpr.Trim(city))
		{
			alert('Please enter the city name ');
			document.getElementById(this.id + '.city').focus();
		}
		else if(!gpr.Trim(email))
		{
			alert('Please enter a email');
			document.getElementById(this.id + '.email').focus();
		}
		else if(!gpr.forms.Checkemail(email))
		{
			document.getElementById(this.id + '.email').focus();
		}
		else if((openAccess != null) && !openAccess && !gpr.Trim(expiryDate))
		{
			alert('Please enter the expiry date');
			document.getElementById(this.id + '.expiryDate').focus();
		}
		else if((openAccess != null) && gpr.Trim(expiryDate) && !gpr.isDate(expiryDate))
		{
			document.getElementById(this.id + '.expiryDate').focus();
		}
		else if((openAccess != null) && new Date(expiryDate) < new Date())
		{
			alert('Expiry Date can not be less than today!');
			document.getElementById(this.id + '.expiryDate').focus();
		}
		else if (PrimaryCareProviderErr == true && isPCP ==  'true' && pcprecordID != ID)
		{
			alert('You have already assigned another provider as your primary care provider. Please deselect it to proceed further');
			document.getElementById(this.id + '.isPCP').focus();
			PrimaryCareProviderErr  = false;
		}
		else
		{
			return ( 
				'id=' + ID +
				'&patientID=' + patientID +
				'&caredataID=' + careDataID +
				'&providerID=' + providerID +
				'&officeID=' + officeID +
				(firstName ? '&firstName=' + encodeURIComponent(firstName) : '' )+
				(lastName ? '&lastName=' + encodeURIComponent(lastName) : '' )+
				(specialityID ? '&specialityID=' + encodeURIComponent(specialityID) : '') +
				(line1 ? '&line1=' + encodeURIComponent(line1) : '') +
				(line2 ? '&line2=' + encodeURIComponent(line2) : '') +
				(city ? '&city=' + encodeURIComponent(city) : '') +
				(state ? '&state=' + encodeURIComponent(state) : '') +
				(openAccess?'':(expiryDate ? '&expiryDate=' + encodeURIComponent(expiryDate) : '')) +
				(zip ? '&zip=' + encodeURIComponent(zip) : '' ) +
				(phone ? '&phone=' + encodeURIComponent(phone) : '' ) +
				(fax ? '&fax=' + encodeURIComponent(fax) : '' ) +
				(email ? '&email=' + encodeURIComponent(email) : '' ) +
				(upin ? '&upin=' + encodeURIComponent(upin) : '' ) + 
				('&CareDataUserID=' + careDatauserID )+
				('&isPCP='+ isPCP)+
				('&ProvidertimeStamp=' + providertimeStamp ) +
				('&PPtimeStamp=' + pptimeStamp) 
				
				);
		} 
	}
	
	this.getSpecialityList = function(html, specialityID, style)
	{
		html.push(
			'<select id="' + this.id + '.specialityID" ' + focusClass +  (style || '') + '>' +
				'<option value=""></option>'
		);
		
		var sp = gpr.dictionaries.specialities;

		for ( var i = 0; i < sp.length; ++i)
		{
			html.push('<option value="' + sp[i].id + '"');
			if ( sp[i].id == specialityID )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push(gpr.htmlString(sp[i].name));
			html.push('</option>');
		}
		html.push('</select>');
	};
}
/////////////// ALLERGY REVIEW HISTROY SECTION ///////////////////
gpr.forms.patientAllergiesReviewHistory= function(id,onClose)
{
	this.id = id;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID,patientAllergyReviewHistory)
	{
		var html = [];
		
		html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center" '+ 'Width="100%"'+'>' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" align="center" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
                                
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">ALLERGY REVIEW HISTORY  ('+ gpr.data.patients[patientID].firstName 				+')</td>'+'</tr>' 
		);
		
		if(patientAllergyReviewHistory.length == 0)
		{
		html.push('<tr><td colspan="3" align="center">No allergy review history for <i>' + gpr.data.patients		[patientID].firstName + ' </i> </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'date" class="panel-column-header">' +
						'Reviewed Date' +
					'</td>' +
					'<td id="' + this.id + '.comments" class="panel-column-header">' +
						'Comments' +
					'</td>' +
					'<td id="' + this.id + '.reviewed by" class="panel-column-header">' +
						'Reviewed By' +
					'</td>' +
					
				'</tr>')
		}
		for( var i = 0; i < patientAllergyReviewHistory.length; ++i)
		{
			var item = patientAllergyReviewHistory[i];
			if(item == null) continue;
			
			html.push(
				'<tr>' +
					'<td>' + gpr.htmlString(gpr.Trim(item.reviewDate)?item.reviewDate:'--') + '</td>' +
					'<td>' + gpr.htmlString(gpr.Trim(item.comments)?item.comments:'--') + '</td>' +
					'<td>' + gpr.htmlString(gpr.Trim(item.userName)?item.userName:'--') + '</td>' +
				
				'</tr>'
			);
		}
			
		html.push(
				'<TR><TD COLSPAN="3">'+
				'<div style="width:90%;text-align:center;padding:10px">' +
				'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' + '<a href="login.htm">Close</a></span>' +
				'</div>' +
					'</td>' +
				'</tr></TABLE>' 
			
		) 
		
		return html.join('') 
	};
		
};
/////////////// ALLERGY REVIEW HISTROY SECTION END ///////////////

gpr.forms.patientAllergies = function(id, onChange,onClose,onView)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	this.onView = onView;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientAllergies)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">ALLERGIES ('+ gpr.data.patients[patientID].firstName +')</td>'/* +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Allergy </a></span></td>*/+'</tr>' 
		);
		
		if(patientAllergies.length == 0)
		{
			//html.push('<tr><td colspan="3" align="center">To add allergies  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Allergy" button above </td></tr>')	
			html.push('<tr><td colspan="3" align="center">No allergies added for <i>' + gpr.data.patients[patientID].firstName + ' </i> </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'allergy" class="panel-column-header">' +
						'Allergy' +
					'</td>' +
					'<td id="' + this.id + '.mostRecentDate" class="panel-column-header">' +
						'Reactions' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientAllergies.length; ++i)
		{
			var item = patientAllergies[i];
			if(item == null) continue;
			if(gpr.htmlString(item.allergyID ? gpr.findID(gpr.dictionaries.allergies, item.allergyID, {name:''}).name : item.allergyName).length > 47 )
			{	
				var allergyName = gpr.htmlString(item.allergyID ? gpr.findID(gpr.dictionaries.allergies, item.allergyID, {name:''}).name : item.allergyName).substring(0,47)+'...';
			}
			else
			{
				var allergyName = gpr.htmlString(item.allergyID ? gpr.findID(gpr.dictionaries.allergies, item.allergyID, {name:''}).name : item.allergyName);
			}
			html.push(
				'<tr>' +
					'<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' +
					'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;"' +
							'>' +

						//gpr.htmlString(item.allergyID ? gpr.findID(gpr.dictionaries.allergies, item.allergyID, {name:''}).name : item.allergyName) +
						allergyName +
						'</a></td>' +
					'<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' )
					
						this.getReactionList(html,item.allergicReactionIDs)
						
				/*	html.push( (gpr.Trim(item.allergicReactionName) || '') + '</td>' +
					'<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '" style="padding-top:2px;" >' + 
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);*/
			html.push( (gpr.Trim(item.allergicReactionName) || '') + '</td>' +
					'<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '" style="padding-top:2px;" >' + 
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>View</a>' +
						'</span>' +
					'</td>' +
				'</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' commneted by nous and added a new line below which will call onclose function on button click.*/
							'<a href="javascript:void(0)" ' + '>Close</a>'
							
							 +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
		/*+ *(
		'<br><small>TODO:<ul>' +
			'<li>add some default width to the table' +
			'<li>fix Add  New and Edit buttons' +
			'<li>add edit date column' +
			'<li>implement column sorting' +
		'</ul></small>');*/
	};
	
	this.getReactionList = function(html, reactionIds)
	{
		var allergyreactions = '';
	
		for ( var a = 0; a < reactionIds.length; ++a)
		{
			allergyreactions = allergyreactions + (gpr.Trim(gpr.findID(gpr.dictionaries.allergicReactions, reactionIds[a], {name:''}).name)?gpr.findID(gpr.dictionaries.allergicReactions, reactionIds[a], {name:''}).name:'--')
		
			if(a == reactionIds.length-1)
			{
				allergyreactions = allergyreactions 
			}
			else
			{
				allergyreactions = allergyreactions  + ', '
			}
			//	html.push(a == reactionIds.length-1 ? '' : ', ')
		}
		if(allergyreactions.length > 47 )
		{
			allergyreactions = allergyreactions.substring(0,47)+'...';
		}
		html.push(allergyreactions);
	}	
};

gpr.forms.patientAllergy = function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;
	
	this.getHtml = function(patientID, patientAllergy)
	{
		patientAllergy = patientAllergy || {id:0, patientID:patientID, allergicReactionIDs:[ ]};
		var isNew = patientAllergy.id == 0;
		var html = [];
		
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end

		
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientAllergy.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'
		html.push(
			(isNew ? "<h3>Add a New Allergy</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientAllergy.id + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientAllergy.patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Allergy </td>' +
					'<td class="gpr-panel-caption" align="right" >'+ deleteHtml +'</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.allergyID" >Select from the list<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>'
		);

		this.getAllergyList(html, patientAllergy);		

		html.push(
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.allergyName">Other Allergy<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.allergyName" style="width:100%"  value="' + gpr.htmlString(patientAllergy.allergyName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Allergic Reactions</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'Select one or more' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>'
		);

		this.getAllergicReactionList(html, patientAllergy);		

		html.push(
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.allergicReactionName" >Other Reaction<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<input type="text" id="' + this.id + '.allergicReactionName" style="width:100%"  value="' + gpr.htmlString(patientAllergy.allergicReactionName) + '" ' + focusClass + ' maxlength="50">' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				
				'<tr>' +
					'<td colspan="2">' +
						'<table class="gpr-panel-section">' +
						'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isActive" >&nbsp;Active</label></td>'+
					'<td align="left">' +
						'<input type="checkbox" id="' + this.id + '.isActive"' + (patientAllergy.isActive == true ? 'checked' : (patientAllergy.id == 0 ? 'checked' : '')) +  '>'+
					'</td>'	+ 
				'</tr>' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.onsetDate" >Date of Onset<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.onsetDate" id="' + this.id + '.onsetDate" value="' + (gpr.isNullDate(patientAllergy.onsetDate) ? '' : gpr.htmlString(patientAllergy.onsetDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.onsetDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
								'<td>' +
									'<span class="reg-required">*</span>' + 
									'<label for="' + this.id + '.mostRecentDate" >Date of Last Episode<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" datepicker="true"  name="' + this.id + '.mostRecentDate" id=DPC_"' + this.id + '.mostRecentDate" value="' + (gpr.isNullDate(patientAllergy.mostRecentDate) ? '' : gpr.htmlString(patientAllergy.mostRecentDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.mostrecentDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.threatment" >Treatment Method<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<textarea id="' + this.id + '.threatment" style1="width1:100%;overflow:hidden" maxlength="1000" cols="60">' +
										gpr.htmlString(patientAllergy.threatment) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
							'<tr valign="top">' +
								'<td>' +
									'<label for="' + this.id + '.providerID" >Provider treating this Allergy<label>' +
								'</td>' +
								'<td colspan="3">' +
									gpr.getProvidersList(this.id + '.providerID', patientAllergy.providerID) +
									' (If the provider is not listed, enter the provider\'s name below)' +
									'</td>' +
							'<tr><td>' +
									'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<input type="text" id="' + this.id + '.providerName" maxlength="100" size="79" value="' + gpr.htmlString(patientAllergy.providerName) + '"  ' + focusClass + '>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<div style="overflow:hidden"><textarea id="' + this.id + '.comments"  cols="60" maxlength="1000">' +
										gpr.htmlString(patientAllergy.comments) +
									'</textarea></div>' +
								'</td>' +
							'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
						'</td>' +
				'</tr>' +
			'</table>'
		);
			
		return html.join(''); 
		/*+ (
		'<br><small>TODO:<ul>' +
			'<li>add some default width to the table' +
			'<li>fix html styles and remove inlline styles' +
			'<li>form validation' +
		'</ul></small>');*/
	};
	
	
	this.getBody = function()
	{
		var id = document.getElementById(this.id + '.id').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value;
		var allergyID = document.getElementById(this.id + '.allergyID').value || '';
                var allergyName = (!allergyID)? gpr.Trim(document.getElementById(this.id + '.allergyName').value || '') : '';
		var allergicReactionIDs = this.getAllergicReactionSelection().join(',');
                var allergicReactionName = (!allergicReactionIDs)? gpr.Trim(document.getElementById(this.id + '.allergicReactionName').value || '') : '';
		var onsetDate = document.getElementById(this.id + '.onsetDate').value || '';
		var mostRecentDate = document.getElementById(this.id + '.mostRecentDate').value || '';
		var	threatment = document.getElementById(this.id + '.threatment').value || '';
		var	providerID = document.getElementById(this.id + '.providerID').value || '';
                var     providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';
		var	comments = document.getElementById(this.id + '.comments').value || '';
		var isActive = (document.getElementById(this.id+ '.isActive').checked==true ? true: false)
			//Below lines added by manoj for Audit log
		if(document.getElementById('careDatauserID'))
		var careDatauserID = document.getElementById('careDatauserID').value;
		
		else
		var careDatauserID = '0';
		
		
		if ( ! allergyID && !gpr.Trim(allergyName))
		{
			alert('Please select an Allergy.');
			document.getElementById(this.id + '.allergyID').focus();
		}
		else if ( ! allergicReactionIDs && ! gpr.Trim(allergicReactionName) )
		{
			alert('Please select Allergic Reaction.');
			var ar = gpr.dictionaries.allergicReactions;
			document.getElementById(this.id + '.allergicReaction.' + ar[0].id).focus();
		}
		else if(!gpr.Trim(onsetDate))
		{
			alert('Please enter a on set date');
			document.getElementById(this.id + '.onsetDate').focus();
		}
		else if (! gpr.isDate(onsetDate))
		{
			document.getElementById(this.id + '.onsetDate').focus();
		}
		else if (new Date(onsetDate) < new Date(gpr.data.patients[patientID].dob))
		{
			alert('On set Date can not be less than  Birth Date!');
			document.getElementById(this.id + '.onsetDate').focus();
		}
		else if(!gpr.Trim(mostRecentDate))
		{
			alert('Please enter a most recent date');
			document.getElementById(this.id + '.mostRecentDate').focus();
		}
		else if (! gpr.isDate(mostRecentDate))
		{
			document.getElementById(this.id + '.mostRecentDate').focus();
		}
		else if (new Date(mostRecentDate) < new Date(gpr.data.patients[patientID].dob))
		{
			alert('Most Recent Date can not be less than  Birth Date!');
			document.getElementById(this.id + '.mostRecentDate').focus();
		}
		else if(gpr.Trim(threatment) && threatment.length > 2000)
		{
			alert('Treatment method cannot exceed 2000 characters');
			document.getElementById(this.id + '.threatment').focus();
		}
		else if(gpr.Trim(comments) && comments.length > 4000)
		{
			alert('Comment cannot exceed 4000 characters');
			document.getElementById(this.id + '.comments').focus();
		}

		/*else if ( ! providerID && ! providerName )
		{
			alert('Please select a Provider from list or enter your provider\'s name.');
		}*/
		else
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(allergyID ? '&allergyID=' + allergyID : '' )+
				(allergyName ? '&allergyName=' + encodeURIComponent(allergyName) : '' )+
				(allergicReactionIDs ? '&allergicReactionIDs=' + encodeURIComponent(allergicReactionIDs) : '') +
				(allergicReactionName ? '&allergicReactionName=' + encodeURIComponent(allergicReactionName) : '') +
				(onsetDate ? '&onsetDate=' + encodeURIComponent(onsetDate) : '') +
				(mostRecentDate ? '&mostRecentDate=' + encodeURIComponent(mostRecentDate) : '') +
				(threatment ? '&threatment=' + encodeURIComponent(threatment) : '') +
				(providerID ? '&providerID=' + providerID : '') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '') + 
				'&isActive=' + encodeURIComponent(isActive) +
				('&CareDataUserID=' + careDatauserID )
			);
		} 
	};

	this.getAllergyList = function(html, patientAllergy)
	{
		html.push(
			'<select id="' + this.id + '.allergyID" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectAllergy\', this); return false;">' +
				'<option value=""></option>'
		);
		
		var alg = gpr.dictionaries.allergyGroups;
		var al = gpr.dictionaries.allergies;
		
		for ( var g = 0; g < alg.length; ++g)
		{
			html.push('<option value="">');
			html.push(gpr.htmlString(alg[g].name));
			//html.push(' (');
			//html.push(gpr.htmlString(alg[g].description));
			//html.push(' )');
			html.push('</option>');
			
			for ( var a = 0; a < al.length; ++a)
			{
				if ( al[a].groupID == alg[g].id )
				{
					html.push('<option value="' + al[a].id + '"');
					if ( al[a].id == patientAllergy.allergyID )
					{
						html.push(' selected ');
					}
					html.push('>&nbsp;&nbsp;&nbsp;&nbsp;');
					html.push(gpr.htmlString(al[a].name));
					html.push('</option>');
				}
			}
		}
		html.push('</select>');
	};
	
	this.onSelectAllergy = function(select)
	{
		if ( ! select.options[select.selectedIndex].value )
		{
			select.selectedIndex = 0;
		}
	}
	
	this.getAllergicReactionList = function(html, patientAllergy)
	{	
		html.push('<table width="100%"><tr>')
		var ar = gpr.dictionaries.allergicReactions;
		for ( var a = 0; a < ar.length; ++a)
		{
			html.push('<td>')
			//html.push('<span style="white-space:">');
			html.push('<input type="checkbox" id="' + this.id + '.allergicReaction.' + ar[a].id + '" ');
			html.push(' value="' + ar[a].id + '" ');
			if ( gpr.find(patientAllergy.allergicReactionIDs, ar[a].id) )
			{
				html.push(' checked ');
			}
			html.push('>');
			html.push(' <label for="' + this.id + '.allergicReaction.' + ar[a].id + '" >');
			html.push(gpr.htmlString(ar[a].name));
			html.push('</label>');
			html.push('</td>')
			if((a+1) % 4 == 0)
			{
			  html.push('</tr><tr>')
			}
			//html.push('</span>');
		}
		html.push('</table>')
	}
	this.getAllergicReactionSelection = function()
	{
		var ar = gpr.dictionaries.allergicReactions;
		var reactions = [];
		for ( var a = 0; a < ar.length; ++a)
		{
			reaction = document.getElementById(this.id + '.allergicReaction.' + ar[a].id)
			if ( reaction.checked )
			{
				reactions.push(reaction.value)
			}
		}
		return reactions;
	}
};


gpr.forms.patientAllergyReviewHistory = function(id,onSubmit,onCancel)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;
	
	var currentTime = new Date()
	var month = currentTime.getMonth() + 1
	var day = currentTime.getDate()
	var year = currentTime.getFullYear()
	
	this.getHtml = function(patientID)
	{
		var html = [];
		
	    if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        
        html.push(
			"<h3>Allergy List Review History</h3>"+
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="80%">' +
			'<tr>' +
					'<td class="gpr-panel-caption">Allergy List Review Details</td>' +
					'<td class="gpr-panel-caption" align="right" >'+ '' +'</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" colspan="2">' +
						'<table class="gpr-panel-section" width="100%">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.allergyreviewDate" >Date<label>' +
								'</td>' +
								'<td>'+
								'<input type="text" name="' + this.id + '.reviewedDate" id="' + this.id + '.reviewedDate" value="' +(month + "/" + day + "/" + year) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.reviewedDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr>' +
							'<td>' +
								'<span class="reg-required">*</span>' +
								'<label for="' + this.id + '.allergyreviewComments" >Comments<label>' +
							'</td>' +
							'<td>' + 
							'<textarea id="' + this.id + '.comments"  cols="50" maxlength="1000">' +													
							'</textarea></td>' +
							'</tr>' +
							'<tr>'+'<td height="10px"></td></tr>'+
							'<tr>' +
							'<td colspan="2" align="center"><hr></td>' +
							'</tr>' +
							'<tr>' +
							'<td align="center" colspan="2">' +
							'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;">' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
							'</span>' +
							'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
							'</span>' +
							'</td>' +
						'</tr>' +
					'</table>');
					
					return html.join(''); 

			}
			
			
	this.getBody = function()
	{
		var patientID = document.getElementById(this.id + '.patientID').value;
		var reviewedDate = document.getElementById(this.id + '.reviewedDate').value || '';
		var	comments = document.getElementById(this.id + '.comments').value || '';
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
			
		var revDate,currDate;
		revDate = new Date(reviewedDate)
		currDate = new Date(gpr.data.patient.currentDate);
		
		if(revDate > currDate)
		{
			alert("Date should be less than or equal to today's date.");	
		}
		else if(!gpr.Trim(reviewedDate))
		{
			alert('Please enter a review date');
			document.getElementById(this.id + '.reviewedDate').focus();
		}
		else if (! gpr.isDate(reviewedDate))
		{
			document.getElementById(this.id + '.reviewedDate').focus();
		}
		else if(gpr.Trim(comments).length == 0)
		{
			alert('Please enter comments');
			document.getElementById(this.id + '.comments').focus();
		}
		else if(gpr.Trim(comments) && comments.length > 100)
		{
			alert('Comment cannot exceed 100 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		else
		{
			return (
				'id=0' +
				'&patientID=' + patientID + 
				(reviewedDate ? '&reviewedDate=' + encodeURIComponent(reviewedDate) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '') + 
				('&CareDataUserID=' + careDatauserID )
			);
		
		}
	}
};


gpr.forms.patientAllergyView = function(id,onCancel)
{
	this.id = id;
	this.onCancel = onCancel;
	gpr.registry.add(this);

	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;

	this.getHtml = function(patientID, patientAllergy)
	{
		patientAllergy = patientAllergy || {id:0, patientID:patientID, allergicReactionIDs:[ ]};
		var isNew = patientAllergy.id == 0;
		var html = [];
	  if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + 				gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }

	html.push(
			(isNew ? "<h3>Add a New Allergy</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientAllergy.id + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientAllergy.patientID + '">' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Allergy </td>' +
				'</tr>' +
				'<tr>' +
				'<td style="padding-bottom:5px" colspan="2">' +
				 '<table class="gpr-panel-section">' +
				 '<tr>' +
				 	'<td>' +
						'<label for="' + this.id + '.allergyID" >Allergy Name	:<label>' +
					'</td>' +
					'<td>'+
						gpr.htmlString(patientAllergy.allergyID ? gpr.findID(gpr.dictionaries.allergies, patientAllergy.allergyID, {name:''}).name : patientAllergy.allergyName)  +
					'</td>' + 
						'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +
				/*'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Allergic Reactions</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" colspan="2">' +
						'<table class="gpr-panel-section">' +
							'<tr>' +
								'<td>' +
								'</td>' +
							'</tr>' +
							'<tr valign="center" heigth="15">' +
							'<td>')
							this.getReactionList(html,patientAllergy.allergicReactionIDs)
							html.push('</td>' +
							'</tr>' +
							'</table>' +
					'</td>' +
				'</tr>' +*/
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				/*'<tr>' +
					'<td colspan="2">' +
						'<table class="gpr-panel-section">' +
						'<tr height="10">' +
					'<td>' +
						'<label for="' + this.id + '.isActive" >Active	</label></td>'+
					'<td align="left">' + ': ' +
						(patientAllergy.isActive == true ? 'Yes' : (patientAllergy.id == 0 ? 'Yes' : 'No')) + 
					'</td>'	+ 
				'</tr>' +
							'<tr height="10">' +
								'<td>' +
									'<label for="' + this.id + '.onsetDate" >Date of Onset<label>' +
								'</td>' +
								'<td>' +
									': ' +(gpr.isNullDate(patientAllergy.onsetDate) ? '--' : gpr.htmlString(patientAllergy.onsetDate)) +
									'</td>' +
							'</tr>' +
							'<tr height="10">'+
							'<td>' +
									'<label for="' + this.id + '.mostRecentDate" >Date of Last Episode<label>' +
								'</td>' +
								'<td>' +
									': ' +(gpr.isNullDate(patientAllergy.mostRecentDate) ? '--' : gpr.htmlString(patientAllergy.mostRecentDate))+
								'</td>' +
							'</tr>'+
							'<tr valign="top" height="10">' +
								'<td>' +
									'<label for="' + this.id + '.threatment" >Treatment Method<label>' +
								'</td>' +
								'<td colspan="3">' +
										': ' + (gpr.htmlString(patientAllergy.threatment).length == 0 ? '--' : gpr.htmlString(patientAllergy.threatment)) +
								'</td>' +
							'</tr>' +*/
							'<tr valign="top" height="10">' +
								'<td width="25%">' +
									'<label for="' + this.id + '.active" >Active<label>' +
								'</td>' +
								'<td>' +
										': ' +  (patientAllergy.isActive ? 'Yes' : 'No') + '</td>' +
							'</tr>' +
							'<tr valign="top" height="10">' +
								'<td width="25%">' +
									'<label for="' + this.id + '.providerID" >Provider treating this Allergy<label>' +
								'</td>' +
								'<td>' +
										': ' + (gpr.Trim(gpr.htmlString(patientAllergy.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientAllergy.providerID, ' ') : patientAllergy.providerName))?gpr.htmlString(patientAllergy.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientAllergy.providerID, '--') : patientAllergy.providerName):'--') 									
								+'</td>' +
							'</tr>' +
							'<tr  valign="top" height="10">' +
								'<td width="25%">' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td>' +
									': ' + (gpr.htmlString(patientAllergy.comments).length == 0 ? '--' :gpr.htmlString(patientAllergy.comments)) +
								'</td>' +
							'</tr>' +
						//'</table>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2"><hr></td>' +
				'</tr>' +
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
						'</td>' +
				'</tr>' +
			'</table>'
				
		
		);
		return html.join(''); 
		}
		
		
	this.getReactionList = function(html, reactionIds)
	{
		var allergyreactions = '';
	
		for ( var a = 0; a < reactionIds.length; ++a)
		{
			allergyreactions = allergyreactions + (gpr.Trim(gpr.findID(gpr.dictionaries.allergicReactions, reactionIds[a], {name:''}).name)?gpr.findID(gpr.dictionaries.allergicReactions, reactionIds[a], {name:''}).name:'--')
		
			if(a == reactionIds.length-1)
			{
				allergyreactions = allergyreactions 
			}
			else
			{
				allergyreactions = allergyreactions  + ', '
			}
			//	html.push(a == reactionIds.length-1 ? '' : ', ')
		}
		html.push((allergyreactions.length == 0 ? '--' : allergyreactions));
	}
};


gpr.forms.patientMedications = function(id, onChange,onClose,onSaveCurrentMedicationStatus,onView)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	this.onSaveCurrentMedicationStatus = onSaveCurrentMedicationStatus
	this.onView	 = onView;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientMedications)
	{
		var html = [];
		var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="4" class="gpr-panel-caption">MEDICATIONS ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right" ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Medication </a></span></td></tr>'+
				'<tr><td colspan="5" class="gpr-panel-alternate">'+ 
				'<b>Are you takig any medication currently ?</b> '+ 
				'<input type="radio" name="' + this.id + '.isCurrentMedicationAvailable"  id="' + this.id + '.isCurrentMedicationAvailableYes" ' + (gpr.data.patients[patientID].isCurrentMedicationAvailable == 1 ? 'checked' : '') +  focusClass + 'value="1" >Yes' + '&nbsp;' +
				'<input type="radio" name="' + this.id + '.isCurrentMedicationAvailable"  id="' + this.id + '.isCurrentMedicationAvailableNo" ' +  (gpr.data.patients[patientID].isCurrentMedicationAvailable == 0 ? 'checked' : '')  + focusClass + ' value="0">No' +
				'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
				'<a class1="item1" href="javascript:void(0)"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSaveCurrentMedicationStatus\'); return false;" href="javascript:void(0)">Save</a>'+
				'<input id="' + this.id + '.patientID" type="hidden" value="' + patientID + '">' 
		);
		
		if(patientMedications.length == 0)
		{
			html.push('<tr><td colspan="5" align="center">To add medication  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Medication" button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'medication" class="panel-column-header">' +
						'Medication' +
					'</td>' +
					'<td id="' + this.id + '.form" class="panel-column-header">' +
						'Form' +
					'</td>' +
					'<td id="' + this.id + '.strength" class="panel-column-header">' +
						'Strength' +
					'</td>' +
					'<td id="' + this.id + '.frequency" class="panel-column-header">' +
						'Frequency' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientMedications.length; ++i)
		{
			var item = patientMedications[i];
			var medicationName = ((gpr.Trim(gpr.htmlString(item.medicationID ? gpr.findID(gpr.dictionaries.medications, item.medicationID, {name:''}).name : item.medicationName))?gpr.htmlString(item.medicationID ? gpr.findID(gpr.dictionaries.medications, item.medicationID, {name:''}).name : item.medicationName):'--'));
			if(medicationName.length >47)
			{
					medicationName = medicationName.substring(0,47)+'...';
			}
			
			html.push( '<tr>' );
			if(item.careDataRecordID == 0)
			{
				html.push( '<td class="' + (item.isCurrent ?  '' : 'gpr-disable-row' ) + '">' +
						'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' + medicationName + '</a></td>');
			}
			else
			{
				html.push( '<td class="' + (item.isCurrent ?  '' : 'gpr-disable-row' ) + '">' +
						'<a href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;"' +
							'>' + medicationName + '</a></td>');
			}
					
			html.push('<td class="' + (item.isCurrent ?  '' : 'gpr-disable-row' ) + '">' +
						(gpr.Trim(gpr.findID(gpr.dictionaries.medicationForms, item.formID, {name:''}).name)?gpr.findID(gpr.dictionaries.medicationForms, item.formID, {name:''}).name:'--')+
					'</td>' +
					'<td class="' + (item.isCurrent ?  '' : 'gpr-disable-row' ) + '">' +
						(gpr.Trim((item.strength || '' )  + gpr.findID(gpr.dictionaries.medicationUnits, item.unitID, {name:''}).name)?(item.strength || '' )  + gpr.findID(gpr.dictionaries.medicationUnits, item.unitID, {name:''}).name:'--')  +
					'</td>' +
					'<td  class="' + (item.isCurrent ?  '' : 'gpr-disable-row' ) + '">' +
						(gpr.Trim(item.frequency)?item.frequency:'--') + // || '' ) +
					'</td>' );
					
					/*'<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a href="javascript:void(0)" ' +'>Edit</a>' +
						'</span>' +
					'</td>' +*/
					if(item.careDataRecordID == 0)
					{
					html.push('<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a class="dropshadow" href="javascript:void(0)" ' + '>Edit</a>' +
						'</span>' +
					'</td>');
					}
					else
					{
						html.push('<td style="padding-top:2px;">' +
						'<span class="dropshadow"onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;">' +
							'<a class="dropshadow" href="javascript:void(0)" ' + '>View</a>' +
						'</span>' +
						'</td>');
					}
				html.push('</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>' +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
	
	this.getBody = function()
	{
		var patientId = document.getElementById(this.id + '.patientID').value || '0';
		var currentMedicationStatus = 
		document.getElementById(this.id + '.isCurrentMedicationAvailableYes').checked ? '1':(document.getElementById(this.id + '.isCurrentMedicationAvailableNo').checked ? '0' : '' );
		if(currentMedicationStatus == '')
		{
			alert("Please select a status yes/no .")
			document.getElementById(this.id + '.isCurrentMedicationAvailableYes').focus();
		}
		else
		{
			return ('patientID=' + patientId + 
					'&currentMedicationStatus=' + currentMedicationStatus 
				    )
		}
		
	}
};

gpr.forms.patientMedication = function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	//Added By DEEPAK (Below 2 lines)
	var cdw;
	cdw = (this.id.indexOf('ShowPatientReport') > 0)?true:false;
	
	this.getHtml = function(patientID, patientMedication)
	{
		patientMedication = patientMedication || {id:0, patientID:patientID, timeStamp:0};
		var isNew = patientMedication.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientMedication.id + ',' + patientID  + '); return false;"' +
					'>Delete this Record?</a></span> '

		var html = [];
		//If condition ADDED BY deepak
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
		html.push(
			(isNew ? "<h3>Add a New Medication</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.id" type="hidden" value="' + patientMedication.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientMedication.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientMedication.patientID + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Medication</td>' +
					'<td class="gpr-panel-caption" align="right">' + deleteHtml + '</td>' +
			
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" colspan1="2" valign="bottom"> ' +
							'<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.medicationID" >Select from the list<label>' +
								'</td>' +
							'<td><div id="'+ this.id+ '.delete" class="gpr-float-dialog"></div></td></tr>' +
							'<tr>' +
								'<td>'
				);


			gpr.getList(html, gpr.dictionaries.medications, patientMedication.medicationID, this.id + '.medicationID')

		html.push(	'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2">' +
						'<label for="' + this.id + '.medicationName" >Other Medication<label>' +
					'</td>' +
				'</tr>' +
		
				'<tr >' +
					'<td style="border-bottom:5 solid white;" colspan="2">' +
						'<input type="text" id="' + this.id + '.medicationName"  value="' + gpr.htmlString(patientMedication.medicationName) + '" ' + focusClass + '  style="width:70%" maxlength="50">' +
					'<br></td>' +
				'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				'<tr><td colspan="2"><table width="100%">' +
				'<tr>' +
					'<td colspan="2">' +'<span class="reg-required">*</span>'+
						'<label for="' + this.id + '.conditionID" >Condition being treated (Below is your conditions list)<label>' +
					'</td>' +
					'<td colspan="2">' +
						'<label for="' + this.id + '.conditionName" >Other Condition<label>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="2" style="padding-bottom:10px">' +
						 this.getConditionList(patientMedication.conditionID, patientMedication.conditionName) +
					'</td>' +
					'<td  colspan="2">' +
						//'<input type="text" id="' + this.id + '.conditionName"  value="' + gpr.htmlString(patientMedication.conditionName) + '" ' + focusClass + '  style="width:70%" maxlength="50">' +
						'<input type="text" id="' + this.id + '.conditionName"  value="' + this.getConditionName(patientMedication.conditionName) + '" ' + focusClass + '  style="width:70%" maxlength="50">' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.strength" >Medication Strength<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="text" id="' + this.id + '.strength"  value="' + gpr.htmlString(patientMedication.strength) + '" ' + focusClass + ' maxlength="10">' +
					'&nbsp;'	);					
						gpr.getList(html, gpr.dictionaries.medicationUnits, patientMedication.unitID, this.id+ '.unitID') 
						
				html.push(' (Unit)</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.form" >Medication Form<label>' +
					'</td>'  +
					'<td colspan="3">')
						gpr.getList(html, gpr.dictionaries.medicationForms, patientMedication.formID, this.id+ '.formID')
					html.push('</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.frequency" >Medication Frequency<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="text" id="' + this.id + '.frequency"  value="' + gpr.htmlString(patientMedication.frequency) + '" ' + focusClass + ' style="width:70%" maxlength="50">' +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.duration" >Medication Duration<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="text" id="' + this.id + '.duration"  value="' + gpr.htmlString(patientMedication.duration) + '" ' + focusClass + ' style="width:70%" maxlength="50">' +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.directions" >Medication Directions<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="text" id="' + this.id + '.directions"  value="' + gpr.htmlString(patientMedication.directions) + '" ' + focusClass + ' style="width:70%" maxlength="100">' +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isCurrent" >Currently taking this medication?<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="radio" name="' + this.id + '.isCurrent"  id="' + this.id + '.isCurrentYes" ' + (patientMedication.isCurrent ? 'checked' : '') +  focusClass + 'value="0" >Yes' + '&nbsp;' +
						'<input type="radio" name="' + this.id + '.isCurrent"  id="' + this.id + '.isCurrentNo" ' +  (!patientMedication.isCurrent ? 'checked' : '')  + focusClass + ' value="1">No' +
					'</td>' +
				'</tr>' +					
				'<tr>' +
					'<td>' +'<span class="reg-required">*</span>' +
						'<label for="' + this.id + '.startdate" >Start Date<label>' +
					'</td>' +
					'<td>' +
						'<input type="text" name="' + this.id + '.startDate"  id="' + this.id + '.startDate" value="' + (gpr.isNullDate(patientMedication.startDate) ? '' : gpr.htmlString(patientMedication.startDate)) + '" ' + focusClass + ' maxlength="10">' +
						'<a href="#" onclick="showCalendar(\'' + this.id + '.startDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
					' (mm/dd/yyyy) </td>' +
					'<td align="right">' + '<span class="reg-required">*</span>' +
						'<label for="' + this.id + '.stopdate" >Stop Date<label>' +
					'</td>' +
					'<td>' +
						'<input type="text" name="' + this.id + '.stopDate" id="' + this.id + '.stopDate" value="' + (gpr.isNullDate(patientMedication.stopDate) ? '' : gpr.htmlString(patientMedication.stopDate)) + '" ' + focusClass + ' maxlength="10">' +
						'<a href="#" onclick="showCalendar(\'' + this.id + '.stopDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
					' (mm/dd/yyyy) </td>' +
				'</tr>' );
					
					if(patientMedication.medicationType == 0 ||patientMedication.medicationType == 1 )
					{
					html.push(
					'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isPrescribed" >Medication Type<label>' +
					'</td>'+
					'<td colspan="3">' +
						'<input type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onMedicationTypeSelect\',0)" name="' + this.id + '.isPrescribed"  id="' + this.id + '.isPrescription" ' + (patientMedication.medicationType == 0 ? 'checked' : '') +  focusClass + 'value="0" >Prescription' + '&nbsp;' +
						'<input type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onMedicationTypeSelect\',1)" name="' + this.id + '.isPrescribed"  id="' + this.id + '.isNonPrescription" ' +  (patientMedication.medicationType == 1 ? 'checked' : '')  + focusClass + ' value="1">Non-Prescription' +
					'</td>' +
				'</tr>' );
					}
					else
					{
					html.push(
					'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isPrescribed" >Medication Type<label>' +
					'</td>'+
					'<td colspan="3">' +
						'<input type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onMedicationTypeSelect\',0)" name="' + this.id + '.isPrescribed"  id="' + this.id + '.isPrescription" '+ 'checked' + focusClass + 'value="0">Prescription' + '&nbsp;' +
						'<input type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onMedicationTypeSelect\',1)" name="' + this.id + '.isPrescribed"  id="' + this.id + '.isNonPrescription" ' + focusClass + ' value="1">Non-Prescription' +
					'</td>' +
				'</tr>' );
					}
					 
				html.push('<tr>' +
					'<td>' + '<span class="reg-required">*</span>' +
						'<label for="' + this.id + '.providerID" >Prescribing Provider </label>' +
					'</td>' +
					'<td colspan="3">' +
						gpr.getProvidersList(this.id + '.providerID', patientMedication.providerID) +
						' (If the provider is not listed, enter the provider\'s name below)' +
						'</td></tr>' +
					'<tr><td>' +
						'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<input type="text" id="' + this.id + '.providerName" style="width:70%" value="' + gpr.htmlString(patientMedication.providerName) + '"  ' + focusClass + ' maxlength="50">' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.comments" >Comments<label>' +
					'</td>' +
					'<td colspan="3">' +
						'<textarea id="' + this.id + '.comments" style="width:70%" cols="74" maxlength="1000">' +
							gpr.htmlString(patientMedication.comments) +
						'</textarea>' +
					'</td>' +
				'</tr>' +
				'<td></tr></table>' +
				'<tr><td colspan="2"><hr></td></tr>' +	
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'
			
		);
					
		return html.join('');
	};
	
	
	this.getConditionName = function(conditionName)
	{
		var conditions = gpr.data.getCurrentPatientCollection('patientConditions')
		for( var i = 0; i < conditions.length; ++i)
		{
			var item = conditions[i];
			
			if(item.conditionName == conditionName)
			{
				return '';
			}
		}
		
		return (conditionName)?conditionName:'';
	}
	
	this.getConditionList = function(conditionID, conditionName)
	{
		var html = '<select id="' + this.id + '.conditionID"><option value=""></option>'
		var conditions = gpr.data.getCurrentPatientCollection('patientConditions')
	  
		for( var i = 0; i < conditions.length; ++i)
		{
			var item = conditions[i]
			var selected = '' ;
			if(item.conditionName == conditionName && item.conditionName != '')
			{
				selected = 'selected';
			}
			else if(item.conditionID == conditionID  && conditionID != '0')
			{
				 selected = 'selected';
			}
			//var selected = ((item.conditionName == conditionName) || (item.id == conditionID && conditionID != '0')) ? 'selected' : ''; /*todo: move user conditions to table */
			html += '<option value="' + item.conditionID + '"' + selected + '>' + (gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName).length > 47 ? gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName).substring(0,47)+'...' : gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName)) + ' </option>' 
		}

		html += '</select>'
		return html
	}
	
	this.onMedicationTypeSelect = function(MedicationType)
	{
		if(MedicationType == 0)
		{
			document.getElementById(this.id + '.providerID').disabled = false;
			document.getElementById(this.id + '.providerName').disabled = false;
			document.getElementById(this.id + '.providerName').style.backgroundColor = "#ffffff";
		}
		else if(MedicationType == 1)
		{
			document.getElementById(this.id + '.providerID').disabled = true;
			document.getElementById(this.id + '.providerName').disabled = true;
			document.getElementById(this.id + '.providerID').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.providerName').style.backgroundColor = "#d3d3d3";
		}
		
	}

	this.getBody = function()
	{
		var id = document.getElementById(this.id + '.id').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value;
		var medicationID = document.getElementById(this.id + '.medicationID').value || '';
                var medicationName = (!medicationID)? gpr.Trim(document.getElementById(this.id + '.medicationName').value || '') : '';
		var strength = gpr.Trim(document.getElementById(this.id + '.strength').value) || '';
		var unitID = document.getElementById(this.id + '.unitID').value || '';
		var formID = document.getElementById(this.id + '.formID').value || '';
		var directions = gpr.Trim(document.getElementById(this.id + '.directions').value) || '';
		var duration = gpr.Trim(document.getElementById(this.id + '.duration').value) || '';
		var frequency = gpr.Trim(document.getElementById(this.id + '.frequency').value) || '';
		var startDate = document.getElementById(this.id + '.startDate').value || '';
		var stopDate = document.getElementById(this.id + '.stopDate').value || '';
		var	providerID = document.getElementById(this.id + '.providerID').value || '';
        var providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';
		var	comments = gpr.Trim(document.getElementById(this.id + '.comments').value) || '';
		var isCurrent = document.getElementById(this.id + '.isCurrentYes').checked ? '1' : '0'
		var conditionID =   gpr.Trim(document.getElementById(this.id + '.conditionID').value || '');
		var medicationType = document.getElementById(this.id + '.isPrescription').checked ? '0' : '1'
		 var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
		var conditionName;
		
		var dtStartDate,dtStopDate,currDate;
		if(gpr.Trim(startDate) && gpr.isDate(startDate))
			dtStartDate = new Date(startDate);
		if(gpr.Trim(stopDate) && gpr.isDate(stopDate))
			dtStopDate = new Date(stopDate);
			var patientID ;
			patientID = gpr.data.currentPatientID || gpr.data.patient.id;
			currDate = new Date(gpr.data.patients[patientID].currentDate)
		
		
		
		//Below lines added by manoj for Audit log
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
		
		if (medicationType == 1)
		{
		providerID = 0;
		providerName = '';
		}
		
		if(conditionID == '0')
		{
			var condition = document.getElementById(this.id + '.conditionID');
			for(i=0; i<condition.options.length; i++)
			{
				if(condition.options[i].selected)
				{
					conditionName = gpr.Trim(condition.options[i].innerText);
					break;
				}
			}
		}
		else
		{
            conditionName = (!conditionID)? gpr.Trim(document.getElementById(this.id + '.conditionName').value || '') : '';
        }
        
		if ( ! medicationID && ! gpr.Trim(medicationName) )
		{
			alert('Please select Medication.');
			document.getElementById(this.id + '.medicationID').focus();
		}
		else if((conditionID == '0' || !conditionID) && !gpr.Trim(conditionName))
		{
			alert('Please enter condition name');
			conditionName = document.getElementById(this.id + '.conditionID').options[document.getElementById(this.id + '.conditionID').selectedIndex].text
			document.getElementById(this.id + '.conditionID').focus();
		}
		else if(!gpr.Trim(startDate))
		{
			alert('Please enter a start date');
			document.getElementById(this.id + '.startDate').focus();
		}
		else if (! gpr.isDate(startDate))
		{
			alert('Please enter a valid start date');
			document.getElementById(this.id + '.startDate').focus();
		}
		else if(!gpr.Trim(stopDate))
		{
			alert('Please enter a stop date');
			document.getElementById(this.id + '.stopDate').focus();
		}
		else if (! gpr.isDate(stopDate))
		{
			alert('Please enter a valid stop date');
			document.getElementById(this.id + '.stopDate').focus();
		}
		else if(dtStartDate > dtStopDate)
		{
			alert('Start date should be less than or equal to stop date.');
			document.getElementById(this.id + '.startDate').focus();
		}
		/*else if(dtStartDate > currDate)
		{
			alert('Start date should be less than or equal to today\'s date.');
			document.getElementById(this.id + '.startDate').focus();
		}
		else if(dtStopDate > currDate)
		{
			alert('Stop date should be less than or equal to today\'s date.');
			document.getElementById(this.id + '.stopDate').focus();
		}*/
		else if(gpr.Trim(comments) && comments.length > 2000)
		{
			alert('Comments cannot exceed more than 2000 characters');
			document.getElementById(this.id + '.comments').focus();
		}
		else if ( (providerID == '0' || !providerID) && ! providerName  && medicationType == 0)
		{
			alert('Please select a Provider from list or enter your provider\'s name.');
		}
		else
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(medicationID ? '&medicationID=' + medicationID : '' )+
				(medicationName ? '&medicationName=' + encodeURIComponent(medicationName) : '' )+
				(startDate ? '&startDate=' + encodeURIComponent(startDate) : '') +
				(stopDate ? '&stopDate=' + encodeURIComponent(stopDate) : '') +
				(strength ? '&strength=' + encodeURIComponent(strength) : '') +
				(unitID ? '&unitID=' + encodeURIComponent(unitID) : '') +
				(formID ? '&formID=' + encodeURIComponent(formID) : '') +
				(directions ? '&directions=' + encodeURIComponent(directions) : '') +
				(duration ? '&duration=' + encodeURIComponent(duration) : '') +
				(frequency ? '&frequency=' + encodeURIComponent(frequency) : '') +
				(isCurrent ? '&isCurrent=' + encodeURIComponent(isCurrent) : '') +
				(providerID ? '&providerID=' + providerID : '') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName) : '') +
				(comments ? '&comments=' + encodeURIComponent(comments) : '') +
				(conditionID ? '&conditionID=' + encodeURIComponent(conditionID) : '') +
				(conditionName ? '&conditionName=' + encodeURIComponent(conditionName) : '')+
				(medicationType ? '&medicationType=' + encodeURIComponent(medicationType) : '')+
				"&timeStamp=" + encodeURIComponent(timeStamp) +
				('&CareDataUserID=' + careDatauserID ) // Added by Manoj for AuditLog
				
	
			);
		} 
	};

};


gpr.forms.patientMeidicationView = function(id,onCancel)
{
	this.id = id;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	var cdw;
	cdw = (this.id.indexOf('ShowPatientReport') > 0)?true:false;
	
	this.getHtml = function(patientID, patientMedication)
	{
		patientMedication = patientMedication || {id:0, patientID:patientID, timeStamp:0};
		var isNew = patientMedication.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientMedication.id + ',' + patientID  + '); return false;"' +
					'>Delete this Record?</a></span> '

		var html = [];
		//If condition ADDED BY deepak
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="#" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
        var medicationName = ((gpr.Trim(gpr.htmlString(patientMedication.medicationID ? gpr.findID(gpr.dictionaries.medications, patientMedication.medicationID, {name:''}).name : patientMedication.medicationName))?gpr.htmlString(patientMedication.medicationID ? gpr.findID(gpr.dictionaries.medications, patientMedication.medicationID, {name:''}).name : patientMedication.medicationName):'--'));
		if(medicationName.length >47)
		{
				medicationName = medicationName.substring(0,47)+'...';
		}
		html.push(
			'<input id="' + this.id + '.id" type="hidden" value="' + patientMedication.id + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientMedication.timeStamp + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientMedication.patientID + '">' +
			'<br>' +
			'<table class="gpr-panel" width="90%">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Medication</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5px" valign="bottom" align="left" width="20%"> ' +
						'<label for="' + this.id + '.medicationID" >Medication<label>' + ' :' +
					'</td>' +
						'<td>' + medicationName +
					'</td>' +
					'</tr>' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' +
				'<tr><td colspan="2"><table width="100%">' +
				'<tr>' +
					'<td colspan="4">' +
						'<label for="' + this.id + '.conditionID" >Conditions being treated <label>' +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td colspan="4" style="padding-bottom:10px">' +
						 (patientMedication.conditionName ? '--' :patientMedication.conditionName)   +
					'</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.strength" >Medication Strength<label>' +
					'</td>' +
					'<td colspan="3">' +
						(gpr.Trim((patientMedication.strength || ' ' )  + gpr.findID(gpr.dictionaries.medicationUnits, patientMedication.unitID, {name:' '}).name)?(patientMedication.strength || ' ' )  + gpr.findID(gpr.dictionaries.medicationUnits, patientMedication.unitID, {name:''}).name:'--')  
					+ '</td>' +
				'</tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.form" >Medication Form<label>' +
					'</td>'  +
					'<td colspan="3">'+
						(gpr.findID(gpr.dictionaries.medicationForms, patientMedication.formID,{name:'--'}).name)
					+ '</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.frequency" >Medication Frequency<label>' +
					'</td>' +
					'<td colspan="3">' +
						(gpr.htmlString(patientMedication.frequency) ? gpr.htmlString(patientMedication.frequency) : '--') +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.duration" >Medication Duration<label>' +
					'</td>' +
					'<td colspan="3">' +
						(gpr.htmlString(patientMedication.duration) ? gpr.htmlString(patientMedication.duration) : '--') +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.directions" >Medication Directions<label>' +
					'</td>' +
					'<td colspan="3">' +
						 (gpr.htmlString(patientMedication.directions)? gpr.htmlString(patientMedication.directions) : '--') +
					'</td>' +
				'</tr>' +	
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isCurrent" >Currently taking this medication?<label>' +
					'</td>' +
					'<td colspan="3">' +
						 (patientMedication.isCurrent ? 'Yes' : 'No') +
					'</td>' +
				'</tr>' +					
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.startdate" >Start Date<label>' +
					'</td>' +
					'<td>' +
					(gpr.isNullDate(patientMedication.startDate) ? '--' : gpr.htmlString(patientMedication.startDate)) +
					' (mm/dd/yyyy) </td>' +
					'<td align="right">' +
						'<label for="' + this.id + '.stopdate" >Stop Date<label>' +
					'</td>' +
					'<td>' +
					(gpr.isNullDate(patientMedication.stopDate) ? '--' : gpr.htmlString(patientMedication.stopDate)) + 
					' (mm/dd/yyyy) </td>' +
				'</tr>' );
					if(patientMedication.medicationType == 0 ||patientMedication.medicationType == 1 )
					{
					html.push(
					'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.isPrescribed" >Medication Type<label>' +
					'</td>'+
					'<td colspan="3">' +
						(patientMedication.medicationType == 0 ? 'Prescription' : 'Non-Prescription') + 
					'</td>' +
				'</tr>' );
					}
				html.push('<tr>' +
					'<td>' + 
						'<label for="' + this.id + '.providerID" >Prescribing Provider </label>' +
					'</td>' +
					'<td colspan="3">' +
						(gpr.Trim(gpr.htmlString(patientMedication.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientMedication.providerID, ' ') : patientMedication.providerName))?gpr.htmlString(patientMedication.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientMedication.providerID, ' ') : patientMedication.providerName):'--')  +
					'</td></tr>' +
				'<tr>' +
					'<td>' +
						'<label for="' + this.id + '.comments" >Comments<label>' +
					'</td>' +
					'<td colspan="3">' +
						(gpr.htmlString(patientMedication.comments) ? gpr.htmlString(patientMedication.comments) : '--') +
					'</textarea>' +
					'</td>' +
				'</tr>' +
				'<td></tr></table>' +
				'<tr><td colspan="2"><hr></td></tr>' +	
				'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" ' + '>Submit</a>' +
						'</span>' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
			'</table>'
			
		);
					
		return html.join('');
	};
	
	
	this.getConditionName = function(conditionName)
	{
		var conditions = gpr.data.getCurrentPatientCollection('patientConditions')
		for( var i = 0; i < conditions.length; ++i)
		{
			var item = conditions[i];
			
			if(item.conditionName == conditionName)
			{
				return '';
			}
		}
		
		return (conditionName)?conditionName:'';
	}
	
	this.getConditionList = function(conditionID, conditionName)
	{
		var html = '<select id="' + this.id + '.conditionID"><option value=""></option>'
		var conditions = gpr.data.getCurrentPatientCollection('patientConditions')
	  
		for( var i = 0; i < conditions.length; ++i)
		{
			var item = conditions[i]
			var selected = '' ;
			if(item.conditionName == conditionName && item.conditionName != '')
			{
				selected = 'selected';
			}
			else if(item.conditionID == conditionID  && conditionID != '0')
			{
				 selected = 'selected';
			}
			//var selected = ((item.conditionName == conditionName) || (item.id == conditionID && conditionID != '0')) ? 'selected' : ''; /*todo: move user conditions to table */
			html += '<option value="' + item.conditionID + '"' + selected + '>' + (gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName).length > 47 ? gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName).substring(0,47)+'...' : gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName)) + ' </option>' 
		}

		html += '</select>'
		return html
	}
	
	this.onMedicationTypeSelect = function(MedicationType)
	{
		if(MedicationType == 0)
		{
			document.getElementById(this.id + '.providerID').disabled = false;
			document.getElementById(this.id + '.providerName').disabled = false;
			document.getElementById(this.id + '.providerName').style.backgroundColor = "#ffffff";
		}
		else if(MedicationType == 1)
		{
			document.getElementById(this.id + '.providerID').disabled = true;
			document.getElementById(this.id + '.providerName').disabled = true;
			document.getElementById(this.id + '.providerID').style.backgroundColor = "#d3d3d3";
			document.getElementById(this.id + '.providerName').style.backgroundColor = "#d3d3d3";
		}
		
	}
}



//-------------------------------------------------------------------------------------------------------------
gpr.forms.patientConditions = function(id, onChange,onClose,onView)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	this.onView = onView;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientConditions)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="3" class="gpr-panel-caption">CONDITIONS ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right" ><span class="panel-button"> <a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Condition </a></span></td></tr>' 

		);
		
		if(patientConditions.length == 0)
		{
			html.push('<tr><td colspan="4" align="center">To add conditions  for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Condition button above </td></tr>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'condition" class="panel-column-header">' +
						'Condition' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Diagnosis Date' +
					'</td>' +
					'<td id="' + this.id + '.isActive" class="panel-column-header">' +
						'Last Treatment Date' +
					'</td>' +
					'<td class="panel-column-header">' +
						'' +
					'</td>' +
				'</tr>')
		}
		for( var i = 0; i < patientConditions.length; ++i)
		{
			var item = patientConditions[i];
			var conditionName = (gpr.Trim(gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName))?gpr.htmlString(item.conditionID ? gpr.findID(gpr.dictionaries.conditions, item.conditionID, {name:''}).name : item.conditionName):'--') ;
			if(conditionName.length > 47)
			{
				conditionName = conditionName.substring(0,47)+'...';
			}
			html.push('<tr>' );
			
			if(item.careDataRecordID == 0)
			{
			html.push( '<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' +
					'<a  href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;"' +
							'>' +
						conditionName +	'</a></td>' );
			}
			else
			{
				html.push( '<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' +
					'<a  href="javascript:void(0)" ' +
								' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;"' +
							'>' +
						conditionName +	'</a></td>' );
			}
			html.push('<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' +
					gpr.htmlString(gpr.Trim(item.diagnosisDate) != '1/1/0001' ? item.diagnosisDate:'--') + 
					'</td>' +
					'<td class="' + (item.isActive ?  '' : 'gpr-disable-row' ) + '">' +
						gpr.htmlString(gpr.Trim(item.lastTreatmentDate) != '1/1/0001'?item.lastTreatmentDate:'--') +
					'</td>');
					if(item.careDataRecordID == 0)
					{
					html.push('<td style="padding-top:2px;">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', ' + item.id + '); return false;">' +
							'<a class="dropshadow" href="javascript:void(0)" ' + '>Edit</a>' +
						'</span>' +
					'</td>');
					}
					else
					{
						html.push('<td style="padding-top:2px;">' +
						'<span class="dropshadow"onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onView\', ' + item.id + '); return false;">' +
							'<a class="dropshadow" href="javascript:void(0)" ' + '>View</a>' +
						'</span>' +
						'</td>');
					}
					
				html.push('</tr>'
			);
		}
		
		
		html.push(
				'<!--tr>' +
					'<td colspan="3"><hr></td>' +
				'</tr-->' +
				'</table>' +
				'<div style="width:90%;text-align:center;padding:10px">' +
						'<span class="dropshadow"  onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onClose\'); return false;">' +
							/*'<a href="login.htm">Close</a>' */
							'<a href="javascript:void(0)" ' +'>Close</a>' +
						'</span>' +
				'</div>' +
					'<!--/td>' +
				'</tr-->' 
			
		) 
		
		return html.join('') 
	};
};

gpr.forms.patientCondition = function(id, onSubmit, onCancel, onDelete)
{
	this.id = id;
	this.onSubmit = onSubmit;
	this.onCancel = onCancel;
	this.onDelete = onDelete;
	gpr.registry.add(this);

	var focusClass = ' onfocus="this.className = \'focus\'" onblur="this.className = \'\'" '
	
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;
	
	this.getWindowCenterElements = function(nWidth, nHeight)
	{
	
	var sFeatures
	var nLeft, nTop
	nLeft = this.getCenterCordinates(screen.availWidth, window.screenLeft, window.document.body.offsetWidth, nWidth - 15 + 20) 
	nTop = this.getCenterCordinates(screen.availHeight, window.screenTop, window.document.body.offsetHeight, nHeight - 1 + 60) 
	sFeatures = "top=" + nTop + ",left=" + nLeft + ",width=" + nWidth + ",height=" + nHeight 
	return sFeatures
	
	}
	
	// Add by Nous(Manoj) to get the center cordinates

	this.getCenterCordinates = function (Sr, Pl, Pw, Dw)
	{
		return Math.max(0, Math.min(Sr - Dw, (Math.max(0, Pl) + Math.min(Sr, Pl + Pw) - Dw) / 2))
	}
	
	
	this.openpopupWindow = function()
	{
		var style = this.getWindowCenterElements(850,600) +  ", status=yes,resizable=no,scrollbars=yes"
		
		if (objWinICDCodes && !objWinICDCodes.closed)
		{
			objWinICDCodes.focus();
		}
		else
		{
			objWinICDCodes = window.open('ICDCodes/ICDCodeSearch.aspx','ICDSearch',style )
		}
	}
	
	this.SetICDCodesValues = function(ICDCode,ICDDescription)
	{
		document.getElementById('divOtherCondition').style.display="block";
		document.getElementById(this.id + '.conditionName').innerText = gpr.htmlString(ICDDescription);
		document.getElementById(this.id + '.ICDCode').value = gpr.htmlString(ICDCode);
		document.getElementById(this.id + '.conditionID').selectedIndex = 0;
		
	}
	
	this.getHtml = function(patientID, patientCondition)
	{
		patientCondition = patientCondition || {id:0, patientID:patientID,isActive:1, treatmentMethodIDs:[],timeStamp:0,icdCode:''};
		var isNew = patientCondition.id == 0;
		var deleteHtml  = isNew ? '' :'<span class="panel-button"><a href="javascript:void(0)" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onDelete\','+  patientCondition.id + ',' + patientID  + '); return false;"' +
				'>Delete this Record?</a></span>'

		var html = [];
	//Below IF Condition added by deepak, Nous 27-Feb-2007
        //These line of codes will be added if the GlobalPatientRecord.Handlers is accessed from CDW using Medical History Link
        if(cdw == true)
        {
                html.push(
                        '<span style="float:right">' +
                                '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
							'<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                                '&nbsp;&nbsp;<a class="cdwlink" href="javascript:void(0)" align="right" onclick="window.close()">Close this window</a>' + 
                        '</span>' +
                        '<table align="center">' +
                                '<tr>' +
                                        '<td classl="gpr-panel-caption" colspan="2">' +
                                                '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                                        '</td>' +
                                '</tr></table>');
        }
        //changes end
		
		html.push(
			(isNew ? "<h3>Add a Condition</h3>" : "<h3></h3>" )+
			'<input id="' + this.id + '.ICDCode" type="hidden" value="' + (patientCondition.icdCode) + '">' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientCondition.id + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientCondition.patientID + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientCondition.timeStamp + '">' +
			
			'<span class="reg-required">*</span> denotes Required Fields' +
			'<br>' +
			'<table class="gpr-panel-Condition" width="90%" cellspacing="0" cellpadding="0">' +
				'<tr>' +
					'<td class="gpr-panel-caption">Condition</td>' +
					'<td  class="gpr-panel-caption" align="right" >' + deleteHtml + '</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5" colspan="2">' +
					'<table class="gpr-panel-section" cellpadding="0" cellspacing="0" width="100%">' +
							'<tr>' +
								'<td>' +
									'&nbsp;<span class="reg-required">*</span>' +
									'<label for="' + this.id + '.conditionID" >Select from the list<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>&nbsp;'
		);

		this.getConditionList(html, patientCondition);		

		html.push('(If condition is not listed, Please select one by'+ 
		'&nbsp;<a id="myDiv1" name="' + this.id + '.pickICDCode" href="javascript:void(0)" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'openpopupWindow\')">clicking here</a>' + ')</td>' +
							'</tr>' +
							'<tr>' +
							'<td>'+'<div id="divOtherCondition"'+ (gpr.htmlString(patientCondition.conditionName)== '' ? 'style=display:none' : '') + '>'+'<table><tr>'+
							'<td>' + 
									'&nbsp;<label for="' + this.id + '.conditionName" >Other condition<label>' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'&nbsp;<b><span id="' + this.id + '.conditionName" >' + gpr.htmlString(patientCondition.conditionName) + '</span></b>' +	
									'</td>' +
								'</tr>' +'</table></div></td></tr>'+
							'</table>' +
						'</td>' +
				'</tr>' +
				'<tr>'+ '<td colspan="2">' + 
				'&nbsp;&nbsp;<label for="' + this.id + '.doyouhavethiscondition">Do you have this condition ? <label> &nbsp;&nbsp;' +
				'<input name="' + this.id + '.status" id="' + this.id + '.statusYes" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',true)"  ' + 
										(patientCondition.isActive == true ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.Yes" >Yes</label>' +
									'<input name="' + this.id + '.status" id="' + this.id + '.statusNo" type="radio" onClick="gpr.dispatcher.call(\'' + this.id + '\', \'onActiveSelect\',false)" ' + 
										(patientCondition.isActive != true ? 'checked' : '' ) + 
									'>' +
									'<label for="' + this.id + '.No" >No</label>' +
				'</td></tr>'+
				'<tr><td colspan="2"><div style="' + (patientCondition.isActive ? 'display:block' : 'display:none') + '" id="' + this.id + '.conditionfrm" ><table width="100%" cellpadding="0">'+
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Details</td>' +
				'</tr>' + 
				'<tr>' +
				'<td colspan="2">'+
					'<table class="gpr-panel-section" width="100%">' +
						'<tr>' +
							//'<td width="10%">' +
							//	'<label for="' + this.id + '.isActive" >&nbsp;&nbsp;Active</label></td>'+
							//'<td>' +
							//	'<input type="checkbox" id="' + this.id + '.isActive"' + (patientCondition.isActive == true ? 'checked' : '') +  '>'+
							//'</td>'	+ 
							'<td width="15%">' + 'Condition Type' + '</td><td>');
							this.getconditionTypeList(html,patientCondition);
								html.push('<br>' +
							'</td>' +
						'</tr></table>' +
				'</td>'+
				'</tr>'+
				'<tr>'+
				'<td colspan="2">'+
				
				'<table class="gpr-panel-section" width="100%">' +
						'<tr>' +
							'<td width="1%" >' +
                                  '<label for="' + this.id + '.diagnosisDate" >&nbsp;Date of Diagnosis<label>' +
							'</td>' +
							'<td>' +
									'<input type="text" id="' + this.id + '.diagnosisDate" name="' + this.id + '.diagnosisDate" value="' + (gpr.isNullDate(patientCondition.diagnosisDate) ? '' : gpr.htmlString(patientCondition.diagnosisDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.diagnosisDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'<td width="1%" >' +
								'<span class="reg-required">*</span>' +
								'<label for="' + this.id + '.onsetDate" >Date of Onset<label>' +
							'</td>' +
							'<td>' +
								'<input type="text" id="' + this.id + '.onsetDate"  name="' + this.id + '.onsetDate" value="' + (gpr.isNullDate(patientCondition.onsetDate) ? '' : gpr.htmlString(patientCondition.onsetDate)) + '" ' + focusClass + ' maxlength="10">' +
								'<a href="#" onclick="showCalendar(\'' + this.id + '.onsetDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
								'<label for="' + this.id + '.resolutionDate" >&nbsp;Date Resolved<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.resolutionDate" id="' + this.id + '.resolutionDate" value="' + (gpr.isNullDate(patientCondition.resolutionDate) ? '' : gpr.htmlString(patientCondition.resolutionDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.resolutionDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
								'<td nowrap>' +
                                '<label for="' + this.id + '.lastTreatmentDate" >&nbsp;Date Last Treated<label>' +
								'</td>' +
								'<td>' +
									'<input type="text" name="' + this.id + '.lastTreatmentDate" id="' + this.id + '.lastTreatmentDate" value="' + (gpr.isNullDate(patientCondition.lastTreatmentDate) ? '' : gpr.htmlString(patientCondition.lastTreatmentDate)) + '" ' + focusClass + ' maxlength="10">' +
									'<a href="#" onclick="showCalendar(\'' + this.id + '.lastTreatmentDate\',\''+ gpr.consts.dateFormat +'\')"><img align="absmiddle" src="images/cal.gif" border="0"></a>' +									
								' (mm/dd/yyyy) </td>' +
							'</tr></td></table>'+
					'</td></tr>'+
					'<tr>'+
					'<td class="gpr-panel-caption" colspan="2">Treatment Methods</td></tr>' +
					'<tr>' +
					'<td style="padding-bottom:5px" colspan="2" >' +
						'<table class="gpr-panel-section" width="100%">' +
							'<tr>' +
								'<td>' +
									'<span class="reg-required">*</span>' +
									'Select one or more' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>'
							);
						this.getTreatmentMethodList(html, patientCondition);		
				html.push(
							'</td>' +
						'</tr>' +
						'</table>' +
					'</td>' +
				'</tr>' +			
				
				'<tr valign="top">' +
								'<td width="20%">' +
									'<label for="' + this.id + '.providerID" >Provider treating this condition <label>' +
								'</td>' +
								'<td colspan="3">' +
									gpr.getProvidersList(this.id + '.providerID', patientCondition.providerID) +
									'(If the provider is not listed, enter the provider\'s name below)' +
								'</td>' +
							'<tr><td>' +
									'<label for="' + this.id + '.providerName" >Provider\'s Name<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<input type="text" id="' + this.id + '.providerName" size="79" value="' + gpr.htmlString(patientCondition.providerName) + '"  ' + focusClass + ' maxlength="100">' +
								'</td>' +
							'</tr>' +
							'<tr>' +
								'<td>' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td colspan="3">' +
									'<textarea id="' + this.id + '.comments" cols="60"  ' + focusClass + ' maxlength="2000">' +
										gpr.htmlString(patientCondition.comments) +
									'</textarea>' +
								'</td>' +
							'</tr>' +
								'</table></div></td></tr>'+
							'<tr>' +
								'<td colspan="2"><hr></td>' +
							'</tr>' +
					'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onSubmit\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Submit</a>' +
						'</span>' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>'
			);
			
		return html.join(''); 
	};
	
	this.getBody = function()
	{
		var id = document.getElementById(this.id + '.id').value || '0';
		var patientID = document.getElementById(this.id + '.patientID').value;
		var conditionID = document.getElementById(this.id + '.conditionID').value || '';
        var conditionName = (!conditionID)? gpr.Trim(document.getElementById(this.id + '.conditionName').innerText || '') : '';
		
		var diagnosisDate = document.getElementById(this.id + '.diagnosisDate').value || '';
		var onsetDate = document.getElementById(this.id + '.onsetDate').value || '';
		var resolutionDate = document.getElementById(this.id + '.resolutionDate').value || '';
		var lastTreatmentDate = document.getElementById(this.id + '.lastTreatmentDate').value || '';
		var isActive =  (document.getElementById(this.id+ '.statusYes').checked==true ? true: false)
		
		//var isActive = (document.getElementById(this.id+ '.isActive').checked==true ? true: false)
		//var severity = (document.getElementById(this.id+ '.severity-acute').checked==true? 0 : 1)
		//var treatmentMethod = document.getElementById(this.id + '.treatmentMethod').value || '';
		var treatmentMethodIDs = this.getTreatmentMethodSelection().join(',');
		
		var	providerID = document.getElementById(this.id + '.providerID').value || '';
        var     providerName = (!providerID)? gpr.Trim(document.getElementById(this.id + '.providerName').value || '') : '';
		var	comments = document.getElementById(this.id + '.comments').value || '';
		var severity = document.getElementById(this.id + '.conditionTypeID').value || '';
		//Below lines added by manoj for Audit log
		if(document.getElementById('careDatauserID'))
			var careDatauserID = document.getElementById('careDatauserID').value;
		else
			var careDatauserID = '0';
			
		var ICDCode = document.getElementById(this.id + '.ICDCode').value
		
		var timeStamp = document.getElementById(this.id + ".timeStamp").value || '0'
				
		if ( ! conditionID && ! gpr.Trim(conditionName) )
		{
			alert('Please select Condition.');
			document.getElementById(this.id + '.conditionID').focus();
		}
		else if(isActive == false)
		{
			return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(conditionID ? '&conditionID=' + conditionID : '' )+
				(conditionName ? '&conditionName=' + encodeURIComponent(conditionName) : '' )+
				 '&isActive=' + encodeURIComponent(isActive) +  //(isActive ? '&isActive=' + encodeURIComponent(isActive) : '' )+
				(severity ? '&severity=' + encodeURIComponent(severity):'' )+
				(diagnosisDate  ? '&diagnosisDate=' + encodeURIComponent(diagnosisDate ):'') +
				(onsetDate  ? '&onsetDate=' + encodeURIComponent(onsetDate ):'') +
				(resolutionDate  ? '&resolutionDate=' + encodeURIComponent(resolutionDate ):'') +
				(lastTreatmentDate  ? '&lastTreatmentDate=' + encodeURIComponent(lastTreatmentDate ):'') +
				(treatmentMethodIDs ? '&treatmentMethodIDs=' + encodeURIComponent(treatmentMethodIDs):'' )+
				(providerID ? '&providerID=' + providerID:'') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName):'') +
				(comments ? '&comments=' + encodeURIComponent(comments):'') + 
				('&ICDCode=' + encodeURIComponent(ICDCode)) + 
				('&timeStamp=' + encodeURIComponent(timeStamp)) +
				('&CareDataUserID=' + careDatauserID ) 
			);
		}
		
		if(isActive)
		{
			if (gpr.Trim(diagnosisDate) && !gpr.isDate(diagnosisDate))
			{//add date validations if functionality changes later. right now just do it like the other one
				document.getElementById(this.id + '.diagnosisDate').focus();
			}
			else if (new Date(diagnosisDate) < new Date(gpr.data.patients[patientID].dob))
			{
				alert('Diagnosis Date can not be less than  Birth Date!');
				document.getElementById(this.id + '.diagnosisDate').focus();
			}
			else if(!gpr.Trim(onsetDate))
			{
				alert('Please enter a on set date');
				document.getElementById(this.id + '.onsetDate').focus();
			}
			else if (! gpr.isDate(onsetDate))
			{
				document.getElementById(this.id + '.onsetDate').focus();
			}
			else if (new Date(onsetDate) < new Date(gpr.data.patients[patientID].dob))
			{
				alert('Onset Date can not be less than  Birth Date!');
				document.getElementById(this.id + '.onsetDate').focus();
			}
			else if (gpr.Trim(resolutionDate) && ! gpr.isDate(resolutionDate))
			{
				document.getElementById(this.id + '.resolutionDate').focus();
			}
			else if (new Date(resolutionDate) < new Date(gpr.data.patients[patientID].dob))
			{
				alert('Resolution Date can not be less than  Birth Date!');
				document.getElementById(this.id + '.resolutionDate').focus();
			}
			else if (gpr.Trim(lastTreatmentDate) && !gpr.isDate(lastTreatmentDate))
			{
				document.getElementById(this.id + '.lastTreatmentDate').focus();
			}	
			else if (new Date(lastTreatmentDate) < new Date(gpr.data.patients[patientID].dob))
			{
				alert('Last Treatment Date can not be less than  Birth Date!');
				document.getElementById(this.id + '.lastTreatmentDate').focus();
			}
            //modified (shuffled) by deepak, nous 18-Jan-2007
			else if ( ! treatmentMethodIDs)
			{
				alert('Please select Treatment Method');
				var ar = gpr.dictionaries.treatmentMethods;
				document.getElementById(this.id + '.treatmentMethod.' + ar[0].id).focus();
			}
			else if(gpr.Trim(comments) && comments.length > 1000)
			{
				alert('Comments cannot exceed than 1000 characters');
				document.getElementById(this.id + '.comments').focus();
			}
			/*else if ( ! providerID && ! providerName )
			{
				alert('Please select a Provider from the list or enter the name of the provider if you dont find the provider in the list.');
			}*/
			else
			{
				return (
				'id=' + id + 
				'&patientID=' + patientID + 
				(conditionID ? '&conditionID=' + conditionID : '' )+
				(conditionName ? '&conditionName=' + encodeURIComponent(conditionName) : '' )+
				 '&isActive=' + encodeURIComponent(isActive) +  //(isActive ? '&isActive=' + encodeURIComponent(isActive) : '' )+
				(severity ? '&severity=' + encodeURIComponent(severity):'' )+
				(diagnosisDate  ? '&diagnosisDate=' + encodeURIComponent(diagnosisDate ):'') +
				(onsetDate  ? '&onsetDate=' + encodeURIComponent(onsetDate ):'') +
				(resolutionDate  ? '&resolutionDate=' + encodeURIComponent(resolutionDate ):'') +
				(lastTreatmentDate  ? '&lastTreatmentDate=' + encodeURIComponent(lastTreatmentDate ):'') +
				(treatmentMethodIDs ? '&treatmentMethodIDs=' + encodeURIComponent(treatmentMethodIDs):'' )+
				(providerID ? '&providerID=' + providerID:'') +
				(providerName ? '&providerName=' + encodeURIComponent(providerName):'') +
				(comments ? '&comments=' + encodeURIComponent(comments):'') + 
				('&ICDCode=' + encodeURIComponent(ICDCode)) + 
				('&timeStamp=' + encodeURIComponent(timeStamp)) +
				('&CareDataUserID=' + careDatauserID )
				);
			} 
		}
	};
	
	this.onActiveSelect = function(status)
	{
		if(status)
		{
			document.getElementById(this.id + '.conditionfrm').style.display = "block";
		}
		else
		{
			document.getElementById(this.id + '.conditionfrm').style.display = "none";
		}
	}


	this.getconditionTypeList = function(html,patientCondition)
	{
		html.push(
				'<select id="' + this.id + '.conditionTypeID" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectConditionType\', this); return false;">' +
				'<option value=""></option>'
				);
				
		html.push('<option value="' + 0 + '"');
			if (patientCondition.severity == 0 )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push("Acute");
			html.push('</option>');
			
		html.push('<option value="' + 1 + '"');
			if (patientCondition.severity == 1 )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push("Chronic");
			html.push('</option>');
			html.push('</select>');
	}
	
	this.onSelectConditionType = function(select)
	{
		//alert('Inside onSelectCondition');
		if ( ! select.options[select.selectedIndex].value )
		{
			select.selectedIndex = 0;
		}
	}
	
	this.getConditionList = function(html, patientCondition)
	{
		html.push(
			//'<select id="' + this.id + '.conditionID" ' + focusClass + '>' +
			'<select id="' + this.id + '.conditionID" ' + focusClass + ' onchange="gpr.dispatcher.call(\'' + this.id + '\', \'onSelectCondition\', this); return false;">' +
				'<option value=""></option>'
		
		);
		
		var im = gpr.dictionaries.conditions;	

		for ( var i = 0; i < im.length; ++i)
		{
			html.push('<option value="' + im[i].id + '"');
			if ( im[i].id == patientCondition.conditionID )
			{
				html.push(' selected ');
			}
			html.push('>')
			html.push(gpr.htmlString(im[i].name));
			html.push('</option>');
			
		}
		
		html.push('</select>');
	};
	
	
	
	this.getTreatmentMethodList = function(html, patientCondition)
	{
		html.push('<table width="100%"><tr>')
		var ar = gpr.dictionaries.treatmentMethods;
		
		for ( var a = 0; a < ar.length; ++a)
		{
			html.push('<td>')
			//html.push('<span style="white-space:">');
			html.push('<input type="checkbox" id="' + this.id + '.treatmentMethod.' + ar[a].id + '" ');
			html.push(' value="' + ar[a].id + '" ');
			if ( gpr.find(patientCondition.treatmentMethodIDs, ar[a].id) )
			{
				html.push(' checked ');
			}
			html.push('>');
			html.push(' <label for="' + this.id + '.treatmentMethod.' + ar[a].id + '" >');
			html.push(gpr.htmlString(ar[a].name));
			html.push('</label>');
			html.push('</td>')
			if((a+1) % 4 == 0)
			{
			  html.push('</tr><tr>')
			}
			//html.push('</span>');
		}
		html.push('</table>')
	}
	this.getTreatmentMethodSelection = function()
	{
		var ar = gpr.dictionaries.treatmentMethods;
		var treatmentMethods = [];
		for ( var a = 0; a < ar.length; ++a)
		{
			treatmentMethod = document.getElementById(this.id + '.treatmentMethod.' + ar[a].id)
			if ( treatmentMethod.checked )
			{
				treatmentMethods.push(treatmentMethod.value)
			}
		}
		return treatmentMethods;
	}
	
};

	this.onSelectCondition = function(select)
	{
		//alert('Inside onSelectCondition');
		if ( ! select.options[select.selectedIndex].value )
		{
			select.selectedIndex = 0;
		}
	}
	
gpr.forms.patientConditionView = function(id,onCancel)
{
	this.id = id;
	this.onCancel = onCancel;
	gpr.registry.add(this);
	var cdw = (id.indexOf('ShowPatientReport')>-1)?true:false;
	this.getHtml = function(patientID, patientCondition)
	{
		patientCondition = patientCondition || {id:0, patientID:patientID,isActive:1, treatmentMethodIDs:[],timeStamp:0,icdCode:''};
		var html = [];
		if(cdw == true)
        {
			html.push('<span style="float:right">' +
                      '<span onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;">' + 
					  '<a class="cdwlink" href="javascript:void(0)" ' +'>Go Back</a></span>' +
                      '&nbsp;&nbsp;<a class="cdwlink" href="javascript:void(0)" align="right" onclick="window.close()">Close this window</a>' + 
                      '</span>' + '<table align="center">' +
                      '<tr>' +'<td classl="gpr-panel-caption" colspan="2">' +
                      '<h3>Medical History of  ' + gpr.data.patient.firstName + ' ' + gpr.data.patient.lastName + '</h3>' +
                      '</td>' +'</tr></table>'
                      );
        }
		html.push(
			'<input id="' + this.id + '.ICDCode" type="hidden" value="' + (patientCondition.icdCode) + '">' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientCondition.id + '">' +
			'<input id="' + this.id + '.patientID" type="hidden" value="' + patientCondition.patientID + '">' +
			'<input id="' + this.id + '.timeStamp" type="hidden" value="' + patientCondition.timeStamp + '">' +
			'<table class="gpr-panel-Condition" width="90%" cellspacing="0" cellpadding="0">' +
				'<tr>' +
					'<td class="gpr-panel-caption" colspan="2">Condition</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="padding-bottom:5" colspan="2">' +
					'<table class="gpr-panel-section" cellpadding="0" cellspacing="0" width="100%">' +
							'<tr>' +
								'<td width="25%">' +
									'&nbsp;<label for="' + this.id + '.conditionID" >Condition <label>' +
								'</td>'+
								'<td>'+
								(gpr.Trim(gpr.htmlString(patientCondition.conditionID ? gpr.findID(gpr.dictionaries.conditions, patientCondition.conditionID, {name:''}).name : patientCondition.conditionName))?gpr.htmlString(patientCondition.conditionID ? gpr.findID(gpr.dictionaries.conditions, patientCondition.conditionID, {name:''}).name : patientCondition.conditionName):'--') +
								'</td></tr>'+
							'<tr>'+ '<td>' + 
							'&nbsp;' + '<label for="' + this.id + '.doyouhavethiscondition">Do you have this condition ? </label>'+'</td><td>'
							);
					if(patientCondition.isActive == true)
					{
						html.push('<label for="' + this.id + '.Yes" >Yes</label>');
					}
					else
					{
						html.push('<label for="' + this.id + '.Yes" >No</label>');
					}	 
				html.push(	'</td></tr><tr>' +
							'<td class="gpr-panel-caption" colspan="2">Details</td>' +
							'</tr>' + '<tr>' +
							'<td colspan="2">'+
							'<table class="gpr-panel-section" width="100%">' +
							'<tr>' + '<td width="25%">' + '&nbsp;Condition Type' + '</td><td>'
						);
						if(patientCondition.severity == 0)
						{
							html.push('Acute');
						}
						else
						{
							html.push('Chronic');
						}
				html.push('<br>' + '</td>' + '</tr></table>' );
				html.push ('</td>'+
				'</tr>'+
				'<tr>'+
				'<td colspan="2">'+
				'<table class="gpr-panel-section" width="100%">' +
						'<tr>' +
							'<td width="25%" >' +
                                  '<label for="' + this.id + '.diagnosisDate" >&nbsp;Date of Diagnosis<label>' +
							'</td>' +
							'<td>' +
							(gpr.isNullDate(patientCondition.diagnosisDate) ? '--' : gpr.htmlString(patientCondition.diagnosisDate)) +
							'&nbsp;&nbsp;(mm/dd/yyyy) </td>' +
							'<td width="20%" >' +
							'<label for="' + this.id + '.onsetDate" >Date of Onset<label>' +
							'</td>' +
							'<td>' +
							(gpr.isNullDate(patientCondition.onsetDate) ? '--' : gpr.htmlString(patientCondition.onsetDate)) +
							'&nbsp;&nbsp;(mm/dd/yyyy) </td>' +
							'</tr>' +
							'<tr>'+'<td>' +
							'<label for="' + this.id + '.resolutionDate" >&nbsp;Date Resolved<label>' +
							'</td>' +
							'<td>' +
							(gpr.isNullDate(patientCondition.resolutionDate) ? '--' : gpr.htmlString(patientCondition.resolutionDate))+ 
							'&nbsp;&nbsp;(mm/dd/yyyy)</td>' +
							'<td nowrap>' +
                            '<label for="' + this.id + '.lastTreatmentDate" >Date Last Treated<label>' +
							'</td>' +
							'<td>' +
							(gpr.isNullDate(patientCondition.lastTreatmentDate) ? '--' : gpr.htmlString(patientCondition.lastTreatmentDate))+
							'&nbsp;&nbsp;(mm/dd/yyyy) </td>' +
							'</tr></td></table>'+
					'</td></tr>'+
					'<tr>'+
					'<td class="gpr-panel-caption" colspan="2">&nbsp;Treatment Methods</td></tr>' +
					'<tr>' +
					'<td style="padding-bottom:5px" colspan="2" >' +
						'<table class="gpr-panel-section" width="100%">' +
							'<tr>'+'<td  style="padding-left:5px">'+'Treatment Methods' + '</td>' +
							'</tr>'+
							'<tr>'+'<td  style="padding-left:5px">&nbsp;'
					);
					this.getTreatmentMethodList(html, patientCondition.treatmentMethodIDs);		
					html.push('</td></tr>' +
							'</table>'+'</td>' +'</tr>' +			
							'<tr valign="top">' +
								'<td width="20%" style="padding-left:5px">' +
									'<label for="' + this.id + '.providerID">Provider treating this condition <label>' +
								'</td>' +
								'<td colspan="3">' +
								(gpr.Trim(gpr.htmlString(patientCondition.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientCondition.providerID, '') : patientCondition.providerName))?gpr.htmlString(patientCondition.providerID ? gpr.findProviderByID(gpr.data.patientProviders, patientCondition.providerID, '') : patientCondition.providerName):'--')	
								+'</td></tr>' +
							'<tr>' +
								'<td style="padding-left:5px">' +
									'<label for="' + this.id + '.comments" >Comments<label>' +
								'</td>' +
								'<td colspan="3">' +
									gpr.htmlString(patientCondition.comments) +
								'</td>' +
							'</tr>' +
								'</table></div></td></tr>'+
							'<tr>' +
								'<td colspan="2"><hr></td>' +
							'</tr>' +
					'<tr>' +
					'<td align="center" colspan="2">' +
						'<span class="dropshadow" onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onCancel\'); return false;" >' +
							'<a href="javascript:void(0)" ' +'>Cancel</a>' +
						'</span>' +
					'</td>' +
				'</tr>' +
				'</table>'
			);
						
		return html.join(''); 
		}
	this.getTreatmentMethodList = function(html, treatmentMethodIds)
	{
		if(treatmentMethodIds.length == 0 )
		{
			html.push('--');
		}
		else
		{
			for ( var a = 0; a < treatmentMethodIds.length; ++a)
			{
				html.push(
					(gpr.Trim(gpr.findID(gpr.dictionaries.treatmentMethods, treatmentMethodIds[a], {name:''}).name)?gpr.findID(gpr.dictionaries.treatmentMethods, treatmentMethodIds[a], {name:''}).name:'--')
					)
				html.push(a == treatmentMethodIds.length-1 ? '' : ', ')
			}
		}
	}
	
};
	
	
	
//-------------------------------------------------------------------------------------------------------------


//********************* : Blood Tests : *********************************

gpr.forms.patientBloodTests = function(id, onChange,onClose)
{
	this.id = id;
	this.onChange = onChange;
	this.onClose = onClose;
	gpr.registry.add(this);

	this.getHtml = function(patientID, patientBloodTests)
	{
		var html = [];
		
		html.push(
			'' +
			'<input id="' + this.id + '.id" type="hidden" value="' + patientID + '">' +
			'<br>' +
			'<table class="gpr-panel panel-border" width="90%">' +
			 ' <tr><td colspan="6" class="gpr-panel-caption">BLOOD TESTS ('+ gpr.data.patients[patientID].firstName +')</td>' +
			 '<td class="gpr-panel-caption" align="right"  ><span class="panel-button"> <a href="javascript:void(0)" id = "addbloodtest" ' +
					' onclick="gpr.dispatcher.call(\'' + this.id + '\', \'onChange\', 0); return false;"' +
				'>Add Blood Test </a></span></td></tr>' 

		);
		
		if(patientBloodTests.length == 0)
		{
			html.push('<tr><td colspan="6" width="100%" align="center">To add blood tests for <i>' + gpr.data.patients[patientID].firstName + ' </i>, click on "Add Blood Test" button above </td></tr></table>')	
		}
		else
		{
		   html.push('<tr>' +
					'<td id="' + this.id + 'testType" class="panel-column-header">' +
						'Test Type' +
					'</td>' +
					'<td id="' + this.id + 'cPTCodeDescription" class="panel-column-header">' +
						'Test Name' +
					'<td id="' + this.id + '.testDate" class="panel-column-header">' +
						'Test Date' +
					'</td>' +
					'<td id="' + this.id + '.testValue" class="panel-column-header">' +
						'Value' +
					'</td>' +
					'<td id="'
