 
/* ===========================================================================
 *
 * $Id: pubchem.js 173299 2009-10-15 19:31:11Z jiazhang $
 * ===========================================================================
 *
 *                            PUBLIC DOMAIN NOTICE
 *               National Center for Biotechnology Information
 *
 *  This software/database is a "United States Government Work" under the
 *  terms of the United States Copyright Act.  It was written as part of
 *  the author's official duties as a United States Government employee and
 *  thus cannot be copyrighted.  This software/database is freely available
 *  to the public for use. The National Library of Medicine and the U.S.
 *  Government have not placed any restriction on its use or reproduction.
 *
 *  Although all reasonable efforts have been taken to ensure the accuracy
 *  and reliability of the software and data, the NLM and the U.S.
 *  Government do not and cannot warrant the performance or results that
 *  may be obtained by using this software or data. The NLM and the U.S.
 *  Government disclaim all warranties, express or implied, including
 *  warranties of performance, merchantability or fitness for any particular
 *  purpose.
 *
 *  Please cite the author in any work or product based on this material.
 *
 * ===========================================================================
 *
 * Author:  Jian Zhang
 *
 *    -- 2004 12 10
 * ===========================================================================
 */


// ========= browser detect ==========

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring, place;

if (BrowserDetect('msie')) {
	browser = "Internet Explorer";
} else { browser = "Other"; }

