var htmlStr = '';

function getXMLError(XMLHttpRequest, textStatus, errorThrown){
	
}
//blog////////////
function getXMLSuccess(data, dataType){
	
	$(data).find('entry').each(function(){
		var name = $(this).find('name').eq(0).text();
		var ttl = $(this).find('ttl').eq(0).text();
		var blog = $(this).find('blog').eq(0).text();
		var rss = $(this).find('rss').eq(0).text();
		var img = $(this).find('img').eq(0).text();
		var division = $(this).find('division').eq(0).text();
		var xmlType = $(this).find('xmlType').eq(0).text();
		var xmlTtl = $(this).find('xmlTtl').eq(0).text();
		var xmlDate = $(this).find('xmlDate').eq(0).text();
		
		var d = xmlDate.split(".");
		var dd = new Date(d[0], d[1]-1, d[2], d[3], d[4], d[5]);
		var html_date = getDateStr(dd);
		var html_ttl = getTtlStr(name+' ／ '+ttl, 20);
		var html_entry_ttl = getTtlStr(xmlTtl, 20);
		
		htmlStr += '<a href="'+blog+'">';
        htmlStr += '<img src="../common/images/blog-news/'+img+'" alt="'+name+'" />';
        htmlStr += '<span class="name">'+html_ttl+'</span>';
		htmlStr += '<span class="division">'+division+'</span>';
		htmlStr += '<span class="date">'+html_date+'</span>';
		htmlStr += '<span class="post-title">'+html_entry_ttl+'</span>';
		htmlStr += '</a>';
		
	});
}
function getXMLComplete(XMLHttpRequest, textStatus){
	$("#blog-news").html(htmlStr);
}
//top/////////////////
function getXMLSuccessTop(data, dataType){
	htmlStr = '<h2 id="blog_news">民主党議員最新のブログ</h2>';
	
	$(data).find('entry').each(function(){
		var name = $(this).find('name').eq(0).text();
		var ttl = $(this).find('ttl').eq(0).text();
		var blog = $(this).find('blog').eq(0).text();
		var rss = $(this).find('rss').eq(0).text();
		var img = $(this).find('img').eq(0).text();
		var division = $(this).find('division').eq(0).text();
		var xmlType = $(this).find('xmlType').eq(0).text();
		var xmlTtl = $(this).find('xmlTtl').eq(0).text();
		var xmlDate = $(this).find('xmlDate').eq(0).text();
		
		var d = xmlDate.split(".");
		var dd = new Date(d[0], d[1]-1, d[2], d[3], d[4], d[5]);
		var html_date = getDateStr(dd);
		var html_ttl = name+' ／<br />'+getTtlStr(ttl, 12);
		var html_entry_ttl = getTtlStr(xmlTtl, 12);
		
		htmlStr += '<a href="'+blog+'">';
        htmlStr += '<img src="./common/images/blog-news/'+img+'" alt="'+name+'" />';
        htmlStr += '<span class="name">'+html_ttl+'</span>';
		htmlStr += '<span class="division">'+division+'</span>';
		htmlStr += '<span class="date">'+html_date+'</span>';
		htmlStr += '<span class="post-title">'+html_entry_ttl+'</span>';
		htmlStr += '</a>';		
	});
}
function getXMLCompleteTop(XMLHttpRequest, textStatus){
	$("#blog-news-top").html(htmlStr);
}

//
function getDateStr(date){
	var youbiAr = new Array("日","月","火","水","木","金","土");
	
	return date.getFullYear()+'年'+(date.getMonth()+1)+'月'+date.getDate()+'日('+youbiAr[ date.getDay() ]+')';
}

function getTtlStr(str, num){
	if(str.length >= num){
		str = str.slice(0, num)+"･･･";	
	}
	
	return str;
}



