// ========== JavaScript Document By Suman Hait ========== //

var xmlHttp;

function checkData(str) {
	xmlHttp = getXmlHttpObject();
	if(xmlHttp == null) { return false; }
	var url = "AJAX.asp"
	url = url + "?q=" + str
	url = url + "&rand=" + Math.random()
	xmlHttp.onreadystatechange = stateChange
	xmlHttp.open("GET", url, true)
	xmlHttp.send(null)
}

function stateChange() {
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById('__DIV_MSG').innerHTML = xmlHttp.responseText;
		if(xmlHttp.responseText == '') {
			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;
	/*var objXMLHttp = null;
	if(window.XMLHttpRequest) { objXMLHttp = new XMLHttpRequest(); }
	else if(window.ActiveXObject) { objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	return objXMLHttp;*/
}

function checkForm(theForm) {
	var validEmail = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;
	var isEntry = false;

	if(theForm.FullName.value.search(/\S/) == -1) {
		alert('Please enter full name.');
		theForm.FullName.focus();
		return false;
	}

	if(theForm.Email.value.search(/\S/) == -1) {
		alert('Please enter email.');
		theForm.Email.focus();
		return false;
	} else {
		if(!validEmail.test(theForm.Email.value)) {
			alert('Please enter valid email.');
			theForm.Email.focus();
			return false;
		}
	}

	if((theForm.PhoneNoResidence.value.search(/\S/) == -1) && (theForm.MobileResidence.value.search(/\S/) == -1)) {
		alert('Please enter atleast one phone no.');
		theForm.PhoneNoResidence.focus();
		return false;
	}

	if(theForm.PresentResidentialAddress.value.search(/\S/) == -1) {
		alert('Please enter present residential address.');
		theForm.PresentResidentialAddress.focus();
		return false;
	}

	if(theForm.NameGuardian.value.search(/\S/) == -1) {
		alert('Please enter full name (parent/gurdian).');
		theForm.NameGuardian.focus();
		return false;
	}

	if(theForm.Relationshipwithstudents.value.search(/\S/) == -1) {
		alert('Please enter relationship with students.');
		theForm.Relationshipwithstudents.focus();
		return false;
	}

	if(theForm.PANNoGuardian.value.search(/\S/) == -1) {
		alert('Please enter PAN no. (parent/gurdian).');
		theForm.PANNoGuardian.focus();
		return false;
	}

	if(theForm.AnnualIncomeGuardian.value.search(/\S/) == -1) {
		alert('Please enter annual income (parent/gurdian).');
		theForm.AnnualIncomeGuardian.focus();
		return false;
	}

	if(theForm.ResidentialAddressGuardian.value.search(/\S/) == -1) {
		alert('Please enter residential address (parent/gurdian).');
		theForm.ResidentialAddressGuardian.focus();
		return false;
	}

	if((theForm.PhoneNoGurdian.value.search(/\S/) == -1) && (theForm.OfficePhoneGurdian.value.search(/\S/) == -1) && (theForm.MobileGurdian.value.search(/\S/) == -1)) {
		alert('Please enter atleast one phone no. (parent/gurdian).');
		theForm.PhoneNoGurdian.focus();
		return false;
	}

	if(theForm.ValueofImmovable.value.search(/\S/) == -1) {
		alert('Please enter value of immovable properties owned (parent/gurdian).');
		theForm.ValueofImmovable.focus();
		return false;
	}

	if(theForm.Valueofmovables.value.search(/\S/) == -1) {
		alert('Please enter value of movables owned (parent/gurdian).');
		theForm.Valueofmovables.focus();
		return false;
	}

	if(theForm.TotOtgLiabilities.value.search(/\S/) == -1) {
		alert('Please enter tot. otg. liabilities (parent/gurdian).');
		theForm.TotOtgLiabilities.focus();
		return false;
	}

	for(var i = 1; i <= 4; i++) {
		if((theForm.elements['Examination'+i].value.search(/\S/) == -1) || (theForm.elements['SchoolCollegeBoardUniversity'+i].value.search(/\S/) == -1) || (theForm.elements['MarksSecured'+i].value.search(/\S/) == -1)) {
			isEntry = false;
			continue;
		} else {
			isEntry = true;
			break;
		}
	}

	if(isEntry == false) {
		alert('Please enter atleast one row of previous examination details.');
		theForm.Examination1.focus();
		return false;
	}

	if(theForm.CourseName.value.search(/\S/) == -1) {
		alert('Please enter course name.');
		theForm.CourseName.focus();
		return false;
	}

	if(theForm.NatureofCourse.value.search(/\S/) == -1) {
		alert('Please enter nature of course.');
		theForm.NatureofCourse.focus();
		return false;
	}

	if(theForm.SelectionProcedure.value.search(/\S/) == -1) {
		alert('Please enter selection procedure.');
		theForm.SelectionProcedure.focus();
		return false;
	}

	if(theForm.DurationofCourse.value.search(/\S/) == -1) {
		alert('Please enter duration of course.');
		theForm.DurationofCourse.focus();
		return false;
	}

	if(theForm.MarksGradeRank.value.search(/\S/) == -1) {
		alert('Please enter marks/grade/rank obtained in selection procedure.');
		theForm.MarksGradeRank.focus();
		return false;
	}

	if(theForm.NameAndaddress.value.search(/\S/) == -1) {
		alert('Please enter name and address of the college/university/institution.');
		theForm.NameAndaddress.focus();
		return false;
	}

	if(theForm.TotalExpenses.value.search(/\S/) == -1) {
		alert('Please enter total expenses on study.');
		theForm.TotalExpenses.focus();
		return false;
	}

	if(theForm.LoanRequested.value.search(/\S/) == -1) {
		alert('Please enter loan requested.');
		theForm.LoanRequested.focus();
		return false;
	}

	if(document.getElementById('TxtImgVer').value.search(/\S/) == -1) {
		alert('Please enter image verification code.');
		document.getElementById('TxtImgVer').focus();
		return false;
	} else { checkData(document.getElementById('TxtImgVer').value); }

	return false;
}