function BrowserDetect(string){
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

//========= string handle ============
// split long string to show correctly in browsers except IE
function LongStringHandler(astr, bint){
var k, i; 
var cstr = "";
	if ((astr.length <= bint) || (BrowserDetect('msie'))){
		document.write ( astr + '<br>' );
	} else {
		for ( i=0; i <= astr.length; i=i+bint) {
			cstr = cstr + astr.substr(i, bint) + '<br>';
		}
	//return cstr;
	document.write ( cstr );
	}
}


// ========== /index.html == submit form handler
function SubmitIndexForm() {
 	if (document.pcform.term.value == "") {
     	alert ("Please provide a query !");
  	} else {
  		document.forms["pcform"].submit();
  	}
}

function pcformSetFocus() {
	document.pcform.term.focus();
	document.pcform.term.select();
	// for survey use -- blocked on 20090608
	//if (browser=="Other")
	//{
	//	document.getElementById('svie').style.display='none';
	//	document.getElementById('svother').style.display='';
	//} else {
	//	document.getElementById('svie').style.display='';
	//	document.getElementById('svother').style.display='none';
	//}
}




// The following functions are used for pubchem subatance image browser
// by JZ 2005-07-21
function prev0() {
 	var pcount = document.frmbr.ppcount.value;
	document.frmbr.currentindex.value = 1;
	document.forms["frmbr"].submit();
}
function prev1() {
 	var pcount = document.frmbr.ppcount.value;
	var tmppcount = document.frmbr.currentindex.value - pcount;
	if (tmppcount <1)
	{
		tmppcount = 1;
	}
	document.frmbr.currentindex.value = tmppcount;
	document.forms["frmbr"].submit();
}
function next0() {
 	var pcount = document.frmbr.ppcount.value;
	document.frmbr.currentindex.value = document.frmbr.recordcount.value;
	document.forms["frmbr"].submit();
}
function next1() {
 	var pcount = document.frmbr.ppcount.value;
	var tmppcount = document.frmbr.currentindex.value - (-pcount);
	if (tmppcount > document.frmbr.recordcount.value)
	{
		tmppcount = document.frmbr.recordcount.value;
	}
	document.frmbr.currentindex.value = tmppcount;
	document.forms["frmbr"].submit();
}
function pcbatgoto() {
 	var pcount = document.frmbr.ppcount.value;
	var tmppcounta = document.frmbr.gotoindex.value;
	var recordcount = document.frmbr.recordcount.value
	if ( (tmppcounta-recordcount) >0 )
	{
		tmppcounta = document.frmbr.recordcount.value;
	}
	if (tmppcounta < 1)
	{
		tmppcounta = 1;
	}

	document.frmbr.currentindex.value = tmppcounta;
	document.forms["frmbr"].submit();
}

// to display/hide page elements
// usage: zShow_hide('elementId',...)
// JZ 2005-10-12
function zShow_Hide()
{
	var hidden = "hidden";
	var visible = "visible";
	var none = "none";
	var argcnt = (arguments.length == 3 ) ? 3 : 2;
	
	for ( var i=0; i < argcnt; i++ ) {
		var gobj = document.getElementById(arguments[i]).style;
		if (gobj.display != "none") {
			gobj.display = none;
		} else if (gobj.display == none) {
			gobj.display = "";
			if (i==3)
			{
				gobj.src = "";
			}
		}
	}
	if ( argcnt == 2)
	{
		for ( var i=parseInt(arguments[4]); i < parseInt(arguments[3]); i++ ) {
			var gobj = document.getElementById(arguments[2]).rows[i].style;
			if (gobj.display != "none") {
				gobj.display = none;
			} else if (gobj.display == none) {
				gobj.display = "";
			}
		}
	}
}

// show and hide
function zSH(s, id)
{

	var gobj = document.getElementById(id);

	var e=window.event;//IE:Moz
	var x=0;
	var y=0;
    //if (!e) var e = window.event; 
    if (e.pageX || e.pageY) 
    { 
        x = e.pageX; 
        y = e.pageY; 
    } 
    else if (e.clientX || e.clientY) 
    { 
        x = e.clientX; 
        y = e.clientY; 
    } 

//alert( 'x:' + x );
	// show
	if (s=='s')
	{
		gobj.style.display = "";
		gobj.style.left = x-240;
		gobj.style.top = y-60;
		//gobj.innerText = text;
	}
	if (s=='sa')
	{
		gobj.style.display = "";
		gobj.style.left = x-640;
		gobj.style.top = y-80;
		//gobj.innerText = text;
	}
	// hide
	if (s=='h') 
	{
		gobj.style.display = "none";
	}
}



//position: absolute; width: 253px; height: 43px; z-index: 1; left: 399px; top: 45px


// to make the div height short or longer
function extb(a, b, divid, height)
{
	document.getElementById(a).style.display ='none'; 
	document.getElementById(b).style.display ='';
	document.getElementById(divid).style.height = height; 
}

function othandler(n)
{
	var disi, dist;
	if (document.qf.ochim.checked)
		disi = '';
	else
		disi = 'none';

	if (document.qf.ochtx.checked)
		dist = '';
	else
		dist = 'none';
	
	for (var i=0; i<n ; i++ )
	{
		var iid = "oim" + i;
		var xi = document.getElementById( iid );
		xi.style.display = disi;

		var oid = "otx" + i;
		var xt = document.getElementById( oid );
		xt.style.display = dist;
	}
}


// hide and show div/span by Id
function hs(h,s,g,d)
{
	document.getElementById(h).style.display ='none'; 
	document.getElementById(s).style.display ='';
	document.getElementById(g).style.backgroundColor ='#dddddd'; 
	document.getElementById(d).style.backgroundColor ='#666666';
}

// hide and show div/span by Id
function hs2(h,s)
{
	document.getElementById(h).style.display ='none'; 
	document.getElementById(s).style.display ='';
}

// to check/uncheck all checkbox in a form
// c1: checkbox to be ckecked/unchecked
// c2: checkbox to control others
// i1: start index
// i2: end index
//JZ 2005-10-14
function zCheckUncheckAll(c1, c2, i1, i2) {
	if ( !i1 )
		i1 = 0;
	if ( !i2 && c1.length)
		i2 = c1.length;
	if (i2 > c1.length )
		i2 = c1.length;
	
	if ( ! c1.length ) {
		c1.checked = c2.checked ;
	} else {
		for (i = i1; i < i2; i++) {
			c1[i].checked = c2.checked ;
		}
	}
}


function AssayQueryHandler( qstr ) {
	var selectcid = 0; // used to control CID select fields
	var selectsid = 0;
	var selectaid = 0;

	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}

		if (document.qf.qb ) 
		{
			document.qf.q.value = document.qf.qb.value;
		}


	if ( qstr == "download") {
		document.qf.p.value = qstr;
	} else if ( qstr == "SID") {
		document.qf.q.value = "t";
		document.qf.dbh.value = "pcsubstance";
		document.qf.addhistory.value = "SID";
	} else if ( qstr == "CID") {
		document.qf.q.value = "t";
		document.qf.dbh.value = "pcsubstance";
		document.qf.addhistory.value = "CID";
	}else if ( qstr == "addhistory") {
		document.qf.q.value = "t";
		document.qf.dbh.value = "pcsubstance";
		document.qf.addhistory.value = "t";
	} else if ( qstr == "getquery" || qstr == "gocids" || qstr == "gosids" || qstr == "godata") {
		//document.qf.cacheid.value = "";
		if ( qstr != "gosids" )
		{
			if (document.qf.pccompoundquery_key)
			{
				if ( document.qf.pccompoundquery_key.value != '' )
					selectcid ++;
			}
			if (document.qf.CIDlist)
			{
				if ( document.qf.CIDlist.value != '' )
					selectcid ++;
			}
			if (document.qf.CIDfile)
			{
				if ( document.qf.CIDfile.value != '' )
					selectcid ++;
			}
			if (document.qf.CIDterm)
			{
				if ( document.qf.CIDterm.value != '' )
					selectcid ++;
			}

			document.qf.q.value = "cids";
		}
		
		if ( qstr != "gocids" )
		{
			if (document.qf.pcsubstancequery_key)
			{
				if ( document.qf.pcsubstancequery_key.value != '' )
					selectsid ++;
			}
			if (document.qf.SIDlist)
			{
				if ( document.qf.SIDlist.value != '' )
					selectsid ++;
			}
			if (document.qf.SIDfile)
			{
				if ( document.qf.SIDfile.value != '' )
					selectsid ++;
			}
			if (document.qf.SIDterm)
			{
				if ( document.qf.SIDterm.value != '' )
					selectsid ++;
			}

			document.qf.q.value = "sids";
		}

		// aid control
			if (document.qf.pcassayquery_key)
			{
				if ( document.qf.pcassayquery_key.value != '' )
					selectaid ++;
			}
			if ( document.qf.AIDlist )
			{
				if ( document.qf.AIDlist.value != '' )
					selectaid ++;
			}
			if ( document.qf.AIDfile ) 
			{	
				if ( document.qf.AIDfile.value != '' )
					selectaid ++;
			}

		if ( qstr == "getquery" )
		{
			if (document.qf.exptype)
			{
				document.qf.exptype.value = '';
			}
			document.qf.q.value = "qr";
		}
		if ( qstr == "godata" )
		{
			if (document.qf.exptype)
			{
				document.qf.exptype.value = '';
			}
			document.qf.q.value = "sidsr";
		}
	} else if ( qstr == "directshow") { // direct show
		document.qf.q.value = 'qr';
	} else if ( qstr == "select") { // go select page
		document.qf.q.value = 't';
	} else if ( qstr == "summary") { // back to summary page
		document.qf.q.value = '';
	} else if ( qstr == "reshow") {
//alert( document.qf.q.value );
		if (document.qf.pcount)
		{
			document.qf.pcount.value = 1;
		}
		document.qf.acount.value = 1;
		document.qf.exptype.value = '';
		document.qf.assaysort.value = "";
		document.qf.cacheid.value = "";
		//document.qf.q.value = "qr";
	} else if ( qstr == "back2q") {
		if (document.qf.q.value == 'r' || document.qf.q.value == 'graph' ||
		    document.qf.q.value == 'sidsr' || document.qf.q.value == 'cidsr' )
		{
			document.qf.exptype.value = '';
		}
		document.qf.q.value = "t";
	} else if ( qstr == "plot") {
		document.qf.q.value = 'p';
		document.qf.exptype.value = '';
		//document.qf.q.value = "qr";
		//document.qf.exptype.value = document.qf.optResultView.value;
	} else if ( qstr == "addassay") {
		document.qf.q.value = "t";
		if (document.qf.version)
		{
			//document.qf.version.value = "";
		}
	} else if ( qstr == "resultdownload") {
		//document.qf.q.value = "";
		document.qf.exptype.value = document.qf.rexp.value;
		if (document.qf.rexp.value !="asn1" && document.qf.rexp.value !="xml")
		{
			//document.qf.cacheid.value = "";
		}
	} else if ( qstr == "bioactivitycsv" || qstr == "alldata" || qstr == "asn1" || qstr == "asnt" || qstr == "asnb"  || qstr == "pagedata" || qstr == "xml" || qstr == "pagedatadepo" ) {
		//document.qf.q.value = "";
		document.qf.exptype.value = qstr;
		if (qstr !="asn1" && qstr !="xml")
		{
			//document.qf.cacheid.value = "";
		}	
	} else if ( qstr == "structuredownload") {
		//document.q.value = "";
		document.qf.exptype.value = document.qf.strucexp.value;
		document.qf.cacheid.value = "";
	//} else if ( qstr == "dt2_activity" || qstr == "dt2_heat") {
	} else if ( qstr == "dt2_activity" ) {
		document.qf.q.value = "sids";
		document.qf.exptype.value = '';
		document.qf.cacheid.value = '';
		//document.qf.q.value = "r";
		//document.qf.exptype.value = qstr;
		//document.qf.cacheid.value = "";
	} else if ( qstr == "cids" ) {
		document.qf.q.value = "cids";
	} else if ( qstr == "cheat" ) {
		document.qf.exptype.value = "cheat";
		document.qf.q.value = "qr";
	} else if ( qstr == "heat" || qstr == "aidsen" || qstr == "activity_data" || qstr == "activity_heat" || qstr == "activity_panel" ) {
		document.qf.q.value = qstr;
	} else if ( qstr == "csel" || qstr == "call" || qstr == "cadd" 
		|| qstr == "ctested" || qstr == "aadd" || qstr == "atested" 
		|| qstr == "cany" || qstr == "asel" || qstr == "aact" || qstr == "csim" ) {
		document.qf.r.value = qstr;
		//document.qf.q.value = "cids";
	//} else if ( qstr == "sselect_tested" || qstr == "aselect_tested" || qstr == "sselect_act" || qstr == "sadd_act" || qstr == "sadd_sim" 
	//	|| qstr == "sadd_tested"  || qstr == "sadd_same" || qstr == "aadd_act" || qstr == "aadd_tested" 
	//	|| qstr == "aselect_act" || qstr=="aselect" ) {
	} else if ( qstr.substring(1,8) == "select_" || qstr.substring(1,5) == "add_" || qstr=="aselect" ) {
		if (document.qf.q.value == "aids")
		{
			document.qf.q.value = "cids";
		}
		document.qf.r.value = qstr;
		//document.qf.q.value = "cids";
	} else if ( qstr == "nbrsummary" ||  qstr == "nbranalysis" || qstr == "nbrheatact" ||  qstr == "nbrclusteract") {
		document.qf.q.value = qstr;
		//document.qf.r.value = "nbrsummary";
	} else if ( qstr == "savequery") {
		document.qf.qfile.value = "save";
	} else if ( qstr == "displayquery") {
		document.qf.qfile.value = "display";
	} else if ( qstr == "loadquery") {
		document.qf.qfile.value = "load";
	} else if ( qstr == "savecsv") {
		if (document.qf.q.value == "t")
		{
			document.qf.q.value = "qr";
		}
		document.qf.exptype.value = "alldata";
		document.qf.qfile.value = "save";
	} else if ( qstr == "savecsvpug" || qstr == "saveasn1pug" || qstr == "saveasntpug" || qstr == "saveasnbpug" || qstr == "savexmlpug") {
		if (document.qf.q.value == "t")
		{
			document.qf.q.value = "qr";
		}
		document.qf.exptype.value = 'alldata';
		if (qstr == "saveasn1pug") // will be removed
		{
			document.qf.exptype.value = 'asn1';
		}
		if (qstr == "saveasntpug")
		{
			document.qf.exptype.value = 'asnt';
		}
		if (qstr == "saveasnbpug")
		{
			document.qf.exptype.value = 'asnb';
		}
		if (qstr == "savexmlpug")
		{
			document.qf.exptype.value = 'xml';
		}
		document.qf.pug.value = "t";
		document.qf.qfile.value = "save";
	} else {
		document.qf.q.value = qstr;
	}
	

	if ( qstr == "gocids" && selectcid == 0 )
		alert("Please provide CID input.. ");
	else if ( qstr == "gosids" && selectsid == 0 ) 
		alert("Please provide SID input.. ");
	else if ( selectcid > 1 )
		alert("Please choose one method only from the Compound Input.. ");
	else if ( selectsid > 1 )
		alert("Please choose one method only from the Substance Input.. ");
	else if ( selectaid > 1 )
		alert("Please choose one method only from the BioAssay Input.. ");
	else {
		qfSubmit();

	}
}

