	//the variables PROPERTY_COMPANY_SELF_EMPLOYED_PROF_CODE, 
	//PROPERTY_COMPANY_SELF_EMPLOYED_NON_PROF_CODE and PROPERTY_COMPANY_OTHER_CODE must be defined 
	//in JSP that is refereing this script 
		
var caps=/[A-Z]/;
var small=/[a-z]/;
var space=/\s/;
var digit=/[0-9]/;
var special=/[+-=|!@#$%&*^~()_\/<>:;`,.?{}"]/;

/* Function to check whether given field is empty or not.
		does not check for spaces
		focuses given field and text inside field gets selected.
		Specified messege will be displayed. 
*/
function isEmptyField(obj,msg)
{
	
	if(obj.value == "") {
	    alert(msg + " is mandatory field.");
		obj.focus();
		obj.select();
		return true;
	}
	return false;	
}

/* Function to check whether given field is having special characters or not.
		does not allow spaces
		focuses given field and text inside field gets selected. 
		Specified messege will be displayed.
*/
function isSpecial(txtObj,msg)
{
	var val=txtObj.value;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	var digits =/[0-9]/;
	var space=/\s/;
	if(val == ""){
		return false;
	}else if(space.test(txtObj.value)){
		alert("No spaces allowed for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}if(digits.test(txtObj.value)||(caps.test(txtObj.value)||small.test(txtObj.value))){
		return false;
	}
	else
	{
		alert("Special characters are not allowed for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}
	return true;
}

/* Function to check whether given field is having alphabets ONLY or not.
		does not allow spaces
		allows empty field
		focuses given field and text inside field gets selected. 
		Specified messege will be displayed.
*/
function isAlpha(txtObj,msg)
{
	var val=txtObj.value;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	var space=/\s/;
	var digit=/[0-9]/;
	var special=/[+-=|!@#$%&*^~()_\/<>:;`,.?{}"]/;
	if(val == ""){
		return true;
	}	
	else if(space.test(txtObj.value)){
		alert("No spaces allowed for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}else if(!(caps.test(txtObj.value)||small.test(txtObj.value)) || special.test(txtObj.value)){
		alert("Please use only alphabetic characters for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}
	else if(digit.test(val) && (caps.test(txtObj.value)||small.test(txtObj.value))){
		alert("Please use only alphabetic characters for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}
	return true;
}

/* Function to check whether given field is having alphabets or not.
		allows empty field
		does not allow only spaces or only numbers		
		but allows spaces and numbers WITH alphabets. (used for Address field.)
		focuses given field and text inside field gets selected. 
		Specified messege will be displayed.
*/
function isOnlySpaceOrNumber(txtObj,msg)
{
	var val=txtObj.value;
	var space=/\s/;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	var digit=/[0-9]/;
		
	if(val == ""){
		return false;
	}else if(space.test(txtObj.value) && !( caps.test(txtObj.value)||small.test(txtObj.value) || digit.test(val) ) ){
		alert("The " + msg+" cannot be left blank.");
		txtObj.focus();
		txtObj.select();
		return true;
	}else if(space.test(txtObj.value) && digit.test(val) && !( caps.test(txtObj.value)||small.test(txtObj.value)) ){
		alert("The " + msg+" cannot have numbers only.");
		txtObj.focus();
		txtObj.select();
		return true;
	}
	else if(digit.test(val) && !( caps.test(txtObj.value)||small.test(txtObj.value)))
	{
		alert("The " + msg+" cannot have numbers only.");
		txtObj.focus();
		txtObj.select();
		return true;
	}
	return false;
}

/* Function to check whether given field is having numbers ONLY or not.
		does not allow spaces
		allows empty field
		focuses given field and text inside field gets selected. 
		Specified messege will be displayed.
*/
function isInt(txtObj,msg)
{
	var val=txtObj.value;
	var space=/\s/;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	//var special=/[+-*!@#$%^&*(){}:<>?,.;]/;
	var special=/[+-]/;
	var digit=/[0-9]/;
	
	if(val == ""){
		return true;
	}else if(space.test(txtObj.value)){
		alert("No spaces allowed for "+msg+".");
		txtObj.focus();
		txtObj.select();
		return false;
	}else if(!digit.test(val) || special.test(val))
	{
		txtObj.focus();
		txtObj.select();
		alert("Please enter proper value for "+msg+".");
		return false;	
	}	
	else if((digit.test(val) && (caps.test(txtObj.value)||small.test(txtObj.value)))){
		txtObj.focus();
		txtObj.select();
		alert("Please enter proper value for "+msg+".");
		return false;	
	}
	return true;
}

/* Function to check whether given field is having proper email ID format.
*/
function emailValidation(txtObj)
{
	var val=txtObj.value;
	
	// there must be >= 1 character before @, so we
	// start looking at character position 1 
	// (i.e. second character)
	var i = 1;
	var sLength = val.length;
	var space=/\s/;	
	//special characters does not include '.','@', '_' and '-'
	var special = /[+=|!#$%&*^~()\/<>:;`,?{}"]/;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	
	//Checking special characters
	if(!(caps.test(val)||small.test(val)) || special.test(val)){
		alert("Special characters are not allowed for email.");
		txtObj.focus();
		txtObj.select();
		return false;
	}
	//END-Checking special characters

	if (space.test(val))
	{	
		txtObj.focus(); 
		txtObj.select();
		alert("Email Address should not contain space.");
		return false;
	}
	
	// look for @
	while ((i < sLength) && (val.charAt(i) != "@"))
	{ 
		i++;
	}
	
	if ((i >= sLength) || (val.charAt(i) != "@")){ 
		txtObj.focus(); 
		txtObj.select();
		alert("Please enter email in proper format.");
		return false;
	}else{ 
		i += 2;
	}
	// look for .
	while ((i < sLength) && (val.charAt(i) != "."))
	{ i++;
	}

	// there must be at least one character after the .
	if ((i >= sLength - 1) || (val.charAt(i) != ".")){ 
		txtObj.focus(); 
		txtObj.select();
		alert("Please enter email in proper format.");
		return false;
	}
	var cnt = 0;
	for(i=0;i< val.length;i++){
		if(val.charAt(i) == "@"){	//to check multiple '@' signs.
			cnt++;
		}
		if(val.charAt(i) == "." || val.charAt(i) == "@"){	//to check presence of ".@" or ".." or "@."
			if(val.charAt(i-1) =="." || val.charAt(i+1) =="."){
				txtObj.focus(); 
				txtObj.select();
				alert("Please enter email in proper format.");
				return false;
			}
		}
	}
	if (cnt > 1) {					//checking multiple '@' signs.
		txtObj.focus();
		txtObj.select(); 
		alert("Please enter email in proper format.");
		return false;
	}	
	return true;
}

/* Function to remove given characters from field.
*/
function removeFrom(txtObj,whatToRemove)
{
	val = txtObj.value;
	for(i=1;i < (txtObj.value.length/2)+1; i++){
		val = val.replace(whatToRemove,"");
	}
	txtObj.value = val;
}


/* Used for */
function dobfunc(dobObject)
{
	var flag3=true;
	currDate = new Date();
	currMonth = "0"+(parseInt(currDate.getMonth())+1);
	currMonth = currMonth.substr(currMonth.length-2);
	currDay = "0"+(parseInt(currDate.getDate()));
	currDay = currDay.substr(currDay.length-2);
	sysDate = currDay+"/"+currMonth+"/"+currDate.getYear();
	if(!isAgeValidNew(dobObject.value,sysDate,18))
	{
		flag3=false;
	}
	if(flag3==false )
	{
			alert("Applicant age must be greater than 18 years");
			return false;
	}
	return flag3;
}



/*  ........... AGE VALIDATION NEW......      */
function isAgeValidNew(dateOfBirth,str,age)  //day1,month1,year1
{
	var year1 = dateOfBirth.substring(6,10) ;
	var month1 =dateOfBirth.substring(3,5) ;
	var day1 = dateOfBirth.substring(0,2) ;

	var yy = str.substring(6,10) ;
	var mm = str.substring(3,5) ;
	var dd = str.substring(0,2) ;

	var year =eval(yy-year1);
	var month= eval(month1-mm);
	var day = eval(dd-day1);

	if( year>age)
	{
		return true;
	}
	if( year<age){
		return false;
	}
	else{
		if (year==age){
			if (month1 < mm){
					return true;
					// less than current month
			}
			else
			{
				if (month1 > mm){
					return false;
					// year same month invalid
				}
				else{
					if (month1 == mm){
						if (day1 > dd)
						{
							return false;
							// year same, month same, date less
						}
						else{
							return true;
						}
					}
				}
			}
		}
		if (month1 < mm){
			return false;
			// year same month invalid
		}
		else{
			if (month1 == mm){
				if (day1 < dd)
				{
					return false;
					// year same, month same, date less
				}
				else{
					return true;
				}
			}
		}
	}
	return true;
}

/*function validateContactMe() is moved to ContactMeValidation.js*/

/*
	Function to remove comma from textbox.
*/
function commaRemoveFunc(obj)
{
	var num=obj.value
	var amount="";
	var rows = num.split(",");
	var len=rows.length;
	for(xf=0;xf < (len);xf++)
		{
			amount=amount+rows[xf];
		}
     obj.value=amount;
return true;

}

/*
	Function similar to isInt() function.
*/
function ForceNumber(objField, FieldName)
{
	var strField = new String(objField.value);
		
	var i = 0;

	for (i = 0; i < strField.length; i++)
		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
			alert(FieldName + " must be a valid numeric entry.");
			return false;
		}

	return true;
}

/*
	Function to check integer value.
		allows comma		
*/
function ForceMoney(objField, FieldName)
{
	var strField = new String(objField.value);
	
	var i = 0;

	for (i = 0; i < strField.length; i++)
		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && (strField.charAt(i) != ',')) {
			alert(FieldName + " must be a valid numeric entry(Only Commas are allowed).");
			objField.focus();
			objField.select();
			return false;
		}

	return true;
}

/*
	Function that does not allow years and months both as '0' at a time.
*/
function validYears(object1, object2){
	var noOfYears = object1.value;
	var noOfMonths = object2.value;
	
	if (noOfYears == 0 && noOfMonths == 0) {
		alert("Please select at least One Month.");
		object2.focus();
		return false;
	}
	return true;
}
/*
	Function that allows
		commas
		numeric length except comma should be 7.
*/
function checkNumericLength(txtobj,msg)
{
	var txtCities = txtobj.value ;
	var totallength=txtCities.length;
	var rows = txtCities.split(",");
	var commanum=rows.length;
	var numericlen=totallength-commanum;
	
	if(commanum>3)
	{
		alert("A maximum of three commas are allowed for "+msg+".");
		txtobj.focus();
		txtobj.select();
		return false;
	}
	if(numericlen>6)
	{
		alert("Numeric length can't be more than 7 for "+msg+".");
		txtobj.focus();
		txtobj.select();
		return false;
	}
	return true;
}

function validatePhoneOfficeMobile(objStd,objPhone,objoffstd,objoffphone,objMobile)
{
// This function validates std/phone and mobile number entered by user and checks that atleast one number will be there. 
	var std=objStd.value;
	var phone=objPhone.value;
	var offstd=objoffstd.value;
	var offphone=objoffphone.value;
	var mobile=objMobile.value;
	var flag=false;

	var phlength=objStd.value.length+objPhone.value.length;
	if(std=="" && phone=="" && mobile=="" && offstd=="" && offphone=="")
	{
		alert("Atleast specify one phone number(landline or office or mobile).");
		return false;
	}
	return true;
}


/*
	Function to check either of landline phone or mobile is present.
*/
function validatePhoneMobile(objStd,objPhone,objMobile)
{
// This function validates std/phone and mobile number entered by user and checks that atleast one number will be there. 
	var std=objStd.value;
	var phone=objPhone.value;
	var mobile=objMobile.value;
	var flag=false;
	var phlength=objStd.value.length+objPhone.value.length;
	if(std=="" && phone=="" && mobile=="")
	{
		alert("Atleast specify one phone number(landline or mobile).");
		return false;
	}
	else if(std=="" && !phone=="")
	{
		alert("Phone number without STD Code can not be accepted.");
		objStd.focus();
		objStd.select();
		return false;
		//alert("STD Code can not be empty, Phone number without STD code is not accepted.");
	}
	else if(!std=="" && phone=="")
	{
		alert("STD Code without Phone number can not be accepted.");
		objPhone.focus();
		objPhone.select();
		return false;
		//alert("STD Code can not be empty, Phone number without STD code is not accepted.");
	}
	else if(!std=="" && !phone=="")
	{
		if(!validateSTD(objStd)){
			objStd.focus();		
			objStd.select();
			return false;
		}
		else {
			if(!landPhoneValidation(objPhone))
				return false;
			else
				flag = true;
		}
		if(phlength != 11) {
			alert("Phone Number including STD code should be 11 digits.");
			objPhone.focus();
			objPhone.select();
			return false;
		}			
	}	
	if(mobile=="")
	{
		flag = true;
	}
	else if(!mobileValidation(objMobile))
		return false;
	else
		flag = true;
	
	return flag;
}

/* Function to validate STD codes.
*/
function validateSTD(txtObj)
{
	var flag=true;
	var stdcode=txtObj.value;
	
	if(!ForceNumber(txtObj,"STD Code")){
		txtObj.focus();
		txtObj.select();
		flag=false;
	}	
	else if(stdcode.substring(0,2)=="00"){
		alert("Consecutive zeros are not allowed in the begining of STD Code.")
		txtObj.focus();
		txtObj.select();
		flag=false;
	}
	else if(stdcode.charAt(0) != "0"){
		alert("STD code should start with 0.");
		txtObj.focus();
		txtObj.select();
		flag=false;
	}
	else if(stdcode.length<3){
		alert("Minimum length of Std Code is 3.");
		txtObj.focus();
		txtObj.select();
		flag=false;
	}	
	return flag;
}
	/*
		Helping function for function validatePhoneMobile().
		checks validity of STD code and phone number
	*/
	function landPhoneValidation(objPhone)
	{
		//This function validates the landline number.
		if(objPhone.value.charAt(0) == "0"){
			alert("Phone Number should not start with 0.");
			objPhone.focus();
			objPhone.select();
			return false;
		}
		else if(objPhone.value.length < 5) {
			alert("Phone Number should be atleast 5 digits.");
			objPhone.focus();
			objPhone.select();
			return false;
		}
		else if(!ForceNumber(objPhone,"Phone Number")){	
			objPhone.focus();
			objPhone.select();
			return false;
		}
		return true;
	}

/*
	Helping function for function validatePhoneMobile().
		checks validity of mobile phone
*/
function mobileValidation(objMobile)
	{	//This function validates the mobile number.
		if(!ForceNumber(objMobile,"Mobile Number"))
		{	objMobile.focus();
			objMobile.select();
			return false;
		}	
		else if(objMobile.value.charAt(0) == "0"){
			alert("Mobile number should start with 9.");
			objMobile.focus();
			objMobile.select();
			return false;
		}
		else if(objMobile.value.charAt(0) != "9"){
			alert("Mobile number should start with 9.");
			objMobile.focus();
			objMobile.select();
			return false;
		}	
		else if(objMobile.value.length<10)
		{
			alert("Mobile number should be 10 digits.");
			objMobile.focus();
			objMobile.select();
			return false;
		}
		return true;
	}

/*
	Validates pan card number
*/
function validatePanCard(object,valueObject)
{
	var space=/\s/;
	var caps=/[A-Z]/;
	var small=/[a-z]/;
	//var special=/[+-]/;
	var digit=/[0-9]/;
	if (object.value == "PAN")
	{
		if (valueObject.value.length == 10)
		{
			var i;
			for (i=0;i<5;i++)
			{
				var value = valueObject.value.charAt(i);
				//alert(value);
				if (digit.test(value) || small.test(value) || space.test(value) || special.test(value))
				{
					alert("Please enter valid PAN number.");
					valueObject.focus();
					valueObject.select();
					return false;
				}
			}
			for (i=5;i<9;i++)
			{
				var value = valueObject.value.charAt(i);
				//alert(value);
				if(caps.test(value) || small.test(value) || space.test(value))
				{
					alert("Please enter valid PAN number.");
					valueObject.focus();
					valueObject.select();
					return false;
				}
			}
			if((caps.test(valueObject.value.charAt(9))==false) || space.test(valueObject.value.charAt(9)) || special.test(valueObject.value.charAt(9)))
			{
				alert("Please enter valid PAN number.");
				valueObject.focus();
				valueObject.select();
				return false;
			}
		}
		else {
			alert("Please enter valid PAN number.");
			valueObject.focus();
			valueObject.select();
			return false;
		}
	}		
	return true;
}

/**
*Disables months if years are 10+
*/
function disableMonths(yearObj,monthObj)
{
	if(yearObj.value =="99"){
		monthObj.disabled = true;
		monthObj.value = "0";
	}
	else{
		monthObj.disabled = false;
	}
}

function companyType(idFieldName,hiddenRowId){
	if(document.forms[0][idFieldName].value=="-1" || document.forms[0][idFieldName].value == PROPERTY_COMPANY_OTHER_CODE){
		document.forms[0][idFieldName].value=PROPERTY_COMPANY_OTHER_CODE;
		document.getElementById(hiddenRowId).style.display="block";
	}
	else{
		document.getElementById(hiddenRowId).style.display="none";
	}
}

/*
	General purpose function to clear the dropdown and fill starting element with specified value.
*/
function clearDropDown(DropDownName,firstItemValue,firstItemTxt){
	document.getElementsByName(DropDownName)[0].options.length = 0;	
	O=new Option(firstItemTxt);  //add a default first option and set the value = -1
	O.value = firstItemValue;
	document.getElementsByName(DropDownName)[0].add(O);
}

function validatePhoneNumber(objStd,objPhone)
{
// This function validatesstd number and phone number entered by user.
	var std=objStd.value;
	var phone=objPhone.value;
	var flag=false;
	var phlength=objStd.value.length+objPhone.value.length;

	if(std=="" && phone=="")
	{
		alert("Enter Phone Number.");
		objStd.focus();
		objStd.select();
		return false;
		
	}
	
	if(std=="" && !phone=="")
	{
		alert("Phone number without STD Code can not be accepted.");
		objStd.focus();
		objStd.select();
		return false;
		//alert("STD Code can not be empty, Phone number without STD code is not accepted.");
	}
	else if(!std=="" && phone=="")
	{
		alert("STD Code without Phone number can not be accepted.");
		objPhone.focus();
		objPhone.select();
		return false;
		//alert("STD Code can not be empty, Phone number without STD code is not accepted.");
	}
	else if(!std=="" && !phone=="")
	{
		if(!validateSTD(objStd)){
			objStd.focus();		
			objStd.select();
			return false;
		}
		else {
			if(!landPhoneValidation(objPhone))
				return false;
			else
				flag = true;
		}
		if(phlength != 11) {
			alert("Phone Number including STD code should be 11 digits.");
			objPhone.focus();
			objPhone.select();
			return false;
		}			
	}	
	
	 	return flag;
}

function roundAmount(obj)
	  //Function to round off the loan amount to the nearest thousand.
	  //This function will contain all the relevant validationa for the loan Amount field.
{	
	commaRemoveFunc(obj);
	//var frm = document.firstForm;
	if(isEmptyField(obj,"Amount")){
		obj.focus();
		obj.select();	
		return false;
	}
	else if(!ForceMoney(obj,"Amount")){
		obj.focus();
		obj.select();	
		return false;
	}
	else if(obj.value.length<=3){
		alert("Amount required is too small.");
		obj.focus();
		obj.select();
		return false;
	}
	var amt=obj.value;
	var sub1=amt.substring(amt.length-3,amt.length);
	var sub=sub1;
	sub=amt-sub;  
	if(sub1.substring(0,1)>=5){    
		sub=parseInt(sub)+1000;
	}
	obj.value=sub;
	return true;
}