function winstat(w) {window.status = w; return true;}
function clearstat(){window.status='';}

function CheckRef(){
  
  var ref = document.referrer.toLowerCase();

  if (!ref) {    return false;  }
  try
   {
  
      if (ref.indexOf('news.google.') > 0)  { return false; }
	 
	  if (ref.indexOf('google.') > 0)  { return true; }
      if (ref.indexOf('yahoo.') > 0) {return true; }
      if (ref.indexOf('search.msn.') > 0) {return true; }
	  if (ref.indexOf('askjeeves.') > 0) {return true; }
	  if (ref.indexOf('aol.') > 0) {return true; }

   }
   catch(ex) {};
  
   return false;
 
}


function google_ad_request_done(google_ads) {  

	var first_ad_unit = '', second_ad_unit = '', goog_url = '';

	// default for second unit	
	var defSec =  '<!-- Begin GS SWF -->' +
				'	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="250" height="250" id="Globalspec_250x250_toolbar" align="middle">' +
				'		  <param name="allowScriptAccess" value="sameDomain" />' +
				'		  <param name="movie" value="http://affiliates.globalspec.com/pix/affiliate/Globalspec_250x250_toolbar.swf?img=83&kbid=1400&frmtrk=affiliate&version=Globalspec_250x250_toolbar060404" />' +
				'		  <param name="quality" value="high" />' +
				'		  <param name="bgcolor" value="#4C699E" />' +
				'		  <embed src="http://affiliates.globalspec.com/pix/affiliate/Globalspec_250x250_toolbar.swf?img=83&kbid=1400&frmtrk=affiliate&version=Globalspec_250x250_toolbar060404" quality="high" bgcolor="#4C699E" width="250" height="250" name="Globalspec_250x250_toolbar" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
				'	</object><span style="position:absolute;"><img src = "http://www.myaffiliateprogram.com/u/globalsp/se.asp?e=83&id=1400"></span>' +
				'<!-- End GS SWF -->';
	
	// 'Ads by google' to first and second 				

		goog_url = '<p style="margin: 4px 4px 6px 10px; padding: 0px; color: GRAY; font-size: 0.9em;" align="left">'; 
		goog_url +='Sponsored Links&nbsp';
		if (google_info.feedback_url) {
		goog_url += '<a href=\"' + google_info.feedback_url + 
					'\">(Ads by Google)</a>';
					} else {
					 goog_url += '(Ads by Google)';
					}
		goog_url += '</p>';



	if (google_ads.length > 0) {

	first_ad_unit += '<div class="adsenseframe">';

	//	if first ad == image	
	if (google_ads[0].type == "image") {
					 first_ad_unit += '<a href="' + google_ads[0].url +
					  '" target="_top" title="go to ' + 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>';
    } 

	// fill the first block			
	else
	{
		first_ad_unit += goog_url; 	
		
		// if only one ad
		if (google_ads.length == 1) {
										 
							  
							  first_ad_unit += '<p style="margin: 4px 4px 2px 10px; font-weight: bold; font-size: 1.4em;">' +
							  '<a onMouseOver="return winstat(\'go to ' + google_ads[0].visible_url +' \')" onMouseOut=\"clearstat()\" href="' +  google_ads[0].url + '">' +
							  google_ads[0].line1 + "</a> - " +
							  '<a style="text-decoration: none; font-weight: normal; color: BLACK;" onMouseOver=\"return winstat(\'go to ' + google_ads[0].visible_url +' \')\" onMouseOut=\"clearstat()\" href=\"' +  google_ads[0].url + '\">' +
							  google_ads[0].line2 + ' ' + google_ads[0].line3 + 
							  '</a>'+
							  '</p>';
		}
		// if more ads
		else
		{
			for(var i = 0; i < 3; ++i) {
				if (google_ads[i].type == 'text') {
			 				  first_ad_unit += '<p style="margin: 4px 4px 2px 10px; font-weight: bold; ">' +
							  '<a onMouseOver="return winstat(\'go to ' + google_ads[i].visible_url +' \')" onMouseOut=\"clearstat()\" href="' +  google_ads[i].url + '">' +
							  google_ads[i].line1 + "</a> - " +
							  '<a style="text-decoration: none; font-weight: normal; color: BLACK;" onMouseOver=\"return winstat(\'go to ' + google_ads[i].visible_url +' \')\" onMouseOut=\"clearstat()\" href=\"' +  google_ads[i].url + '\">' +
							  google_ads[i].line2 + ' ' + google_ads[i].line3 + 
							  '</a>'+
							  '</p>';
				}
			}
		}// end else more ads

		// close adsenseframe DIV
		first_ad_unit += '</div>';			
	} // end fill the first block	

	// second block
	if (google_ads.length > 2) {
				second_ad_unit += goog_url; 	
				for(var i = 3; i < google_ads.length; ++i) {
					if (google_ads[i].type == 'text') {
			 				  second_ad_unit += '<p style="margin: 4px 4px 2px 10px; font-weight: bold; ">' +
							  '<a onMouseOver="return winstat(\'go to ' + google_ads[i].visible_url +' \')" onMouseOut=\"clearstat()\" href="' +  google_ads[i].url + '">' +
							  google_ads[i].line1 + "</a> <br> " +
							  '<a style="text-decoration: none; font-weight: normal; color: BLACK;" onMouseOver=\"return winstat(\'go to ' + google_ads[i].visible_url +' \')\" onMouseOut=\"clearstat()\" href=\"' +  google_ads[i].url + '\">' +
							  google_ads[i].line2 + ' ' + google_ads[i].line3 + 
							  '</a>'+
							  '</p>';
					}
				}

	}// end if > 2
	
	} // end google_ads.length > 0

	// add default ads from tradepub/globalspec
	
	if (first_ad_unit == ''){
		first_ad_unit +=	'<a href="http://physorg.tradepub.com/?pt=cat&page=_INTL">'+
							'<img src="banner/lifesci468x60.gif" border="0" width="468" height="60" alt=""></a>';
	}

	
	if (second_ad_unit == ''){
		second_ad_unit +=	defSec;
	}


	if (CheckRef()){
		document.getElementById("top_ad_unit").innerHTML += first_ad_unit + '<br>';
	}
	else {
		document.getElementById("first_ad_unit").innerHTML += first_ad_unit;
	}

	document.getElementById("second_ad_unit").innerHTML += second_ad_unit;
	
}