function HeatHandler( url, service ) {
	document.qf.service.value = service;
	document.qf.action = url;
	qfSubmit();
}

function AssayNbrHandler( aid, qstr ) {

	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}
	document.qf.aid.value = aid;
	document.qf.q.value = qstr;
	qfSubmit();
}

function AssaySummaryHandler( aid ) {

	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}
		document.qf.aid.value = aid;
		document.qf.q.value = "";
	qfSubmit();
}

function AidDataHandler( aid, activity )
{
	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	document.qf.q.value = "aidsr";
	var temp = new Array();
	temp = aid.split('_');
	if (document.qf.mid_p)
	{
		document.qf.mid_p.value = aid;
	}
	document.qf.taid.value = temp[0];
	document.qf.activity.value = activity;
	qfSubmit();
}

function AssayAnalysisHandler( toolcgi, service )
{
	document.qf.action = toolcgi;
	document.qf.service.value = service;
	qfSubmit();
}

// bioassay result browsing
function asbr( str, flag ) {

	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}


	if ( str == 'd' ) {
		document.qf.acount.value = "1";
	} else if ( str != 'g')	{
		document.qf.acount.value = str;
	} else {
		if ( parseInt(document.qf.gacount.value) > parseInt(document.qf.tpn.value) )
		{
			document.qf.acount.value = document.qf.tpn.value;
		} else {
			document.qf.acount.value = document.qf.gacount.value;
		}
	}

	if (flag == 'cids' || flag == 'sids' || flag == 'aids' || flag == 'sum'  || flag == '' || flag == 'cidsv')
	{
		document.qf.q.value = flag;
	} else {
		//document.qf.cacheid.value = "";
		document.qf.q.value = document.qf.qb.value;
		document.qf.exptype.value = '';
		document.qf.queue.value = 't';
	}
	if (document.qf.br)
	{
		document.qf.br.value = 'y';;
	}
	qfSubmit();
}

