/**
 * ajax関連コマンドを入力する。
 */

/**
 * continue next comment Data For Html 
 * 
 * @param currentNumId 現在のnumId
 * @param inputDivId 入れるDivId
 * @param whatData 種類を選択
 * @return
 */
function ajaxNextCommentForHtml(currentNumId, inputDivId, whatData) {

	var currentNum = document.getElementById(currentNumId).value;
	var plusHtml = "";  
	var inAjaxDataCount = 0;
  
	// all comment
	if (whatData == 1) {
	   	$.ajax({
	   	  url: "/ajax/getNextCommentForHtml.php?type=1&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextCommentForHtml.php?type=1&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#comment_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// post comment
	if (whatData == 2) {
		
		var seqNum = $("#postseq").val();
		
	   	$.ajax({
	   	  url: "/ajax/getNextCommentForHtml.php?type=2&seqNum=" + seqNum + "&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextCommentForHtml.php?type=2&seqNum=' + seqNum + '&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#comment_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// 現在の番号を+1する。
	document.getElementById(currentNumId).value = parseInt(currentNum, 10) + parseInt("1", 10);
}

/**
 * continue next Data For Html 
 * 
 * @param currentNumId 現在のnumId
 * @param inputDivId 入れるDivId
 * @param whatData 種類を選択
 * @return
 */
function ajaxContinueDataForHtml(currentNumId, inputDivId, whatData, category) {

	var currentNum = document.getElementById(currentNumId).value;
	var plusHtml = "";  
	var inAjaxDataCount = 0;
	var categoryGetText = "";
    if (category == null) {
    	categoryGetText = "";
    } else {
    	categoryGetText = "&category=" + category;
    }
    
	// new all post
	if (whatData == 1) {
	   	$.ajax({
	   	  url: "/ajax/getNextPostForHtml.php?type=1" + categoryGetText + "&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextPostForHtml.php?type=1' + categoryGetText + '&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#recent_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// new category post
	if (whatData == 2) {
	   	$.ajax({
	   	  url: "/ajax/getNextPostForHtml.php?type=2" + categoryGetText + "&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextPostForHtml.php?type=2' + categoryGetText + '&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#recent_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// gold all post
	if (whatData == 3) {
	   	$.ajax({
	   	  url: "/ajax/getNextPostForHtml.php?type=3" + categoryGetText + "&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextPostForHtml.php?type=3' + categoryGetText + '&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#goldpost_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// gold category post
	if (whatData == 4) {
	   	$.ajax({
	   	  url: "/ajax/getNextPostForHtml.php?type=4" + categoryGetText + "&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextPostForHtml.php?type=4' + categoryGetText + '&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#goldpost_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// postImageSetting
	if (whatData == 5) {
		
		jQuery.ajaxSetup({cache:false});
	   	$.ajax({
	   	  url: "../ajax/getNextPostForHtml.php?type=5&category=artwork&currentNum=" + currentNum, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('../ajax/getNextPostForHtml.php?type=5&type2=count&currentNum=' + currentNum , function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#post_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}

	// search Next
	if (whatData == 6) {
		
		var sort = document.getElementById("sort").value;
		var searchKey = document.getElementById("searchKeyword").value;
		var searchType = document.getElementById("searchType").value;
		
		var types = "";
		if (searchType != "") {
			types = "&searchType=" + searchType; 
		}
		var searchKeyword = "&searchKey=" + searchKey;
		
	   	$.ajax({
	   	  url: "/ajax/getNextPostForHtml.php?type=6&currentNum=" + currentNum + types + searchKeyword, cache: false, success: function(html){
	   		$("#"+inputDivId).append(html); // to add div
	   	  }
	   	});
	    	
	   	$.getJSON('/ajax/getNextPostForHtml.php?type=6&type2=count&currentNum=' + currentNum + types + searchKeyword, function(data) {
	   	    // data search : each() count数よりforする。
	   	    $.each(data, function(index, entry) {   	  
	   	  	  if (entry["result"] == "ok") {
	    	  	  // もっと読むを消す
	   	  	  } else {
	   	  		$("#search_more_div").html(""); // もっと読むボタンを見えないようにする。
	  	  	  }
	   	    });
	   	});
	}
	
	// 現在の番号を+1する。
	document.getElementById(currentNumId).value = parseInt(currentNum, 10) + parseInt("1", 10);
}


/**
 * continue next Data 
 * 
 * @param currentNumId
 * @param inputDivId
 * @param whatData 
 * @return
 */
function ajaxContinueData(currentNumId, inputDivId, whatData) {
  var currentNum = document.getElementById(currentNumId).value;
  var plusHtml = "";  
  var inAjaxDataCount = 0;
  
  // twitter Commentの場合
  if (whatData == 1) {
      $.getJSON('../ajax/getNextTwitPost.php?currentNum=' + currentNum, function(data) {

        // data search : each() count数よりforする。
        $.each(data, function(index, entry) {
            plusHtml += 
            	'<div class="twitter_contents clearfix">' +
            	'  <div class="leftArea">' +
            	'    <div class="rate r99">' +
				'      <strong class="count">' + entry["commentCount"]+ '</strong>' +				
			    '    </div>' +
			    '    <a class="btn" href="#"><span>Retweet</span></a>' +
			    '  </div>' +
			    '  <div class="text">' +
				'  <h3 class="title">' +
					  '<a href="#none">' + entry["title"] + '</a>' +
				'  </h3>' +
				'  <div class="information">' +
				'	  <a href="' + entry["link"] + '"><span class="url">' + entry["link"] + '</span></a>' +
				'  </div> '+
				'    <div class="timeLine">'+
				'	 ' + entry["pubDate"] +
				'    </div>' +
			    '  </div>' +
		        '</div>';
            
            inAjaxDataCount = inAjaxDataCount + 1;
            
        });

        $("#"+inputDivId).append(plusHtml); // to add div
        
        // 最後のデータの場合
        if (inAjaxDataCount < 15) {
          $("#twitter_more_div").html(""); // もっと読むボタンを見えないようにする。
        }
        
        // 現在の番号を+1する。
        document.getElementById(currentNumId).value = parseInt(currentNum, 10) + parseInt("1", 10);
        
    });
      
  // getNextGoldPost
  } else if (whatData == 2) {
	  var currentCategory = document.getElementById("current_category").value;
	  $url = '../ajax/getNextPost.php?currentNum=' + currentNum + '&category=' + currentCategory + '&type=gold';

  // whatData 3: getNextRecentPost
  // whatData　4: getNextPostImage 
  } else if (whatData == 3 || whatData == 4) {
	  var currentCategory = document.getElementById("current_category").value;
	  $url = '../ajax/getNextPost.php?currentNum=' + currentNum + '&category=' + currentCategory + '&type=recent';
	        
  }
   else if (whatData == 5) {	  
	  $url = '../ajax/getNextComment.php?currentNum=' + currentNum;
	        
	}
  
  if (whatData == 2 || whatData == 3) {

	     $.getJSON($url , function(data) {
	         // data search : each() count数よりforする。
	         $.each(data, function(index, entry) {
	             plusHtml +=
	     			'<div class="rss_contents clearfix">' +
					'	<div class="leftArea">' +
					'		<div class="rate r99">' +
					'			<strong class="count" id="point-{' + entry["seq"] + '}" onClick="choix(' + entry["seq"] + ');">' + entry["point"] + '</strong>' +
					'		</div><!-- //rate -->' +
					'		<a class="btn" href="#"><span>Twitter</span></a>' +
					'	</div>' +
					'	<div class="text {if $goldposts[cus].hasThumbnail}with_img{else}{/if}"><!-- mediaがあれば class="with_img 追加" -->' +
					'		<h3 class="title">' +
					'			<a href="/getpost/{' + entry["seq"] + '}">{$goldposts[cus].title|stripslashes|strip_tags}</a>' +
					'			<br />' +
					'			<a href="' + entry["linkUrl"] + '" target="_blank" onMouseUp="view(' + entry["seq"] + ');" title="' + entry["linkUrl"] + 
					'				<span class="url">{' + entry["linkUrl"] + '</span>' +
					'			</a>' +
					'		</h3>' +
					'		<div class="information">' +
					'			<span class="date">' + entry["regDate"] + '</span>' +
					'		</div>' +
					'		<p name="item-meta-desc" class="desc">' + entry["summary"] + '</p>' +
					'		<div class="subInfo">' +
					'			<span class="ico ico_comment" onClick="showhidecomment({$goldposts[cus].seq});" style="cursor: pointer">-comment</span> <a href="/getpost/{$goldposts[cus].seq}"><span id="meta-commentcount{$goldposts[cus].seq}">{$goldposts[cus].commentCount}コメンット</span></a>' +
					'			<span class="ico ico_twit">-comment</span>  <!-- a href="#none">2バトルス</a -->' +
					'			<span class="ico ico_care" id="reportpost' + entry["seq"] + '" onClick="reportpost(' + entry["seq"] + ', ' + entry["choixerId"] + ');">-comment</span>' +
					'		</div>' +
					'	</div><!-- //text -->' +
					'	{if $goldposts[cus].hasThumbnail}' +
					'		<div class="media">' +
					'		<a href="' + entry["linkUrl"] + '" target="_blank" >' +
					'			<img src="{$image_server}/img/thumb/' + entry["seq"] + '" alt="thumbnail" width="86" height="72" />' +
					'		</a>' +
					'		</div>' +
					'		{/if}' +
					'		{if $goldposts[cus].preview}' +
					'		<a href="' + entry["linkUrl"] + '" target="_blank" onMouseUp="view(' + entry["seq"] + ');>' +
					'			<img src="{$image_server}/img/preview/large/' + entry["seq"] + '" width="120" height="90" alt="site" />' +
					'		</a>' +
					'	{/if}' +
	             	'</div><!-- //rss_contents -->';	      
					
	             inAjaxDataCount = inAjaxDataCount + 1;	             
	         });	
	            	                  
	         
	         
	         $("#"+inputDivId).append(plusHtml); // to add div
	         
	         // 最後のデータの場合
	         if (inAjaxDataCount < 15) {		       
		        if (whatData == 2) {
		          $("#goldpost_more_div").html(""); // もっと読むボタンを見えないようにする。
				} else if (whatData == 3) {
				  $("#recent_more_div").html(""); // もっと読むボタンを見えないようにする。
				}      
	         }
	         
	         // 現在の番号を+1する。
	         document.getElementById(currentNumId).value = parseInt(currentNum, 10) + parseInt("1", 10);
	     });
  } 
  
  // Post Image Setting
  if (whatData == 4) {

	     $.getJSON($url , function(data) {
	         // data search : each() count数よりforする。
	         $.each(data, function(index, entry) {
	             plusHtml +=
	            	 
	     			'<div class="rss_contents clearfix">' +
					'	<div class="leftArea">' +
					'		<div class="rate r99">' +
					'			<strong class="count" id="point-{' + entry["seq"] + '}" onClick="choix(' + entry["seq"] + ');">' + entry["point"] + '</strong>' +
					'		</div><!-- //rate -->' +
					'		<a class="btn" href="#"><span>Twitter</span></a>' +
					'	</div>' +
					'	<div class="text {' + entry["hasThumbnail"] + ')with_img"><!-- mediaがあれば class="with_img 追加" -->' +
					'		<h3 class="title">' +					
					'			<a href="/getpost/{' + entry["seq"] + '}">{' + entry["title"] + '}</a>' +
					'			<br />' +
					'			<a href="' + entry["linkUrl"] + '" target="_blank" onMouseUp="view(' + entry["seq"] + ');" title="' + entry["linkUrl"] + 
					'				<span class="url">{' + entry["linkUrl"] + '</span>' +
					'			</a>' +
					'		</h3>' +
					'		<div class="information">' +
					'			<span class="date">' + entry["regDate"] + '</span>' +
					'		</div>' +
					'		<p name="item-meta-desc" class="desc">' + entry["summary"] + '</p>' +
					'		<div class="subInfo">' +
					'			<span class="ico ico_comment" onClick="showhidecomment(' + entry["seq"] + ');" style="cursor: pointer">-comment</span> <a href="/getpost/' + entry["seq"] + '"><span id="meta-commentcount{' + entry["seq"] + '}"{'+ entry["commentCount"] +'}>コメンット</span></a>' +
					'			<span class="ico ico_twit">-comment</span>  <!-- a href="#none">2バトルス</a -->' +
					'			<span class="ico ico_care" id="reportpost' + entry["seq"] + '" onClick="reportpost(' + entry["seq"] + ', ' + entry["choixerId"] + ');">-comment</span>' +
					'		</div>' +
					'</div><!-- //text -->';
	             
							
					if( entry["preview"] ){
						plusHtml +=						
							'		<a href="' + entry["linkUrl"] + '" target="_blank" onMouseUp="view(' + entry["seq"] + ');>' +
							'			<img src="{$image_server}/img/preview/large/' + entry["seq"] + '" width="120" height="90" alt="site" />' +
							'		</a>' ;
					}
					
					'	<div class="inputarea">' ;	
					
					if( entry["hasThumbnail"] ){
						plusHtml +=
							'		<p class="meta-email">' +
							'		<form action="t_postimage_setting.php" method="post" enctype="multipart/form-data">' +
							'		<input name="seq" type="hidden" value="' + entry["postSeq"] +'" />' +
							'		<input name="page" type="hidden" value="' + entry["page"] + '" />' +
							'		<input type="file" name="do_fileup"><input name="do_fileup" type="submit" class="txt1" value="写真" /> /' +
							'		<input name="do_post" type="submit" class="txt1" value="選択" />' +
							'		</form>' +
							'		</p>' +					
					'	</div>' ;
					}
	             	'</div><!-- //rss_contents -->';	      
					
	             inAjaxDataCount = inAjaxDataCount + 1;	             
	         });	
	         
	         
	         $("#"+inputDivId).append(plusHtml); // to add div
	         
	         // 最後のデータの場合	         
	         if (inAjaxDataCount < 15) {		       		        
		          $("#recent_more_div").html(""); // もっと読むボタンを見えないようにする。				    
	         }
	         
	         // 現在の番号を+1する。
	         document.getElementById(currentNumId).value = parseInt(currentNum, 10) + parseInt("1", 10);
	     });
  }  
 }
