

   //##############################################################//
   //## checks if the search box has values                  ######//
   //## if not, returns false, if so, validates sic code     ######//
   //##############################################################//
   function validateSearch(theForm) {
        var warning;
        var retval = false;
        if (theForm.sic_input.value == '' && theForm.kw_input.value == '') {
            warning = 'You pressed the search button without entering any search terms.'; 
            warning += '\n\nPlease enter a keyword or sic code for your search.';
            alert(warning);
          } else {
            retval =  validateSic(theForm.sic_input);
        }

        return retval;
   }
   //##############################################################//


   //##############################################################//
   //## checks if the number entered follows 1,000.00 format ######//
   //## numbers must be stripped of commas later by PHP      ######//
   //##############################################################//
   function validateSic(theInput) {

      // checks that input is only numbers, commas, and periods.
      myRegExp = new RegExp("^[0-9,]*$", "i")

      var warning ; 
      warning  = 'The value you entered: \n\t' + theInput.value;
      warning += '\n is not properly formatted. \n\nThis field'
      warning += ' only accepts numeric data.\n';


      if (myRegExp.exec(theInput.value)) {
           return true;
        } else {
           // not properly formatted, so delete
           // and refocus
           alert(warning);
           theInput.value='';
           theInput.focus();
           return false;
      } 
   }    
   //##############################################################//



   //##############################################################//
   //## sets a hidden trdb form field to a target page       ######//
   //## target then becomes the action param of next page    ######//
   //##############################################################//
   function RecordRedirect(target) {
      document.frm.elements["redirector"].value =  target;
   }
   //##############################################################//


   //##############################################################//
   //## checks if the number entered follows 1,000.00 format ######//
   //## numbers must be stripped of commas later by PHP      ######//
   //##############################################################//
   function validateNumber(theInput) {

      // checks that input is only numbers, commas, and periods.
      myRegExp = new RegExp("^[0-9,-\.]*$", "i")

      var warning ; 
      warning  = 'The value you entered: \n\t' + theInput.value;
      warning += '\n is not properly formatted. \n\nThis field'
      warning += ' only accepts numeric data.\n';
      warning += 'You may use decimals for fractional amounts.\nYou may use commas as 1000 separators for dollar amounts.\n';
      warning += '$ and % symbols are not allowed.\n'


      if (myRegExp.exec(theInput.value)) {
           //properly formatted, so do nothing
        } else {
           // not properly formatted, so delete
           // and refocus
           alert(warning);
           theInput.value='';
           theInput.focus();
      } 
   }    
   //##############################################################//


   //##############################################################//
   //## checks to make sure the first form is filled out ##########//
   //##############################################################//
   function firstFormCheck(formobj){
  
     var e, i, warning;
  
     var foundoneofname = false;
     var foundoneofdate = false;
     var foundoneoftime = false;
  
     warning = 'Please fill out name, date, and billable time for RFP, Auction, or both.\n\n';
  
     //walk thru all form items
     for (i=0;i<formobj.elements.length;i++) {
         e = formobj.elements[i];
         switch(e.type){
            case 'checkbox':
                 break;
  
            //figure out what kind of form element it is
            //certain items have special (ex: require one of two) handling
  
            case 'select-one': 
                 if (e.selectedIndex == 0 || e.options[e.selectedIndex].value == ""){
  
                	  } else {
                    if(e.name == 'mm_event_date_auction' 
                        || e.name == 'dd_event_date_auction' 
                        || e.name == 'yyyy_event_date_auction' 
                        || e.name == 'mm_event_date_rfp' 
                        || e.name == 'dd_event_date_rfp' 
                        || e.name == 'yyyy_event_date_rfp' ) {
   
                        foundoneofdate = true; 
                	   }
                	}
                 break;
  
  
            case 'text': 
                 if (e.value == ""){
                   } else {
                    if(e.name == 's_event_name_rfp' || e.name == 's_event_name_auction')  
                        foundoneofname = true; 
                    if(e.name == 's_billable_time_rfp' || e.name == 's_billable_time_auction')  
                        foundoneoftime = true; 
                 }
                 break;
  
            case 'textarea': 
                 break;
         }
     }
  
     //find out how the check went, either warn or pass
     if (
          foundoneofname == false
          || foundoneofdate == false
          || foundoneoftime == false) {
  
          return warning;

       } else {
          return '';
     }
  }
  //##############################################################//


  //##############################################################//
  //# checks that all fields on first page and second page #######//
  //# are filled out                                       #######//
  //##############################################################//
  function pageCheck(formobj,page) {

   var e, i, j, missing, firstPageWarning, foundone, warning;

   missing = '';
   foundone = false;

    if (page == 1) {
        warning  = 'These fields on the client information page are mandatory.\n\n';
        firstPageWarning = firstFormCheck(formobj);
        warning += firstPageWarning;
  	   var fieldReq = Array("s_event_type", 
                             "s_customer_number", 
                             "s_customer_category", 
                             "base_currency", 
                             "multi_currency", 
                             "customer_sourcing_skills", 
                             "kmr[]",
                             "third_party_involvement", 
  
                             "s_esourcing_manager", 
                             "s_sales_account_manager" 
                             );
  
  	   var fieldDesc = Array( "Event Type", 
                             "Customer Name", 
                             "Category", 
                             "Base Currency", 
                             "MultiCurrency", 
                             "Customer Sourcing Skills", 
                             "Knowledge Management Resources",
                             "Third Party Involvement", 
                             "eSourcing Manager", 
                             "Sales Account Manager" 
                             );
  
  
  
      } else {
        warning  = 'These fields on the strategy/outcome page are required.\n\n';
        //array of mandatory fields
  	   var fieldReq = Array("goal[]", 
                             "goal_most_desirable_outcome", 
                             "goal_least_desirable_outcome", 
                             "goal_other_comments", 
                             "strat[]", 
                             "strat_mkt_outlook_for_category",
                             "strat_other_mkt_details_n_dyn",
                             "strat_other_comments",
                             "out[]", 
                             "out_bidding_activity", 
                             "out_incumbent[]", 
                             "out_other_comments",
                             "customer_satisfaction_rating",
                             "customer_testimonial",
                             "esourcing_manager_comments"
                             );
        //pretty names for mandatory fields
  	   var fieldDesc = Array("Goal Checkboxes", 
                             "Most Desirable Outcome", 
                             "Least Desirable Outcome", 
                             "Goal Comments", 
                             "Strategy Checkboxes",
                             "Market Outlook for Category",
                             "Other Market Details and Dynamics",
                             "Strategy Comments",
                             "Outcome Checkboxes",
                             "Bidding Activity",
                             "Incumbent Won/Lost",
                             "Outcome Comments",
                             "Customer Satisfaction Rating",
                             "Customer Testimonial",
                             "eSourcing Manager Comments"
                             );
  
     }
  
  
  	for (i = 0; i < fieldReq.length; i++){
       foundone = false;
  
  	    e = formobj.elements[fieldReq[i]];
  
         switch(e.type){
            case 'select-one': 
                 if (e.selectedIndex == 0 || e.options[e.selectedIndex].value == ""){
  		               missing += " - " + fieldDesc[i] + "\n";
                 	}
                 break;
            case 'text': 
                 if (e.value == ""){
  		            missing += " - " + fieldDesc[i] + "\n";
                 }
                 break;
            case 'textarea': 
                 if (e.value == ""){
  		            missing += " - " + fieldDesc[i] + "\n";
                 }
                 break;
  
            // handles checkboxes and radios
            default:
  
      			  for (j = 0; j < e.length; j++){
  	    			   	if (e[j].checked){
  		    		   		foundone = true;
  			    	   	}
  				     }
  				     if (!foundone){
  					    missing += " - " + fieldDesc[i] + "\n";
  				     }
                 break;
  
  
         }
     }
  
     if (missing || firstPageWarning) {
           if (missing) warning += 'Please fill out the following fields:\n';
           alert (warning + missing );
           return false;
        } else {
           return true;
     }

  }
  //##############################################################//


  //##############################################################//
  //# checks that all fields on first and second trdb page #######//
  //# are filled out                                       #######//
  //##############################################################//
  function finalCheck() {
     if (
         pageCheck(window.document.frm,1)
                 &&
         pageCheck(window.document.frm,2)
        ) {
     
         return true;
     } else {
         return false;
     }
  }
  //##############################################################//


  //##############################################################//
  //# checks all checkboxes with  the passed name          #######//
  //# assumes form is called 'frm'                         #######//
  //##############################################################//
  function checkAll(arr) {
    list=document.frm;
    len = list.elements.length;
    var i=0;
    for( i=0 ; i<len ; i++) {
      if (list.elements[i].name==arr) {
        if (list.elements[i].checked==true) {
             list.elements[i].checked=0; 
           } else {
             list.elements[i].checked=1; 
        }
      }
    }
  }
  //##############################################################//