function hbr( str, flag ) {

	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}


	if ( str == 'd' ) {
		document.qf.pcount.value = "1";
	} else if ( str != 'g')	{
		document.qf.pcount.value = str;
	} else {
		if ( parseInt(document.qf.gpcount.value) > parseInt(document.qf.apn.value) )
		{
			document.qf.pcount.value = document.qf.apn.value;
		} else {
			document.qf.pcount.value = document.qf.gpcount.value;
		}
	}

	if (flag == 'cids' || flag == 'sids' || flag == 'aids' || flag == 'sum'  || flag == '' || flag == 'cidsv')
	{
		document.qf.q.value = flag;
	} else {
		//document.qf.cacheid.value = "";
		document.qf.q.value = document.qf.qb.value;
		document.qf.exptype.value = '';
		document.qf.queue.value = 't';
	}
	if (document.qf.br)
	{
		document.qf.br.value = 'y';;
	}
	qfSubmit();
}

// bioassay result export
function qrbuttona( qrstr ) {
	if ( qrstr == 'back2assay' )
	{
		document.qf.q.value="";
		qfSubmit();
	}
	if ( qrstr == 'back2query' )
	{
		document.qf.q.value="t";
		qfSubmit();
	}
	if ( qrstr == 'export' )
	{
		if ( document.qf.exptypea.value == 'none' )
		{
			alert( 'Please select export type !' );
		} else {
			if (document.qf.exptypea.value != 'page data')
			{
				document.qf.queue.value = '';
			}
			//document.qf.cacheid.value = "";
			//document.qf.q.value="qr";
			document.qf.exptypeb.value = document.qf.exptypea.value;
			document.qf.exptype.value = document.qf.exptypea.value;
			qfSubmit();
		}
	}
}
// bioassay result export
function qrbuttonb( qrstr ) {
	if ( qrstr == 'back2assay' )
	{
		document.qf.q.value="";
		qfSubmit();
	}
	if ( qrstr == 'back2query' )
	{
		document.qf.q.value="t";
		qfSubmit();
	}
	if ( qrstr == 'export' )
	{
		if ( document.qf.exptypeb.value == '' )
		{
			alert( 'Please select export type !' );
		} else {
			if (document.qf.exptypeb.value == 'pagedata')
			{
				document.qf.queue.value = 'f';
			} else {
				document.qf.queue.value = 't';
			}
			//document.qf.cacheid.value = "";
			//document.qf.q.value="qr";
			document.qf.exptypea.value = document.qf.exptypeb.value;
			document.qf.exptype.value = document.qf.exptypeb.value;
			qfSubmit();
		}
	}
}

