// Begin Utility functions
function GlamGetQueryVariable(variable) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
  return null;
} 

function GlamSetCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function GlamGetCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function GlamEraseCookie(name) {
	createCookie(name,"",-1);
}

// End Utility functions


function GlamShowAds()
{
   if ( window.location.href.indexOf('glam_module_mode=normal') > -1  )
   {
       GlamSetCookie('glam_module_mode', 'normal', 1);
   }
   else if ( window.location.href.indexOf('glam_module_mode=google_direct') > -1  )
   {
       GlamSetCookie('glam_module_mode', 'google_direct', 1);
   }
   else if ( window.location.href.indexOf('glam_module_mode=google_dart') > -1  )
   {
       GlamSetCookie('glam_module_mode', 'google_dart', 1);
   }

   if ( GlamGetCookie('glam_module_mode') == 'google_direct' ) {
        GlamShowGoogleAdDirect();
   }
   else if ( GlamGetCookie('glam_module_mode') == 'google_dart' ) {
        GlamShowGoogleAdViaDart();
   }
   else {
        if ( ! window.glam_module_type ) {
           window.glam_module_type = 'c_ad';
        }
             
        GlamShowGoogleAdDirect();
        //GlamShowRotatingAdViaDart();
   }
}


function show_glam_ads() { 
         google_adtest='on';
	window.google_skip = '0';

        if ( ! window.glam_ad_counter_defined  ) {
             window.glam_ad_counter_defined = true;
             window.glam_ad_counter = 0;
        }

        if ( ! window.glam_rad_counter_defined  ) {
             window.glam_rad_counter_defined = true;
             window.glam_rad_counter = 0;
        }
        
        if ( window.glam_module_type && window.glam_module_type == 'c_link' && 
             window.glam_rl_mode && window.glam_rl_mode == 'live') {
          google_adtest='off';
          window.google_adtest='off';
          window.google_skip = String(window.glam_rad_counter);
          //delete google_adtest;
          //delete window.google_adtest;
        }
        if ( window.glam_module_type && window.glam_module_type == 'c_ad' &&
             window.glam_ca_mode && window.glam_ca_mode == 'live') {
          google_adtest='off';
          window.google_adtest='off';
          //delete google_adtest;
          //delete window.google_adtest;
          window.google_skip = String(window.glam_ad_counter);
        }
        if ( window.glam_module_type && window.glam_module_type == 'c_ad' &&
             window.glam_google_mode && window.glam_google_mode == 'live') {
          google_adtest='off';
          window.google_adtest='off';
          //delete google_adtest;
          //delete window.google_adtest;
          window.google_skip = String(window.glam_ad_counter);
        }

	glam_protocol='http://';
	if ( window.location.href.indexOf('https') > -1 )
	{
	   glam_protocol='https://';
	}



/*
	google_ad_client = 'ca-glam_js';  // this is a glam site
        window.glam_google_prefix = 'GLAM';

        window.glam_is_blogger = false;
        glam_current_url = window.location.href.toLowerCase();
        if ( glam_current_url.indexOf('blogspot.com') > -1  || glam_current_url.indexOf('typepad.com') > -1)
        {
            window.glam_google_prefix = 'GNET';
            window.glam_is_blogger = true;
	    google_ad_client = 'ca-glam_3p_blog_js';  // this is a 3rd party hosted blogger site
        }
        else if ( window.glam_affiliate_id != '0' && window.glam_affiliate_id != '61091505' &&
                  window.glam_affiliate_id != '104510405' && window.glam_affiliate_id != '90480197' &&
                  window.glam_affiliate_id != '132714989' && window.glam_affiliate_id != '104510412' &&
                  window.glam_affiliate_id != '104510401'  )
        {
            window.glam_google_prefix = 'GNET';
	    google_ad_client = 'ca-glam_3p_js';  // this is a 3rd party site
        }
       
        
	google_ad_channel = ''; 
*/

        if ( ! window.glam_ad_type  ) {
             window.glam_ad_type  = 'text';
        }

         window.glam_ad_type =  window.glam_ad_type.toLowerCase();

        if ( ! window.glam_affiliate_id ) {
             window.glam_affiliate_id = '0';
        }
        if ( ! window.glam_placement_type ) {
             window.glam_placement_type = 'fixed';
        }
        if ( ! window.glam_color_border ) {
             window.glam_color_border = '#FFFFFF';
        }
        if ( ! window.glam_color_bg ) {
             window.glam_color_bg = '#FFFFFF';
        }
        if ( window.glam_color_title &&  window.glam_color_bg &&
              window.glam_color_title !=  window.glam_color_bg ) {
             window.glam_abg_color_bg = window.glam_color_bg;
             window.glam_abg_color_text = window.glam_color_title;
        }
        else {
             window.glam_abg_color_bg = '#FFFFFF';
             window.glam_abg_color_text = '#000000';
             if ( window.glam_color_bg == '#000000' ) {
                  window.glam_abg_color_bg = '#000000';
                  window.glam_abg_color_text = '#FFFFFF';
              }
        }

        if ( ! window.glam_color_link ) {
             window.glam_color_link = '#0000FF';
        }
        if ( ! window.glam_color_text ) {
             window.glam_color_text = '#000000';
        }
        if ( ! window.glam_color_url ) {
             window.glam_color_url = '#008000';
        }
        
        if ( ! window.glam_text_size ) {
             // Set default text size to 13 if it is not specified
             window.glam_text_size = '13';
        } else if (isNaN(glam_text_size) || glam_text_size < 9 || glam_text_size > 13) {
             // Check that the glam_text_size passed in is a number between 9-13
             glam_text_size = '13';
        }
		
        if ( ! window.glam_display_direct ) {
             window.glam_display_direct = true;
        }

        // if this is a Glam O&Om we never serve CPM Ads...
        /* UNCOMMENT THE FOLLOWING TO DISABLE CPM ADS ON GLAM O&O
        if ( window.glam_affiliate_id == '0' || window.glam_affiliate_id == '61091505' ||
             window.glam_affiliate_id == '104510405' || window.glam_affiliate_id == '90480197' ||
             window.glam_affiliate_id == '132714989' || window.glam_affiliate_id == '104510412' ||
             window.glam_affiliate_id == '104510401'  ) {
          google_targeting = 'content';
        }
       */


        if ( glam_placement_type == 'glam_rotating' ) {
             google_ad_channel = window.glam_google_RotatingChannelId;
             google_ad_client  = window.glam_google_RotatingClientId;
              //google_ad_channel = window.glam_google_prefix + '_D_' + glam_affiliate_id;
        }
        //else if ( glam_placement_type == 'rotating' ) {
             //google_ad_channel = window.glam_google_RotatingChannelId;
             //google_ad_client  = window.glam_google_RotatingClientId;
              ////google_ad_channel = window.glam_google_prefix + '_D_' + glam_affiliate_id;
        //}
        else if ( glam_placement_type == 'fixed' ) {
             google_ad_channel = window.glam_google_FixedChannelId;
             google_ad_client  = window.glam_google_FixedClientId;
              //google_ad_channel = window.glam_google_prefix + '_T_' + glam_affiliate_id;
        }
        else if ( glam_placement_type == 'search' ) {
             google_ad_channel = window.glam_google_SearchChannelId;
             google_ad_client  = window.glam_google_SearchClientId;
              //google_ad_channel = window.glam_google_prefix + '_S_' + glam_affiliate_id;
        }
        else if ( glam_placement_type == 'related_links' ) {

             google_ad_channel = window.glam_google_LinksChannelId;
             google_ad_client  = window.glam_google_LinksClientId;
	      	 //google_ad_client = 'ca-glam_radlinks_js';  // this is a glam site
             //google_ad_channel = window.glam_google_prefix + '_R_' + glam_affiliate_id;
        }

        if ( GlamGetQueryVariable('google_rt') != null && glam_placement_type == 'related_links' ) {

            google_rt =  GlamGetQueryVariable('google_rt');
        }
	google_ad_type = glam_ad_type;


	google_image_size = glam_ad_size;
        window.glam_show_as_cpm = false;
	ad_style      ='text-align:left;display:block;';
	// we calculate the number of ads to display based on the size of the ad

	//3-14-08
	glam_single_ad_width ='';

        // hack: if this is a 728 and it is the second time we call, we use a text ad bc it might be at the end of the page
	if ( window.glam_ad_counter > 0 &&  glam_ad_size == "728x90" ) {
	   google_ad_type='text';
	   google_max_num_ads = '3'; 			//test 3-14-08: if change to 4; glam_single_ad_width is 175
	   glam_single_ad_width = 225;      //test 3-14-08: go to #597 to change colspan to 4
	}
	else if ( glam_ad_size == "728x90" ) {
	   google_max_num_ads = '3'; 		//test 3-14-08: if change to 4; glam_single_ad_width is 175
	   glam_single_ad_width = 225;  //test 3-14-08: go to #597 to change colspan to 4
	}
	else if ( glam_ad_size == "468x60" ) {
		ad_style = 'text-align:left;';
		google_max_num_ads = 2; //the max number is supposed to be 2; 4-14-08 sylc 
		glam_single_ad_width = 200; //ads are placed side by side 4-14-08 sylc
	}
	else if ( glam_ad_size == "234x60" ) {
	    google_ad_type = 'text'; // this ad size only supports text ads
		ad_style = 'text-align:left;';
		google_max_num_ads = '1';
		glam_single_ad_width = 234;
	}
	else if ( glam_ad_size == "125x125" ) {
	        google_ad_type = 'text'; // this ad size only supports text ads
		google_max_num_ads = '1';
		glam_single_ad_width = 125;
	}
	else if ( glam_ad_size == "120x600" ) {
	    google_ad_type = 'text'; // Should be fixed.
		google_max_num_ads = '4';
		glam_single_ad_width = 120;
	}
	else if ( glam_ad_size == "160x600" ) {
		google_max_num_ads = '5';
		glam_single_ad_width = 160;
	}
	else if ( glam_ad_size == "180x150" ) {
	    google_ad_type = 'text'; // this ad size only supports text ads
		google_max_num_ads = '1';
		glam_single_ad_width = 180;
	}
	else if ( glam_ad_size == "120x240" ) {
	        google_ad_type = 'text'; // this ad size only supports text ads
		google_max_num_ads = '2';
		glam_single_ad_width = 120;
	}
	else if ( glam_ad_size == "300x250" ) {
		google_max_num_ads = '3';
		glam_single_ad_width = 300;
	}
	else if ( glam_ad_size == "200x200" ) {
		google_max_num_ads = '2';
		glam_single_ad_width = 200;
	}
	else if ( glam_ad_size == "250x250" ) {
		google_max_num_ads = '2';
		glam_single_ad_width = 250;
	}
	else if ( glam_ad_size == "336x280" ) {
	        google_ad_type = 'text'; // this ad size only supports text ads
		google_max_num_ads = '4';
		glam_single_ad_width = 336;
	}
	else if ( glam_ad_size == "300x600" ) {
		google_max_num_ads = '7';
		glam_single_ad_width = 300;
	}
        else if ( glam_ad_size == "158x380" ) {
                google_max_num_ads = '4';
				glam_single_ad_width = 158;
        }
	else {
		// we dont know what the size is... we make it one
                google_max_num_ads = '1';
	}

        // if the ad type requested says image but we dont support it, we remove it from the list
        
        if ( google_ad_type == 'image' ) {
            google_max_num_ads = '1';
        }
        else if ( google_ad_type == 'text' ) {
	    google_image_size = '';
        }

        // if we were given a number of ads, this is a custom size module for text ads....
        if ( window.glam_max_num_ads && window.glam_max_num_ads > 0 ) {
                google_max_num_ads = window.glam_max_num_ads;
                google_ad_type = 'text';
        }
 
	window.glam_ad_width = parseInt(glam_ad_size.substring(0,3));
	window.glam_ad_height = parseInt(glam_ad_size.substring(4));
        window.glam_ad_span = glam_ad_width;

       google_ad_output = 'js';
       // we force the mode to be custom till google has fixed their bug 
       window.glam_display_template = 'custom'; 

       if ( window.glam_display_template && window.glam_display_template == 'standard' ) {
           google_ad_output = 'html';
	   google_ad_width = window.glam_ad_width;
	   google_ad_height = window.glam_ad_height;
           google_ad_format = glam_ad_size + '_as';
           google_color_border = glam_color_border.substring(glam_color_border.indexOf('#')+1);
           google_color_bg = glam_color_bg.substring(glam_color_bg.indexOf('#')+1);
           google_color_link = glam_color_link.substring(glam_color_link.indexOf('#')+1);
           google_color_url = glam_color_url.substring(glam_color_url.indexOf('#')+1);
           google_color_text = glam_color_text.substring(glam_color_text.indexOf('#')+1);
        }

        if ( window.glam_custom_line_separator && window.glam_custom_line_separator != '' ) {
              window.glam_ads_line_separator = window.glam_custom_line_separator;
        }
        else if ( glam_ad_span < 200 || glam_ad_size == '300x250' || glam_ad_size == '250x250' || glam_ad_size == '336x280') {
            window.glam_ads_line_separator = ' ';
        }
        else {
            window.glam_ads_line_separator = '<br />';
        }
          
    
        if ( window.glam_keywords && window.glam_ad_targetting &&  window.glam_ad_targetting == 'keyword' ) {
                google_hints = '';
                google_kw = window.glam_keywords;
                google_kw_type = 'broad';
        }
	else if ( window.glam_keywords && window.glam_keywords != '') {
		google_hints = glam_keywords; 
	}
        else {
                google_hints = '';
                google_kw = '';
                google_kw_type = '';
        }


	google_encoding = 'utf8'; 
	google_safe = 'high'; 


    google_num_radlinks = 0;
    if ( window.glam_placement_type && window.glam_placement_type == 'related_links' &&
         google_kw && google_kw != '' )
    {
          google_kw_type = 'radlink';
    }
    if ( window.glam_module_type && window.glam_module_type == 'c_link' )
    {
     google_max_radlink_len = 15; 
     google_rl_filtering = 'high'; 
     google_rl_mode = 'relevance';
     google_kw_type = '';
     if ( google_kw && google_kw != '' )
     {
          google_kw_type = 'broad';
     }

     google_num_radlinks = glam_max_num_links;
     google_ad_type='*';
     google_max_num_ads = '0';
     window.glam_max_num_ads = 0;
     google_prev_ad_formats_by_region = 'adlinks';
     google_page_url = window.location.href;     
     //google_page_url = document.referrer;
    }
	document.write('<scr' + 'ipt type="text/javascript" language="JavaScript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><' + '/sc' + 'ript>');

}

