function HideServerValidation(isValid, validationGroup)
{    
    if(!isValid && typeof(HideServerFeedback == "function"))
    {
        HideServerFeedback(validationGroup);
    }
}

function Validate(stringToValidate, regex, validationGroup)
{
    var valid = regex.test(stringToValidate) && (stringToValidate.length > 0);
    
    HideServerValidation(valid, validationGroup);
    return valid;
}

function ValidPhone(source, clientside_arguments)
{           
  var phone = clientside_arguments.Value;
  phone = GetAllSpacesRemoved(phone);
  
  var regex = /^[0-9 +()-]{8,16}$/;
  clientside_arguments.IsValid = Validate(phone, regex, source.validationGroup);
}

function NoInvalidChars(source, clientside_arguments)
{   
    var str = GetAllSpacesRemoved(clientside_arguments.Value);
    var regex = /^[0-9a-zA-Z åÅøØæÆ \w\xc0-\xff\’\'\.\,\+\-\(\)]*$/;
    clientside_arguments.IsValid = Validate(str, regex, source.validationGroup);
}

function ValidEmail(source, clientside_arguments)
{           
    var regex = /^[-a-zA-Z0-9][-._a-zA-Z0-9]*@[-._a-zA-Z0-9]+(\.[-._a-zA-Z0-9]+)*\.[a-zA-Z]{2,6}$/;    
    clientside_arguments.IsValid = Validate(clientside_arguments.Value, regex, source.validationGroup);
}

function ValidZip(source, clientside_arguments)
{        
    var regex = /^\d{4}$/;
    clientside_arguments.IsValid = Validate(clientside_arguments.Value, regex, source.validationGroup);
}

function GetAllSpacesRemoved(input)
{
    return input.replace(/\s/g,'');
}

function IsChecked(source, clientside_arguments)
{    
    var controlid = source.getAttribute("MyControlToValidate");
    var chk = $get(controlid);
    
    var valid = chk.checked;
    HideServerValidation(valid, source.validationGroup);
    
    clientside_arguments.IsValid = valid;
}

function RadioCheck(source, clientside_arguments)
{    
    var valid = false;
    var array = document.getElementsByTagName("input");
    for(i=0;i<array.length;i++)
    {
        if(array[i].type == "radio")
        {
            if(array[i].checked)
            {
                valid = true;
            }
        }
    }
    clientside_arguments.IsValid = valid;
}