//
// bioassay result export
function rexp( qrstr ) 
{
	document.qf.exptype.value = qrstr.value;
	//alert( 'VV:' + document.qf.exptype.value);
	if ( document.qf.exptype.value == 'none' || document.qf.exptype.value == '' )
	{
		alert( 'Please select export type !' );
	} else {
		document.qf.cacheid.value = "";
		qfSubmit();
	}
}


function resortassay( sortstr ) {
	if ( sortstr == '' )
	{
		alert( 'This column cannot be sorted !' );
	} else {
		if (document.qf.qfile)
		{
			document.qf.qfile.value = "";
		}
		if (document.qf.exptype)
		{
			document.qf.exptype.value = "";
		}
		
		if (document.qf.qb ) 
		{
			document.qf.q.value = document.qf.qb.value;
		}

		document.qf.assaysort.value = sortstr;
		document.qf.acount.value = 1;
		document.qf.exptype.value = '';
		//document.qf.cacheid.value ='';

		//if (document.qf.sortdir.value == 1)
		//{
		//	document.qf.sortdir.value = 2;
		//} else {
		//	document.qf.sortdir.value = 1;
		//}

		qfSubmit();
	}
}

function AssayToolHandler(checkbox, url, tool, service) {
	if ( checkbox.length == 0 )
		alert('No result field found.');
	var tid;
	var k=0;
	var ccnt=1;
	var msg = "Please select 1 or more integer/float type result field from the query form.";

	document.qf.action= url;

	for (i=0; i<checkbox.length; i++ )
	{
			if (checkbox[i].checked)
			{
				if (checkbox[i].value.split('_')[2] <3 )
				{
					k++;
					if (k==1) {
						tid = checkbox[i].value;
					} else {
						tid += ',' + checkbox[i].value;
						if (k>5)
						{
							break;
						}
					}
				}
			}
	}

	document.qf.service.value = service;

	if (tool == 'histo' )
	{
		ccnt = 1;
	}
	if (tool == 'scatter' )
	{
		document.qf.service.value = service;
		//alert(tid);
		msg = "Please select 2 or more integer/float type result fields from the result definition table.";
		ccnt = 2;
	}
	if (k < ccnt)
	{
		alert(msg);
	} else if ( k>5 )
	{
		alert( "Please select 5 or less integer/float type result fields from the result definition table.");
	} else {
		document.qf.TID.value = tid;
		//window.open( url+tid, 'tool');
		qfSubmit();

	}
}

