<!--

function exitField(f1)
{
   f1.style.background="#FFFFFF";
}

function enterField(f1)
{
   f1.style.background="#F0F8F0";
}


var marked = "#000000", faint="#B5D6BD", white = "#FFFFFF";
var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZŠŒŽŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßabcdefghijklmnopqrstuvwxyzšœžƒàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
var quote = '"', num = "0123456789", basic = "--'!?, \t\r\n\f"+quote, extended = ".:;";
var full = "-,.!?;/:+%^*#~[]{}@()£&$-' \t\r\n\f"+quote;
var urlcodes = ".?:/+%$@_-=";
var emailcodes = ".@_-";

var error, errordetected, changedetected;
var cell, font, str;

var Month = new Array(12);
	Month[0] =  "January";
	Month[1] =  "February";
	Month[2] =  "March";
	Month[3] =  "April";
	Month[4] =  "May";
	Month[5] =  "June";
	Month[6] =  "July";
	Month[7] =  "August";
	Month[8] =  "September";
	Month[9] =  "October";
	Month[10] = "November";
	Month[11] = "December";

var DayofWeek = new Array(7);
	DayofWeek[0] =  "Sunday";
	DayofWeek[1] =  "Monday";
	DayofWeek[2] =  "Tuesday";
	DayofWeek[3] =  "Wednesday";
	DayofWeek[4] =  "Thursday";
	DayofWeek[5] =  "Friday";
	DayofWeek[6] =  "Saturday";
	
var bgCol = new Array(6);
	bgCol[0] = "#CCCCFF";
	bgCol[1] = "#EEFFEE";
	bgCol[2] = "#FFFFEE";
	bgCol[3] = "#FFFFE6";
	bgCol[4] = "#FFFFDD";
	bgCol[5] = "#CCFFFF";

function CleanStr(checkStr, checkOK)
{
 var newstr = "";
 var i, ch;
 for (i = 0;  i < checkStr.length;  i++)
 {
    ch = checkStr.charAt(i);
	if (checkOK.indexOf(ch)>-1)
       newstr = newstr + ch;  
  }
  error = checkStr != newstr;
  return newstr;
}

function SentenceStyle(checkStr)
{
 var newstr = "", punc = " ,;:-", punc2 = ".!?";
 var i, j, ch;
 var wposn = 0, sposn = 0;
 var cap = alpha.length/2;
 for (i = 0;  i < checkStr.length;  i++)
 {
    ch = checkStr.charAt(i);
	if (punc.indexOf(ch)>-1) wposn=0;
	else 
	if (punc2.indexOf(ch)>-1) sposn=0;
	else 
	{
	  j = alpha.indexOf(ch);
	  if (j>-1)
	  {
	    if (j >= cap)
		{
		  if (sposn == 0) ch = ch.toUpperCase();
		}
		else 
		  if (wposn > 0) ch = ch.toLowerCase();  
	    wposn++;
 	    sposn++;
	  }
	}
	newstr = newstr + ch;
  }
  error |= (checkStr != newstr);
  return newstr;
}

function Replace(checkStr, ch1, ch2)
{
 var newstr = "";
 var i, ch;
 for (i = 0;  i < checkStr.length;  i++)
 {
    ch = checkStr.charAt(i);
	newstr = newstr + ((ch == ch1) ? ch2 : ch);
  }
  return newstr;
}

function GetSeqUntil(chars)
{
  var newstr = "";
  var i,ch;
  if (str != null)
  {
	  for (i = 0;  i < str.length;  i++)
	  {
		ch = str.charAt(i);
		if (chars.indexOf(ch)>-1)
		{
		  str = str.substr(i,str.length);
		  return newstr;
		}
		else
		  newstr = newstr+ch;
	  }
  }
  str = null;
  return newstr; 
}

function SkipZero(str)
{
  var i;
  if (str != null)
	for (i = 0;  i < str.length;  i++)
	  if (str.charAt(i) != '0')
		return str.substr(i,str.length);
  return null;
}

