
NS6 = (!document.all && document.getElementById)? 1:0;
NS4 = (document.layers) ? 1:0;
IE4 = (document.all) ? 1:0;

//alert('NS6:' + NS6 +',NS4:' +  NS4 +',IE4:' +  IE4);

var divname = "jstooldiv";
var x = 0;
var y = 0;
var fen;
var window_width = 800;
var timeoutId = 0;
var Z_MENU_XOFFSET	= -50;
var Z_MENU_YOFFSET	= 20;
var Z_MENU = true;

var Z_MENU_TIMEIN = 200;
var Z_MENU_TIMEOUT = 6000;

if(NS4 || IE4 || NS6) {
    document.onmousemove = mouseMove;

    if(NS4 || NS6) {
		document.captureEvents(Event.MOUSEMOVE);
		window_width = window.innerWidth;
    }
}

function showHide(theSelect){
	if(theSelect.name == 'type_recherche'){
		if(theSelect.options[theSelect.selectedIndex].value == 'cytoband') {
			document.getElementById('chromosome').style.visibility = 'visible';
		}
		else{
			document.getElementById('chromosome').style.visibility = 'hidden';
			document.getElementById('cytoband').style.visibility = 'hidden';
		}
	}
	else if(theSelect.name == 'chromosome'){
		document.getElementById('cytoband').style.visibility = 'visible';
	}

}

function mouseMove(e) {
	if(NS4) {
		x = e.pageX +Z_MENU_XOFFSET;
		y = e.pageY +Z_MENU_YOFFSET;
    } else if(IE4) {
		x = event.x +Z_MENU_XOFFSET + document.body.scrollLeft;
		y = event.y +Z_MENU_YOFFSET + document.body.scrollTop;
    } else if(NS6) {
		x = e.clientX +Z_MENU_XOFFSET + window.pageXOffset;
		y = e.clientY +Z_MENU_YOFFSET + window.pageYOffset;
    }
}

function checkAll(){
	var frm = document.search;
	
	for (var i=0;i<frm.elements.length;i++){
		var e = frm.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')){
			e.checked = frm.allbox.checked;
		}
	}
}

function checkAllMicroarray(){
	var frm = document.imageManager;
	
	for (var i=0;i<frm.elements.length;i++){
		var e = frm.elements[i];
		var splitArray = e.name.split('_');
		if ((e.name != 'allbox') && (e.type=='checkbox') && (splitArray[0]=='microarray')){
			e.checked = frm.allbox.checked;
		}
	}
}

function zmenu() {
    zmenuoff();

    var txt = "";
	
	var TITLE_BG	= arguments[0];
	var TITLE_FONT	= arguments[1];
	var TIP_BG		= arguments[2];
	var TIP_FONT	= arguments[3];

    txt += '<div id="title" style="position:relative;top:0;left:2;"><table border="0" cellpadding="0" cellspacing="0">';
	
	if(arguments[4] != ''){
	   txt += '<tr bgcolor="'+TITLE_BG+'"><td width="100%" colspan="2"><span style="color:'+TITLE_FONT+'; '+
	   'font-family:arial,sans-serif,helvetica;font-size: 8pt;font-weight:bold;">&nbsp;'+arguments[4]+'&nbsp;</span></td></tr>';
	}

    for(i = 5; i < arguments.length; i+=2)
	{
		var name  = arguments[i];
		var value  = arguments[i+1];
		txt += '<tr bgcolor="'+TIP_BG+'">';
		txt += '<td><span style="color:'+TIP_FONT+'; '+ 'font-family:arial,sans-serif,helvetica;font-size: 8pt;font-weight:bold;">'+name+'&nbsp;</span></td>';
		txt += '<td align="right"><span style="color:'+TIP_FONT+'; '+ 'font-family:arial,sans-serif,helvetica;font-size: 8pt;font-weight:bold;">&nbsp;'+value+'</span></td></tr>';
	}
	
	txt += '</table></div>';
	
    if(NS4) {
		l = document.layers[divname];
		l.document.open("text/html");
		l.document.write(txt);
		l.document.close();
		l.document.bgColor	= TIP_BG;
		l.left			= x;
		l.top			= y;
    }
	else if(IE4) {
		l = document.all[divname];
		l.style.backgroundColor	= TIP_BG;
		l.innerHTML		= txt;
		l.style.pixelLeft	= x;
		l.style.pixelTop	= y;
    }
	else if(NS6) {
		l = document.getElementById(divname);

		rng = document.createRange();
		rng.setStartBefore(l);
		htmlFrag = rng.createContextualFragment(txt);

		while (l.hasChildNodes()) {
		    l.removeChild(l.lastChild);
		}
		l.appendChild(htmlFrag);

		l.style.border		= 1;
		l.style.border
		l.style.backgroundColor	= TIP_BG;
		l.style.left		= x;
		l.style.top		= y;
    }

    window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout('zmenuon_now()', Z_MENU_TIMEIN);
    return true;
}