function GoHistogram(url, tid, histservice )
{
	document.qf.action= url;
	//document.qf.service.value = 'cgi';
	document.qf.TID.value = tid;
	document.qf.service.value = histservice;
//alert(url);
//alert(tid);
//alert(histservice);

	qfSubmit();
}

function AssayVersionHandler(aid)
{
	document.qf.q.value = 'sum';
	document.forms["qf"].submit();

	//var versionlist = document.qf.assayversion;
	//for (i=0; i< versionlist.length; i++) {
	//	if (versionlist.options[i].selected) {
	//	document.location.href='bioassay.cgi?aid=' + aid + '&version=' + versionlist.options[i].value
	//	}
	//}
}

function RviewChange()
{
	if (document.qf.optResultView.value == 'substance')
	{
		if ( document.qf.assaysort.value = 'cid' )
		{
			document.qf.assaysort.value = 'sid';
		}
	} else {
		if ( document.qf.assaysort.value = 'sid' )
		{
			document.qf.assaysort.value = 'cid';
		}
	}
	document.qf.acount.value = 1;
	document.qf.exptype.value = '';
	qfSubmit();
}

function DateValidator(dt)
{
	var is_datevalid = 't';
	if (dt)
	{
		var y = dt.split('/')[0];
		var m = dt.split('/')[1];
		var d = dt.split('/')[2];
		if ( y.length != 4 || isNaN(y))
		{
			is_datevalid = 'f';
		//	alert("yealength..");
		} else if (!m) {
			m = '12';
			d = '31';
		} else if (isNaN(m) || parseInt(m)>12 || parseInt(m)<1 ) {
			is_datevalid = 'f';
		} else {
			if (!d) {
				var mi = parseInt(m);
				if (mi==1 || mi==3 ||mi==5 ||mi==7 ||mi==8 ||mi==10 ||mi==12)
				{
					d='31';
				} else if (mi==4 || mi==6 ||mi==9 ||mi==11)
				{
					d='30';
				} else if ( parseInt(y) % 4 ==0)
				{
					d = '29';
				}  else if (parseInt(y) % 4 ==0)
				{
					d = '28';
				}
			} else if (isNaN(d)) {
				is_datevalid = 'f';
			} else {
				var mi = parseInt(m);
				if (mi==1 || mi==3 ||mi==5 ||mi==7 ||mi==8 ||mi==10 ||mi==12)
				{
					if (parseInt(d)>31 || parseInt <1)
					{
						is_datevalid = 'f';
					}
				}
				if (mi==4 || mi==6 ||mi==9 ||mi==11)
				{
					if (parseInt(d)>30 || parseInt <1)
					{
						is_datevalid = 'f';
					}
				}
				if (mi==2)
				{
					if (parseInt(d)>29 || parseInt <1)
					{
						is_datevalid = 'f';
					}
				}
			}
		}
		
		if (is_datevalid == 't')
		{
			if (d.length<2)
			{
				d = '0'+d;
			}
			if (m.length<2)
			{
				m = '0'+m;
			}
			dt= y + '/' + m + '/' + d;
			is_datevalid = 't';
		} else {
			is_datevalid = 'f';
		}
	}
	if (is_datevalid == 'f')
		return is_datevalid;
	else
		return dt;
}

