/*
Description:	Information/Validation on form object
Author:			Tim Chan
Version:		1.0
Date:			6 May 2004
Specification:	Javascript v1.2
				Netscape 4+
				Explorer 4+
Feature:		First version.
				Support form object of type:
				  text			  	textarea				
				  hidden
				  checkbox			radio
				  select-one		select-multiple
*/
function FormObject() {
  return FormObject;
}

FormObject.hasValue = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.hasValue(obj);
    else if(type == 'hidden') return FormInputHidden.hasValue(obj);
    else if(type == 'textarea') return FormTextArea.hasValue(obj);
    else if(type == 'checkbox') return FormInputCheckbox.hasValue(obj);
    else if(type == 'radio') return FormInputRadio.hasValue(obj);
    else if(type == 'select-one') return FormSelectOne.hasValue(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.hasValue(obj);
			  
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }
  
  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(FormObject.hasValue(obj[i])) return true;
  }
    
}

FormObject.isDecimal = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isDecimal(obj);
    else if(type == 'hidden') return FormInputHidden.isDecimal(obj);
    else if(type == 'textarea') return FormTextArea.isDecimal(obj);
    else if(type == 'checkbox') return FormInputCheckbox.isDecimal(obj);
    else if(type == 'radio') return FormInputRadio.isDecimal(obj);
    else if(type == 'select-one') return FormSelectOne.isDecimal(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.isDecimal(obj);
				   
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }

  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isDecimal(obj[i])) return false;
  }
}

FormObject.isPositive = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isPositive(obj);
    else if(type == 'hidden') return FormInputHidden.isPositive(obj);
    else if(type == 'textarea') return FormTextArea.isPositive(obj);  
    else if(type == 'checkbox') return FormInputCheckbox.isPositive(obj);
    else if(type == 'radio') return FormInputRadio.isPositive(obj);
    else if(type == 'select-one') return FormSelectOne.isPositive(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.isPositive(obj);
				  
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }

  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isPositive(obj[i])) return false;
  }

}

FormObject.isInteger = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isInteger(obj);
    else if(type == 'hidden') return FormInputHidden.isInteger(obj);
    else if(type == 'textarea') return FormTextArea.isInteger(obj); 
    else if(type == 'checkbox') return FormInputCheckbox.isInteger(obj);
    else if(type == 'radio') return FormInputRadio.isInteger(obj);
    else if(type == 'select-one') return FormSelectOne.isInteger(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.isInteger(obj);
			    
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }
  
  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isInteger(obj[i])) return false;
  }

}

FormObject.isEmail = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isEmail(obj);
    else if(type == 'hidden') return FormInputHidden.isEmail(obj);
    else if(type == 'textarea') return FormTextArea.isEmail(obj); 
    else if(type == 'checkbox') return FormInputCheckbox.isEmail(obj); 
    else if(type == 'radio') return FormInputRadio.isEmail(obj);
    else if(type == 'select-one') return FormSelectOne.isEmail(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.isEmail(obj);
				    
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }
  
  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isEmail(obj[i])) return false;
  }
}

FormObject.isPostcode = function(obj) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isPostcode(obj);
    else if(type == 'hidden') return FormInputHidden.isPostcode(obj);
    else if(type == 'textarea') return FormTextArea.isPostcode(obj); 
    else if(type == 'checkbox') return FormInputCheckbox.isPostcode(obj); 
    else if(type == 'radio') return FormInputRadio.isPostcode(obj);
    else if(type == 'select-one') return FormSelectOne.isPostcode(obj);
    else if(type == 'select-multiple') return FormSelectMultiple.isPostcode(obj);
				    
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }
  
  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isPostcode(obj[i])) return false;
  }
}

FormObject.isExpression = function(obj, expr) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.isExpression(obj, expr);
    else if(type == 'hidden') return FormInputHidden.isExpression(obj, expr);
    else if(type == 'textarea') return FormTextArea.isExpression(obj, expr); 
    else if(type == 'checkbox') return FormInputCheckbox.isExpression(obj, expr); 
    else if(type == 'radio') return FormInputRadio.isExpression(obj, expr);
    else if(type == 'select-one') return FormSelectOne.isExpression(obj, expr);
    else if(type == 'select-multiple') return FormSelectMultiple.isExpression(obj, expr);
				    
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }

  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  if(!FormObject.isExpression(obj[i], expr)) return false;
  }

}

FormObject.putValue = function(obj, value) {
  if(obj.type) {
    var type = obj.type.toLowerCase();
    if(type == 'text') return FormInputText.putValue(obj, value);
    else if(type == 'hidden') return FormInputHidden.putValue(obj, value);
    else if(type == 'textarea') return FormTextArea.putValue(obj, value);
    else if(type == 'checkbox') return FormInputCheckbox.putValue(obj, value);
    else if(type == 'radio') return FormInputRadio.putValue(obj, value);
    else if(type == 'select-one') return FormSelectOne.putValue(obj, value);
    else if(type == 'select-multiple') return FormSelectMultiple.putValue(obj, value);
			  
    else {
      //alert("Form object type not supported yet.");
      return false;
    }
  }

  //if it is an array
  else if(obj && obj.length) {
    for(var i = 0; i < obj.length; i++)
	  FormObject.putValue(obj[i], value);
  }

}

FormObject.focus = function(obj) {
  if(obj.type) {
	obj.focus();
  }

  //if it is an array
  else if(obj && obj.length && obj.length > 0) {
    FormObject.focus(obj[0]);
  }
}
