﻿var dBox;
var ysmtabp;
var domaincheck = document.location.href;
var replaceData = [
  {orig:'<td width="50%">‧<a href="http://www.wretch.cc/hala/viewtopic.php?t=232904">無名影音火熱上線</a></td><td width="50%">‧<a href="http://www.wretch.cc/blog/?func=hot&hid=0&class_id=49">拍賣教主人氣火拚</a></td>'},
  {orig:'<td width="50%">‧<a href="http://www.wretch.cc/blog/?func=hot&hid=0&class_id=7">醫療保健團隊無名免費健診</a></td><td width="50%">‧<a href="http://www.wretch.cc/album/?func=hot&hid=0&class_id=0">靚妹酷哥無名通通給你</a></td>'}, 
  {orig:'<td width="50%">‧<a href="http://www.wretch.cc/blog/?func=hot&hid=0&class_id=1">直擊!人氣偶像明星的真面目</a></td><td width="50%">‧<a href="http://www.wretch.cc/album/?func=hot&hid=6&class_id=39">好狗命!豪門貴族的心肝寶貝</a></td>'},
  {orig:'<td width="50%">‧<a href="http://www.wretch.cc/blog/?func=hot&hid=0&class_id=1">超級星光大道的幕後推手</a></td><td width="50%">‧<a href="http://www.wretch.cc/album/?func=locations&lid=1">台北搞什麼?無名小站原形畢現</a></td>'}
];
function  GetTabResult(p,c,i){
	dBox  = i;
	ysmtabp  = p;
	if(ysmtabp != "wretch_tw_homepage_tab_cm"){
		dBox.innerHTML="";
		if(c == ''){c="tw_news_ron_001"}
		var q_url = '';
		zSr = null;
		q_url= 'http://cmx.tw.yahoo.overture.com/js_flat_1_0/?config=4967000410&source='+ ysmtabp +'&mkt=tw&maxCount=2&ctxtId='+ c;
		loadysmtab(q_url);
	}
	checkysmtabloaded();
}

function loadysmtab(file){
  var scriptTag = document.getElementById('loadScript');
  var head = document.getElementsByTagName('head').item(0)
  if(scriptTag) head.removeChild(scriptTag);
  script = document.createElement('script');
  script.src = file;
  script.setAttribute('charset','utf-8');
	script.type = 'text/javascript';
	script.id = 'loadScript';
	head.appendChild(script)
} 

function checkysmtabloaded() {
	if (zSr == null){
		setTimeout(checkysmtabloaded,10);
	}else{
		showysmtab();
	}
}

function showysmtab(){ 
	if(zSr.length>6){
		var html="";
		var i=6; 
		var zsrleng;
		var ysmtabtitle = ["【快訊】","【熱門】"];
		var ysmtabnum = 0;
		while(i < zSr.length){
			var descr=zSr[i++]; 
			var unused1=zSr[i++]; 
			var clickURL=zSr[i++]; 
			var title=zSr[i++]; 
			var sitehost=zSr[i++]; 
			var unused2=zSr[i++]; 
			html=html + '<li>' + ysmtabtitle[ysmtabnum] + '<a href="' + clickURL + '" target="_blank">'+title+'</a></li>';
			ysmtabnum = ysmtabnum  + 1;
		}
		if(ysmtabp=="wretch_tw_homepage_tab_cm"){
			zsrleng  =  Number(new Date) % replaceData.length ;
			html='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>' + replaceData[zsrleng].orig + '</tr></table>';
		}
		dBox.innerHTML=html;
	}
}