

// 
// Firefox does not have event.keyCode. It only handles "document.onkeypress = function(e)"
// Save global lastEventCode for later use.
//
var lastEventCode = null;
if (typeof(window.event) != 'undefined') 
{
	lastEventCode = null;
}
else 
{
	document.onkeypress = function(e)
	{
		lastEventCode = e.keyCode;
		// if (e.target.nodeName.toUpperCase() == 'INPUT')
		// 			return isValidChar(e.keyCode);   // Keycode is always 0 exept for special chars.
	}
}

function isValidChar(ch)
{
	//
	// This function has serious problems with unicode...
	//
	return true;
	/*	
	return 		ch >= "A".charCodeAt(0) && ch <= "Z".charCodeAt(0) ||
				ch >= "a".charCodeAt(0) && ch <= "z".charCodeAt(0) ||
				ch == "Å".charCodeAt(0) || ch == "å".charCodeAt(0) ||
				ch == "Ä".charCodeAt(0) || ch == "ä".charCodeAt(0) ||
				ch == "Ö".charCodeAt(0) || ch == "ö".charCodeAt(0) ||
				ch == "É".charCodeAt(0) || ch == "é".charCodeAt(0) ||
				ch == "Ü".charCodeAt(0) || ch == "ü".charCodeAt(0) ||
				ch == "Á".charCodeAt(0) || ch == "á".charCodeAt(0) ||
				ch == "À".charCodeAt(0) || ch == "à".charCodeAt(0) ||
				ch == "Í".charCodeAt(0) || ch == "í".charCodeAt(0) ||
				ch == "Ì".charCodeAt(0) || ch == "Ì".charCodeAt(0) ||
				ch == "Ï".charCodeAt(0) || ch == "ï".charCodeAt(0) ||
				ch == "*".charCodeAt(0) || 
				ch == "?".charCodeAt(0) || 
				ch == "'".charCodeAt(0) ||
				ch == "-".charCodeAt(0) ||
				ch == " ".charCodeAt(0) ||
				ch == "#".charCodeAt(0) ||
				ch == "@".charCodeAt(0) ||
				ch == "[".charCodeAt(0) ||
				ch == "]".charCodeAt(0) ||
				ch == 13;		// RETURN
	*/
}

function eventToUpper()
{
	// Check if is character...
	event.returnValue = isValidChar(event.keyCode);

	event.keyCode = String.fromCharCode(event.keyCode).toUpperCase().charCodeAt(0);
	
	return event.returnValue;
}

function handleKeys(form, field)
{
	if (typeof(window.event) != 'undefined')
		lastEventCode = event.keyCode;
		
	if (lastEventCode == 8 && field > 1)		// BACKSPACE
	{
		if (document.forms[form].elements["L" + field].value.length > 0)
		{
			document.forms[form].elements["L" + field].value = "";
		}
		else
		{
			document.forms[form].elements["L" + (field - 1)].value = "";
			document.forms[form].elements["L" + (field - 1)].focus();
		}
		return;
	}

}

function fieldToUpper(form, field)
{
	document.forms[form].elements["L" + field].value = document.forms[form].elements["L" + field].value.toUpperCase();
}

function checkField(form, field)
{
	if (!isValidChar(document.forms[form].elements["L" + field].value.charCodeAt(0)))
		document.forms[form].elements["L" + field].value = "";
}

function checkFieldLong(form, field)
{
	sOld = document.forms[form].elements[field].value;
	sNew = "";
	for (i = 0; i < sOld.length; i++)
	{
//alert(sOld.charAt(i));
		if (isValidChar(sOld.charCodeAt(i)))
			sNew = sNew + sOld.charAt(i);
	}
	document.forms[form].elements[field].value = sNew;
}

function nextField(form, field)
{
	var len = document.forms[form].elements["L" + field].value.length;
	if (len >= 1)
			document.forms[form].elements["L" + (field + 1)].focus();
}

function antiEmailRobotImg(imgsrc, name, domain){
	document.write("<a href=" + "mail" + "t" + "o:" + name + "@" + domain + ">" + name + "<img valign=absmiddle src=" + imgsrc + " border=0>" + domain + "</a>");
}

function antiEmailRobot(name, domain){
	document.write("<a href=" + "mail" + "t" + "o:" + name + "@" + domain + ">" + name + "@" + domain + "</a>");
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}