var datePat = /^(\d{4})(\-)(\d{1,2})(\-)(\d{1,2})$/;
var matchArray = "";

 

String.prototype.trim = function() {
  return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}
function isArray(obj){
	return(typeof(obj.length)=="undefined")?false:true;
}

function isBlankField(field)
{
  var charCount=0;
  
  for (var i=0; i < field.value.length; i++)
  {
    if (field.value.charAt(i) == " ")
       charCount++;
  }
  if (charCount == field.value.length){
     field.value="";
    // field.focus();
     return true;
     }
  else return false;
}

function isBlankValue(field){ 
var charCount=0;
	if (field != null){ 
		for (var i=0; i < field.length; i++){
			if (field.charAt(i) == " ")
				charCount++;
			}
			if(charCount == field.length){
				field="";
				// field.focus();
				return true;
			}else 
				return false;
	}else 
		return false;
}
 
function isBlankFieldName(field,fieldName)
{
  var charCount=0;
  
  for (var i=0; i < field.value.length; i++)
  {
    if (field.value.charAt(i) == " ")
       charCount++;
  }
  if (charCount == field.value.length){
     field.value="";
//     field.focus();
	 alert("Please enter the "+fieldName);
     return true;
     }
  else return false;
}

function isWhitespace (s)
{ 
    var i;
    var whitespace =" ";

    // Is s empty?
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
    // Check that current character isn't whitespace.
    var c = s.charAt(i);

    if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

function isValidChar(s,al){
ret=0;
for(i=0;i< s.length ;i++){

if((s.charCodeAt(i)>=32)&&s.charCodeAt(i)<48){
ret=1;
}
if((s.charCodeAt(i)>57)&&s.charCodeAt(i)<65){
    ret=1;
}
}
if(ret==1){
    return false;
}
    else{
    return true;
    }
}

function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
    result = true;
  }
  if(result){ 
    return true;
  }
  else{
    return false;
  }
}


function checkemail(str){
	var testresults;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true;
	else{
		testresults=false;
	}
	return (testresults)
}

function checkPhoneNo(str){
	var testresults;
	var filter=/^\d{6,16}/;
	var dotFilter=/^\W/;
	if (filter.test(str))
		if (str.indexOf('.')==-1){
			testresults=true;
		}else{
			testresults=false;
		}
	else{
		testresults=false;
	}
	return (testresults)
}

function validateEmail(email)
{
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  var str = theStr.substring(index+1);
  if ((index > 0)&&(theStr.length>index+1)&&(!(isWhitespace(str))))
  {
    return true;
  }
  else{
    return false;
  }
}

function isFutureDate(givenDate,today)
{
  gYear  = givenDate.getYear();
  gMonth = givenDate.getMonth();
  gDay   = givenDate.getDate();

  tYear  = today.getYear();
  tMonth = today.getMonth();
  tDay   = today.getDate();

    if (gYear > tYear)
        return false;
    else if (gYear < tYear)
        return true;
    else if (gYear == tYear) {
        if (gMonth < tMonth)
            return true;
        else if (gMonth > tMonth)
            return false;
        else if (gMonth == tMonth) {
            if (gDay <= tDay)
                return true;
            if (gDay > tDay)
                return false;
        }
   }
}

function isFutureDate1(givenDate,today)
{
  gYear  = givenDate.getYear();
  gMonth = givenDate.getMonth();
  gDay   = givenDate.getDate();

  tYear  = today.getYear();
  tMonth = today.getMonth();
  tDay   = today.getDate();

    if (gYear > tYear)
        return false;
    else if (gYear < tYear)
        return true;
    else if (gYear == tYear) {
        if (gMonth < tMonth)
            return true;
        else if (gMonth > tMonth)
            return false;
        else if (gMonth == tMonth) {
            if (gDay < tDay)
                return true;
            if (gDay > tDay)
                return false;
        }
   }
}

function isPastDate(givenDate,today)
{

  gYear  = givenDate.getYear();
  gMonth = givenDate.getMonth();
  gDay   = givenDate.getDate();
  tYear  = today.getYear();
  tMonth = today.getMonth();
  tDay   = today.getDate();
  
 if (gYear > tYear) {  return false;}
  else if (gYear <= tYear) {
	  if (gMonth < tMonth){ return false;}
	  else if (gMonth >= tMonth) {
		  if (gDay < tDay){  return false;}
		  if (gDay >= tDay){ return true;}
	  }
  }


}

