// Crated by Terapon Rodyam
// postdate 27-04-2009
/*-------------------------*/
// Default value

google_ad_client = 'pub-1044823792492543'; //Public ID
google_ad_output = 'js';
google_feedback = 'on';
google_adtest  = 'off'; //for test ad Default = 'off' 

/* Only insert this line for your first ad unit */ 
var google_adnum = 0; 

//Set value to default;
if(displayBorderTop==null){
	var displayBorderTop	 = false; 
}
if(displayLandScape==null){
	var displayLandScape = false; // false=Default, true=landscape *** if set Landscape not arrow ad type image
}
if(position_ad_detail==null){
	var position_ad_detail ='';//Set to Default
}

//Function google Ads
function google_ad_request_done (google_ads) {
var s = '';
var i;

//main container div
var container = document.createElement('div');//<div class="google-AdBox">...</div>
	container.className = 'google-AdBox';
	
	//chcek Display ad for landscape
	if(google_ads[0].type == 'text'){
		if(displayLandScape){
			container.id = 'Ad-landscap';	//for Ad Lanscape 
		}
	}
	//Check for Ad In content	
	if(position_ad_detail == 'in'){
		container.id = 'Ad-Intext'; //In Detail
	}else if(position_ad_detail=='under'){
			container.id = 'Ad-UnderDetail'; //Under Detail
			if (google_ads[0].type == 'image') {
				if(google_ads[0].image_width=='300'){
					container.style.margin="0 auto 10px";
					container.style.width =google_ads[0].image_width+"px";
					container.style.borderBottom = 0;
				}
			}
		
	}

//Create DIV Container 
document.getElementById(ads_ID).appendChild(container); 

if (google_ads.length == 0) {return;}

		//Create Ads By Google
		if (google_ads[0].type != "image"){ 
		var adBy = document.createElement('div'); //<div class="google-ads-by">...</div>
			adBy.className = 'google-ads-by';	
			headGoogle = '<a href="'+google_info.feedback_url+'" target="_blank">โฆษณาโดย Google</a>';
			adBy.innerHTML = headGoogle;
			container.appendChild(adBy);	
		}
//-------------- Founction for Image Ads
	function google_ad_create_IMG_elem (google_ad){
		// Google encodes "&"
		google_ad.url = google_ad.url.replace(/&amp;/g,"&");
		//	
		var ads = document.createElement('div'); //<div class="google-AdvertLnks">...</div>
	   		   ads.className = 'google-AdvertLnks';
			   ads.style.margin = 0;
			   ads.style.paddingTop = 0;
			   ads.style.paddingBottom = 0;
		var imgLink = document.createElement('a');
				imgLink.target = "_blank";
				imgLink.href = google_ad.url;
				imgLink.onmouseover = function () { window.status = google_ad.visible_url; return true; };
		var image =  document.createElement('img');
			   image.src= google_ads[0].image_url; 
			   image.width = google_ads[0].image_width;
			   image.height = google_ads[0].image_height;			   
			   imgLink.appendChild(image);
			   ads.appendChild(imgLink);
		return ads;	   
	}

//-------------- Founction for Text Ads
	function google_ad_create_elem (google_ad,count){
		// Google encodes "&"
		google_ad.url = google_ad.url.replace(/&amp;/g,"&");
		//		
		
		var ads = document.createElement('div'); //<div class="google-AdvertLnks">...</div>
				if(!displayBorderTop){	
					  ads.className = 'google-AdvertLnks';	
				}else{
					  ads.className = 'google-AdvertLnks '+'ad'+count;				
				}			
		
		var st = document.createElement('strong'); //<strong></strong>
		var Link1 = document.createElement('a');//<a></a>
				Link1.innerHTML = google_ad.line1;
				Link1.target = "_blank";
				Link1.href = google_ad.url;
				Link1.onmouseover = function () { window.status = google_ad.visible_url; return true; };
				st.appendChild(Link1);
				ads.appendChild(st);
				
	if(displayLandScape){				
		var span1 = document.createElement('span'); //<span></span>
		var Link2 = document.createElement('a');//<a></a>
				var i = document.createTextNode(google_ad.visible_url);
				Link2.target = "_blank";
				Link2.href = google_ad.url;
				Link2.onmouseover = function () { window.status = google_ad.visible_url; return true; };
				Link2.appendChild(i);
				span1.appendChild(Link2);
				ads.appendChild(span1);

		var span3 = document.createElement('span'); //<span></span>
			  span3.innerHTML = google_ad.line2 + ' ' + google_ad.line3; //show text description
  			  ads.appendChild(span3);
	}else{
		var span3 = document.createElement('span'); //<span></span>
			  span3.innerHTML = google_ad.line2 + ' ' + google_ad.line3; //show text description
  			  ads.appendChild(span3);

		var span1 = document.createElement('span'); //<span></span>
		var Link2 = document.createElement('a');//<a></a>
				var i = document.createTextNode(google_ad.visible_url);
				Link2.target = "_blank";
				Link2.href = google_ad.url;
				Link2.onmouseover = function () { window.status = google_ad.visible_url; return true; };
				Link2.appendChild(i);
				span1.appendChild(Link2);
				ads.appendChild(span1);	
	}			   
		return ads;	   
	}

//	alert('google_ads[0].type = '+google_ads[0].type);
	
	if (google_ads[0].type == "image") {
		var ad_img;
		ad_img = google_ad_create_IMG_elem(google_ads[0]);
		container.appendChild(ad_img); 
	} else if (google_ads[0].type == "text") {
		//For Loop show Ad	
		var ad;
		var count=0;
		for (var i = 0; i < google_ads.length; i++)	{
			count = count+1;	
			ad = google_ad_create_elem(google_ads[i],count);
			container.appendChild(ad);
		}

		if(google_ads[0].bidtype == "cpc") {
			google_adnum = google_adnum + google_ads.length;	
	    }		
	}
}//End Function