/**
 *
 * Description: Replaces the default salesforce_campaign_ID based
 * on a referrer query string.
 *
 * Thoms Nicolosi
 * Red Bus Corp.
 * Contact: thomas@redbuscorp.com
 *
 * Current Revision:
 * 1.1.0.0
 * 2008-07-23
 * Changes:
 * Added code to remove "gclid=" referrer from query string.
 *
 */
 function idFromQuery(){
   var theQuery = location.search;
   var theQueryString = theQuery.toString();
   var equalsIndex = theQueryString.indexOf('=') + 1;
   var googleIndex = theQueryString.indexOf('&gclid=');
   var newId;
   var testInt;
   if (googleIndex < 0)
   {
    newId = theQueryString.substring(equalsIndex);
   }
   else
   {
     //googleIndex = googleIndex + 1;
     newId = theQueryString.substring(equalsIndex, googleIndex);
   }
   testInt = newId.toString().length;
   if (testInt > 0)
     {
      //alert(theQueryString + "\n" + newId);
      return newId;
     }
   else
     {
       return false;
     }
   

 }
 function setCampaignId(){
   if (!document.getElementById)
   {
     return false;
   }
   //get the element to change
   var campaignInput = document.getElementById("salesforce_campaign_ID");
   //request the new campaign Id from the query string
   var newCampaignId = idFromQuery();
   //check to see if newCampaignId exists
   if (newCampaignId)
     {
       //if the newCampaignId exists then set the new value of campaignInput
       campaignInput.value = newCampaignId;
     }
     else
     {
       return false;
     }
 }

