function setTooltips(){
	tooltips["export"] = "Export the combined interactions in several file formats.<br/>Once the file is ready for download, a small area with the link will appear below this box.";
	tooltips["qm"] = "Apply confidence measures to asses the reliability of interactions. <br/>The scores of the measures will be used to color the interaction squares accordingly.";
	tooltips["sources"] = "Define the interaction sources that <span class=\"dasmiweb\">DASMIweb</span> uses.";
	tooltips["clearSources"] = "Remove all interaction sources from your current session.";
	tooltips["loadSources"] = "Retrieve the list of available DASMI sources from the DAS registry.";	
	tooltips["closeConfig"] = "Close the Source Configuration.";
	tooltips["allIsActive"] = "(De)activate all sources at once.";
	tooltips["tisActive"] = "(De)activate this source.";
	tooltips["mydasmi"] = "myDASMI is allows you the control the presentation of results. You can influence the query mode, sorting, and tabbed browsing. ";
	tooltips["emptysources"] = "Defines if you want to the all results, or only the non-empty ones. <br/><span style=\"color:green;font-weight:bold;\">YES</span>: if you want to show the results of all sources, containg empty resul sets. <br/><span style=\"color:red;font-weight:bold;\">NO</span>: if you want to hide sources that did not report any interactions.";
	tooltips["idmapping"] = "Should <span class=\"dasmiweb\">DASMIweb</span> automatically try to map identifiers into compatible coordinate systems?<br/><span style=\"color:green;font-weight:bold;\">YES</span>: All compatible sources will be included and identifiers will be mapped.<br/><span style=\"color:red;font-weight:bold;\">NO</span>:Only results from sources in the same coordiante system as the query will be included.";
	tooltips["clearInter"] = "Remove The results from you last query. You will start with a new <span class=\"dasmiweb\">DASMIweb</span> session.";
	tooltips["newCS"] = "Specify the identifier type that can be used to query the new source.";
	tooltips["newLabels"] = "You can use labels to further specify the source.";
	tooltips["newURL"] = "Enter the valid URL of the new source, e.g., htt://somewhere.net/das/mysource/.";
	tooltips["newDesc"] = "You can optionally describe the source in some words.";
	tooltips["newName"] = "This name will be shown in the interaction table.";
	tooltips["newID"] = "The ID will be autogenerated by DASMIweb.";
	tooltips["newAct"] = "Specify if the new source should be included in all future queries.";
	tooltips["newQM"] = "Check this box if the source should be used as a confidence measure.";
	tooltips["tabbing"] = "Define how many interactions you want to see per page. <br/> Arrows will allow you to browse through additional interactions.";
	tooltips["sorting"] = "Define which column you want to use for sorting the results and whether the sorting should be in ascending or descending order. <br/><br/><b>Consensus</b> sorts according to the number of occurences of interactions in all data sources. <br/> <b>Name</b>, <b>ID</b> and <b>Description</b> sort the results alphabetically according to the selected column. <br/> <b>Data source columns</b> sort according to the existence of an interaction in the respective data source.";
	tooltips["exactSearch"] = "<span style=\"color:green;font-weight:bold;\">Exact</span>: only considers complete identifier or name matches. <br/> <span style=\"color:red;font-weight:bold;\">Partial/Full-text</span> will additionally consider matching parts of name. <br/><br/><b>Example:</b> An exact search for 1212 will find only the Entrez Gene interactor with this identifier. <br/> A partial seach for 1212 will in additiona find Q7TR08_MOUSE,<br/> as its description contains the string 1212";
	//tooltips[""] = "";
}


/**
* Clear the new sources entries. deletes all values and 
* requests new from Dasmi
*/
function clearNewLine(type) {
	/*dwr.util.setValue("nickname", null);
	dwr.util.setValue("nicknameHelp", null);
	dwr.util.setValue("url", "http://");
	dwr.util.setValue("urlHelp", null);
	//dwr.util.setValue("adminemail", null);
	//dwr.util.setValue("adminemailHelp", null);
	dwr.util.setValue("description", null);
	dwr.util.setValue("descriptionHelp", null);
	//dwr.util.setValue("capabilitiesHelp", null);
	dwr.util.setValue("labelsHelp", null);	
	dwr.util.setValue("coordinateSystemHelp", null);	    
	dwr.util.setValue("isQM", false);	    
	dwr.util.setValue("file", null);	    
	dwr.util.setValue("fileHelp", null);	    */

    //dwr.engine.beginBatch();
  	Dasmi.getNextId( function(id) {
		dwr.util.setValue("id", id);
	});
	
	//Dasmi.getAllCapabilities( function(caps) {
	//dwr.util.removeAllOptions("capabilities");
	//dwr.util.addOptions("capabilities", ['interaction']);
	//});
	if (type != "file"){
		Dasmi.getAllCoordinateSystems( function(coords) {
			var unmarshaledCoordSys = unmarshalCoordSys(coords)
			dwr.util.removeAllOptions("coordinateSystem");
			dwr.util.addOptions("coordinateSystem", unmarshaledCoordSys) ;
		});
	}
	//Dasmi.getAllLabels( function(labels) {
	dwr.util.removeAllOptions("labels");
	dwr.util.addOptions("labels", ['experimental', 'literature curated', 'predicted']) ;
	//});
	//dwr.engine.endBatch();
}





