/*
Description:	Information/Validation for select single, in the form of
						<select multiple>
						  [<optgroup>]
						  <option value="?">.</option>
						  [</optgroup>]
						</select>
Author:			Tim Chan
Version:		1.0
Date:			6 May 2004
Specification:	Javascript v1.2
				Netscape 4+
				Explorer 4+
Feature:		First version.
				So Far now is using AND operator for all the selected item in the group
Next Feature: 	Need to define whether we are using AND or OR.
*/

function FormSelectMultiple(){
  return FormSelectMultiple();
}

FormSelectMultiple.hasValue = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
      if(!Expression.isBlank(obj.options[i].value)) return true;
  }
  return false;
}
  
FormSelectMultiple.isDecimal = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isDecimal(obj.options[i].value)) return false;
  }
  return true;
}
  
FormSelectMultiple.isPositive = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isPositive(obj.options[i].value)) return false;
  }
  return true;
}
	
FormSelectMultiple.isInteger = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isInteger(obj.options[i].value)) return false;
  }
  return true;
}

FormSelectMultiple.isEmail = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isEmail(obj.options[i].value)) return false;
  }
  return true;
}
  
FormSelectMultiple.isPostcode = function(obj) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isPostcode(obj.options[i].value)) return false;
  }
  return true;
}

FormSelectMultiple.isExpression = function(obj, expr) {
  for(var i=0; i < obj.options.length; i++) {
    if(obj.options[i].selected)
	  if(!Expression.isBlank(obj.options[i].value) &&
	     !Expression.isExpression(obj.options[i].value, expr)) return false;
  }
  return true;
}

FormSelectMultiple.putValue = function(obj, value) {
 if(value != "") {
   for(var i=0; i < obj.length; i++) {
     if(obj.options[i].value == value) obj.options[i].selected = true;
   }
 }
}
