//HealthJournal

function showChildren(childValue,tableTR) {

	var DataTR = eval('document.all.' + tableTR);
	if(childValue != 4) {
		DataTR.style.display="none";
	} else {
		DataTR.style.display="block";
	}
	
}

//HealthCareProvider

function editHealthCareRow(rowId) {

	var focusVal = "providername"+rowId;
	var idVal = "primarycarephysician" + rowId;
	var idValue = "groupassociation" + rowId;
	for (var i = 0; i<document.healthCareProvidersForm.length; i++) {
		var elmnts = document.healthCareProvidersForm.elements[i].name + rowId;
		if (document.healthCareProvidersForm.elements[i].id == elmnts) {
	   	 	document.healthCareProvidersForm.elements[i].readOnly = false;  
	   	}
	   	try {
			document.getElementById(idVal).disabled = false;
			document.getElementById(idValue).disabled = false;
		} catch(err) {
			
		}
			
	}
	
	document.getElementById(focusVal).focus();
	
}

function addHCProviderFormRow() {
	
	var result = checkHCProviderRequiredFields();
	if (result == true) {
		var tbl = document.getElementById('hcprovider');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);

		if(document.getElementById('showError').innerHTML!=''){
		document.getElementById('showError').innerHTML='';
		}

		var tbody = document.getElementById("hcprovider").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		    
	    var content1='';
	    	content1+='<input type="text" name="providername" value="" class="provider_name" maxlength="255" id=providername';
	    	content1+= idVal;
	    	content1+='>';
	    
		var content2='';
			content2+='<select name="primarycarephysician" id=primarycarephysician';
			content2+= idVal;
			content2+='>';
			content2+='<option value="">-- Select --</option>';
			content2+='<option value="1" Title="Yes">Yes</option>';
			content2+='<option value="0" Title="No">No</option>';
			content2+='</select>';
			
			
		
		var content3='';
			content3+='<select name="groupassociation" id=groupassociation';
			content3+= idVal;
			content3+=' onmouseover="tip_it(1,\'\',\'Please select Group/Association\');" onmouseout="tip_it(0, \'\', \'\')">';
			content3+='<option value="">-- Select --</option>';
			content3+='<option value="Group" Title="Group">Group</option>';
			content3+='<option value="Association" Title="Group">Association</option></select>';
			
		var content4='';
			content4+='<textarea name="address" class="addy" id=address';
			content4+= idVal; 
			content4+=' onkeyup="return ismaxlength(this)">';
			content4+='</textarea>';
		
		var content5='';
			content5+='<nobr>Phone: <input type="text" name="phone" value="" class="phone" maxlength="15" id=phone';
			content5+= idVal; 
			content5+='></nobr><br />';
			content5+='<nobr>Email: <input type="text" name="email" value="" class="email" maxlength="255" id=email';
			content5+= idVal; 
			content5+='></nobr><br />';
			content5+='<nobr>Fax: <input type="text" name="fax" value="" class="phone" maxlength="15"  id=fax';
			content5+= idVal; 
			content5+='></nobr><br />';
		
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
			cell5.className='contact';
			cell5.innerHTML=content5;
			
		var cell6 = document.createElement("td");
			                    
	    row.appendChild(cell1);
	    row.appendChild(cell2);
	    row.appendChild(cell3);
	    row.appendChild(cell4);
		row.appendChild(cell5);
	    row.appendChild(cell6);
	    tbody.appendChild(row);
	    
	    var focusVal = "providername"+idVal;
	    document.getElementById(focusVal).focus();

    }
}

