
/* browser distinction
---------------------------------------------------------------- */
$(function(){
	if(!$.support.checkOn && !$.support.checkClone){
		$("body").addClass("android_iphone_ipad");
	}else if(!$.support.checkOn && $.support.checkClone){
		if(navigator.userAgent.match((/Chrome\/([\.\d]+)/))){
			$("body").addClass("chrome");
		}else $("body").addClass("safari");
	}else if($.support.checkOn && $.support.htmlSerialize && window.globalStorage){
		$("body").addClass("firefox");
	}else if($.support.checkOn && $.support.htmlSerialize && !window.globalStorage){
		$("body").addClass("opera");
	}else if(!$.support.htmlSerialize && $.support.scriptEval){
		$("body").addClass("ie9");
	}else if(!$.support.opacity){
		if(!$.support.style){
			if(typeof document.documentElement.style.maxHeight != "undefined"){
				$("body").addClass("ie7");
			}else $("body").addClass("ie6");
		}else $("body").addClass("ie8");
	}else $("body").addClass("other");
	if(navigator.userAgent.toLowerCase().indexOf("win") != -1){
		$("body").addClass("win");
	}else if(navigator.userAgent.toLowerCase().indexOf("mac") != -1){
		$("body").addClass("mac");
	}else $("body").addClass("etc");
});

/* link to external site
---------------------------------------------------------------- */
$(function(){
	$("a[href*='rad.php']").attr("target","_blank").attr("title","Open new window");
	$("a[href*='redirect.php']").attr("target","_blank").attr("title","Open new window");
	$("a[href^=http]").not("[href*='raksul.com/']").attr("target","_blank").attr("title","Open new window");
	$("a[rel$='_blank']").attr("target","_blank").attr("title","Open new window");
	$("a[href$='.pdf']").attr("target","_blank").attr("title","PDF(Open new window)");
});

/* active navigation
---------------------------------------------------------------- */
$(function(){
	if(location.pathname != "/"){
		$("#gnavi li a[href*='/" + location.pathname.split('/')[1] + "']").addClass("active");
	}// else $("#gnavi li a:eq(0)").addClass("active"); 20110513 YT Delete  -> [backlog RKS-2]
});



/* addclass priority and indexs
---------------------------------------------------------------- */
$(function(){
	$("ul.product.top li:nth-child(3n)").addClass("third");
	$("ul.product.second li:nth-child(5n)").addClass("fifth");
	$("#fnavi dd.product li:nth-child(3n)").addClass("third");
});

// price table
$(function(){
	$("div.search_detail table tr:nth-child(6n+1)").addClass("midth");
	$("div.search_detail table tr:eq(0)").removeClass("midth");
	$("div.search_detail table tr:last").removeClass("midth");
	$("div.search_detail table tr:last").find("td:last").addClass("last");
	$("div.search_detail table tr").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
});

// advertisement
$(function(){
	$("div.content_head ul").each(function(index, elem){
		$("li:last", $(elem)).addClass("last");
	});
	$("div.selecter ul").each(function(index, elem){
		$("li:last", $(elem)).addClass("last");
	});
	$("ul.ad").each(function(index, elem){
		$("li:last", $(elem)).addClass("last");
	});
	$("div.company_profile ul.article").each(function(index, elem){
		$("li:last", $(elem)).addClass("last");
	});
});

$(function(){
	$("div.meta>ul>li:eq(0)").addClass("first");
	$("div.meta>ul>li:eq(1)").addClass("second");
	$("div.meta>ul>li:eq(2)").addClass("third");
	$("div.meta>ul>li:eq(3)").addClass("fourth");
	$("div.meta>ul>li:eq(4)").addClass("fifth");
	$("form.companysearch_form>div:eq(0)").addClass("first");
	$("form.companysearch_form>div:eq(1)").addClass("second");
	$("form.pickup>div.ttl_snow:eq(0)").addClass("first");
});

$(function(){
	$("form.product_search fieldset:even").addClass("beige");
	$("form.product_research fieldset:even").addClass("beige");
	$("form.contact fieldset:even").addClass("beige");
	$("form.regist fieldset:even").addClass("beige");
	$("div.present div.condition ul:even").addClass("beige");
});

/* addclass form object
---------------------------------------------------------------- */
$(function(){
	$("input[type=text]").addClass("text");
	$("input[type=radio]").addClass("radio");
	$("input[type=checkbox]").addClass("checkbox");
	$("input[type=submit]").addClass("submit");
	$("input[type=reset]").addClass("reset");
	$("button[type=submit]").addClass("submit");
	$("button[type=reset]").addClass("reset");
	$("button").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
});

