﻿var regdata = '';
      
      function tradeshoweventreg_v1_validateReg(e) {      
        
          if (window.handle_tradeshoweventreg_v1_validateReg) {
            var msg = '';
            var anynames = '';
            regdata = '<registrationvalues>';
            
            //what show show ScheduleId
            regdata += '<scheduleid>' + document.forms[0].elements['ScheduleId'].value + '</scheduleid>'
            regdata += '<show><![CDATA[' + document.forms[0].elements['show'].value + ']]></show>'
            
            // must provide a company name
            regdata += '<txtcustname><![CDATA[' + document.forms[0].elements['txtcustname'].value + ']]></txtcustname>';
                     
           if (document.forms[0].elements['txtcustname'].value == '') {
              msg += 'Please provide your company name.\n\n';
            } 
            
            
            regdata += '<txtcustno>' + document.forms[0].elements['txtcustno'].value + '</txtcustno>';
            if (document.forms[0].elements['txtcustno'].value == '') {
              msg += 'Please provide your customer number (this can be located on the top of an invoice). If you dont know your customer number please enter a zero.\n\n';
            }     
            if (formvalidate_IsNumeric(document.forms[0].elements['txtcustno'].value) == false) {
              msg += 'Customer Number must be numeric, if you dont know your customer number please enter a zero.\n\n';
            }
            regdata += '<txtemail><![CDATA[' + document.forms[0].elements['txtemail'].value + ']]></txtemail>';
            if (document.forms[0].elements['txtemail'].value == '') {
              msg += 'Please provide your email address so that we can communicate confirmation of your registration.\n\n';
            }
            
            regdata += '<brno>' + document.forms[0].elements['brno'].options[document.forms[0].elements['brno'].selectedIndex].text + '</brno>';
            if (document.forms[0].elements['brno'].selectedIndex < 1) {
              msg += 'Please selected The Granite Group branch that you do business with. \n\n';
            }
            
            // create the attendess section of the xml
            regdata += '<attendees>';
            
            for (var i = 1; i < 5; i++) {
              // start attendee data xml
              regdata += '<txtattendee' + i + '><attendeename><![CDATA[' + document.forms[0].elements['txtattendee' + i].value + ']]></attendeename>'
              regdata += '<tradeshow>' + document.forms[0].elements['ts' + i].checked + '</tradeshow>';
            
              //create the seminars section of the xml
               regdata += '<seminars>';
               
              // initialize the tradshow and seminar validation as false for each attendee iteration
              msg = msg + validateAttend(i);
              
              //clsoe the seminars section of the xml
               regdata += '</seminars>';
              
              // check that at least one name is provided
              anynames += document.forms[0].elements['txtattendee' + i].value;
              
              regdata += '</txtattendee' + i + '>' ;
            }
            // close the attendess section of the xml
              regdata += '</attendees>';
            
            // create a message if no names are provided
            if (anynames == '') {
              msg += 'Please enter the name of at least one person who will be attending the tradeshow and/or a seminar.\n\n';
            }
            regdata += '</registrationvalues>';
            if (msg == '') {
              handle_tradeshoweventreg_v1_validateReg(e,regdata);
              regdata = '';
            } else {
              alert(msg);
            }
          } else {
            alert('Sorry, there is no page available for submitting your registration!');
          }
      }
      
      function validateAttend(i) {
          var valids = false;
          var validt = false;
          var ret = 'Checking attendee #' + i;
          
          // var to hold the group name of the seminar
          var group = 's' + i;
          
          // length of group
          var m = document.forms[0].elements[group].length;
         
          // check if the tradeshow is checked
          validt = document.forms[0].elements['ts' + i].checked;
          
          // check if each seminar is checked          
          for (var n = 0; n < m; n++) {
            regdata += '<' + document.forms[0].elements[group][n].value + '>' + document.forms[0].elements[group][n].checked + '</' + document.forms[0].elements[group][n].value + '>'
            if (document.forms[0].elements[group][n].checked) {              
              valids = true;
            }
          }
          
          
          if ((valids) || (validt)) {
            if (document.forms[0].elements['txtattendee' + i].value == '') {
              // name is required if tradeshow or seminars are checked
              ret = 'You must provide a name for attendee #' + i + ' for them to attended the tradeshow and/or seminars.\n\n';
            } else {  
              // no name and no seminars or tradeshow is ok
              ret = '';         
            }
          } else {
            if (document.forms[0].elements['txtattendee' + i].value == '') {
              // name and tradewhow or seminar reg is ok.
              ret = ''; 
            } else {
              // a name but no tradeshow or seminar reg is not ok.
              ret = 'Attendee #' + i + '(' + document.forms[0].elements['txtattendee' + i].value + ') must register for the tradeshow and/or seminar(s).\n\n';
            }
          } 
          
          return ret
      }
      function formvalidate_IsNumeric(strString)
       //  check for valid numeric strings	
       {
       var strValidChars = "0123456789";
       var strChar;
       var blnResult = true;

       if (strString.length == 0) return false;

       //  test strString consists of valid characters listed above
       for (i = 0; i < strString.length && blnResult == true; i++)
          {
          strChar = strString.charAt(i);
          if (strValidChars.indexOf(strChar) == -1)
             {
             blnResult = false;
             }
          }
       return blnResult;
       }
