home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2000 #10 / K_CD_10_2000.ISO / Web / Amused / www.amused.com / js / ad-amused.js
Text File  |  2000-06-08  |  3KB  |  88 lines

  1. /****    FUNCTION DESCRIPTION    ****/
  2. /*    returns string of characters between first occurrence of 2 delimeters (startStr & endStr). 
  3.     checkStr is the string to be checked. If endStr is not available, 
  4.     getWord returns the string between startStr and the end of checkStr  
  5.     called from writeAd() */
  6. function getWord(checkStr, startStr, endStr) {
  7.         var returnString = null;
  8.         var start = end = 0;
  9.         var length = 0;
  10.         /* If checkStr is a JavaObject, we must call length() as a method. Otherwise, it is a JavaScript property of "string" */
  11.         length = (typeof(checkStr) == "object") ? checkStr.length() : checkStr.length;
  12.         start = checkStr.indexOf(startStr);    
  13.         if (start != -1) {
  14.             start += startStr.length;
  15.             end = checkStr.indexOf(endStr,start);
  16.             if (end != -1) {
  17.                 returnString = checkStr.substring(start,end);
  18.                 }
  19.             else {
  20.                 returnString = checkStr.substring(start,length);
  21.             }
  22.         }
  23.         if ((returnString != "") && (returnString != null)) { 
  24.             return returnString; 
  25.         }        
  26.         else { 
  27.             return -1;
  28.         }
  29. }
  30.  
  31. /****    FUNCTION DESCRIPTION    ****/
  32. /*    Called from page location where ad needs to be written. Writes DoubleClick code based on information in adString passed to function.
  33.     site = Ad Site (e.g. "uproar.amused")
  34.     page = Page we're on (mostly "restofsite")
  35.     size = WidthxHeight (e.g. "468x60")
  36.     tile = Page Position (to differentiate multiple ads on page)
  37.     rich = Is this rich media? If not, we'll write simple creative
  38.     ord = Cache busting miscellaneous number
  39. */
  40. function writeAd(adString) {
  41.     var primarySrc = "http://ad.doubleclick.net/";
  42.     var site = getWord(adString,"site=","&");
  43.     var page = getWord(adString,"page=","&");
  44.     var size = getWord(adString,"size=","&");
  45.     var tile = getWord(adString,"tile=","&");
  46.     var rich = (adString.indexOf('richmedia=true')) ? true : false;
  47.  
  48.     var date = new Date();
  49.     var ord = "ord=";
  50.     ord += date.getTime();
  51.     ord += "?";
  52.     
  53.     site = (site == -1) ? "" : site + "/";
  54.     page = (page == -1) ? "" : page +";";
  55.     size = (size == -1) ? "sz=468x60;" : "sz="+size +";";
  56.     tile = (tile == -1) ? "tile=1;" : "tile=" + tile + ";";
  57.     
  58.     var width = getWord(size,"sz=","x");
  59.     var height = getWord(size,"x","&");
  60.     
  61.     if (rich) {
  62.         var iframeString = '<i'+'frame SRC="'+primarySrc+'adi/'+site+page+size+tile+ord+'" width="'+width+'" height="'+height+'" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no">';
  63.         var scriptString = '<s'+'cript language="JavaScript1.1" src="'+primarySrc+'adj/'+site+page+'abr=!ie;'+size+tile+ord+'"></s'+'cript>';
  64.         var hrefString = '<a href="'+primarySrc+'jump/'+site+page+size+tile+ord+'" target="_blank">';
  65.         var imgString = '<img name="'+size+'" src="'+primarySrc+'ad/'+site+page+size+tile+ord+'" border="0" width="'+width+'" height="'+height+'"></a>';
  66.     }
  67.     else {
  68.         var hrefString = '<a href="'+primarySrc+'jump/'+site+page+'abr=!ie;'+size+tile+ord+'">';
  69.         var imgString = '<img src="'+primarySrc+'ad/'+site+page+'abr=!ie;'+size+tile+ord+'" border=0 height="'+height+'" width="'+width+'"></a>';
  70.     }
  71.  
  72.     document.write('<'+'!-- Begin DoubleClick Ad -->');
  73.     if (rich) {
  74.         document.write(iframeString);
  75.         document.write(scriptString);
  76.         document.write('<noscript>');
  77.         document.write(hrefString);
  78.         document.write(imgString);
  79.         document.write('</noscript>');
  80.         document.write('</iframe>');
  81.     }
  82.     else {
  83.         document.write(hrefString);
  84.         document.write(imgString);
  85.     }
  86.     document.write('<'+'!-- End DoubleClick Ad -->');
  87. }
  88.