	

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
       var dc = document.cookie;
       var prefix = name + "=";
       var begin = dc.indexOf("; " + prefix);
       if (begin == -1)
       {
           begin = dc.indexOf(prefix);
           if (begin != 0) return null;
       }
       else
       {
           begin += 2;
       }
       var end = document.cookie.indexOf(";", begin);
       if (end == -1)
       {
           end = dc.length;
       }
       return unescape(dc.substring(begin + prefix.length, end));
}

 /**
  * Extract the camp value
  */
function extractCampValue()
{
  search_parameters_list = window.location.search;
  search_parameters = search_parameters_list.split("&");
  index = 0;
  while (index < search_parameters.length) {
    pos = search_parameters[index].indexOf("AlepoCamp=")
     if ( pos != -1) {
         alepo_camp_val =search_parameters[index].substr(pos + 10, search_parameters[index].length);
         return  alepo_camp_val;
    }
     index++;
  }
   return " ";
}

/**
 * Extract the keywords used for searching
 */
function extractKeywords()
{
   ref = document.referrer;
   if (ref && (ref.indexOf("google") > 0  || ref.indexOf("msn") > 0)) {
      pos = ref.indexOf("&q=")
   }
   else if (ref.indexOf("yahoo") > 0 ) {
      pos = ref.indexOf("&p=")
   }
   else {
      return "";
   }

   search_keywords_list_till_end = ref.substr(pos + 3, ref.length);
   pos = search_keywords_list_till_end.indexOf("&");
   if (pos > 0) {
     search_keywords_list = search_keywords_list_till_end.substring(0, pos);
   }
   else {
     search_keywords_list = search_keywords_list_till_end
   }

   /*search_keywords = search_keywords_list.split("+");*/
   search_keywords = search_keywords_list;
   return search_keywords;
}

/**
 * Sets the info in the cookie.
 */
function setInfo()
{
  // set cookie ONLY if it does not exist.
  var cookie_exists =  getCookie("alepo_cookie");
  if (cookie_exists)
     return;

  // get todays date
  var my_date = new Date();

  /**
   * New values can be appended to the cookie value. Note "####" is used as
   * seperator.
  */
  // build timeoffset string
  offsetHrsMins =  -1*(my_date.getTimezoneOffset()/60);
  offsetHrs = Math.floor(offsetHrsMins);
  offsetMins = -1*(my_date.getTimezoneOffset()%60);
  currentTimeZoneOffset =  + offsetHrs + ":" + offsetMins;
  if (offsetHrs > 0)
     currentTimeZoneOffset = "+" + currentTimeZoneOffset;

  // build date in mm/dd/yyyy format
  date_mm_dd_yyyy = (my_date.getMonth()+1) + "\\"
                    + my_date.getDate()	   + "\\"
					+ my_date.getYear();

  value = document.referrer
              + "####"
              + navigator.browserLanguage
              + "####"
              + date_mm_dd_yyyy
              + "####"
              + extractCampValue()
              + "####"
              + extractKeywords()
              + "####"
              + currentTimeZoneOffset;

  var exp_date = new Date("December 31, 2023");
  var the_cookie_date = exp_date.toGMTString();
  var the_cookie = "alepo_cookie="
                              + escape(value)
                              + ";expires="
                              + the_cookie_date;
                              + ";path=/;";

  document.cookie = the_cookie;
}




