//　

function ChangeTab(id){

	new Ajax.Request('./bg_getTopTab.do', {
		method: 'get',
		parameters: {
			cat_id: id
		},
		onLoaded: function(tr) {
		},
		onLoading: function(tr) {
			el = replaceHtml2('Index_Tweet_Display_Tab',"<img src='../"+mini_ajax_load+"'><br><br><br><br><br>");

			for (i = 1; i <= 8; i++) {
				if(i=="1" || i=="2" || i=="3" || i=="6"){
					if(i!=id){
						document.getElementById("tab_on_"+i).style.display="block";
						document.getElementById("tab_off_"+i).style.display="none";
					}else{
						document.getElementById("tab_on_"+i).style.display="none";
						document.getElementById("tab_off_"+i).style.display="block";
					}
				}
			}
		},
		onFailure: function(tr) {
			alert('Error');
		},
		onSuccess: function(tr) {
			if(Common_Error_Check_Crp(tr.responseText)){
				el = replaceHtml2('Index_Tweet_Display_Tab',tr.responseText);
			}else{
				el = replaceHtml2('Index_Tweet_Display_Tab',"Data Error");
			}
		}
	});

}

function Common_Error_Check_Crp(str){

	if(str.match('99999')){
		return false;
	}else{
		return true;
	}
}






function ShowIndex(){


//	alert('ShowIndex');

}

function check_str_Count_CoreSpo(){

	var str =  document.getElementById('status').value;

	el = replaceHtml2("strCount",StartLength - CRLF_LF(str).length);

	if(str.length==0){
		document.getElementById('rep_id').value="";
		el = replaceHtml2('whatsNow',"");
//		document.getElementById('is_dm').value="";
	}else{
		if(JStrim(str).match(/^d @/i)){
			el = replaceHtml2('whatsNow',"ダイレクトメッセージ：");
			var dm_send_user = str.match(/(@[0-9a-zA-Z_]+)/);
			if(dm_send_user!=null){
				el = replaceHtml2('whatsNow',dm_send_user[0]+"へのダイレクトメッセージ：");
				document.getElementById('is_dm').value="1";
				document.getElementById('dm_user').value=dm_send_user[0];
			}
		}else{
			var regex = new RegExp(rep_str, "i");
			if(str.search(regex) == -1){
				el = replaceHtml2('whatsNow',"");
				document.getElementById('rep_id').value="";
//				document.getElementById('is_dm').value="";
				rep_str="";
			}else{
				if(str.match(/^@[0-9a-zA-Z_]/i)){
					var rep_send_user = str.match(/(@[0-9a-zA-Z_]+)/);
					el = replaceHtml2('whatsNow',rep_send_user[0]+"への返信：");
				}
			}
		}
	}


}


function setStatusRep(screen_name,id){

	if(document.getElementById('rep_id').value!=id){
		document.getElementById('status').value = "";

		var tmp = document.getElementById('status').value;
		var regex = new RegExp("@"+screen_name+" ", "i");

		if(tmp.search(regex) == -1){
			el = replaceHtml2('whatsNow', "@"+screen_name+"への返信");
			document.getElementById('status').value = "@"+screen_name+" "+tmp;
			rep_str = "@"+screen_name+" ";
		}

		document.getElementById('rep_id').value=id;
	}
	check_str_Count_CoreSpo();
}



function setStatusUnOfficaliRt(screen_name){
	var RT_buf = document.getElementById('RT_Str').value;
	document.getElementById('status').value = " RT @"+screen_name+": "+ RT_buf.unescapeHTML();
	check_str_Count_CoreSpo();
}


function do_Official_RtCoreSpo(id,corespo_id){

	new Ajax.Request('./bg_official_rtOPE.do', {
		method: 'get',
		parameters: {
			id: id,
			corespo_id: corespo_id
		},
		onLoaded: function(tr) {
		},
		onLoading: function(tr) {
		},
		onFailure: function(tr) {
			alert('Error');
		},
		onSuccess: function(tr) {
			if(checkResponseError(tr.responseText)){
				alert('RT処理エラー');
			}else{
				alert('RTをいたしました。');
			}
		}
	});

}




