// JavaScript Document For UCO Bank Education Loan Application Form By Suman Hait //

//========== Useful Functions Start ==========//
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, '');
}
function checkFieldLength(elm, len, msg) {
    if(elm.value.search(/\S/) != -1) {
        if(elm.value.length > len) {
            alert(msg + '\nCurrently you have entered ' + elm.value.length + ' characters.');
            elm.focus();
            return false;
        }
    }

    return true;
}
function isDate(dateStr, dateElm, chkType) {
	var dateFormat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	var matchArray = dateStr.match(dateFormat); // is the format ok?

	if (matchArray == null) {
		alert("Please enter date as dd/mm/yyyy format.");
		dateElm.focus();
		return false;
	}

	day = matchArray[1]; // parse date into variables
	month = matchArray[3];
	year = matchArray[5];

	if (day < 1 || day > 31) { // check day range
		alert("Day must be between 1 and 31.");
		dateElm.focus();
		return false;
	}

	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		dateElm.focus();
		return false;
	}

	var dt = new Date();
	var currentYear = parseInt(dt.getFullYear());

	if (chkType == '') {
		if (year < 1900 || year > currentYear) { // check year range
			alert("Year must be between 1900 and " + currentYear + ".");
			dateElm.focus();
			return false;
		}
	} else {
		if (year < currentYear) { // check year range
			alert("Year mustn't be less than " + currentYear + ".");
			dateElm.focus();
			return false;
		}
	}

	if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
		alert("Month " + month + " doesn't have 31 days.");
		dateElm.focus();
		return false;
	}

	if (month == 2) { // check for february 29th
		var isLeapYear = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !isLeapYear)) {
			alert("February " + year + " doesn't have " + day + " days.");
			dateElm.focus();
			return false;
		}
	}

	return true; // date is valid
}
function makePopUp(pageName, top, left, pageWidth, pageHeight) {
	window.open(pageName, 'myPopUp', 'top=' + top + ',left=' + left + ',width=' + pageWidth + ',height=' + pageHeight + ',directories=0,fullscreen=0,menubar=0,resizable=0,scrollbars=1,status=0,titlebar=1,toolbar=0', false);
}
//========== Useful Functions End ==========//

//========== Function is Called After Rendering Starts ==========//
function setOptionalValue() {
	var theForm = document.forms['FrmMain'];
	if(!theForm) { theForm = document.forms[0]; }
	if(!theForm) { theForm = document.FrmMain; }

	for(var i = 0; i < theForm.elements.length; i++) {
		if((theForm.elements[i].type == 'text') || (theForm.elements[i].type == 'textarea')) {
			//if((theForm.elements[i].name != 'CourseName') && (theForm.elements[i].name != 'ApplicantFName') && (theForm.elements[i].name != 'ApplicantLName') && (theForm.elements[i].name != 'PerAddress1') && (theForm.elements[i].name != 'PerCity') && (theForm.elements[i].name != 'PerPin') && (theForm.elements[i].name != 'PreAddress1') && (theForm.elements[i].name != 'PreCity') && (theForm.elements[i].name != 'PrePin') && (theForm.elements[i].name != 'Email') && (theForm.elements[i].name != 'TxtImgVer')) {
			if(theForm.elements[i].name != 'TxtImgVer') {
				if(theForm.elements[i].value.search(/\S/) == -1) {
					theForm.elements[i].value = 'NA';
				}
			}
			//}
		}
	}
}
//========== Function is Called After Rendering Ends ==========//

