window.onload=show;
function show(id) {
// Hide all frop downs
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
// display the one we were called with
if (d) {d.style.display='block';}
}
//---------------------------------------------
function LPad(param,n) {
  if(n<0) return param;
  var s='0';
  var res=param;
  while(res.length<n) res=s+res;
  return res;
}
//--------------------------------------------
  function validRequired(formField,fieldLabel){
    var result = true;
    var spacectr = 0;
    //alert('Checking ' + fieldLabel );
    if (formField.value == "" || formField.value.length==0){
      alert('Please enter a value for the ' + fieldLabel +' field.');
      formField.focus();
      result = false;
    }else{
      for(var i=0;i<formField.value.length;i++) {
          if ((formField.value.charAt(i)==" ") || (formField.value.charAt(i)=="\t")) {
          		spacectr ++;
  				}
      }

     // alert("spcectr is " + spacectr + ", and length is " + formField.value.length);
      if (spacectr==formField.value.length || formField.value.charAt(0)==" ") {
     		 alert('Please enter a value for the ' + fieldLabel +' field.');
        		formField.focus();
  					result = false;
      }
      //alert('finished ' + fieldLabel );
    }
    return result;
  }
  
//--------------------------------------------
function clearvalue(formField){
// trying to get the input field to behave nicely with a blinking caret
// first field behaves differently!
  //alert(formField.name + ' Clearing');
 //alert ('value is ' + formField.value + ', legnth is ' + formField.value.length);
    if (formField.value == "0" || formField.value == "0.0" || formField.value == "0.00" || formField.value == "0.000" ){
    	if (formField.id=='focusname') {
      	formField.value='';
      }
    }else{
      var oRange = formField.createTextRange();
			oRange.moveStart("character", 0);
			oRange.moveEnd("character", formField.value.length);
			oRange.select();
			formField.focus();
		}
  }
//--------------------------------------------
function setzerovalue(formField){
    var result = true;
    if (formField.value == ""){
      formField.value='0';
    }
    if (isNaN(formField.value)) {
    	formField.value='0';
    }
  }
//--------------------------------------------
function hov(loc,cls){
   if(loc.className)
      loc.className=cls;}
//----------------------------------------------
  function validpassword(formField,fieldLabel,formField2){
  	
    if (!validRequired(formField,fieldLabel)){
      return false;
    } 
		if (!validInputString(formField,fieldLabel)){
         return false;
    }   
    if (!matchPassword(formField,formField2)){
      return false;
    }  
		// not doing strong passwords    
	  //if (!checkPassword(formField)){
	  //	return false;
    //}
		if (!validLenght("4",formField,fieldLabel)){
	  	return false;
    } 
    return true;
  } 
//----------------------------------------------
  function validphone(formField,fieldLabel){
  	//var re = new RegExp('/^[0-9]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$/');
  	//var RE_SSN = "/^[0-9+]{3}[\- ]?[0-9]{2}[\- ]?[0-9]{4}$/";

  	//var m = re.test(formField.value);
  	//if (!formField.value.match(re)) {
	  //  alert(fieldLabel + "is not a valid phone number, please retry");
	  //  formField.focus();
	  //  return false;
	  //} 
    //return true;
    // All we're going to do at the moment is check for between 7 and 20 characters
    if (formField.value.length > 0) { // don;t validate if not required
	    if (!validLenght(7,formField,fieldLabel)){
	      return false;
	    }
	    if (formField.value.length > 20) {
	    	alert('The ' + fieldLabel +' field needs to be less than 20 characters.');
	      formField.focus();
	    	return false;
	    }
	  }
    return true;
} 