function glam_prepare_style() {  

    if ( ! window.glam_click_url  )
    {
        window.glam_click_url = '';
    }
    window.glam_click_url = '';

    // if the color of the url is white, we force it to black
    if ( glam_color_url == "FFFFFF" ) {
         glam_color_url = "000000";
    }

	glam_default_margin_1 = 'margin: 1px 0px 0px 0px !important;'; //4-14-08 changed the top padding from 5px to 1px
    glam_default_margin_2 = 'margin: 0px 0px 0px 0px !important;';
    glam_default_text_font = 'font-size:11px;';
    glam_default_font_family = 'font-family: Arial,Verdana,sans-serif !important;';

    if ( window.glam_ads_abg_style && window.glam_ads_abg_style != '' ) {
       glam_google_abg_style = window.glam_ads_abg_style;
       glam_custom_google_abg_style = true;
    }
    else {
       glam_google_abg_style=glam_default_margin_2 + 
                             'padding: 1px 0px 1px 0px; text-align:left;font-family:Arial,Verdana,sans-serif;font-size:8pt;color:'+
                             glam_abg_color_text;
       glam_custom_google_abg_style = false;
    }

    if ( window.glam_ads_line1_style && window.glam_ads_line1_style != '' ) {
       glam_google_line1_style = window.glam_ads_line1_style;
    }
    else {
       glam_google_line1_style=glam_default_margin_1 + glam_default_text_font + 'text-decoration:underline;font-weight: bold; color:'+glam_color_link;
    }

    if ( window.glam_ads_line2_style && window.glam_ads_line2_style != '' ) {
       glam_google_line2_style = window.glam_ads_line2_style;
    }
    else {
       glam_google_line2_style=glam_default_margin_2 + glam_default_font_family +  glam_default_text_font + 'color:'+glam_color_text;
    }

    if ( window.glam_ads_url_style && window.glam_ads_url_style != '' ) {
       glam_google_url_style = window.glam_ads_url_style;
    }
    else {
       glam_google_url_style=glam_default_margin_2 + 'font-size:9px;color:'+glam_color_url;
    }
    if ( window.glam_ads_box_style && window.glam_ads_box_style != '' ) {
       glam_google_box_style = window.glam_ads_box_style;
       glam_custom_google_box_style = true;
    }
    else {
       glam_google_box_style='background:' + glam_color_bg +';width:'+glam_ad_span+'px;text-align:left';
       glam_custom_google_box_style = false;
    }


    if ( ! glam_custom_google_box_style  && window.glam_color_border ) {
        glam_google_box_style += ';border:solid 1px ' + window.glam_color_border ;
    }
    else if ( ! glam_custom_google_box_style  ) {
        glam_google_box_style += ';border:solid 1px black;';
    }


    if (  window.glam_module_type && window.glam_module_type == 'c_link' ) {
        glam_google_abg_style += ';background:' + window.glam_abg_color_bg  ;
    }
    else if ( ! glam_custom_google_abg_style  && window.glam_color_border ) {
        glam_google_abg_style += ';background:' + window.glam_abg_color_bg + '; border-bottom:solid 1px ' + window.glam_color_border ;
        //glam_google_abg_style += ';background:' + window.glam_abg_color_bg  ;
    }
    else if ( ! glam_custom_google_abg_style  ) {
        glam_google_abg_style += ';background:' + window.glam_abg_color_bg + '; border-bottom:solid 1px black;';
        //glam_google_abg_style += ';background:' + window.glam_abg_color_bg  ;
    }

    
    glam_url_span = ';width:' +(glam_ad_span-10)+'px;';

    if ( glam_ad_size == "728x90" || (window.glam_display_orientation && window.glam_display_orientation == 'horizontal')) {
         glam_url_span = '';
         ad_separator_begin = '<td ' + ad_cell_style + ' >';
         ad_separator_end = '</td>';
    } 
	//begin: test 468 x 60 dimension 4-14-08
	else   if ( glam_ad_size == "468x60" || (window.glam_display_orientation && window.glam_display_orientation == 'horizontal')) {
         glam_url_span = '';
         ad_separator_begin = '<td ' + ad_cell_style + 'valign="top" >';
         ad_separator_end = '</td>';
    } //end: test 468 x 60 dimension 4-14-08
    else {
         ad_separator_begin = '<tr><td ' + ad_cell_style + ' >';
         ad_separator_end = '</td></tr>';
    }

}





