﻿
/* Select a row for editing, the row data of the selected row appears in the boxes which can be edited */

//Dairy Editing
function onRecordSelect(arrSelectedRecords) 
{
    var record = arrSelectedRecords[0];

    var theForm = document.forms[0];
    
    for(i = 0; i < theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('txthidden') != -1)
        {
            theForm.elements[i].value = record.DiaryID;
        }
        if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = record.Subject;
        }
        if(theForm.elements[i].id.indexOf('txtDescription') != -1)
        {
            theForm.elements[i].value = record.Description;
        }
        if(theForm.elements[i].id.indexOf('ddlFeatures') != -1)
        {
             theForm.elements[i].value = record.Features;
        }   
        if(record.PostingTo == "Team")
        {
            if(theForm.elements[i].id.indexOf('rbTeam') != -1)
            {
                theForm.elements[i].checked = true;
            }
        }
        if(record.PostingTo == "Personal")
        {
            if(theForm.elements[i].id.indexOf('rbPersonal') != -1)
            {
                theForm.elements[i].checked = true;
            }
        }
    }
 }
 
 function onMemberRecordSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    var index;
    var dob = record.DOB;
    var dateOfBirth;
    var arr = new Array();
    dateOfBirth = dob.substring(0,dob.length - 12);
    arr = dateOfBirth.split('/');
    var CurrentUserID;
    var userType;
                      
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnCurrentUID') != -1)
        {
            CurrentUserID = theForm.elements[i].value;
        }
        if(theForm.elements[i].id.indexOf('hdnUserType') != -1)
        {
            userType = theForm.elements[i].value;
        }              
    }
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnUserID') != -1)
        {
            theForm.elements[i].value = record.UserID;
        }
        if(theForm.elements[i].id.indexOf('txtUser') != -1)
        {
            theForm.elements[i].value = record.ScreenName;
        }
        if(theForm.elements[i].id.indexOf('txtFName') != -1)
        {
            theForm.elements[i].value = record.FirstName;
        }
        if(theForm.elements[i].id.indexOf('txtMName') != -1)
        {
            theForm.elements[i].value = record.MiddleName;
        }
        if(theForm.elements[i].id.indexOf('txtLName') != -1)
        {
            theForm.elements[i].value = record.LastName;
        }
        if(theForm.elements[i].id.indexOf('txtEmail') != -1)
        {
            theForm.elements[i].value = record.EmailID;
            theForm.elements[i].readOnly = true;
        }
        if(theForm.elements[i].id.indexOf('ddlMaritalStatus') != -1)
        {   
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(theForm.elements[i].options[a].text == trim(record.MaritalStatus))
                {
                    index = a;        
                }
            }
            theForm.elements[i].selectedIndex = index;
        }
        if(theForm.elements[i].id.indexOf('txtMobile') != -1)
        {
            theForm.elements[i].value = record.Mobile;
        }
        if(theForm.elements[i].id.indexOf('ddlMonth') != -1)
        {
            for(a=0; a <= 12; a++)
            {
                if(a == arr[0])
                {
                    index = a;        
                }
            }
            theForm.elements[i].selectedIndex = index;
        }
        if(theForm.elements[i].id.indexOf('ddlDay') != -1)
        {
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(theForm.elements[i].options[a].text == trim(arr[1]))
                {
                    index = a;        
                }
            }
            theForm.elements[i].selectedIndex = index;
        }
        if(theForm.elements[i].id.indexOf('ddlYear') != -1)
        {
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(theForm.elements[i].options[a].text == trim(arr[2]))
                {
                    index = a;        
                }
            }
            theForm.elements[i].selectedIndex = index;
        }
        if(theForm.elements[i].id.indexOf('ddlEducation') != -1)
        {
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(theForm.elements[i].options[a].value == record.EducationID)
                {
                    index = a;
                }
            }
            theForm.elements[i].selectedIndex = index;
        }
        if(theForm.elements[i].id.indexOf('chkDisable') != -1)
        {
            if(record.IsDisable == "True")
            {
                theForm.elements[i].checked = true;
            }
            else
            {
                theForm.elements[i].checked = false;
            }
        }
        if(theForm.elements[i].id.indexOf('chkChildWorking') != -1)
        {
            if(record.IsChildWorking == "True")
            {
                theForm.elements[i].checked = true;
            }
            else
            {
                theForm.elements[i].checked = false;
            }
        }
        if(theForm.elements[i].id.indexOf('btnSave') != -1)
        {
            if(userType == 'M' && CurrentUserID != record.UserID.toString())
            {
                theForm.elements[i].disabled = true;
            }
            else if(userType == 'A' || userType == 'S')
            {              
                theForm.elements[i].disabled = false;
            }
            else 
            {   
                theForm.elements[i].disabled = false;
            }          
        }
        if(record.Gender == "M")
        {
            if(theForm.elements[i].id.indexOf('rbMale') != -1)
            {
                theForm.elements[i].checked = true;
            }
        }
        if(record.Gender == "F")
        {
            if(theForm.elements[i].id.indexOf('rbFemale') != -1)
            {
                theForm.elements[i].checked = true;
            }
        }
        if(theForm.elements[i].id.indexOf('btnSave') != -1)  // Change the text of button when select user from grid
        {
            theForm.elements[i].value = "Update";
        }
        if(theForm.elements[i].id.indexOf('ddlCurrency') != -1)  // Change the text of button when select user from grid
        {
           var index = -1;
           try
           {
               for(a=0; a < ddlCurrency.options.length; a++)
                {
                    if (ddlCurrency.options[a].value == record.CurID)
                    {
                        index = a;
                        break;
                    }
                }
                ddlCurrency.selectedIndex(index);
                if (index == -1)
                    ddlCurrency.setText('');
                else
                    ddlCurrency.setText(ddlCurrency.options[index].text);

                if (theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_lblAdminCurr').innerHTML != ddlCurrency.options[index].text)
                {
                    document.getElementById('ctl00_ContentPlaceHolder1_trExchRate').style.display = 'block';
                    document.getElementById('ctl00_ContentPlaceHolder1_lblMemberCurr').innerHTML = ddlCurrency.options[index].text;
                    document.getElementById('ctl00_ContentPlaceHolder1_txtExchRate').focus();
                }
                else
                {
                    document.getElementById('ctl00_ContentPlaceHolder1_trExchRate').style.display = 'none';
                    document.getElementById('ctl00_ContentPlaceHolder1_lblMemberCurr').innerHTML = adminCur;
                }            
            }
            catch(e)
            {
            }         
        }
        if(theForm.elements[i].id.indexOf('txtExchRate') != -1)  // Change the text of button when select user from grid
        {
            theForm.elements[i].value = record.ExchRate;
        }
    }
 }
 
 function onAdminRecordSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    var index;
    var CurrentUserID;
    var userType;
                      
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnCurrentUID') != -1)
        {
            CurrentUserID = theForm.elements[i].value;
        }
        if(theForm.elements[i].id.indexOf('hdnUserType') != -1)
        {
            userType = theForm.elements[i].value;
        }
        if(theForm.elements[i].id.indexOf('hdnIsSuspended') != -1)
        {
            userType = theForm.elements[i].checked;
        }
    }
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnUserID') != -1)
        {
            theForm.elements[i].value = record.UserID;
        }
        if(theForm.elements[i].id.indexOf('txtFName') != -1)
        {
            theForm.elements[i].value = record.FirstName;
        }
        if(theForm.elements[i].id.indexOf('txtMName') != -1)
        {
            theForm.elements[i].value = record.MiddleName;
        }
        if(theForm.elements[i].id.indexOf('txtLName') != -1)
        {
            theForm.elements[i].value = record.LastName;
        }
        if(theForm.elements[i].id.indexOf('txtEmail') != -1)
        {
            theForm.elements[i].value = record.EmailID;
            theForm.elements[i].readOnly = true;
        }
        if(theForm.elements[i].id.indexOf('txtMobile') != -1)
        {
            theForm.elements[i].value = record.Mobile;
        }
        if(theForm.elements[i].id.indexOf('txtRegistrationDate') != -1)
        {
            theForm.elements[i].value = record.RegistrationDate;
        }
        if(theForm.elements[i].id.indexOf('txtCountry') != -1)
        {
            theForm.elements[i].value = record.Country;
        }
        
    }
 }
  
 function onExpenseMasterSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnExpID') != -1)
        {
            theForm.elements[i].value = record.ExpenseID;
        }
    }
 }
 
 function onExpenseDetailSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
       if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
          //  alert("hi4");
            theForm.elements[i].value = record.NodeHTML;
            //alert(record.NodeHTML);
        }
        if(theForm.elements[i].id.indexOf('txthidden') != -1)
        {
            theForm.elements[i].value = record.NodeID;
        }
        if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = record.Subject;
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Quantity);
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Price).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = record.Comment;
        }
        if(theForm.elements[i].id.indexOf('txtTotAmt') != -1)
        {
            theForm.elements[i].value = parseFloat(record.TotalAmount).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtFedTax') != -1)
        {
            theForm.elements[i].value = parseFloat(record.FederalTax).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtStateTax') != -1)
        {
            theForm.elements[i].value = parseFloat(record.StateTax).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtOther') != -1)
        {
            theForm.elements[i].value = parseFloat(record.OtherTax).toFixed(2);
        } 
        
         if(theForm.elements[i].id.indexOf('txtDiscount') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Discount).toFixed(2);
        }
        
        
        if(theForm.elements[i].id.indexOf('txtDate') != -1)
        {
            var date = record.ExpDate;
            theForm.elements[i].value = date.substring(0,date.length - 11);
        } 
        if(theForm.elements[i].id.indexOf('txtNetAmt') != -1)
        {
            theForm.elements[i].value = parseFloat(record.NetAmount).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('hiddenExpenseID') != -1)
        {
            theForm.elements[i].value = record.ExpenseDetailID;
        }
        if(theForm.elements[i].id.indexOf('ddlPaymentSource') != -1)
        {
            theForm.elements[i].selectedIndex = -1;
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(trim(record.PaymentSource) == "Not Specified")
                {
                    theForm.elements[i].options[0].selected = true;
                    break;
                }
                if(theForm.elements[i].options[a].text == trim(record.PaymentSource))
                {
                    theForm.elements[i].options[a].selected = true;
                    break;
                }
            }
        }
    }
 }
 
 function onFutureExpenseMasterSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnExpID') != -1)
        {
            theForm.elements[i].value = record.FExpenseID;
        }
    }
 }
 
 function onFutureExpenseDetailSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
       if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = record.NodeHTML;
        }
        if(theForm.elements[i].id.indexOf('txthidden') != -1)
        {
            theForm.elements[i].value = record.NodeID;
        }
        if(theForm.elements[i].id.indexOf('hiddenExpenseID') != -1)
        {
            theForm.elements[i].value = record.FExpenseDetailID;
        }
        if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = record.Subject;
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Quantity);
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Price).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = record.Comment;
        } 
        if(theForm.elements[i].id.indexOf('txtTotAmt') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Total).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtDate') != -1)
        {
            var date = record.FExpDate;
            theForm.elements[i].value = date.substring(0,date.length - 11);
        } 
    }
 }
 
 function onRevenueMasterSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnRevID') != -1)
        {
            theForm.elements[i].value = record.RevenueID;
        }
    }
 }
 
 function onRevenueDetailSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = record.NodeHtml;
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = record.Comment;
        }
        if(theForm.elements[i].id.indexOf('txtQty') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Qty).toString();
        }
        if(theForm.elements[i].id.indexOf('txtUnit') != -1)
        {
            theForm.elements[i].value = parseFloat(record.UnitPrice).toString();
        }
        if(theForm.elements[i].id.indexOf('txtIncome') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Income).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtFDPertMain') != -1)
        {
            theForm.elements[i].value = parseFloat(record.FedPert).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtFedTax') != -1)
        {
            theForm.elements[i].value = parseFloat(record.FederalTax).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtSTPertMain') != -1)
        {
            theForm.elements[i].value = parseFloat(record.StatePert).toFixed(2);
        }        
        if(theForm.elements[i].id.indexOf('txtStateTax') != -1)
        {
            theForm.elements[i].value = parseFloat(record.StateTax).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtOther') != -1)
        {
            theForm.elements[i].value = parseFloat(record.OtherTax).toFixed(2);
        } 
        if(theForm.elements[i].id.indexOf('hiddenRevDetID') != -1)
        {
            theForm.elements[i].value = record.RevenuDetailID;
        }
        if(theForm.elements[i].id.indexOf('txthidden') != -1)
        {
            theForm.elements[i].value = record.NodeID;
        }
        if(theForm.elements[i].id.indexOf('txtNetIncome') != -1)
        {
            theForm.elements[i].value = parseFloat(record.NetIncome).toFixed(2);
        }
        if (theForm.elements[i].id.indexOf('txtClientComments') != -1)
        {
            theForm.elements[i].value = record.ClientComments;
        }
        if(theForm.elements[i].id.indexOf('txtHdIncome') != -1)
        {
            theForm.elements[i].value = parseFloat(record.NetIncome).toFixed(2);
        }
    }
      try 
      {
       if(ddlClient != null)
       {
           var index = 0;
           for(a=0; a < ddlClient.options.length; a++)
            {
            if (ddlClient.options[a].text == record.FirstName + " " + record.LastName)
            {
                index = a;
                break;
            }
            }
            ddlClient.selectedIndex(index);
            ddlClient.SelectedText(ddlClient.options[index].text);
        }
        }
        catch(e)
        {
        }
 }
 
 function onShoppingNavigatorSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hiddenShopID') != -1)
        {
            theForm.elements[i].value = record.ShoppingListID;
        }
     }
 }
 
 function onShoppingDetailSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
       if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = record.NodeHTML;
        }
        if(theForm.elements[i].id.indexOf('txthidden') != -1)
        {
            theForm.elements[i].value = record.NodeID;
        }
        if(theForm.elements[i].id.indexOf('txtDate') != -1)
        {
            var date = record.ShoppingListDate;
            theForm.elements[i].value = date.substring(0,date.length - 11);
        }
        if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = record.Subject;
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Quantity);
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Price).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtTotal') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Total).toFixed(2);
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = record.Comment;
        }
        if(theForm.elements[i].id.indexOf('hiddenShopID') != -1)
        {
            theForm.elements[i].value = record.ShoppingListDetailID;
        }
     }
 }
 
 function onFootPrintSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hiddenNodeID') != -1)
        {
            theForm.elements[i].value = record.NodeID;
        }
     }
 }
 
 function onScheduleSelect(arrSelectedRecords)
 {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
       
    var startT = record.StartTime;
    var endT = record.EndTime;
    var arrS = startT.split(' ');
    var arrE = endT.split(' ');
    var when = arrS[0]; // When - Date
    var subWhen = arrS[1];
    var whenTime = subWhen.substring(0,subWhen.length - 3)+ " " + arrS[2]; // When - Time
   
    var to = arrE[0]; // To - Date
    var subTo = arrS[1];
    
    var toTime = subTo.substring(0,subTo.length - 3) + " " + arrS[2]; // To - Time
    
    var hdnUrsID;
    var usrID;
    for(i = 0; i < theForm.elements.length; i++)
    {
         if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = record.Subject;
        }
        if(theForm.elements[i].id.indexOf('hdnUserID') != -1)
        {
            hdnUrsID = parseInt(theForm.elements[i].value);
            usrID = parseInt(record.UserID);
        }
        if(theForm.elements[i].id.indexOf('hdnEventID') != -1)
        {
            theForm.elements[i].value = record.ID;
        }
        if(theForm.elements[i].id.indexOf('ob_comboWhenTextbox') != -1)
        {
            theForm.elements[i].value = whenTime;
        }
        if(theForm.elements[i].id.indexOf('ob_comboToTextbox') != -1)
        {
            theForm.elements[i].value = toTime;
        }
        if(theForm.elements[i].id.indexOf('txtWhen') != -1)
        {
            theForm.elements[i].value = when;
        }
        if(theForm.elements[i].id.indexOf('txtTo') != -1)
        {
            theForm.elements[i].value = to;
        }
        if(theForm.elements[i].id.indexOf('txtPlace') != -1)
        {
            theForm.elements[i].value = record.Place;
        }
        if(theForm.elements[i].id.indexOf('txtDescription') != -1)
        {
            theForm.elements[i].value = record.Description;
        }
        if(hdnUrsID == usrID)
        {
            if(theForm.elements[i].id.indexOf('btnNew1') != -1)
            {
                theForm.elements[i].disabled = false;
            }
            if(theForm.elements[i].id.indexOf('btnSave1') != -1)
            {
                theForm.elements[i].disabled = false;
            }
            if(theForm.elements[i].id.indexOf('btnDelete1') != -1)
            {
                theForm.elements[i].disabled = false;
            }  
        }
        else
        {
            if(theForm.elements[i].id.indexOf('btnNew1') != -1)
            {
                theForm.elements[i].disabled = true;
            }
            if(theForm.elements[i].id.indexOf('btnSave1') != -1)
            {
                theForm.elements[i].disabled = true;
            }
            if(theForm.elements[i].id.indexOf('btnDelete1') != -1)
            {
                theForm.elements[i].disabled = true;
            }
        }
        if(theForm.elements[i].id.indexOf('ddlCategory') != -1)
        {
            theForm.elements[i].selectedIndex = -1;
            for(a=0; a < theForm.elements[i].options.length; a++)
            {
                if(theForm.elements[i].options[a].value == trim(record.CategoryID))
                {
                    theForm.elements[i].options[a].selected = true;
                    break;
                }
            }
        }
        
    }
 }
 
 
 /* On clicking the "NEW" button, it clears all the boxes */
 /* Clears Diary Controls */
 function ClearAllControls(lblMsg)
 {
    var theForm = document.forms[0];
    
    for(i = 0; i < theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "hidden")
        {
            if(theForm.elements[i].name.indexOf('txthidden')!= -1)
            {
                theForm.elements[i].value = "";
            }
            if(theForm.elements[i].name.indexOf('hiddenExpenseID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea")
        {   
            if(theForm.elements[i].id.indexOf('txtDate') == -1)
            {
                theForm.elements[i].value = "";            
            }
            if (theForm.elements[i].id.indexOf('txtSubject') == -1)
            {
                theForm.elements[i].value = "";            
            }
        }
        if(theForm.elements[i].id.indexOf('ddlFeatures') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].type == "radio")
        {
            theForm.elements[i].checked = false;
        }
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    }
    return false;
 }
 
 //Clear the textboxes,dropdown and check boxes on Click of new button
 function ClearMemberRegistrationControls(lblUserMessage)
 {  
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('hdnUserID') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtUser') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPwd') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtConfirmPwd') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtFName') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtMName') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtLName') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtEmail') != -1)
        {
            theForm.elements[i].value = "";
            theForm.elements[i].readOnly = false;
        }
        if(theForm.elements[i].id.indexOf('txtMobile') != -1)
        {
            theForm.elements[i].value = "";
        }       
        if(theForm.elements[i].id.indexOf('ddlMaritalStatus') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].id.indexOf('ddlMonth') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].id.indexOf('ddlDay') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].id.indexOf('ddlYear') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].id.indexOf('ddlEducation') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        if(theForm.elements[i].id.indexOf('chkDisable') != -1)
        {
            theForm.elements[i].checked = 0;
        }
        if(theForm.elements[i].id.indexOf('chkChildWorking') != -1)
        {
            theForm.elements[i].checked = 0;
        }
        if(theForm.elements[i].id.indexOf('btnSave') != -1)
        {
            theForm.elements[i].value = "Save";
        }
        if(theForm.elements[i].id.indexOf('ddlCurrency') != -1)
        {
            try
              {
                ddlCurrency.selectedIndex(-1);
                ddlCurrency.SelectedText("");
              }
            catch(e)
              {
              }        
        }        
        if(theForm.elements[i].id.indexOf('txtExchRate') != -1)
        {
            theForm.elements[i].value = "";
        }
        
        var VS = document.getElementById('ctl00_ContentPlaceHolder1_ValidationSummary1');
        VS.style.display = "none";
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblUserMessage);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
        
    }
    return false;
 }
 
 function ClearFutureControls(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "hidden")
        {
            if(theForm.elements[i].name.indexOf('txthidden')!= -1)
            {
                theForm.elements[i].value = "";
            }
            if(theForm.elements[i].name.indexOf('hiddenExpenseID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtTotAmt') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = "";
        }
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    }
    return false;
 }
 
 
 function ClearExpenseControls(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "hidden")
        {
            if(theForm.elements[i].name.indexOf('txthidden')!= -1)
            {
                theForm.elements[i].value = "";
            }
            
            if(theForm.elements[i].name.indexOf('hiddenExpenseID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].id.indexOf('txtDate') != -1)
        {
            //theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtTotAmt') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtFedTax') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtStateTax') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtOther') != -1)
        {
            theForm.elements[i].value = "";
        } 
        if(theForm.elements[i].id.indexOf('txtNetAmt') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('ddlPaymentSource') != -1)
        {
            theForm.elements[i].selectedIndex = 0;
        }
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    }
    return false;
 }
 
 
 function ClearSchedulerControl(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('txtSubject') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('hdnEventID') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('ob_comboWhenTextbox') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('ob_comboToTextbox') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtWhen') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtTo') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPlace') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtDescription') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtDescription') != -1)
        {
            theForm.elements[i].value = "";
        }
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    }
    return false;
 }
 
 function ClearRevenueControls(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "hidden")
        {
            if(theForm.elements[i].name.indexOf('txthidden')!= -1)
            {
                theForm.elements[i].value = "";
            }
            if(theForm.elements[i].name.indexOf('txtHdIncome')!= -1)
            {
                theForm.elements[i].value = "";
            }
            
            if(theForm.elements[i].name.indexOf('hiddenRevDetID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtUnit') != -1)
        {
            theForm.elements[i].value = "";
        }      
        if(theForm.elements[i].id.indexOf('txtIncome') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtTotAmt') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtFDPertMain') != -1)
        {
            theForm.elements[i].value = "";
        }        
        if(theForm.elements[i].id.indexOf('txtFedTax') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtSTPertMain') != -1)
        {
            theForm.elements[i].value = "";
        }                
        if(theForm.elements[i].id.indexOf('txtStateTax') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtOther') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtDiscount') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtNetIncome') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('ddlClient') != -1)
        {
            try
              {
                ddlClient.selectedIndex(-1);
                ddlClient.SelectedText("");
              }
            catch(e)
              {
              }        
        }        
        }
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    return false;
 }
 
 function ClearShoppingListControls(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].type == "hidden")
        {
            if(theForm.elements[i].name.indexOf('txthidden')!= -1)
            {
                theForm.elements[i].value = "";
            }
            if(theForm.elements[i].name.indexOf('hiddenShopID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].id.indexOf('txtItem') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPrice') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtQuantity') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtTotal') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtComment') != -1)
        {
            theForm.elements[i].value = "";
        }
        
        //clear user friendly message on click of NEW button
        var errMsg = document.getElementById(lblMsg);
        if(errMsg != null)
        {
            errMsg.style.display = "none";
        }
    }
    return false;
 }
 
  function ClearClientControls(lblMsg)
 {
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('txtClientNo') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtCompany') != -1)
        {
            var txtCompany = theForm.elements[i];
            theForm.elements[i].value = "";
            txtCompany.focus();
        }
        if(theForm.elements[i].id.indexOf('txtFName') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtLName') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtCity') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtState') != -1)
        {
            theForm.elements[i].value = "";
        }
        if(theForm.elements[i].id.indexOf('txtPhone') != -1)
        {
            theForm.elements[i].value = "";
        }       
       }
      if(document.getElementById('ctl00_ContentPlaceHolder1_ValidationSummary1') != null)
        {
            document.getElementById('ctl00_ContentPlaceHolder1_ValidationSummary1').innerHTML = "";
            document.getElementById('ctl00_ContentPlaceHolder1_ValidationSummary1').style.display = "none";
        } 
 }
 
