function validateFormOnSubmit(theForm) {
	var reason = "";

	  reason += validateEmpty(theForm.title);
	  reason += validateEmpty(theForm.url);
	  reason += validateEmpty(theForm.tags);
	  reason += validateEmpty(theForm.description);
	  reason += validateEmail(theForm.email);
		  
	  if (reason != "") {
		alert("Some fields need correction:\n" + reason);
		return false;
	  }

	  return true;
	}

function validateEmpty(fld) {
		var error = "";
	 
		if (fld.value.length == 0) {
			fld.style.background = 'Yellow'; 
			error = "A required field has not been filled in.\n"
		} else {
			fld.style.background = 'White';
		}
		return error;  
	}

function trim(s)
	{
	  return s.replace(/^\s+|\s+$/, '');
	}

function validateEmail(fld) {
		var error="";
		var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
		var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	   
		if (fld.value == "") {
			fld.style.background = 'Yellow';
			error = "You didn't enter an email address.\n";
		} else if (!emailFilter.test(tfld)) {              //test email for illegal characters
			fld.style.background = 'Yellow';
			error = "Please enter a valid email address.\n";
		} else if (fld.value.match(illegalChars)) {
			fld.style.background = 'Yellow';
			error = "The email address contains illegal characters.\n";
		} else {
			fld.style.background = 'White';
		}
		return error;
	}

function toggleDiv(id,flagit) {
	if (flagit=="1"){
	if (document.layers) document.layers[''+id+''].visibility = "show"
	else if (document.all) document.all[''+id+''].style.visibility = "visible"
	else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible"
	}
	else
	if (flagit=="0"){
	if (document.layers) document.layers[''+id+''].visibility = "hide"
	else if (document.all) document.all[''+id+''].style.visibility = "hidden"
	else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden"
	}
	}

function wopen(url, name, w, h)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
	w = screen.width;
	wleft = 0;
  }
  if (wtop < 0) {
	h = screen.height;
	wtop = 0;
  }
  var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no');
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}
