function calc_mw(sSeq)
{	sSeq = clean_seq(sSeq);
	var aWts = new Array ( 711, 0, 1031, 1151, 1291, 1472, 570, 1371, 1132, 0, 1282, 1132, 1312,
	                       1141, 0, 971, 1281, 1562, 871, 1011, 0, 991, 1862, 0, 1632, 0	);
	var aCnts = new Array (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
	var nMW = 180;
	var iA = 'A'.charCodeAt(0);
	for (var idx=0; idx < sSeq.length; ++idx) {	++aCnts[sSeq.charCodeAt(idx) - iA];}
	for (idx=0; idx < 26; ++idx) {	nMW += aCnts[idx] * aWts[idx];}
	return nMW / 10;
}
function clean_seq(sSeq)
{	return sSeq.toUpperCase().replace(/[^A-Z]/g, "");
}
function trim_space(obj)
{ obj.value = obj.value.replace(/^\s*(.*?)\s*$/, "$1");
  return true;
}
function date_fmt(obj)
{ if(obj.value.match(/^\s*$/)) return true;
	var dt = new Date(obj.value.replace(/\-/g, ' '));
	var aMon = new Array ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
	var iDay = dt.getDate();
	if(iDay.toString() == 'NaN')
	{	alert('Unknown date format.');
		return false;
	}
	var iYear = dt.getFullYear();
	if(iYear < 1980) iYear += 100;
	obj.value = (iDay < 10 ? '0':'') + iDay.toString() + ' ' + aMon[dt.getMonth()] + ' ' + iYear.toString();
	return true;
}
function date_today(obj)
{	var dt = new Date();
	obj.value = dt.toDateString();
	return date_fmt(obj);
}
function check_int(obj)
{	if(obj.value.match(/^\s*$/)) return true;
	if(obj.value.match(/^\s*\-?\d+\s*$/)) return true;
	alert("'" + obj.value + "' is not an integer.");
	return false;
}
function check_float(obj)
{	if(obj.value.match(/^\s*$/)) return true;
	if(obj.value.match(/^\s*\-?(\.\d+|\d+\.?\d*)\s*$/)) return true;
	alert("'" + obj.value + "' is not a number.");
	return false;
}
function check_seq(obj)
{	obj.value = clean_seq(obj.value); 
	return true;
}
function calc_parent_barcode(vec_id, vec_type, vec_abbr, gene_form, bac_sel)
{	if(!vec_id || !vec_type || !vec_abbr || !gene_form || !bac_sel) return '';
	var bc = vec_id.substring(0,3).toUpperCase() + vec_type.substring(0,1).toUpperCase() +
			vec_abbr.substring(0,6).toUpperCase() + gene_form.substring(0,1).toUpperCase() +
			bac_sel.substring(0,1).toUpperCase();
	return bc.length == 12 ? bc : '';
}
function upper(obj)
{	obj.value = obj.value.toUpperCase();
	return true;
}
function nav_orange(linkname)
{  	if(document.getElementById == null) return;
	var lnk = document.getElementById('nav_'+linkname);
	if(lnk != null) lnk.className= "orangelink";
}
function submit_rq(obj)
{	obj.form.elements['rq'].value = obj.name;
	if(obj.name.match(/^delete/))
	{	if(!confirm('Delete? Are you sure?')) return false;
	}
	obj.form.submit();
	return true;
}
function enter_search(p_btn, p_ev)
{	var ky = (window.event != null) ? window.event.keyCode : p_ev.which;
	if(ky == 13) 
	{	if(window.event != null) window.event.returnValue = false;
		submit_rq(p_btn);
	}
	return true;
}
function switch_span(objid1, objid2)
{	if(document.getElementById == null) return;
	if(document.getSelection && document.getSelection()) return;
	if(document.selection && document.selection.createRange && document.selection.createRange().text) return;
	var obj1 = document.getElementById(objid1);
	var obj2 = document.getElementById(objid2);
	if(obj1 != null)
	{	obj1.style.display = obj1.style.display == 'none' ? '' : 'none';
	}
	if(obj2 != null)
	{	obj2.style.display = obj2.style.display == 'none' ? '' : 'none';
	}
}
function toggle_display(objid)
{	if(document.getElementById == null) return;
	var obj1 = document.getElementById(objid);
	if(obj1 != null)
	{	obj1.style.display = obj1.style.display == 'none' ? '' : 'none';
	}
}
function char_index(str)
{	if(str == null || str.length == 0) { return 0; }
	return str.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 1;
}
function toggle_all(obj, cb_name)
{	var f = obj.form;
	var cb = f.elements[cb_name];
	if(cb.length)
	{	for(idx = 0; idx < cb.length; ++idx)
		{	cb[idx].checked = cb[idx].checked ? false : true;
		}
	}
	else
	{	cb.checked = cb.checked ? false : true;
	}
	return true;
}
function select_to_text(p_sel, p_textbox)
{	var tb = p_sel.form.elements[p_textbox];
	if(!tb) return;
	tb.value = p_sel.value;
	tb.focus();
}
function onchange_location(obj)
{	if(obj.value.match(/^\s*$/)) return true;
	var f = obj.form;
	var loc = obj.value.replace(/^\s*(\S*)\s*$/,"$1").toUpperCase();
	obj.value = loc;
	if(!loc.match(/^[A-Z]\d\d\d\-[A-I\d]\d\d?$/) && !loc.match(/^[A-Z\d]\d\d\d\d\d$/))
	{	alert('Note: the location is not in one of the standard N001-01, N001-A1, 000001 or R00001 forms.');
	}
	return true;
}
function date_time_fmt(obj)
{ if(obj.value.match(/^\s*$/)) return true;
	var dt = new Date(obj.value.replace(/\-/g, ' '));
	var aMon = new Array ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
	var iDay = dt.getDate();
	if(iDay.toString() == 'NaN')
	{	alert('Unknown date format.');
		return false;
	}
	var iYear = dt.getFullYear();
	if(iYear < 1980) iYear += 100;
	obj.value = (iDay < 10 ? '0':'') + iDay.toString() + '-' + aMon[dt.getMonth()] + '-' + iYear.toString() + 
              ' ' + dt.getHours() + ':' + dt.getMinutes();
	return true;
}
function check_scientific(obj)
{	if(obj.value.match(/^\s*$/)) return true;
	if(obj.value.match(/^\s*\-?(\.\d+|\d+\.?\d*)((E|e)\-?\d+)?\s*$/)) return true;
	alert("'" + obj.value + "' is not a number.");
	return false;
}

