// check if a string is empty (i.e. the empty string "" or a combination of spaces, tabs, and control chars)
function is_empty(str) {
    return str.search("^[ \t\n\r]*$") > -1 ? 1 : 0 ;
}

function is_email(str) {
    return str.search("^([a-zA-Z0-9_]|\\-|\\.)+@(([a-zA-Z0-9_]|\\-)+\\.)+[a-zA-Z]{2,4}\$") > -1 ? 1 : 0 ;
}

function is_uint(str) {
    return str.search("^[0-9]+$") > -1 ? 1 : 0 ;
}

// signed: 0 or 1 (true or false) => wether the number can be negative or not
// dec_symbol: if null the number must be an integer else this parameter should be the decimal symbol.
function is_number(str, signed, dec_symbol) {
    var reg_expresion;
    var reg_exp1 = "[0-9]+";
    var reg_exp2 = "[0-9]*";
    if(signed) { reg_exp1 = "-?" + reg_exp1; reg_exp2 = "-?" + reg_exp2; }
    if(!dec_symbol) {
	reg_expresion = reg_exp1;
	return str.search("^"+reg_expresion+"$") > -1 ? 1 : 0 ;
	}
    else {
	var dsym = "["+ dec_symbol +"]";
	reg_exp2 = reg_exp2 + dsym + "[0-9]+";
	var r1 = str.search("^"+reg_exp1+"$") > -1 ? 1 : 0 ;
	var r2 = str.search("^"+reg_exp2+"$") > -1 ? 1 : 0 ;
	return (r1 | r2);
	}
}

function is_hex(str, prefix, sufix) {
    var reg_expresion = "^"+prefix+"[0-9a-fA-F]+"+sufix+"$";
    return str.search(reg_expresion) > -1 ? 1 : 0 ;
}



// *************

// frmObj is form object
// arr_text_box is an array with the textbox names
// return -1 if an error occurs otherwise return 0 (false) if at least one textbox is not empty or 1 if all the textboxes are empty
function textbox_group_is_empty(frmObj, arr_textbox) {
    if(!arr_textbox) return -1; // invalid arguments
    var l = arr_textbox.length;
    if(l<2) return -1; // invalid arguments
    var j=0;
    for(var i=0; i<l; i++) if(!is_empty(frmObj[arr_textbox[i]].value)) j++;
    return !j;
}

function radio_group_is_unchecked(frmObj, radio_name) {
    var radio_arr = frmObj.elements[radio_name];
    var l = radio_arr.length;
    var j=0;
    for(var i=0; i<l; i++) if(radio_arr[i].checked) j++;
    return !j;
}

// ****************