//getElementById(arguments[i]).style
function AssayResultViewHandler( a )
{
	if (a == "all" )
	{
		if (document.qf.cmpdv.value != 'sub')
		{
			alert('The BioAssay Display Option will be changed to Substance.');
			document.qf.cmpdv.value = 'sub';
		}
	}

	if (document.qf.cmpdv.value == 'sub')
	{
		//document.qf.cmpdf[0].value == 'sall';

		document.getElementById("cmpdftr").style.display = "none";
		document.getElementById("subftr").style.display = "";
		//alert(document.getElementById('cmpdftr').style.display);
	} else {
		//alert(document.qf.cmpdf.value);
		document.getElementById('cmpdftr').style.display = '';
		document.getElementById("subftr").style.display = "none";
		//document.cmpdftr.style.display == '';
	}

}

function AssayResultViewHandlera( a )
{
	if (a == "all" )
	{
		if (document.qf.cmpdv.value != 'sub')
		{
			alert('The BioAssay Display Option will be changed to Substance.');
			document.qf.cmpdv.value = 'sub';
		}
	}

	if (document.qf.cmpdv.value == 'sub')
	{
		document.getElementById("cmpdftr").style.display = "none";
		//alert(document.getElementById('cmpdftr').style.display);
	} else {
		document.getElementById('cmpdftr').style.display = '';
		//document.cmpdftr.style.display == '';
	}

}

