home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 August / Chip_2004-08_cd2.bin / avid_dvfree / info / limit_soubory / setTracking.js < prev    next >
Text File  |  2004-06-17  |  2KB  |  77 lines

  1. function setCookie(name, value, expire) {
  2.     document.cookie = name + "=" + escape(value) + "; path=/" + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
  3. }
  4.  
  5. function createRequestObject(){
  6.     var request   = new Object();       // Creates a new request object.
  7.     var nameVal   = "";                 // Holds array for a single name-value pair.
  8.     var inString  = location.search;    // Strips query string from URL.
  9.     var separator = ",";                 // Character used to separate multiple values.
  10.  
  11.    // If URL contains a query string, grabs it.
  12.  
  13.     if (inString.charAt(0) == "?")
  14.     {
  15.         // Removes "?" character from query string.
  16.         inString = inString.substring(1, inString.length);
  17.         // Separates query string into name-value pairs.
  18.         keypairs = inString.split("&");
  19.         // Loops through name-value pairs.
  20.         for (var i=0; i < keypairs.length; i++)
  21.         {
  22.             // Splits name-value into array (nameVal[0]=name, nameVal[1]=value).
  23.             nameVal = keypairs[i].split("=");
  24.             // Replaces "+" characters with spaces and then unescapes name-value pair.
  25.             for (a in nameVal)
  26.             {
  27.                nameVal[a] = nameVal[a].replace(/\+/g," ");
  28.                nameVal[a] = unescape(nameVal[a]);
  29.             }
  30.             // Checks to see if name already exists in request object
  31.             // (since select lists may contain multiple values).
  32.             if (request[nameVal[0]])
  33.             {
  34.             request[nameVal[0]] += separator + nameVal[1];
  35.             }
  36.             else
  37.             {
  38.             request[nameVal[0]] = nameVal[1];
  39.             }
  40.         }
  41.     }
  42.     return request;
  43. }
  44.  
  45. function getTrackingID(){
  46.     request = createRequestObject();
  47.     if(request.itrackingid){
  48.         setCookie("source",request.itrackingid);
  49.     }
  50. }
  51.  
  52. function getPOI(){
  53.     request = createRequestObject();
  54.     if(request.poi){
  55.         setCookie("product",request.poi);
  56.     }
  57. }
  58.  
  59.  
  60. function getCookie(Name) {
  61.     var search = Name + "=";
  62.     if (document.cookie.length > 0) { // if there are any cookies
  63.         offset = document.cookie.indexOf(search);
  64.         if (offset != -1) { // if cookie exists
  65.             offset += search.length;
  66.             // set index of beginning of value
  67.             end = document.cookie.indexOf(";", offset);
  68.             // set index of end of cookie value
  69.             if (end == -1)
  70.                 end = document.cookie.length;
  71.             return unescape(document.cookie.substring(offset, end))
  72.         }
  73.     }
  74. }
  75.  
  76. getTrackingID();
  77. getPOI();