function doSend2CorespoDetail(){

//alert( document.getElementById('rep_id').value );

	if(document.getElementById('status').value!=""){

//		if(document.getElementById('short_url_enabled').checked){
//			var short_url_enabled = 1;
//		}else{
//			var short_url_enabled = 0;
//		}
		if(document.getElementById('add_tw')!=null){
			var now_add = document.getElementById('add_tw').value;
		}else{
			var now_add = '1';
		}

		new Ajax.Request('./bg_status_update.do', {
			method: 'get',
			parameters: {
				status: document.getElementById('status').value,
				rep_id: document.getElementById('rep_id').value,
				parents_corespo_id:  document.getElementById('parents_corespo_id').value,
				now_add: now_add
			},
			onLoaded: function(tr) {
			},
			onLoading: function(tr) {
				document.getElementById('sBt').disabled=true;
				el = replaceHtml2('strCount',"<img src='"+mini_ajax_load+"'>");
			},
			onFailure: function(tr) {
				el = replaceHtml2('strCount',StartLength);
				document.getElementById('sBt').disabled=false;
				alert('Error');
			},
			onSuccess: function(tr) {
				if(checkResponseError(tr.responseText)){
					document.getElementById('sBt').disabled=false;
					alert('投稿エラー');
				}else{
//alert('a');
					el = replaceHtml2("noneRes","");
//alert('b');
					document.getElementById('status').value="";
//alert('c');
					el = replaceHtml2("strCount",StartLength);
//alert('d');
					document.getElementById('rep_id').value="";
//alert('e');
					el = replaceHtml2("adTimeLine_"+now_add,tr.responseText);
//alert('f');
					document.getElementById('sBt').disabled=false;
					document.getElementById('now_add').value = now_add_status*1+1;
				}

			}
		});
	}else{
		alert('未入力です');
	}

}

function readMore(){

	if(document.getElementById('now_more')!=null){
		var now_more = document.getElementById('now_more').value;
	}else{
		var now_more = '1';
	}

	if(document.getElementById('last_id')!=null){

	new Ajax.Request('./bg_getStatusMore.do', {
		method: 'get',
		parameters: {
			last_id: document.getElementById('last_id').value,
			corespo_id: document.getElementById('corespo_id').value,
//			rt_exs: document.getElementById('rt_exs').value,
			now_more: now_more
		},
		onLoaded: function(tr) {
		},
		onLoading: function(tr) {
			el = replaceHtml2("moreTimeLine_"+now_more,"<img src='"+mini_ajax_load+"'>");
		},
		onFailure: function(tr) {
			alert('Error');
		},
		onSuccess: function(tr) {
			if(checkResponseError(tr.responseText)){
				alert('データ取得エラー');
			}else{
				if(tr.responseText=="More_None"){
					el = replaceHtml2("moreTimeLine_"+now_more,"");
					document.images['moreBtImg'].src = "/corespo/common/images/btn_more_end.gif";
					document.images['moreBtImg'].alt = tr.responseText;
					document.getElementById('moreLink').disabled=true;
				}else{
					el = replaceHtml2("last_id_row_"+now_more,"");
					document.getElementById('now_more').value = now_more*1+1;
					el = replaceHtml2("moreTimeLine_"+now_more,tr.responseText);
				}
			}

		}
	});

	}

}


function showRtUsers(id){


	new Ajax.Request('./bg_getRtUser.do', {
		method: 'get',
		parameters: {
			corespo_id: id
		},
		onLoaded: function(tr) {
		},
		onLoading: function(tr) {
			el = replaceHtml2("rtUsers","<img src='"+mini_ajax_load+"'>");
		},
		onFailure: function(tr) {
			alert('Error');
		},
		onSuccess: function(tr) {
			if(checkResponseError(tr.responseText)){
				alert('データ取得エラー');
			}else{
				el = replaceHtml2("rtUsers",tr.responseText);
			}

		}
	});
}