/* addclass areamap action to background rollover
---------------------------------------------------------------- */
$(function(){
	$("div.areamapbox ul").hover(function(){
		$(this).addClass("over");
		$(this).find("li a").removeClass("active");
	},function(){
		$(this).removeClass("over");
	});
	$("div.areamapbox ul li").click(function(){
		$(this).parent().removeClass("over");
		$(this).find("a").addClass("active");
	});
});

/* ie6 bugfix elements
---------------------------------------------------------------- */
$(function(){
	if(location.pathname.match(/^\/search\/.+/g)){
		$("h1").wrap('<span class="content"></span>');
	}
});

/* contact form
---------------------------------------------------------------- */
$(function(){
	$("form.contact input[type=text]").keypress(function(e){
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			$("button[type=submit] .default").click();
			return false;
		}
	});
	if(location.pathname == "/contact/"){
		$("form.contact").validate({
			rules:{
				"name":{ required:true, minlength:2 },
				"tel":{ required:true, minlength:10, phone:true },
				"email":{ required:true, email:true },
				"email_confirm":{ required:true, email:true, equalTo:"#email" },
				"comment":{ required:true, minlength:20 },
				"agree":{ required:true }
			},
			messages:{
				"name":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"tel":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"email":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。" },
				"email_confirm":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。", equalTo:"メールアドレスが一致していません。" },
				"comment":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"agree":{ required:"プライバシーポリシーにご同意ください。" }
			}
		});
		$("form.contact dd:last").addClass("lbl").prepend("<label for=\"comment\" generated=\"true\" class=\"error\"></label>");
		$("form.contact div.privacy_confirm label").after("<label for=\"agree\" generated=\"true\" class=\"error\"></label>");
		$("form.contact input:text").each(function(index){
			if($(this).val().match(/^例）/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.contact textarea").each(function(index){
			if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.contact button").click(function(){
			$("form.contact input:text").each(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
			$("form.contact textarea").each(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
	}
});


/* sample_address/.php form
---------------------------------------------------------------- */
$(function(){
	$("form.contact input[type=text]").keypress(function(e){
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			$("button[type=submit] .default").click();
			return false;
		}
	});
	if(location.pathname == "/sample/"){ /* 2011 01 25 利根川修正 */
		$("form.contact").validate({
			rules:{
				"name":{ required:true, minlength:2 },
				"tel":{ required:true, minlength:10 },
				"email":{ required:true, email:true },
				"email_confirm":{ required:true, email:true, equalTo:"#email" },
				"comment":{ required:true, minlength:20 },
				"agree":{ required:true },
				"experience":{ required:true }
			},
			messages:{
				"name":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"tel":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"email":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。" },
				"email_confirm":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。", equalTo:"メールアドレスが一致していません。" },
				"comment":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"agree":{ required:"プライバシーポリシーにご同意ください。" },
				"experience":{ required:"印刷通販利用経験をご回答ください。" }
			}
		});
		$("form.contact dd:last").addClass("lbl").prepend("<label for=\"comment\" generated=\"true\" class=\"error\"></label>");
		$("form.contact div.privacy_confirm label").after("<label for=\"agree\" generated=\"true\" class=\"error\"></label>");
		$("form.contact input:text").each(function(index){
			if($(this).val().match(/^例）/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.contact textarea").each(function(index){
			if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.contact button").click(function(){
			$("form.contact input:text").each(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
			$("form.contact textarea").each(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
	}
});


/* sample form
---------------------------------------------------------------- */
$(function(){
	$("form.sample input[type=text]").keypress(function(e){
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			$("button[type=submit] .default").click();
			return false;
		}
	});
	if(location.pathname == "/sample/"){
		$("form.sample").validate({
			rules:{
				"agree":{ required:true }
			},
			messages:{
				"agree":{ required:"プライバシーポリシーにご同意ください。" }
			}
		});
		$("form.sample dd:last").addClass("lbl").prepend("<label for=\"comment\" generated=\"true\" class=\"error\"></label>");
		$("form.sample div.privacy_confirm label").after("<label for=\"agree\" generated=\"true\" class=\"error\"></label>");
		$("form.sample input:text").each(function(index){
			if($(this).val().match(/^例）/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.sample textarea").each(function(index){
			if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.sample button").click(function(){
			$("form.sample input:text").each(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
			$("form.sample textarea").each(function(){
				if($(this).val().match(/^こちらにお問い合わせ内容をご入力ください/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
	}
});

/* regist form
---------------------------------------------------------------- */
$(function(){
	$("form.regist input[type=text]").keypress(function(e){
		if((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)){
			$("button[type=submit] .default").click();
			return false;
		}
	});
//u	if(location.pathname == "/companysearch/registform"){
	var mode="input[name=mode]";
	if($(mode).val() != "thanks" && location.pathname == "/companysearch/registform" ){ //20110511利根川修正
		$("form.regist").validate({
			rules:{
				"company_name":{ required:true },
				"person_name":{ required:true, minlength:2 },
				"addr_zip":{ required:true, minlength:7 },
				"prefecture":{ required:true },
				"addr_detail":{ required:true },
				"tel":{ required:true, minlength:10 },
				"email":{ required:true, email:true },
				"email_confirm":{ required:true, email:true, equalTo:"#email" },
				"copy":{ maxlength:75 },
				"work":{ maxlength:500 },
				"machine_press":{ maxlength:250 },
				"machine_prepress":{ maxlength:125 },
				"machine_postpress":{ maxlength:125 },
				"agree":{ required:true }
			},
			messages:{
				"company_name":{ required:"入力内容をご確認ください。" },
				"person_name":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"addr_zip":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"prefecture":{ required:"都道府県を選択してください。" },
				"addr_detail":{ required:"入力内容をご確認ください。" },
				"tel":{ required:"入力内容をご確認ください。", minlength:"入力内容をご確認ください。" },
				"email":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。" },
				"email_confirm":{ required:"入力内容をご確認ください。", email:"メールアドレスに誤りがあります。", equalTo:"メールアドレスが一致していません。" },
				"copy":{ maxlength:"最大文字数は75文字までです。" },
				"work":{ maxlength:"最大文字数は500文字までです。" },
				"machine_press":{ maxlength:"最大文字数は250文字までです。" },
				"machine_prepress":{ maxlength:"最大文字数は125文字までです。" },
				"machine_postpress":{ maxlength:"最大文字数は125文字までです。" },
				"agree":{ required:"プライバシーポリシーにご同意ください。" }
			}
		});
		$("form.regist label[for='copy']").parent().append('<label for="copy" generated="true" class="error"></label>');
		$("form.regist label[for='work']").parent().append('<label for="work" generated="true" class="error"></label>');
		$("form.regist label[for='machine_press']").parent().append('<label for="machine_press" generated="true" class="error"></label>');
		$("form.regist label[for='machine_prepress']").parent().append('<label for="machine_prepress" generated="true" class="error"></label>');
		$("form.regist label[for='machine_postpress']").parent().append('<label for="machine_postpress" generated="true" class="error"></label>');
//		$("form.regist div.privacy_confirm label").after('<label for="agree" generated="true" class="error"></label>');
		$("form.regist input:text").each(function(index){
			if($(this).val().match(/^例）/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.regist textarea").each(function(index){
			if($(this).val().match(/^例）/)){
				$(this).addClass("ex");
			}
			$(this).focus(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
		$("form.regist button").click(function(){
			$("form.regist input:text").each(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
			$("form.regist textarea").each(function(){
				if($(this).val().match(/^例）/)){
					$(this).val("").removeClass("ex");
				}
			});
		});
	}
});



$(function(){
	// ラジオボタン処理
	// hover 処理
	$('label').hover(
		function(){
			$(this).addClass('hover');
		},
		function(){
			$(this).removeClass('hover');
		}
	);

	// select 処理
	$('label :radio').change(function(){
		var name = $(this).attr('name');
		$('input[name=' + name + ']').each(function(){
			if ($(this).attr('checked')) {
				$(this).parents('label').addClass('selected');
			} else {
				$(this).parents('label').removeClass('selected');
			}
		});
	});	

	// デフォルト選択処理
	$('label :radio').each(function(){
		if ($(this).attr('checked')) {
			$(this).parents('label').addClass('selected');
		} else {
			$(this).parents('label').removeClass('selected');
		}
	});
});

/* keywords magazine icon
---------------------------------------------------------------- */
$(function(){
	$("table.keywords_magazine td").each(function(index){
		$(this).find("a").hover(function(){
			$("table.keywords_magazine td").eq(index).find("a").addClass("hover");
		},function(){
			$("table.keywords_magazine td").eq(index).find("a").removeClass("hover");
		});
	});
});

/* clouw words hover
---------------------------------------------------------------- */
$(function(){
	$("p.cloud_words span").each(function(index){
		$(this).find("a").hover(function(){
			$("p.cloud_words span").eq(index).find("a").addClass("hover");
		},function(){
			$("p.cloud_words span").eq(index).find("a").removeClass("hover");
		});
	});
});


/* companysearch hover
---------------------------------------------------------------- */
$(function(){
	$("div.article ul li").each(function(index){
		$(this).find("a").hover(function(){
			$("div.article ul li").eq(index).find("a").addClass("hover");
		},function(){
			$("div.article ul li").eq(index).find("a").removeClass("hover");
		});
	});
});

