//
//	File:		functions.js
//	Created:	20/01/2009
//

window.onload = init;

function init ()
{
	if (isOldIE ())
	{
		png2gif ();
	}
}

function isOldIE ()
{
	var oldie = false;
	var app = new String (navigator.appName);
	var agent = new String (navigator.userAgent);
	
	if (app.indexOf ("Microsoft Internet Explorer") >= 0)
	{
		if (agent.indexOf ("Opera") < 0)
		{
			if (document.all)
			{
				var i = agent.indexOf ("MSIE");
				var s = new String (agent.substr (i));
				i = s.indexOf (" ");
				s = s.substr (i);
				var v = parseFloat (s);
				if (v < 7)
					oldie = true;
			}
		}
	}
	return oldie;	
}


function png2gif ()
{
	var el;
	var pics = new Array ();
	
	el = getId ("pagetitle");
	pics = el.getElementsByTagName ("img");
	pics[0].setAttribute ("src", "images/perfumestitle.gif");
}


var textList =
	{
		"info": "BG?HgHNL>LUHK@UND",
		"science": "L<B>G<>gHNL>LUHK@UND",
		"membership": "F>F;>KLABIgHNL>LUHK@UND",
		"webmaster": "P>;F:LM>KgHNL>LUHK@UND",
		"Doug Paulley": "=HN@UI:NEE>RgDBG@JN>>GUHK@UND",
		"Steven Rose": "LUIUKUKHL>gHI>GU:<UND"
	};


function getId (id)
{
	return document.getElementById (id);
}

function remove (idList)
{
	var l = idList.length;
	
	for (var i = 0;  i < l;  i++)
	{
		var el = getId (idList[i]);
		el.className = "nodisplay";
	}
}


function display (idList)
{
	var l = idList.length;
	
	for (var i = 0;  i < l;  i++)
	{
		var el = getId (idList[i]);
		el.className = "";
	}
}


function getText (text)
{
	var start = 44;
	var last = 122;
	var mod = last - start;
	var diff = mod / 2;
	var len;
	var ch;
	var nextch = new String();
	var newtext = new String();
	var i;
	
	len = text.length;
	
	for  (i = 0;  i < len;  i++)
	{
		ch = text.charCodeAt (i);
		if  ((ch > start) && (ch <= last))
		{
			ch += diff;
			if  (ch > last)
			{
				ch -= mod;
			}
		}
		nextch = String.fromCharCode (ch);
		newtext = newtext.concat (nextch);
	}
	return newtext;
}


function getCode (text)
{
	var len;
	var ch = new Number();
	var nextch = new String();
	var newtext = new String();
	var i;
	
	len = text.length;
	
	for  (i = 0;  i < len;  i++)
	{
		ch = text.charCodeAt (i);
		nextch = ch.toString (10);
		newtext = newtext.concat ("&#", nextch, ";");
	}
	return newtext;
}


function insert (elist)
{
	var info = new String();
	var ptx = new String();
	var ltx = new String();
	var dtx = new String();
	var el;
	var name;
	var ml = '&#109;&#97;&#105;&#108;&#116;&#111;&#58;';
	
	var len = elist.length;

	for (var i = 0;  i < len;  i++)
	{
		el = getId (elist[i].id);
		name = elist[i].name;
		ptx = elist[i].text;
		dtx = elist[i].display;
		em = new String (textList[name]);
		tx = new String (getText (em));
		ltx = getCode (tx);
		
		if (ptx != "") ptx += " ";
		if (dtx == 0) dtx = ltx;
		
		info = ptx + '<a href="' + ml + ltx +'">' + dtx +'</a>';
		el.innerHTML = info;
	}		
}












