var playlistID = 0;

preloadImg(["/images/common/icon_loader.gif","/images/artist/btn_add_favorite_ok.gif"]);

//add favorite for listener
function addFavorite(id){

	playlistID = id;

	document.getElementById('btnAddFavorite').innerHTML = '処理中・・・';

	var action = '/apis/api_playlist/'
	action += 'add_favorite/' + playlistID + '/';
	sendRequest(showAddFavorite,'','GET',action,true,true);
}

function showAddFavorite(returnObj){
	//coversion json to array
	if(returnObj.responseText){
		var html = '<img src="/images/artist/btn_add_favorite_ok.gif" width="120" height="40" alt="追加しました" />';	
	}
	else{
		var html = '追加されています';	
	}
	document.getElementById('btnAddFavorite').innerHTML = html;
}

//change main contents
function changeInfo(id){

	//show loader
	document.getElementById('artistInfo').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';

	//change contents
	var action = '/apis/api_artist/get_info/' + id + '/';
	sendRequest(showInfo,'','GET',action,true,true);
}
function showInfo(returnObj){
	if(returnObj.responseText){
		document.getElementById('artistInfo').innerHTML = returnObj.responseText;
	}
	else{
		document.getElementById('artistInfo').innerHTML = "-NO ENTRY-";
	}
}

//change comment 
function changeComment(id,offset){

	//show loader
	document.getElementById('commentContainer').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';

	//change contents
	var action = '/apis/api_playlist/get_comments/' + id + '/' + offset + '/';
	sendRequest(showComment,'','GET',action,true,true);
}
function showComment(returnObj){
	if(returnObj.responseText){
		document.getElementById('commentContainer').innerHTML = returnObj.responseText;
	}
	else{
		document.getElementById('commentContainer').innerHTML = "-NO ENTRY-";
	}
}

//submit comment
function submitComment(){
	var comment_str = document.commentForm.comment_body.value;
	var comment_len = comment_str.length;
	var error_cnt = false;
	if(comment_len == 0){
		error_cnt = true;
		document.getElementById('commentFormMess').innerHTML = "コメントを入力してください。";
	}
	if(comment_len >= 250 && comment_len == 0){
		error_cnt = true;
		document.getElementById('commentFormMess').innerHTML = "250文字以内です。";
	}

	var playlist_id = document.commentForm.playlist_id.value;
	if(playlist_id.match(/[^0-9]+/)){
		error_cnt = true;
		document.getElementById('commentFormMess').innerHTML = "情報が適切に設定されていません。";
	}
	
	if(error_cnt == false){
		//show loader
		document.getElementById('commentFormContainer').innerHTML = '<div class="loaderIcon"><img src="/images/common/icon_loader.gif" /></div>';

		//change contents
		var action = '/apis/api_playlist/add_comment/' + playlist_id + '/';
		var param = new Array();
		param['comment_body'] = comment_str;
		sendRequest(showCommentForm,param,'POST',action,true,true);
	}
}
function showCommentForm(returnObj){
	if(returnObj.responseText){
		document.getElementById('commentFormContainer').innerHTML = returnObj.responseText;
	}
	else{
		document.getElementById('commentFormContainer').innerHTML = "-エラーが発生しました。-";
	}
}