function readMoreUser(){
	if(document.getElementById('now_more')!=null){
		var now_more = document.getElementById('now_more').value;
	}else{
		var now_more = '1';
	}

	if(document.getElementById('last_id')!=null){

		new Ajax.Request('./bg_getUserMore.do', {
			method: 'get',
			parameters: {
				last_id: document.getElementById('last_id').value,
				user_id: document.getElementById('user_id').value,
				now_more: now_more
			},
			onLoaded: function(tr) {
			},
			onLoading: function(tr) {
				el = replaceHtml2("moreTimeLine_"+now_more,"<img src='"+mini_ajax_load+"'>");
			},
			onFailure: function(tr) {
				alert('Error');
			},
			onSuccess: function(tr) {
				if(checkResponseError(tr.responseText)){
					alert('データ取得エラー');
				}else{
					if(tr.responseText=="More_None"){
						el = replaceHtml2("moreTimeLine_"+now_more,"");
					}else{
						el = replaceHtml2("last_id_row_"+now_more,"");
						document.getElementById('now_more').value = now_more*1+1;
						el = replaceHtml2("moreTimeLine_"+now_more,tr.responseText);
					}
				}
			}
		});

	}
}


function readMoreList(){
	if(document.getElementById('now_more')!=null){
		var now_more = document.getElementById('now_more').value;
	}else{
		var now_more = '1';
	}

//	alert(document.getElementById('last_id').value + "----" +  document.getElementById('cat_id').value + "----" +  now_more ) ;

	if(document.getElementById('last_id')!=null){

		new Ajax.Request('./bg_getListMore.do', {
			method: 'get',
			parameters: {
				last_id: document.getElementById('last_id').value,
				cat_id: document.getElementById('cat_id').value,
				now_more: now_more
			},
			onLoaded: function(tr) {
			},
			onLoading: function(tr) {
				el = replaceHtml2("moreTimeLine_"+now_more,"<img src='"+mini_ajax_load+"'>");
			},
			onFailure: function(tr) {
				alert('Error');
			},
			onSuccess: function(tr) {
				if(checkResponseError(tr.responseText)){
					alert('データ取得エラー');
				}else{
					if(tr.responseText=="More_None"){
						el = replaceHtml2("moreTimeLine_"+now_more,"");
					}else{
						el = replaceHtml2("last_id_row_"+now_more,"");
						document.getElementById('now_more').value = now_more*1+1;
						el = replaceHtml2("moreTimeLine_"+now_more,tr.responseText);
					}
				}
			}
		});
	}
}


function readMoreSearch(){

	if(document.getElementById('now_more')!=null){
		var now_more = document.getElementById('now_more').value;
	}else{
		var now_more = '1';
	}

//	alert(document.getElementById('last_id').value + "----" +  document.getElementById('q').value + "----" +  now_more ) ;

	if(document.getElementById('last_id')!=null){

		new Ajax.Request('./bg_getSearchMore.do', {
			method: 'get',
			parameters: {
				last_id: document.getElementById('last_id').value,
				q: document.getElementById('q').value,
				now_more: now_more
			},
			onLoaded: function(tr) {
			},
			onLoading: function(tr) {
				el = replaceHtml2("moreTimeLine_"+now_more,"<img src='"+mini_ajax_load+"'>");
			},
			onFailure: function(tr) {
				alert('Error');
			},
			onSuccess: function(tr) {
				if(checkResponseError(tr.responseText)){
					alert('データ取得エラー');
				}else{
					if(tr.responseText=="More_None"){
						el = replaceHtml2("moreTimeLine_"+now_more,"");
					}else{
						el = replaceHtml2("last_id_row_"+now_more,"");
						document.getElementById('now_more').value = now_more*1+1;
						el = replaceHtml2("moreTimeLine_"+now_more,tr.responseText);
					}
				}
			}
		});
	}

}


function MypageTop_Repo(){

	if(document.getElementById('sel_ym')!=null){
		var fl = document.getElementById('sel_ym').value;
	}else{
		var fl = 0;
	}

	new Ajax.Request('./bg_getMyPageTop_Repo.do', {
		method: 'get',
		parameters: {
			preview: fl
		},
		onLoaded: function(tr) {
		},
		onLoading: function(tr) {
			el = replaceHtml2("tweetsRepo","<img src='"+mini_ajax_load+"'>");
		},
		onFailure: function(tr) {
			alert('Error');
		},
		onSuccess: function(tr) {
			el = replaceHtml2("tweetsRepo",tr.responseText);
		}
	});

}


