function $() {
    var element = arguments[0];
    if (document.getElementById) {
        element = document.getElementById(element);
    } else if (document.all) {
        element = document.all[element];
    }
    return element;
}

function showwaiver()
{
    MyWindow = window.open('waiver.txt', 'MyWindow1', 'toolbar=no,' +
        'location=no,directories=no, status=no,menubar=no,scrollbars=yes,' +
        'resizable=yes,width=700,height=300');
}

function showform()
{
    var rf = $('rf')
	//    alert("hello bello " + rf);
    rf.style.display = "block";
}

function bigboxes()
{
    $('gender').style.width = "auto";
    $('shirtsize').style.width = "auto";
    $('experience').style.width = "auto";
    $('height').style.width = "auto";
    $('knowledge').style.width = "auto";
    $('throws').style.width = "auto";
    $('athleticism').style.width = "auto";
    $('spirit').style.width = "auto";
}

function clear_field(the_field)
{
	the_field.value = "";
	the_field.onfocus = "";
}

function verify_form(the_form)
{
	var msg = "";
	var errors = 0;
	var x, y;
	var error_color = "pink";

	x = the_form.name;
	if (x.value.length <= 1 || x.value.search(/\b[A-z]+\s+\b[A-z]+/)==-1) {
		errors++;
		msg = msg+errors+": Please enter your first and last name.\n";
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	x = the_form.email;
	var bad_email = false;
	if (x.value.length <= 6) {
		errors++;
		msg = msg + errors + ": E-Mail addresse too short.\n";
		bad_email = true;
	} else if (x.value.indexOf("@") == -1 || x.value.indexOf(".") == -1) {
		errors++;
		msg = msg + errors +
		    ': E-Mail address must have the "@" and "." characters\n';
		bad_email = true;
	}
	if (bad_email) {
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	x = the_form.waiver;
	if (x.value.toLowerCase() != "i agree" &&
	    x.value.toLowerCase() != "i agree." &&
	    x.value.toLowerCase() != '"i agree"' &&
	    x.value.toLowerCase() != '"i agree."' ) {
		errors++;
		msg = msg + errors + ": Acknowledge the waiver.\n";
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	x = the_form.gender;
	if (x.value.length <= 0) {
		errors++;
		msg = msg + errors + ": Choose a gender.\n";
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	x = the_form.shirtsize;
	if (x.value.length <= 0) {
		errors++;
		msg = msg + errors + ": Choose a shirt size.\n";
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	x = the_form.experience;
	if (x.value.length <= 0) {
		errors++;
		msg = msg + errors + ": Ultimate Experience.\n";
		x.style.backgroundColor = error_color;
	} else {
		x.style.backgroundColor = "";
	}

	if (errors > 0) {
		window.location='#reg';
		alert("Thank you for registering with Bend Ultimate!\n"
		      + "You must correct " + errors + " error(s) before\n"
		      + "continuing.  The relevant fields have been\n"
		      + "highlighted for you.\n\n"
		      + msg);
		return false;
	}
	return true;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return unescape(results[1]);
}

function form_prefill()
{
    var rf = $('rf');
	/*  alert('hello world: '+ rf) */
    rf.name.value = gup('n');
    rf.email.value = gup('e');
    rf.gender.value = gup('g');
    rf.shirtsize.value = gup('s');
    if (rf.name.value.length > 0) {
        rf.waiver.value = "I agree."
    }
}
