

function setClassBtn() {
	$(".setButton img, .setButton input, ul#localNav li a img, div#pageTitle p a img,table.inputList td img, ul.stepFlow a img, div#homeNav a img, div#pointSummary a img, ul#secondNav a img").each(function() {
		$(this).addClass("btn");
	});
}

function setTableAddSpan() {
	$("table.viewDetail th, table.inputDetail th" ).each(function() {
	    var theading = jQuery(this).html();
    	jQuery(this).html("<span>" + theading + "</span>");
	});
}
function setTableFormAddMust() {
	$("table.inputDetail th").each(function() {
		var th_text = jQuery(this).html();
		th_text = th_text.replace(/（必須）/g, "<img src='/img/common/ic_must.gif' alt='必須' width='25' height='11' />");
		jQuery(this).html(th_text);
	});
}

function setCheckBoxAddClass() {
	$("table.inputList td  input[type=checkbox]").click(function() {
		jQuery(this).parent().parent().toggleClass('select');
	});
}



function initsetButtonImages() {
	var image_cache = new Object();
	//$("a img.btn,input[type=image].btn").not("[@src*='_o.'],[@src*='_d.']").each(function(i) {
	$("a img.btn, input:image").not("[@src*='_o.'],[@src*='_d.']").each(function(i) {
		$(this).hover(
			function() {
                            if (this.src.lastIndexOf('_o.') !== -1) {
                                return;
                            }
                            var dot = this.src.lastIndexOf('.');
                            this.src = this.src.substr(0, dot) + '_o' + this.src.substr(dot, 4);
                        },
			function() {
                            this.src = this.src.replace('_o.', '.');
                        }
		);
	});
}

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 popUpForSupportSite() {
	$(function(){
		$('a').each(function(){
			var support_site_pattern = /^(https?:\/\/[-a-zA-Z.]*)?\/support/;
			if (!(this.href.match(support_site_pattern))) {
				return;
			}
			$(this).click(function(){
				window.open(this.href, "support","width=780,height=600,menubar=yes,scrollbars=yes,resizable=yes");
				return false;
			});
		});
	});
}

function setCorner() {
	$('ul#localNav,div.formBox,div.aggregateBox,dl.colorSelectBox,div#messageFinish').corner("round");
}

// 職種をリセットする
function resetJobType() {
    var options, parsed;
    parsed = location.host.match(/^([a-z0-9-]+?\.)([a-z0-9-.]+)$/);
    options = {
        path: '/',
        expires: 1
    };
    if (parsed && parsed.length == 3) {
        options.domain = '.' + parsed[2];
    }

    $.cookie('CakeCookie[job_type]', '', options);
}

// 左上のサイトロゴをクリックした場合、職種をリセットする
function attachResetJobType() {
    $('div#header h1 a').click(resetJobType)
}


$(document).ready(setClassBtn);
$(document).ready(setTableAddSpan);
$(document).ready(setTableFormAddMust);
$(document).ready(initsetButtonImages);
$(document).ready(pageScroll);
//$(document).ready(setCorner);
$(document).ready(setCheckBoxAddClass);
$(document).ready(popUpForSupportSite);
$(document).ready(attachResetJobType);
