function setValue( obj, newValue, formIndex ){
	var loForm;
	if ( formIndex > 0 ) {
		loForm = document.forms[formIndex];
	} else {
		loForm = document.forms[0];
	}
	if( typeof(obj) == 'object' ) {
    obj.value = newValue;
	} else {
		for ( var i=0; i<loForm.length; i++) {
			if ( loForm.elements[i].name == obj ) {
				loForm.elements[i].value = newValue;
				/*				alert( 'found '+obj+' = '+loForm.elements[i].value ); */
			}
		}
	}
	return loForm;
}

function submitForm( obj, newValue, formIndex ){
	var loForm;
	loForm = setValue( obj, newValue, formIndex );
	loForm.submit();    
}

function deleteSelected( name, ptrnConfirm, formIndex, msgNothing ) {
	var loForm;
	var ind = -1;
	if ( formIndex > 0 ) {
		loForm = document.forms[formIndex];
	} else {
		loForm = document.forms[0];
	}
	var count=0;
	for ( var i=0; i<loForm.length; i++) {
		var fieldName = loForm.elements[i].name;
		var ind = fieldName.indexOf( '[' );
		if( ind != -1){
			/*if (fieldName.charAt(ind+1)!=']') 
			{*/
				fieldName = fieldName.substr(0,ind);
			/*}*/
		}
		
		if ( fieldName == name ) {
			
			if ( loForm.elements[i].checked )
				count++;
		} 
	}
	
	if( count ) {
		if( ptrnConfirm ) {
			var msgConfirm = ptrnConfirm.replace( /%d/, count);
			if ( confirm( msgConfirm ) ) {
				for ( var i=0; i<loForm.length; i++) {
					if (loForm.elements[i].name == 'action') {
						loForm.elements[i].value = 'delete';
					}
				}
				loForm.submit();
			}
		} else {
			loForm.submit();
		}
	} else {
		if( msgNothing ){
			alert( msgNothing );
		}
	}
}

function checkedAll( name, checked, formIndex){
	var loForm;
	if ( formIndex > 0 ) {
		loForm = document.forms[formIndex];
	} else {
		loForm = document.forms[0];
	}
	var count=0;
	for ( var i=0; i<loForm.length; i++) {
		var fieldName = loForm.elements[i].name;
		var ind = fieldName.indexOf( '[' );
		if( ind != -1){
			fieldName = fieldName.substr(0,ind);
		}
		if ( fieldName == name ) {
			if( !loForm.elements[i].disabled ){
				loForm.elements[i].checked  = checked;
			}
		}
	}
}

function toggleAll( name, disabled, formIndex){
	var loForm;
	if ( formIndex > 0 ) {
		loForm = document.forms[formIndex];
	} else {
		loForm = document.forms[0];
	}
	var count=0;
	for ( var i=0; i<loForm.length; i++) {
		var fieldName = loForm.elements[i].name;
		var ind = fieldName.indexOf( '[' );
		if( ind != -1){
			fieldName = fieldName.substr(0,ind);
		}
		if ( fieldName == name ) {
			loForm.elements[i].disabled = disabled;
		}
	}
}

function toggleItem( name, disabled, formIndex){
	var loForm;
	if ( formIndex > 0 ) {
		loForm = document.forms[formIndex];
	} else {
		loForm = document.forms[0];
	}
	var count=0;
	for ( var i=0; i<loForm.length; i++) {
		if ( loForm.elements[i].name == name ) {
			loForm.elements[i].disabled = disabled;
		}
	}
}

function setAction( val, action1, action2 ){
	var loForm = this.form;
	switch( val ){
	case 1:
		loForm.action = action1;
		break;
	case 2:
		loForm.action = action2;
	}
}

function displayDiv( id, dspl ){
	var div = document.getElementById(id);

	if(div){
		if(dspl){
			div.style.display = '';
		}else{
			div.style.display = 'none';
		}
	}else{
		//		alert(id+' : '+div);
	}
}
