/*****************************
 * @file: WS.step1.js
 *****************************/
$(function()
{
	var locked = false;

	var bgOff = "bgOff";
	var bgHilight = "bgHilight";

	// navi
	$('#navi_step1').addClass(bgHilight);

	// fm
	var $fm = $('#fm');
	$fm.attr('target', 'fr');

	// iframe
	var o = $(document.createElement('iframe'));
	o.attr({
		src: 'javascript:false',
		id: 'fr',
		name: 'fr',
		width: 0,
		height: 0
	}).hide();
	$('body').append(o);

	// ipt
	var $ipt = {
		type: $('input[@name="type"]'),
		str: $('input[@name="str"]'),
		img: $('input[@name="img"]')
	};

	$ipt['type'].click(function(){
		var v = $(this).val();
		if (v == 1) {
			$ipt['str'].removeClass(bgOff).attr('disabled', false);
			$ipt['img'].addClass(bgOff).attr('disabled', true);
		} else {
			$ipt['str'].addClass(bgOff).attr('disabled', true);
			$ipt['img'].removeClass(bgOff).attr('disabled', false);
		}
	});

	// submit
	$fm.submit(function(){
		$(this).blur();
		if (!locked) {
			locked = true;
			try {
				$fm.ajaxSubmit({
					success: _response
				});
			} catch(e) {
				alert("送信エラーです");
				locked = false;
			}
		}
		return false;
	});

	// response
	function _response(res, stat)
	{
		locked = false;
		if (res.indexOf('step2') > 0) {
			window.location.href = res;
		} else {
			alert(res);
		}
	}
});

