﻿/*
 *  m:code
 *  2010.03.02
 */


$(document).ready(function(){
	$.ajax({
		url: "common/js/proxy.php",//proxy.phpへのパス
		async: true,
		cache: false,
		dataType:"xml",
		success: function(xml){
		
			$(xml).find('item').each(function(i){
			
				/* 初期設定で3件出力します。件数を変更は"i > 2"の部分を修正してください。
				数値は"出力したい件数 - 1"を入力して下さい。*/
				if ( i > 2 ) {
					return false;
				}
				
				//記事内容の取得
				var title = $(this).find('title').text();
				var link = $(this).find('link').text();
				var category = $(this).find('category').text();
				
				//PDFの確認・分離
				var description = pdfCheck($(this).find('description').text());
				
				//日にちの編集
				var date = dateParse($(this).find('pubDate').text());
				
				//出力内容
				var htmlData = '';
				htmlData += '<div class="articleBox">';
				htmlData += '<div class="date fontEnglish">'+date+'</div>';
				htmlData += '<div class="text">';
				htmlData += description[0]+'<br />';
				if(description[1]){
					htmlData += '<a href="'+description[1]+'" target="_blank"><img src="global_images/pdf01.gif" width="87" height="21" alt="詳しくはこちら" class="pdf" /></a>';
				}
				htmlData += '</div>';
				htmlData += '</div>';
				
				$('#feedBox').append(htmlData);
			
			});
		
		}
	});
});


function pdfCheck(cmd){
	
	var dText = cmd;
	var pdfPass = "";
	
	if (dText.search(/＜pdf＞/i) != -1) {
		dText = RegExp.leftContext;
		pdfPass = RegExp.rightContext;
	}
	
	cmd = new Array(2);
	cmd[0] = dText;
	cmd[1] = pdfPass;
	
	return cmd;
	
}

function dateParse(cmd){
	
	var objDate = new Date(cmd);
	var year = objDate.getFullYear();
	var month = objDate.getMonth() + 1;
	var date = objDate.getDate();
	
	if ( month < 10 ) { month = "0" + month; }
	if ( date < 10 ) { date = "0" + date; }
	cmd = year + '.' + month + '.' + date;
	
	return cmd;
	
}





