// JavaScript Document
Ads = function(){
	
}
Ads.url = 'http://www.hongpak.in.th/';
Ads.urlreal = 'http://realestate.hongpak.in.th/';
Ads.ads = new Array();
Ads.adsstat = new Array();
Ads.ads['T'] = [ { "id": "98", "name": "กรองทองแมนชั่น", "image": "550x70.swf", "title": "แมนชั่นหรูแนวคิดใหม่  ซ. 19-21 สวนหลวง เขตสวนหลวง กรุงเทพ", "st": "Y", "swf": "1", "pv": "10", "am": "0", "cols": "1", "p": 1 } ];
Ads.ads['A'] = [ { "id": "45", "name": "ชูโชค อพาร์ทฺเมนท์", "image": "so1.gif", "title": "ซอยรังสิต-นครนายก\r\n13 ต.ประชาธิปัตย์\r\nอ.ธัญบุรี ปทุมธานี", "st": "Y", "swf": "0", "pv": "13", "am": "0", "cols": "1", "p": 0 }, { "id": "69", "name": "จารุวรรณ อพาร์ทเม้นท์", "image": "Jaruwan-Apartment.gif", "title": "ซ.รังสิต-นครยายก 13\r\nปทุมธานี ใกล้ฟิวเจอร์พาร์ครังสิต", "st": "Y", "swf": "0", "pv": "13", "am": "0", "cols": "1", "p": 0 }, { "id": "66", "name": "BCJ Residence", "image": "BCJResidence.gif", "title": "งามวงศ์วาน47แยก 18\r\nซ.ซินเขต 2\/16\r\nทุ่งสองห้อง เขตหลักสี่", "st": "Y", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 0 }, { "id": "107", "name": "อ่อนนุช แมนชั่น", "image": "onnus.gif", "title": "ห้องเช่ารายวัน\r\nรายเดือน สุขุมวิท 77\r\n(อ่อนนุช ซ.2-4) \r\nเขตสวนหลวง กรุงเทพ", "st": "Y", "swf": "0", "pv": "10", "am": "34", "cols": "1", "p": 0 }, { "id": "34", "name": "Grand Sukhawatee ", "image": "grand-sukhawatee.gif", "title": "เงียบสงบเป็นส่วนตัว\r\nซอยจรัญสนิทวงศ์65 แยก12 ถ.จรัญสนิทวงศ์ บางพลัด กทม.", "st": "Y", "swf": "0", "pv": "10", "am": "25", "cols": "1", "p": 0 }, { "id": "48", "name": "กรองทองแมนชั่นลาดพร้าว81", "image": "so.gif", "title": "ซอยลาดพร้าว 81 \r\nวังทองหลาง กทม\r\nแมนชั่นหรู ตกแต่ง\r\nทันสมัย บรรยากาศดี", "st": "Y", "swf": "0", "pv": "10", "am": "45", "cols": "1", "p": 0 }, { "id": "46", "name": "ริสกี เรสซิเดนซ์", "image": "riski-banner.gif", "title": "อพาร์ทเม้นเปิดใหม่\r\nงามวงศ์วานซอย 8 \r\nห้องพักระยะสั้น-ระยะยาว", "st": "Y", "swf": "0", "pv": "12", "am": "57", "cols": "2", "p": 0 }, { "id": "106", "name": "Chic Color Suites", "image": "so(2).gif", "title": "ห้องพักรายวัน-เดือน\r\nใกล้ BTS อ่อนนุช \r\nสวนหลวง กทม.", "st": "Y", "swf": "0", "pv": "10", "am": "34", "cols": "1", "p": 0 }, { "id": "121", "name": "พลอยภัทรา", "image": "1(1).gif", "title": "หอพักเครือข่ายหญิงม.มหาสารคาม\r\nใกล้ม.เพียง 2 นาที\r\n ถูก สวย เก๋  ", "st": "Y", "swf": "0", "pv": "44", "am": "434", "cols": "1", "p": 0 }, { "id": "122", "name": "ธารธเนศ แกรนด์", "image": "so(3).gif", "title": "ห้องพักรายวัน-เดือน\r\n  อ.กันทรวิชัย\r\n จ.มหาสารคาม", "st": "Y", "swf": "0", "pv": "44", "am": "434", "cols": "1", "p": 1 }, { "id": "61", "name": "ธัญธร", "image": "1(2).gif", "title": "ห้องพักฟรีเมียม\r\nรายวัน-รายเดือน\r\nมหาสารคาม ", "st": "Y", "swf": "0", "pv": "44", "am": "434", "cols": "1", "p": 0 } ];
Ads.ads['B'] = [ { "id": "104", "name": "โรงแรมสตาร์ เชียงใหม่", "image": "11.gif", "title": "สวรรค์น้อยๆใจกลาง\r\nเมืองเชียงใหม่ \r\nเพียง 999 บาท เท่านั้น", "st": "Y", "swf": "0", "pv": "50", "am": "519", "cols": "1", "p": 0 }, { "id": "105", "name": "Rivendell", "image": "cpbanner_125_2.swf", "title": "ฉลองปิดโครงการ 15 ห้องสุดท้าย\r\nรับไปเลย 3 ต่อ มูลค่ารวม 250,000 บาท", "st": "Y", "swf": "1", "pv": "40", "am": "0", "cols": "1", "p": 1 }, { "id": "119", "name": "P.J. apartment", "image": "P.gif", "title": "ห้องพักรายวัน - รายเดือน \r\nพร้อมเฟอร์ฯ  ราคามิตรภาพ \r\nใจกลางเมืองนนทบุรี \r\nตรงข้ามโลตัสพระนั่งเกล้า", "st": "Y", "swf": "0", "pv": "12", "am": "57", "cols": "1", "p": 1 }, { "id": "88", "name": "", "image": "20101011174233-690.JPG", "title": "เห็นทุกหน้า\r\nคนคลิกมากกว่า 1,000\r\nเพียง 700 บ\/เดือน\r\nลงนานมีส่วนลดพิเศษ\r\nโทร 086-9129728", "st": "A", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 0 } ];
Ads.ads['C'] = [ { "id": "31", "name": "สินสิริ 3 อพาร์ทเม้นท์", "image": "20090722112425-290.jpg", "title": "เขตวังทองหลาง กทมฯ\r\nรายวัน-รายเดือน สะอาด สะดวก สบาย มาตราฐาน", "st": "Y", "swf": "0", "pv": "10", "am": "45", "cols": "1", "p": 0 }, { "id": "37", "name": "เอส ที เรสซิเด้นท์", "image": "ST-Resident.jpg", "title": "ห้องพัก รายวัน รายเดือน\r\nใกล้ดอนเมือง  ศูนย์ราชการแจ้งวัฒนะ", "st": "Y", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 0 }, { "id": "40", "name": "เอก เฮ้าส์ แมนชั่น", "image": "DSC00165.jpg", "title": "ซอยประวิทย์และเพื่อน 10\r\nสุขุมวิท 101\/1 เขตพระโขนง", "st": "Y", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 1 }, { "id": "41", "name": "ห้องพักรายวัน ในเมืองทองธานี ใกล้ อิมแพ็ค ชาเลนเจอร์ อารีน่า มสธ.", "image": "rom.jpg", "title": "สะอาด และเป็นกันเอง", "st": "Y", "swf": "0", "pv": "12", "am": "0", "cols": "1", "p": 0 }, { "id": "62", "name": "เมืองทองห้องพักรายวัน", "image": "20091123122049-156.jpg", "title": "ห้องพักเมืองทองธานี ห้องพักใกล้อิมแพค ห้องพักใกล้ชาร์แลนเจอร์", "st": "Y", "swf": "0", "pv": "12", "am": "0", "cols": "1", "p": 0 }, { "id": "68", "name": "ธนา เพลส งามวงศ์วาน", "image": "20100915134752-673.jpg", "title": "ใกล้เดอะมอลล์ งามวงศ์วาน\r\nซ.งามวงศ์วาน 31 เขตบางเขน กรุงเทพ", "st": "Y", "swf": "0", "pv": "10", "am": "5", "cols": "1", "p": 0 }, { "id": "89", "name": "เลอพิมานเพส", "image": "20101113122652-892.jpg", "title": "รายวัน รายเดือน ย่านรามอินทรา ติดแฟชั่นไอส์แลนด์ บรรยากาศรีสอร์ท", "st": "Y", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 0 }, { "id": "99", "name": "แสงรัชณีเฮ้าส์", "image": "20110223091015-094.jpg", "title": "ห้องกว้างขวาง บรรยากาศดี ใกล้เซ็นทรัลแอร์พอร์ทเชียงใหม่และม.เชียงใหม่", "st": "Y", "swf": "0", "pv": "50", "am": "0", "cols": "1", "p": 0 }, { "id": "108", "name": "สวนสนเพลส อนุสาวรีย์ชัย ", "image": "20110526175655-529.jpg", "title": "ซ.ราชวิถี4 สามเสนใน เขตพญาไท กรุงเทพ", "st": "Y", "swf": "0", "pv": "10", "am": "0", "cols": "1", "p": 0 }, { "id": "109", "name": "Three-D Living Place", "image": "20100823000530-613.JPG", "title": "อพาร์ทเม้นท์  ซ.รัตนาธิเบศร์ 22 (ตรงข้ามบิ๊กซี)\r\nอ.เมืองนนทบุรี จ.นนทบุรี", "st": "Y", "swf": "0", "pv": "12", "am": "57", "cols": "1", "p": 0 }, { "id": "110", "name": "สินสิริ 1", "image": "20100918133447-110.jpg", "title": "เขตบางกะปิ ห้องพักรายวัน-รายเดือน ซอยรามคำแหง 81, ลาดพร้าว 130", "st": "Y", "swf": "0", "pv": "10", "am": "6", "cols": "1", "p": 0 }, { "id": "100", "name": "โอโซน เพลส ราม2บางนา ", "image": "20110308151741-125.jpg", "title": "หอพักสร้างใหม่ บางนา กรุงเทพ  ใกล้ ม.รามคำแหง 2 ,เซ็นทรัลบางนา", "st": "Y", "swf": "0", "pv": "10", "am": "32", "cols": "1", "p": 0 }, { "id": "59", "name": "สินสิริ 4 อพาร์ทเม้นท์", "image": "Untitled-1.jpg", "title": "ซ.นวมินทร์ 93 ถ.นวมินทร์ \r\nคลองกุ่ม เขตบึงกุ่ม กรุงเทพ\r\nใกล้ประกันสังคมพื้นที่ 10 \r\n", "st": "Y", "swf": "0", "pv": "10", "am": "27", "cols": "1", "p": 0 }, { "id": "57", "name": "สินสิริ 2 อพาร์ทเม้นท์", "image": "Untitled-1(1).jpg", "title": "ลาดพร้าว 98\/1 วังทองหลาง กทม.ใกล้บิ๊กซีลาดพร้าว,รามคำแหง 1,MRT Ladprao \r\n", "st": "Y", "swf": "0", "pv": "10", "am": "38", "cols": "1", "p": 0 }, { "id": "50", "name": "สินสิริรีสอร์ท ", "image": "Untitled-1(2).jpg", "title": "ห้องพักรายวัน-รายเดือนถ.ปัญญา-รามอินทรา\r\n คันนายาว กทม. ", "st": "Y", "swf": "0", "pv": "10", "am": "43", "cols": "1", "p": 0 }, { "id": "35", "name": "ศรีโรจน์อพาร์ทเม้นท์ ", "image": "Untitled-1(4).jpg", "title": "สุขุมวิท 62 แยก1-1บางจาก\r\nเขตพระโขนง กรุงเทพ\r\nใกล้รถไฟฟ้า BTS บางจาก,", "st": "Y", "swf": "0", "pv": "10", "am": "9", "cols": "1", "p": 0 }, { "id": "58", "name": "ขอนแก่น เฮือนมัดหมี่ รีสอร์ท", "image": "20110921165215-778.jpg", "title": "ห้องพักรายวัน-รายเดือน กลางเมืองขอนแก่น ใกล้แฟรี่ ตลาดโต้รุ่ง สถานีรถไฟ แรด สนทนา น.ส.ข้าวต้ม\r\nบรรยากาศดี ที่จอดรถสะดวก\r\nสิ่งอำนวยความสะดวกครบครัน", "st": "Y", "swf": "0", "pv": "40", "am": "355", "cols": "1", "p": 0 }, { "id": "39", "name": "กิตติพรอพาร์ทเม้นท์ ", "image": "20110411114524-349.jpg", "title": "ซ.บางขุนนนท์ 29 ถ.บางขุนนนท์\r\nเขตบางกอกน้อย กรุงเทพ", "st": "Y", "swf": "0", "pv": "10", "am": "20", "cols": "1", "p": 0 }, { "id": "60", "name": "เอสวีเพลส วิภาวดี", "image": "20111002140611-799.jpg", "title": "ตกแต่งหรูสไตล์โมเดิน\r\nอากาศดี เงียบสงบ \r\nสะอาด ปลอดภัย", "st": "Y", "swf": "0", "pv": "10", "am": "40", "cols": "1", "p": 0 }, { "id": "64", "name": "", "image": "Picture-032_2.jpg", "title": "ลงโฆษณาราคาประหยัด\r\nเพียง 250 บ\/เดีอน\r\nพร้อมส่วนลดพิเศษ 15 %", "st": "A", "swf": "0", "pv": "50", "am": "0", "cols": "1", "p": 0 }, { "id": "63", "name": "", "image": "20100802162149-747.jpg", "title": "ลงโฆษณาราคาประหยัด\r\nโทร086-9129728", "st": "A", "swf": "0", "pv": "14", "am": "0", "cols": "1", "p": 0 } ];
Ads.ads['G'] = [ { "id": "14579", "title": "บริเวณที่ซีวิวและวิวภูเขา สามารถต่อรองได้", "image": "20110608215414-015.jpg", "pv": "83", "st": "Y" }, { "id": "17553", "title": "ลงประกาศแบบปักหมุดบนสุด 200\/เดือน, 1500\/ปี โทร. 086-9129728", "image": "20110925073828-537.png", "pv": "10", "st": "Y" } ];
Ads.show = function(pos, pv, am){
	//if(!(pv = parseInt(pv))) pv = 0;
	//if(!(am = parseInt(pv))) am = 0;
	switch(pos){
		case "T":
			ad = Ads.ads['T'][0];
			document.writeln('<div class="t-bnn"><embed src="'+Ads.url+'adlogo/550x80.swf" width="550" height="80" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></div><a href="'+Ads.url+'clickad.php?adid=98" class="t-bnn" target="_blank">กรองทองแมนชั่น</a>');
			Ads.adsstat.push(ad.id);
			break;
		case "A":
			w = 125;
			cap = 8;
			
			for(i in Ads.ads['A']){
				ad = Ads.ads['A'][i];
				if(ad==null) continue;
				img_w = (ad.cols*w)+(cap*(ad.cols-1));
				document.writeln('<li class="cols'+ad.cols+'">');
				if(ad.st=="A"){
					document.writeln('<a href="'+Ads.url+'kosana/" rel="nofollow">'+
						'<img src="'+Ads.url+'images/kosana1.gif" alt="'+ad.name+'" width="'+img_w+'" height="125" /><br />'+
						''+AdsUtil.txt2html(ad.title)+'</a>');
				}else{
					document.writeln('<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.url+'clickad.php?adid='+ad.id+'">'+
						'<img src="'+Ads.url+'media/adsfile/logo/'+ad.image+'" alt="" width="'+img_w+'" height="125" /><br />'+
						''+AdsUtil.txt2html(ad.title)+'</a>');
						Ads.adsstat.push(ad.id);
				}
				document.writeln('</li>');
			}
			
			break;
		case "A1":
			w = 125;
			cap = 8;
			
			_ads = AdsUtil.filter(Ads.ads['A'],5,pv,am);
			for(i in _ads){
				ad = _ads[i];
				if(ad==null) continue;
				img_w = (ad.cols*w)+(cap*(ad.cols-1));
				document.writeln('<li class="cols'+ad.cols+'">');
				if(ad.st=="A"){
					document.writeln('<a href="'+Ads.url+'kosana/" target="_blank" rel="nofollow">'+
						'<img src="'+Ads.url+'images/kosana1.gif" alt="'+ad.name+'" width="'+img_w+'" height="125" alt="ลงโฆษณาหอพัก" /><br />'+
						''+AdsUtil.txt2html(ad.title)+'</a>');
				}else{
					document.writeln('<a href="'+Ads.url+'clickad.php?adid='+ad.id+'"'+((ad.p==1)? ' target="_blank"' : '')+'>'+
						'<img src="'+Ads.url+'media/adsfile/logo/'+ad.image+'" alt="" width="'+img_w+'" height="125" alt="หอพัก" /><br />'+
						''+AdsUtil.txt2html(ad.title)+'</a>');	
						Ads.adsstat.push(ad.id);					
				}
				document.writeln('</li>');
			}
			break;
		case "B":
			for(i in Ads.ads['B']){
				ad = Ads.ads['B'][i];
				document.writeln('<div>');
				if(ad.st=="A"){
					document.writeln('<a href="'+Ads.url+'kosana/" rel="nofollow"><img src="'+Ads.url+'images/kosana1.gif" alt="" width="125" height="125" /><br />'+AdsUtil.txt2html(ad.title)+'</a>');
				}else{
					if(ad.swf==1){
						document.writeln('<embed width="125" height="125" " wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="'+Ads.url+'media/adsfile/logo/'+ad.image+'"><br /><a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.url+'clickad.php?adid='+ad.id+'">'+AdsUtil.txt2html(ad.title)+'</a>');
					}else{
						document.writeln('<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.url+'clickad.php?adid='+ad.id+'"><img src="'+Ads.url+'media/adsfile/logo/'+ad.image+'" alt="'+ad.image+'" width="125" height="125" /><br />'+AdsUtil.txt2html(ad.title)+'</a>');
					}
					Ads.adsstat.push(ad.id);
				}
			  	document.writeln('</div>');
			}
			break;
		case "C1":
			_ads = AdsUtil.filter(Ads.ads['C'],3,pv,am);
			for(i in _ads){
				ad = _ads[i];
				document.writeln('<div class="it">');
				if(ad.st=="A"){
					document.writeln('<div class="it'+((i%2)? ' odd' : '')+'">'+
						'<a href="'+Ads.url+'kosana/" class="thb" rel="nofollow" title="ลงโฆษณาหอพัก">'+
						'<img src="'+Ads.url+'images/kosana3.gif" alt="" width="90" height="70" alt="ลงโฆษณาหอพัก" />'+
						'</a>'+
						'<div class="info">'+
						'<a href="'+Ads.url+'kosana/" rel="nofollow"><strong>'+ad.name+'</strong></a><br />'+
						'<p>'+AdsUtil.txt2html(ad.title)+'</p>'+
						'</div>'+
						'</div>');
				}else{
					document.writeln('<div class="it'+((i%2)? ' odd' : '')+'">'+
						'<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.url+'clickad.php?adid='+ad.id+'" class="thb">'+
						'<img src="'+Ads.url+'media/adsfile/logo/'+ad.image+'" alt="หอพัก" width="90" height="70" />'+
						'</a>'+
						'<div class="info">'+
						'<a href="'+Ads.url+'clickad.php?adid='+ad.id+'" target="_blank"><strong>'+ad.name+'</strong></a>'+
						'<p>'+AdsUtil.txt2html(ad.title)+'</p>'+
						'</div>'+
					 	'</div>');
						Ads.adsstat.push(ad.id);
				}
				document.writeln('</div>');
			}
			break;
		case "C":
			for(i in Ads.ads['C']){
				ad = Ads.ads['C'][i];
				document.writeln('<div class="it">');
				if(ad.st=="A"){
					document.writeln('<a href="'+Ads.url+'kosana/" class="thb" rel="nofollow" title="ลงโฆษณาหอพัก">'+
						'<img src="'+Ads.url+'images/kosana3.gif" alt="" width="90" height="70" alt="ลงโฆษณาหอพัก" />'+
						'</a>'+
						'<div class="info">'+
						'<a href="'+Ads.url+'kosana/" rel="nofollow"><strong>'+ad.name+'</strong></a><br />'+
						''+AdsUtil.txt2html(ad.title)+''+
						'</div>');
				}else{
					document.writeln('<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.url+'clickad.php?adid='+ad.id+'" class="thb" title="รายละเอียดหอพัก">'+
						'<img src="'+Ads.url+'media/adsfile/logo/'+ad.image+'" width="90" height="70" alt="หอพัก" />'+
						'</a>'+
						'<div class="info">'+
						'<a target="_blank" href="'+Ads.url+'clickad.php?adid='+ad.id+'"><strong>'+ad.name+'</strong></a><br />'+
						''+AdsUtil.txt2html(ad.title)+''+
						'</div>');
						Ads.adsstat.push(ad.id);
				}
				document.writeln('</div>');
			}
			break;
		case "G":
			_ads = AdsUtil.filter(Ads.ads['G'],10);
			document.writeln('<table border="0" cellspacing="0">');
			for(var i=0;i<2;i++){
				document.writeln('<tr>');
				for(var j=0;j<5;j++){					
					if(ad = _ads[(i*5)+j]){
						document.writeln('<td valign="top">');
						document.writeln('<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.urlreal+'Property/'+ad.id+'"><img src="'+Ads.url+'media/wbfiles/pv/'+ad.image+'" width="120" height="90" class="thumb" /><br />'+ad.title+'</a>');
						document.writeln('</td>');
					}else{
						document.writeln('<td><a href="'+Ads.url+'kosana/#ads-g" valign="top"><img src="'+Ads.url+'images/gads.png" width="120" height="90" class="thumb" /><br />ลงโฆษณาตำแหน่งนี้ เห็นชัดกว่า คุ้มสุด 450/เดือน</a></td>');
					}					
				}
				document.writeln('</tr>');
			}
			document.writeln('</table>');
			break;
		case "G1":
			_ads = AdsUtil.filter(Ads.ads['G'],5,pv,am);
			document.writeln('<table border="0" cellspacing="0">');
			document.writeln('<tr>');
			for(var j=0;j<5;j++){					
				if(ad = _ads[j]){
					document.writeln('<td valign="top">');
					document.writeln('<a'+((ad.p==1)? ' target="_blank"' : '')+' href="'+Ads.urlreal+'Property/'+ad.id+'"><img src="'+Ads.url+'media/wbfiles/pv/'+ad.image+'" width="120" height="90" class="thumb" /><br />'+ad.title+'</a>');
					document.writeln('</td>');
				}else{
					document.writeln('<td><a href="'+Ads.url+'kosana/#ads-g" valign="top"><img src="'+Ads.url+'images/gads.png" width="120" height="90" class="thumb" /><br />ลงโฆษณาตำแหน่งนี้ เห็นชัดกว่า คุ้มสุด 450/เดือน</a></td>');
				}					
			}
			document.writeln('</tr>');
			document.writeln('</table>');
			break;
	}
}
AdsUtil = function(){
	
}
AdsUtil.txt2html = function(str){
	return str.replace(/\n/g, '<br />');
}
AdsUtil.random_ad = function(arr_ad, num){
	var total = arr_ad.length;
	if(total==0) return(null);
	
	var arr_match = new Array();
	while(total>0 && num>0){
		rand = Math.floor(Math.random()*arr_ad.length);
		ad = arr_ad[rand];
		if(ad == null) continue;
		arr_match.push(ad);
		arr_ad[rand] = null;
		total--;
		num--;
	}
	return(arr_match);
}
AdsUtil.count = function(arr_ad){
	var x_count = 0;
	for(j in arr_ad){
		ad = arr_ad[j];
		x_count += parseInt(ad.cols);
	}
	return x_count;
}
AdsUtil.filter = function(arr,num,pv, am){
	
	var arr_ad = new Array();
	var arr_adpv = new Array();
	var arr_adam = new Array();
	var arr_avail = new Array();
	for(j in arr){
		ad = arr[j];
		if(ad.st == "Y"){
			if(am && ad.am == am){
				arr_adam.push(ad);
			}else if(ad.pv == pv){
				arr_adpv.push(ad);
			}else{
				arr_ad.push(ad);
			}
		}else{
			arr_avail.push(ad);
		}
	}
	var x_count = 0;
	var arr_match = new Array();
	if(arr_adam.length>0) arr_match = arr_match.concat(AdsUtil.random_ad(arr_adam, (num-x_count)));
	x_count = AdsUtil.count(arr_match);
	if(arr_adpv.length>0) arr_match = arr_match.concat(AdsUtil.random_ad(arr_adpv, (num-x_count)));
	x_count = AdsUtil.count(arr_match);
	if(arr_ad.length>0) arr_match = arr_match.concat(AdsUtil.random_ad(arr_ad, (num-x_count)));
	x_count = AdsUtil.count(arr_match);
	if(arr_avail.length>0) arr_match = arr_match.concat(AdsUtil.random_ad(arr_avail, (num-x_count)));
	x_count = AdsUtil.count(arr_match);
	if(x_count>num){
		//shift last ad
		last_ad = arr_match[arr_match.length-1];
		if(last_ad.cols>1){
			arr_match[arr_match.length-2] = last_ad;
		}
		arr_match[arr_match.length-1] = null
	}
	return arr_match;
}
