﻿
/* Select a row for editing, the row data of the selected row appears in the boxes which can be edited */

//Diary 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";
        }
    }
 }
 
 function onAdminRecordSelect(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('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(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;
            }
        }
    }
 }
 
 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;
        }
        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('txtIncome') != -1)
        {
            theForm.elements[i].value = parseFloat(record.Income).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('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);
        }
        
    }
 }
 
 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";
        }
              
        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('hiddenRevDetID')!= -1)
            {
                theForm.elements[i].value = "";
            }
        }
        if(theForm.elements[i].id.indexOf('txtItem') != -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('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('txtNetIncome') != -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 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;
 }
 
 /* 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);
    alert(FTax);
    
    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)
 {
    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;
    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);
        
    }
 }
 
 function CalculateNetIncome(totIncome, FedTax, StaTax, OthTax, NetAmt)
 {
    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 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(totalIncome == '' || isNaN(totalIncome))
    {
        totalIncome = 0;
    }
    else
    {
        NAmt.value = (parseFloat(totalIncome) - parseFloat(FTax) - parseFloat(STax) - parseFloat(OTax)).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;
}