function ReplaceStr(checkStr, checkOK, replacement)
{
 var newstr = "";
 var i, j, ch;
 for (i = 0;  i < checkStr.length;  i++)
 {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
      {
	    ch = replacement;  
		break;
	  }
	newstr = newstr + ch;
  }
  error = checkStr != newstr;
  return newstr;
}

function number(string, mini, maxi)
{
	var n = parseInt(SkipZero(string));
	if (isNaN(n)) 
		n = 0;
	if (n > maxi) 
		n = maxi;
	else
	if (n < mini) 
		n = mini;
	return n;
}

function paddigits(val, n)
{
	var s = val.toString(), i;
	if (s.length > n)
	  s = s.substring(s.length-n,s.length);
	else
	  for (i = s.length; i < n; i++)
		s = "0"+s;
	return s;
}

var dd, mm, yy;
function ParseDate(date)
{
   var punc = " .,:;/\\"
   str = date;
   dd = number(GetSeqUntil(punc), 1, 31);
   GetSeqUntil(num);
   mm = number(GetSeqUntil(punc), 1, 12);
   GetSeqUntil(num);
   yy = number(GetSeqUntil(punc), 0, 99);
   return str;
}

function date2str(date)
{
   yy = date.getYear();
   mm = date.getMonth()+1;
   dd = date.getDate();// curious bug! getDate <-> getDay
   return paddigits(dd,2) + "/" + paddigits(mm,2) + "/" + paddigits(yy,2);
}

function CleanDate(date)
{
   var copy, now = new Date(), newdate;
   ParseDate(date); 
   newdate = new Date(yy+2000,mm-1,dd,0,0,0,0,0);
   if (newdate < now) newdate = now; 
   copy = date2str(newdate);
   error = copy != date;
   return copy;
}

function DateStr(date)
{
  var newdate;
  ParseDate(date);
  newdate = new Date(yy+2000,mm-1,dd,0,0,0,0,0);
  return DayofWeek[newdate.getDay()]+ " " + dd + " " + Month[mm-1] + " " + (yy+2000);
}

function DateStr2(date1, date2)
{
  var newdate, yy2, mm2, str;
  ParseDate(date2);
  yy2=yy;
  mm2=mm;
  ParseDate(date1);
  newdate = new Date(yy+2000,mm-1,dd,0,0,0,0,0);
  str = DayofWeek[newdate.getDay()]+ " " + dd;
  if (yy != yy2)
  	str = str + " " + Month[mm-1] + " " + (yy+2000);
	else
		if (mm != mm2)
			str = str + " " + Month[mm-1];
  return str;
}


function ampm(str)
{
   var s;
   if (str)
   {
	 s = str.charAt(0);
	 return ((s == 'a') || (s == 'A')) ? 2 : 
	 		((s == 'p') || (s == 'P')) ? 1 : 0;
   }
   return 0;
}

function CleanTime(time)
{
   var hh, mm, pm;
   var punc = " .,:;/\\apmAPM", copy, s;
   copy = time;
   str = time;
   hh = number(GetSeqUntil(punc), 0, 24);
   if (hh == 24) hh = 0;                // 24:00 = 00:00
   pm = ampm(GetSeqUntil(num));
   mm = number(GetSeqUntil(punc), 0, 59);
   pm |= ampm(str);
   if ((pm == 1) && (hh < 12)) hh += 12; // 12pm = 12:00
   if ((pm == 2) && (hh == 12)) hh = 0; // 12am = 0:00
   time = paddigits(hh,2) + ":" + paddigits(mm,2);
   error = copy != time;
   return time;
}

function ColourCode(element, edit)
{  
  if (edit)
  {
	//window.location = "#form";
	element.focus();
  	cell.style.backgroundColor = marked;
	if (font) font.style.color = white;
	errordetected = true;
  }
  else
  {
	if (error)
	{
	    changedetected = true;
		cell.style.backgroundColor = faint;
		if (font) font.style.color = white;
	}
	else
	{
	    cell.style.backgroundColor = white;
		if (font) font.style.color = marked;
	}
  }
}

