﻿// JScript File
function ValidatePassword(source, args)
{
    args.IsValid=false;
    
    var controlToValidate = source.controltovalidate
    
    if(controlToValidate != null && controlToValidate.length > 0)
    {
        var REQUIRED_LENGTH = 5;
        var control=getControl(controlToValidate);
        
        if(control!=null && control.value.length < REQUIRED_LENGTH)
        {
             args.IsValid=false;
             source.errormessage='Password should be minimum of ' + REQUIRED_LENGTH + ' characters';
        }
        else
        {
             args.IsValid=true; 
        }
   }
   else
   {
     //The control must have the 'ControlToValidate' field set!!! 
     source.errormessage = '[FieldValidators:ValidatePassword] The control must have the \'ControlToValidate\' field set!!!';
   }
}


function ValidateCheckBoxChecked(source, args)
{
    args.IsValid=false;
    
    var atttrib = source.attributes.getNamedItem("validatecheckbox");       
    var controlToValidate = getAttributeValue(atttrib);
            
    if(controlToValidate != null && controlToValidate.length > 0)
    {        
        var control=getControl(controlToValidate);
        
        if(control!=null && control.checked)
        {
             args.IsValid=true;
             //source.errormessage = "chk is valid";
        }
        else
        {
            //source.errormessage = "chk not valid";
            args.IsValid=false; 
        }
   }
   else
   {
     //The control must have the 'ControlToValidate' field set!!! 
     source.errormessage = '[FieldValidators:ValidateCheckBoxChecked] The control must have the \'ControlToValidate\' field set!!!';
   }
}


function getAttributeValue(objAttrib)
{
    if(objAttrib.nodeName!=null && objAttrib.nodeName.length > 0)
        return objAttrib.nodeValue;
    else if(objAttrib.name!=null && objAttrib.name.length > 0)
        return  objAttrib.value;
    else
        return false;
       
}

function getControl(controlId) 
{
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
    if(document.getElementById && document.getElementById(controlId)) 
    {
        return document.getElementById(controlId);
    }
    else if (document.all && document.all(controlId)) 
    {  
        return document.all(controlId);
    } 
    else if (document.layers && document.layers[controlId]) 
    { 
        return document.layers[controlId];
    } 
    else 
    {
        return false;
    }
}