function google_ad_request_done(google_ads) { 
   //if statement added 01/31/2008 by Simon as this was being execulted even though module type was c_link
   if (window.glam_module_type == 'c_link') { return;}
    var s = ''; 
    var i; 

    window.glam_google_ads_found = google_ads.length;
//alert('ads count = ' + google_ads.length);
    if (google_ads.length == 0) { 
//      document.write('<span style="color:#000000;">No google ads were returned</span>');
      return; 
    } 

    ad_cell_style = '';
	
	//Test CPM ad by using the following 2 lines
	//google_ads.length = 1;
	//window.glam_show_as_cpm = true;
	
    if ( ( window.glam_show_as_cpm == true || google_ads[0].bidtype == 'CPM') && google_ads.length == 1 ) {
            //ad_cell_style = 'height="' + (glam_ad_height-30) + '" valign="middle" align="center" ';
			if (glam_ad_size == "125x125" ){
				ad_style = 'text-align:left;';
			} else {
				ad_style = 'text-align:center;';
			}
			
			if ((glam_ad_size == "234x60" ) || (glam_ad_size == "468x60" )) {
					glam_text_size = '11';
			} else {
					glam_text_size = '13';	
			}
			
			
			
			google_max_num_ads = '1';
			glam_single_ad_width = glam_ad_size.substr(0,glam_ad_size.indexOf('x'));

    } else {
	if ((glam_ad_size == "234x60") || (glam_ad_size == "468x60")) {
		if ((parseInt(glam_text_size)) > 11) {
			glam_text_size = '11';
		}
	}
    }

    // we prepare all the possible formatting based on parameters...
    glam_prepare_style();
    glam_google_box_style = 'height:' + glam_ad_height + 'px;' + glam_google_box_style;

    if (google_ads[0].type == "image") {  

      glam_ads_image_abg_style = "height:10px; padding: 0px 0px 0px 5px; line-height:10px; background:#656565; font-family:Arial,Verdana,sans-serif;color:#FFFFFF;font-weight:normal;font-size:7; border:solid 1px #656565;";

      glam_ads_url_style="height: 10px; margin: 0px 2px 0px 2px; line-height:10px;color:#656565;font-size:10px;";
      //s += '<table cellspacing="0" cellpadding="0" border="0" style="border:solid 1px #656565;">' +



      s += '<table cellspacing="0" cellpadding="0" border="0" style="border:1px solid #ccc;">' +
            //'<tr><td valign="top" align="center" style="' + glam_ads_image_abg_style + '">' +
             // 'Ads by Google</td></tr>' + 
  
              '<tr><td><div style="padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; height: '+ google_ads[0].image_height + 'px;" ' + 
              'onmouseout="window.status=\'\'; return true;" ' + 
              'onmouseover="window.status=\'' + 
              google_ads[0].visible_url + '\'; return true;" >' + 
              '<a href="' + window.glam_click_url + google_ads[0].url + 
              '" target="_' + String(Math.random()*10000000000000000) + '" title="' + google_ads[0].visible_url + 
              '"><img border="0" src="' + google_ads[0].image_url + 
              '"width="' + google_ads[0].image_width + 
              '"height="' + google_ads[0].image_height + '"></a></div></td></tr>' +
              '<tr><td valign="top" align="center" style="' + glam_ads_url_style + ';text-align:center;">' +
              '<div style="padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px; ';
			  if ((parseInt(google_ads[0].image_width)) > (parseInt(google_ads[0].image_height))) {				  		
			  	s += 'float:left;"';
			  }
              s += 'onmouseout="window.status=\'\'; return true;" ' +
              'onmouseover="window.status=\'' +
              google_ads[0].visible_url + '\'; return true;" >' +
              '<a style="text-decoration:none" href="' + window.glam_click_url + google_ads[0].url + 
              '" target="_' + String(Math.random()*10000000000000000) + '" title="' + google_ads[0].visible_url + '">' +
              google_ads[0].visible_url + '</a></div>';
			  if ((parseInt(google_ads[0].image_width)) > (parseInt(google_ads[0].image_height))) {		
				s += '<div style="float: right;">Ads by Google</div></td></tr>';
			  } else {
				  s += '<tr><td valign="top" align="center" style="' + glam_ads_image_abg_style + ';text-align:center;">' +
    	          'Ads by Google</td></tr>';
			  }
			  s +='</table>'; 
			  
	document.write(s);
	} else if (google_ads[0].type == "text") {

        
        s += '<table style="'+ glam_google_box_style +  '" width="' + glam_ad_span + '" cellspacing="0" cellpadding="0" border="0"><tr><td valign="top" class="glam_single_ad_style_' + glam_single_ad_width  + '">';

        s += '<table cellspacing="0" cellpadding="0" border="0" height="' + (glam_ad_height-30) + '">';

        if ( glam_google_abg_style && glam_google_abg_style != "none" ) {
           s += '<tr><td valign="middle" colspan="3" width="' + glam_ad_span + '"  style="height:18px; ' + glam_google_abg_style + '">Ads by Google</td></tr>';
        } //change it to 4 due to max number ad for 728x 90 is 4; 4-14-08

        for(i=0; i < google_ads.length; ++i) { 
            if ( google_ads[i].url && google_ads[i].line1) {
		ad_font_begin = '<div style="text-decoration:underline;color:'+glam_color_link+';font-family:arial,sans-serif;font-size:' + glam_text_size + 'px; line-height:' + (parseInt(glam_text_size)+2) + 'px; margin-left:0px;'+ ad_style + '">';

		
		ad_font_desc_begin = '<div style="font-weight:normal;color:'+glam_color_text+';font-family:arial,sans-serif;font-size:' + glam_text_size + 'px; line-height:' + (parseInt(glam_text_size)+2) +'px; margin-left:0px;' + ad_style + '">';
		
		ad_font_url_begin = '<div style="font-family:arial,sans-serif;color:'+glam_color_url+';font-size:10px; line-height:14px; margin-left:0px;' + ad_style + '">';
		ad_font_end   = '</div>';

            // if this is a cpm ad, we show it bigger
            //if ( google_ads[i].bidtype == 'CPM' || window.glam_show_as_cpm == true ) {
             //  ad_font_begin = '<span style="font-size:15px; line-height:15px;">';
  	       	  // ad_font_desc_begin = '<span style="font-size:15px; line-height:15px;">';
             //  ad_font_url_begin = '<span style="font-size:10px; line-height:15px;">';
            //   ad_font_end   = '</span>';
             //  ad_style      ='text-align:center; ';
             //  glam_ads_line_separator = '<br />';
            //}
			
            ad_link_html_begin = '<a target="_' + String(Math.random()*10000000000000000) + '" href="' +
                              window.glam_click_url + google_ads[i].url + '" ' +
                              'onmouseout="window.status=\'\'; return true;" ' +
                              'onmouseover="window.status=\'' +
                              google_ads[i].visible_url + '\'; return true;" ' +
                              'class="GlamDefaultLinkDeclaration">';
            ad_link_html_end = '</a>';

            if ( window.location.href.indexOf('glamGoogleTestLongLine') > -1 ) {
                google_ads[i].line1 = 'ColorARibbonsADiamondsABlonds';
                google_ads[i].line2 = 'ColorARibbonsADiamondsABlonds';
                google_ads[i].visible_url = 'ColorARibbonsADiamondsABlonds';
            }
            s += ad_separator_begin +
			
				//'<div style="overflow:hidden;' + glam_url_span + ad_style + 'margin: 12px 0 13px 2px; width: ' + (glam_ad_span-10)+'px !important;">' +
				//the width is not glam_ad_span-10; should be based on single ad width set above 

                 '<div style="overflow:hidden;' + glam_url_span + ad_style + 'margin: -1px 0 2px 2px; width: ' + (glam_single_ad_width-4) +'px !important;">' +
				 	 
                 ad_link_html_begin +
                 //'<span style="display:block; overflow:hidden;' + glam_google_line1_style + glam_url_span + '">' + 
                 '<div style="' + glam_google_line1_style + '">' + 
                 '' + ad_font_begin + google_ads[i].line1 + ad_font_end + '</div>' + 
                 ad_link_html_end +
                
				 ad_link_html_begin +
                 //'<div style="overflow:hidden;' + glam_google_line2_style + glam_url_span + '">' + 
                 '<div style="' + glam_google_line2_style + '">' + 
                 ad_font_desc_begin + google_ads[i].line2 + glam_ads_line_separator  + 
                 google_ads[i].line3 + ad_font_end + '</div>' + 
                 ad_link_html_end;
                 
                 //these two ad sizes do not show url in google 4-14-2008
                 if ((glam_ad_size != '468x60') && (glam_ad_size != '234x60')) {
			s +=		 ad_link_html_begin +
			//'<span  style="display:block;' +(glam_url_span)+ ';overflow:hidden;' + glam_google_url_style + '">' + 
			'<div style="' + glam_google_url_style + '">' + 
			ad_font_url_begin  + google_ads[i].visible_url + ad_font_end + '</div>' +
			ad_link_html_end + 
			'</div>';
		 }	 
                 s += ad_separator_end; 

           }
        } 
    s +="</table></td></tr></table>";
    glamDefaultLinkDeclaration = '<style>.GlamDefaultLinkDeclaration {border:none !important;text-decoration:none !important;padding:0 !important;}';
    glamDefaultLinkDeclaration += 'a.GlamDefaultLinkDeclaration, a.GlamDefaultLinkDeclaration:link, a.GlamDefaultLinkDeclaration:visited, a.GlamDefaultLinkDeclaration:hover {background-color: '+ glam_color_bg +' !important;cursor:pointer !important; background: none !important; }	</style>';
    glamDefaultLinkDeclaration += '<style>td.glam_single_ad_style_' + glam_single_ad_width  + ' div {width: ' +(glam_single_ad_width-4)+'px !important;} </style>'; //3-14-08 the width for one entry diff width base on size;
    document.write(glamDefaultLinkDeclaration);
    document.write(s); 
    } 

    window.glam_ad_counter = window.glam_ad_counter + google_ads.length;
    window.glam_click_url = '';
    window.glam_max_num_ads = 0;
    window.glam_ads_line_separator = '';
    window.glam_custom_line_separator = '';
    window.glam_display_orientation='';
    window.glam_placement_type = '';
    return; 
} 




