   /*validation script for registration form*/



   function validateForm()
   {
      //The following vars are for mandatory fields----------------
      //var title = document.getElementById("title").value;
      //var first = document.getElementById("firstname").value;
      //var last = document.getElementById("lastname").value;
      /*var email = document.getElementById("email").value;
      var datepurchasedday = document.getElementById("datePurchaseDay");
      var datepurchasemonth = document.getElementById("datePurchaseMonth");
      var datepurchaseyear = document.getElementById("datepurchaseyear");
      var productPurchase = document.getElementById("productPurchased");*/
      //var mandatoryCheck = true;

      //end of mandatory fields 
   
      //check for all mandatory fields
      //
      //
      //


     //
      mandatoryCheck = checkFields(); 

      //mandatoryCheck = false;

      if(mandatoryCheck == false)
      {
	   
         alert("There was an error in processing " + '\n' + "Please ensure the fields that are marked red are filled properly"); 
         document.getElementById("title").focus();
	 return false;
      }

     
    
      else 
      {
	      
          return true;
      }


   }


   
   function checkFields()
   {

       var checkboxcounter = 0;
       var dateformatcounter =0;
       var requiredFieldStatus = true; 
       var influenceStatus = true;      
       var datestatusdob = true;
       var datestatuspurchase = true;
       var formFieldStatus = true;
         

      
       
       if(document.customerRegistration.elements.length == 0 )
       {

              return false;
       }    
 
       
       

       for(i=0;i<document.customerRegistration.elements.length; i++)
       {
             //--------------the following checks if all mandatory fields are filled up-----------------
	     //checks if title is empty  
	     if(document.customerRegistration.elements[i].id=="title")
	     {
                   if(isEmpty(document.customerRegistration.elements[i].value))
                   {

                       requiredFieldStatus = false;
		       document.getElementById('titleText').style.color="red";
		   }

	     }


	      //checks if firstname is empty  
	     if(document.customerRegistration.elements[i].id=="firstName")
	     {
           	  if(isEmpty(document.customerRegistration.elements[i].value))
                  {
                       requiredFieldStatus = false;
		       document.getElementById('firstNameText').style.color="red";
		  }

             }

             //checks if last name is empty
	     if(document.customerRegistration.elements[i].id=="lastName")
	     {
                   if(isEmpty(document.customerRegistration.elements[i].value))
                   {
		       				
                       requiredFieldStatus = false;
		       document.getElementById('lastNameText').style.color="red";
                       
		   }

             }

       
	     if(document.customerRegistration.elements[i].id=="numberAreaCode")
	     {
                   if(isEmpty(document.customerRegistration.elements[i].value) || (isNaN(document.customerRegistration.elements[i].value)))
                   {
		       				
                       requiredFieldStatus = false;
		       document.getElementById('daytimeNumberText').style.color="red";
                       
		   }

             }

	     if(document.customerRegistration.elements[i].id=="daytimeNumber")
	     {
                   if(isEmpty(document.customerRegistration.elements[i].value) || (isNaN(document.customerRegistration.elements[i].value)))
                   {
		       				
                       requiredFieldStatus = false;
		       document.getElementById('daytimeNumberText').style.color="red";
                       
		   }

             }
             


             //checks if email is empty
	     if(document.customerRegistration.elements[i].id=="email")
	     {
                   if(isEmpty(document.customerRegistration.elements[i].value))
                   {

                      requiredFieldStatus = false;
		      document.getElementById('emailText').style.color="red";
		   }
		   
		   //-----do checking on email format ----
                  if(!isEmail(document.customerRegistration.elements[i].value))
		  {
		       requiredFieldStatus = false;
		       document.getElementById('emailText').style.color="red";
		  }
	     
	     }



	      // -------------------------do checking for the DOB date, month year --------------------------

	         
              //checks if dob date field is empty
	      if(document.customerRegistration.elements[i].id=="dobDate")
	      {

		 while((document.customerRegistration.elements[i].id=="dobDate") || (document.customerRegistration.elements[i].id=="dobMonth") || (document.customerRegistration.elements[i].id=="dobYear" ))
	         {

                        if(isEmpty(document.customerRegistration.elements[i].value))
                        {


			    datestatusdob = false;
		        }

		        //-----checks to see if is a number -------
		        if(isNaN(document.customerRegistration.elements[i].value))
		        {
			    datestatusdob = false;

		        }

                        if(document.customerRegistration.elements[i].id=="dobMonth")
	                {

			     if(isNaN(document.customerRegistration.elements[i].value) || (document.customerRegistration.elements[i].value >12))
			     {
		  	         datestatusdob = false;
   		             }

			}

			 i++;

		    }

		    if(datestatusdob == false)
		    {

			document.getElementById('dobText').style.color="red";
		    }
		 }

               
	    //---------------------------------------------end of check for DOB---------------------------------------



	    //---------------------------------------------check for date of purchase---------------------------------
            //checks if datePurchase day is empty
	    
              if(document.customerRegistration.elements[i].id=="PurchaseDateDay")
	      {

		 while((document.customerRegistration.elements[i].id=="PurchaseDateDay") || (document.customerRegistration.elements[i].id=="PurchaseDateMonth") || (document.customerRegistration.elements[i].id=="PurchaseDateYear" ))
	         {

                        if(isEmpty(document.customerRegistration.elements[i].value))
                        {
			    datestatuspurchase = false;
		        }

		        //-----checks to see if is a number -------
		        if(isNaN(document.customerRegistration.elements[i].value))
		        {
			    datestatuspurchase = false;

		        }

                        if(document.customerRegistration.elements[i].id=="PurchaseDateMonth")
	                {

			     if(isNaN(document.customerRegistration.elements[i].value) || (document.customerRegistration.elements[i].value >12))
			     {
		  	         datestatuspurchase = false;
   		             }
			}

			i++;
		  }  

		  if(datestatuspurchase == false)
		    {

			document.getElementById('dateofPurchaseText').style.color="red";
		    }   
	      }
         
	     

	      //-----------------------------end of check purchase date------------------------------

	      //checks if product purchased field is empty
	      if(document.customerRegistration.elements[i].id=="productPurchased")
	      {

                  if(isEmpty(document.customerRegistration.elements[i].value))
                  {
			  requiredFieldStatus = false;
			  document.getElementById('productPurchasedText').style.color="red";

                      
	 	   }
                

	      }

	    //-----------------end of mandatory field check-----------------------

	    //checks to see if the checkboxes have at most 2
	    


	      if(document.customerRegistration.elements[i].type =="checkbox")
	      {
	          
	          while(document.customerRegistration.elements[i].type =="checkbox")
	          {
	                
		        if(document.customerRegistration.elements[i].checked == true)
		        {
			      checkboxcounter++;
                              
		        }
		        
			i++;//go on to next index to check 
                          
		  } 
		 
		   
		  if(checkboxcounter >2)
		  {

                       influenceStatus = false;
                        
			document.getElementById('influenceText').style.color="red";
   
		  }

	      }
            //----------------------------------end checking checkboxes---------------------------  


       }
             
       
       if((requiredFieldStatus == false) || (influenceStatus == false) || (datestatusdob == false) || (datestatuspurchase == false))
       {
	       formFieldStatus = false;
	       
     

       }
       else
       {
            
      
       
       }

       return formFieldStatus;
   }


 //----------------------------following code taken from Ben --------------------------------- 


   //check if something is a valid email
   function isEmail(str)
   {
       if(isEmpty(str)) return false;
    			
          var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
			
	  return re.test(str);
	
   }


   //check to see if empty field
   function isEmpty(str)
   {
	   return (str == null) || (str.length == 0);
   }
   


	     

