﻿function validateChatterStat(form)
{
    var fv = new FormValidator();
    
    fv.addValidator(new TextValidator('description', 'Description is required'));    
    
    if(fv.validate())
    {
        return true;
    }
    else
    {
        return false;
    }
}

function submitChatter(form, value, intChatterID)
{
    var fv = new FormValidator();
    
    if(value == 'Approve')
    {
        fv.addValidator(new TextValidator('startDate', 'Start Date is required'));
        fv.addValidator(new TextValidator('endDate', 'End Date is required'));
        fv.addValidator(new TextValidator('comments', 'Comments is required'));
        
        fv.addValidator(new DateValidator('startDate', 'Start Date must be valid (mm/ dd/yyyy) or (mm-dd-yyyy)'));
        fv.addValidator(new DateValidator('endDate', 'End Date must be valid (mm/dd/yyyy) or (mm-dd-yyyy)'));
    
        fv.addValidator(new CurrentDateValidator('startDate', 'Start Date must be greater than or equal to Current Date'));
        fv.addValidator(new CurrentDateValidator('endDate', 'End Date must be greater than or equal to Current Date'));
    
        fv.addValidator(new FromToDateValidator('startDate','endDate', 'End Date must be greater than or equal to Start Date'));
    }
    
    if(value == 'Reject')
    {
        fv.addValidator(new TextValidator('comments', 'Comments is required'));
    }
    
    if(fv.validate())
    {
        form.cmd.value = value;
        form.chatterID.value = intChatterID;
    }
    else
    {   
        return false;
    }
}

function validateManageChatters(form, value) 
{
    var fv = new FormValidator();
    
    if(form.status.value == 1 || form.status.value == 0)
    {   
        fv.addValidator(new DateValidator('startDate', 'Start Date must be valid (mm/ dd/yyyy) or (mm-dd-yyyy)'));
        fv.addValidator(new DateValidator('endDate', 'End Date must be valid (mm/dd/yyyy) or (mm-dd-yyyy)'));

        fv.addValidator(new FromToDateValidator('startDate','endDate', 'End Date must be greater than or equal to Start Date'));
    }
     
    if(form.status.value != 1)
    {
        fv.addValidator(new CompareControlsHasValue('startDate','endDate','status', form.status.value, 'Status of type approved alone will have Start Date and End Date'));
    }
    
    if(fv.validate())
    {
        form.cmd.value = value;
        form.submit();
    }
    else
    {   
        return false;
    }
}

