//
// Base validation
//
function KCT_Validate_Base(val)
{
    var evalfunction = val.evaluationfunction2;
    
    var validate = true;
    
    if( validate )
        return eval(evalfunction + '(val);')
    else
        return true;
   
    return false;
}

//
// OneOfMany Validator
//
function KCT_Validate_OneOfMany(val)
{
    var controlstovalidate = val.controlstovalidate.split(',');
    var valuetocompare = val.valuetocompare;
    var validationType = val.valoperator;
    var minCount = val.minRequired;
    var count = 0;
    
//    alert('validating');
    
    for (i=0;i<controlstovalidate.length;i++)
    {
        var control = document.getElementById(controlstovalidate[i]);
        var cvalue = GetStringValueOfControl(control);
        
//        alert('operator: ' + validationType);
//        alert('control: ' + control.id);
//        alert('cvalue: ' + cvalue);
        
        if( validationType == '1' ) // 'n' controls = valuetocompare
        {
            if( cvalue == valuetocompare )
                count++;
        }
        else if( validationType == '2' ) // 'n' controls != valuetocompare
        {
            if( cvalue != valuetocompare )
                count++;
        }
        else if( validationType == '3' ) // 'n' controls == ''
        {
            if( cvalue == '' )
                count++;
        }
        else if( validationType == '4' ) // 'n' controls != ''
        {
            if( cvalue != '' )
                count++;
        }
        
//        alert('count: ' + count);
        
        if( count >= minCount )
            return true;
    }    
    
    return false;
}

function GetStringValueOfControl(ctrl)
{
    if( ctrl )
    {
        //alert('ctrl is not null');
        //alert('tagName: ' + ctrl.tagName);
        if( ctrl.tagName == 'INPUT' )
        {
            ///alert('returning control value: input');
            return ctrl.value;
        }
        else if( ctrl.tagName == 'SELECT' )
        {
            return ctrl.options[ctrl.selectedIndex].value;
        }
    }
    
    return '';
}