//========== AJAX Starts ==========//
var xmlHttp;
var what;
function getData(str, type) {
	what = type;
	xmlHttp = getXmlHttpObject(); /* Creating Object */
	if(xmlHttp == null) { return false; }
	var url = "AJAX.aspx"
	url = url + "?q=" + str
	url = url + "&rand=" + Math.random()
	url = url + "&what=" + what
	xmlHttp.onreadystatechange = stateChange
	if((what == '1') || (what == '2')) {
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	} else if(what == '3') {
		var params = "EncodeString=" + document.getElementById('EncodeString').value;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("content-length", params.length);
		xmlHttp.setRequestHeader("connection", "close");
		xmlHttp.send(params);
	}
}
function stateChange() {
	if(what == '1') {
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			document.getElementById('DistrictId').options.length = 0;
			document.getElementById('BranchId').options.length = 1;
			var newElement = document.createElement('OPTION');
			newElement.text = '-- Select District --';
			newElement.value = '0';
			document.getElementById('DistrictId').options.add(newElement);
			if(xmlHttp.responseText != '') {
				var strData = xmlHttp.responseText.substring(2);
				var arrStrData = strData.split('~!');
				var i = 0;
				while(i < arrStrData.length) {
					var arrThis = arrStrData[i].split('~');
					var newElement = document.createElement('OPTION');
					newElement.text = arrThis[1];
					newElement.value = arrThis[0];
					document.getElementById('DistrictId').options.add(newElement);
					i += 1;
				}
			}
		}
	} else if(what == '2') {
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			document.getElementById('BranchId').options.length = 0;
			var newElement = document.createElement('OPTION');
			newElement.text = '-- Select Branch --';
			newElement.value = '0';
			document.getElementById('BranchId').options.add(newElement);
			if(xmlHttp.responseText != '') {
				var strData = xmlHttp.responseText.substring(2);
				var arrStrData = strData.split('~!');
				var i = 0;
				while(i < arrStrData.length) {
					var arrThis = arrStrData[i].split('~');
					var newElement = document.createElement('OPTION');
					newElement.text = arrThis[1];
					newElement.value = arrThis[0];
					document.getElementById('BranchId').options.add(newElement);
					i += 1;
				}
			}
		}
	} else if(what == '3') {
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			document.getElementById('__DIV_MSG').innerHTML = xmlHttp.responseText;
			if(xmlHttp.responseText == 'Saving...') {
				document.getElementById('mode').value = 'SUBMIT';
				document.forms['FrmMain'].submit();
			}
		}
	}
}
function getXmlHttpObject() {
	var objXMLHttp = null;
	try {
		objXMLHttp = new XMLHttpRequest(); // except IE
	} catch (e) {
		try {
			objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP"); // IE higher
		} catch (e) {
			objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE lower
		}
	}
	return objXMLHttp;
}
//========== AJAX Ends ==========//

