//<!-- =================================================================== -->
// get checked radio button
function getCheckedRadio(theElement)
{ 	
   checkedRadio = "";
   for(var i=0; i<theElement.length; i++)
   {
      if(theElement[i].checked)
      {
         checkedRadio= theElement[i].value;
      }
   }
   return checkedRadio;
}

//<!-- =================================================================== -->
// get selected list option
function getSelectedOption(theElement)
{
 	
   selectedOption = "";
   selectedOption = theElement.options[theElement.selectedIndex].value;
   return selectedOption;
}

//<!-- =================================================================== -->
// update country to "U.S." if state selected
function updateCountry(theForm)
{
   if( (theForm.state.selectedIndex!=-1) && (theForm.state.options[theForm.state.selectedIndex].value!="") )
   {
      theForm.country[0].checked=true;
   }
}

//<!-- =================================================================== -->
// update state to <blank> if "Outside U.S." selected
function updateState(theForm)
{
   if(theForm.country[1].checked)
   {
      theForm.state.selectedIndex=0;
   }
}

//<!-- =================================================================== -->
// check and submit webForm
function validateWebForm (theForm)
{ 	
   if (!document.getElementById)
   {
      return true;  // not available on this browser - leave validation to the server
   }

   if (!validAlphaCharSymField(theForm.first_name,1))
   {
      alert("Please enter a valid first name. \nSymbols allowed: - _ . , ' ( ) & / :");
      theForm.first_name.focus();
      return false;
   }

   if (!validAlphaCharSymField(theForm.last_name,1))
   {
      alert("Please enter a valid last name. \nSymbols allowed: - _ . , ' ( ) & / :");
      theForm.last_name.focus();
      return false;
   }

   if (!validEmailField(theForm.email,1))
   {
      alert("Please enter a valid email.");
      theForm.email.focus();
      return false;
   }

   if(theForm.phone.value.length != 0)
   {
      if (!validPhoneField(theForm.phone,10,25))
      {
         alert("Please enter a valid phone number. \nSymbols allowed: ( ) - . and leading +");
         theForm.phone.focus();
         return false;
      }
   }

   if ((!answeredSelectList(theForm.state)) && (!theForm.country[1].checked))
   {
      alert("Please select a state, or \"Outside U.S\"");
      theForm.state.focus();
      return false;
   }

   if (!validAllCharExceptField(theForm.addlInfo))
   {
      alert("Additional Information field contains invalid symbol(s): # % * = \"");
      theForm.addlInfo.focus();
      return false;
   }

   // passed form validation...
   return true;
}

//<!-- =================================================================== -->
// submit webForm
function webFormCheck(theForm)
{ 	
   // if passed form validation...
   if (validateWebForm(theForm))
   {
      theForm.submit();
   }
}

//<!-- =================================================================== -->
// check and send webForm to d_url before submitting webForm
function webFormCheckAJAX (theForm, d_url)
{
   // if passed form validation...
   if (validateWebForm(theForm))
   {
      //=========================
      // form submit w/ AJAX to db and email page
      new Ajax.Request (
         d_url,
   		{
            method: 'post',
            parameters: {
               oid: theForm.elements['oid'].value,
               first_name: theForm.elements['first_name'].value,
               last_name: theForm.elements['last_name'].value,
               phone: theForm.elements['phone'].value,
               email: theForm.elements['email'].value,
               state: getSelectedOption(theForm.elements['state']),
               country: getCheckedRadio(theForm.elements['country']),
               '00N70000001nkwF': getCheckedRadio(theForm.elements['00N70000001nkwF']),
               description: theForm.elements['description'].value,
               '00N700000025qDT': theForm.elements['00N700000025qDT'].value,
               lead_source: theForm.elements['lead_source'].value,
               formName: theForm.elements['formName'].value
            },
            asynchronous: false,
            onSuccess: function(t) {
//				        alert(t.responseText);
            },
            onFailure: function(t) {
//				        alert("ERROR");
            }
         }
      );
      //=========================
      // form submit to salesforce, with ret_url
      theForm.submit();
   }
}
//<!-- =================================================================== -->