function s2dt() 
{
	document.qf.q.value = "sidsr";
	qfSubmit();
}
function Activity2DataTable() {
	var checkbox;
	if (document.qf.chAID)
	{
		checkbox = document.qf.chAID;
	}
	if ( checkbox.length == 0 )
		alert('No result field found.');
	var k=0, aidcnt, limit;
	var argcnt = arguments.length;
	
	aidcnt = arguments[0];
	
	if (argcnt >1)
	{
		limit = arguments[1];
	} else {
		limit = 30;
	}

	for (i=0; i<checkbox.length; i++ )
	{
		if (checkbox[i].checked)
		{
			k++;
		}
	}
	if ( (k==0 && aidcnt >limit) || k>limit)
	{
		alert( 'Please select <=' + limit + ' BioAssays for DataTable.' );
	} else {
		AssayQueryHandler('activity_data');
	}
}

function Concise_CompleteHandler( rsts ){
	document.qf.resultsummary.value = rsts;
	AssayQueryHandler('reshow');
}

function SubComHandler(s)
{
	//document.qf.reset();
	if (document.qf.pcassayquery_key)
	{
		document.qf.pcassayquery_key.value = '';
	}
	if (document.qf.AIDlist)
	{
		document.qf.AIDlist.value = '';
	}
	if (document.qf.AIDfile)
	{
		document.qf.AIDfile.value='';
	}
	if (document.qf.pccompoundquery_key)
	{
		document.qf.pccompoundquery_key.value = '';
	}
	if (document.qf.CIDlist)
	{
		document.qf.CIDlist.value = '';
	}
	if (document.qf.CIDfile)
	{
		document.qf.CIDfile.value='';
	}
	if (document.qf.pcsubstancequery_key)
	{
		document.qf.pcsubstancequery_key.value = '';
	}
	if (document.qf.SIDlist)
	{
		document.qf.SIDlist.value = '';
	}
	if (document.qf.SIDfile)
	{
		document.qf.SIDfile.value='';
	}

	document.qf.cmpdv.value = s;
	qfSubmit();
}

function AssayPageHandler( page ) 
{
	if (document.qf.qfile)
	{
		document.qf.qfile.value = "";
	}
	if (document.qf.exptype)
	{
		document.qf.exptype.value = "";
	}
	if (document.qf.stested_key)
	{
		document.qf.stested_key.value = "";
	}
	if (document.qf.acount)
	{
		document.qf.acount.value = "";
	}
	document.qf.pcount.value=page;
	qfSubmit();
}

function qfSubmit()
{
	if ( document.getElementById('v_u') && document.qf.ax)
	{
		document.qf.ax.value = document.getElementById('v_u').style.display;
	}
	if ( document.getElementById('v_l') && document.qf.cx)
	{
		document.qf.cx.value = document.getElementById('v_l').style.display;
	}

	document.qf.submit();
}

function xSH(s, id)
{
 	var gobj = document.getElementById(id);
	//alert( x + ',' + y );
	// show
	if (s=='s')
	{
		gobj.style.display = "";
		gobj.style.left = window_pageX-40;
		gobj.style.top = window_pageY+14;
		//gobj.innerText = id.text;
	}
	// hide
	if (s=='h') 
	{
		gobj.style.display = "none";
	}
}

