/// popup window function
function popup(URL,w,h) {

day = new Date();
id = day.getTime();

var width = w;
var height = h;

var left = ((screen.width-width)/2);
var top = ((screen.height-height)/2);

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');");
}

/// popup window function with name
function wpopup(URL,n,w,h,sb) {

day = new Date();

var name = n;
var width = w;
var height = h;
if(sb==null){var scrollbar=1}else{var scrollbar=sb}

var left = ((screen.width-width)/2);
var top = ((screen.height-height)/2);


var features = 'toolbar=0,scrollbars=' + scrollbar + ',location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top;

//eval("page" + name + " = window.open(URL, '" + name + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');");
    
var popWin = window.open(URL, name, features);
popWin.focus();

}

function popWindow(url, name, features) 
{
    var host = location.hostname;
	window.top.name = "opener";
	var popupWin = window.open( url, name, features );
	
	if ( popupWin && popupWin.opener ) {
		if ( openerUrl )
		{
			popupWin.opener.location = openerUrl;
			popupWin.focus();
		}
	}
}


function enable_other()
{
	if (document.getElementById('clubs_other_check').checked)
	{
		document.getElementById('clubs_other').disabled = false;
		document.getElementById('clubs_other').focus();
	}
	else
	{
		document.getElementById('clubs_other').disabled = true;
		document.getElementById('clubs_other').value = "";
	}
}


/////
///onKeyPress="return numbersonly(this, event)";
/////

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if ((("+1234567890").indexOf(keychar) > -1)){
		return true;
	}else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}
}

///// onKeyUp="numTyped(this.value,p3,'3')"
/// jump phone number fields
function numTyped(current, next,maxlen) {
  var len = current.length;
  if (len==maxlen) {
    next.focus();
  }
}

//// form validation

/// form validation starts here

var new_fieldname = ""

//this is the onclick that calls this function
//
// onClick="return check(form,form.elements.length)"
//


function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
		return (true)
	}
	else
	{
		return (false)
	}
}



function check(form,x)

{

	var message = ""
	var more_message = new Array //(4)
	var showmsg = "no"
	var doItNow = "yes"

	var required = new Array (12)

	if (doItNow == "yes") 	{

			var i = 0;

						
						if (count_checkboxes('clubs[]') >= 0 && count_checkboxes('clubs[]') < 3)
							{more_message [i++] = "\nPlease Select at least 3 choices from the activities section"}
						else if (count_checkboxes('clubs[]') > 3)
							{more_message [i++] = "\nPlease Only Select 3 choices from the activities section"}
						
						if (document.getElementById('clubs_other_check').checked && form.clubs_other.value == "")
						{
							more_message [i++] = "\nPlease enter what your other club is";	
						}
						/// end construct messgaes
						if (more_message != "") {

								if (message == "") {message = more_message}

									else

									{message = message + "\n" + more_message}

				        }

						if (message > "")

								{showmsg = "yes"}																

						if (showmsg == "yes")

			{
				alert("The following form field(s) were incomplete or incorrect:\n\n" + message + "\n\n Please complete or correct the form and submit again.")
				return false;
			}
			else
			{ 
				form.submit()
				return true;
			}

		}

}

/// functions for form validation script

function count_checkboxes(element_name)
{ 
	box_checked = 0;
	with (document.form) { 
		for (var i=0; i < elements.length; i++) { 
			if (elements[i].name == element_name)
				if (  elements[i].checked )
				{ 
						box_checked += 1;
				}
		}
	}
	return box_checked;
}

 
function chkAll(frm, arr, mark) {
  for (i = 0; i <= frm.elements.length; i++) {
   try{
     if(frm.elements[i].name == arr) {
       frm.elements[i].checked = mark;
     }
   } catch(er) {}
  }
}

function chkThis(frm, arr, itm) {
   
  var keepchecked = itm.checked;
/*
 for (i = 0; i <= frm.elements.length; i++) {
   try{
     if(frm.elements[i].name == arr) {
       frm.elements[i].checked = false;
     }
   } catch(er) {}
  }
*/  
   if(keepchecked) { itm.checked = true; }
//  itm.checked = (itm.checked)?false:true;
}