/* ポップアップの処理 */
$(document).ready(function(){
	$(".signUpPop a").hover(function() {
		$(this).next("em").stop(true, true).animate({opacity: "show", top: "40"}, "fast");
	}, 
	function() {
		$(this).next("em").animate({opacity: "hide", top: "35"}, "fast");
	});

	$(".mailmagazinePop1 span").mouseover(function() {
		tarTop = $(document).scrollTop();
		pos = $(this).position();
		$(this).next("em").css( { "top" : tarTop + 39, "left" : pos.left + 80 });
		$(this).next("em").stop(true, true).animate({opacity: "show", top: tarTop + 40}, "fast");
	}).mouseout(function(){
		$(this).next("em").animate({opacity: "hide", top: tarTop + 39}, "fast");
	});
	
	$(".mailmagazinePop2 span,.mailmagazinePop3 span").mouseover(function() {
		tarTop = $(document).scrollTop();
		pos = $(this).position().left - $(this).next("em").width() - 30;
		$(this).next("em").css( { "top" : tarTop + 39, "left" : pos });
		$(this).next("em").stop(true, true).animate({opacity: "show", top: tarTop + 40}, "fast");
	}).mouseout(function(){
		$(this).next("em").animate({opacity: "hide", top: tarTop + 39}, "fast");
	});
	
	
});




/*  画像化したチェックボックスの処理　*/
$(function(){
	$("p input.serviceCheck").parent().attr("class","unchecked");
	$("p input.serviceCheck:checked").parent().attr("class","checked");
	$(".checked, .unchecked").click(function(){
		$(this).toggleClass("unchecked").toggleClass("checked")
		if($(this).attr("class")=="unchecked"){
			$(this).children("input").attr("checked","");
		}else{
			$(this).children("input").attr("checked","checked");
		}
	});
});

/* 「もっと詳細を見る」 */

$(function(){
	$(".switch").click(function(){
		tarParent = $(this).parent();
		tarTable = tarParent.next(".append").children("table");
		if(tarTable.css("display") == "none"){
			$(this).html("<img src='../img_cmn/closeDetailBtn.gif'/>")
			tarTable.show("200");
		}else{
			$(this).html("<img src='../img_cmn/openDetailBtn.gif'/>")
			tarTable.hide("200r");
		}
	});
});

/* 前付き、後付き、無しのラジオボタンによって、セレクトボックスの位置移動 */
$(function(){
	$("#backPrefix").click(function(){
		var tarObj = $("#companyPrefixSelect");
		tarObj.insertAfter("#companyTextArea").show();
	});
	$("#frontPrefix").click(function(){
		var tarObj = $("#companyPrefixSelect");
		tarObj.insertBefore("#companyTextArea").show();
	});
	$("#noPrefix").click(function(){
		var tarObj = $("#companyPrefixSelect");
		tarObj.hide();
	});
});

/* 産業分類 */
$(function(){
	//onloadのタイミングで、input:hiddenに格納されているvalueから、現在選択されている産業の項目にテキストをいれる。
	for(i=1;i<4;i++){
		var tarVal = $("#hiddenIndustry"+ i).val();
		var tarText = tarVal.replace(/.*\./,"");
		$("#industry" + i + " span").append(tarText);
		
	};
	//さらにonloadのタイミングでチェックされているcheckboxを見て、それぞれの大カテゴリーにあたるtdを黄色くする。
	$(".businessUl li input:checked").each(function(){
		var tarClass = $(this).attr("class");
		var tarTd = $("#cat"+ tarClass).parent("td");
		tarTd.css("background","yellow");
	});
	
	//大カテゴリークリック時の動作
	$(".industryCatTbl a").click(function(){
		$("#selectIndustryDetail").fadeIn("fast");
		$(".businessUl li").css("display","none");
		var tarId = $(this).attr("id");
		tarId = tarId.replace("cat","");
		$(".businessUl li input." + tarId ).parents("li").css("display","block");
	})
	
	//小カテゴリーにcheckが入った時に走る関数
	function checkFunc(a,b,c){
		var tarTd = $("#cat"+b).parent("td");
		var tarText = a.replace(/.*\./,"");
		tarTd.css("background","yellow");
		$("#industry" + c + " span").append(tarText);
		$("#hiddenIndustry" + c).val(a);
	};
	
	//小カテゴリークリック時の動作
	$(".businessUl li input").click(function(){
		
		
		//checkしたとき
		if($(this).is(":checked")){
			var tarVal = $(this).val();
			var tarText = tarVal.replace(/.*\./,"");
			//同じ産業は選択できないようにする。
			for(i=1;i<4;i++){
				var selectedVal = $("#hiddenIndustry"+ i).val();
				selectedVal = selectedVal.replace(/.*\./,"");
				if(tarText == selectedVal){
					alert("その産業はすでに選択されています。")
					$(this).get(0).checked = false;
					return false;
				}
			};
			
			if( $("#industry1").text() == "" ){

				checkFunc(tarVal , $(this).attr("class") , "1");

			}else if( $("#industry2").text() == "" ){

				checkFunc(tarVal , $(this).attr("class") , "2");

			}else if( $("#industry3").text() == "" ){

				checkFunc(tarVal , $(this).attr("class") , "3");

			}else{
				alert("産業分類は三つまでしか設定できません。")
				$(this).get(0).checked = false;
			}
			
		//check外したとき
		}else{
			var tarIndustry = $(this).val();
			var tarText = tarIndustry.replace(/.*\./,"");
			var tarClass = $(this).attr("class");
			if($("."+ tarClass + ":checked").length == 0){
		
				var tarTd =	$("#cat"+ tarClass ).parent("td");
				tarTd.css("background","white");
			}
			$("#selectedTbl td span:contains(" + tarText + ")" ).text("");
			$("#selectedTbl td input[value=" + tarIndustry + "]").val("");
			
		
		}
	})
});

$(function(){
	$("#competiter li:gt(4)").filter(function(){
		return $(this).children("input").val() == ""
	}).css("display","none");
	$("#competiter li:gt(3) input").focus(function(){
		var tarIndex = $("#competiter li input").index(this);
		tarIndex++;
		$("#competiter li:eq(" + tarIndex +")").fadeIn("fast");
		$(".suggest:eq(" + tarIndex + ")").suggest("http://static.astamuse.com/js/companyname.php?jsoncallback=?", { delay: "1000" });
	});
});







