
var targetWord = '';
var targetText = '';

function uploadDU()
{
	var oj = new Ajax.Request(
		"http://navitte.jp/ajsu.php",
		{
			method:"post",
			asynchronous:true,
			postBody:"&data="+encodeURIComponent(targetText)+"&t="+targetWord,
			onComplete:function onloaded(roj){
				if( blogCount == 0 )
				{
					window.location.reload();
				}
			}
		}
	);
}

function initialize() {
	var url = location.href;
	var num = 50;

	var feed = new google.feeds.Feed("http://blogsearch.google.co.jp/blogsearch_feeds?q="+targetWord+"&output=rss&num="+num+"&hl=ja&ie=UTF-8&lr=lang_ja&rand="+Math.floor(Math.random()*100000));
	feed.setNumEntries(num);
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	feed.load(function(result) {
		if (!result.error){
			var items = result.xmlDocument.getElementsByTagName('item');
			for (var i = 0; i < items.length; i++)
			{
				targetText += "<item>";
				targetText += "<title><![CDATA[";
        targetText += encodeURI(items[i].getElementsByTagName("title")[0].firstChild.nodeValue);
				targetText += "]]></title>";
				targetText += "<link>";
        targetText += encodeURI(items[i].getElementsByTagName("link")[0].firstChild.nodeValue);
				targetText += "</link>";
				targetText += "<dc:date>";
        targetText += encodeURI(items[i].getElementsByTagName("dc:date")[0].firstChild.nodeValue);
				targetText += "</dc:date>";
				targetText += "<description><![CDATA[";
        targetText += encodeURI(items[i].getElementsByTagName("description")[0].firstChild.nodeValue);
				targetText += "]]></description>";
				targetText += "</item>";
			}
			if( items.length > 0 )
			{
				uploadDU();
			}
			else
			{
				if( blogCount == 0 )
				{
					document.getElementById('blogHead').innerHTML = 'データが見つかりませんでした';
				}
			}
		}
		else
		{
			if( blogCount == 0 )
			{
				document.getElementById('blogHead').innerHTML = '接続に失敗しました('+result.error.message+')<br /><a href="javascript:window.location.reload();" style="font-color:#FFFFFF;">再読み込み</a>してください。';
			}
		}
	});
}

function du(word)
{
	targetWord = word;
	google.load("feeds", "1");
	google.setOnLoadCallback(initialize);
}


