function populateMyUs() {
	var iWe = document.getElementsByName('form10b.declaration.point1.iWe1')[0];

	if (iWe.value == "1") {
		document.getElementsByName('form10b.declaration.point2.iWe1')[0].value = 'I';
		document.getElementsByName('form10b.declaration.point3.myOur')[0].value = 'my';
		document.getElementsByName('form10b.declaration.point4.myOur')[0].value = 'my';
		document.getElementsByName('form10b.declaration.point5.myUs')[0].value = 'me';
		document.getElementsByName('form10b.declaration.point6.myOur')[0].value = 'my';
		document.getElementsByName('form10b.declaration.point7.myUs')[0].value = 'me';
		document.getElementsByName('form10b.declaration.point8.myOur')[0].value = 'my';
		document.getElementsByName('form10b.declaration.point9.myOur')[0].value = 'my';
		document.getElementsByName('form10b.declaration.point10.myUs')[0].value = 'me';
	} else if (iWe.value == "2") {
		document.getElementsByName('form10b.declaration.point2.iWe1')[0].value = 'we';
		document.getElementsByName('form10b.declaration.point3.myOur')[0].value = 'our';
		document.getElementsByName('form10b.declaration.point4.myOur')[0].value = 'our';
		document.getElementsByName('form10b.declaration.point5.myUs')[0].value = 'us';
		document.getElementsByName('form10b.declaration.point6.myOur')[0].value = 'our';
		document.getElementsByName('form10b.declaration.point7.myUs')[0].value = 'us';
		document.getElementsByName('form10b.declaration.point8.myOur')[0].value = 'our';
		document.getElementsByName('form10b.declaration.point9.myOur')[0].value = 'our';
		document.getElementsByName('form10b.declaration.point10.myUs')[0].value = 'us';
	} else {
		document.getElementsByName('form10b.declaration.point2.iWe1')[0].value = '';
		document.getElementsByName('form10b.declaration.point3.myOur')[0].value = '';
		document.getElementsByName('form10b.declaration.point4.myOur')[0].value = '';
		document.getElementsByName('form10b.declaration.point5.myUs')[0].value = '';
		document.getElementsByName('form10b.declaration.point6.myOur')[0].value = '';
		document.getElementsByName('form10b.declaration.point7.myUs')[0].value = '';
		document.getElementsByName('form10b.declaration.point8.myOur')[0].value = '';
		document.getElementsByName('form10b.declaration.point9.myOur')[0].value = '';
		document.getElementsByName('form10b.declaration.point10.myUs')[0].value = '';

	}
}

function populateTrustInst() {
	var trustInst = document
			.getElementsByName('form10b.declaration.point1.trustInstType')[0];

	if (trustInst.value == "1") {
		document.getElementsByName('form10b.declaration.point11.trstInst')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part1.trstInst1')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst2')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst3')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst4')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst5')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst6')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst7')[0].value = 'trust';
		document.getElementsByName('form10b.annexture.part2.trstInst8')[0].value = 'trust';
	} else if (trustInst.value == "2") {
		document.getElementsByName('form10b.declaration.point11.trstInst')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part1.trstInst1')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst2')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst3')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst4')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst5')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst6')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst7')[0].value = 'institution';
		document.getElementsByName('form10b.annexture.part2.trstInst8')[0].value = 'institution';
	} else {
		document.getElementsByName('form10b.declaration.point11.trstInst')[0].value = '';
		document.getElementsByName('form10b.annexture.part1.trstInst1')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst2')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst3')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst4')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst5')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst6')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst7')[0].value = '';
		document.getElementsByName('form10b.annexture.part2.trstInst8')[0].value = '';
	}

}

function populateValues(src, dest) {

	var srcVal = document.getElementsByName(src)[0].value;
	if (srcVal != null || srcVal != "") {
		document.getElementsByName(dest)[0].value = srcVal.toUpperCase();
	} else {
		document.getElementsByName(dest)[0].value = "";
	}
}

function populateAnnexureIII() {
	document.getElementsByName('form10b.annexure3.point1.name')[0].value = document
			.getElementsByName('form10b.declaration.point1.name')[0].value

	document.getElementsByName('form10b.annexure3.point1.address')[0].value = document
			.getElementsByName('form10b.declaration.point1.address')[0].value

	document.getElementsByName('form10b.annexure3.point1.placeofSign')[0].value = document
			.getElementsByName('form10b.declaration.point1.placeofSign')[0].value

	document.getElementsByName('form10b.annexure3.point1.memNo')[0].value = document
			.getElementsByName('form10b.declaration.point1.memNo')[0].value

	document.getElementsByName('form10b.annexure3.point1.dateOfSign')[0].value = document
			.getElementsByName('form10b.declaration.point1.dateOfSign')[0].value

	document.getElementsByName('form10b.annexure3.point1.frn')[0].value = document
			.getElementsByName('form10b.declaration.point1.frn')[0].value

}