function onClientSelectEvt(arrSelectedRecords)
    {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('txtClientNo') != -1)
        {
            theForm.elements[i].value = record.ClientID;
        }
        if(theForm.elements[i].id.indexOf('txtCompany') != -1)
        {
            theForm.elements[i].value = record.CompanyName;
        }
        if(theForm.elements[i].id.indexOf('txtFName') != -1)
        {
            theForm.elements[i].value = record.FirstName;
        }
        if(theForm.elements[i].id.indexOf('txtLName') != -1)
        {
            theForm.elements[i].value = record.LastName;
        }
       if(theForm.elements[i].id.indexOf('txtCity') != -1)
        {
            theForm.elements[i].value = record.City;
        }
        if(theForm.elements[i].id.indexOf('txtState') != -1)
        {
            theForm.elements[i].value = record.State;
        }
        if(theForm.elements[i].id.indexOf('txtPhone') != -1)
        {
            theForm.elements[i].value = record.Phone;
        }
    }
 }
 //Select Prospect function
 function onProspectSelectEvt(arrSelectedRecords)
    {
    var record = arrSelectedRecords[0];
    var theForm = document.forms[0];
    for(i=0;i< theForm.elements.length; i++)
    {
        if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtClientNo') != -1)
        {
            theForm.elements[i].value = record.ProspectID;
            document.getElementById('ctl00_ContentPlaceHolder1_hdnProspectID').value = record.ProspectID;
        }
        if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtCompany') != -1)
        {
            theForm.elements[i].value = record.CompanyName;
            document.getElementById('company').innerHTML = record.CompanyName;
        }
        if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtFName') != -1)
        {
            theForm.elements[i].value = record.FirstName;
            document.getElementById('fName').innerHTML = record.FirstName;
        }
        if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtLName') != -1)
        {
            theForm.elements[i].value = record.LastName;
            document.getElementById('lName').innerHTML = record.LastName;
        }
       if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtCity') != -1)
        {
            theForm.elements[i].value = record.City;
        }
        if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtState') != -1)
        {
            theForm.elements[i].value = record.State;
        }
         if(theForm.elements[i].id.indexOf('ctl00_ContentPlaceHolder1_txtPhone') != -1)
        {
            theForm.elements[i].value = record.Phone;
        }
    }
    document.getElementById('divCommentContainer').style.display = 'block';
    document.getElementById("divComments").style.display='none';
    document.getElementById("errMessage").innerHTML = '';
 }
 /* Other Calculations*/
 function CalculateTotal(price,quantity,TotalAmt)
 {
 
    var prc = document.getElementById(price).value;
    var qty = document.getElementById(quantity).value;
    var txtTotalAmt = document.getElementById(TotalAmt);    
    txtTotalAmt.value = (prc * qty).toFixed(2);
 }
 
 function CalculateNetTotal(totAmt, FedTax, StaTax, OthTax, NetAmt)
 {
   
    var totalAmt = document.getElementById(totAmt).value;
    var FTax = document.getElementById(FedTax).value;
    var STax = document.getElementById(StaTax).value;    
    var OTax = document.getElementById(OthTax).value;
    var NAmt = document.getElementById(NetAmt);
    
    if(FTax == '')
    {
        FTax = 0;
    }
    if(STax == '')
    {
        STax = 0;
    }
    if(OTax == '')
    {
        OTax = 0;
    }
    
    if(totalAmt == '')
    {
        totalAmt = 0;
    }
    else
    {
        NAmt.value = (parseFloat(totalAmt) + parseFloat(FTax) + parseFloat(STax) + parseFloat(OTax)).toFixed(2);
        
    }
 }
 
 function CalculateFutureExpense(price, quantity, totAmt)
 {
    var prc = document.getElementById(price).value;
    var qty = document.getElementById(quantity).value;
    var txtTotalAmt = document.getElementById(totAmt);
    if(qty == '' || prc == '')
    {
        qty = 0;
        prc = 0;
    }
    if(isNaN(prc*qty))
    {
        txtTotalAmt.value = 0.00;
    }
    else
    {
        txtTotalAmt.value = (prc * qty).toFixed(2);
    }
 }
 
 function CalculateTotalShoppingExpenses(Price, Quantity, totAmt)
 {
    var prc = document.getElementById(Price).value;
    var qty = document.getElementById(Quantity).value;
    var txtTotalAmt = document.getElementById(totAmt);
    if(qty == '' || prc == '' || prc == '.')
    {
        qty = 0;
        prc = 0;
    }
    if(isNaN(prc*qty))
    {
        txtTotalAmt.value = 0.00;
    }
    else
    {
        txtTotalAmt.value = (prc * qty).toFixed(2);
    }
    
    var totalAmt = txtTotalAmt.value;
    
    if(totalAmt == '')
    {
        totalAmt = 0;
    }
 }
 
 
 