function daysInFebruary (year){
      return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   }
   return this
}

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) {
            if(c == ".") {
            
            } else {
                return false;
            }
            
        }
    }
    return true;
}

function isValidDateFormat(dtStr)
 {
 
 var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
  
 var matchArray = dtStr.match(datePat);
    if (matchArray == null) {
         alert("Please enter date in DD/MM/YYYY format");
         return false;
        }
        return true;
   }

function isValidDate(dtStr, fldName)
{
    var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
    var matchArray = dtStr.match(datePat);
    if (matchArray == null) {
         alert("Please enter date in DD/MM/YYYY format for " + fldName);
         return false;
        }
    var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;
    
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)

    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)


    strYr=strYear

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1)
        strYr=strYr.substring(1)
    }
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)

    if (pos1==-1 || pos2==-1){
        alert("Date format should be : DD/MM/YYYY for " + fldName)
        return false;
    }
    if (month<1 || month>12){
        alert("Please enter valid month for "+ fldName)
        return false;
    }
    if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter valid date for " + fldName)
        return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter valid 4 digit year between "+minYear+" and "+maxYear +" for " + fldName)
        return false;
    }

return true;
}

function validateDate(dtStr, fldName, fieldDay, fieldMonth, fieldYear)
{

	var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
    var matchArray = dtStr.match(datePat);
    if (matchArray == null) {
		alert("Please enter date in DD/MM/YYYY format for " + fldName);
		fieldDay.focus();
		return false;
    }
    var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;
    
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)

    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)


    strYr=strYear

    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1)
        strYr=strYr.substring(1)
    }
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)

    if (pos1==-1 || pos2==-1){
        alert("Date format should be : DD/MM/YYYY for " + fldName);
		fieldDay.focus();
        return false;
    }
    if (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        alert("Please enter valid date for " + fldName);
		fieldDay.focus();
        return false;
    }
	if (month<1 || month>12){
        alert("Please enter valid month for "+ fldName);
		fieldMonth.focus();
        return false;
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        alert("Please enter valid 4 digit year between "+minYear+" and "+maxYear +" for " + fldName);
		fieldYear.focus();
        return false;
    }

return true;
}

function trimstr(str)
{
    i = 0;
    max = str.length;
    j = max - 1;
    while (i < max && str.charAt(i) == " ")
    {
        i++;
    }
    while (j >= 0 && str.charAt(j) == " ")
    {
        j--;
    }
    if (i > j)
    {
        return "";
    }
    else
    {
        retstr = ""
        for (k=i;k<=j;k++)
        {
            retstr += str.charAt(k);
        }
        return retstr
    }
}

function isString(string) {
    if (!string)  return false;
    var Chars = "0123456789!@#$%^&*()_+|\/=-:><.,:;"
 
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) != -1)
           return false;
    }
    return true;
}

function isSplChar(string) {
    var Chars = "~`!@#$%^&*()_+|\/=-:><.,:';"
 
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) >=0)
           return false;
    }
    return true;
}

function isSplCharwithComma(string) {
    var Chars = "~`!@#$%^&*()_+|\/=-:><:';"
 
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) >=0)
           return false;
    }
    return true;
}

function isAddressSplChar(string) {
    var Chars = "~`!@$%^*_+|=:><:';"
 
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) >=0)
           return false;
    }
    return true;
}
function isYNChar(string) {
    if (!string)  return false;
    var Chars = "YNyn"
    if (Chars.indexOf(string.charAt(0)) == -1)
           return false;
    return true;
}

 
function isvalidFormatYYYYMM(yyyymm,name)
 {
 
    var datePat = /^(\d{4})(\d{1,2})$/;
    var minYear=1900;
    var maxYear=2100;
   var matchArray = yyyymm.match(datePat);
      if (matchArray == null){
      alert("Enter "+name+" in YYYYMM format")
      return false
      }
 var strYear=yyyymm.substring(0,4)
 var strMonth=yyyymm.substring(4)
 
 if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

 month=parseInt(strMonth)
 year=parseInt(strYear)
 
 if (month<1 || month>12){
  alert("Please enter a valid month for"+name)
  return false
 }
 if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
  alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
  return false
 }
    return true
}

function isNumeric(s){
    var i;
    for (i = 0; i < s.value.length; i++){
        var c = s.value.charAt(i);
        if ((c < "0") || (c > "9")) 
        {
            if (c!=".")
            {
            alert("Enter numeric value.");
            s.focus();
            return false;
            }
        }
    }
    return true;
}

