
function refresh(input_field, input_value){
	
	
var objform = parent.window.document.forms["frm_refresh"] ;	
	
if (input_value == 'frm_genomes'){
var objform2 = parent.window.document.forms["frm_genomes"] ;
var nc2add = "";


// if only one checkbox selected ie not a collection
if (document.forms["frm_genomes"].selectgenome.length == undefined) {

nc2add += document.forms["frm_genomes"].selectgenome.value + "_xyz_";
} else {


// if multiple checkboxes selected then iterate 
for(var i=0; i < document.forms["frm_genomes"].selectgenome.length; i++){

	if(document.forms["frm_genomes"].selectgenome[i].checked)
		nc2add += document.forms["frm_genomes"].selectgenome[i].value + "_xyz_";

}} // end if 

input_field.value = nc2add;
}

else {
input_field.value = input_value;
}
	
var url = this.parent.location.href;

// split url on ? to retrieve parameters

var array_url 		= new Array();

array_url 		= escape(url).split('%3F');
	

var http_path 		= array_url[0];
var http_parameters 	= array_url[1];

var array_parameters 	= new Array();


if (http_parameters){
array_parameters 	= http_parameters.split("%26");
} 





var new_url 		= unescape(http_path) + "?";

var page 	= parent.window.document.forms["frm_refresh"].page.value;
var structure 	= parent.window.document.forms["frm_refresh"].structure.value;
var format	= parent.window.document.forms["frm_refresh"].format.value;
var header 	= parent.window.document.forms["frm_refresh"].header.value;
var provenance  = parent.window.document.forms["frm_refresh"].provenance.value;
var nc  	= parent.window.document.forms["frm_refresh"].nc.value;
var action 	= parent.window.document.forms["frm_refresh"].action.value;


for (var n = 0; n < array_parameters.length; n++) {
	
	var param 	= unescape(array_parameters[n]); 
	var regex	= new RegExp(/^structure|^format|^header|^nc|^action|^page|^search|^provenance/);
	
	if ((param.match(regex) == null) && (param != "")) {
		new_url += "&" + param ;
	} 
}

if (input_value == 'frm_genomes'){
action = "genomebank";

} 


// do not include nc numbers
var url4popup = new_url +  "&provenance=" + provenance + "&structure=" + structure + "&format=" + format + "&header=" + header + "&action=" + action + "&page=" + page ;


if ((format == "xml")||(format == "rss") || (format == "rdf")  || (header == "hide")|| (format == "text")){	


parent.window.document.forms["frm_refresh"].header.value 	= "";
parent.window.document.forms["frm_refresh"].format.value 	= "";

if (action != "datasets"){
parent.window.document.forms["frm_refresh"].provenance.value 	= "";
}
parent.window.document.forms["frm_refresh"].nc.value 		= "";

parent.window.document.forms["frm_refresh"].structure.value 	= structure;	
parent.window.document.forms["frm_refresh"].page.value 		= "";	


if (format == "text") {
this.parent.location.href = url4popup;

} else {
	var win = window.open(url4popup, 'win', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600');
}


} else if (provenance == "yes")  {

parent.window.document.forms["frm_refresh"].header.value 	= "";
parent.window.document.forms["frm_refresh"].format.value 	= "html";
parent.window.document.forms["frm_refresh"].provenance.value 	= "";	
parent.window.document.forms["frm_refresh"].nc.value 		= "";	
parent.window.document.forms["frm_refresh"].structure.value 	= "";	
parent.window.document.forms["frm_refresh"].page.value 		= "";
	
var url4prov = new_url + "&structure=serial&format=html&provenance=yes&header=hide&action=" + action;


if (action == 'datasets') {
	parent.window.location.href = new_url + "&structure=" + structure + "&format=" + format + "&provenance=yes&header=" + header + "&action=" + action;;
	
} else {

var win = window.open(url4prov, 'win', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600');


}


} else {
	
// use post method	


parent.window.document.forms["frm_refresh"].header.value 	= header;
parent.window.document.forms["frm_refresh"].format.value 	= format;
parent.window.document.forms["frm_refresh"].provenance.value 	= provenance;

parent.window.document.forms["frm_refresh"].nc.value 		= nc;
parent.window.document.forms["frm_refresh"].structure.value 	= structure;
parent.window.document.forms["frm_refresh"].page.value 		= page;	
parent.window.document.forms["frm_refresh"].action.value	= action;




if (nc == "") {
parent.window.document.forms["frm_refresh"].method		= "GET";
} else {
parent.window.document.forms["frm_refresh"].method		= "POST";
}



parent.window.document.forms["frm_refresh"].submit();	


//this.parent.location.href = url4popup;
}



}














function selected_radio(objradio){

var selected = "";
for(var i=0; i<objradio.length; i++){
	if (objradio[i].checked)
		selected =  (objradio[i].value);
}
return selected;
}




function sel(select){


var collCheckbox 	= parent.window.document.forms["frm_genomes"].selectgenome;	
var swtch 		= (select == "select") ? true : false;
	
// if there is only one checkbox, then assign value and return
if (collCheckbox.length == undefined) {
collCheckbox.checked = swtch;
return;
} 

// if there is a collection of checkboxes

for(var i=0; i < collCheckbox.length; i++){
	collCheckbox[i].checked = swtch;	
}

}




	
function go2page(maxpage){
	

var page_selected = parent.window.document.forms['frm_genomes'].page.value;

if ((page_selected > maxpage)|| (page_selected < 1)) {
alert('Please enter a page number between 1 and ' + maxpage);


} else {

	
refresh(parent.window.document.forms['frm_refresh'].page, page_selected);	
}


}	
	



function showdiv(div_title_id){

var divnew = div_title_id.replace("title", "table");

var divnew2 = eval("document.getElementById('" + divnew + "')");


if (divnew2.className == "div_genomebank"){
divnew2.className = "div_genomebank_show";
} else {
divnew2.className = "div_genomebank";

}
}




function frm_submit_genomebank(objform){

	
objform.format.value 	= "html";
objform.action.value 	= "genomebank";

var nc 		= objform.nc;

var ncshow 	= objform.ncshow;

var nc_value 	= ncshow.value;

// replace commas with _xyz_ and submit form

var new_nc = nc_value.replace(/\s*,\s*/g, "_xyz_");

objform.nc.value 	= new_nc;
objform.method	 	= "POST";

objform.submit();

}


function genomebank_submit(action, format) {

var objform = parent.document.forms["frm_genomebank"];


objform.action.value 	= action;
objform.format.value 	= format;
objform.page.value 	= "all";



var nc 		= objform.nc;
var ncshow 	= objform.ncshow;
var nc_value 	= ncshow.value;

// replace commas with _xyz_ and submit form

var new_nc = nc_value.replace(/\s*,\s*/g, "_xyz_");


objform.nc.value 	= new_nc;
objform.method 		= "POST";


objform.submit();

}