/**
* Helper function to convert the array of coordinate system objects into 
* an array of descriptive strings for display purposes
* Stores coordinate systems in a cache to later retrieve the full information
* when preparing the objects for marshalling
*/
function unmarshalCoordSys(coordinateSystems){
	var coordArray = new Array();
	for (var i = 0; i < coordinateSystems.length; i++){
		//alert(dump(coordinateSystems[i]));
      	var hash = getCoordSysHash(coordinateSystems[i]);
		coordArray.push(hash);
		coordSysCache[hash] = coordinateSystems[i];
	}
	//alert(dump(coordSysCache));
	return coordArray;
}


/**
* Converts the array of coordinate system hashes into an array of coordinate
* system objects retrieving the original coordinate systems form the cache
*/
function marshalCoordSys(coordSysStringArray){
//alert(dump(coordSysStringArray));
	var coordSysArray = new Array();
	
	if (coordSysStringArray != undefined){
		for (var i = 0; i < coordSysStringArray.length; i++){
			var coordSys = coordSysCache[coordSysStringArray[i]]
			//alert(coordSys);
			if (coordSys != undefined){
				coordSysArray.push(coordSys);
			}
		}
	}
	//alert(dump(coordSysArray));
	return coordSysArray;
}


/**
* Converts the coord sys abbreviation, e.g. "uniprot" or "giid" to 
* the string version of the coord sys, e.g. "UniProt,Protein Sequence"
*/
function getCoordSysString(csAbbr){
	if (csAbbr == "entrez"){
		return "Entrez,Gene_Identifier";
	} else if (csAbbr == "pfam_id") {
		return "Pfam,Protein Sequence";
	} else if (csAbbr == "uniprot_id") {
		return "UniProt,Protein Sequence";
	}else if (csAbbr == "uniprot_ac") {
		return "UniProt,Protein Sequence";
	}else if (csAbbr == "giid") {
		return "Gene Info Identifier";
	}else if (csAbbr == "refseq") {
		return "RefSeq";
	}else if (csAbbr == "ensembl") {
		return "Ensembl,Protein Sequence";
	}
}
/*
function getPrintableCSString(csAbbr){
	csAbbr = csAbbr.toLowerCase;
	if (csAbbr == "entrez" || csAbbr = "entrez,gene_identifier"){
		return "Entrez Gene";
	} else if (csAbbr == "pfam_id" || csAbbr == "pfam,protein sequence") {
		return "Pfam";
	} else if (csAbbr == "uniprot_id" || csAbbr = "uniprot_ac" || csAbbr = "uniprot" || csAbbr == "uniprot,protein sequence") {
		return "UniProt KB";
	}else if (csAbbr == "uniprot_ac" || csAbbr ==) {
		return "UniProt,Protein Sequence";
	}else if (csAbbr == "giid" || csAbbr == "Gene Info Identifier") {
		return "Gene Info Identifier";
	}else if (csAbbr == "refseq" || csAbbr ==) {
		return "RefSeq";
	}else if (csAbbr == "ensembl" || csAbbr == "Ensembl,Protein Sequence") {
		return "Ensembl,Protein Sequence";
	}
}
*/

/**
* Converts the coordinate system to its identifieng string,
* containing the authority, category and if present version and organism 
*/
function getCoordSysHash(coordSys){
   	var coord = coordSys["name"];
  	if (coordSys["version"].length > 0){
   		coord = coord + "_" + coordSys["version"];
   	}
   	coord = coord + "," + coordSys["category"];
   	if (coordSys["organismName"].length > 0){
   		coord = coord + "," + coordSys["organismName"];
   	}
	return coord;
}