function isNumericCap(s,capName){
    var i;
    for (i = 0; i < s.value.length; i++){
        var c = s.value.charAt(i);
        if ((c < "0") || (c > "9")) 
        {
            if (c!=".")
            {
            alert("Enter numeric digit for "+capName);
            s.focus();
            return false;
            }
        }
    }
    return true;
}

function isDigitCap(s,capName){
    var i;
    for (i = 0; i < s.value.length; i++){
        var c = s.value.charAt(i);
        if ((c < "0") || (c > "9")) 
        {
            alert("Enter numeric digit for "+capName);
            s.focus();
            return false;
        }
    }
    return true;
}

function isNumericBase(s,capName){
    var i;
    for (i = 0; i < s.value.length; i++){
        var c = s.value.charAt(i);
        if ((c < "0") || (c > "9")) 
        {
            if (c!=".")
            {
            alert(capName+" can not be negative value.");
            return false;
            }
        }
    }
    return true;
}



function zeroLimit(obj)
{
  var bool = false;

   with (document.form1)
   {
        if(obj.value > 0)
        {
        bool = true; 
        }
        
        else 
        {
          bool = false;
          
        }
  
  }
  
  return bool;

  
}




function checkDecimalPoints(fieldName){


     if(isNumeric(fieldName)){
     
    var i = fieldName.value.indexOf(".");
    var j = fieldName.value.substring(i+1);
    var x = fieldName.value.substring(0,i);
    var k = fieldName.value.lastIndexOf(".");
    
    if(i!=k){
            alert("Enter a valid number");
            fieldName.focus();
            return false;
    }

    if (i>=0)
     {

    if(j.length > 2) {

        alert("Decimal value is valid only up to two digits");
        fieldName.focus();
        return false;

    }else if(x.length > 13){

        alert("Value before decimal point should not be more than 13 digits");
        fieldName.focus();
        return false;
    } else {
    return true;
    }

     }else {
      if((i<0)&&(fieldName.value.length>13)){

        alert("Value before decimal point should not be more than 13 digits");
            fieldName.focus();
            return false;   

     }else {

            return true;
    }
    }
 }
}

function checkDecimalPoints(fieldName,capName){


     if(isNumericCap(fieldName,capName)){
     
    var i = fieldName.value.indexOf(".");
    var j = fieldName.value.substring(i+1);
    var x = fieldName.value.substring(0,i);
    var k = fieldName.value.lastIndexOf(".");
    
    
    if(i!=k){
            alert("Enter a valid number");
            fieldName.focus();
            return false;
        }
   
        

    if (i>=0)
     {

    if(j.length > 2) {

        alert("Decimal value is valid only up to two digits for "+capName);
        fieldName.focus();
        return false;

    }else if(x.length > 13){

        alert("Value before decimal point should not be more than 13 digits for "+capName);
        fieldName.focus();
        return false;
    } else {
    return true;
    }

     }else {
      if((i<0)&&(fieldName.value.length>13)){

        alert("Value before decimal point should not be more than 13 digits for "+capName);
            fieldName.focus();
            return false;   

     }else {

            return true;
    }
    }
 }
}

function checkBeforeDecimalPoints(fieldName,capName){


     if(isNumericCap(fieldName,capName)){
     
    var i = fieldName.value.indexOf(".");
    var j = fieldName.value.substring(i+1);
    var x = fieldName.value.substring(0,i);
    var k = fieldName.value.lastIndexOf(".");
    
    
    if(i!=k){
            alert("Enter a valid number");
            fieldName.focus();
            return false;
        }
   
        

    if (i>=0)
     {

    if(j.length > 2) {

        alert("Decimal value is valid only up to two digits for "+capName);
        fieldName.focus();
        return false;

    }else if(x.length > 3){

        alert("Value before decimal point should not be more than 3 digits for "+capName);
        fieldName.focus();
        return false;
    } else {
    return true;
    }

     }else {
      if((i<0)&&(fieldName.value.length>3)){

        alert("Value before decimal point should not be more than 3 digits for "+capName);
            fieldName.focus();
            return false;   

     }else {

            return true;
    }
    }
 }
}

