function allstart() {
	var st = $("#h_st").val();
	if(st == "g"){
		yahoo_blog_search();					
	}
	if(st == "t"){
		//getTimeLineSearch();
		TwitterSearch(50);	
		$("#tweetpage_area").charCount();				
	}
	if(st == "w"){
		GoogleAjaxOnLoad4();					
	}
	if(st == "h"){
		get_hatene_Json();
	}
	if(st == "m"){
		$("#tweetpage_area").charCount();				
	}

	gettab();
}

function getsim(obj,asin) {
	var st = $("#h_st").val();
	$(obj).html('<br><img src="/img/loading.gif">');
	$.ajax({
		url: "/get_relate.pl",
		type: "get",
		data:{ asin : asin , st : st },
	    success : function(date){
			$(obj).html('');
			$(obj).after('<div>'+date+'</div>');
	    },
	    error : function(){
	        //alert('error');
	    }
	});
	return;
}

function getreflexa() {
	var query = decodeURIComponent($("#h_query").val());
	$("#tagging").html('<br><img src="/img/loading.gif">');
	$.ajax({
		url: "http://labs.preferred.jp/reflexa/api.php",
		type: "post",
		data:{ format : "json" , q :  query },
	    success : function(date){
			$("#reflexa").html(date);
	    },
	    error : function(){
	        //alert('error');
			//$("#tagging").html("エラーが発生しています。ページを更新してみてください。");
	    }
	});
	return;
}
function gettab() {
	var text = $("#h_text").val();
	$("#tagging").html('<br><img src="/img/loading.gif">');
	$.ajax({
		url: "/get_tag.pl",
		type: "post",
		data:{ text : text  },
	    success : function(date){
			$("#tagging").html(date);
	    },
	    error : function(){
	        //alert('error');
			$("#tagging").html("エラーが発生しています。ページを更新してみてください。");
	    }
	});
	return;
}
function nextauth(obj,last_id) {
	if (last_id < 0) return;

	var h_star  = $("#h_star").val();
	$(obj).html('<img src="/img/loading.gif">');
	$.ajax({
		url: "/get_nextauth.pl",
		type: "post",
		data:{ star : h_star ,last_id : last_id },
	    success : function(date){
			$(obj).html('');
			$(obj).css("display","none");
			$(obj).after('<div>'+date+'</div>');
	    },
	    error : function(){
	        //alert('error');
			$(obj).html('エラーが発生しています。ページを更新してみてください。');
	    }
	});
	return;
}
function next(obj,last_id) {
	if (last_id < 0) return;

	var h_star  = $("#h_star").val();
	var h_user_id  = $("#h_user_id").val();
	$(obj).html('<img src="/img/loading.gif">');
	$.ajax({
		url: "/get_nextauth.pl",
		type: "post",
		data:{ star : h_star ,user_id : h_user_id ,last_id : last_id },
	    success : function(date){
			$(obj).html('');
			$(obj).css("display","none");
			$(obj).after('<div>'+date+'</div>');
	    },
	    error : function(){
	        //alert('error');
			$(obj).html('エラーが発生しています。ページを更新してみてください。');
	    }
	});
	return;
}

function get_hatene_Json(){
	//backToTop();
	var set_url = $("#hatena_url").val() ;
	var commentOnly = true;
	if (set_url == "") {
		$("#hatena_bookmark").text("検索文字が空です。エラーです");

		return;
	}
	
	$("#hatena_bookmark").html('<img src="/img/loading.gif">');

	$.ajax({
	    url : "http://b.hatena.ne.jp/entry/json/",
	    dataType : "jsonp",
	    data : {
	        "url" : set_url	,"callback" : "j"
	    },
	    success : function(j){
			$("#hatena_bookmark").empty();
			var html = "" ;
			if(j){
				html =  j.title + " <br><a href=\"http://b.hatena.ne.jp/entry/"+j.url+"\" target=\"_blank\"><img src=\"http://b.hatena.ne.jp/entry/image/"+j.url+"\"> </a> " ;
		        html += '<ul>';
				var cnt = 0 ;
				var line = "";
				$.each(j.bookmarks, function(){
		          var u = this.user;
		          if (!commentOnly || this.comment != ''){
		              line += '<li><span class="hb_timestamp">' + this.timestamp.slice(0,10) + '</span> <img src="http://www.hatena.ne.jp/users/' + u.slice(0,2) + '/' + u + '/profile_s.gif" alt="' + u + '" title="' + u + '" /> <a href="http://b.hatena.ne.jp/' + u + '/">' + u + '</a> <span class="hb_tag">' + this.tags.join(', ') + '</span> <span class="hb_comment">' + this.comment + '</span></li>';
					cnt++;
					}
		        });
				if(cnt == 0){
			        html = '検索結果は0件でした。<div class="hiheight"><br><br></div>';
				}else{
			        html += line+'</ul>';
				}
			}else{
			        html = '検索結果は0件でした。<div class="hiheight"><br><br></div>';
			}
			$("#hatena_bookmark").html(html);

	    },
	    error : function(){
	       // alert('error');
			$("#hatena_bookmark").html("エラーが発生しています。ページを更新してみてください。");

	    }
	});
}



