//============================================
//  global java functions
//============================================

//--------------------------------------------
//	check or uncheck all listed checkboxes
//  should use default name for header and items
//--------------------------------------------
function __check_all(form, checkbox_all, checkbox_sel){
	cnt = __get_count(checkbox_sel);
	if(checkbox_all.checked){
		value="ON";
	}
	else{
		value="";
	}
	if(cnt==1){
		checkbox_sel.checked=value;
	}
	else{
		for(i=0; i < cnt; i++){
			checkbox_sel[i].checked=value;
		}	
	}
	return true;		
}

//--------------------------------------------
//	get total items count
//--------------------------------------------
function __get_count(obj){
	var cnt;
	cnt=0;
	if(obj==null){
		cnt=0;
		return cnt;
	}
	cnt=obj.length;
	if(isNaN(cnt)){
		cnt=1;
	}
	return cnt;
}
//--------------------------------------------
//	get total selected checkbox count
//--------------------------------------------
function __get_selected_count(obj){
	var item_count, selected_count
	
	selected_count = 0;
	item_count = __get_count(obj);
	if(item_count == 0){
		return 0;
	}
	
	if(item_count == 1){
		if(obj.checked){
			return 1;
		}
		else{
			return 0;
		}
	}
	for(var i=0; i< item_count; i++){
		if(obj[i].checked){
			selected_count = selected_count + 1;
		}
	}
	return selected_count;
}

function required_field(obj){
	if(obj == null || obj.value.length == 0){
		obj.focus();	
		return false;
	}
	if(has_invalid_char(obj.value))
		return false;
	return true;
}

function required_field_fix_len(obj,fix_length){
	if(obj == null || obj.value.length == 0 || obj.value.length != fix_length){
		obj.focus();	
		return false;
	}
	if(has_invalid_char(obj.value))
		return false;
	return true;
}

function has_invalid_char(str){
	var lt="<";
	var ret = false;
	if(str.length > 0){
		if(str.indexOf(lt) != -1){
			ret = true;
		}
	}
	return ret;
}
function emailValidate(emailAddress) {
    if (emailAddress==null || emailAddress=="")
		return false;
    var rx =/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if(rx.exec(emailAddress)==null)
		return false;
    else
	    return true;
}


//Validates that a string contains only valid integer number.
function validateInteger( strValue ) {
  var objRegExp  = /(^-?\d\d*$)/;
  return objRegExp.test(strValue);
}