// JavaScript Document

function submitenter(myfield,e)

{

var keycode;

if (window.event) keycode = window.event.keyCode;

else if (e) keycode = e.which;

else return true;



if (keycode == 13)

   {

   myfield.form.onsubmit();

   return false;

   }

else

   return true;

}

function IsEmail(str)

{

  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

}

function IsEmpty(aTextField) {

   if ((aTextField.value.length==0) ||

   (aTextField.value==null)) {

      return true;

   }

   else { return false; }

}	

function isInteger(s)

{   var i;

    for (i = 0; i < s.length; i++)

    {   

        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;

    }

    return true;

}

function stripCharsInBag(s, bag)

{   var i;

    var returnString = "";

    for (i = 0; i < s.length; i++)

    {   

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}

function checkInternationalPhone(strPhone) {

  var digits = "0123456789";

  var phoneNumberDelimiters = "()- ";

  var validWorldPhoneChars = phoneNumberDelimiters + "+";

  var minDigitsInIPhoneNumber = 10;

  s=stripCharsInBag(strPhone,validWorldPhoneChars);

  return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);

}

function clearPage() {

  return true;

}

function updatePage() {

  docForm=document.getElementById("newuser");

  var division=document.getElementById("team_division");

  docFieldOne=document.getElementById("member4info");

  docFieldTwo=document.getElementById("member3info");

  if (division.value=='4C' || division.value=='4M' || division.value=='4F') {

	docFieldOne.style.visibility="visible";
	
	docFieldOne.style.display="block";
	
	var basepay=260;
	
  }

  else {

	docFieldOne.style.visibility="hidden";
	
	docFieldOne.style.display="none";
	
	var basepay=195;
	
	  if (division.value=='3C' || division.value=='3M' || division.value=='3F') {
	
		docFieldTwo.style.visibility="visible";
		
		docFieldTwo.style.display="block";
		
		var basepay=195;
		
	  }
	
	  else {
	
		docFieldTwo.style.visibility="hidden";
		
		docFieldTwo.style.display="none";
		
		var basepay=130;
		
	  } 
	
  } 

  if (docForm.team_website.value.length>0 && docForm.team_website.value.indexOf('http://'))

    docForm.team_website.value='http://'+docForm.team_website.value;


//Paddles & PFDs
  if (isNaN(docForm.team_paddles.value) || docForm.team_paddles.value==' ') { docForm.team_paddles.value = 0; }

  if (isNaN(docForm.team_pfds.value) || docForm.team_pfds.value==' ') { docForm.team_pfds.value = 0; }

  var paddlepfdtotal=parseInt(docForm.team_paddles.value)-parseInt(docForm.team_pfds.value);

  if (paddlepfdtotal<0) {

    paddlepfdpremium=(-1*paddlepfdtotal*5)+(parseInt(docForm.team_paddles.value)*8);

  }

  else {

	paddlepfdpremium=(paddlepfdtotal*5)+(parseInt(docForm.team_pfds.value)*8);

  }

  var totalreg=basepay+paddlepfdpremium;

  document.getElementById("totalspan").innerHTML="$"+totalreg+"";

  document.getElementById("entryfee").innerHTML="$"+basepay+"";

  document.getElementById("paddlepfdfee").innerHTML="$"+paddlepfdpremium+"";

  document.getElementById("amount").value=parseInt(totalreg);

}

function ValidateForm(form)

{

  if (IsEmpty(form.team_name))

  {

  alert('Team Name is required!');

  form.team_name.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_name))

  {

  alert('Captains name is required!');

  form.team_capt_name.focus();

  return false;

  }

  if (form.team_division.value=="")

  {

  alert('You must choose a division!');

  form.team_division.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_address))

  {

  alert('Team Captain address is required!');

  form.team_capt_address.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_city))

  {

  alert('Team Captain City is required!');

  form.team_capt_city.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_state))

  {

  alert('Team Captain State is required!');

  form.team_capt_state.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_zip))

  {

  alert('Team Captain Zip is required!');

  form.team_capt_zip.focus();

  return false;

  }  

  if (!IsEmail(form.team_capt_email.value))

  {

  alert('You must enter a valid email address!');

  form.team_capt_email.focus();

  return false;

  }

  if (IsEmpty(form.team_capt_phone))

  {

  alert('Team Captain phone number is required!');

  form.team_capt_phone.focus();

  return false;

  }

  if (checkInternationalPhone(form.team_capt_phone.value)==false){

  alert("Please Enter a Valid Phone Number with area code!")

  form.team_capt_phone.value=""

  form.team_capt_phone.focus()

  return false;

  }

  return true;

}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