function selectedjump(sel) {
	if (sel.selectedIndex == -1) return;
	var asin = $("#asin").val();
	var opt = sel.options[sel.selectedIndex];
	if (opt && opt.value){
		if(opt.value >= 0 ){
			var url = "/add/"+asin +"/" + opt.value ;
		}
		location.href = url;
	}
}  
function selectedjumpSort(sel) {
	if (sel.selectedIndex == -1) return;
	var book_q  = $("#book_q").val();
	var book_st = $("#book_st").val();
	var opt = sel.options[sel.selectedIndex];
//alert("/booksearch.pl?query="+ encodeURIComponent(book_q) +"&st=" + book_st + "&sort=" + opt.value );
	var url = "/booksearch.pl?q="+ encodeURIComponent(book_q) +"&st=" + book_st + "&sort=" + opt.value ;
	location.href = url;
}    
function selectedjumpBN(sel) {
	if (sel.selectedIndex == -1) return;
	var opt = sel.options[sel.selectedIndex];
//alert("/cat/" + opt.value );
	var url = "/cat.pl?bn=" + opt.value ;
	location.href = url;
}    
function selectedjumpSortBN(sel) {
	if (sel.selectedIndex == -1) return;
	var h_bn  = $("#h_bn").val();
	var book_st = $("#book_st").val();
	var opt = sel.options[sel.selectedIndex];
//alert("/booksearch.pl?query="+ encodeURIComponent(book_q) +"&st=" + book_st + "&sort=" + opt.value );
	var url = "/cat.pl?bn="+h_bn + "&sort=" + opt.value +"&st=" + book_st;
	location.href = url;
}    

