function isNumber(evt) {
	var iKeyCode = (evt.which) ? evt.which : evt.keyCode
	if (iKeyCode != 46 && iKeyCode > 31 && (iKeyCode < 48 || iKeyCode > 57)){
		return false;
	}
	return true;
}

function makeUpper(elem){
	elem.value = elem.value.toUpperCase();
}

function onlyAlphabets(evt){
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;
    if ( (charCode >= 65 && charCode <= 90) || (charCode >=97 && charCode<=122)|| charCode == 32){
        return true;
    }else{
        alert("Only Alphabets Allowed");
        e.keyCode=0;
    }
    return false;
}

function verName(){
	document.forms[0].verifierName.value = document.forms[0].panName.value ;
}


function fillSex(elem){
	//alert(elem.value);
	if(elem.value=="1"){
		document.forms[0].sex.value="M";

	}
	else{
		document.forms[0].sex.value="F";

	}
	//if(document.forms[0].OTHERFLAG.value=="Yes"){
	//document.forms[0].OTHTITLE.value=elem.value;
	// }
	if(elem.value=="4"){
		alert("M/S is not a proper title for this Cateory");
		document.forms[0].sex.value="";
		document.forms[0].title.value="";
	}
}

 function isValidShortName(objName){
	var forceInvalid = "N";
	if(objName.value==""){
		return true;
	}
	objName.value = ltrim(rtrim(objName.value));
	var nameSplit = objName.value.split(" ");
	if(objName.value.length > 2 && nameSplit.length == 1){
		return true;
	}
	var url = 'NameValidationMySql?shortname=';
	if(nameSplit.length >1){
		for(var x = 0;x<nameSplit.length;x++){
			if(nameSplit[x].length <=2){
				forceInvalid="Y";
				break;
			}
		}
	}
	if(forceInvalid=="Y" && document.forms[0].status.value=="P"){
		alert("With two character Name no additional word is accepted in the same field");
		objName.value="";
		objName.focus();
		return false;
	}
	if(objName.value.length <=2){
		lastNameObj = objName;
		url = url+objName.value;
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
			req.onreadystatechange = checkName;
			req.open("GET", url, true);
			req.send(null);
		}else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = checkName;
				req.open("GET", url, true);
				req.send();
			}
		}
	}
}

 function compressMultipleSpace(objTextBox){
	var newText = "";
	if(objTextBox.value==""){
		return true;
	}else{
		objTextBox.value = ltrim(rtrim(objTextBox.value));
		var spaceSplit = objTextBox.value.split(" ");
		if(spaceSplit.length > 1){
			for (var x=0;x<spaceSplit.length;x++){
				spaceSplit[x] = spaceSplit[x].replace(/^\s+|\s+$/g, '')
				if(spaceSplit[x] !="" ){
					newText = newText.concat(spaceSplit[x]," ");
				}
			}
			objTextBox.value= rtrim(newText);
		}
	}
	return true;
}

function nameCard(elem){	
	//if(document.forms[0].status.value == "P"){
		var lastName  = document.getElementById("addPANApp_lastName").value;		
		var middleName = trim(document.getElementById("MIDDLENAME").value);
	
		if(middleName==""){
			middleName = " ";
		}
		var firstName=trim(document.forms[0].firstName.value);
		var fullName = firstName + " "+ middleName+ " "+lastName;
		fullName = fullName.trim();
		//alert(x.length);
		var nameLen=fullName.length;
		if(nameLen <= 25){
			document.forms[0].panName.value= formatName(fullName);
		}else{
			fullName = firstName+" "+middleName.substr(0, 1)+" "+lastName;
			fullName = formatName(fullName);
			if(fullName.length > 25){
				fullName = firstName.substr(0,1)+" "+middleName.substr(0, 1)+" "+lastName;
				fullName = formatName(fullName);
			}
			if(fullName.length > 25){
				fullName = firstName.substr(0,1)+" "+lastName;
				fullName = formatName(fullName);
			}
			if(fullName.length > 25){
				fullName = lastName;
				fullName = formatName(fullName);
			}
			document.forms[0].panName.value= fullName.trim();
		}
	//}else{
		//return true;
	//}
} 

function titleAlert(elem){
	var title=document.forms[0].title.value;
	if(elem.value=="M"&&title!="1"){
		elem.value="2";
		alert("Title Mismatch");
		document.forms[0].title.focus();
	}
	if(elem.value=="F"&&title=="1"){
		elem.value="1";
		alert("Title Mismatch");
		document.forms[0].title.focus();
	}

}