function zmenuon_now() {
    if(NS4) {
		l = document.layers[divname];
		l.visibility		= "show";
    }
	else if(IE4) {
		l = document.all[divname];
		l.style.visibility	= "visible";
    }
	else if(NS6) {
		l = document.getElementById(divname);
		l.style.visibility	= "visible";
    }
    window.clearTimeout(timeoutId);
    timeoutId = window.setTimeout('zmenuoff()', Z_MENU_TIMEOUT);
    return true;
}

function zmenuoff() {
    if(NS4) {
		document.layers[divname].visibility = "hide";
    }
	else if(IE4) {
		document.all[divname].style.visibility = "hidden";
    }
	else if(NS6) {
		document.getElementById(divname).style.visibility = "hidden";
    }
}

function pseudoSubmit(){
	var form = document.recherche;
	var query = form.query;
	query.setAttribute('onchange','Y');
	form.submit();
}	
	
function validTextarea(val,lst){
	var msg = '';
	var str = '';
	var valid = true;
	var re = new RegExp ('\r\n', 'gi');
	var newstr = val.replace(re, ',');
	splitArrayValue = newstr.split(',');
	splitIndexValue = splitArrayValue.length;
	
	for(var i=0; i<splitIndexValue; i++){
		if(splitArrayValue[i] != ''){
			str += splitArrayValue[i] + ',';
    		splitArray = lst.split(splitArrayValue[i]);
			splitArrayVal = str.split(splitArrayValue[i]);
    		splitIndex = splitArray.length;
			splitIndexVal = splitArrayVal.length;
			
			if(splitIndex == 1){
				msg += splitArrayValue[i] + ' is not a valid Plate 384' + '\n';
				valid = false;
			}
			if(splitIndexVal > 2){
				msg += splitArrayValue[i] + ' was already scanned' + '\n';
				valid = false;
			}
		}
	}
	if(!valid){ alert(msg); }
}

function validInput(val,lst){
    splitArray = lst.split(val);
    splitIndex = splitArray.length;
	if(splitIndex == 1){ alert(val + ' is not a valid Plate 96'); }
}

function flip(quien,path){
	document.images[quien].src=path;
}  

function navigation(){
	fen =
	window.open("","alignement","0,0,0,status=yes,0,scrollbars=yes,resizable,top=80,left=80,0,height=600,width=630");
	if(self.focus) fen.focus();
}
function miame(){
	fen =
	window.open("","miame","0,0,0,status=yes,0,scrollbars=yes,resizable,top=10,left=10,0,height=820,width=670");
	if(self.focus) fen.focus();
}
function fileformat(){
	fen =
	window.open("","fileformat","0,0,0,status=yes,0,scrollbars=yes,resizable,top=10,left=10,0,height=450,width=800");
	if(self.focus) fen.focus();
}
function grid(){
	fen =
	window.open("","grid","0,0,0,status=yes,0,scrollbars=yes,resizable,top=50,left=50,0,height=370,width=440");
	if(self.focus) fen.focus();
}
function orderBon(){
	fen =
	window.open("","orderBon","0,0,0,menubar=yes,status=yes,0,scrollbars=yes,resizable,top=50,left=50,0,height=600,width=500");
	if(self.focus) fen.focus();
}
function popup(){
	fen =
	window.open("","popup","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=100,width=350");
	if(self.focus) fen.focus();
}
function popup_viewer(){
	fen =
	window.open("","popup_viewer","0,0,0,status=yes,0,scrollbars=yes,resizable=no,top=50,left=50,0,height=620,width=700");
	if(self.focus) fen.focus();
}
function popup_confirm(){
	fen =
	window.open("","popup_confirm","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=80,width=300");
	if(self.focus) fen.focus();
}
function popup_2(){
	fen =
	window.open("","popup_2","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=170,width=370");
	if(self.focus) fen.focus();
}
function popup_3(){
	fen =
	window.open("","popup_3","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=280,width=360");
	if(self.focus) fen.focus();
}
function popup_help(){
	fen =
	window.open("","popup_help","0,0,0,status=yes,0,scrollbars=yes,resizable=yes,top=50,left=50,0,height=350,width=600");
	if(self.focus) fen.focus();
}
function popup_4(){
	fen =
	window.open("","popup_4","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=550,width=500");
	if(self.focus) fen.focus();
}
function popup_5(){
	fen =
	window.open("","popup_5","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=200,width=400");
	if(self.focus) fen.focus();
}
function popup_stats(){
	fen =
	window.open("","popup_stats","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=200,width=520");
	if(self.focus) fen.focus();
}
function legend(){
	fen =
	window.open("","legend","0,0,0,status=yes,0,scrollbars=no,resizable=yes,top=100,left=400,0,height=130,width=250");
	if(self.focus) fen.focus();
}

