/* ------------------------------------------------------------------------------- +

	File:		validation.js
	Author:		Ben Nadel
	Date:		January 20, 2005
	Desc:		This has functions for validating objects.

+ ------------------------------------------------------------------------------- */


// Checks to see if an object is a button input
function IsButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "button"));
}


// Checks to see if an object is a checkbox
function IsCheckBox(objCheckBox){
	return(IsObjectOfTagNameAndType(objCheckBox, "input", "checkbox"));
}


// Checks to see if the argument passed is a float
function IsFloat(objNumber){
	// Check to see if it is even a number and that it has a decimal
	if (objNumber && IsNumeric(objNumber) && (objNumber.toString().indexOf(".") >= 0)){
		return(true);
	} else {
		// It is not a number and therefore not a float
		return(false);
	}
}


// Checks to see if an object is a image input
function IsImageInput(objInput){
	return(IsObjectOfTagNameAndType(objInput, "input", "image"));
}


// Check to see if the argument passed is an integer
function IsInt(objNumber){
	// Check to see if it is even a number 
	if (objNumber && IsNumeric(objNumber)){
		// Check to see if the rounded version is same as non-rounded version
		return(objNumber == Math.round(objNumber));
	} else {
		return(false);
	}
}


// Checks to see if argument passed is a number
function IsNumeric(objNumber){
	if (objNumber){
		try {
			return(!isNaN(objNumber * 1));
		} catch(e) {
			return(false);
		}
	} else {
		return(false);
	}
}


// Checks to see if the given object is of type tag name
function IsObjectOfTagName(objNode, strTagName){
	if (
		objNode &&
		(typeof(objNode) == "object") &&
		(objNode.nodeType == 1) &&
		(objNode.tagName.toLowerCase() == strTagName.toLowerCase())
		){
		return(true);	
	} else {
		return(false);
	}
}


// Checks to see if the given object is of type tag name
// and has the given type attribute
function IsObjectOfTagNameAndType(objNode, strTagName, strType){
	if (
		IsObjectOfTagName(objNode, strTagName) &&
		(objNode.getAttribute("type").toLowerCase() == strType.toLowerCase())
		){
		return(true);
	} else {
		return(false);
	}
}


// Checks to see if an object is a radio box
function IsRadioBox(objRadio){
	return(IsObjectOfTagNameAndType(objRadio, "input", "radio"));
}


// Checks to see if an object is a reset button input
function IsResetButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "reset"));
}


// Checks to see if an object is a select box
function IsSelectBox(objSelect){
	return(IsObjectOfTagName(objSelect, "select"));
}


// Checks to see if an object is a submit button input
function IsSubmitButton(objButton){
	return(IsObjectOfTagNameAndType(objButton, "input", "submit"));
}


// Checks to see if an object is a textarea
function IsTextArea(objTextArea){
	return(IsObjectOfTagName(objTextArea, "textarea"));
}

