if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', cmxform, false);

function cmxform(){
  // Hide forms
  $( 'form.cmxform' ).hide().end();
  
  // Processing
  $( 'form.cmxform' ).find( 'label' ).not( '.nocmx' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();

  // Show forms
  $( 'form.cmxform' ).show().end();
 
}

function validateForm(){
   var msg = new String;
   msg = "";

   if(document.getElementById('fname').value == ""){
      msg += "\tFirst Name\n";
   }
   if(document.getElementById('lname').value == ""){
      msg += "\tLast Name\n";
   }
   if(document.getElementById('company').value == ""){
      msg += "\tCompany\n";
   }
   if(document.getElementById('address').value == ""){
      msg += "\tAddress\n";
   }
   if(document.getElementById('city').value == ""){
      msg += "\tCity\n";
   }
   if(document.getElementById('state').value == ""){
      msg += "\tState\\Province\n";
   }
   if(document.getElementById('zip').value == ""){
      msg += "\tZip\\Postal Code\n";
   }
   if(document.getElementById('country').value == ""){
      msg += "\tCountry\n";
   }
   if(document.getElementById('phone').value == ""){
      msg += "\tPhone\n";
   }
   if(document.getElementById('fax').value == ""){
      msg += "\tFax\n";
   }
   if(document.getElementById('email').value == ""){
      msg += "\tEmail\n";
   }

   if(document.getElementById('cbgolf').checked == true){
      if(document.getElementById('handicap').value == ""){
         msg += "\tGolf Handicap\n";
      }  
   }
   
   if(document.getElementById('cbclubs').checked == true){
      if(document.getElementById('clubtype1').selectedIndex == 0){
         msg += "\tClub Type 1\n";
      }
      if(document.getElementById('clubtype2').selectedIndex == 0){
         msg += "\tClub Type 2\n";  
      }
   }
   
   if(msg !== ""){
      alert("The following fields require values:\n\n" + msg + "\nPlease correct these errors and try again.\n");
      return false;
   }
}

function calcCustAmt(){
   
   var attndcost = 375;
   document.frmCustSignup.attndcost.value = '375.00';
   
   if(document.getElementById('cbgolf').checked == true){
      var golfcost = 75;
      document.frmCustSignup.golfcost.value = '75.00';
   } else {
      var golfcost = 0;
      document.frmCustSignup.golfcost.value = '0.00';
   }
   
   if(document.getElementById('cbclubs').checked == true){
      var clubcost = 40;
      document.frmCustSignup.clubcost.value = '40.00';
   } else {
      var clubcost = 0;
      document.frmCustSignup.clubcost.value = '0.00';
   }
   
   var ttlcost = attndcost + golfcost + clubcost;
   
   document.frmCustSignup.x_Amount.value = ttlcost + '.00';
   
}

function calcAmt(){

   var attndcost = 425;
   document.frmSignup.attndcost.value = '425.00';
   
   if(document.getElementById('cbgolf').checked == true){
      var golfcost = 75;
      document.frmSignup.golfcost.value = '75.00';
   } else {
      var golfcost = 0;
      document.frmSignup.golfcost.value = '0.00';
   }
   
   if(document.getElementById('cbclubs').checked == true){
      var clubcost = 40;
      document.frmSignup.clubcost.value = '40.00';
   } else {
      var clubcost = 0;
      document.frmSignup.clubcost.value = '0.00';
   }
   var ttlcost = attndcost + golfcost + clubcost;
   
   document.frmSignup.x_Amount.value = ttlcost + '.00';

}

function clearForm(){
   document.getElementById('fname').focus();
   document.getElementById('cbgolf').checked = false;
   document.getElementById('cbclubs').checked = false;
   document.getElementById('clubtype1').selectedIndex = 0;
   document.getElementById('clubtype2').selectedIndex = 0;
}

function toggleDiv(div){

   //set the element based on what's passed as the div id
   var elem, vis;
    
   if( document.getElementById ) // this is the way the standards work
      elem = document.getElementById(div);
   else if( document.all ) // this is the way old msie versions work
      elem = document.all[div];
   else if( document.layers ) // this is the way nn4 works
      elem = document.layers[div];
   vis = elem.style;
   
   // if the style.display value is blank we try to figure it out here
   if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
      vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
      vis.display = (vis.display==''||vis.display=='block')?'none':'block';
      
   //because we're using this on the EMI reg forms, we know we want to scroll down
   window.scroll(0,600);
   
   //move the cursor to the handicap field if the golf checkbox is checked
   if(document.getElementById('cbgolf').checked == true){
      setFocus('handicap');
   }
}

function setFocus(el){
   document.getElementById(el).focus();
}
