function createXMLHttpRequest() {
    if (window.ActiveXObject) {
    	try {
	        return new ActiveXObject("Msxml2.XMLHTTP"); 
	    } catch(e){
	    	return new ActiveXObject("Microsoft.XMLHTTP");
	    }
    }
    else if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }    
}

var recdata = new Array();
function getList(id,target,kwd,ppid,sppid,aid,title,wd) {

    if(recdata[id] != null){
        return;
    }else{
        recdata[id] = 1;
    }

	var xmlHttp = createXMLHttpRequest();

	var url = "recommend";
	var param = "kwd="+ encodeURIComponent(kwd)
            + "&ppid=" + encodeURIComponent(ppid)
            + "&sppid=" + encodeURIComponent(sppid)
            + "&aid=" + encodeURIComponent(aid)
            + "&title=" + encodeURIComponent(title)
            + "&wd=" + encodeURIComponent(wd);
    xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState == 4) {
	        if(xmlHttp.status == 200) {
	            parseResults(id,target,xmlHttp.responseXML);
	        }
	    }
    }
    xmlHttp.open("POST", url, true);
    xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttp.send(param);
}

function parseResults(id,target,obj) {
	var allResults=obj.getElementsByTagName('item');
    if(allResults == null || allResults.length == 0){ return; }

    var contents = '';
	for(var i = 0; i < allResults.length && i<5; i++) {
	    result = allResults[i];
        url = getChildElementText(result, "url");
        title = getChildElementText(result, "title");
        contents += '<a href="'+url+'">' + title + '</a><br>';
    }

    // プルダウンを作ってすぐ表示
	createSearchToolTip(id,target, contents, 'searchDefault').showDelayed();
}

function getChildElementText(parentNode, childTagName) {
	var rst;
	try {
    	var childTag = parentNode.getElementsByTagName(childTagName);
    	
    	rst = childTag[0].firstChild.nodeValue;
    } catch( e ){
    	rst = null;
	}
    
    return rst;
}
function createSearchToolTip(id, target, content, cname) {
//<![CDATA[
	return new Tip(
		id, 
		content, 
		{ 
            target: target,
			hideOn: { element: 'tip', event: 'mouseout'}, 
			hideAfter: 1, 
			effect: 'appear', 
			hook: { tip: 'topLeft', target: 'bottomLeft'},
            offset: { x: 0, y: 2 },
			className: cname});
//]]>
}