function checkHCProviderRequiredFields() {
	
	var mess = '';
	var result = true;
	var result1 = true;
	for (var i = 0; i<document.healthCareProvidersForm.length; i++) {
		try {
			var idValue = "providername" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Provider name is required.</li></ul>';
				document.getElementById('showError').innerHTML = mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {

			if(	document.getElementById('showError').innerHTML !=""){
				document.getElementById('showError').innerHTML ='';
			}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.healthCareProvidersForm.length; i++) {
		try {
			var idEmailValue = "email" + i ;
			if (document.getElementById(idEmailValue).value.length > 0) {
				if(checkEmail(document.getElementById(idEmailValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Invalid email address.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idEmailValue).focus();
					}
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	if(result && result1) {
		return true;
	} else {
		return false;
	}
}

function enableHCProviderCombo() {
	
	var result = checkHCProviderRequiredFields(); 
	if(result == true) {
		for (var i = 0; i<document.healthCareProvidersForm.length; i++) {
			try {
				var idVal = "primarycarephysician" + i;
				document.getElementById(idVal).disabled = false;
				var idValue = "groupassociation" + i;
				document.getElementById(idValue).disabled = false;
			} catch(err) {
			
			}
	
		}
		return true;
	} else {
		return false;
	}
}

//InsuranceProvider

function editInsProviderRow(rowId) {

	var focusVal = "companyname"+rowId;
	for (var i = 0; i<document.insuranceProvidersForm.length; i++) {
		var elmnts = document.insuranceProvidersForm.elements[i].name + rowId;
		if (document.insuranceProvidersForm.elements[i].id == elmnts) {
	   	 	document.insuranceProvidersForm.elements[i].readOnly = false;   
	   	}
	}
	
	document.getElementById(focusVal).focus();
	
}

function addInsProviderFormRow() {

	var result = checkInsProviderRequiredFields();
	if (result == true) {
		var tbl = document.getElementById('insprovider');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("insprovider").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		
		var content1='';
			content1+='<span class="required">*</span>&nbsp;<nobr>Company Name: <input type="text" name="companyname" value="" maxlength="255" class="company_name" id=companyname';
			content1+= idVal;
			content1+='><br /></nobr><nobr>Contact Name: <input type="text" name="contactname" value="" maxlength="255" class="contact_name" id=contactname';
			content1+= idVal;
			content1+='></nobr><br />';

		var content2='';
			content2+='Complete Address: <textarea name="address" class="addy" id=address';
			content2+= idVal; 
			content2+=' onkeyup="return ismaxlength(this)">';
			content2+='</textarea>';

		var content3='';
			content3+='<nobr>ID Group &#035;: <input type="text" name="identificationgroup" value="" maxlength="255" class="group_num" id=identificationgroup';
			content3+= idVal;
			content3+='><br /></nobr><nobr>Member &#035;: <input type="text" name="member" value="" maxlength="25" class="member_num" id=member';
			content3+= idVal;
			content3+='></nobr><br />';

		var content4='';
			content4+='<nobr>Email: <input type="text" name="email" value="" maxlength="255"  class="email" id=email';
			content4+= idVal; 
			content4+='></nobr><br />';
			content4+='<nobr>Phone: <input type="text" name="phone" value="" maxlength="15" class="phone" id=phone';
			content4+= idVal; 
			content4+='></nobr><br />';
			content4+='<nobr>Fax: <input type="text" name="fax" value="" maxlength="15"  class="fax" id=fax';
			content4+= idVal; 
			content4+='></nobr><br />';
			
		var cell1 = document.createElement("td");
			cell1.className='company';
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.className='num';
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.className='contact';
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);	
		
		var focusVal = "companyname"+idVal;
		document.getElementById(focusVal).focus();
	
	}

}

function checkInsProviderRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	for (var i = 0; i<document.insuranceProvidersForm.length; i++) {
		try {
			var idValue = "companyname" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Company name is required.</li></ul>';
				document.getElementById('showError').innerHTML = mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML !=""){
				document.getElementById('showError').innerHTML ='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.insuranceProvidersForm.length; i++) {
		try {
			var idEmailValue = "email" + i ;
			if (document.getElementById(idEmailValue).value.length > 0) {
				if(checkEmail(document.getElementById(idEmailValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Invalid email address.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idEmailValue).focus();
					}
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	if(result && result1) {
		return true;
	} else {
		return false;
	}
}

//MedicalHistory

function editMedHistoryRow(rowId) {

	var dateSet = "onsetdate"+rowId;
	var focusVal = "diseasename"+rowId;
	
	for (var i = 0; i<document.medicalHistoryForm.length; i++) {
		var elmnts = document.medicalHistoryForm.elements[i].name + rowId;
		if (document.medicalHistoryForm.elements[i].id == elmnts) {
	   	 	document.medicalHistoryForm.elements[i].readOnly = false;  
	   	}
	   	document.getElementById(focusVal).disabled = false;
	}
	for (var i = 0; i<document.medicalHistoryForm.length; i++) {
		document.getElementById(dateSet).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'onsetdate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	
	document.getElementById(focusVal).focus();

}

function addMedHistoryFormRow() {

	var result = checkMedHistoryRequiredFields(); 
	if(result == true) {
		var tbl = document.getElementById('medhistory');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("medhistory").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		
		var content = document.getElementById("diseasename0").innerHTML;
		var removeSelected = remove(content,"selected");
		
		var content1 = '<select name="diseasename" class="disease" id=diseasename';
			content1 += idVal;
			content1 += '>'
			content1 += removeSelected;
			content1 += '</select>'
		
		var content2='';
			content2+='<input type="text" name="onsetdate" value="" readonly="readonly" class="date" id=onsetdate';
			content2+= idVal;
			content2+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'onsetdate';
			content2+= idVal;
			content2+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
			
		var content3='';
			content3+='<textarea name="comments" class="comments" id=comments';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea>'	
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
		
		
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		tbody.appendChild(row);	
		var focusVal = "diseasename"+idVal;
		document.getElementById(focusVal).focus();
	
	}
}

function checkMedHistoryRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	for (var i = 0; i<document.medicalHistoryForm.length; i++) {
		try {
			var idValue = "diseasename" + i;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Disease name is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=''){
				document.getElementById('showError').innerHTML='';
			}
			
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.medicalHistoryForm.length; i++) {
		try {
			var idDateValue = "onsetdate" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Date of onset can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	if(result && result1) {
		return true;
	} else {
		return false;
	}
}

function enableMedHistoryCombo() {
	
	var result = checkMedHistoryRequiredFields(); 
	if(result == true) {
		for (var i = 0; i<document.medicalHistoryForm.length; i++) {
			try {
				var idValue = "diseasename" + i;
				document.getElementById(idValue).disabled = false;
			} catch(err) {
			
			}
	
		}
		return true;
	} else {
		return false;
	}

}

//InfectionDiseases

function editInfectionRow(rowId) {

	var dateSet = "dateofonset"+rowId;
	var focusVal = "diseasename"+rowId;
	
	for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
		var elmnts = document.infectionDiseasesForm.elements[i].name + rowId;
		if (document.infectionDiseasesForm.elements[i].id == elmnts) {
	   	 	document.infectionDiseasesForm.elements[i].readOnly = false;  
	   	}
	   	try {
			document.getElementById(focusVal).disabled = false;
		} catch(err) {
			
		}
	}
	for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
		document.getElementById(dateSet).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofonset';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(focusVal).focus();

}

function addInfectionFormRow() {

	var result = checkInfectionDiseasesRequiredFields(); 
	if(result == true) {
		var tbl = document.getElementById('infection');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("infection").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		
		var content = document.getElementById("diseasename0").innerHTML;
		var removeSelected = remove(content,"selected");
		
		var content1 = '<select name="diseasename" class="disease" id=diseasename';
			content1 += idVal;
			content1 += '>'
			content1 += removeSelected;
			content1 += '</select>'
		
		var content2='';
			content2+='<input type="text" name="age" value="" maxlength="3" class="age" id=age';
			content2+= idVal;
			content2+='>';
			
		var content3='';
			content3+='<input type="text" name="dateofonset" value="" readonly="readonly" class="date" id=dateofonset';
			content3+= idVal;
			content3+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofonset';
			content3+= idVal;
			content3+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
			
		var content4='';
			content4+='<textarea name="comments" class="comments" id=comments';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>'	
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
		
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);	
		
		var focusVal = "diseasename"+idVal;
		document.getElementById(focusVal).focus();
		
	
	}
}

function checkInfectionDiseasesRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
		
		try {
			var idValue = "diseasename" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Disease name is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
		try {
			var idAgeValue = "age" + i ;
			if (document.getElementById(idAgeValue).value.length > 0) {
				if(allDigits(document.getElementById(idAgeValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idAgeValue).focus();
					}
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
		try {
			var idDateValue = "dateofonset" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Date of onset can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1 && result2) {
		return true;
	} else {
		return false;
	}
}

function enableInfectionDiseasesCombo() {
	
	var result = checkInfectionDiseasesRequiredFields(); 
	if(result == true) {
		for (var i = 0; i<document.infectionDiseasesForm.length; i++) {
			try {
				var idVal = "diseasename" + i;
				document.getElementById(idVal).disabled = false;
			} catch(err) {
			
			}
	
		}
		return true;
	} else {
		return false;
	}
}

//Immunization

function editImmunizationRow(rowId) {

	var date0 = "boosterdate0"+rowId;
	var date1 = "boosterdate1"+rowId;
	var date2 = "boosterdate2"+rowId;
	var date3 = "boosterdate3"+rowId; 
	var focusVal = "immunizationfor"+rowId;
	
	for (var i = 0; i<document.immunizationsForm.length; i++) {
		var elmnts = document.immunizationsForm.elements[i].name + rowId;
		if (document.immunizationsForm.elements[i].id == elmnts) {
	   	 	document.immunizationsForm.elements[i].readOnly = false;  
	   	}
	   	try {
			document.getElementById(focusVal).disabled = false;
		} catch(err) {
			
		}
	}
	for (var i = 0; i<document.immunizationsForm.length; i++) {
		document.getElementById(date0).readOnly = true;
		document.getElementById(date1).readOnly = true;
		document.getElementById(date2).readOnly = true;
		document.getElementById(date3).readOnly = true;
		break;
	}
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate0';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanOneId = "span1"+rowId;
	var content2 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate1';
		content2+= rowId;
		content2+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanTwoId = "span2"+rowId;
	var content3 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate2';
		content3+= rowId;
		content3+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanThreeId = "span3"+rowId;
	var content4 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate3';
		content4+= rowId;
		content4+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(spanOneId).innerHTML = content2;
	document.getElementById(spanTwoId).innerHTML = content3;
	document.getElementById(spanThreeId).innerHTML = content4;
	
	document.getElementById(focusVal).focus();

}

function addImmunizationFormRow() {

	var result = checkImmunizationRequiredFields(); 
	if(result == true) {
		var tbl = document.getElementById('immunization');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("immunization").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		
		var content = document.getElementById("immunizationfor0").innerHTML;
		var removeSelected = remove(content,"selected");
		
		var content1 = '<select name="immunizationfor" class="immune" id=immunizationfor';
			content1 += idVal;
			content1 += '>'
			content1 += removeSelected;
			content1 += '</select>'
			
		var content2 = '';
    		content2 += '<table class="mini"> <tr> <td class="ml">Age: </td> <td><input type="text" name="boosterage0" value="" class="age" maxlength="3" id=boosterage0';
			content2 += idVal;
			content2 += '></td> </tr> <tr> <td class="ml">Date: </td> <td><input type="text" name="boosterdate0" value="" readonly="readonly" class="date" id=boosterdate0'
			content2 += idVal;
			content2 += '>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate0';
			content2 += idVal;
			content2 += '\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
			content2 += '</td> </tr> </table>';
			
		var content3 = '';
     		content3 += '<table class="mini"> <tr> <td class="ml">Age: </td> <td><input type="text" name="boosterage1" value="" class="age" maxlength="3" id=boosterage1';
	 		content3 += idVal;
	  		content3 += '></td> </tr> <tr> <td class="ml">Date: </td> <td><input type="text" name="boosterdate1" value="" readonly="readonly" class="date" id=boosterdate1';
	   		content3 += idVal;
	   		content3 += '>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate1';
	    	content3 += idVal;
		 	content3 += '\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		  	content3 += '</td> </tr> </table>';
		  	
		var content4 = '';
			content4 +=	'<table class="mini"> <tr> <td class="ml">Age: </td> <td><input type="text" name="boosterage2" value="" class="age" maxlength="3" id=boosterage2';
			content4 += idVal;
			content4 += '></td> </tr> <tr> <td class="ml">Date: </td> <td><input type="text" name="boosterdate2" value="" readonly="readonly" class="date" id=boosterdate2';
			content4 += idVal;
			content4 += '>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate2';
			content4 += idVal;
			content4 += '\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
			content4 += '</td> </tr> </table>';
			
		var content5 = '';
			content5 +=	'<table class="mini"> <tr> <td class="ml">Age: </td> <td><input type="text" name="boosterage3" value="" class="age" maxlength="3" id=boosterage3';
			content5 += idVal;
			content5 += '></td> </tr> <tr> <td class="ml">Date: </td> <td><input type="text" name="boosterdate3" value="" readonly="readonly" class="date" id=boosterdate3';
			content5 += idVal;
			content5 += '>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'boosterdate3';
			content5 += idVal;
			content5 += '\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
			content5 += '</td> </tr> </table>';
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
			cell5.innerHTML=content5;
			
		var cell6 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		row.appendChild(cell6);
		tbody.appendChild(row);
		
		var focusVal = "immunizationfor"+idVal;
		document.getElementById(focusVal).focus();	
	}		
			
}

function checkImmunizationRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	for (var i = 0; i<document.immunizationsForm.length; i++) {
	
		try {
			var idValue = "immunizationfor" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Immunization For is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.immunizationsForm.length; i++) {
		try {
			
			var idboosterAge0 = "boosterage0" + i ;
			var idboosterAge1 = "boosterage1" + i ;
			var idboosterAge2 = "boosterage2" + i ;
			var idboosterAge3 = "boosterage3" + i ;
			
			if (document.getElementById(idboosterAge0).value.length > 0) {
				if(allDigits(document.getElementById(idboosterAge0).value)) {
					result1 = true;
				} else {
					mess += '<ul><li>Booster0 age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idboosterAge0).focus();
					}
					result1 = false;
					break;
				}
			}
			if (document.getElementById(idboosterAge1).value.length > 0) {
				if(allDigits(document.getElementById(idboosterAge1).value)) {
					result1 = true;
				} else {
					mess += '<ul><li>Booster1 age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idboosterAge1).focus();
					}
					result1 = false;
					break;
				}
			}
			if (document.getElementById(idboosterAge2).value.length > 0) {
				if(allDigits(document.getElementById(idboosterAge2).value)) {
					result1 = true;
				} else {
					mess += '<ul><li>Booster2 age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idboosterAge2).focus();
					}
					result1 = false;
					break;
				}
			}
			if (document.getElementById(idboosterAge3).value.length > 0) {
				if(allDigits(document.getElementById(idboosterAge3).value)) {
					result1 = true;
				} else {
					mess += '<ul><li>Booster3 age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idboosterAge3).focus();
					}
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	} 
	
	/*
	for (var i = 0; i<document.immunizationsForm.length; i++) {
		try {
			var boosterdate0 = "boosterdate0" + i ;
			var boosterdate1 = "boosterdate1" + i ;
			var boosterdate2 = "boosterdate2" + i ;
			var boosterdate3 = "boosterdate3" + i ;
			
		if (document.getElementById(boosterdate0).value.length > 0 ) {
				if(validateDate(document.getElementById(boosterdate0).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Booster0 date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
			if (document.getElementById(boosterdate1).value.length > 0 ) {
				if(validateDate(document.getElementById(boosterdate1).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Booster1 date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
			if (document.getElementById(boosterdate2).value.length > 0 ) {
				if(validateDate(document.getElementById(boosterdate2).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Booster2 date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
			if (document.getElementById(boosterdate3).value.length > 0 ) {
				if(validateDate(document.getElementById(boosterdate3).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Booster3 date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	} */
	
	if(result && result1) {
		return true;
	} else {
		return false;
	}

}

function enableImmunizationCombo() {
	
	var result = checkImmunizationRequiredFields(); 
	if(result == true) {
		for (var i = 0; i<document.immunizationsForm.length; i++) {
			try {
				var idVal = "immunizationfor" + i;
				document.getElementById(idVal).disabled = false;
			} catch(err) {
			
			}
	
		}
		return true;
	} else {
		return false;
	}
}
	

//Allergy-SensitiveDrugs

function editAllergyRow(rowId) {

	var idVal = "lastrecordeddate"+rowId;
	var focusVal = "allergicto"+rowId;
	for (var i = 0; i<document.allergySensitiveDrugsForm.length; i++) {
		var elmnts = document.allergySensitiveDrugsForm.elements[i].name + rowId;
		if (document.allergySensitiveDrugsForm.elements[i].id == elmnts) {
	   	 	document.allergySensitiveDrugsForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.allergySensitiveDrugsForm.length; i++) {
		document.getElementById(idVal).readOnly = true;
		break;
	}
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'lastrecordeddate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	
	document.getElementById(focusVal).focus();
	
}

function addAllergyFormRow() {
			
	var result = checkAllergyRequiredFields();
	if(result == true) {
		var tbl = document.getElementById('allergy');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);

		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("allergy").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1='<input type="text" name="allergicto" value="" maxlength="255" class="allergy" id=allergicto';
			content1+= idVal;
			content1+='>';
		
		var content2='';
			content2+='<input type="text" name="reaction" value=""  maxlength="255" class="reaction" id=reaction';
			content2+= idVal;
			content2+='>';
		
		var content3='';
			content3+='<input type="text" name="lastrecordeddate" value="" class="date" readonly="readonly" id=lastrecordeddate';
			content3+= idVal;
			content3+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'lastrecordeddate';
			content3+= idVal;
			content3+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		
		var content4='';
			content4+='<textarea name="treatment" class="treatment" id=treatment';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>'	
						
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);
		var focusVal = "allergicto"+idVal;
		document.getElementById(focusVal).focus();
		
	} 
}

function checkAllergyRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	for (var i = 0; i<document.allergySensitiveDrugsForm.length; i++) {
		try {
			var idValue = "allergicto" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Alergy/Sensitive is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {

			if(document.getElementById('showError').innerHTML!=''){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch (err) {
		
		}
	}
	
	for (var i = 0; i<document.allergySensitiveDrugsForm.length; i++) {
		try {
			var idReactionValue = "reaction" + i ;
			if (document.getElementById(idReactionValue).value.length < 1) {
				mess += '<ul><li>Reaction is required</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				if (result) {
					document.getElementById(idReactionValue).focus();
				} 
				result1 = false;
				break;
			} else {
				if (result) {

				if(document.getElementById('showError').innerHTML!=""){
					document.getElementById('showError').innerHTML='';
					}
				}
				result1 = true;
					
			}
		} catch (err) {
		
		}
	}
	for (var i = 0; i<document.allergySensitiveDrugsForm.length; i++) {
		try {
			var idDateValue = "lastrecordeddate" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Date Last Occured can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1 && result2) {
		return true;
	} else {
		return false;
	}
	
	
}	

//HealthLog

function editHealthLogRow(rowId) {

	var idVal = "diagnosisdate"+rowId;
	var focusVal = "doctorsname"+rowId;
	for (var i = 0; i<document.healthLogsForm.length; i++) {
		var elmnts = document.healthLogsForm.elements[i].name + rowId;
		if (document.healthLogsForm.elements[i].id == elmnts) {
	   	 	document.healthLogsForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.healthLogsForm.length; i++) {
		document.getElementById(idVal).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'diagnosisdate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(focusVal).focus();

}

function addHealthLogFormRow() {

	var result = checkHealthLogRequiredFields();
	if(result == true) {

		var tbl = document.getElementById('healthLog');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("healthLog").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<input type="text" name="diagnosisdate" value="" readonly="readonly" class="date" id=diagnosisdate'
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'diagnosisdate';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		var content2='';
			content2+='<table class="mini"><tr><td class="ml"><span class="required">*</span>&nbsp;Doctor\'s Name:</td><td><input type="text" name="doctorsname" value="" maxlength="255" id=doctorsname';
			content2+= idVal;
			content2+='></td></tr><tr><td class="ml">Nature of Problem:</td><td><input type="text" name="natureofproblem" value="" maxlength="255" id=natureofproblem';
			content2+= idVal;
			content2+='></td></tr><tr><td class="ml">Age at onset:</td><td><input type="text" name="onsetage" maxlength="3" value="" class="age" id=onsetage';
			content2+= idVal;
			content2+='></td></tr></table>';
		var content3='';
			content3+='<table class="mini"><tr><td class="ml">Condition/Status:</td><td><input type="text" name="currentstatus" value="" maxlength="255" id=currentstatus';
			content3+= idVal;
			content3+='></td></tr><tr class="msg"><td class="ml">Comments:</td><td><textarea name="comments" class="comments" id=comments';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea></td></tr></table>';
						
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		tbody.appendChild(row);
		
		var focusVal = "doctorsname"+idVal;
		document.getElementById(focusVal).focus();
		
	} 

}

function checkHealthLogRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	for (var i = 0; i<document.healthLogsForm.length; i++) {

		try {
		
			var idValue = "doctorsname" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Doctor Name is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.healthLogsForm.length; i++) {
		try {
			var idDateValue = "diagnosisdate" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Date Diagnosed can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.healthLogsForm.length; i++) {
		try {
			var idAgeValue = "onsetage" + i ;
			if (document.getElementById(idAgeValue).value.length > 0) {
				if(allDigits(document.getElementById(idAgeValue).value)) {
					result2 = true;
				} else {
					mess += '<ul><li>Age is invalid.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					if (result) {
						document.getElementById(idAgeValue).focus();
					}
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1 && result2) {
		return true;
	} else {
		return false;
	}
}	

//Medication

function editMedicationsRow(rowId) {

	var presDate = "prescriptiondate"+rowId;
	var startDate = "startdate"+rowId;
	var endDate = "enddate"+rowId;
	var focusVal = "medicinename"+rowId;
	
	for (var i = 0; i<document.medicationsForm.length; i++) {
		var elmnts = document.medicationsForm.elements[i].name + rowId;
		if (document.medicationsForm.elements[i].id == elmnts) {
	   	 	document.medicationsForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.medicationsForm.length; i++) {
		document.getElementById(presDate).readOnly = true;
		document.getElementById(startDate).readOnly = true;
		document.getElementById(endDate).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'prescriptiondate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanOneId = "span1"+rowId;
	var content2 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'startdate';
		content2+= rowId;
		content2+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanTwoId = "span2"+rowId;
	var content3 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'enddate';
		content3+= rowId;
		content3+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(spanOneId).innerHTML = content2;
	document.getElementById(spanTwoId).innerHTML = content3;
	
	document.getElementById(focusVal).focus();
	
}

function addMedicationFormRow(){

	var result = checkMedicationRequiredFields();
	if(result == true) {
	
		var tbl = document.getElementById('medication');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("medication").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<span class="required">*</span>&nbsp;Name:<input type="text" name="medicinename"  maxlength="255" value="" id=medicinename';
			content1+= idVal;
			content1+='><br />Dose:<input type="text" name="medicinedose"  maxlength="255" value="" id=medicinedose';
			content1+= idVal;
			content1+='><br />Freq:<input type="text" name="medicinefreq"  maxlength="255" value="" id=medicinefreq';
			content1+= idVal;
			content1+='><br />Prescribed By:<input type="text" name="prescribedby" maxlength="255" value="" id=prescribedby';
			content1+= idVal;
			content1+='>';
		
		var content2='';
			content2+='Prescription Date: <input type="text" name="prescriptiondate" value="" readonly="readonly" class="date" id=prescriptiondate';
			content2+= idVal;
			content2+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'prescriptiondate';
			content2+= idVal;
			content2+='\'));return false" HIDEFOCUS>';
			content2+='<img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a><br />';

			content2+='Start Date: <input type="text" name="startdate" value="" readonly="readonly" class="date" id=startdate';
			content2+= idVal;
			content2+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'startdate';
			content2+= idVal;
			content2+='\'));return false" HIDEFOCUS>';
			content2+='<img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a><br />';

			content2+='End Date: <input type="text" name="enddate" value="" readonly="readonly" class="date" id=enddate';
			content2+= idVal;
			content2+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'enddate';
			content2+= idVal;
			content2+='\'));return false" HIDEFOCUS>';
			content2+='<img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a><br />';
	
		var content3='';
			content3+='<table class="mini"><tr><td class="ml">Allergic Reaction:</td><td><input type="text" name="allergyreaction" maxlength="255" value="" id=allergyreaction';
			content3+= idVal;
			content3+='></td></tr><tr class="msg"><td class="ml">Comments:</td><td><textarea name="comments" id=comments';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea></td></tr></table>';
						
		var cell1 = document.createElement("td");
			cell1.className='presc';
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.className='dates';
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		tbody.appendChild(row);
		
		var focusVal = "medicinename"+idVal;
		document.getElementById(focusVal).focus();
	} 

}

function checkMedicationRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	var result3 = true;
	for (var i = 0; i<document.medicationsForm.length; i++) {

		try {
			var idValue = "medicinename" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Name is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		}catch(err) {
		
		}
	}
	for (var i = 0; i<document.medicationsForm.length; i++) {
		try {
			var prescriptionDate = "prescriptiondate" + i ;
			if (document.getElementById(prescriptionDate).value.length > 0 ) {
				if(validateDate(document.getElementById(prescriptionDate).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Prescription Date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}/*
	for (var i = 0; i<document.medicationsForm.length; i++) {
		try {
			var startDate = "startdate" + i ;
			if (document.getElementById(startDate).value.length > 0 ) {
				if(validateDate(document.getElementById(startDate).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Start Date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.medicationsForm.length; i++) {
		try {
			var endDate = "enddate" + i ;
			if (document.getElementById(endDate).value.length > 0 ) {
				if(validateDate(document.getElementById(endDate).value)) {
					result3 = true;
				}else {
					mess += '<ul><li>End Date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result3 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}*/
	for (var i = 0; i<document.medicationsForm.length; i++) {
		try {
			var startDate = "startdate" + i ;
			var endDate = "enddate" + i ;	
					
			if ((document.getElementById(startDate).value.length && 
				document.getElementById(endDate).value.length) > 0 ) {
				var strDate  = document.getElementById(startDate).value;				
				var enDate = document.getElementById(endDate).value;
				if ( enDate < strDate ) {
					mess += '<ul><li>Start date can not be greater than End date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result3 = false;
					break;			
				}
			}
		} catch(err) {
		
		}
	}
	if(result && result1 && result3) {
		return true;
	} else {
		return false;
	}
}

//DoctorVisit

function editDoctorVisitRow(rowId) {

	var idVal = "visitdate"+rowId;
	var focusVal = "doctorsname"+rowId;
	for (var i = 0; i<document.doctorVisitsForm.length; i++) {
		var elmnts = document.doctorVisitsForm.elements[i].name + rowId;
		if (document.doctorVisitsForm.elements[i].id == elmnts) {
	   	 	document.doctorVisitsForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.doctorVisitsForm.length; i++) {
		document.getElementById(idVal).readOnly = true;
		break;
	}
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'visitdate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(focusVal).focus();
	
}

function addDoctorVisitFormRow(){
			
	var result = checkDoctorVisitRequiredFields();
	if(result == true) {
		var tbl = document.getElementById('doctorVisit');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("doctorVisit").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<input type="text" name="visitdate" value="" readonly="readonly" class="date"  id=visitdate'
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'visitdate';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		var content2='';
			content2+='<input type="text" name="doctorsname" value="" class="doctor" maxlength="255" id=doctorsname';
			content2+= idVal;
			content2+='>';
		var content3='';
			content3+='<input type="text" name="reason" value="" class="reason" maxlength="255" id=reason';
			content3+= idVal;
			content3+='>';
		var content4='';
			content4+='<textarea name="diagnosis" class="diagnosis" id=diagnosis';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>';
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;
	
		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;
	
		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
	
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
			
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);
		
		var focusVal = "doctorsname"+idVal;
		document.getElementById(focusVal).focus();
	}

}

function checkDoctorVisitRequiredFields() {

	var mess = ''; 
	var result = true;
	var result1 = true;
	var result2 = true;
	
	for (var i = 0; i<document.doctorVisitsForm.length; i++) {
		try {
			var idValue = "visitdate" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Date is required</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	
	for (var i = 0; i<document.doctorVisitsForm.length; i++) {
		try {
			var doctorValue = "doctorsname" + i;
			if (document.getElementById(doctorValue).value.length < 1) {
				mess += '<ul><li>Doctor Name is required</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				if (result) {
					document.getElementById(doctorValue).focus();
				}
				result1 = false;
				break;
			} else {
				if (result) {
				if(document.getElementById('showError').innerHTML!=""){
					document.getElementById('showError').innerHTML='';
					}
				}
				result1 = true;
			}
		} catch(err) {
		
		}
	}
	
	for (var i = 0; i<document.doctorVisitsForm.length; i++) {
		try {
			var idDateValue = "visitdate" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1 && result2) {
		return true;
	} else {
		return false;
	}
}

//Hospitalization

function editHospitalizationRow(rowId) {

	var admissionDate = "admissiondate"+rowId;
	var dischargeDate = "dischargedate"+rowId;
	var focusVal = "doctorsname"+rowId;
	
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		var elmnts = document.hospitalizationForm.elements[i].name + rowId;
		if (document.hospitalizationForm.elements[i].id == elmnts) {
	   	 	document.hospitalizationForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		document.getElementById(admissionDate).readOnly = true;
		document.getElementById(dischargeDate).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'admissiondate';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	var spanOneId = "span1"+rowId;
	var content2 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dischargedate';
		content2+= rowId;
		content2+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(spanOneId).innerHTML = content2;
	document.getElementById(focusVal).focus();
	
}

function addHospitalizationFormRow() {

	var result = checkHospitalizationRequiredFields();
	if(result == true) {
	
		var tbl = document.getElementById('hospitalization');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("hospitalization").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<span class="required">*</span>&nbsp;Admission Date: <input type="text" name="admissiondate" value="" readonly="readonly" class="date" id=admissiondate';
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'admissiondate';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS>';
			content1+='<img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a><br />';
			content1+='Discharge Date: <input type="text" name="dischargedate" value="" readonly="readonly" class="date" id=dischargedate';
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dischargedate';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS>';
			content1+='<img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a><br />';

		var content2='';
			content2+='<input type="text" name="doctorsname" value="" maxlength="255" id=doctorsname';
			content2+= idVal;
			content2+='>';

		var content3='';
			content3+='<textarea name="reason" id=reason';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea>';

		var content4='';
			content4+='<textarea name="diagnosis" id=diagnosis';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>';
						
		var cell1 = document.createElement("td");
			cell1.className='dates';
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.valign = "top";
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;
		
		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;

		var cell5 = document.createElement("td");
						
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);	
		
		var focusVal = "doctorsname"+idVal;
		document.getElementById(focusVal).focus();
	}

}

function checkHospitalizationRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	var result2 = true;
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		try {
			var idValue = "admissiondate" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Admission date is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else {
			if(document.getElementById('showError').innerHTML!=''){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		try {
			var idDateValue = "admissiondate" + i ;
			if (document.getElementById(idDateValue).value.length > 0 ) {
				if(validateDate(document.getElementById(idDateValue).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Admission date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		try {
			var dischargeDate = "dischargedate" + i ;
			if (document.getElementById(dischargeDate).value.length > 0 ) {
				if(validateDate(document.getElementById(dischargeDate).value)) {
					result2 = true;
				}else {
					mess += '<ul><li>Discharge date can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	for (var i = 0; i<document.hospitalizationForm.length; i++) {
		try {
			var dischargeDate = "dischargedate" + i ;
			var admissionDate = "admissiondate" + i ;			
			if ((document.getElementById(dischargeDate).value.length && 
				document.getElementById(admissionDate).value.length) > 0) {
				var disDate = document.getElementById(dischargeDate).value;
				
				var admDate = document.getElementById(admissionDate).value;
				if ( disDate < admDate ) {
					mess += '<ul><li>Admission date can not be greater than Discharge date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result2 = false;
					break;			
				}
			}
		} catch(err) {
		
		}
	}
	if(result && result1 && result2) {
		return true;
	} else {
		return false;
	}


}

//Lab&Image

function editLabImageRow(rowId) {

	var focusVal = "testtype"+rowId;
	for (var i = 0; i<document.labImageForm.length; i++) {
		var elmnts = document.labImageForm.elements[i].name + rowId;
		if (document.labImageForm.elements[i].id == elmnts) {
	   	 	document.labImageForm.elements[i].readOnly = false;  
	   	}
	}
	document.getElementById(focusVal).focus();
	
}

function addLabImageFormRow() {

	var result = checkLabImageRequiredFields();
	if(result == true) {
		var tbl = document.getElementById('laborimage');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=''){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("laborimage").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<input type="text" name="testtype" value="" maxlength="255" class="testtype"  id=testtype'
			content1+= idVal;
			content1+='>'
			var content2='';
			content2+='<input type="text" name="requestingdoctor" value="" maxlength="255" class="doctor" id=requestingdoctor';
			content2+= idVal;
			content2+='>';
		var content3='';
			content3+='<textarea name="reason" class="reason" id=reason';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea>';
		var content4='';
			content4+='<textarea name="result" class="result" id=result';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>';
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;

		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
			
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);
		
		var focusVal = "testtype"+idVal;
		document.getElementById(focusVal).focus();
	
	}

}

function checkLabImageRequiredFields() {

	var mess = '';
	var result = true;
	for (var i = 0; i<document.labImageForm.length; i++) {
	
		try {
			var idValue = "testtype" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Test Type is required</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
			} else if (document.getElementById(idValue).value.length > 1) {

				if(document.getElementById('showError').innerHTML!=''){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch(err) {
		
		}
	}
	return result;
}

// Vision 

function editVisionRow(rowId) {

	var idVal = "dateofvisit"+rowId;
	var focusVal = "nameofdoctor"+rowId;
	for (var i = 0; i<document.visionForm.length; i++) {
		var elmnts = document.visionForm.elements[i].name + rowId;
		if (document.visionForm.elements[i].id == elmnts) {
	   	 	document.visionForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.visionForm.length; i++) {
		document.getElementById(idVal).readOnly = true;
		break;
	}
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofvisit';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(focusVal).focus();
	
}

function addVisionFormRow(){
	
	var result = checkVisionRequiredFields();
	if(result == true) {
	
		var tbl = document.getElementById('vision');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=''){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("vision").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<input type="text" name="dateofvisit" value="" readonly="readonly" class="date"  id=dateofvisit'
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofvisit';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		var content2='';
			content2+='<input type="text" name="nameofdoctor" value="" class="doctor"  maxlength="255" id=nameofdoctor';
			content2+= idVal;
			content2+='>';
		var content3='';
			content3+='<textarea name="visionprescription" class="prescription" id=prescription';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea>';
		var content4='';
			content4+='<textarea name="comments" class="comments" id=comments';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>';
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;

		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
			
		var cell5 = document.createElement("td");
			
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);
		
		var focusVal = "nameofdoctor"+idVal;
		document.getElementById(focusVal).focus();
	}

}

function checkVisionRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	for (var i = 0; i<document.visionForm.length; i++) {
	
		try {
			var idValue = "dateofvisit" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Date of Visit is required.</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
					
			} else {
			if(document.getElementById('showError').innerHTML!=""){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		}catch (err) {
		
		}
	}
	
	for (var i = 0; i<document.visionForm.length; i++) {
		try {
			var visitDate = "dateofvisit" + i ;
			if (document.getElementById(visitDate).value.length > 0 ) {
				if(validateDate(document.getElementById(visitDate).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Date of visit can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1) {
		return true;
	} else {
		return false;
	}

		
	
}

//Dental

function editDentalRow(rowId) {
	
	var idVal = "dateofvisit"+rowId;
	var focusVal = "dentistname"+rowId;
	for (var i = 0; i<document.dentalForm.length; i++) {
		var elmnts = document.dentalForm.elements[i].name + rowId;
		if (document.dentalForm.elements[i].id == elmnts) {
	   	 	document.dentalForm.elements[i].readOnly = false;  
	   	}
	}
	for (var i = 0; i<document.dentalForm.length; i++) {
		document.getElementById(idVal).readOnly = true;
		break;
	}
	
	var spanId = "span"+rowId;
	var content1 = '<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofvisit';
		content1+= rowId;
		content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
	
	document.getElementById(spanId).innerHTML = content1;
	document.getElementById(focusVal).focus();
	
}

function addDentalFormRow(){

	var result = checkDentalVisitRequiredFields();
	if(result == true) {

		var tbl = document.getElementById('dental');
		var lastRow = tbl.rows.length;
		var idVal = eval(lastRow-1);
		if(document.getElementById('showError').innerHTML!=""){
		document.getElementById('showError').innerHTML='';
		}
		var tbody = document.getElementById("dental").getElementsByTagName("tbody")[0];
		var row = document.createElement("tr");
		var content1='';
			content1+='<input type="text" name="dateofvisit" value="" readonly="readonly" class="date"  id=dateofvisit';
			content1+= idVal;
			content1+='>&nbsp;<a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.getElementById(\'dateofvisit';
			content1+= idVal;
			content1+='\'));return false" HIDEFOCUS><img align="absmiddle" src="js/calendar/calbtn.gif" width="34" height="22" border="0" alt="Calendar"></a>';
		var content2='';
			content2+='<input type="text" name="dentistname" value="" class="dentist" maxlength="255" id=dentistname';
			content2+= idVal;
			content2+='>';
		var content3='';
			content3+='<textarea name="problems" class="problem" id=problems';
			content3+= idVal;
			content3+=' onkeyup="return ismaxlength(this)"></textarea>';
		var content4='';
			content4+='<textarea name="resolution" class="resolution" id=resolution';
			content4+= idVal;
			content4+=' onkeyup="return ismaxlength(this)"></textarea>';
			
		var cell1 = document.createElement("td");
			cell1.innerHTML=content1;

		var cell2 = document.createElement("td");
			cell2.innerHTML=content2;

		var cell3 = document.createElement("td");
			cell3.innerHTML=content3;

		var cell4 = document.createElement("td");
			cell4.innerHTML=content4;
		
		var cell5 = document.createElement("td");
			
		row.appendChild(cell1);
		row.appendChild(cell2);
		row.appendChild(cell3);
		row.appendChild(cell4);
		row.appendChild(cell5);
		tbody.appendChild(row);
		var focusVal = "dentistname"+idVal;
		document.getElementById(focusVal).focus();
		
	}

}
function checkDentalVisitRequiredFields() {

	var mess = '';
	var result = true;
	var result1 = true;
	for (var i = 0; i<document.dentalForm.length; i++) {
		
		try {
			var idValue = "dateofvisit" + i ;
			if (document.getElementById(idValue).value.length < 1) {
				mess += '<ul><li>Date of Visit is required</li></ul>';
				document.getElementById('showError').innerHTML= mess;
				document.location.href="#error";
				document.getElementById(idValue).focus();
				result = false;
				break;
					
			} else {
			if(document.getElementById('showError').innerHTML!=''){
				document.getElementById('showError').innerHTML='';
				}
				result = true;
				
			}
		} catch (err) {
		
		}
	}

	for (var i = 0; i<document.dentalForm.length; i++) {
		try {
			var visitDate = "dateofvisit" + i ;
			if (document.getElementById(visitDate).value.length > 0 ) {
				if(validateDate(document.getElementById(visitDate).value)) {
					result1 = true;
				}else {
					mess += '<ul><li>Date of visit can not be greater than current date.</li></ul>';
					document.getElementById('showError').innerHTML = mess;
					document.location.href="#error";
					result1 = false;
					break;
				}
			}
		} catch(err) {
		
		}
	}
	
	if(result && result1) {
		return true;
	} else {
		return false;
	}
	
}

//Other Validation.

function allDigits(str) {
     return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset) {
     var result = true;

     for (var i=0;i<str.length;i++) 
          if (charset.indexOf(str.substr(i,1))<0) {
               result = false;
               break;
          }
     
     return result;
}

function checkEmail(emailStr) {
   if (emailStr.length == 0) {
       return true;
   }
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);
   if (matchArray == null) {
       return false;
   }
   var user=matchArray[1];
   var domain=matchArray[2];
   if (user.match(userPat) == null) {
       return false;
   }
   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
       for (var i = 1; i <= 4; i++) {
          if (IPArray[i] > 255) {
             return false;
          }
       }
       return true;
   }
   var domainArray=domain.match(domainPat);
   if (domainArray == null) {
       return false;
   }
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if ((domArr[domArr.length-1].length < 2) ||
       (domArr[domArr.length-1].length > 3)) {
       return false;
   }
   if (len < 2) {
       return false;
   }
   return true;
}


function remove(s, t) {

	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + remove(s.substring(i + t.length), t);
	return r;
	
}

//Checks if the given date is less than current date.
function validateDate(dateStr) {
	
	var strDate = new Date(dateStr);
  	var curDate = new Date();
  	if (strDate > curDate) {
		return false;
	}
	return true;
}

function ismaxlength(obj) {

	var mlength=4000
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
	
}

function confirmDelete() {

    var agree = confirm("Are you sure you wish to delete this entry?");
    if (agree)
        return true;
    else
        return false;
} 


function callAction(actionStr) {

	if(actionStr == "Export") {
		document.forms['eventregreport'].action="registeredEventExportCSVAction.do";
		document.forms['eventregreport'].method="POST";
		document.forms['eventregreport'].submit(); 
	} else {
		document.forms['eventregreport'].action="registeredEventsSearchAction.do";
		document.forms['eventregreport'].method="POST";
		document.forms['eventregreport'].submit();
	}

	
	
}


//ToolTip
<!--

ContentInfo = "";
topColor = "#808080"
subColor = "#FFFFCC"
var mouse_X;
var mouse_Y;
var tip_active = 0;

function update_tip_pos() {

	document.getElementById('ToolTip').style.left = mouse_X + 20;
	document.getElementById('ToolTip').style.top  = mouse_Y;

}

var ie = document.all?true:false;
if (!ie) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

function getMouseXY(e) {

	if (ie) { // grab the x-y pos.s if browser is IE
		mouse_X = event.clientX + document.body.scrollLeft;
		mouse_Y = event.clientY + document.body.scrollTop;
	}
	else { // grab the x-y pos.s if browser is NS
		mouse_X = e.pageX;
		mouse_Y = e.pageY;
	}
	if (mouse_X < 0){mouse_X = 0;}
	if (mouse_Y < 0){mouse_Y = 0;}
	if(tip_active){update_tip_pos();}

}

function EnterContent(TTitle, TContent) {

	ContentInfo = '<table border="1" width="100" cellspacing="0" cellpadding="0">'+ 
					'<tr><td width="100%" bgcolor='+subColor+' bordercolor="#000000">'+
					'<table border="0" width="100%" cellspacing="1" cellpadding="0">'+
					'<tr><td width="100%" bgcolor='+subColor+' bordercolor="#000000">'+
					'<table border="0" width="90%" cellpadding="0" cellspacing="1" align="center">'+
					'<tr><td width="100%">'+
					'<font class="tooltipcontent">'+TContent+'</font>'+
					'</td></tr>'+
					'</table>'+
					'</td></tr>'+
					'</table>'+
					'</td></tr>'+
					'</table>';

}

function tip_it(which, TTitle, TContent) {	

	if(which){	
		update_tip_pos();	
		tip_active = 1;		
		document.getElementById('ToolTip').style.visibility = "visible";		
		EnterContent(TTitle, TContent);		
		document.getElementById('ToolTip').innerHTML = ContentInfo;	
	}else{	
		tip_active = 0;	
		document.getElementById('ToolTip').style.visibility = "hidden";
	}

}

//-->