// function displayStyleSet()
// {
// alert("1"); 
// var txt= document.getElementById('ctl00_ContentPlaceHolder1_txtTotAmt');
// txt.style.display='none';
// return false;
// }
 
 
 
 
 
 
 function CalculateNetExpense(price, quantity, totAmt, FedTax, StaTax, OthTax,discount,NetAmt,hdExpense)
 {
    var prc = document.getElementById(price).value;   
    var qty = document.getElementById(quantity).value;
    var txtTotalAmt = document.getElementById(totAmt);
    var hdExpNetAmt =  document.getElementById(hdExpense);
    
    if(qty == '' || prc == '' || prc == '.')
    {
        qty = 0;
        prc = 0;
    }
    if(isNaN(prc*qty))
    {
        txtTotalAmt.value = 0.00;
    }
    else
    {
        txtTotalAmt.value = (prc * qty).toFixed(2);
    }
    
    var totalAmt = txtTotalAmt.value;
    var FTax = document.getElementById(FedTax).value;
    var STax = document.getElementById(StaTax).value;    
    var OTax = document.getElementById(OthTax).value;
    var Discount = document.getElementById(discount).value;
    var NAmt = document.getElementById(NetAmt);
    
    if(isNaN(FTax) || FTax == '' || FTax == '.')
    {
        FTax = 0;
        
    }
    if(isNaN(STax) || STax == '' || STax == '.')
    {
        STax = 0;
         
    }
    if(isNaN(OTax) || OTax == '' || OthTax == '.')
    {
        OTax = 0;
       
    }
    if(isNaN(Discount) || Discount == '' || Discount == '.')
    {
        Discount = 0;
        
    }
    if(totalAmt == '')
    {
        totalAmt = 0;
        
    }
    else
    {
        NAmt.value = (parseFloat(totalAmt) + parseFloat(FTax) + parseFloat(STax) + parseFloat(OTax)- parseFloat(Discount)).toFixed(2);
        hdExpNetAmt.value = NAmt.value;
    }
 }
 
 function CalculateNetIncome(totIncome, FedTax, StaTax, OthTax, Disc , NetAmt, Product, UnitAmt, Qty, hdIncome)
 {
    var totalIncome = document.getElementById(totIncome).value;
    var FTax = document.getElementById(FedTax).value;
    var STax = document.getElementById(StaTax).value;    
    var OTax = document.getElementById(OthTax).value;
    var Disc = document.getElementById(Disc).value;
    var NAmt = document.getElementById(NetAmt);
    var HdAmt = document.getElementById(hdIncome);
    
    if (document.getElementById(Product) != null)
    {
        var UAmt = document.getElementById(UnitAmt).value;
        var Pqty = document.getElementById(Qty).value;
        if (UAmt != '' && Pqty != '')
        {
            document.getElementById(totIncome).value = (parseFloat(UAmt) * parseFloat(Pqty)).toFixed(2);
            document.getElementById(totIncome).enabled = false;
        }
        else
        {
           document.getElementById(totIncome).enabled = true;
        }
    }
    
    if(isNaN(FTax) || FTax == '' || FTax == '.')
    {
        FTax = 0;
    }
    if(isNaN(STax) || STax == '' || STax == '.')
    {
        STax = 0;
    }
    if(isNaN(OTax) || OTax == '' || OthTax == '.')
    {
        OTax = 0;
    }
    if(isNaN(Disc) || Disc == '' || Disc == '.')
    {
        Disc = 0;
    }
    if(totalIncome == '' || isNaN(totalIncome))
    {
        totalIncome = 0;
    }
    else
    {
        NAmt.value = (parseFloat(totalIncome) - parseFloat(FTax) - parseFloat(STax) - parseFloat(OTax) + parseFloat(Disc)).toFixed(2);
        HdAmt.value = NAmt.value;
    }
 }
 
  function CalculateBusinessNetIncome(totIncome, FTPert, FedTax, STPert, StaTax, OthTax, Disc, NetAmt, Product, UnitAmt, Qty, hdIncome)
 {
    var totalIncome = document.getElementById(totIncome).value;
    var FTPert = document.getElementById(FTPert).value;
    var FTax = document.getElementById(FedTax).value;
    var STPert = document.getElementById(STPert).value;
    var STax = document.getElementById(StaTax).value;
    var OTax = document.getElementById(OthTax).value;
    var Disc = document.getElementById(Disc).value;
    var NAmt = document.getElementById(NetAmt);
    var hdAmt = document.getElementById(hdIncome);
    
//    document.getElementById(FTPert).enabled = false;
//    document.getElementById(STPert).enabled = false;
    
    if (document.getElementById(Product) != null)
    {
        var UAmt = document.getElementById(UnitAmt).value;
        var Pqty = document.getElementById(Qty).value;
        if (UAmt != '' && Pqty != '')
        {
            totalIncome = (parseFloat(UAmt) * parseFloat(Pqty)).toFixed(2);
            document.getElementById(totIncome).value = totalIncome;
            document.getElementById(totIncome).enabled = false;
        }
        else
        {
           document.getElementById(totIncome).enabled = true;
        }
    }
    if (isNaN(FTPert) || FTPert == '' || FTPert == '.')
    {
        FTPert = 0;
    }
    if(isNaN(FTax) || FTax == '' || FTax == '.')
    {
        FTax = 0;
    }
    if (totalIncome != 0 || FTPert != 0)
    {
        FTax = parseFloat(parseFloat(totalIncome)*(parseFloat(FTPert))* 0.01).toFixed(2); 
        document.getElementById(FedTax).value = FTax;
        document.getElementById(FedTax).enabled = false;
    }
    
    if (isNaN(STPert) || STPert == '' || STPert == '.')
    {
        STPert = 0;
    }

    if(isNaN(STax) || STax == '' || STax == '.')
    {
        STax = 0;
    }
    if (totalIncome != 0 || STPert != 0)
    {
        //document.getElementById(STPert).value = STPert;
        STax = parseFloat((parseFloat(STPert)*parseFloat(totalIncome))*0.01).toFixed(2);
        document.getElementById(StaTax).value = STax;
        document.getElementById(StaTax).enabled = false;        
    }

    if(isNaN(OTax) || OTax == '' || OthTax == '.')
    {
        OTax = 0;
    }
    
    if(isNaN(Disc) || Disc == '' || Disc == '.')
    {
        Disc = 0;
    }
    
    if(totalIncome == '' || isNaN(totalIncome))
    {
        totalIncome = 0;
    }
    else
    {
        NAmt.value = (parseFloat(totalIncome) + parseFloat(FTax) + parseFloat(STax) + parseFloat(OTax) - parseFloat(Disc)).toFixed(2);
        hdAmt.value = NAmt.value;
    }
 }
 
 function formatNumeric(objText)
 {
    if (isNaN(objText.value) || objText.value == "")
    {
        objText.value = 0;
    }
    objText.value = parseFloat(objText.value).toFixed(2);
 }
 
 function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
 }

 //Calculate age of a person according to his birth date
 function calculate_Age(ddlYear, hdAge)
 {
    var age;
    var currentYear = new Date().getFullYear();
    var birthYear = ddlYear.options[ddlYear.selectedIndex].value;
    age = currentYear - birthYear;
    hdAge.value = age.toString();
 }

 //Checks for "Terms of Services"
 function checkbox_Validate(sender, args)
 {
    var chkBox = document.getElementById("ctl00_ContentPlaceHolder1_chkTerms");
    if (chkBox.checked)
    {
        args.IsValid = true;
    }
    else
    {
        args.IsValid = false;
    }
 }

 //Checks for birth date
 function checkDate(sender, args)
 {
    var ddlYear = document.getElementById("ctl00_ContentPlaceHolder1_ddlYear");
    var ddlMonth = document.getElementById("ctl00_ContentPlaceHolder1_ddlMonth");
    var ddlDay = document.getElementById("ctl00_ContentPlaceHolder1_ddlDay");
    if (ddlYear.selectedIndex == 0 || ddlMonth.selectedIndex == 0 || ddlDay.selectedIndex == 0)
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid= true;
    }
 }

 //Checks for "ToDate" and "FromDate"
 function checkDateRange(sender, args)
 {
    var txtFromDate = document.getElementById("ctl00_ContentPlaceHolder1_txtFromDate");
    var txtToDate = document.getElementById("ctl00_ContentPlaceHolder1_txtToDate");
    
    if (txtFromDate.value == "" || txtToDate.value == "")
    {
        args.IsValid = false;
    }
    else
    {
        args.IsValid= true;
    }
 }
 
 //Show Scheduler
 function ShowSchedule(ddlUser,urlPrefix)
 {
    var theForm = document.forms[0];
    var hdnUsrID;
    var selectUser = document.getElementById(ddlUser);
    var userID = selectUser.options[selectUser.selectedIndex].value;
    for(i = 0; i < theForm.elements.length; i++)
    {
       if(theForm.elements[i].id.indexOf('hdnUserID') != -1)
        {
            hdnUrsID = parseInt(theForm.elements[i].value);
        }
    }
    
    if(userID == 'All')
    {
        alert('Please select a user from member list');
    }
    else if(userID == hdnUrsID)
    {
        var url = urlPrefix + '/Schedules.aspx?UserID=' + userID;
        window.open(url,'name','height=525,width=625,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
    }
    else
    {
        var url = urlPrefix + '/SchedulerWithNoRights.aspx?UserID=' + userID;
        window.open(url,'name','height=525,width=625,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=no,resizable=no ,modal=yes');
    }
    return false;
 }
 
 
/* Restricts EDIT functionality for some keys */
function getKeyCode(e)
{
    if (window.event)
    return window.event.keyCode;
    else if (e)
    return e.which;
    else
    return null;
}

function RestrictEdit(e)
{
    var key;
    key = getKeyCode(e);
    if (key == 39 || key == 8 ||  key == 46 || key == 18 || (key == 17 && event.altKey)) 
    return false;
    else
    return false;
}


/* Change the display name with change of Admin/Member selection */
function onSelectingUserType(rb,lblUser)
{
    var displayName = document.getElementById(lblUser);
    
    if(rb.id.indexOf('Member') == -1)
    {
        displayName.innerHTML = "Email:";
    }
    else
    {
        displayName.innerHTML = "User Name:";
        
    }
    rb.checked = true;
    
    return false;
}

/* Check numeric number */

function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
 var key;
 var isCtrl = false;
 var keychar;
 var reg;
  
 if(window.event) {
  key = e.keyCode;
  isCtrl = window.event.ctrlKey
 }
 else if(e.which) {
  key = e.which;
  isCtrl = e.ctrlKey;
 }
 
 if (isNaN(key)) return true;
 
 keychar = String.fromCharCode(key);
 
 // check for backspace or delete, or if Ctrl was pressed
 if (key == 8 || isCtrl)
 {
  return true;
 }

 reg = /\d/;
 var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
 /// <reference path="extJsLibrary.js" />
 var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
 return isFirstN || isFirstD || reg.test(keychar);
}

function setFocus(cntrl)
{
    if (cntrl != null ) cntrl.focus();
}

function ValidateDate()
    
    {
    var SDate = document.getElementById("ctl00_ContentPlaceHolder1_txtFromDate").value;    	
    var EDate =  document.getElementById("ctl00_ContentPlaceHolder1_txtToDate").value;
    // alert(SDate); 
          
    var alertReason1 =  'To Date Date must be greater than or equal to  From Date.' 
    var alertReason2 =  'End Date can not be less than Current Date.';
	
    var endDate = new Date(EDate);    	
    var startDate= new Date(SDate);
     
       if(SDate != '' && EDate != '' && startDate > endDate)
    {
	    alert(alertReason1);
	   document.getElementById("ctl00_ContentPlaceHolder1_txtToDate").value = "";
	    return false;
    }
    else if(SDate == '')	
    {
        alert("Please enter From Date");
        return false;
    }
    else if(EDate == '')	
    {
        alert("Please enter To Date");
        return false;
    }
//       else
//       {
//       window.open ("../Payment/Balance.aspx" ,"mywindow","menubar=1,resizable=1,width=350,height=120,top=300,left=500,menubar=no,toolbar=no,addressbar=no");
//       }
       
}