function isDate(field) {
    var allowBlank = true;
    var cutOffDate = document.forms[0].overageCutOffDate.value;
    var minYear = cutOffDate.substr(6,4);
    var date = new Date();
    var maxYear = date.getFullYear();
    var maxMonth = date.getMonth();
    var maxDate = date.getDate();
    var errorMsg = "";
    if (field.value == "" || field.value == "DD/MM/YYYY")
        return false;
    // regular expression to match required date format
    re = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
    if (field.value != '') {
        if (regs = field.value.match(re)) {
            if (regs[1] < 1 || regs[1] > 31)
                errorMsg = "Invalid value for day: " + regs[1];
            else if (regs[2] < 1 || regs[2] > 12)
                errorMsg = "Invalid value for month: " + regs[2];

            if ((regs[2] == 4 || regs[2] == 6 || regs[2] == 9 || regs[2] == 11)
                && regs[1] == 31) {
                errorMsg = "Invalid value for day: " + regs[1];
            }

            if (regs[2] == 2
                && (regs[1] > 29 || ((regs[3] % 4 == 0
                    && regs[3] % 100 != 0 || regs[3] % 400 == 0) == false && regs[1] == 29)))
                errorMsg = "Invalid value for day (for Feb month): " + regs[1];

            if ((regs[3] < minYear || regs[3] > maxYear)
                || (regs[3] == maxYear && regs[2] > maxMonth + 1)
                || (regs[3] == maxYear && regs[2] == maxMonth + 1 && regs[1] > maxDate))
                errorMsg = "Not a valid Date of Birth";

        } else
            errorMsg = "Invalid date format: " + field.value;
    } else if (!allowBlank)
        errorMsg = "Empty date not allowed!";
    if (errorMsg != "") {
        alert(errorMsg);
        field.value = "";
        field.focus();
        return false;
    }
    return true;
}

function filldob(elem){
	if (document.forms[0].status.value=="H" && elem.value==""){
		alert("Date of Birth /Date of Incorporation if left blank then 01/01/9999 is taken as default");
		elem.value="01/01/9999";
	}
}

function cutoffdate(){
	try{
		var benDOB = document.forms[0].dob.value;
		var cutOffDate = document.forms[0].minorCutOffDate.value;
		var toDay = document.forms[0].toDay.value;
		var yyyymmddBenDOB = "";
		var yyyymmddToDay = "";
		if(document.forms[0].status.value == "P" ){
			if( document.forms[0].dob.value!= "" && document.forms[0].repLast.value==""){
				yyyymmddBenDOB = yyyymmddBenDOB.concat(benDOB.substr(6,4),benDOB.substr(3,2),benDOB.substr(0,2));
				yyyymmddToDay = yyyymmddToDay.concat(cutOffDate.substr(6,4),cutOffDate.substr(3,2),cutOffDate.substr(0,2));
				if(document.forms[0].repLast.value=="" && (parseInt(yyyymmddBenDOB, 10)> yyyymmddToDay )) {
					alert("In Case of Minor Representative Details are Necessary");
					document.forms[0].repLast.focus();
					return false;
				}else{
					return true;
				}
			}
			return false;
		}else{
			return true;
		}
	}catch(err) {
		alert("err.message");
		return false;
	}
}

function chooseCategory( selectList ){	
	if(selectList!="P"){
		elem = document.getElementById( "PARENTSNAME" );
		elem.style.display="none";
	}else{
		elem = document.getElementById( "PARENTSNAME" );
		elem.style.display="block";
	}
	
}

function HUF(elem){
	var element;
	if( elem.value=="H"){
		element = document.getElementById("SALARIED");
		element.disabled = false;
		element = document.getElementById("BUSINESS");
		element.disabled = true;
		document.getElementById("aadhaarNo").style.display ='table-row' ;
	}
}
//anant
function nonindividual(elem){
	var element;
	if( elem.value!="H" && elem.value!="P"){
		element = document.getElementById("SALARIED");
		element.disabled = true;
		element = document.getElementById("BUSINESS");
		element.disabled = false;
		element = document.getElementById("NOINCOME");
		element.disabled = true;
		document.getElementById("aadhaarNo").style.display ='none' ;
		document.getElementById("photoSigTab").style.display ='none' ;
	}
}
function Individual(elem){
	var element;
	if( elem.value=="P"){
		element = document.getElementById("SALARIED");
		element.disabled = false;
		element = document.getElementById("BUSINESS");
		element.disabled = false;
		element = document.getElementById("NOINCOME");
		element.disabled = false;
		document.getElementById("aadhaarNo").style.display ='table-row' ;
		document.getElementById("photoSigTab").style.display ='table-row';
	}
}

function otherNameSelection( otherNameSelectCombo ){
	
	var element;
	if ( otherNameSelectCombo.selectedIndex == 2 ){
		element  = document.getElementById( "OTHTITLE" );
		element.style.display="block" ;		
		document.forms[0].othTitle.value=document.forms[0].title.value;
	}else{
		element  = document.getElementById( "OTHTITLE" );
		element.style.display="none" ;		
	}
}

 function showHide( elementId ){	 
	elem  = document.getElementById( elementId );
	display  = elem.style.display;
	if(document.forms[0].business.checked==true){
		elem.style.display = 'block';
	}else{
		elem.style.display = 'none';
		document.forms[0].profession.value= "";
	}
}

function NoIncome(){
	if(document.forms[0].noIncome.checked==true){
		alert("If no Income checked then rest all source of income are disabled");
		document.forms[0].business.disabled = true  ;
		document.forms[0].salaried.disabled = true;
		document.forms[0].capitalGain.disabled = true;
		document.forms[0].incOthSrc.disabled = true;
		document.forms[0].houseProperty.disabled = true;
	}
	else{
		document.forms[0].business.disabled = false;
		document.forms[0].salaried.disabled = false;
		document.forms[0].capitalGain.disabled = false;
		document.forms[0].incOthSrc.disabled = false;
		document.forms[0].houseProperty.disabled = false;
	}

}







