
function toggleHighlight() {

	//don't mess with non-semantic
	//if(this.className.indexOf('rowHighlight')!=-1) return false;

	if(this.className.indexOf('highlight')==-1) this.className += ' highlight';
	else this.className = this.className.replace(' highlight','');
}

function toggleCheckbox() {
	toggleRowStyle(this,this.checked);
}

function toggleRowStyle(tr,checked) {
	if (tr.parentNode) { while (tr.nodeName != 'TR') { tr = tr.parentNode; } }
	else if (tr.parentElement) { while (tr.nodeName != 'TR') { tr = tr.parentElement; } }
	else return false;
	if(checked==true) tr.className += ' selected';
	else tr.className = tr.className.replace(' selected','');
}

function toggleAllCheckbox(cb,id) {
	var e = $('atForm_'+id).elements;
	for(var i=0; i < e.length; i++) {
		if(e[i].name == 'item_list[]') {
			e[i].checked = cb.checked;
			toggleRowStyle(e[i],e[i].checked)
		}
	}
}

function confirm_checked(id,reaction_value,message,nomessage) {
	var form = $('atForm_'+id);
	var e = form.elements;
	var num = 0;
	for(var i=0; i < e.length; i++) {
		if(e[i].name == 'item_list[]' && e[i].checked == true) num++;
	}
	if(num == 0) {
		alert(nomessage);
	} else {
		if (message!='' && message!=null) {
			var you_sure = message+ '\nClick OK to continue, Cancel to abort...';
			if(confirm(you_sure)) {
				form.reaction.value=reaction_value;
				form.submit();
			} else {
				//do not return false in this case. NS will go to a pages that says false
			}
		} else {
			form.reaction.value=reaction_value;
			form.submit();
		}
	}
}
function confirm_checked_(reaction_value) {
	confirm_checked('',reaction_value,'','Please select some items.');
}

function update_order(id,newReaction) {
	var form = $('atForm_'+id);
	form['reaction'].value=newReaction;
	form.submit();
}


addLoadEvent(function () {
	//check for a semantic table
	if(getElementsByClass('jSemantic autoTable',document,'input')) return false;

	cbs = getElementsByClass('atCheckbox',document,'input');
	for (e in cbs) {
		addEvent( cbs[e], 'click', toggleCheckbox );
	}

	trTags = getElementsByClass('rowA',document,'tr');
	for (e in trTags) {
		addEvent( trTags[e], 'mouseover', toggleHighlight );
		addEvent( trTags[e], 'mouseout', toggleHighlight );
	}
	trTags = getElementsByClass('rowB',document,'tr');
	for (e in trTags) {
		addEvent( trTags[e], 'mouseover', toggleHighlight );
		addEvent( trTags[e], 'mouseout', toggleHighlight );
	}
});