/*
================================================================================
@File Name: js_form_lib.js
@Author: Fabio Serra AKA Faser - faser@faser.net
@Last Update: 12/07/01
@Version: 0.5
@Description: Base library for Form validation
@Revision History:
================================================================================
*/

/**
@Function: verifyCheckedBox
@Author: Fabio Serra AKA Faser - faser@faser.net
@Input: obj (The name of the html form field fully qualified); 
@Output: True (one box has been checked at least) | False (no checkbox has been 
checked)
@Date: 12/07/01
@Description: When there are more checkbox with the same name, control if one
checkbox has been checked at least.
*/

function verifyCheckedBox(obj) {
	if(obj.value && !obj.length) {
		if(obj.checked) {
			return true;
		}
	}
	for(var i=0; i < obj.length; i++) {
		if(obj[i].checked) {
			return true;
		} 
	}
	
	return false;
}


/**
@Function:checkLen 
@Author: Fabio Serra AKA Faser - faser@faser.net
@Input: Obj: Object (form+field);  minLen; maxLen
@Output: True | False 
@Date: 03/09/01
@Description: verify the string len
*/

// check string lenght
function checkLen(obj,minLen,maxLen) {
	len=obj.value.length;
	if (len<minLen || len > maxLen ) {
		return false;
	}
	return true;
}


function isEmail(formobj,inputobj,valueobj) {
    if (valueobj.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
} 


function tornaFocus (formobj,inputobj,valueobj,message) {
	alert(message);
	inputobj.focus();
 	return false;
}