//========== Form Validation Starts ==========//
function checkForm() {
	var theForm = document.forms['FrmMain'];
	if(!theForm) { theForm = document.forms[0]; }
	if(!theForm) { theForm = document.FrmMain; }

	if((theForm.CourseName.value.search(/\S/) == -1) || (theForm.CourseName.value.trim().toUpperCase() == 'NA')) {
		alert('Please enter valid name of the course.');
		theForm.CourseName.focus();
		return false;
	}

	if((theForm.ApplicantFName.value.search(/\S/) == -1) || (theForm.ApplicantFName.value.trim().toUpperCase() == 'NA')) {
		alert('Please enter valid first name.');
		theForm.ApplicantFName.focus();
		return false;
	}

	if((theForm.ApplicantLName.value.search(/\S/) == -1) || (theForm.ApplicantLName.value.trim().toUpperCase() == 'NA')) {
		alert('Please enter valid last name.');
		theForm.ApplicantLName.focus();
		return false;
	}

	var varDay = parseInt(theForm.DayApplicantDOB.value);
	var varMonth = parseInt(theForm.MonthApplicantDOB.value);
	var varMonthName = theForm.MonthApplicantDOB.options[theForm.MonthApplicantDOB.selectedIndex].text;
	var varYear = parseInt(theForm.YearApplicantDOB.value);

	if(theForm.DayApplicantDOB.value == 'dd') {
		alert('Please enter day of date of birth.');
		theForm.DayApplicantDOB.focus();
		return false;
	}

	if(theForm.MonthApplicantDOB.value == 'mm') {
		alert('Please enter month of date of birth.');
		theForm.MonthApplicantDOB.focus();
		return false;
	}

	if(theForm.YearApplicantDOB.value == 'yyyy') {
		alert('Please enter year of date of birth.');
		theForm.YearApplicantDOB.focus();
		return false;
	}

 	if((varMonth == 4) || (varMonth == 6) || (varMonth == 9) || (varMonth == 11)) {
		if(varDay > 30) {
			alert(varMonthName + ' doesn\'t have ' + varDay + ' days.');
			theForm.DayApplicantDOB.focus();
			return false;
		}
	}

	if(varMonth == 2) {
		var isLeapYear = ((varYear % 4 == 0) && ((varYear % 100 != 0) || (varYear % 400 == 0)))
			if(varDay > 29 || (varDay == 29 && !isLeapYear)) {
			alert('February ' + varYear + ' doesn\'t have ' + varDay + ' days.');
			theForm.DayApplicantDOB.focus();
			return false;
		}
	}

	if(theForm.CategoryId.value == '0') {
		alert('Please select category.');
		theForm.CategoryId.focus();
		return false;
	}

	if(((theForm.PerAddress1.value.search(/\S/) == -1) || (theForm.PerAddress1.value.trim().toUpperCase() == 'NA')) && ((theForm.PerAddress2.value.search(/\S/) == -1) || (theForm.PerAddress2.value.trim().toUpperCase() == 'NA')) && ((theForm.PerAddress3.value.search(/\S/) == -1) || (theForm.PerAddress3.value.trim().toUpperCase() == 'NA'))) {
		alert('Please enter valid permanent address.');
		theForm.PerAddress1.focus();
		return false;
	}

	if((theForm.PerCity.value.search(/\S/) == -1) || (theForm.PerCity.value.trim().toUpperCase() == 'NA')) {
		alert('Please enter valid permanent city.');
		theForm.PerCity.focus();
		return false;
	}

	if(theForm.PerStateId.value == '0') {
		alert('Please select permanent state.');
		theForm.PerStateId.focus();
		return false;
	}

	var isWholeNumber = /^\s*\d+\s*$/;

	if(!isWholeNumber.test(theForm.PerPin.value)) {
		alert('Please enter valid permanent pin code.');
		theForm.PerPin.focus();
		return false;
	}

	if((theForm.DistrictId.value == '0') || (theForm.DistrictId.value == '')) {
		alert('Please select district.');
		theForm.DistrictId.focus();
		return false;
	}

	if((theForm.BranchId.value == '0') || (theForm.BranchId.value == '')) {
		alert('Please select branch.');
		theForm.BranchId.focus();
		return false;
	}

	if(((theForm.PreAddress1.value.search(/\S/) == -1) || (theForm.PreAddress1.value.trim().toUpperCase() == 'NA')) && ((theForm.PreAddress2.value.search(/\S/) == -1) || (theForm.PreAddress2.value.trim().toUpperCase() == 'NA')) && ((theForm.PreAddress3.value.search(/\S/) == -1) || (theForm.PreAddress3.value.trim().toUpperCase() == 'NA'))) {
		alert('Please enter valid present address.');
		theForm.PreAddress1.focus();
		return false;
	}

	if((theForm.PreCity.value.search(/\S/) == -1) || (theForm.PreCity.value.trim().toUpperCase() == 'NA')) {
		alert('Please enter valid present city.');
		theForm.PreCity.focus();
		return false;
	}

	if(theForm.PreStateId.value == '0') {
		alert('Please select present state.');
		theForm.PreStateId.focus();
		return false;
	}

	if(!isWholeNumber.test(theForm.PrePin.value)) {
		alert('Please enter valid present pin code.');
		theForm.PrePin.focus();
		return false;
	}

	var validEmail = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;

	if(!validEmail.test(theForm.Email.value)) {
		alert('Please enter valid email address.');
		theForm.Email.focus();
		return false;
	}

	var cnt = 0;

	for(var i = 0; i < theForm.elements.length; i++) {
		if((theForm.elements[i].type == 'text') || (theForm.elements[i].type == 'textarea')) {
			if(theForm.elements[i].style.display == '') {
				if(theForm.elements[i].name != 'TxtImgVer') {
					if(theForm.elements[i].value.search(/\S/) == -1) {
						theForm.elements[i].style.border = 'solid 1px #ff3300';
						cnt++;
					}
					else { theForm.elements[i].style.border = 'solid 1px gray'; }
				}
			}
		}
		/*if(theForm.elements[i].type == 'select-one') {
			if((theForm.elements[i].name.indexOf('ApplicantDOB') < 0) && (theForm.elements[i].name.indexOf('Duration') < 0)) {
				if(theForm.elements[i].value == '0') {
					theForm.elements[i].style.backgroundColor = '#eef3df';
					cnt++;
				}
				else { theForm.elements[i].style.backgroundColor = '#ffffff'; }
			}
			else {
				if(isNaN(theForm.elements[i].value)) {
					theForm.elements[i].style.backgroundColor = '#eef3df';
					cnt++;
				}
				else { theForm.elements[i].style.backgroundColor = '#ffffff'; }
			}
		}*/
	}

	/*varMsg = 'Please enter \'NA\' in every blank field.\n';
	varMsg += 'Every blank field is highlighted by red border.\n';
	varMsg += '\n';
	varMsg += 'Please select any value from every unselect list.\n';
	varMsg += 'Every unselect list is highlighted by light green background.';*/

	varMsg = 'Please enter \'NA\' in every blank field.\n';
	varMsg += 'Every blank field is highlighted by red border.';

	if(cnt != 0) {
		alert(varMsg);
		return false;
	}

    if(checkFieldLength(theForm.Address, 500, 'Please enter complete address of the college/institution/university within 500 characters.') == false) {
        return false;
    }

    if(checkFieldLength(theForm.Prospect, 2000, 'Please enter prospect for employment after completion of studies within 2000 characters.') == false) {
        return false;
    }

    if(theForm.MatureDate_1.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.MatureDate_1.value, theForm.MatureDate_1, 'UCO')) {
            return false;
        }
    }

    if(theForm.LastPreDate_1.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.LastPreDate_1.value, theForm.LastPreDate_1, '')) {
            return false;
        }
    }

    /*if(theForm.MatureDate_2.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.MatureDate_2.value, theForm.MatureDate_2, 'UCO')) {
            return false;
        }
    }

    if(theForm.LastPreDate_2.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.LastPreDate_2.value, theForm.LastPreDate_2, '')) {
            return false;
        }
    }

    if(theForm.MatureDate_3.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.MatureDate_3.value, theForm.MatureDate_3, 'UCO')) {
            return false;
        }
    }

    if(theForm.LastPreDate_3.value.trim().toUpperCase() != 'NA') {
        if(!isDate(theForm.LastPreDate_3.value, theForm.LastPreDate_3, '')) {
            return false;
        }
    }*/

    if(checkFieldLength(theForm.Security, 500, 'Please enter securities proposed, if any within 500 characters.') == false) {
        return false;
    }

    if(checkFieldLength(theForm.OtherInfo, 500, 'Please enter any other information which the applicant like to give within 500 characters.') == false) {
        return false;
    }

	/*var amtExpense = (parseFloat(theForm.Total_1st.value) + parseFloat(theForm.Total_2nd.value) + parseFloat(theForm.Total_3rd.value) + parseFloat(theForm.Total_4th.value) + parseFloat(theForm.Total_5th.value) + parseFloat(theForm.Total_6th.value));
	var amtIncome = (parseFloat(theForm.TotalOther_1st.value) + parseFloat(theForm.TotalOther_2nd.value) + parseFloat(theForm.TotalOther_3rd.value) + parseFloat(theForm.TotalOther_4th.value) + parseFloat(theForm.TotalOther_5th.value) + parseFloat(theForm.TotalOther_6th.value));*/

	var amtExpense = parseFloat(theForm.Total_Total.value);
	var amtIncome = parseFloat(theForm.TotalOther_Total.value);

	if(amtExpense > amtIncome) {
		theForm.LoanAmount.value = (amtExpense - amtIncome);
	} else {
		theForm.LoanAmount.value = 0;
	}

	if(theForm.Chk.checked == false) {
		alert('Please accept the terms and conditions.');
		return false;
	}

	if(document.getElementById('TxtImgVer').value.search(/\S/) == -1) {
		alert('Please enter image verification code.');
		document.getElementById('TxtImgVer').focus();
		return false;
	} else { getData(document.getElementById('TxtImgVer').value, '3'); }

	return false;
}
//========== Form Validation Ends ==========//