//----------------------------------------------
  function validhome_phone(formField,fieldLabel){
  	if (!validphone(formField,fieldLabel)) {
        return false;  
    }
		return true; 
}
//----------------------------------------------
  function validbus_phone(formField,fieldLabel){
  	if (!validphone(formField,fieldLabel)) {
        return false; 
    }
		return true;
}
//----------------------------------------------
  function validmobile_phone(formField,fieldLabel){
  	if (!validphone(formField,fieldLabel)) {
        return false; 
    }
		return true;
}
//----------------------------------------------
  function validemail(formField,fieldLabel){
  	if (formField.value!='' > 0) {
  		if (!emailCheck(formField.value)){
  		  formField.focus();
        return false;
      }
    }
		return true; 
}
//----------------------------------------------
  function validcustomchar4(formField,fieldLabel){
		return mustbeyes(formField,fieldLabel);
}
//----------------------------------------------
  function validcustomchar5(formField,fieldLabel){
		return mustbeyes(formField,fieldLabel);
}
//----------------------------------------------
  function mustbeyes(formField,fieldLabel){
  
  	if (formField[0].checked && formField[0].value=='N') {	
      	formField[0].focus();
      	alert('The answer to ' + fieldLabel + ' must be Yes in order to proceed.');
      	return false;
    }else{
    	if (formField[1].checked && formField[1].value=='N') {
	      	formField[1].focus();
	      	alert('The answer to ' + fieldLabel + ' must be Yes in order to proceed.');
	      	return false;
    	}
    }
		return true; 
}
//----------------------------------------------
  function validdob_year(formField,formField1,formField2,fieldLabel,memtype){
//alert ('Checking 1  ' + formField.value+'/'+formField1.value+'/'+formField2.value+'/' + memtype.value);
  if (formField.value!='' ) {
  //	if (memtype=="P" || memtype=="G") {    // we took this out 23 september because we didn't know why it was here 
        if (!validLenght("4",formField,fieldLabel)){
          return false;
        }       
        if (!validInt(formField,fieldLabel,true)){
          return false;
        }
        var yrBirth = parseInt(formField.value);
        if(yrBirth < 1900) {
            alert('Invalid ' + fieldLabel);
            formField.focus();
            return  false;
         }
         if(yrBirth > 2100) {
            alert('Invalid ' + fieldLabel);
            formField.focus();
            return false;
         }
         
         if (!isDate(formField.value,formField1.value,formField2.value)) {
            alert('Invalid ' + fieldLabel);
            formField.focus();
            return false;
         }
      //}
    }
		return true;
} 
//----------------------------------------------
  function ispositive(formField,fieldLabel){
  	var result = true;
		if (formField.value < 0) {
      alert('Please enter a zero or positive value for the ' + fieldLabel +' field.');
      formField.focus();
      result = false;          
    }
    return result;
}
//----------------------------------------------
  function validGrade(formField,fieldLabel){
    var result = true;

    if (formField.value == "0"){
      alert('Please enter a value for the ' + fieldLabel +' field.');
      formField.focus();
      result = false;
    }
    return result;
  }
  
//----------------------------------------------
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//----------------------------------------------
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
//----------------------------------------------
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30;}
		if (i==2) {this[i] = 29;}
   } 
   return this;
}
//----------------------------------------------
function isDate(strYear,strMonth,strDay){

	var daysInMonth = DaysArray(12);
	var strYr = strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) {strDay=strDay.substring(1);}
	if (strMonth.charAt(0)=="0" && strMonth.length>1) {strMonth=strMonth.substring(1);}
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) {strYr=strYr.substring(1);}
	}

	var month=parseInt(strMonth,10);
	var day=parseInt(strDay,10);
	var year=parseInt(strYr,10);
//alert ('Checking ' + year+'/'+month+'/'+day);	
	if (strMonth.length<1 || month<1 || month>12){
		return false;
	}
	
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false;
	}
	
	if (strYear.length != 4 || year==0 ){
		return false;
	}
	
return true;
}
  //----------------------------------------------
  function allDigits(str){
    return inValidCharSet(str,"0123456789");
  }
  //----------------------------------------------
  function validYears(formFieldyrstart,formFieldyrend)
  // This function needs enhancing to chedk for contiguous dates and
  // non overlaps depending on gender
  { 
   var result = true;
	 var yrStart = parseInt(formFieldyrstart.value);
	 var yrEnd = parseInt(formFieldyrend.value);
   if(yrStart > yrEnd) {
        alert('Starting year must precede Ending year');
        formFieldyrstart.focus();
        result = false;
   }
   return result;
  }
 //----------------------------------------------
  /* Nanda added this for getting the cursor into the ifrst field */
var formInUse = false;

/* Called on body stmt int company layout */
function setFocus()
{
 if(!formInUse) {
 	if (document.getElementById("focusname")) { // if it exists
  		document.getElementById("focusname").focus();
  }
  if (document.tcform) {
  	if (document.tcform.tcmessage)
    	alert(document.tcform.tcmessage.value);
  }
 }
}
 //----------------------------------------------
