
function gup(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = document.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function loadContent(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  ShowListings()  {
	if (zSr.length > 6){
		var  html="";
		var  i=6;
		//Listing
		var p = 1;
		while  (i  <  zSr.length)  {
    		var  descr  =  zSr[i++];	//  listing  description 
    		var  unused1  =  zSr[i++];	//  (ignore)
    		var  clickURL  =  zSr[i++];	//  listing  link 
    		var  title  =  zSr[i++];	//  listing  title
    		var  sitehost  =  zSr[i++];	//  advertisers  domain  name 
    		var  unused2  =  zSr[i++];	//  (ignore)
    		var rExp = eval('/' + decodeURIComponent(theywkw) + '/gi');
    		title = title.replace(rExp,'<font color=\'#FF3333\'>' + decodeURIComponent(theywkw) + '</font>');
    		descr = descr.replace(rExp,'<font color=\'#FF3333\'>' + decodeURIComponent(theywkw) + '</font>');
		    //'<table width="100%" border="0" cellspacing="0" cellpadding="0" onClick="window.open(\''+ clickURL +'\')" class="listtable">' +
			html =  html +
               '<table width="100%" border="0" cellspacing="0" cellpadding="0">' +
                '<tr>' +
                  '<td valign="top" background="images/lbg.gif">' +
                  '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="listtable">' +
                      '<tr valign="top">' +
                        '<td onClick="window.open(\'rdt.php?k=' + thekno + '&l=' + encodeURIComponent(clickURL) +'\')"><div class="thumb"><img src="http://open.thumbshots.org/image.aspx?url=' + sitehost + '" width="120" height="90" border="0" alt="' + title + '"></div>' +
                        '</td>' +
                        '<td width="100%" id="sitelist">' +
                            '<div onClick="window.open(\'rdt.php?k=' + thekno + '&l=' + encodeURIComponent(clickURL) +'\')">' +
                                '<div class="title">' + title + '</div>' +
                                '<div class="host">' + sitehost + '</div>' +
                                '<div class="descr">' + descr + '</div>' +
                            '</div>' +
                            '<div >' +
                            '<a href="rdt.php?k=' + thekno + '&l=' + encodeURIComponent(clickURL) +'" target="_blank"><span class="goto">>> 進入網站</span></a>' +
                            '</div>' +
                        '</td>' +
                      '</tr>' +
                    '</table>' +
                  '</td>' +
                '</tr>' +
              '</table>';
            p++;
            if( 10 == p ) p = 1;
		}
		document.getElementById("ysmcontent").innerHTML=html;
	}
	else {
		document.getElementById("ysmcontent").innerHTML="";
	}
}

function  GetResults(kw){
	var q_url = "";
	zSr = null;
	q_url= 'http://xml.tw.overture.com/d/search/p/yahoo/js/flat/tw/kk/?mkt=tw&Partner=youthwant_tw_topic_association_pm_hybrid&maxCount=30&Keywords='+ kw + '&affilData=' + affilData + '&serveUrl=' + serveUrl + '&kkClient=yahootwkingkongbucket4&adultFilter=any&rnd=' + Math.random() + Date.parse(new Date());
	loadContent(q_url);
	check_ysmloaded();
}
function check_ysmloaded() {	
	if (zSr == null){
		setTimeout(check_ysmloaded,10);
	}else{
		if(zSr.length > 6){
			ShowListings();
		}else{
			document.getElementById("ysmcontent").innerHTML="";
		}
	}
}

function ysm_loading(){
	var  ysmcontent = document.getElementById("ysmcontent");
	ysmcontent.innerHTML = '<div style="margin-top:20px" align="center"><img src="images/loading2.gif"></div>';
}

var theywkw2 = encodeURIComponent(theywkw);
ysm_loading();
GetResults(theywkw2);
