function showPatientDtlsInSrchRecord(patientId,rowId,parentScreen,referralCount,csId){
    document.getElementById('action').value='expandDetails';
    var screen="../referrals/expandPatientDetails.form";	
	jQuery.ajax({
	   type: 'GET',
	   url: screen,
	   data:"action=expandDetails&patientId="+patientId+"&csId="+csId,
       success: function(msg){
	       document.getElementById('action').value='';
	       if(msg.consultationNoteListSize>0 ||msg.listDtoSize>0){
	       		addMinusButton(rowId,patientId,parentScreen,referralCount,csId);
	       }
	       var tbl= document.getElementById('searchTableId');
	       var rowCount=document.getElementById(rowId).rowIndex+1+referralCount;
	       if(msg.consultationNoteListSize>0){
	        var attrName;
	        var attrValue;
	        var obj = msg.patientConsultationNotesDTO.consultationNoteList;
	        for(var key in obj){
				attrName = key;
				if (obj.hasOwnProperty(key)){
					attrValue=obj[key];
				}
				var conNoteGuid = attrValue.noteGuid;
				var row = tbl.insertRow(rowCount);
	      	 row.setAttribute('id','searchRowId'+rowCount);
	      	 if("FindExisting"==parentScreen){
	      	  	 if(rowCount%2==0){
	          	 	 row.setAttribute('class','oddRow');
	          	 }else{
	          	 	row.setAttribute('class','evenRow');
	          	 }
	      	 }else{
	      	  	 if(rowCount%2==0){
	          	 	 row.setAttribute('class','evenRow');
	          	 }else{
	          	 	row.setAttribute('class','oddRow');
	          	 }
	          }
	      	 var ContentTD = document.createTextNode(' '+attrName);
			 var TD = document.createElement("TD");
			 var newImg = document.createElement('img');
			 newImg.setAttribute('src','../images/16x16/application_view_columns.png');
			 var hyperLink = document.createElement('a');
			 hyperLink.appendChild (newImg);
		     hyperLink.setAttribute("href","consultationNote.form?patientId="+patientId+"&csId="+csId+"&conNoteId="+conNoteGuid);
			 hyperLink.setAttribute('title','Click here to view the form');
			 hyperLink.appendChild(ContentTD);
			 TD.appendChild(hyperLink);
			 TD.setAttribute ('colspan', '14');
			 TD.setAttribute ('class', 'patientHistoryFormNameTD');
			 row.appendChild(TD);
		     rowCount++;
	         }
	        }
	       if(msg.listDtoSize>0){
		       for(var index=0;index<msg.listDtoSize;index++){
		        	 var row = tbl.insertRow(rowCount);
		          	 row.setAttribute('id','searchRowId'+rowCount);
		         	 if("FindExisting"==parentScreen){
			      	  	 if(rowCount%2==0){
			          	 	 row.setAttribute('class','oddRow');
			          	 }else{
			          	 	row.setAttribute('class','evenRow');
			          	 }
			      	 }else{
			      	  	 if(rowCount%2==0){
			          	 	 row.setAttribute('class','evenRow');
			          	 }else{
			          	 	row.setAttribute('class','oddRow');
			          	 }
			          }
		      	     var ContentTD = document.createTextNode(' ' + msg.listDto.listImagingStatus[index].description);
		    		 var TD = document.createElement("TD");
		
		    		 var newImg = document.createElement('img');
		    		 newImg.setAttribute('src','../images/16x16/application_view_columns.png');
		    		 var hyperLink = document.createElement('a');
		    		 hyperLink.appendChild (newImg);
		    	     hyperLink.setAttribute("href","consultationNote.form?patientId="+patientId+"&csId"+csId+"&conNoteId="+msg.listDto.listImagingStatus[index].noteGuid+"&filterFormId="+msg.listDto.listImagingStatus[index].formId);
		    		 hyperLink.setAttribute('title','Click here to view the form');
		    		 
		    		 hyperLink.appendChild(ContentTD);
		    		 TD.appendChild(hyperLink);
		    		 TD.setAttribute ('colspan', '4');
		    		 TD.setAttribute ('class', 'patientHistoryFormNameTD');
		    		 row.appendChild(TD);
		
		    		 ContentTD = document.createTextNode(msg.listDto.listImagingStatus[index].statusDescription);
		    		 var TD = document.createElement("TD");
		    		 TD.appendChild(ContentTD);
		    		 if(msg.listDto.listImagingStatus[index].status ==2){
		    		 TD.setAttribute ('colspan','2');
		    		 }else{
		    		 TD.setAttribute ('colspan','10');
		    		 }
		    		 row.appendChild(TD);
		
				 if(msg.listDto.listImagingStatus[index].status ==2){
					 var newImg = document.createElement('img');
					 newImg.setAttribute('src','../images/16x16/zoom.png');
					 var hyperLink = document.createElement('a');
					 hyperLink.setAttribute('title','View');
					 hyperLink.appendChild (newImg);
				     hyperLink.setAttribute('href',"imgStatusTracking.form?patientId="+patientId);
					 TD = document.createElement("TD");	  
					 TD.appendChild(hyperLink);
					 TD.setAttribute ('colspan', '8');
					 row.appendChild(TD);
				}
				 rowCount++;
		       }
	       }
       	} 
	 });
}
function closeTable(patientId, fromRowId, toRowId,parentScreen,referralCount,csId){
	var table=document.getElementById('searchTableId');
	var rowCount=table.rows.length;
	var fromRowCount=document.getElementById(fromRowId).rowIndex+1;
	var toRowCount;
	if(document.getElementById(toRowId)){
	 toRowCount =document.getElementById(toRowId).rowIndex;
	}else{
	 toRowCount=rowCount
	}
	for(var i=fromRowCount;i<toRowCount;i++){
		if(document.getElementById('searchRowId'+i)){
		var row = document.getElementById('searchRowId'+i);
	    row.parentElement.removeChild(row); 
	    }
	}
	addPlusButton(patientId,fromRowId,parentScreen,referralCount,csId);
}

function addPlusButton(patientId,rowId,parentScreen,referralCount,csId){
	var row= document.getElementById(rowId);
	row.cells[0].innerHTML="";
  	var newImg = document.createElement('img');
  	newImg.setAttribute('src','../images/add.png');
  	newImg.setAttribute('onclick',"showPatientDtlsInSrchRecord('"+patientId+"','"+rowId+"','"+parentScreen+"',"+referralCount+","+csId+");");
  	newImg.setAttribute('title','more details');
  	newImg.setAttribute('value','Add');
    row.cells[0].appendChild(newImg);
}
function addMinusButton(rowId,patientId,parentScreen,referralCount,csId){
	var row= document.getElementById(rowId);
	var rowCount=document.getElementById(rowId).rowIndex;
	var nextRowCount=rowCount+1;
	row.cells[0].innerHTML="";
  	var newImg = document.createElement('img');
  	newImg.setAttribute('src','../images/minus_green.png');
  	newImg.setAttribute('onclick',"closeTable('"+patientId+"','"+rowId+"','rowId"+nextRowCount+"','"+parentScreen+"',"+referralCount+","+csId+");");
  	newImg.setAttribute('title','close details');
  	newImg.setAttribute('value','close');
    row.cells[0].appendChild(newImg);
  }
