function bvaj_send(url,async,meth,user,pass){//send an Ajax request and return the request object
	if (!meth){
		meth=true;
		if(!async){
			async=false;
		}
	}
	if (window.XMLHttpRequest){//std
		xmlhttp=new XMLHttpRequest();
	}else{//IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(meth===true){
		meth='GET';
	}else if(!meth){
		meth='POST'
	}
	xmlhttp.open(meth,url,async,user,pass);
	xmlhttp.send(null);
//	return xmlhttp.responseText;
	return xmlhttp;
}
function bvaj_fill(id,url,async,meth,user,pass){//Ajax fill a DOM id element
//id    - The id of the element being filled
//url   - The URL of the page that will return the new content (name should end with "-aj")
//async - "GET" or "POST" defaults to GET
//meth  - true - synchronous (default), script waits for response
//        false- async, script proceeds immediately and is responsible for monitoring request status
//user  - unused
//pass  - unused
//returns: the URL's output, must be complete new content of the id element, including any HTML tags
	xmlhttp=bvaj_send(url,async,meth,user,pass);
	document.getElementById(id).innerHTML=xmlhttp.responseText;
}
function bv_setfocus(id){
	document.getElementById(id).focus();
}
function allcbs(form,mode){//checks/unchecks/inverts all checkboxes in a specific form
//form	- id of the target form
//mode	- 1: 	check all
//				0:	uncheck all
//				-1:	invert all
//sample attribute call: onclick="allcbs('form1',1)"
	formid=document.getElementById(form);
	for (i = 0; i < formid.elements.length; i++){
		box=formid.elements[i];
		if (box.type == "checkbox"){
			switch (mode){
				case 0:
					if (box.checked==true){
						box.checked=false;
					}
				break;
				case 1:
					if (box.checked==false){
						box.checked=true;
					}
				break;
				case -1:
					box.checked=!box.checked;
				//break
			}
		}
	}
}
function arraytable(tbl){//returns an html table populated from 2D array
//tbl=2d array of rowwise data, row 0 must contain column names
//each table element has an onclick event, called as cellclick(rownum,colnum)
	htbl='<table id="results" border="2"><tr class="bold" id="hdr">'
	ncols=tbl[0].length
	nrows=tbl.length-1
	for(j=0;j<ncols;j++){
		htbl+='<td class="bold" id="h'+j+'" onclick="cellclick(0,'+j+')">'+tbl[0][j]+'</td>'
	}
	for(i=1;i<=nrows;i++){
		htbl+='<tr id="d'+i+'">'
		for(j=0;j<ncols;j++){
			htbl+='<td id="d'+i+'_'+j+'" onclick="cellclick('+i+','+j+','+ncols+')">'+tbl[i][j]+'</td>'
		}//
		htbl+='</tr>'
	}
	htbl+='</table>'
	return(htbl)
}
function cellclick(row,col,ncols){//copy cell value to textarea for editing
	if (row>0){//not in title row
		cellvaltotextarea('d'+row+'_'+col,document.getElementById('cell'))
//		cellvaltotextarea1(row,col,ncols)
	}
}
function cellvaltotextarea(tablecellid,textareaobj){//load text of cell with unique id into textarea
//The textarea text node seems not to exist (JS bug?) if there is no text. Workaround: if no textarea child, create a text node with null text
//This technique assumes each <td> cell in page has a unique id. 
	if (!textareaobj.firstChild){//if no textarea text then textnode nonexistent (DOM bug?)
		newText = document.createTextNode("")
		textareaobj.appendChild(newText)
	}
	textareaobj.firstChild.data=document.getElementById(tablecellid).firstChild.data;//copy text
}
function cellvaltotextarea1(row,col,ncols){//test-load cell text into textarea using direct "name" attribute refs
//Assumes there is only 1 table in doc and accesses cell by calculating NodeList offset
	elt=document.getElementsByTagName('td')
	n=row*ncols+col
	document.query.cell.value=elt[n].childNodes[0].nodeValue
//	window.document.query.cell.value=elt[n].childNodes[0].nodeValue
}
function light(evt) {//tints a rectangle that is the target of an event
	var rect = evt.target
	rect.setAttribute("style","opacity:.4");
}
function unlight(evt) {//untints a rectangle that is the target of an event
	var rect = evt.target
	rect.setAttribute("style","opacity:.001")
}
function goback(){//go back to previous page
	history.back()
}
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++){
		x.src=x.oSrc
	}
}
function MM_preloadImages(){ //v3.0
	var d=document
	if (d.images){
		if (!d.MM_p){
			d.MM_p=new Array()
		}
		var i,j=d.MM_p.length
		var a=MM_preloadImages.arguments
		for (i=0; i<a.length; i++){
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image
				d.MM_p[j++].src=a[i]
			}
		}
	}
}
function MM_findObj(n, d){ //v3.0
	var p,i,x
	if (!d){
		d=document
	}
	if ((p=n.indexOf("?"))>0&&parent.frames.length){
		d=parent.frames[n.substring(p+1)].document
		n=n.substring(0,p)
	}
	if (!(x=d[n])&&d.all){
		x=d.all[n]
	}
	for (i=0;!x&&i<d.forms.length;i++){
		x=d.forms[i][n]
	}
  for (i=0;!x&&d.layers&&i<d.layers.length;i++){
		x=MM_findObj(n,d.layers[i].document)
	}
	return x;
}
function MM_swapImage(){ //v3.0
	var i,j=0
	var x,a=MM_swapImage.arguments
	document.MM_sr=new Array
	for (i=0;i<(a.length-2);i+=3){
		if ((x=MM_findObj(a[i]))!=null){
			document.MM_sr[j++]=x
			if (!x.oSrc){
				x.oSrc=x.src
			}
			x.src=a[i+2]
		}
	}
}
function jstest(t){
	alert(t)
}