function enableAnnexureIIPt1() {
	var propertyLent = document
			.getElementsByName('form10b.annexture.part2.propertyLent')[0].value;

	var table = document.getElementById('pt1table');
	var noOfRows = table.rows.length;
	if (propertyLent == 'Y') {
		for (var i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].readOnly = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].readOnly = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].readOnly = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].readOnly = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].value = '';
		}
	} else {
		for (i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].value = '';
		}
	}
}

function enableAnnexureII(field, tableId, fieldHolder) {
	var fieldValue = document.getElementsByName(field)[0].value;

	var table = document.getElementById(tableId);
	var noOfRows = table.rows.length;

	if (fieldValue == 'Y') {
		for (var i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = false;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].value = '';

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = false;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].value = '';
		}
	} else {
		for (i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].value = '';

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].value = '';
		}
	}
}

function enableAnnexureIIperName(field, tableId, fieldHolder) {
	var fieldValue = document.getElementsByName(field)[0].value;

	var table = document.getElementById(tableId);
	var noOfRows = table.rows.length;

	if (fieldValue == 'Y') {
		for (var i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			// if(null !=
			// document.getElementsByName(fieldHolder+'['+i+'].perName')[0]){
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].readOnly = false;
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].value = '';
			// }

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = false;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].value = '';

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = false;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].value = '';
		}
	} else {
		for (i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			// if(null !=
			// document.getElementsByName(fieldHolder+'['+i+'].perName')[0]){
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].value = '';
			// }

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].value = '';

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].value = '';
		}
	}
}
function hideCompanyDetails() {
	var tab = document.getElementById('annx3table');
	var rowcount = tab.rows.length;
	for (var i = 0; i < rowcount - 4; i++) {
		var compFlag = document.getElementsByName('invstmtHeld[' + i + '].companyFlag')[0].value;
		if (compFlag == 'N') {
			document.getElementsByName('invstmtHeld[' + i + '].sharesClass')[0].value = '';
			document.getElementsByName('invstmtHeld[' + i + '].sharesClass')[0].disabled = true;
			document.getElementsByName('invstmtHeld[' + i + '].classOfShare')[0].value = '';
			document.getElementsByName('invstmtHeld[' + i + '].classOfShare')[0].disabled = true;
		}else if (compFlag == 'Y'){
			document.getElementsByName('invstmtHeld[' + i + '].sharesClass')[0].value = '';
			document.getElementsByName('invstmtHeld[' + i + '].sharesClass')[0].disabled = false;
			document.getElementsByName('invstmtHeld[' + i + '].classOfShare')[0].value = '';
			document.getElementsByName('invstmtHeld[' + i + '].classOfShare')[0].disabled = false;
		}
		
	}
}

function calculateTotalAnnexIII() {
	var tab = document.getElementById('annx3table');
	var rowcount = tab.rows.length;
	var totalTotNominalVal = 0, totalTotIncInvestment = 0;
	var totNominalVal = document
			.getElementsByName('invstmtHeld.totNominalValue')[0];
	var totIncInvestment = document
			.getElementsByName('invstmtHeld.totalIncInvestment')[0];

	for (var i = 0; i < rowcount - 4; i++) {
		var nominalVal = document.getElementsByName('invstmtHeld[' + i
				+ '].nominalValue')[0].value;
		var incInvestment = document.getElementsByName('invstmtHeld[' + i
				+ '].incmInvstmnt')[0].value;
		totalTotNominalVal = parseInt(coalesce(totalTotNominalVal), 10)
				+ parseInt(coalesce(nominalVal), 10);
		totalTotIncInvestment = parseInt(coalesce(totalTotIncInvestment), 10)
				+ parseInt(coalesce(incInvestment), 10);
	}

	totNominalVal.value = parseInt(totalTotNominalVal);
	totIncInvestment.value = parseInt(totalTotIncInvestment);
}

function enableAnnxIPt23(srcField, enableField) {
	var srcFieldVal = document.getElementsByName(srcField)[0].value;

	if (srcFieldVal == 'Y') {
		document.getElementsByName(enableField)[0].disabled = false;
		document.getElementsByName(enableField)[0].readOnly = false;
		document.getElementsByName(enableField)[0].value = '';
	} else {
		document.getElementsByName(enableField)[0].disabled = true;
		document.getElementsByName(enableField)[0].readOnly = true;
		document.getElementsByName(enableField)[0].value = '';
	}
}

