function paycheck()
{
	var payschedule    = document.add.payschedule.value;
	var emp   = document.add.emp.value;
	var totamt=document.add.totamt.value;
	var tottax=document.add.tottax.value;
	var totded=document.add.totded.value;
	var netpay=document.add.netpay.value;
	var totcount=document.add.totcount.value;
	var taxcount=document.add.taxcount.value;
	var dedcount=document.add.dedcount.value;
	hidemsg('ss');
	if(payschedule == "0" || emp == "0" || totamt=='' || netpay=='0' || netpay=='')
	{
	    inlinemsg('ss','Fill all the fields','');
		return false;
	}
	if(netpay<0){
	  inlinemsg('ss','Net pay should not be a negative number','');
	  return false;
	}
	/*for(var i=0;i<=totcount;i++){
	  var qty=eval("document.add.qty"+i+".value");
	  var rate=eval("document.add.rate"+i+".value");
	  if(qty<=0){
	    inlinemsg('ss','Quantity cannot be zero!','');
		return false;
	}
	if(rate<=0){
	    inlinemsg('ss','Rate cannot be zero!','');
		return false;
	}
   }*/
return true;
}

function calcamt(val){
  var rate=eval('document.add.rate'+val+'.value');
  var qty=eval('document.add.qty'+val+'.value');
  var qty1=eval('document.add.qty'+val);
  var rate1=eval('document.add.rate'+val);
  var totamt= eval('document.add.amt'+val);
  var ss1=rate.indexOf(".");
  var ss2=qty.indexOf(".");
  hidemsg('ss');
	if(ss2==0){
	   qty1.value=0+qty;	   
	}
	if (isNaN(rate) || (rate <= 0))
    {
        totamt.value = "0.00";
        inlinemsg('ss','Enter valid rate.','');
	    rate1.value = "";
		return false;	 
	}
  if ((isNaN(qty) || (qty <0)) && (ss2!=0) && qty!='')
    {
       inlinemsg('ss','Please enter only positive numbers in the Quantity field.','');
	   qty1.value = "";
	   totamt.value = "0.00";
	   return false;
	}
  if(ss2==-1){
	     if(qty.length>10){
	      totamt.value = "0.00";
	      inlinemsg('ss','Quantity exceeds maximum length','');	    
	      qty1.value = "";
	      totamt.value = "0.00";
	     }	     
		}
	   else{
	     var st=qty.split(".");
	     if(st[0].length>10){
	       inlinemsg('ss','Quantity exceeds maximum length','');
		   
	       qty1.value = "";
		   totamt.value = "0.00";
		  
		}
		if(st[1].length>2){
		  inlinemsg('ss','Quantity should have 2 decimal values','');
		    qty1.value = "";
			totamt.value = "0.00";
		
		}
		
     }
     if(ss1==-1){
	     if(rate.length>10){
	      totamt.value = "0.00";
	      inlinemsg('ss','Rate exceeds maximum length','');	    
	      rate1.value = "";
	      totamt.value = "0.00";
	     }	     
		}
	   else{
	     var st=rate.split(".");
	     if(st[0].length>10){
	       inlinemsg('ss','Rate exceeds maximum length','');
		   
	       rate1.value = "";
		   totamt.value = "0.00";
		  
		}
		if(st[1].length>2){
		  inlinemsg('ss','Rate should have 2 decimal values','');
		    rate1.value = "";
			totamt.value = "0.00";
		
		}
		
     }
  var d=rate*qty;
  totamt.value=d.toFixed(2);
  chgtot();
  chgcalctaxes();
  chgcalcdeductions();
}
function chgcalctaxes(){
  var totamt=document.add.totamt.value;
  var count=document.add.taxcount.value;
  for(var i=0;i<=count;i++){
  var rate=eval('document.add.taxrate'+i+'.value');
  var taxamt= eval('document.add.taxamt'+i);
  var d=totamt*(rate/100);
  taxamt.value=d.toFixed(2);
  }
  
  chgtottaxes();
}
function chgcalcdeductions(){
  var totamt=document.add.totamt.value;
  var count=document.add.dedcount.value;
  for(var i=0;i<=count;i++){
  var rate=eval('document.add.dedrate'+i+'.value');
  var dedamt= eval('document.add.dedamt'+i);
  var d=totamt*(rate/100);
  dedamt.value=d.toFixed(2);
  }
  
  chgtotded();
}
function calctaxes(val){
  hidemsg('ss');
  var totamt=document.add.totamt.value;
  var rate=eval('document.add.taxrate'+val+'.value');
 
 if (isNaN(rate) || rate < 0) {
    inlinemsg('ss','Enter valid rate','');
    return false;
  }
 if(rate>100){
   inlinemsg('ss','Rate should not exceed 100%');
   return false;
}
  var taxamt= eval('document.add.taxamt'+val);
  var d=totamt*(rate/100);
  taxamt.value=d.toFixed(2);
  
  chgtottaxes();
}
function calcdeductions(val){
  hidemsg('ss');
  var totamt=document.add.totamt.value;
  var rate=eval('document.add.dedrate'+val+'.value');
  if (isNaN(rate) || rate < 0) {
    inlinemsg('ss','Enter valid rate','');
    return false;
  }
  if(rate>100){
   inlinemsg('ss','Rate should not exceed 100%');
   return false;
}
  var dedamt= eval('document.add.dedamt'+val);
  var d=totamt*(rate/100);
  dedamt.value=d.toFixed(2);
 
  chgtotded();
}
function chgtot(){
  var count=document.add.totcount.value;
  var s=0;
  for(var i=0;i<=count;i++){
    var totamt= eval('document.add.amt'+i+'.value');
    if(totamt!=0 && totamt!='')
    s=eval(s)+eval(totamt);
    else
    s=eval(s); 
  }
   s=s.toFixed(2);
  document.add.totamt.value=s;
   gtotal();
}
function chgtottaxes(){
  var count=document.add.taxcount.value;
  var s=0;
  for(var i=0;i<=count;i++){
    var taxamt= eval('document.add.taxamt'+i+'.value');
    if(taxamt!=0 && taxamt!='')
    s=eval(s)+eval(taxamt);
    else
    s=eval(s); 
  }
   s=s.toFixed(2);
  document.add.tottax.value=s;
   gtotal();
}
function chgtotded(){
  var count=document.add.dedcount.value;
  var s=0;
  for(var i=0;i<=count;i++){
    var dedamt= eval('document.add.dedamt'+i+'.value');
    if(dedamt!=0 && dedamt!='')
    s=eval(s)+eval(dedamt);
    else
    s=eval(s); 
  }
  s=s.toFixed(2);
  document.add.totded.value=s;
   gtotal();
}
function gtotal(){
  var totded=document.add.totded.value;
  var tottax=document.add.tottax.value;
  var totamt=document.add.totamt.value;
  if(totamt!='' && tottax!='' && totded!=''){
  var gtot=eval(totamt)-eval(tottax)-eval(totded);
  gtot=gtot.toFixed(2);
  document.add.netpay.value=gtot;
  }
}