function checkFourDecimalPoints(fieldName,capName){

     if(isNumericCap(fieldName,capName)){
     
    var i = fieldName.value.indexOf(".");
    var j = fieldName.value.substring(i+1);
    var x = fieldName.value.substring(0,i);   
    

    if (i>=0)
		{

    if(j.length > 4) {

        alert("Decimal value is valid only up to four digits for "+capName);
        fieldName.focus();
        return false;

    }else if(x.length > 3){

        alert("Value before decimal point should not be more than 3 digits for "+capName);
        fieldName.focus();
        return false;
    } else {
    return true;
    }

     }else {
      if((i<0)&&(fieldName.value.length>3)){

        alert("Value before decimal point should not be more than 3 digits for "+capName);
            fieldName.focus();
            return false;   

     }else {

            return true;
    }
    }
 }
}


function strip(filter,str){
      var i,curChar;
      var retStr = '';
      var len = str.length;
      for(i=0; i<len; i++){
         curChar = str.charAt(i);
         if(filter.indexOf(curChar)<0) 
           //not in filter, keep it
            retStr += curChar;
      }
      return retStr;
   }

function isEmpty(str)
    {
        return (strip(" \n\r\t",str).length ==0)
    }


function checkDecimalZeroPoints(fieldName){

     if(isNumeric(fieldName)){
                
        if(!zeroLimit(fieldName)) {
            alert("Please enter amount greater than zero");
            fieldName.focus();
			return false;
        }
        
        var i = fieldName.value.indexOf(".");
        var j = fieldName.value.substring(i+1);
        var x = fieldName.value.substring(0,i);
        if (i>=0)
         {
            
            if(j.length > 2) {
                
                alert("Decimal value is valid only up to two digits");
                fieldName.focus();
                return false;

            }else if(x.length > 13){
                
                alert("Value before decimal point should not be more than 13 digits");
                fieldName.focus();
                return false;
	        }
			else{
				return true;
			}

            
         }else if((i<0)&&(fieldName.value.length>13)){
                 
                alert("Value before decimal point should not be more than 13 digits");
                fieldName.focus();
                return false;   
                
         }else{ 
            return true;
		 }



     }
     
    
    
}


//Added By Kishore Somavarpu
function validateDecimalField(fieldvalue, sizeafterdecipoint) {
    
    indx = fieldvalue.indexOf('.');
    if(indx == -1) {
        return true;
    } else {
        strafterdecipoint = fieldvalue.substring(indx+1, fieldvalue.length);
        numcount = strafterdecipoint.length;
        if(numcount > sizeafterdecipoint) {
            return false;
        } else {
            return true;
        }
    }
}

//Added By Sumathi
function numOfDigitsBeforePointWithMinus(fieldvalue, digitsAllowed) {
    indx = fieldvalue.indexOf('.');
	var firstDigit = fieldvalue.indexOf('-');
	if(firstDigit != -1){
		digitsAllowed = digitsAllowed + 1;
	}
    if(indx == -1) {
        count = fieldvalue.length;
        if(count <= digitsAllowed) {
            return true;
        } else if(count > digitsAllowed) {
            return false;
        }
    } else {
        digitsbeforepoint = fieldvalue.substring(0, indx);
        cnt2 = digitsbeforepoint.length;
        if(cnt2 <= digitsAllowed) {
            return true;
        } else {
            return false;
        }
    }
 
 }

//Added By Kishore Somavarpu
function numOfDigitsBeforePoint(fieldvalue, digitsAllowed) {
    indx = fieldvalue.indexOf('.');
    if(indx == -1) {
        cnt = fieldvalue.length;
        if(cnt <= digitsAllowed) {
            return true;
        } else if(cnt > digitsAllowed) {
            return false;
        }
    } else {
        digitsbeforepoint = fieldvalue.substring(0, indx);
        cnt2 = digitsbeforepoint.length;
        if(cnt2 <= digitsAllowed) {
            return true;
        } else {
            return false;
        }
    }
 
 }
 
 
 //Added By Kishore Somavarpu
 function ageDifference(laterdate, earlierdate) {
     var acceptableDiff = getAllowedDaysDiff();
     //alert("Acceptabl Difference: "+acceptableDiff);
     var difference = earlierdate.getTime() - laterdate.getTime();
 
     var difference = Math.floor(difference/1000/60/60/24);
     //difference -= daysDifference*1000*60*60*24
     //alert("Actual Difference: "+difference);
     if(difference >= acceptableDiff) {
        return true;
     } else {
        return false;
     }
     
 }
 
 //Added By Kishore Somavarpu
 function getAllowedDaysDiff() {
    var curDate = new Date();
    cdd = curDate.getDate();
    cmm = curDate.getMonth();
    cyy = curDate.getYear();
    var age = 18;
    var newDate = new Date((cyy - age), cmm, cdd);
    //alert("newDate: "+newDate);
    var daysDiff = curDate.getTime() - newDate.getTime();
    daysDiff = Math.floor(daysDiff/1000/60/60/24);
    return daysDiff;
 }