var tooltips = new Array();






function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/**
* Returns the tooltip with the given id
*/ 
function tt(id){
	return tooltips[id];
}

/**
* Error Handler.
*/
function errh(msg) {
	/*clearMainArea();
	closeArea("configArea");
	dwr.util.setValue("infoH1", "System Error");
	dwr.util.setValue("infoContent", "<p class=\"serverError\">We are sorry, but a server error has occured. The reason for this can be a temporary connection disruption or a restart of our application server. We will try to reload <span class=\"dasmiweb\">DASMIweb</span> in five seconds.</p><p class=\"serverError\">If this error message remains, please <a href=\"contact.php\">contact us</a>!</p>  ", {escapeHtml:false});
	if (msg == "Internal Server Error"){
		window.setTimeout ('redirect_to (location.href)', 5000);
	}*/
}


/**
* Sumbit the query after ENTER has been pressed.
*/
function submitEnter(e){
	var key = window.event ? e.keyCode : e.which;
	if (key == "13"){
        querySources();
    }
}


/**
* Actually forgot why I needed this ...
*/
function doNothing(){

}



/**
* Return the position of an element given its id. The return value is a [left,top] pair.
*/
function findPos(obj) {
	var border = posBorder();
	var curleft = 0 ;
	var curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft-border[0],curtop-border[1]];
}


/**
* MPII has a strang layout that sets the col2o2 as root element, and corrupts the offset
* This function returns the strange offet and can be used to determine the real offset of an elememnt
*/
function posBorder() {
	var col2 = $("col2o2");
	var curleft = col2.offsetLeft;
	var curtop = col2.offsetTop;
	return [curleft,curtop];
}


/**
* Set the focus on certain elements
*/
var activeId = null;

function focusDelayed(id){
	$(activeId).focus();
}

function setFocus(id){
	if (id != undefined){
		// delay the focus for 0.1 secs due to an IE bug
		activeId = id;
		setTimeout("focusDelayed()", 50 );
	}
}


/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*
* copied from http://binnyva.blogspot.com/2005/10/dump-function-javascript-equivalent-of.html
* (c) Binny V A
*/
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
			if (typeof(value) == 'function') {
				
			}
			else if(typeof(value) == 'object') { //If it is an array,
	   			dumped_text += level_padding + "'" + item + "' ...\n";
   				dumped_text += dump(value,level+1);
  			} else {
   				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  			}
 		}
	}else { //Stings/Chars/Numbers etc.
 		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

var x_cookieName = "dasmicookietest"; // unique




function cookiesAccepted(url){
	alert (cookieTest(url));
}


function cookieTest(tmpUrl){
	var x_domain  = ".mpg.de"; // set to whatever domain you want to test, with the standard provisos
	var urlparts = tmpUrl.split("//");
	
	if (urlparts[1] != null){
		urlparts = urlparts[1].split("/")
	}
	var domain = "";
	if (urlparts[0] != null){
		domain = urlparts[0];
	}
	if (domain.length == 0){
		domain = x_domain;
	}else{
		domain = "."+domain;
	}
	//alert(domain);
	var x_expires = new Date(); 
	x_expires.setFullYear(x_expires.getFullYear()+1); // testing persistent cookies
	xDeleteCookie(x_cookieName); // don't get false positive

	// add path if you want to. drop expires for session cookie. drop domain for default domain test.
	document.cookie = x_cookieName + "=test; expires=" + x_expires.toGMTString() + "; domain=" + domain;

	// now look for it.
	var x_cookieString = document.cookie || "";
	var x_cookies = x_cookieString.split(/\s*;\s*/);
	var x_found = 0;
	for (var i in x_cookies) {
		//alert(dump(x_cookies[i]));
		if((typeof(x_cookies[i]) == "string") && (x_cookies[i].length > 0)) {
			var cookie = x_cookies[i];
			var dough = cookie.split(/\s*=\s*/);
			if (dough[0] == x_cookieName) { 
				x_found = 1; 
				break; 
			}
		}
	}

	// ensure it's gone
	xDeleteCookie(x_cookieName);

	// do whatever you want with x_found bool
	if (x_found == 1) {
		//alert("Cookie accepted.");
		return true;
	}
	else {
		//alert("It's all gone pear shaped.");
		return false;
	}
}

function xDeleteCookie(name) {
	var oldDate = new Date(1970, 1, 1);
	document.cookie = x_cookieName + "=0; expires=" + oldDate.toGMTString();
}


