function validate_Save(pg)
{
    var msg="";
    var count=0;

    if (pg == 1) {
        var FirstName = document.getElementById('txtFirstName').value;
        var LastName = document.getElementById('txtLastName').value;
        var Company = document.getElementById('txtCompany').value;
        var EmailID = document.getElementById('txtEmailID').value;
        var Phone = document.getElementById('txtPhone').value;
        var Country = document.getElementById('ddlCountry').value;
        var State = document.getElementById('ddlState').value;

		if(State=="")
        {
            msg="   - State\n"+msg;
            count=count+1;
        }	
		if(Country=="")
        {
            msg="   - Country\n"+msg;
            count=count+1;
        }
		if(Phone=="")
        {
            msg="   - Phone Number\n"+msg;
            count=count+1;
        }
		if(EmailID=="")
        {
            msg="   - Email Address\n"+msg;
            count=count+1;
        }
        if(Company=="")
        {
            msg="   - Company Name\n"+msg;
            count=count+1;
        }
		if(LastName=="")
        {
            msg="   - Last Name\n"+msg;
            count=count+1;
        }
		if(FirstName=="")
        {
            msg="   - First Name\n"+msg;
            count=count+1;
        }

    } else if (pg == 2) {
        var totalInvoices = getRadioValue('ddlPOsPerYear'); 
        var totalInvoiceValue = document.getElementById('txtTotalValueofInvoice').value; 
        var suppliersPaid = getRadioValue('ddlNumberofSuppliersPaid'); 
        var noAPPersons = getRadioValue('ddlNoApPersons'); 
        if (!noAPPersons)
        {
            msg="   - Number of A/P Invoices\n"+msg;
            count=count+1;
        }
        if (!suppliersPaid)
        {
            msg="   - Number of Suppliers Paid\n"+msg;
            count=count+1;
        }
        if (totalInvoiceValue =="")
        {
            msg="   - Total Value of Invoices\n"+msg;
            count=count+1;
        }
        if (!totalInvoices)
        {
            msg="   - Total number of invoices\n"+msg;
            count=count+1;
        }
        
    } else if (pg == 3) {
        var timeSpentPerInvoice = document.getElementById('txtTimeSpentInDataEntryPerInvoice').value; 
        var timeSpentPerCall = document.getElementById('txtTimeSpentPerCall').value; 
        var callsFielded = document.getElementById('txtSupplierFieldedPerAp').value; 
        if (callsFielded == "")
        {
            msg="   - Supplier Calls\n"+msg;
            count=count+1;
        }
        if (timeSpentPerCall =="")
        {
            msg="   - Time Spent Per Call\n"+msg;
            count=count+1;
        }
        if (timeSpentPerInvoice == "")
        {
            msg="   - Time Spent Per Invoice\n"+msg;
            count=count+1;
        }
        
    } else if (pg == 4) {
        var pctInvRcvElectonically= getRadioValue('ddlPctInvoiceReceivedElect'); 
        var pctNonPO = document.getElementById('txtPercentNonPO').value; 
        var invSettledElectronically = getRadioValue('ddlPctInvoiceSettleElect'); 
        
        if (!invSettledElectronically )
        {
            msg="   - Invoices Settled Electronically\n"+msg;
            count=count+1;
        }
        if (pctNonPO =="")
        {
            msg="   - Percentage of Non-PO's\n"+msg;
            count=count+1;
        }
        if (!pctInvRcvElectonically)
        {
            msg="   - Percentage of Invoices Received Electronically\n"+msg;
            count=count+1;
        }
        
    }
    
    
    if(count>0)
    {
        alert("Please enter your:\n" + msg);
        return false;
    }
    else
    {
        document.getElementById('btnSubmit').click();
        return true;
    }

}

function getRadioValue(RadioName)
{
    var colRadio = document.getElementsByName(RadioName);
    for (var i = 0; i < colRadio.length; i++)
    {
    //alert(colRadio[i].value);
        if (colRadio[i].checked)
        {
        return true;
        }
    }
    return false;
}

