/**
*  	JavaScript functions for the MedOBIS website
*  
*	Filename: medobis_script.js
*	Author: Sarah Faulwetter
*  	Last update: June 18th, 2005	
**/


//-------------------------  highlights stations on the map -------------------------------
 

function highlight(jsarray, win)	
{

// transforming the string into an array

	var arr= jsarray;
	var ids = jsarray.split(" ");
	var lg = ids.length;

//set layer
	if (win=="self") 
	{	
		//alert(top.applet.document.mapApplet.name);
		appl=top.applet.document.mapApplet;
		var map= appl.getMap();

	}
	if (win=="o") 	// calling form normal result window
	{
		appl=opener.top.applet.document.mapApplet;
		var map= appl.getMap();
	}	
	if (win=="oo")  //calling from advanced search window
	{
		appl=opener.opener.top.applet.document.mapApplet;
		var map= appl.getMap();
	}

	var lyr = map.getProject().getLayerByName("Stations");
	map.setActiveLayer(lyr);


// transform the array into a Vector of records
	
	var v = appl.createVector();
	
	for(i=0;i<lg;i++)
	{
		var rec = lyr.findById(ids[i]);
		v.addElement(rec); 

	}
	
//select on map	

	map.zoomToFullExtent();
	lyr.setSelection(v);
	map.updateMap();
	map.updateMap();

}




//------------------ function to open results window as a popup -------------------------------


function popupform(form, windowname, h, w, l, t)
{
	size= "height="+h+",width="+w+",left="+l+",top="+t+",scrollbars=yes,resizable=yes";
	if (! window.focus) return true;
	window.open('', windowname, size);
	form.target=windowname;
	return true;
}



//------------------ function to show date of last modification -------------------------------

  	
function updt() 
{	
	lastmod=new Date(document.lastModified);
	year=lastmod.getFullYear();
	var str = "Last update: "+ lastmod.getDate()+"."+(lastmod.getMonth()+1)+ "."+year;
	document.write(str); 
}


//------------------ function to write station IDs into hidden form field -------------------------------


function passIDs()
{
	if(self.location == null) 
	{
		return "";
	}

	var srch = self.location.search;

	if (srch.length==0) 
	{
		return "";
	}

	srch = srch.slice(1);
	top.applet.document.choiceMenu.statIDs.value=srch;
}


//------------------ function to highlight the navigation buttons -------------------------------




contact = new Image();
contact.src = "medimages/contacts.gif";
contact_rlvr = new Image();
contact_rlvr.src = "medimages/contacts_rlvr.gif";

downloads = new Image();
downloads.src = "medimages/downloads.gif";
downloads_rlvr = new Image();
downloads_rlvr.src = "medimages/downloads_rlvr.gif";

link = new Image();
link.src = "medimages/links.gif";
links_rlvr = new Image();
links_rlvr.src = "medimages/links_rlvr.gif";

home = new Image();
home.src = "medimages/home.gif";
home_rlvr = new Image();
home_rlvr.src = "medimages/home_rlvr.gif";

mail_list = new Image();
mail_list.src = "medimages/mail_list.gif";
mail_list_rlvr = new Image();
mail_list_rlvr.src = "medimages/mail_list_rlvr.gif";

partners = new Image();
partners.src = "medimages/partners.gif";
partners_rlvr = new Image();
partners_rlvr.src = "medimages/partners_rlvr.gif";

projct_info = new Image();
projct_info.src = "medimages/projct_info.gif";
projct_info_rlvr = new Image();
projct_info_rlvr.src = "medimages/projct_info_rlvr.gif";

publications = new Image();
publications.src = "medimages/publications.gif";
publications_rlvr = new Image();
publications_rlvr.src = "medimages/publications_rlvr.gif";

whats_new = new Image();
whats_new.src = "medimages/whats_new.gif";
whats_new_rlvr = new Image();
whats_new_rlvr.src = "medimages/whats_new_rlvr.gif";



function rollover(nr,object)
	{
		window.document.images[nr].src = object.src;
	}




/***************************************************************************
 *
 *   BEWARE! The following code is subject to a license!
 *
 ***************************************************************************/


/***************************************************************************
 *                                show.js
 *                            -------------------
 *   copyright            : (C) 2005 Panayiotis P. Gotsis
 *   email                  : g_panayiotis@hotmail.com
 *
 *   The source code contained herein is considered trivial. However I decide to
 *   release it under GPLv2 cause there are some people who seem to even steal 10
 *   lines of code instead of typing something on their own, *forgeting* to mention
 *   where they got this code from.
 * 
 *   These functions would not have been conceived of, if it wasn't for the inspiration
 *   offered by a similar feature on the website of the Management School of the
 *   University of Lancaster.
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of version 2 of the GNU General Public License as published by
 *   the Free Software Foundation.
 *
 ***************************************************************************/


function showEmail(el,caption,cipher)
{
	document.getElementById(el).innerHTML="<a href=\"mailto:" + decodeEmail(cipher) + "\">"+caption+"</a>";
}

function computeCipher(fromEl,toEl)
{
	document.getElementById(toEl).value=encodeEmail(document.getElementById(fromEl).value);
}

function decodeEmail(txtIn)
{
	var s;
	
	s=xorChar(hex2bin(txtIn));
//	s=hex2bin(txtIn);

	return s;
}

function encodeEmail(txtIn)
{
	var s;
	
	s=bin2hex(xorChar(txtIn));
//	s=bin2hex(txtIn);
	
	return s;
}

function xorChar(txtIn)
{
	var txtLen;
	var key;
	var i;
	var el;
	var s;

	key=189;
	
	txtLen=txtIn.length;
	s='';
	for (i=0;i<txtLen;i++)
	{
		el=txtIn.charCodeAt(i) ^ key;
		s=s+String.fromCharCode(el);
	}

	return s;
}

function bin2hex(txtIn)
{
	var txtLen;
	var i;
	var el;
	var s;

	txtLen=txtIn.length;
	s='';
	for (i=0;i<txtLen;i++)
	{
		el=(txtIn.charCodeAt(i) & 240) >>> 4;
		if (el==10) { el='a' }
		else if (el==11) { el='b' }
		else if (el==12) { el='c' }
		else if (el==13) { el='d' }
		else if (el==14) { el='e' }
		else if (el==15) { el='f' }
		s=s + el;

		el=(txtIn.charCodeAt(i) & 15);
		if (el==10) { el='a' }
		else if (el==11) { el='b' }
		else if (el==12) { el='c' }
		else if (el==13) { el='d' }
		else if (el==14) { el='e' }
		else if (el==15) { el='f' }
		s=s + el;
	}
	
	return s;
}

function hex2bin(txtIn)
{
	var txtLen;
	var i;
	var el,out;
	var s;

	txtLen=txtIn.length;
	s='';
	for (i=0;i<txtLen;i=i+2)
	{
		el=txtIn.charAt(i);
		if (el=='a') { el=10 }
		else if (el=='b') { el=11 }
		else if (el=='c') { el=12 }
		else if (el=='d') { el=13 }
		else if (el=='e') { el=14 }
		else if (el=='f') { el=15 }
		out=el*16;

		el=txtIn.charAt(i+1);
		if (el=='a') { el=10 }
		else if (el=='b') { el=11 }
		else if (el=='c') { el=12 }
		else if (el=='d') { el=13 }
		else if (el=='e') { el=14 }
		else if (el=='f') { el=15 }
	
		s=s + String.fromCharCode(out*1+el*1);
	}
	
	return s;
}

