function lm(msg) {
	//display loading message
	var lid = document.getElementById('load_msg');
	//lid.innerHTML = '<span class="pmsg"><img src="/genexpdb/inc/images/loading.gif" alt=""><font color=\"red\">'+msg+'</font> ... please wait</span>';
	lid.innerHTML = '<span class="pmsg"><img src="/genexpdb/inc/images/loading.gif" alt="">  <font color=\"red\">'+msg+'</font> ...</span>';
	lid.className = 'showrec';
}
function hm() {
	//hide loading message
	var lid = document.getElementById('load_msg');
	lid.className = 'hidden';
}
function sh(id) {
	//show/hide the div
	var element = document.getElementById(id);
	if (element.className == 'hidden') {
		element.className = 'showrec';
	}else{
		element.className = 'hidden';
	}
}
function expand(id) {
	// (+/-) 
	var element = document.getElementById(id);
	var sign = document.getElementById('sign'+id);
	if (element.className == 'hidden') {
		sign.src = "/genexpdb/inc/images/minus.gif";
		sign.title = "Collapse";
		element.className = 'showrec';
	}else{
		sign.src = "/genexpdb/inc/images/plus.gif";
		sign.title = "Expand";
		element.className = 'hidden';
	}
}
function hmo(id,gene,lt,ratio,std,acc,title,ename) {
	//show hmap mouseover info
	if (ratio<0){
		title = '<b>OUID: </b>'+id+'<br><b>Accession:</b> '+acc+'<br><b>Ratio:</b> <font color=red>'+ratio+'</font>  &nbsp;&nbsp; <b>StdDev:</b> '+std+'<br><b>Title:</b> '+title+'<br><b>ExpName:</b> '+ename;
	}else{
		title = '<b>OUID: </b>'+id+'<br><b>Accession:</b> '+acc+'<br><b>Ratio:</b> '+ratio+'  &nbsp;&nbsp; <b>StdDev:</b> '+std+'<br><b>Title:</b> '+title+'<br><b>ExpName:</b> '+ename;
	}
	overlib(title, WIDTH, 450);
}
function expinfo(type,id) {
	//return exp Info via ajax call
	rec = document.getElementById(id);
	esign = document.getElementById('esign'+id);
	if (rec.className == 'hidden') {
		if (type == 'eset' || type == 'dleset') {
			esign.src = "/genexpdb/inc/images/minus.gif";
			sendRequest('/genexpdb/expInfo.php', 'type='+type+'&expmID='+id);
		}
		lm("Loading");
		sendRequest('/genexpdb/expInfo.php', 'type='+type+'&expmID='+id);
		rec.className = 'showrec';
	}else{
		esign.src = "/genexpdb/inc/images/plus.gif";
		rec.className = 'hidden';
	}
}
function plotdata(id) {
	//return plot data via ajax call
	rec = document.getElementById('pd'+id);
	lm("Loading");
	sendRequest('/genexpdb/plotData.php', 'expmID='+id);
	rec.className = 'showrec';
}
function mfun() {
	//ajax call for multifun
	rec = document.getElementById('mfun');
	lm("Loading");
	sendRequest('/genexpdb/mfun.php', '');
	rec.className = 'showrec';
}
function replot(expmID, ltag) {
	lm('Loading');
	location.href='http://genexpdb.ou.edu/v2?rePlot=1&query='+ltag+'&expmID='+expmID;
}
function ckdopt(radioObj, expmID, ltag, accession) {
	if(!radioObj)	return "";
	for(var i = 0; i < radioObj.length; i++) {
		if(radioObj[i].checked) {
			if(radioObj[i].value == 'plot') {
				//ajax call for heatmap plot
				lm("Creating Plot");
				sendRequest('/v2', 'callPlot=1&id='+expmID+'&selGene='+ltag);
				rec = document.getElementById('hmplot'+ltag);
				if (rec.className == 'hidden'){
					rec.innerHTML = '';
				}
				rec.className = 'showrec';
			}else if(radioObj[i].value == 'ering') {
				window.open('http://genexpdb.ou.edu/ering/index.php?sampID='+expmID);
			}else if(radioObj[i].value == 'jbrowse') {
				window.open('http://genexpdb.ou.edu/genexpdb/jbrowse/index.php?acc='+accession+'_'+expmID);
			}
		}
	}
}
function hmplot(pubexpmID, selGene, nsd, dispOpt) {
	if (dispOpt == 0) {
		//ajax call for heatmap plot
		lm("Creating Plot");
		sendRequest('/genexpdb/hmplot.php', 'id='+pubexpmID+'&selGene='+selGene+'&nsd='+nsd);
		rec = document.getElementById('hmplot'+selGene);
		if (rec.className == 'hidden'){
			rec.innerHTML = '';
		}
		rec.className = 'showrec';
	}else if (dispOpt == 1) {
		//Ering
		window.open('http://genexpdb.ou.edu/ering/index.php?sampID='+pubexpmID);
	}
}
function xxxxxhmplot(pubexpmID, selGene, nsd) {
	//ajax call for heatmap plot
	lm("Creating Plot");
	sendRequest('/genexpdb/hmplot.php', 'id='+pubexpmID+'&selGene='+selGene+'&nsd='+nsd);
	rec = document.getElementById('hmplot'+selGene);
	if (rec.className == 'hidden'){
		rec.innerHTML = '';
	}
	rec.className = 'showrec';
}
function selUnselAll(elem) {
    var frm = elem.form, z = 0;
	for(i=0; i<frm.length;i++) {
    	if(frm[i].type == 'checkbox' && frm[i].name != 'checkall') {
	  		frm[i].checked = elem.checked;
	  	}
	}
}
//ajax functions
var xmlhttp;
function sendRequest(url,parms) {
	xmlhttp=null;
	if (window.XMLHttpRequest){
 		xmlhttp=new XMLHttpRequest();
 	}else if (window.ActiveXObject){
  		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
 	}else if (window.ActiveXObject){
  		xmlhttp=new ActiveXObject("Msxml3.XMLHTTP");
 	}else if (window.ActiveXObject){
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
  	if (xmlhttp!=null){
  		xmlhttp.onreadystatechange=stateChange;
		xmlhttp.open('POST', url, true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(parms);
	}else{
  		alert("Your browser does not support XMLHTTP.");
  	}
}
function stateChange(){
	if (xmlhttp.readyState==4){
  		if (xmlhttp.status==200){
    		hm();
			rec.innerHTML = '';
			rec.innerHTML = xmlhttp.responseText;
   		}else{
    		alert("Problem retrieving data"+xmlhttp.statusText);
    	}
  	}
}