//Added By Kishore Somavarpu 
function validateBorIdNumber(borIdNumber) {
    flag = true;
    retval = "";
    
    if((borIdNumber.length == 9) && ((borIdNumber.charAt(0) >= 'A') &&  (borIdNumber.charAt(0) <= 'Z'))) {
        for(var i=1; i<8; i++) {
            if((borIdNumber.charAt(i)>='0') && (borIdNumber.charAt(i)<='9')) {
                flag = true;
            } else {
                return false;
            }
        }
        
        if(((borIdNumber.charAt(8) >= 'A') && (borIdNumber.charAt(8) <= 'Z')) && (flag == true)) {
            sum = 0;
            sum = sum + parseInt(borIdNumber.charAt(1)) * 2;
            sum = sum + parseInt(borIdNumber.charAt(2)) * 7;
            sum = sum + parseInt(borIdNumber.charAt(3)) * 6;
            sum = sum + parseInt(borIdNumber.charAt(4)) * 5;
            sum = sum + parseInt(borIdNumber.charAt(5)) * 4;
            sum = sum + parseInt(borIdNumber.charAt(6)) * 3;
            sum = sum + parseInt(borIdNumber.charAt(7)) * 2;
            if(borIdNumber.charAt(0) == 'T') {
                sum = sum + 4;
            }
            sum = sum % 11;
            sum = 11 - sum;
            switch(sum) {
                case 1: retval = 'A';
                        break;
                case 2: retval = 'B';
                        break;
                case 3: retval = 'C';
                        break;
                case 4: retval = 'D';
                        break;
                case 5: retval = 'E';
                        break;
                case 6: retval = 'F';
                        break;
                case 7: retval = 'G';
                        break;
                case 8: retval = 'H';
                        break;
                case 9: retval = 'I';
                        break;
                case 10: retval = 'Z';
                         break;
                case 11: retval = 'J';
                         break;
                default: retval = "";
                         break;
            }
            if(borIdNumber.charAt(8) == retval) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}

//Added By Kishore Somavarpu
function autotab(original,destination){
    if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
    destination.focus()
}

//Added By Kishore Somavarpu
function getAge(dob, appdate) {
    //var appdate = new Date();
    appdd = appdate.getDate();
    appmm = appdate.getMonth();
    appyy = appdate.getYear();
           
    dobday = dob.getDate();
    dobmon = dob.getMonth();
    dobyear = dob.getYear();
    if(dobyear < 100) {
    	dobyear = dobyear + 1900;
    }
    
    
    diffinyear = 0;
    diffinmonth = 0;
    diffinday = 0;
    
    if(appyy >= dobyear) {
    	diffinyear = appyy - dobyear;
    	if(diffinyear >= 0) {
    		diffinmonth = appmm - dobmon;
       		if(diffinmonth >= 0) {
    			diffinday = appdd - dobday;
       			if(diffinday >= 0) {
    				//do nothing for the moment
       			} else if(diffinyear >= 0 && diffinmonth > 0 && diffinday < 0) {
       				diffinmonth = diffinmonth - 1;
       				daysinmon = getNoOfDaysInMonth(dobyear, dobmon);
       				diffinday = daysinmon - dobday + appdd;
        		} else if(diffinyear >= 0 && diffinmonth == 0 && diffinday < 0) {
        			diffinyear = diffinyear - 1;
        			diffinmonth = 11 - dobmon + appmm;
        			daysinmon = getNoOfDaysInMonth(dobyear, dobmon);
        			diffinday = daysinmon - dobday + appdd;
        		} else {
    				return 'false';
    			}
    		} else if(diffinyear > 0) {
    			diffinyear = diffinyear - 1;
    			diffinmonth = 12 - dobmon + appmm;
    			diffinday = appdd - dobday;
    			if(diffinday >= 0) {
    				//do nothing for the moment
    			} else {
    				diffinmonth = diffinmonth - 1;
    				daysinmon = getNoOfDaysInMonth(dobyear, dobmon);
    				diffinday = daysinmon - dobday + appdd;
    			}
    		} else {
    			return 'false';
    		}
    	} else {
    		return 'false';
    	}
    } else {
    	return 'false';
    }
    return (diffinyear+" Years");
//    return (diffinyear+" Years "+diffinmonth+" Months "+diffinday+" Days ");
}


function getNoOfDaysInMonth(year, month) {
	switch(month) {
	
		case 0:
				return 31;
				break;
		case 1:
				return daysInFebruary(year);
				break;
		case 2:
				return 31;
				break;
		case 3:
				return 30;
				break;
		case 4:
				return 31;
				break;
		case 5:
				return 30;
				break;
		case 6:
				return 31;
				break;
		case 7:
				return 31;
				break;
		case 8:
				return 30;
				break;
		case 9:
				return 31;
				break;
		case 10:
				return 30;
				break;
		case 11:
				return 31;
				break;
		default:
				break;
	
	}

}

function isIntegerValue(s){
    var i;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if ((c < "0") || (c > "9") || (c == ".")) {
            return false;
        }else{
            
        }
    }
    return true;
}

function isNumber(s, capName){
    var i;
    for (i = 0; i < s.value.length; i++){
        var c = s.value.charAt(i);
        if ((c < "0") || (c > "9") || (c == ".")) {
            alert("Enter numeric digit for "+capName);
            s.focus();
            return false;
        }else{
            
        }
    }
    return true;
}

/******************************************************
 ** Function to carry out validations for ID number****
 ** and Type                                      *****
******************************************************/

function centralizedIDTypeValidations(){

	var idNumArr = new Array();
	var ownersSize = document.forms[0].size.value;
	for(i=0;i<ownersSize;i++){
		var idNum = eval("document.forms[0].IDNum"+i+".value");
		eval("document.forms[0].IDNum"+i+".value=idNum.toUpperCase()");
	}
	for(i=0; i<ownersSize; i++){
		
		if ( (!isBlankField(eval("document.forms[0].CIF"+i))) || 
			     (!isBlankField(eval("document.forms[0].IDType"+i))) ||
			     (!isBlankField(eval("document.forms[0].IDNum"+i))) || 
			     (!isBlankField(eval("document.forms[0].relation"+i))) ) {
		
				if (isBlankField(eval("document.forms[0].name"+i))) {
					alert("Please enter name.");
					eval("document.forms[0].name"+i+".focus()");
					return false;
				}
		}
		
		var idType = eval("document.forms[0].IDType"+i+".value").trim();
		var idNum = eval("document.forms[0].IDNum"+i+".value").trim();
		
		if (idType != "" && idNum=="") {
			alert("Please enter the ID Number.");
			eval("document.forms[0].IDNum"+i+".focus()");
			return false;
		}
		if (idType == "" && idNum!="") {
			alert("Please select the ID Type.");
			eval("document.forms[0].IDType"+i+".focus()");
			return false;
		}
	
		if (idNum != "") {
			// Prepare Array for duplicate ID number checking
			idNumArr[i] = idType+idNum;
			if (!isSplChar(idNum)) {
				alert("No special characters are allowed.");
				eval("document.forms[0].IDNum"+i+".focus()");
				return false;
			}
			if (idType == "SP" || idType == "SB") {
				fltr = idNum.substring(0,1);
				if (((fltr != 'S') && (fltr != 's')) && ((fltr != 'T') && (fltr != 't'))) {
					alert("ID Number should begin with letter 'S' or 'T' for this IDType.");
	        			eval("document.forms[0].IDNum"+i+".focus()");
	        			return false; 
	    			}
				if ((validateBorIdNumber(idNum)) == false) {
					alert("ID number is invalid. NRIC check failed.");
					eval("document.forms[0].IDNum"+i+".focus()");
					return false;   
				}
			}
		} 	
			}
		// For Duplicate ID Number Checking
		for(i=0;i<idNumArr.length;i++){
			for(j=i+1;j<idNumArr.length;j++){
				if ( idNumArr[i]==idNumArr[j] ) {
					alert('ID number already exists');
					return false;
									
				}
			}
		}
		
			
		return true;
}
function getConvertedFXLimit(FXRate, limit, facType){
	if(facType == "FX"){
		if(limit != ""){
			limit = parseFloat(limit);
		}else{
			limit = 0;
		}
		if(FXRate != ""){
			FXRate = parseFloat(FXRate);
		}else{
			FXRate = 0;
		}
		limit = limit * FXRate;
		return limit;
	}else{
		return limit;
	}
}