<!--

// subform javascript functions for dreamersreality.com
// pop up code is from http://www.quirksmode.org/js/popup.html
// slightly modified for centering of window

// last update : 27/08/2006 @ 11:06

// whitespace characters
var whitespace = " \t\n\r";


var RecaptchaOptions = { theme : 'clean' };


function checkForm() {
	maxchars = 800;
//	poem_title_check = document.subform.poem_title.value.length;
//	message_check = document.comment_form.message.value.length;
//	title_check = document.comment_form.title.value.length;

	var poem_length_check = document.subform.poem_text.value.length;
	var len = 0;
	var i = 0;

	if ( isBlank(document.subform.poem_title) ) {
		alert('You forgot to enter a title for your poem.');
		subform.poem_title.focus();
		return false;
	}

	// get the value selected in cat_list
	len = document.subform.cat_list.length;
	var cat_list_value = 0;

	for (i = 0; i < len; i++) {
		if (document.subform.cat_list[i].selected) {
			cat_list_value = document.subform.cat_list[i].value
		}
	}

	// get the value selected in author_list
	len = document.subform.author_list.length;
	var author_list_value = 0;

	for (i = 0; i < len; i++) {
		if (document.subform.author_list[i].selected) {
			author_list_value = document.subform.author_list[i].value
		}
	}

	if ( cat_list_value == 0 ) {
		alert('You forgot to choose a Category for your poem.');
		subform.cat_list.focus();
		return false;
	}
/*
	if ( document.subform.cat_list.selectedIndex  == 0 ) {
		alert('You forgot to choose a Category for your poem.');
		subform.cat_list.focus();
		return false;
	}
*/
/*
	if ( isBlank(document.subform.user_name) ) {
		alert('You forgot to enter your Name or Nick.');
		subform.user_name.focus();
		return false;
	}
*/
	if ( isBlank(document.subform.user_email) ) {
		alert('You forgot to enter your E-mail address.');
		subform.user_name.focus();
		return false;
	}

	if ( isBlank(document.subform.poem_text) ) {
		alert('Whoops, you forgot to write in your Poem.');
		subform.poem_text.focus();
		return false;
	}

	var chosen = "";
	len = document.subform.poem_type.length;

	for (i = 0; i <len; i++) {
		if (document.subform.poem_type[i].checked) {
			chosen = document.subform.poem_type[i].value
		}
	}

	if (chosen == "") {
		alert('Whoops, you need to pick the poem type.');
		subform.poem_type.focus();
		return false;
	}

	if ( poem_length_check > 65535 ) {
		alert('Your poem is too large for our database.');
		subform.poem_text.focus();
		return false;
	}

	return true;
}


function popitup_sz(url,strWidth,strHeight)
{

	var strWidth  = (strWidth == null)  ? 400 : strWidth;
	var strHeight = (strHeight == null) ? 400 : strHeight;

	leftPos = 0
	topPos = 0

	if (screen) {
		leftPos = screen.width / 2  - (strWidth / 2)
		topPos  = screen.height / 2 - (strHeight / 2)
	}

	newwindow = window.open(url,'name',"resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",top="+topPos+",left="+leftPos+"");
	if ( window.focus ) { newwindow.focus() }
	return false;
}


function isBlank(tocheck) {

	// check for all whitespace
	if ( isWhitespace(tocheck.value) ) {
		return true;
	}

	// check if zero length or just null value
	if ( tocheck.value.length == 0 || tocheck.value == null ) {
		return true;
	}

	return false;
}


function isWhitespace (s)
{
	var i;

	// Search through strings characters one by one
	// until we find a non-whitespace character
	// When we do, return false; if we dont, return true

	for (i = 0; i < s.length; i++)
	{
		// Check that current character is not whitespace
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) return false;
	}

	// All characters are whitespace
	return true;
}


/*
  this code is from

  Justin Whitford

  http://www.whitford.id.au/webmonkey/code/dropdown.php
*/

/*
  filtery(pattern, list)
  pattern: a string of zero or more characters by which to filter the list
  list: reference to a form object of type, select

  Example:
  <form name="yourForm">
    <input type="text" name="yourTextField"
       onchange="filtery(this.value,this.form.yourSelect)">
    <select name="yourSelect">
      <option></option>
      <option value="Australia">Australia</option>
       .......
*/

function filtery(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
    if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}

/*

first letter alpha filter

changed
if(list.bak[n][1].toLowerCase().indexOf(pattern.toLowerCase())!=-1){
for
if(list.bak[n][1].substring(0,pattern.length).toLowerCase().indexOf(pattern.toLowerCase())!=-1){

*/

function filteryFirst(pattern, list){
  /*
  if the dropdown list passed in hasn't
  already been backed up, we'll do that now
  */
  if (!list.bak){
    /*
    We're going to attach an array to the select object
    where we'll keep a backup of the original dropdown list
    */
    list.bak = new Array();
    for (n=0;n<list.length;n++){
      list.bak[list.bak.length] = new Array(list[n].value, list[n].text);
    }
  }

  /*
  We're going to iterate through the backed up dropdown
  list. If an item matches, it is added to the list of
  matches. If not, then it is added to the list of non matches.
  */
  match = new Array();
  nomatch = new Array();
  for (n=0;n<list.bak.length;n++){
	if(list.bak[n][1].substring(0,pattern.length).toLowerCase().indexOf(pattern.toLowerCase())!=-1){
      match[match.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }else{
      nomatch[nomatch.length] = new Array(list.bak[n][0], list.bak[n][1]);
    }
  }

  /*
  Now we completely rewrite the dropdown list.
  First we write in the matches, then we write
  in the non matches
  */
  for (n=0;n<match.length;n++){
    list[n].value = match[n][0];
    list[n].text = match[n][1];
  }
  for (n=0;n<nomatch.length;n++){
    list[n+match.length].value = nomatch[n][0];
    list[n+match.length].text = nomatch[n][1];
  }

  /*
  Finally, we make the 1st item selected - this
  makes sure that the matching options are
  immediately apparent
  */
  list.selectedIndex=0;
}

//-->