//========== Get Same Details Starts ==========//
function getSameDetails() {
	var theForm = document.forms['FrmMain'];
	if(!theForm) { theForm = document.forms[0]; }
	if(!theForm) { theForm = document.FrmMain; }

	if(theForm.CheckSame.checked) {
		theForm.PreAddress1.value = theForm.PerAddress1.value;
		theForm.PreAddress2.value = theForm.PerAddress2.value;
		theForm.PreAddress3.value = theForm.PerAddress3.value;
		theForm.PreCity.value = theForm.PerCity.value;
		theForm.PreStateId.value = theForm.PerStateId.value;
		theForm.PrePin.value = theForm.PerPin.value;
		theForm.PreMobile.value = theForm.PerMobile.value;
		theForm.PreSTDCode.value = theForm.PerSTDCode.value;
		theForm.PreTelNo.value = theForm.PerTelNo.value;
	} else {
		theForm.PreAddress1.value = '';
		theForm.PreAddress2.value = '';
		theForm.PreAddress3.value = '';
		theForm.PreCity.value = '';
		theForm.PreStateId.value = '0';
		theForm.PrePin.value = '';
		theForm.PreMobile.value = '';
		theForm.PreSTDCode.value = '';
		theForm.PreTelNo.value = '';
	}
}
//========== Get Same Details Ends ==========//