function Evaluate(element, filter, minlen)
{
  element.value = CleanStr(element.value, filter);
  ColourCode(element, element.value.length < minlen);
}

function EvaluateSentence(element, filter, minlen)
{
  element.value = SentenceStyle(CleanStr(element.value, filter));
  ColourCode(element, element.value.length < minlen);
}

function EvaluateLimit(element, filter, minlen, maxlen)
{
  element.value = CleanStr(element.value, filter);
  if (element.value.length > maxlen)
  {
  	element.value = element.value.substring(0, maxlen);
	error = true;
  }
  ColourCode(element, element.value.length < minlen);
}

function EvaluateURLorMailTo(element, http)
{
  var c, str = CleanStr(element.value, alpha+num+urlcodes);
  c = str.indexOf(':');
  if ((http !=2) && ((str.indexOf('@') > -1) == http))
    errordetected = true;
  else
  if (str.indexOf('@') == -1)
  {
  	if (c > -1)
	{
	   while (str.charAt(++c) == '/');
	   str = str.substring(c, str.length);
	}
    if (str.indexOf('@') > -1)
 		errordetected = true;
  }
  else 
  { 
    if (c > -1) str = str.substring(++c, str.length);
	if (str.indexOf('@') == -1)
		errordetected = true;
  }

  if (str != element.value) 
  {
  	error = true;
	element.value = str;
  }
  ColourCode(element, errordetected || (element.value.length < 1));
}

function EvaluateUpper(element, filter, minlen)
{
  var str = CleanStr(element.value, filter);
  str = str.toUpperCase();
  if (str != element.value) 
  {
  	error = true;
	element.value = str;
  }
  ColourCode(element, element.value.length < minlen);
}

function EvaluateDate(element)
{
  element.value = CleanDate(element.value);
  ColourCode(element, false);
}

function EvaluateDateDiff(element1, element2)
{
  var date1, date2;
  ParseDate(element1.value);
  date1 = new Date(yy+2000,mm-1,dd,0,0,0,0,0);
  ParseDate(element2.value);
  date2 = new Date(yy+2000,mm-1,dd,0,0,0,0,0);
  if (date2<date1)
  {
	error = true;
	element2.value = date2str(date1);
	ColourCode(element2, false);
  }
}

function EvaluateTime(element)
{
  element.value = CleanTime(element.value);
  ColourCode(element, false);
}

function ClearCode(element)
{
  	error = false;
  	element.value = "";
	ColourCode(element, false);
}

function cellfont(base)
{
  cell = document.getElementById(base+'cell');
  font = document.getElementById(base+'col');
}

function pdvalue(element)
{
  return element.options[element.selectedIndex].text;
}

function NonNullStr(element, def)
{
  return (element == "") ? def: element;
}

function set_text(target, element, def)
{
  var t = document.getElementById(target);
  if (t == null)
  	alert("error: target '"+ target +"' not found.");
  t.innerHTML = NonNullStr(element, def);
}

function set_text_opt(target, element, plus)
{
  var t = document.getElementById(target);
  t.innerHTML = (element== "") ? "" : plus+element;
}

function set_text_colour(target, element, def, col)
{
  var t = document.getElementById(target);
  if (t == null)
  	alert("error: target '"+ target +"' not found.");
  t.innerHTML = NonNullStr(element, def);
  t.color = col;
}

function set_url(main, url)
{
  if ((main!="") && (url!=""))
	main = "<a href='http://" + url +"' target=_blank>" + main.fontcolor('#000066') + "</a>";
  return main;
}

function set_text_url(target, main, def, url)
{
  set_text(target, set_url(main, url), def);
}

function set_seq_text(target, prefix, main, url, suffix, opt)
{
  if (main!="")
  {
	str = prefix+" "+set_url(main, url);
	if (suffix!="") str+=", "+suffix;
  }
  else
    str="";
  set_text_opt(target, str, opt);
}

