/* var webdir = "http://yar.ncbi.nlm.nih.gov/geo/";      */
/* var imghome = "http://yar.ncbi.nlm.nih.gov/geo/img/"; */
var webdir = "/PEPR/";
var imghome = "/PEPR/images/";
//var webdir = "/";
//var imghome = "/images/";

var ca1=new Image();ca1.src = imghome + 'checkall1.gif';
var ca2=new Image();ca2.src = imghome + 'checkall2.gif';

var ua1=new Image();ua1.src = imghome + 'uncheckall1.gif';
var ua2=new Image();ua2.src = imghome + 'uncheckall2.gif';

var dl1=new Image();dl1.src = imghome + 'download1.gif';
var dl2=new Image();dl2.src = imghome + 'download2.gif';

var gr1=new Image();gr1.src = imghome + 'graphit1.gif';
var gr2=new Image();gr2.src = imghome + 'graphit2.gif';

var tg1=new Image();tg1.src = imghome + 'toggle1.gif';
var tg2=new Image();tg2.src = imghome + 'toggle2.gif';

var cw1=new Image();cw1.src = imghome + 'closewin1.gif';
var cw2=new Image();cw2.src = imghome + 'closewin2.gif';

var op1=new Image();op1.src = imghome + 'opts1.gif';
var op2=new Image();op2.src = imghome + 'opts2.gif';

function is_unix() {
    var agt=navigator.userAgent.toLowerCase();
    return  (agt.indexOf("unix")!=-1);
}

function is_win() {
    var agt=navigator.userAgent.toLowerCase();
    return  (agt.indexOf("win")!=-1);
}

function is_mac() {
    var agt=navigator.userAgent.toLowerCase();
    return  (agt.indexOf("mac")!=-1);
}

function uncheck_all(name) {
    for(i=0;i<name.length;++i)
	name[i].checked = false;
}

function check_all(name) {
    for(i=0;i<name.length;++i)
	name[i].checked = true;
}
      
function toggle_check(name) {
    for(i=0;i<name.length;++i)
	name[i].checked = !name[i].checked;
}

function validate(name) {
    for(i=0;i<name.length;++i) 
        if(name[i].checked) 
	    return true;
    alert("you must select one or more Samples");
    return false;
}

function subCk(name) {
    var boxname = "csub" + name;
    var subname = "sub" + name;
    var thebox = eval("document.exp_form." + boxname);
    var arr = eval("document.exp_form." + subname);
    var exps = document.exp_form.exps;
    
    if(thebox.checked) {
    	if (typeof arr != 'undefined') {
    		//alert("arr is not undefined " + name + " length is " + arr.length);
    		if (typeof arr.length != 'undefined') {
			for(j=0;j<arr.length;++j) {
			    var exp = arr[j].value;
			    //alert("exp is " + exp);
			    if(exp == 0)
				continue;
			    for(k=0; k<exps.length; ++k)
				if(exps[k].value == exp)
				    exps[k].checked = true;
			}
		} else {
			var exp = arr.value;
			for (k=0; k< exps.length; ++k)
				if (exps[k].value == exp)
					exps[k].checked = true;
		}
	} else {
		//alert("arr is undefined");
	}
    }
    else {
    	if (typeof arr != 'undefined') {
    		//alert("arr is not undefined " + name + " length is " + arr.length);
		if (typeof arr.length != 'undefined') {
			for(j=0;j<arr.length;++j) {
			    var exp = arr[j].value;
			    //alert("exp is " + exp);
			    if(exp == 0)
				continue;
			    for(k=0; k<exps.length; ++k)
				if(exps[k].value == exp)
				    exps[k].checked = false;
			}
		} else {
			var exp = arr.value;
			for (k=0; k< exps.length; ++k)
				if (exps[k].value == exp)
					exps[k].checked = false;
		}
	} else {
		//alert("arr is undefined");
	}
    }
}  

function img_fwd(iname) {
    var i2 = iname + "2";
    var nsrc = eval(i2).src;
    if(nsrc != document.images[iname].src)
	document.images[iname].src = nsrc;
}

function img_bkwd(iname) {
    var i1 = iname + "1";
    var nsrc = eval(i1).src;
    if(nsrc != document.images[iname].src)
	document.images[iname].src = nsrc;
}

function openurl(url) {
	window.location.href= url;
}

function openWindow(url, title, openCmd) {
  window.location.href= url;
  var w = window.open(url, title, eval(openCmd)); 
  w.focus();
}


function show_type(quantity, exps) {
  var tocgi = webdir + "browse.do?action=download&datatype=" + quantity + "&exps=" + exps;
  var open_cmd = '"width=650,height=500,resizable,scrollbars"';
  window.location.href= tocgi;
  //var w = window.open(tocgi, "download", eval(open_cmd)); 
  //w.focus();
}

function download(frm, quantity) {
    var samps = frm.exps;
    var exps = '';
    var n_selected = 0;
    for(i=0;i<samps.length;++i) {
	if(samps[i].checked) {
	    if(n_selected++)
		exps += "&exps=";
	    exps += samps[i].value;
        }
    }
    
    if(n_selected < 1) {
        alert("You must select 1 or more Experiment(s)");
        return;
    }
    
      
      show_type(quantity, exps);
      return;   
}

function show_download_type(quantity, exps) {
  var tocgi = webdir + "browse.do?action=offlineDownload&datatype=" + quantity + "&exps=" + exps;
  var open_cmd = '"width=650,height=500,resizable,scrollbars"';
  var w = window.open(tocgi, "download", eval(open_cmd)); 
  w.focus();
}

function offlineDownload(frm, quantity) {
    var samps = frm.exps;
    var exps = '';
    var n_selected = 0;
    for(i=0;i<samps.length;++i) 
    {
      if(samps[i].checked) {
        if(n_selected++)
          exps += "&exps=";
          exps += samps[i].value;
        }
      }
      
      if(n_selected < 1) {
          alert("You must select 1 or more Experiment(s)");
          return;
      }
      
      show_download_type(quantity, exps);
      return;   
}

function show_chart(frm) {
  var projectId = frm.projectId;
  var idvalue = '';
  idvalue =  projectId.value;
  
  var tourl = webdir + "charting.do?action=selectChartProjectType&projectId=" + idvalue;
  window.location.href= tourl;
  //var w = window.open(tocgi, "download", eval(open_cmd)); 
  //w.focus();
}

function show_cluster(frm) {
  var projectId = frm.projectId;
  var idvalue = '';
  idvalue =  projectId.value;
  
  var tourl = webdir + "charting.do?action=selectClusterChart&projectId=" + idvalue;
  window.location.href= tourl;
  //var w = window.open(tocgi, "download", eval(open_cmd)); 
  //w.focus();
}