function backToTop() {
	var x1 = x2 = x3 = 0;
	var y1 = y2 = y3 = 0;
	if (document.documentElement) {
	x1 = document.documentElement.scrollLeft || 0;
	 y1 = document.documentElement.scrollTop || 0;
	 }
	 if (document.body) {
	 x2 = document.body.scrollLeft || 0;
	 y2 = document.body.scrollTop || 0;
	 }
	 x3 = window.scrollX || 0;
	 y3 = window.scrollY || 0;
	 var x = Math.max(x1, Math.max(x2, x3));
	 var y = Math.max(y1, Math.max(y2, y3));
	 window.scrollTo(Math.floor(x / 4), Math.floor(y / 4));
	 if (x > 0 || y > 0) {
	 window.setTimeout("backToTop()", 25);
	 }
}
function setGoiken(){

	var response = "<br><br><b>ご意見ありがとうございました。</b><br><br>頂いたご意見には必ず目を通しますが、個々のご意見にお返事できないことを予めご了承ください。<br>";
	response    += '<br>返事が必要な<br>お問い合わせの場合は<br><a href="http://loopshoot.com/feedback.pl">こちらから連絡ください。</a>';

	var goiken_len = document.getElementById("goiken_len").value;

	document.getElementById("goiken").innerHTML = response ;

	if(goiken_len.length > 0 ){
		goiken_len = goiken_len.replace(/</g, '＜') ;
		goiken_len = goiken_len.replace(/>/g, '＞') ;
		goiken_len = goiken_len.replace(/\"/g, '"') ;
	}
	var url = document.URL ;

	var get_url = "set_goiken.cgi?goiken_len=" + goiken_len + "&url=" +url ; 
	xmlhttp = new XMLHttpRequest() ;

	xmlhttp.open("get",get_url);
	xmlhttp.send("");
	//$.get("set_goiken.cgi?", { goiken_len: goiken_len , url : url} );

	return;


}
yahoo_key = "whoever2" ;
function yahoo_blog_search(){
	$("#yahoo_result").html('<img src="/img/loading.gif">');
	var query = $("#q_for_yahoo").val() ;
	var html = "" ;
	var result = "" ;
	if (query == "") {
		return;
	}
	var turl = "http://search.yahooapis.jp/BlogSearchService/V1/blogSearch?appid="+ yahoo_key + "&query="+ encodeURIComponent(query) +"&results=20&output=json&callback=?"  ;
	$.ajax({   
        type: 'GET',
	    url : turl ,
		dataType: 'jsonp',
	    success : function(data, status){
			$("#yahoo_result").html('<img src="/img/loading.gif">');
		        $.each(data.Result,
		          function(index, value) {
					var ymd  = value.DateTime.substring(0,10);
		            result 
			            += '<div class="bres" >'
							+  '<div class="tit" >'+ '<a href="' + value.Url + '" target="_blank">' + value.Title + "</a></div>"
				            +  '<div class="date" >'+ ymd + ' <a href="' + value.Site.Url + '" target="_blank">' + value.Site.Title + "</a>" + '</div>'
				            +  '<div class="desc" >'+ value.Description +  '</div>'
	//			            +  '<span class="creater" >'+ value.Creator +  '</span>'
			            +  '</div>'
	//		            +  '<div class="last_line"></div>';
		          }
		        );
/*
			var cnt = 0 ;
		    for ( var i=0; i<res.list.length; i++ ) {
		        tweet     = res.list[i];
				if(cnt < 50 ){
			        thumb     = tweet.author.photo_url.replace(/(normal)\.([a-z]{3,4})$/i,'mini.$2');
			        author_id = tweet.author.url.replace('http://twitter.com/','');
					var retext = tweet.content ;
					retext = retext.replace(/(http:\/\/[\x21-\x7e]+)/gi, "<a target=\"_blank\" href='$1'>$1</a>");
					retext = retext.replace(/(\r\n|\r|\n)/g,'') ;
			        html
			            += '<div class="ont" >'
			            +  '<a href="/user/'+author_id+'" >'
			            +  '<img src="'+thumb+'" alt="'+tweet.author.name+'" style="float:left;border:0;vertical-align:bottom;width:30px;height:30px;padding:0 4px 0 0" />'
			            +  '</a> '
			            +  ' <a href="/user/'+author_id+'" style="color:#0084B4;">'
			            +  author_id
			            +  '</a> '
			            +  retext
						+  ' <a href="'+tweet.permalink_url+'" target="_blank" style="color:#0084B4;">'+tweet.date_alpha+'</a>'
			            +  '</div>'
			            +  '<div class="last_line"></div>';

				}
				cnt++;
		    }
*/
/*
		    if ( res.total > 50 ) {
		        html
		            += '<div>'
		            +  '<a href="'+res.topsy_trackback_url+'" target="_blank" style="display:inline-block;margin:0;padding:5px; sans-serif;color:#0084B4;text-decoration:none;border:1px solid #CCC;-moz-border-radius:5px;-webkit-border-radius:5px;">'
		            +  'もっと読む'
		            +  '</a>'
		            +  '</div>';
		    }
*/
			$("#yahoo_result").html(result);
	    },
	    error : function(){
	        alert('error  ajax error');
			$("#yahoo_result").html("エラーが発生しました。");
	    }
	});
}


function GoogleAjaxOnLoad3(){
		var search_player = document.getElementById("q_for_google").value;
		if (search_player == "") return;
		//search in loopshoot.com
		var loopshoot = new google.search.WebSearch();
		loopshoot.setUserDefinedLabel("loopshoot.com");
		loopshoot.setSiteRestriction("009214614192160974402:vwlz9dthoqy");

		//search in social book mark
		var sbm = new google.search.WebSearch();
		sbm.setUserDefinedLabel("SBM");
		sbm.setSiteRestriction("009214614192160974402:s7v_zas21xw");

		var hatena = new google.search.BlogSearch();
		hatena.setUserDefinedLabel("はてなダイアリー");
		hatena.setSiteRestriction("d.hatena.ne.jp");

		var ameblo = new google.search.BlogSearch();
		ameblo.setUserDefinedLabel("アメブロ");
		ameblo.setSiteRestriction("ameblo.jp");

		var livedoor = new google.search.BlogSearch();
		livedoor.setUserDefinedLabel("livedoorブログ");
		livedoor.setSiteRestriction("blog.livedoor.jp");

		var fc2 = new google.search.BlogSearch();
		fc2.setUserDefinedLabel("FC2ブログ ");
		fc2.setSiteRestriction("fc2.com");

		var seesaa = new google.search.BlogSearch();
		seesaa.setUserDefinedLabel("seesaaブログ ");
		seesaa.setSiteRestriction("blog.seesaa.jp");

		var goo = new google.search.BlogSearch();
		goo.setUserDefinedLabel("gooブログ ");
		goo.setSiteRestriction("blog.goo.ne.jp");

        // create a tabbed mode search control
        var tabbed = new google.search.SearchControl();
        tabbed.setResultSetSize(google.search.Search.LARGE_RESULTSET);

/*
		//news
		var news = new google.search.NewsSearch();
		news.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS,{  "ned" : "uk"});
		news.setUserDefinedLabel("ニュース(UK)");
        tabbed.addSearcher(news);

		var news_us = new google.search.NewsSearch();
		news_us.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS,{  "ned" : "us"});
		news_us.setUserDefinedLabel("ニュース(US)");
        tabbed.addSearcher(news_us);
*/
        tabbed.addSearcher(new google.search.BlogSearch());

	    tabbed.addSearcher(hatena);
	    tabbed.addSearcher(ameblo);
	    tabbed.addSearcher(livedoor);
	    //tabbed.addSearcher(fc2);
	    //tabbed.addSearcher(seesaa);
	    //tabbed.addSearcher(goo);
        tabbed.addSearcher(new google.search.BookSearch());
        tabbed.addSearcher(new google.search.WebSearch());
	    tabbed.addSearcher(sbm);
	    //tabbed.addSearcher(loopshoot);

        // establish a keep callback
        //tabbed.setOnKeepCallback(this, MyKeepHandler,"Pick up!");

		//NoResults
		tabbed.setNoResultsString("検索結果は0件でした。");
		tabbed.setLinkTarget(google.search.Search.LINK_TARGET_BLANK); //LINK_TARGET_SELF


        // draw in tabbed layout mode
        var drawOptions = new google.search.DrawOptions();
        drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
        tabbed.draw(document.getElementById("google_result"), drawOptions);
        tabbed.execute(search_player);
}
function MyKeepHandler(result) {
		$("#copy_result").html('Loading....');
		$("#tbox").empty();
		$("#hint").html('Loading....');
		backToTop();
		$("#hide_url").val("");
		$("#hide_title").val("");

        // clone the result html node
        var unescapedUrl      = result.unescapedUrl;
        var url               = result.url;
		if(url == undefined){
			url = result.postUrl; //for blog
		}
        var content           = result.content;
        var title             = result.title;
        var titleNoFormatting = result.titleNoFormatting;
        var blogUrl               = result.visibleUrl;
        var pub_date               = result.publishedDate;

		if(blogUrl == undefined){
			blogUrl = result.blogUrl; //for blog
		}
		var add_url = 'blog.pl?mode=p' ;
		add_url += '&url='             + url         ;
		add_url += '&title=' + escape(titleNoFormatting);
		add_url += '&blogUrl='        + escape(blogUrl)  ;
		add_url += '&content='         + escape(content)     ;
		//add_url += '&unescapedUrl='    + unescapedUrl;
		//add_url += '&title='           + escape(title)       ;

		//asin
		//var asin = $("#asin").val();
		//add_url += '&asin=' + escape(asin);

		var decodeurl = decodeURIComponent(url);

		$("#copy_result").empty();
		$("#copy_result")
       		.append($("<div/>").addClass("news")
			.append($("<div/>").html('<a href="'+decodeurl+'" target="_blank">'+titleNoFormatting+'</a>')
       		.append($("<div/>").addClass("date").html(pub_date))
			.append($("<div/>").html(content)))
		);

		$("#h_url").val(decodeurl);
		$("#h_title").val(titleNoFormatting);
		$("#h_content").val(content);
		$("#h_pub_date").val(pub_date);
		$("#post_succeed").css({display:"block"});
		$("#copy_result").css({display:"block",backgroundColor:"#eafaff"});
		$("#keyword_result").css({display:"block"});
		$("#keyword_result").html("Loading......");


		$.ajax({
		  type: "post",
		  url: "get_keyword.pl",
		  data:{ q : titleNoFormatting + content },
		  success: function(data){
				$("#keyword_result").html(data);
			},	
		    error : function(){
				$("#keyword_result").html("ごめんなさい。エラーが発生してます。");
		    }
		  
		});


		return;
}
function GoogleAjaxOnLoad4(){
		var search_player = document.getElementById("q_for_google").value;
		if (search_player == "") return;

		//search in social book mark
		var sbm = new google.search.WebSearch();
		sbm.setUserDefinedLabel("SBM");
		sbm.setSiteRestriction("009214614192160974402:s7v_zas21xw");

        // create a tabbed mode search control
        var tabbed = new google.search.SearchControl();
        tabbed.setResultSetSize(google.search.Search.LARGE_RESULTSET);

        tabbed.addSearcher(new google.search.WebSearch());
        tabbed.addSearcher(new google.search.BlogSearch());
        tabbed.addSearcher(new google.search.NewsSearch());
        tabbed.addSearcher(new google.search.ImageSearch());
        tabbed.addSearcher(new google.search.BookSearch());

	    tabbed.addSearcher(sbm);

        // establish a keep callback
        //tabbed.setOnKeepCallback(this, MyKeepHandler,"Pick up!");

		//NoResults
		tabbed.setNoResultsString("検索結果は0件でした。");
		tabbed.setLinkTarget(google.search.Search.LINK_TARGET_BLANK); //LINK_TARGET_SELF


        // draw in tabbed layout mode
        var drawOptions = new google.search.DrawOptions();
        drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
        tabbed.draw(document.getElementById("google_result"), drawOptions);
        tabbed.execute(search_player);
}

/* start */

function eraseSA(obj){
	if (obj.value == obj.defaultValue) obj.value = "";
}
function eraseSA_team(obj){
	if( $("open_mb").checked == true ){
		obj.value = "";
		$("warning1").style.display = 'block';
		$("warning1").innerHTML = '<img src="/img/warning.png"> 入力サポート使用時はチーム名は手動入力できません。<br>(入力したい場合はチェックを外してください。)';
	}
}
function nameSet(obj){	
	var out = "out_" + obj.name;
	document.getElementById(out).innerHTML = obj.value;
}
function idjump(id){	
	var url = $("#"+id).val();
	location.href = url ;
}

function getreflexa(){
	$("#reflexa").html('<img src="/img/loading.gif">');
	var h_query = $("#h_query").val() ;
	var html = "" ;
	$.ajax({   
        type: 'GET',
	    url : "/get_reflexa.pl?" ,
		data:{"q" : h_query},
	    success : function(date){
			$("#reflexa").html(date);
	    },
	    error : function(){
	        //alert('error  ajax error');
			$("#reflexa").html("エラーが発生しました。");
	    }
	});
}






function getTimeLine(){
	$("#tweets").html('<img src="/img/loading.gif">');
	var asin = $("#asin").val() ;
	var html = "" ;
	if (asin == "") {
		if (asin == "") {
			alert("error !! asinがありません。");
		}
		return;
	}
	var turl = "http://otter.topsy.com/search.js?perpage=50&q=" + asin ;
	$.ajax({   
        type: 'GET',
	    url : turl ,
		dataType: 'jsonp',
	    success : function(j, status){
			$("#tweets").html("Loading.....");

		    res = j.response;
		    if ( !res.total ) {
		        html
		            += '検索結果は0件でした。';
					$("#tweets").html(html);
		        return false;
		    }
		    var hint = '';
		    //if ( document.getElementById('topsy_counter') ) {
		    //    document.getElementById('topsy_counter').innerHTML = html;
		    //}
			var cnt = 0 ;
		    for ( var i=0; i<res.list.length; i++ ) {
		        tweet     = res.list[i];
				if(cnt < 50 ){
			        thumb     = tweet.author.photo_url.replace(/(normal)\.([a-z]{3,4})$/i,'mini.$2');
			        author_id = tweet.author.url.replace('http://twitter.com/','');
					var retext = tweet.content ;
					retext = retext.replace(/(http:\/\/[\x21-\x7e]+)/gi, "<a target=\"_blank\" href='$1'>$1</a>");
					retext = retext.replace(/(\r\n|\r|\n)/g,'') ;
			        html
			            += '<div class="ont" >'
			            +  '<a href="/user/'+author_id+'" >'
			            +  '<img src="'+thumb+'" alt="'+tweet.author.name+'" style="float:left;border:0;vertical-align:bottom;width:30px;height:30px;padding:0 4px 0 0" />'
			            +  '</a> '
			            +  ' <a href="/user/'+author_id+'" style="color:#0084B4;">'
			            +  author_id
			            +  '</a> '
			            +  retext
						+  ' <a href="'+tweet.permalink_url+'" target="_blank" style="color:#0084B4;">'+tweet.date_alpha+'</a>'
			            +  '</div>'
			            +  '<div class="last_line"></div>';

				}
				cnt++;
		    }

		    if ( res.total > 50 ) {
		        html
		            += '<div>'
		            +  '<a href="'+res.topsy_trackback_url+'" target="_blank" style="display:inline-block;margin:0;padding:5px; sans-serif;color:#0084B4;text-decoration:none;border:1px solid #CCC;-moz-border-radius:5px;-webkit-border-radius:5px;">'
		            +  'もっと読む'
		            +  '</a>'
		            +  '</div>';
		    }
		    if ( document.getElementById('tweets') ) {
		        document.getElementById('tweets').innerHTML = html;
		    }
	    },
	    error : function(){
	        alert('error  ajax error');
			$("#tweets").html("エラーが発生しました。");
	    }
	});
}


function getTimeLineSearch(){
	$("#tweets").html('<img src="/img/loading.gif">');
	var url = $("#pos").val() ;
	var html = "" ;
	if (url == "") {
		if (url == "") {
			alert("error !! ");
		}
		return;
	}
	var decodeurl = decodeURIComponent(url);
	var turl = "http://otter.topsy.com/search.js?perpage=50&q=" + encodeURIComponent(url) ;
//alert(turl);
	$.ajax({   
        type: 'GET',
	    url : turl ,
		dataType: 'jsonp',
	    success : function(j, status){
			$("#tweets").html("Loading.....");

		    res = j.response;
		    if ( !res.total ) {
		        html
		            += '検索結果は0件でした。';
					$("#tweets").html(html);
		        return false;
		    }
			var cnt = 0 ;
		    for ( var i=0; i<res.list.length; i++ ) {
		        tweet     = res.list[i];
				if(cnt < 50 ){
			        thumb     = tweet.topsy_author_img ;
			        author_id = tweet.trackback_author_url.replace('http://twitter.com/','');
					var retext = tweet.content ;
					retext = retext.replace(/(http:\/\/[\x21-\x7e]+)/gi, "<a  target=\"_blank\" href='$1'>$1</a>");
					retext = retext.replace(/(\r\n|\r|\n)/g,'') ;
			        html
			            += '<div class="ont" style="">'
			            +  '<a href="/user/'+author_id+'" >'
			            +  '<img src="'+thumb+'" alt="'+author_id+'" style="float:left;border:0;vertical-align:bottom;width:30px;height:30px;padding:0 4px 0 0" />'
			            +  '</a> '
			            +  ' <a href="/user/'+author_id+'"  style="color:#0084B4;">'
			            +  author_id
			            +  '</a> '
			            +  retext
			            +  '</div>'
			            +  '<div>'
						+  'このページに 合計 '+tweet.trackback_total + ' ツイート '
			            +  '</div>'
			            +  '<div class=""></div>';

				}
				cnt++;
		    }

		    if ( res.total > 50 ) {
		        html
		            += '<div>'
		            +  '<a href="'+res.topsy_trackback_url+'" target="_blank" style="display:inline-block;margin:0;padding:5px; sans-serif;color:#0084B4;text-decoration:none;border:1px solid #CCC;-moz-border-radius:5px;-webkit-border-radius:5px;">'
		            +  'もっと読む'
		            +  '</a>'
		            +  '</div>';
		    }
		    if ( document.getElementById('tweets') ) {
		        document.getElementById('tweets').innerHTML = html;
		    }
	    },
	    error : function(){
	        alert('error  ajax error');
			$("#tweets").html("エラーが発生しました。");
	    }
	});
}
function set_bitly() {
	var text = $("#tweetpage_area").val();
	$("#tweetpage_area").val("Loading.....");
	var long = $("#self_url").val();
	var bitly    = "/bitly.pl?long_url=" + encodeURIComponent(long) ;
	$.ajax({
		url: bitly,
		type: "get",
	    success : function(date){
			var re=new RegExp(long,'g');
			text = text.replace(re,date) ;
			$("#tweetpage_area").val(text);

	    },
	    error : function(){
	        alert('error');
	    }
	});
	return;
}    


function nav(sel) {
   if (sel.selectedIndex == -1) return;
   var opt = sel.options[sel.selectedIndex];
   if (opt && opt.value)
      location.href = opt.value;
}    
function topsyCallback(json) {
//script = document.createElement('script');
//script.type = 'text/javascript';
//script.src  = 'http://otter.topsy.com/trackbacks.js?callback=topsyCallback&url='+encodeURIComponent(url);
//document.getElementsByTagName('head')[0].appendChild(script);

    res = json.response;
    if ( !res.total ) {
        return false;
    }
    html = '（' + res.total + ' tweets）';
    if ( document.getElementById('topsy_counter') ) {
        document.getElementById('topsy_counter').innerHTML = html;
    }
    html = '<ul style="list-style:none;margin:0 0 5px 0;padding:0;">';
    for ( var i=0; i<res.list.length; i++ ) {
        tweet     = res.list[i];
        thumb     = tweet.author.photo_url.replace(/(normal)\.([a-z]{3,4})$/i,'mini.$2');
        author_id = tweet.author.url.replace('http://twitter.com/','');
        html
            += '<li style="margin:0;padding:1px;font:11px/16px sans-serif;color:#333;white-space:pre;overflow:hidden;">'
            +  '<a href="'+tweet.author.url+'" target="_blank">'
            +  '<img src="'+thumb+'" alt="'+tweet.author.name+'" style="border:0;vertical-align:middle;width:24px;height:24px;" />'
            +  '</a> '
            +  '<a href="'+tweet.author.url+'" target="_blank" style="color:#0084B4;">'
            +  author_id
            +  '</a> '
            +  tweet.content.replace(/(\r\n|\r|\n)/g,'')
            +  '</li>';
    }
    html += '</ul>';
    if ( res.total > 10 ) {
        html
            += '<div>'
            +  '<a href="'+res.topsy_trackback_url+'" target="_blank" style="display:inline-block;margin:0;padding:5px;font:14px/16px sans-serif;color:#0084B4;text-decoration:none;border:1px solid #CCC;background:#EEE;-moz-border-radius:5px;-webkit-border-radius:5px;">'
            +  'もっと読む'
            +  '</a>'
            +  '</div>';
    }
    if ( document.getElementById('topsy_trackbacks') ) {
        document.getElementById('topsy_trackbacks').innerHTML = html;
    }
}




function get_controll(method,q,return_id){
	$("#"+return_id).text("Loading.....");
	$.ajax({
		url: "word_controll.pl",
		type: "get",
		data: ({q : q,method:method}),
	    success : function(date){

			$("#"+return_id).html(date);


	    },
	    error : function(){
	        alert('error');
	    }
	});

}


function setSid(){
	var cnt  = 0 ;
	var text = '@mekutter_post '
	$('.sid').each(function(){
		if( $(this).attr('checked')) {
			text += String(this.value) + " ";
			cnt++ ;
		}
	});

	if(text.length > 140){
		alert("140文字を超えました。何回かに分けてpostしてください。");
	}else{
		if(cnt > 0){
			text += " ";
			$("#to_mekutter").removeAttr("disabled");
		}else{
			text = "チェックを1つ以上付けてください。";
			$("#to_mekutter").attr("disabled", "disabled");

		}
		$('#status_text').val(text);
	}
	return;
}
function next_time_line(next){

	var user  = $("#disped_user").val();
	
	$("#screen_name").val(user);
	$("#set_page").val(next);
	getTimeLine();

	return;
}
function follow_off(user){
 	$("#tofollow").empty();
 	$.ajax({
	  type: "GET",
	  url: "follow_function.pl",
      data: {user: user , action: "off" },
	  success: function(html){
			$("#tofollow").html(html);
	  },
	  error:function(html){
			$("#tofollow").html("エラーが発生しました。ページを更新してみてください。ごめんなさい。");
	  },
	});
}
function follow_on(user){
 	$("#tofollow").empty();
 	$.ajax({
	  type: "GET",
	  url: "follow_function.pl",
      data: {user: user , action: "on" },
	  success: function(html){
			$("#tofollow").html(html);
	  },
	  error:function(html){
			$("#tofollow").html("エラーが発生しました。ページを更新してみてください。ごめんなさい。");
	  },
	});
}



function reGsearch(obj){
		var search_player = obj.innerHTML ;
		if (search_player == "") return;
	    document.getElementById("q_for_google").value = document.getElementById("q_org").value +" "+ search_player;

		GoogleAjaxOnLoad3();

		return;
}



function follow_off(user_id,screen_name){
 	$("#tofollow").html("Loading.....");
 	$.ajax({
	  type: "GET",
	  url: "follow_function.pl",
      data: {user_id: user_id , action: "off" ,screen_name : screen_name},
	  success: function(html){
			$("#tofollow").html(html);
	  },
	  error:function(html){
			$("#tofollow").html("エラーが発生しました。ページを更新してみてください。ごめんなさい。");
	  },
	});
}
function follow_on(user_id,screen_name){
 	$("#tofollow").html("Loading.....");
 	$.ajax({
	  type: "GET",
	  url: "follow_function.pl",
      data: {user_id: user_id , action: "on",screen_name:screen_name },
	  success: function(html){
			$("#tofollow").html(html);
	  },
	  error:function(html){
			$("#tofollow").html("エラーが発生しました。ページを更新してみてください。ごめんなさい。");
	  },
	});
}
function postStatus(){
	$("#res_status").html('<img src="/img/loading.gif">');
	var text = $("#tweetpage_area").val();
	var initweet  = $("#initweet").val();
	var pos  = $("#pos").val();
 	$.ajax({
	  type: "GET",
	  url: "/post.php",
      data: {text: text , pos: pos },
	  success: function(html){
			$("#res_status").html(html);
		    $("#tweetpage_area").val(initweet);

	  },
	  error:function(html){
			$("#res_status").html("エラーが発生しました。ページを更新してみてください。ごめんなさい。");
	  },
	});

}
function TwitterSearch(disp_cont) {

	$("#tweets").html('<img src="/img/loading.gif">');
	var query = $("#pos").val() ;
					query = query.replace(/X$/gi, ""); //なぜかXがあると検索がうまくいかないのでとってしまう

	var turl = "http://search.twitter.com/search.json?rpp=50&q=" + encodeURIComponent(query) ;
//alert(turl);
	$.ajax({   
        type: 'GET',
	    url : turl ,
		dataType: 'jsonp',
	    success: function(data) {
	      	$("#topsy_result").empty();
			var html = "" ;
			var cnt = 0 ;
	      	$.each(data.results, function(i, item) {
			    if(cnt < disp_cont ){
					thumb     = item.profile_image_url.replace(/(normal)\.([a-z]{3,4})$/i,'mini.$2');
					retext = item.text.replace(/(\r\n|\r|\n)/g,'');
					retext = retext.replace(/(http:\/\/[\x21-\x7e]+)/gi, "<a  target=\"_blank\" href='$1'>$1</a>");
					xx = retext.match(/asin([B0-9][A-Z0-9]{9})/);
					asin = RegExp.$1 ;
					//image = "" ;
					//if(asin.length > 1 ){
					//	image = "http://images-jp.amazon.com/images/P/" + asin +".09.THUMBZZZ.jpg"; //小さい順に、THUMBZZZ,TZZZZZZZ,MZZZZZZZ,LZZZZZZZ
					//	image = '<a href="/'+asin+'"><img style="border:1px solid #ddd;padding:1px;" src="'+image+'"></a>';
					//}
			        html
			            += '<div class="ont" style="clear:both;">'
			            +  '<a href="http://twitter.com/'+item.from_user+'">'
			            +  '<img src="'+thumb+'" alt="'+item.from_user+'" style="float:left;border:0;vertical-align:bottom;width:40px;height:40px;padding:0 4px 0 0" />'
			            +  '</a> '
						//+  '<div style="float:right;">'+image+"</div>"
			            +  ' <a href="http://twitter.com/'+item.from_user+'" style="color:#0084B4;">'
			            +  item.from_user
			            +  '</a><br> '
			            +  retext
						+  ' <a href="http://twitter.com/' +item.from_user+ '/status/'+item.id+'" target="_blank" style="color:#0084B4;">'+item.created_at.substr(0,25)+'</a>'
			            +  '</div>'
			            + '<div   style="clear:both;border-bottom:1px solid #ddd;margin:4px 0;"></div>';
				}
				cnt++ ;
	      });

			if(html.length > 1 ){
				var tsuduki= 'http://search.twitter.com/search?q=' + encodeURIComponent(query) ;
		        html
		            += '<div>'
		            +  '<a href="'+tsuduki+'" target="_blank" style="display:inline-block;margin:0;padding:5px; sans-serif;color:#0084B4;text-decoration:none;border:1px solid #CCC;-moz-border-radius:5px;-webkit-border-radius:5px;">'
		            +  'Twitter Searchへ'
		            +  '</a>'
		            +  '</div>';
				$("#tweets").html(html);
			}else{
				$("#tweets").html("検索結果は0件でした。<div class=\"hiheight\"><br><br></div>");
			}
	    },
	    error : function(){
	        alert('error  ajax error');
	    }
	});

	return ;

}

    
    // Replace the following string with the AppId you received from the
    // Bing Developer Center.
    var AppId = "185AB419E15B97A2935D31DB319AA26A4E2E5EFF";
    
    // Bing API 2.2 code sample demonstrating the use of the
    // Translation SourceType over the JSON Protocol.
    function Search()
    {
        var requestStr = "http://api.bing.net/json.aspx?"
        
            // Common request fields (required)
            + "AppId=" + AppId
            + "&Query=Espero"
            + "&Sources=Translation"
            
            // Common request fields (optional)
            + "&Version=2.2"
            
           // SourceType-specific fields (required)
            + "&Translation.SourceLanguage=es"
            + "&Translation.TargetLanguage=en"

            // JSON-specific request fields (optional)
            + "&JsonType=callback"
            + "&JsonCallback=SearchCompleted";

         var requestScript = document.getElementById("searchCallback");
         requestScript.src = requestStr;
    }

    function SearchCompleted(response)
    {
        var errors = response.SearchResponse.Errors;
        if (errors != null)
        {
            // There are errors in the response. Display error details.
            DisplayErrors(errors);
        }
        else
        {
            // There were no errors in the response. Display the
            // Translation results.
            DisplayResults(response);
        }
    }

    function DisplayResults(response)
    {
        var output = document.getElementById("output");
        var resultsHeader = document.createElement("h4");
        var resultsList = document.createElement("ul");
        output.appendChild(resultsHeader);
        output.appendChild(resultsList);
    
        var results = response.SearchResponse.Translation.Results;
        
        // Display the results header.
        resultsHeader.innerHTML = "Bing API Version "
            + response.SearchResponse.Version
            + "<br />Translation results for "
            + response.SearchResponse.Query.SearchTerms
            + "<br />";
        
        // Display the Translation results.
        var resultsListItem = null;
        for (var i = 0; i < results.length; ++i)
        {
            resultsListItem = document.createElement("li");
            resultsList.appendChild(resultsListItem);
            resultsListItem.innerText = results[0].TranslatedTerm;
        }
    }
    
        function DisplayErrors(errors)
    {
        var output = document.getElementById("output");
        var errorsHeader = document.createElement("h4");
        var errorsList = document.createElement("ul");
        output.appendChild(errorsHeader);
        output.appendChild(errorsList);
        
        // Iterate over the list of errors and display error details.
        errorsHeader.innerHTML = "Errors:";
        var errorsListItem = null;
        for (var i = 0; i < errors.length; ++i)
        {
            errorsListItem = document.createElement("li");
            errorsList.appendChild(errorsListItem);
            errorsListItem.innerHTML = "";
            for (var errorDetail in errors[i])
            {
                errorsListItem.innerHTML += errorDetail
                    + ": "
                    + errors[i][errorDetail]
                    + "<br />";
            }
            
            errorsListItem.innerHTML += "<br />";
        }
    }
    


/*
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
(function($) {

	$.fn.charCount = function(options){
	  
		// default configuration properties
		var defaults = {	
			allowed: 140,		
			warning: 25,
			css: 'counter',
			counterElement: 'span',
			cssWarning: 'warning',
			cssExceeded: 'exceeded',
			counterText: ''
		}; 
			
		var options = $.extend(defaults, options); 
		
		function calculate(obj){
			var count = $(obj).val().length;
			var available = options.allowed - count;
			if(available <= options.warning && available >= 0){
				$(obj).next().addClass(options.cssWarning);
			} else {
				$(obj).next().removeClass(options.cssWarning);
			}
			if(available < 0){
				$(obj).next().addClass(options.cssExceeded);
			} else {
				$(obj).next().removeClass(options.cssExceeded);
			}
			$(obj).next().html(options.counterText + available);
		};
				
		this.each(function() {  			
			$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
			calculate(this);
			$(this).keyup(function(){calculate(this)});
			$(this).change(function(){calculate(this)});
		});
	  
	};

})(jQuery);



