
/**********************************************************
pageScroll
--------
ページをスムーズにスクロール（ href属性値が#で始まるものが対象 ）
@param / @return
**********************************************************/
function pageScroll() {
	$("a[href*=#]").click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 500);
				return false;
			}
		}
	});
}

function change_images(image)
{
	$('#main_image').attr("src",image);
}

function favorite(e,pid,rid,m)
{
	var $this = $(e);
	$.getJSON ("/toc_api/add/favorite?id="+pid+"_"+rid+"&mode="+m, function (data)
	{
		if(m=='list'){
			$('#fav_'+pid+"_"+rid+"_f").hide();
		}else if(m=="map"){
		}else if(m=="res"){
			$this.html (data.action);
			$("p#btn_class_"+rid).removeClass("addBtn");
			$("p#btn_class_"+rid).removeClass("dllBtn");
			if(data.klass=="remove"){
				$("p#btn_class_"+rid).addClass("dllBtn");
			}else{
				$("p#btn_class_"+rid).addClass("addBtn");
			}
		}else{
			$this.html (data.action);
		}
		$("#fav_count").text(data.count);
		$("#fav_count_2").text(data.count);
	});
}

function clear_history(){
	var $element = $('#historyBox');
	if(confirm("本当に閲覧履歴を削除しますか？")){
		$.ajax({
		  type: 'get',
		  url: '/toc_api/clear/history',
		  dataType: 'html',
		  success: function(data, status) {
				$element.hide();
		  },
		  error: function(xhr, status, e) {
		  }
		});
			
	}
	return false;
}
 
function goSodan(form)
{
	var sodan_email = $('#sodan_email').val();
	var sodan_text = $('#sodan_text').val();

	if(!sodan_email.match(/.+@.+\..+/)){
		alert('メールアドレスを正しく入力してください。');
	}else if(!sodan_text.match(/\S/g)){
		alert('ご相談内容を入力してください。');
	}else{
		$.ajax({data:$.param($(form).serializeArray()), success:function(request){$('#new_goiken').html(request);}, type:'post', url:'/toc_api/goiken'});
	}
	return false;
}

$(function(){
	pageScroll();
})