//========== Calculations Start ==========//
function getTotalForExpenses(val_1, val_2, val_3, val_4, val_5, str) {
	var total = 0;

	if(val_1.search(/\S/) == -1) { val_1 = 0; }
	else if(isNaN(val_1)) { val_1 = 0; }
	else { val_1 = parseFloat(val_1); }

	if(val_2.search(/\S/) == -1) { val_2 = 0; }
	else if(isNaN(val_2)) { val_2 = 0; }
	else { val_2 = parseFloat(val_2); }

	if(val_3.search(/\S/) == -1) { val_3 = 0; }
	else if(isNaN(val_3)) { val_3 = 0; }
	else { val_3 = parseFloat(val_3); }

	if(val_4.search(/\S/) == -1) { val_4 = 0; }
	else if(isNaN(val_4)) { val_4 = 0; }
	else { val_4 = parseFloat(val_4); }

	if(val_5.search(/\S/) == -1) { val_5 = 0; }
	else if(isNaN(val_5)) { val_5 = 0; }
	else { val_5 = parseFloat(val_5); }

	total = (val_1 + val_2 + val_3 + val_4 + val_5);

	document.getElementById(str).value = total.toFixed(2);
}
function getTotalForIncomeSources(val_1, val_2, val_3, val_4, str) {
	var total = 0;

	if(val_1.search(/\S/) == -1) { val_1 = 0; }
	else if(isNaN(val_1)) { val_1 = 0; }
	else { val_1 = parseFloat(val_1); }

	if(val_2.search(/\S/) == -1) { val_2 = 0; }
	else if(isNaN(val_2)) { val_2 = 0; }
	else { val_2 = parseFloat(val_2); }

	if(val_3.search(/\S/) == -1) { val_3 = 0; }
	else if(isNaN(val_3)) { val_3 = 0; }
	else { val_3 = parseFloat(val_3); }

	if(val_4.search(/\S/) == -1) { val_4 = 0; }
	else if(isNaN(val_4)) { val_4 = 0; }
	else { val_4 = parseFloat(val_4); }

	total = (val_1 + val_2 + val_3 + val_4);

	document.getElementById(str).value = total.toFixed(2);
}
function getColumnWiseTotal(val_1, val_2, val_3, val_4, val_5, val_6, str) {
	var total = 0;

	if(val_1.search(/\S/) == -1) { val_1 = 0; }
	else if(isNaN(val_1)) { val_1 = 0; }
	else { val_1 = parseFloat(val_1); }

	if(val_2.search(/\S/) == -1) { val_2 = 0; }
	else if(isNaN(val_2)) { val_2 = 0; }
	else { val_2 = parseFloat(val_2); }

	if(val_3.search(/\S/) == -1) { val_3 = 0; }
	else if(isNaN(val_3)) { val_3 = 0; }
	else { val_3 = parseFloat(val_3); }

	if(val_4.search(/\S/) == -1) { val_4 = 0; }
	else if(isNaN(val_4)) { val_4 = 0; }
	else { val_4 = parseFloat(val_4); }

	if(val_5.search(/\S/) == -1) { val_5 = 0; }
	else if(isNaN(val_5)) { val_5 = 0; }
	else { val_5 = parseFloat(val_5); }

	if(val_6.search(/\S/) == -1) { val_6 = 0; }
	else if(isNaN(val_6)) { val_6 = 0; }
	else { val_6 = parseFloat(val_6); }

	total = (val_1 + val_2 + val_3 + val_4 + val_5 + val_6);

	document.getElementById(str).value = total.toFixed(2);

	var val = 0;

	if(document.getElementById('Total_1st').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_1st').value)) {
			val += parseFloat(document.getElementById('Total_1st').value);
		}
	}

	if(document.getElementById('Total_2nd').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_2nd').value)) {
			val += parseFloat(document.getElementById('Total_2nd').value);
		}
	}

	if(document.getElementById('Total_3rd').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_3rd').value)) {
			val += parseFloat(document.getElementById('Total_3rd').value);
		}
	}

	if(document.getElementById('Total_4th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_4th').value)) {
			val += parseFloat(document.getElementById('Total_4th').value);
		}
	}

	if(document.getElementById('Total_5th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_5th').value)) {
			val += parseFloat(document.getElementById('Total_5th').value);
		}
	}

	if(document.getElementById('Total_6th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('Total_6th').value)) {
			val += parseFloat(document.getElementById('Total_6th').value);
		}
	}

	document.getElementById('_Total').value = val.toFixed(2);

	val = 0;

	if(document.getElementById('TotalOther_1st').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_1st').value)) {
			val += parseFloat(document.getElementById('TotalOther_1st').value);
		}
	}

	if(document.getElementById('TotalOther_2nd').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_2nd').value)) {
			val += parseFloat(document.getElementById('TotalOther_2nd').value);
		}
	}

	if(document.getElementById('TotalOther_3rd').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_3rd').value)) {
			val += parseFloat(document.getElementById('TotalOther_3rd').value);
		}
	}

	if(document.getElementById('TotalOther_4th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_4th').value)) {
			val += parseFloat(document.getElementById('TotalOther_4th').value);
		}
	}

	if(document.getElementById('TotalOther_5th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_5th').value)) {
			val += parseFloat(document.getElementById('TotalOther_5th').value);
		}
	}

	if(document.getElementById('TotalOther_6th').value.search(/\S/) != -1) {
		if(! isNaN(document.getElementById('TotalOther_6th').value)) {
			val += parseFloat(document.getElementById('TotalOther_6th').value);
		}
	}

	document.getElementById('_TotalOther').value = val.toFixed(2);
}
function getBalanceAmountForReypayment() {
	var valIncome = 0;
	var valExpence = 0;
	var valReypayment = 0;

	if((! isNaN(document.getElementById('ExpectedIncomeMain').value)) && (parseFloat(document.getElementById('ExpectedIncomeMain').value) > 0)) {
		valIncome = parseFloat(document.getElementById('ExpectedIncomeMain').value);
	}

	if((! isNaN(document.getElementById('Expence').value)) && (parseFloat(document.getElementById('Expence').value) > 0)) {
		valExpence = parseFloat(document.getElementById('Expence').value);
	}

	if(valIncome > valExpence) {
		valReypayment = (valIncome - valExpence);
	}

	document.getElementById('Repayment').value = valReypayment.toFixed(2);
}
function getLoanAmountRequired() {
	var valIncome = 0;
	var valExpence = 0;
	var valLoanAmountRequired = 0;

	if((! isNaN(document.getElementById('Total_Total').value)) && (parseFloat(document.getElementById('Total_Total').value) > 0)) {
		valIncome = parseFloat(document.getElementById('Total_Total').value);
	}

	if((! isNaN(document.getElementById('TotalOther_Total').value)) && (parseFloat(document.getElementById('TotalOther_Total').value) > 0)) {
		valExpence = parseFloat(document.getElementById('TotalOther_Total').value);
	}

	if(valIncome > valExpence) {
		valLoanAmountRequired = (valIncome - valExpence);
	}

	document.getElementById('LoanAmountRequired').value = valLoanAmountRequired.toFixed(2);
}
//========== Calculations End ==========//