function validateOnSubmit() {

	populateAnnexureIII();
	checkMembershipNoLengthLoad();
	setAssessmentYear('bsPrepDate');
}

function getPan() {
	return "";
}

function enableAnnexureIIPt1OnLoad() {
	var propertyLent = document
			.getElementsByName('form10b.annexture.part2.propertyLent')[0].value;

	var table = document.getElementById('pt1table');
	var noOfRows = table.rows.length;
	if (propertyLent == 'Y') {
		for (var i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].readOnly = false;

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].readOnly = false;

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].readOnly = false;

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].disabled = false;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].readOnly = false;
		}
	} else {
		for (i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].details')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].amount')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].rateOfInt')[0].value = '';

			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].disabled = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].readOnly = true;
			document
					.getElementsByName('form10b.annexture.part2.propertyLentDtl['
							+ i + '].natureOfSec')[0].value = '';
		}
	}
}

function enableAnnexureIIOnLoad(field, tableId, fieldHolder) {
	var fieldValue = document.getElementsByName(field)[0].value;

	var table = document.getElementById(tableId);
	var noOfRows = table.rows.length;

	if (fieldValue == 'Y') {
		for (var i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			if (null != document.getElementsByName(fieldHolder + '[' + i
					+ '].perName')[0]) {
				document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].disabled = false;
				document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].readOnly = false;
			}

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = false;

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = false;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = false;
		}
	} else {
		for (i = 0; i < eval(parseInt(noOfRows, 10) - 2); i++) {
			if (null != document.getElementsByName(fieldHolder + '[' + i
					+ '].perName')[0]) {
				document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].disabled = true;
				document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].readOnly = true;
				document.getElementsByName(fieldHolder + '[' + i + '].perName')[0].value = '';
			}

			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].details')[0].value = '';

			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].disabled = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].readOnly = true;
			document.getElementsByName(fieldHolder + '[' + i + '].amount')[0].value = '';
		}
	}
}

function enableAnnxIPt23OnLoad(srcField, enableField) {
	var srcFieldVal = document.getElementsByName(srcField)[0].value;

	if (srcFieldVal == 'Y') {
		document.getElementsByName(enableField)[0].disabled = false;
		document.getElementsByName(enableField)[0].readOnly = false;
	} else {
		document.getElementsByName(enableField)[0].disabled = true;
		document.getElementsByName(enableField)[0].readOnly = true;
		document.getElementsByName(enableField)[0].value = '';
	}
}

function checkMembershipNoLength(memberShipNO) {

	if (memberShipNO.value.length == 5) {
		memberShipNO.value = 0 + memberShipNO.value;
	} else if (memberShipNO.value.length == 4) {
		memberShipNO.value = '00' + memberShipNO.value;
	} else if (memberShipNO.value.length == 3) {
		memberShipNO.value = '000' + memberShipNO.value;
	} else if (memberShipNO.value.length == 2) {
		memberShipNO.value = '0000' + memberShipNO.value;
	} else if (memberShipNO.value.length == 1 && memberShipNO.value != 0) {
		memberShipNO.value = '00000' + memberShipNO.value;
	}
}

function checkMembershipNoLengthLoad() {

	var memberShipNO = document
			.getElementsByName('form10b.declaration.point1.memNo')[0];

	if (memberShipNO.value != null && memberShipNO.value != '') {
		if (memberShipNO.value.length == 5) {
			memberShipNO.value = 0 + memberShipNO.value;
		} else if (memberShipNO.value.length == 4) {
			memberShipNO.value = '00' + memberShipNO.value;
		} else if (memberShipNO.value.length == 3) {
			memberShipNO.value = '000' + memberShipNO.value;
		} else if (memberShipNO.value.length == 2) {
			memberShipNO.value = '0000' + memberShipNO.value;
		} else if (memberShipNO.value.length == 1 && memberShipNO.value != 0) {
			memberShipNO.value = '00000' + memberShipNO.value;
		}
	}
}

function setAssessmentYear(elemId) {
	var selectedDate = document.getElementById(elemId).value;
	if (validateDate(selectedDate)) {
		var fields = [ '01', '02', '03' ];
		var month = selectedDate.substring(3, 5);
		var year = selectedDate.substring(6);
		var assessmentYear = document
				.getElementsByName('form10b.formdetails.year')[0];
		assessmentYear.value = eval(parseInt(year, 10) + parseInt(1, 10));
		for (var i = 0; i < fields.length; i++) {
			if (fields[i] == month) {
				assessmentYear.value = year;
			}
		}
	}
}

function validateDate(testdate) {
	var date_regex = /^\d{2}\/\d{2}\/\d{4}$/;
	return date_regex.test(testdate);
}