/* Called on body stmt int company layout */
function moveFocus(formField)
{
 	formField.focus();
}
  //----------------------------------------------
  function inValidCharSet(str,charset){
    var result = true;

    // Note: doesn't use regular expressions to avoid early Mac browser bugs
    for (var i=0;i<str.length;i++)
      if (charset.indexOf(str.substr(i,1))<0){
        result = false;
        break;
      }
    return result;
  }
  //---------------------------------------------- 
  function validNum(formField,fieldLabel,required)
  {
    var result = true;

    if (required && !validRequired(formField,fieldLabel))
      result = false;

    if (result){
      if (!allDigits(formField.value)){
        alert('Please enter a number for the ' + fieldLabel +' field.');
        formField.focus();
        result = false;
      }
    }
    return result;
  }
  //----------------------------------------------
  function validInt(formField,fieldLabel,required){
    var result = true;

    if (required && !validRequired(formField,fieldLabel))
      result = false;

    if (result){
      var num = parseInt(formField.value);
      
      if (isNaN(num)){
        alert('Please enter a number for the ' + fieldLabel +' field.');
        formField.focus();
        formField.value="";
        result = false;
      }
    }
    return result;
  }
  //----------------------------------------------
  function validMoney(formField,fieldLabel,required){
    var result = true;

    if (required && !validRequired(formField,fieldLabel))
      result = false;

    if (result){
      var num = parseFloat(formField.value);
      
      if (isNaN(num)){
        alert('Please enter a number for the ' + fieldLabel +' field.');
        formField.focus();
        formField.value="";
        result = false;
      }
    }
    return result;
  }
  //----------------------------------------------
  function matchPassword(formField1,formField2){
    var result = true;

    if (formField1.value!=formField2.value){
      alert('The confimation password does not match with the password. Please try again');   
      formField1.focus();
      formField1.value="";
      formField2.value="";   
      result = false;
    }
    return result;     
  }
  //----------------------------------------------
function checkPassword(formField) {
    var result = true;
    var strng = formField.value;
    var illegalChars = /[\W_]/; // allow only letters and numbers

    if ((strng.length < 6) || (strng.length > 15)) {
       alert("The password must be between 6 and 15 characters.");
       formField.focus();
       result = false;
    }
    else if (illegalChars.test(strng)) {
      alert("The password contains illegal characters.");
       formField.focus();
       result = false;
    }
    else if ( (strng.search(/[a-z]+/)==-1) ||
							(strng.search(/[A-Z]+/)==-1) ||
							(strng.search(/[0-9]+/)==-1) ) {
    	alert("The password must contain at least one uppercase letter, one lowercase letter,and one numeral.");
       formField.focus();
       result = false;
    }
      return result;
}
  //----------------------------------------------
  function validDonation(formField,clubDesc){
    var result = true;
       
    var theMax = 10000; 
    var theDon = parseInt(formField.value); 
    
    if (theDon >= theMax){
      alert('Please contact the '+ clubDesc.value +' if you want to make a donation of this amount.');
      formField.focus();
      result = false;
    }
    
    return result;
  }
  //----------------------------------------------
function validLenght(validLength,formField,fieldLabel){
    var result = true;
    // alert('here 1 '+ fieldLabel);  
    var theLength = parseInt(validLength); 
    
    if (formField.value.length < theLength){
      alert('The ' + fieldLabel +' field needs to be at least ' + theLength +' characters.');
      formField.focus();
      result = false;
    }
    // alert('here 2');  
    return result;
  }
 
//---------------------------------------------------
function validInputString(formField, fieldLabel) {
	 var result = true;

  // The following pattern describes that we want to know if 
  // any single non word characters exist
  var mystr = /\W/
  //var strPat=new RegExp("^" + word + "(\\." + word + ")*$")
  var matchStr;
  matchStr = formField.value;
  
  if (mystr.test(matchStr)) {
      // string is not valid becuase there was a match
      alert('The ' + fieldLabel + ' field can only contain letters and/or numbers.');
      formField.focus();
       result = false;
  }
return result;
}

  //----------------------------------------------
  function validNumberLength(validLength,formField,fieldLabel){
    var result = true;
    var theLength = parseInt(validLength); 
    var mystr = formField.value;
    mystr = mystr1.replace("/[^0-9]/","");
    if (mystr.length < theLength){
      alert('The ' + fieldLabel +' field needs to be numeric only and at least ' + theLength +' numbers.');
      formField.focus();
      result = false;
    }
    
    return result;
  }
  
  //----------------------------------------------  
    function delete_family()
    {
      if (!confirm("Delete entire family?")){
        return false;
      }
      return true;
    }
  //----------------------------------------------
    function delete_account()
    {
      if (!confirm("Delete logon?")){
        return false;
      }
      return true;
    }
  //----------------------------------------------
    function delete_team()
    {
      if (!confirm("Delete team?")){
        return false;
      }
      return true;
    }
  //----------------------------------------------
    function delete_confirm()
    {
      if (!confirm("Delete ?")){
        return false;
      }
      return true;
    }
    
  //----------------------------------------------
    function reverse_payment()
    {
      if (!confirm("Reverse Payment?")){
        return false;
      }
      return true;
    }
    
  //-------------------------------------------------
  <!-- Begin
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    
	 We are also going to disallow a single quote becuase it never seems to be sent*/
var specialChars="\\(\\)<>@,;:\\'\\\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. MAY BE SO, BUT WE ARE NOT GOING TO ALLOW IT*/
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username part of the email address doesn't seem to be valid. Only letters (a-z), numbers (0-9), and periods (.) are allowed.).")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. 
	 Now also can have 4 letter one*/

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>4) {
   // the address must end in a two letter or three or four letter word.
   alert("The address must end in a three or four letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->