function ActionConfValidator(theForm)
{
  errordetected = false;
  changedetected = false;
  marked = "#000000";  // not mandatory

  cellfont('comments');
  EvaluateLimit(theForm.Submitted_Comments.value, alpha+num+basic, 0, 200);

  marked = "#990099"; 

  cellfont('by');
  Evaluate(theForm.Submitted_By.value, alpha+num+emailcodes, 8);
  return !(errordetected || changedetected);
}

function March20Validator(theForm)
{
  errordetected = false;
  changedetected = false;
  
  marked = "#000000";

  cellfont('EventURL');
  EvaluateURLorMailTo(theForm.EventURL, true);

  marked = "#339966"; 
  cellfont('org');
  Evaluate(theForm.Organisation, alpha+num+full, 0);

  cellfont('date')
  EvaluateDate(theForm.EventDate);

  cellfont('time')
  EvaluateTime(theForm.StartTime);
  
  marked = "#000000"; 
  cellfont('country');
  Evaluate(theForm.Country, alpha+full, 2);

  cellfont('city');
  Evaluate(theForm.City, alpha+full, 3);

  marked = "#339966"; 
  cellfont('assemble');
  Evaluate(theForm.AssemblyPoint, alpha+num+full, 0);

  font = document.getElementById('errcol');
  font.style.color = errordetected ? 0 : white;
  
  return (!(errordetected || changedetected));
}

function code2mapurl(postcode)
{
	return (postcode == "") ? "" : "http://www.multimap.com/map/browse.cgi?pc=" + Replace(postcode,' ','+');
}

function openwindow(url, opt)
{
 var rep = 1, win, platform;
 if (navigator.appVersion.substring(0,1) == "2")
 {
  platform=navigator.appVersion;
  if ((platform.indexOf("X11")!=-1) || (platform.indexOf("Mac")!=-1)) rep = 2;
 }
 for (;rep;rep--)
    win = window.open(url, 'example', opt);
 if (win != null) win.creator = self;
 return win;
}

function Map(theForm)
{
	var url;
	errordetected = false;
	cell = document.getElementById('pcodecell');
	font = null;
	EvaluateUpper(theForm.PostCode, alpha+num+" ", 5);
	if (!errordetected)
	{
	  url = code2mapurl(theForm.PostCode.value);
	  openwindow(url, "");
	}
	return (false);
}

function TestURL(theForm, id, http)
{
	var url, element;
	errordetected = false;
	element = document.getElementById(id);
	cellfont(id);
	EvaluateURLorMailTo(element, http);
	if (!errordetected)
	  if (http)
	    openwindow("http://"+element.value, "");
	  else
	  	window.location = "mailto:"+element.value;
	return (true);
}

function March20Reset(theForm)
{
  marked = "#000000";  

  cellfont('EventURL');
  ClearCode(theForm.EventURL);
  
  marked = "#339966"; 
  cellfont('org');
  ClearCode(theForm.Organisation); 

  cellfont('time');
  ClearCode(theForm.StartTime);

  cellfont('date');
  ClearCode(theForm.EventDate);

  marked = "#000000";  
  
  cellfont('country');
  ClearCode(theForm.Country);
  
  cellfont('city');
  ClearCode(theForm.City);

  cellfont('assemble');
  ClearCode(theForm.AssemblyPoint);
  
  font = document.getElementById('errcol');
  font.style.color = white;
  return false;
}

function SetJS(str)
{
  var wid
  cell = document.getElementById('pad');
  cell.value = '<script language="JavaScript" src="http://www.stopwar.org.uk/march20/public/' + str + '.js"></script> Courtesy of <a href="http://www.stopwar.org.uk/march20/index.asp" target=_blank><img src="http://www.stopwar.org.uk/march20/images/m20.gif" alt="add event to march20th.org" width=52 height=20 border=0 align=absmiddle> Add</a>. See also <a href="http://www.unitedforpeace.org/calendar.php?caltype=17" target=_blank>United For Peace &amp; Justice</a>.';
  openwindow("example.asp?src="+str, "height=400,width=200,status=0,menubar=0,scrollbars=1").focus();
  return false;
}


//-->