function google_radlink_request_done(google_radlinks) { 

    var s = ''; 
    var i; 

    window.glam_google_ads_found = google_radlinks.length;
    if (google_radlinks.length < 1) 
      return; 

    ad_cell_style = '';

    // we prepare all the possible formatting based on parameters...
    glam_prepare_style();
    ad_style      = '';

    glam_google_box_style = glam_google_box_style + ';line-height:1em;';
    s += '<table   style="'+ glam_google_box_style +  '" cellspacing="0" cellpadding="0" border="0">';

    cell_width = '' ; //'width="' + parseInt(100/(google_radlinks.length+1)) + '%"'; 
    if ( glam_google_abg_style && glam_google_abg_style != "none" ) {
     if ( glam_display_orientation == 'vertical' ) {
       s += '<tr><td valign="middle" colspan="9" width="' + glam_ad_span + '"  style="height:15px; ' + glam_google_abg_style + '"><b>Related Ads</b></td></tr>';
     }
     else {
       s += '<tr><td ' + cell_width + ' valign="middle" align="left" style="height:15px; ' + glam_google_abg_style + '"><b>Related Ads</b></td>';
     }
    }


    if ( glam_display_orientation == 'horizontal' ) {
       ad_separator_begin = '<td ' + cell_width + ' valign="middle" align="left">';
       ad_separator_end = '</td>';
    }

    // pass page_url parameter
    origURLsearch = location.href;
    cutAtsearch = (origURLsearch.indexOf('?') > 0) ? origURLsearch.indexOf('?') : origURLsearch.length;
    contentURL = encodeURIComponent(origURLsearch.substring(0, cutAtsearch));

    for(i=0; i < google_radlinks.length; ++i) { 
      if ( google_radlinks[i].term  ) {
        ad_font_begin = '';
        ad_font_url_begin = '';
        ad_font_end   = '';
        ad_style      = '';

        // changed so it does not open a new window ad_link_html_begin = '<a target="_' + String(Math.random()*10000000000000000) + '" href="' +
        ad_link_html_begin = '<a href="' +
                          window.glam_click_url + 
                          'http://search.glam.com/search/affiliate/?submitButton.x=18&submitButton.y=7&affiliateId=' + 
                          glam_affiliate_id + '&searchMode=site&radLink=true&q=' +
                          google_radlinks[i].url_escaped_term + '&google_rt=' +
                          google_radlinks[i].radlink_token + '&google_prev_ad_formats_by_region=adlinks&page_url=' + contentURL + '" '+
                          'onmouseout="window.status=\'\'; return true;" ' +
                          'onmouseover="window.status=\'' +
                          google_radlinks[i].term + '\'; return true;" ' +
                          'style="background:none;border:none;text-decoration:none">';
        ad_link_html_end = '</a>';

        s += ad_separator_begin +  
             '<div style="' + ad_style + 'margin-top:1px; margin-bottom:1px;">' +
             ad_link_html_begin +
             '<span style="' + glam_google_line2_style + ';line-height:normal !important;text-decoration:underline;">' + 
             '' + ad_font_begin + google_radlinks[i].term + ad_font_end + '</span>' + 
             ad_link_html_end +
            '</div>' +
             ad_separator_end; 

      }
    } 

    if ( glam_display_orientation == 'horizontal' ) {
         s += "</tr>";
    }
    s += "</table>";
    document.write(s); 

    // Uncomment following line to see html
    //document.getElementById('html_text').value = s;

    window.glam_rad_counter = window.glam_rad_counter + google_radlinks.length;
    window.glam_click_url = '';
    window.glam_max_num_ads = 0;
    window.glam_max_num_links = 0;
    window.google_num_radlinks = 0;
    window.glam_ads_line_separator = '';
    window.glam_custom_line_separator = '';
    window.glam_display_orientation='';
    return; 
} 






