var nb_selected = 0;

function openJmol(name) {
    name=window.open('',name,'height=725,width=660,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
    var ix=Math.round(200*Math.random()); name.moveTo(ix,0);
    }
function newWindow(name) {
    name=window.open('',name,'height=725,width=660,status=no,toolbar=no,directories=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
    var ix=Math.round(200*Math.random()); name.moveTo(ix,0);
    }

function selectAll(theBool){
	var formSize = document.icsdResults.elements.length;
	var nb_checkboxes = 0;
	for(var i=0; i < formSize; i++){
		if(document.icsdResults.elements[i].type=='checkbox'){
			nb_checkboxes++;
			document.icsdResults.elements[i].checked = theBool;
		}
	nb_selected =(theBool ? nb_checkboxes : 0);
	}
}
function setPageRows(thePage, theRows){
	document.icsdForm.page.value = thePage;
	document.icsdForm.nb_rows.value = theRows;
	document.icsdResultsPref.nb_rows.value = theRows;
	document.icsdForm.submit();
}
function setOrder(order_by){
	document.icsdForm.page.value = '1';
	document.icsdForm.order_by.value = order_by;
	document.icsdForm.nb_rows.value = document.forms['icsdResultsPref'].nb_rows.value;
	document.icsdForm.submit();
}

function add(theValue, theInput){
  document.icsdForm.getElementsById[theInput].value=theValue;
}


// modified javascript code from :
// http://developer.apple.com/internet/javascript/hideshow_layer.html

function showPopup(targetObjectId, eventObj){
	if(eventObj){
		hideCurrentPopup();
		eventObj.cancelBubble = true;
		if(changeObjectVisibility(targetObjectId, 'visible')){
			window.currentlyVisiblePopup = targetObjectId;
			return true;
		} else{
			return false;
		}
	} else{
		return false;
	}
}

function hideCurrentPopup(){
	if(window.currentlyVisiblePopup){
		changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
		window.currentlyVisiblePopup = false;
	}
}

document.onclick = hideCurrentPopup;

function getStyleObject(objectId){
	if(document.getElementById && document.getElementById(objectId)){
		return document.getElementById(objectId).style;
	} else if(document.all && document.all(objectId)){
		return document.all(objectId).style;
	} else if(document.layers && document.layers[objectId]){
		return document.layers[objectId];
	} else{
		return false;
	}
}

function changeObjectVisibility(objectId, newVisibility){
	var styleObject = getStyleObject(objectId);
	if(styleObject){
		styleObject.visibility = newVisibility;
		return true;
	} else{
		return false;
	}
}
