
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }



function ff()
{

var year=parseInt(document.rgs.year.value);
var ttyr=parseInt(document.rgs.tyr.value);
var gnm=parseInt(document.rgs.tmnth.value);
var dst=parseInt(document.rgs.tdys.value);

var dfr=year-ttyr;
bcsl=parseFloat(document.rgs.bcsl.value);

if(document.rgs.tyr.value == "")
{
alert("Please enter a value in total service period field!");
document.rgs.tyr.focus();

}
else if(isNaN(document.rgs.tyr.value))
{
alert("Please enter a numeric value in total service period field!");
document.rgs.tyr.focus();

}

else if(document.rgs.year.value == "")
{
alert("Please enter a value in age field!");
document.rgs.year.focus();

}
else if(isNaN(document.rgs.year.value))
{
alert("Please enter a numeric value in age field!");
document.rgs.year.focus();

}

else if(document.rgs.bcsl.value == "")
{
alert("Please enter a value in salary field!");
document.rgs.bcsl.focus();

}
else if(IsNumeric(document.rgs.bcsl.value) == false)
{
alert("Please check non numeric value!");
document.rgs.bcsl.focus();

}

else if(bcsl<100)
{
document.rgs.tot.value="";
alert("Sorry you are not entitled to get pension because your average salary is below than 100.")
document.rgs.bcsl.focus();
}

else if(dfr<=15)
{
alert("Please check your age value, there should be 15 years of difference between your age and total period of service!");
document.rgs.tot.value="";
document.rgs.year.focus();

}

else
{
//alert(year)
var sx=document.rgs.sex.options[document.rgs.sex.selectedIndex].value
sx=sx.toUpperCase();

if(sx=="M")
{

if( ttyr<=14)
{
document.rgs.tot.value="";
alert("Sorry you are not entitled to get pension because your total service period is below then 14 years")
}
else if( ttyr>=14 && ttyr<=19 && year>=60)
{

ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;

}
else if(ttyr>19)
{

ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 

//geny & saeed

if(year<45)
{
//ttl=ttl*80/100
//ttl=Math.round(ttl*1000)/1000
//document.rgs.tot.value=ttl;
document.rgs.tot.value="";
alert("Minuim Age for pension is 45.")
}

// *************** Modified
else if(year>=45 && year<46)
{
ttl=ttl - ttl*30/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=46 && year<47)
{
ttl=ttl - ttl*28/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=47 && year<48)
{
ttl=ttl - ttl*26/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=48 && year<49 )
{
ttl=ttl - ttl*24/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=49 && year<50)
{
ttl=ttl - ttl*22/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=50 && year<51 )
{
ttl=ttl - ttl*20/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=51 && year<52)
{
ttl=ttl - ttl*18/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=52 && year<53)
{
ttl=ttl - ttl*16/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=53 && year<54)
{
ttl=ttl - ttl*14/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=54 && year<55)
{
ttl=ttl - ttl*12/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=55 && year<56)
{
ttl=ttl - ttl*10/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=56 && year<57)
{
ttl=ttl - ttl*9/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=57 && year<58)
{
ttl=ttl - ttl*8/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=58 && year<59)
{
ttl=ttl - ttl*7/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=59 && year<60)
{
ttl=ttl - ttl*6/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=60)
{
ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}

}

else
{
document.rgs.tot.value="";
alert("Sorry, you are not entitled to get the pension salary because you dont full fill the conditions to get pension salary.")
}

}


if(sx=="F")
{
//document.rgs.tot.value="";
//alert("Sorry you are not entitled to get pension because your total service period is below then 14 years")



if( ttyr<=9)
{
document.rgs.tot.value="";
alert("Sorry you are not entitled to get pension because your total service period is below then 9 years")
}
else if( ttyr>=9 && ttyr<=14 && year>=55)
{

ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;

}
else if(ttyr>14)
{

ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 
if(year<45)
{
//ttl=ttl*80/100
//ttl=Math.round(ttl*1000)/1000
//document.rgs.tot.value=ttl;
document.rgs.tot.value="";
alert("Minimum Age for the Pension is 45.")
}
// ***************************** Modified
else if(year>=45 && year<46)
{
ttl=ttl - ttl*25/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=46 && year<47)
{
ttl=ttl - ttl*23/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=47 && year<48)
{
ttl=ttl - ttl*21/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=48 && year<49)
{
ttl=ttl - ttl*19/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=49 && year<50)
{
ttl=ttl - ttl*17/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=50 && year<51)
{
ttl=ttl - ttl*15/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=51 && year<52)
{
ttl=ttl - ttl*13/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=52 && year<53)
{
ttl=ttl - ttl*11/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=53 && year<54)
{
ttl=ttl - ttl*9/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=54 && year<55)
{
ttl=ttl - ttl*7/100
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}
else if(year>=55)
{
ttl=1/40 * [(bcsl * ttyr) + (bcsl * gnm/12) + (bcsl * dst/365)] 
ttl=Math.round(ttl*1000)/1000
document.rgs.tot.value=ttl;
}

}

else
{
document.rgs.tot.value="";
alert("Sorry, you are not entitled to get the pension salary because you dont full fill the conditions to get pension salary.")
}

}

//female finish...

}

return false; 

}