if ( ! window.glam_display_direct ) {
      window.glam_display_direct = true;
}

if ( window.glam_affiliate_id && window.glam_affiliate_id != '' &&
     ! window.glam_settings_included )
{
      window.glam_settings_included = true;
      // We set default variables for everything in case there is a problem loading the settings
      window.glam_rl_mode='test';
      window.glam_ca_mode='test';
      window.glam_google_SiteType='GLAM';
      window.glam_google_SearchChannelId='GLAM_S_0';
      window.glam_google_LinksChannelId='GLAM_R_0';
      window.glam_google_RotatingChannelId='GLAM_D_0';
      window.glam_google_FixedChannelId='GLAM_T_0';
      
      window.glam_google_SearchClientId='glam';
      window.glam_google_LinksClientId='ca-glam_radlinks_js';
      window.glam_google_RotatingClientId='ca-glam_js';
      window.glam_google_FixedClientId='ca-glam_js';

      document.write('<scr' +
                     'ipt type="text/javascript" language="JavaScript" src="http://www2.glam.com/app/site/affiliate/viewChannelModule.act?mName=getSettings&affiliateId=' +
                      window.glam_affiliate_id + '"><' + '/sc' + 'ript>');
}
else if ( window.glam_display_direct &&  window.glam_display_direct == true && 
          (window.glam_module_type == 'c_ad' || window.glam_module_type == 'c_link') )
{
      show_glam_ads();
}


