﻿// Client side validation routines
MRG_CustomValidators = function() {
    /// <summary>
    /// The MRG_CustomValidators class contains functionality utilized across a number
    /// of controls (but not universally)
    /// </summary>
    /// <remarks>
    /// You should not create new instances of _Validators.  Instead you should use the shared instance MRG_CustomValidators.
    /// </remarks>
}
MRG_CustomValidators.prototype = {
    checkForHtml : function(source, argument){
        var html = new RegExp("<[^>]*>");
        argument.IsValid = !argument.Value.match(html);
    },
    checkInvalidValueSelected : function(source, argument){
        argument.IsValid = !(argument.Value == 0);
    },
    isValidForcedChoice : function(){ 
            
var tooMany = false;
  
  var occur5 = document.activeElement.value.match(/5/g);
  var occur4 = document.activeElement.value.match(/4/g);
  var occur3 = document.activeElement.value.match(/3/g);
  var occur2 = document.activeElement.value.match(/2/g);
  var occur0 = document.activeElement.value.match(/0/g);
  
  var count_5;
  var count_4;
  var count_3;
  var count_2;
  var count_0;
  
  if (occur5 != null){
  		count_5 = occur5.length;
	} else {
		count_5 = 0;
	}
	
	 if (occur4 != null){
  		count_4 = occur4.length;
	} else {
		count_4 = 0;
	}

	 if (occur3 != null){
  		count_3 = occur3.length;
	} else {
		count_3 = 0;
	}
	
	 if (occur2 != null){
  		count_2 = occur2.length;
	} else {
		count_2 = 0;
	}
	
	if (occur0 != null){
  		count_0 = occur0.length;
	} else {
		count_0 = 0;
	}
	
	if ((count_5 > 1 || count_4 > 1 || count_3 > 1 || count_2 > 1) || (document.activeElement.value.indexOf("5") >= 0 && document.activeElement.value.indexOf("4") >= 0) || document.activeElement.value.indexOf("3") >= 0 && document.activeElement.value.indexOf("2") >= 0)
	{
		tooMany = true;	
	}

if (document.activeElement.value.length<3 || document.activeElement.value.indexOf("0") < 0 || tooMany == true) {
            window.event.returnValue = false;
            alert('Forced choice requires 3 answers: most, next and not chosen. Use 0 for the answer not chosen.');
            document.activeElement.value = "";
            window.event.srcElement.focus();
            }
            
    },
    isMaxLength : function(source,mlength){
        if (source.getAttribute && source.value.length > mlength)
            source.value = source.value.substring(0, mlength);
    }
}
var MRGCustomValidators;
var $mrg_customvalidators = MRGCustomValidators = new MRG_CustomValidators();