function validate_Calculate_Page3()
{
    var SupplierFieldedPerAp = document.getElementById('txtSupplierFieldedPerAp').value;
    var TimeSpentInDataEntryPerInvoice = document.getElementById('txtTimeSpentInDataEntryPerInvoice').value;
    var TimeSpentPerCall = document.getElementById('txtTimeSpentPerCall').value;
 
    var msg="";
    var count=0;
 
    if(SupplierFieldedPerAp=="")
    {
        msg=msg+"Please enter No. of supplier calls per AP personnel per day\n";
        count=count+1;
    }
    else if(SupplierFieldedPerAp==0)
    {
        msg=msg+"Please enter a Non Zero value for No. of supplier calls per AP personnel per day\n";
        count=count+1;
    }
 
    if(TimeSpentInDataEntryPerInvoice=="")
    {
        msg=msg+"Please enter Time Spent In Data Entry Per Invoice\n";
        count=count+1;
    }
    else if(TimeSpentInDataEntryPerInvoice==0)
    {
        msg=msg+"Please enter a Non Zero value for Time Spent In Data Entry Per Invoice\n";
        count=count+1;
    }
 
    if(TimeSpentPerCall=="")
    {
        msg=msg+"Please enter Time Spent Per Call\n";
        count=count+1;
    }
    else if(TimeSpentPerCall==0)
    {
        msg=msg+"Please enter a Non Zero value for Time Spent Per Call\n";
        count=count+1;
    }
 
    if(count>0)
    {
        alert(msg);
        return false;
    }
    else
    {
        return true;        
    }
 
}
function validate_Calculate_Page4()
{
    var PercentNonPO = document.getElementById('txtPercentNonPO').value;
    
    var msg="";
    var count=0;
    if(PercentNonPO=="")
    {
        msg=msg+"Please enter Percentage of Non-PO invoices\n";
        count=count+1;
    }
    else if(PercentNonPO==0)
    {
        msg=msg+"Please enter a Non Zero value for Percentage of Non-PO invoices\n";
        count=count+1;
    }
  
    if(count>0)
    {
        alert(msg);
        return false;
    }
    else
    {
        return true;        
    }
 
}
 
function validateValue(o, msg)
   {
      if (isInteger(o.value) == false && !isEmpty(o.value))
      {
         var label = getLabel(o);
         alert("\"" +o.value +"\" is invalid, "+msg);
         o.select();
      }
   }

function isInteger (s)
   {

      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

function getLabel(inputElem){
    if(inputElem.parentNode){
        if(inputElem.parentNode.tagName=='label'){
            return inputElem.parentNode;
        }
    }
    
    var labels=document.getElementsByTagName("label");
    for( var i=0; i<labels.length;i++ ){
        if(labels[i].htmlFor==inputElem.id){
            return labels[i];
        }
    }
    return false;
}


function allowsintegeronly()
{
if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode == 46 || event.keyCode == 32)) {
        event.returnValue = true;
        return true;
    }
    else {
        event.returnValue = false;
        return false;
    }
    if (event.keyCode == 8) {
        charRemove();
    }
    if (event.keyCode == 127) {
        charRemove();
    }
}

function TabclaC()
{
    var PercentNonPO = document.getElementById('txtPercentNonPO').value;
    var TotalValueofInvoice = document.getElementById('txtTotalValueofInvoice').value;
    var SupplierFieldedPerAp = document.getElementById('txtSupplierFieldedPerAp').value;
    var TimeSpentInDataEntryPerInvoice = document.getElementById('txtTimeSpentInDataEntryPerInvoice').value;
    var TimeSpentPerCall = document.getElementById('txtTimeSpentPerCall').value;
 
    if(PercentNonPO != "" && TotalValueofInvoice != "" && SupplierFieldedPerAp != "" && TimeSpentInDataEntryPerInvoice != "" && TimeSpentPerCall != "")
    {
       document.getElementById('btnCalculate').click(); 
    }
 
}