function biochipSubmit(save,type,truc_a_virer) 
{
	document.forms['biochip'].del.value = truc_a_virer;
	document.forms['biochip'].save.value = save;
	document.forms['biochip'].type.value = type;
	document.forms['biochip'].submit();
} 

function adminSubmit(user_id,type,val)
{
	document.forms['admin'].user_id.value = user_id;
	document.forms['admin'].type.value = type;
	document.forms['admin'].val.value = val;
	document.forms['admin'].submit();
} 

function affiche(gene_1, bloc_1, row_1, column_1, cy3_median_1, cy3_bruit_1, cy5_median_1, cy5_bruit_1, ratio_1){
	with (document.legend){
		gene.value			= gene_1
		bloc.value			= bloc_1
		row.value			= row_1
		column.value		= column_1
		cy3_median.value	= cy3_median_1
		cy3_bruit.value		= cy3_bruit_1
		cy5_median.value	= cy5_median_1
		cy5_bruit.value		= cy5_bruit_1
		ratio.value			= ratio_1
	}
}

function afficheDEV(sy, bl, ro, co, oid, cy3, cy5, ra, avg, lograt, fl){
	with (document.legend){
		name.value		= sy
		bloc.value		= bl
		row.value		= ro
		column.value	= co
		id.value		= oid
		ch1.value		= cy3
		ch2.value		= cy5
		ratio.value		= ra
		average.value	= avg
		logratio.value	= lograt
		flag.value		= fl
	}
}
function afficheSymbols(sy){
	with (document.legend){
		var tmp = sy.replace(/,/g,"\n")
		lst.value = tmp.replace(/;/g,"  ")
	}
}

function DOMGetElement(o) {
  if (document.getElementById) return document.getElementById(o);
  else if (document.all)             return document.all[o];
  else if (document.layers)          return document.layers[o];
  return null;
}

function DOMWindowGetXOffset() {
  if (document.all)            return document.body.scrollLeft;
  else if (document.getElementById)  return window.pageXOffset;
  else if (document.layers)          return window.pageXOffset;
}

function DOMWindowGetYOffset() {
  if (document.all)             return document.body.scrollTop;
  else if (document.getElementById)  return window.pageYOffset;
  else if (document.layers)          return window.pageYOffset;
}

function DOMElementSetTopPos(o,val) {
  if (document.getElementById) o.style.top = val;
  else if (document.all)       o.style.top = val;
  else if (document.layers)    o.pageY = val;
}

function DOMElementSetLeftPos(o,val) {
  if (document.getElementById) o.style.left = val;
  else if (document.all)       o.style.left = val;
  else if (document.layers)    o.pageX = val;
}

function DOMWindowGetInnerWidth() {
  if (document.all)           return document.body.clientWidth;
  else if (document.getElementById)   return window.innerWidth;
  else if (document.layers)           return window.innerWidth;
}

function DOMWindowGetInnerHeight() {
  if (document.all)          return document.body.clientHeight;
  else if (document.getElementById)  return window.innerHeight;
  else if (document.layers)          return window.innerHeight;
}

function DOMElementGetHeight(o) {
  if (document.all)                 return o.clientHeight;
  else if (document.getElementById) return parseInt(o.offsetHeight);
  else if (document.layers)         return o.document.height;
}

function DOMElementGetWidth(o) {
  if (document.all)                 return o.clientWidth;
  else if (document.getElementById) return parseInt(o.offsetWidth);
  else if (document.layers)         return o.document.width;
}

function pageOffset() {
  var o = DOMGetElement('o');
  if (o) {
    DOMElementSetLeftPos(o, DOMWindowGetXOffset() + DOMWindowGetInnerWidth() - DOMElementGetWidth(o) - 20);
    DOMElementSetTopPos(o, DOMWindowGetYOffset() + DOMWindowGetInnerHeight() - DOMElementGetHeight(o) - 20);

    setTimeout('pageOffset()',10);
  }
}


