// JavaScript Document
 /*@cc_on _d=document;eval('var document=_d')@*/
 
document.write('\
	<script type="text/javascript" src="/global_src/js/jquery-1.4.2.min.js"></script>\
	<script type="text/javascript" src="/global_src/js/swfobject.js"></script>\
	<script type="text/javascript" src="/global_src/js/func.js"></script>\
');



var formSet = (function(){
	var that;
	var doc;
	// -----------------------
	// variables
	// -----------------------
	var preCheck = false;
	var
		cause = "#cause_set";
		name = "#input_name",
		hurigana = "#input_hurigana",
		type = "#type_set",
		ogn = "#input_ogn",
		sec = "#input_sec",
		zip = "#input_zip",
		adr1 = "#input_adr1",
		adr2 = "#input_adr2",
		tel = "#input_tel",
		mobi = "#input_mobi",
		fax = "#input_fax",
		mail = "#input_mail",
		info = "#info_set",
		contact = "#contact_set",
		comment = "#comment_set";

	//----------------------------------------------------------------
	//  modal モーダル生成
	//----------------------------------------------------------------
	var modal;
	var _modal = function(){
		var that;
		// init --------------------------------
		function _init(){
			$('body').prepend('<div id="modal"></div>');
			modal = $('#modal');
			modal.css({
				display:'none',
				background:'#000',
				opacity:.5,
				color:'#FFF',
				position:'absolute',
				left:'0',
				margin:'0',
				width:doc.width()+'px',
				height:doc.height()+'px',
				zIndex:100
			});
			modal.bind('click',function(){del()});
			resize(that);
			del(that);
			};
			return {
				//---------------------------------------
				init:function(){that = this;_init()},
				//---------------------------------------
				resize:function(){
					modal.css({
						width:doc.width()+'px',
						height:doc.height()+'px'
					});
				},
				//---------------------------------------
				del:function(){
					modal.css('display','none');
				},
				//---------------------------------------
				disp:function(){
					modal.css('display','block');
				}
				//---------------------------------------
			}
		}();

	//----------------------------------------------------------------
	//  area 地域リスト生成
	//----------------------------------------------------------------
	var area;
	var _area = function(){
		var that;
		var handlr = "#input_adr1";
		var areaID = '#area_select';
		var data ='\
		<dl id="area_select">\
			<dt>北海道</dt>\
			<dd><ul><li>北海道</li></ul></dd>\
			<dt>東北</dt>\
			<dd><ul><li>青森県</li><li>岩手県</li><li>宮城県</li><li>秋田県</li><li>山形県</li><li>福島県</li></ul></dd>\
			<dt>関東</dt>\
			<dd><ul><li>東京都</li><li>茨城県</li><li>栃木県</li><li>群馬県</li><li>埼玉県</li><li>千葉県</li><li>神奈川県</li></ul></dd>\
			<dt>北陸</dt>\
			<dd><ul><li>富山県</li><li>石川県</li><li>福井県</li></ul></dd>\
			<dt>甲信越</dt>\
			<dd><ul><li>新潟県</li><li>山梨県</li><li>長野県</li></ul></dd>\
			<dt>東海</dt>\
			<dd><ul><li>岐阜県</li><li>静岡県</li><li>愛知県</li><li>三重県</li></ul></dd>\
			<dt>関西</dt>\
			<dd><ul><li>滋賀県</li><li>京都府</li><li>大阪府</li><li>兵庫県</li><li>奈良県</li><li>和歌山県</li></ul></dd>\
			<dt>中四国</dt>\
			<dd><ul><li>鳥取県</li><li>島根県</li><li>岡山県</li><li>広島県</li><li>山口県</li><li>徳島県</li><li>香川県</li><li>愛媛県</li><li>高知県</li></ul></dd>\
			<dt>九州</dt>\
			<dd><ul><li>福岡県</li><li>佐賀県</li><li>長崎県</li><li>熊本県</li><li>大分県</li><li>宮崎県</li><li>鹿児島県</li></ul></dd>\
			<dt>沖縄</dt>\
			<dd><ul><li>沖縄県</li></ul></dd>\
		</dl>\
	';
		// init --------------------------------
		function _init(){
			$('body').prepend(data);
			area_set();
			handler_set();
			del(that);
		};
		// -------------------------------------
		function area_set(){
			area = $(areaID);
			$(areaID+' dd:last-child').css('background','none');
			$(areaID+' dd li').bind('click',function(){
				$(handlr).attr('value',$(this).text());
				del();
			});
		};
		// -------------------------------------
		function handler_set(){
			$(handlr).bind('focus',function(){
				_modal.disp();
				var offsetY = $(window).height() / 2 + $(window).scrollTop();
				var offsetX = $(window).width() / 2 + $(window).scrollLeft();
				var _top = offsetY - area.height() / 2;
				var _left = offsetX - area.width() / 2;
				area
					.css({display:'block',opacity:0,top:_top+'px',left:_left+'px'})
					.animate({opacity:1},300);
			});
		};
		// instance
		return {
			//--------------------------------------------
			init:function(){that = this;_init()},
			//--------------------------------------------
			del:function(){
				area.css('display','none');
			}
		}
	}();
	
	//----------------------------------------------------------------
	//  cancel　キャンセルボタンのメソッド
	//----------------------------------------------------------------
	var cancel;
	var _cancel = function(){
		var that;
		var cancelID = '#cancel';
		var handlr = "#cancel_btn";
		var data = '\
			<div id="cancel">\
				<p>内容を削除します。よろしいですか？</p>\
				<div><button type="button" class="yes">はい</button><button type="button" class="no">いいえ</button></div>\
			</div>\
		';
		function _init(){
			$('body').prepend(data);
			cancel = $(cancelID);
			cancel_button_set();
			del(that);
		};
		function cancel_button_set(){
			$(handlr).bind('click',function(){
				_modal.disp();
				var offsetY = $(window).height() / 2 + $(window).scrollTop();
				var offsetX = $(window).width() / 2 + $(window).scrollLeft();
				var _top = offsetY - cancel.height() / 2;
				var _left = offsetX - cancel.width() / 2;
				cancel
					.css({display:'block',opacity:0,top:_top+'px',left:_left+'px'})
					.animate({opacity:1},300);
			});
			$(cancelID+' .yes').bind('click',function(){
				$("#content_02 input[type='text']").val("");
				$("#content_02 textarea").val("");
				$("#content_02 .err").css("display","none");
				del();
			});
			$(cancelID+' .no').bind('click',function(){
				del();
			});
		};
		// instance
		return {
			//--------------------------------------------
			init:function(){that = this;_init()},
			//--------------------------------------------
			del:function(){
				cancel.css('display','none');
			}
		}
	}();
	
	//----------------------------------------------------------------
	//  check　リアルタイムで確認　＆　チェックメソッドを提供
	//----------------------------------------------------------------
	var _check = function(){
		var that;
		
		// methods -----------------------------
		var _twoByte = function(){
			var str = '';
			return function(t){
				str = $(t).val();
				if (str === '') return null;
				var filter = str.match(/[0-9a-zA-Z\+\-\/\*\,\. ]+/g);
				if(str != filter) return true;
				if(str == filter) return false;
			}
		}();
		var _oneByte = function(){
			var str = '';
			return function(t){
				str = $(t).val();
				if (str === '') return null;
				var filter = str.match(/[0-9a-zA-Z\+\-\@\/\*\,\. ]+/g);
				if(str != filter) return false;
				if(str == filter) return true;
			}
		}();
		var _mailAddress = function(){
			var str = '';
			var ptn = /.+@.+\..+/;
			return function(t){
				var byte = _oneByte(t);
				if(byte == null) return null;
				if(byte == false) return "byteError";
				str = $(t).val();
				if(str === '') return null;
				if(!str.match(ptn)) return false;
				return true;
			}
		}();
		var _choiceRadio = function(t){
			var ta = $(t+' input[type="radio"]:checked').val(); 
			return (typeof ta === 'undefined')? false : true;
		};

		//  totalCheck -----------------------------
		function _totalCheck(){
			if(!_check.choiceRadio(cause)) $(cause+' .err').css("display","block");
			if(!_check.choiceRadio(type)) $(type+' .err').css("display","block");
			if(!_check.choiceRadio(contact)) $(contact+' .err').css("display","block");
			if($(name).val() === '') $(name).nextAll('.err02').css("display","block");
			if($(hurigana).val() === '') $(hurigana).nextAll('.err02').css("display","block");
			if($(mail).val() === '') $(mail).nextAll('.err03').css("display","block");
			if($(comment+" textarea").val() == '') $(comment+' .err01').css("display","block");
			return function(){
				var target = $('#content_02 .err');
				var num = target.length;
				for(var i=0; i<num; i++){
					if(target.eq(i).css("display") === 'block') return false;
				};
				return true;
			}();
		};

		function _init(){
			// always check handlers
			$(name).bind('blur',function(){
				var bln = _twoByte($(this));
				if(bln === null){
					$(this).nextAll().css("display","none");
					$(this).nextAll('.err02').css("display","block");
				}else if(!bln){
					$(this).nextAll().css("display","none");
					$(this).nextAll('.err01').css("display","block");
				}else{
					$(this).nextAll().css("display","none");
				}
			});
			$(hurigana).bind('blur',function(){
				var bln = _twoByte($(this));
				if(bln === null){
					$(this).nextAll().css("display","none");
					$(this).nextAll('.err02').css("display","block");
				}else if(!bln){
					$(this).nextAll().css("display","none");
					$(this).nextAll('.err01').css("display","block");
				}else{
					$(this).nextAll().css("display","none");
				}
			});
			$(zip).bind('blur',function(){
				var bln = _oneByte($(this));
				if(bln === null){
					$(this).next().css("display","none");
				}else if(!bln){
					$(this).next().css("display","block");
				}else{
					$(this).next().css("display","none");
				}
			});
			$(adr2).bind('blur',function(){
				var bln = _twoByte($(this));
				if(bln === null){
					$(this).next().css("display","none");
				}else if(!bln){
					$(this).next().css("display","none");
					$(this).next().css("display","block");
				}else{
					$(this).next().css("display","none");
				}
			});
			$(tel).bind('blur',function(){
				var bln = _oneByte($(this));
				if(bln === null){
					$(this).nextAll(".err").css("display","none");
				}else if(!bln){
					$(this).nextAll(".err").css("display","none");
					$(this).nextAll(".err").css("display","block");
				}else{
					$(this).nextAll(".err").css("display","none");
				}
			});
			$(mobi).bind('blur',function(){
				var bln = _oneByte($(this));
				if(bln === null){
					$(this).nextAll(".err").css("display","none");
				}else if(!bln){
					$(this).nextAll(".err").css("display","none");
					$(this).nextAll(".err").css("display","block");
				}else{
					$(this).nextAll(".err").css("display","none");
				}
			});
			$(fax).bind('blur',function(){
				var bln = _oneByte($(this));
				if(bln === null){
					$(this).nextAll(".err").css("display","none");
				}else if(!bln){
					$(this).nextAll(".err").css("display","none");
					$(this).nextAll(".err").css("display","block");
				}else{
					$(this).nextAll(".err").css("display","none");
				}
			});
			$(mail).bind('blur',function(){
				var bln = _mailAddress($(this));
				if(bln === null){
					$(this).nextAll().css("display","none");
					$(this).nextAll(".err03").css("display","block");
				}else if(bln == 'byteError'){
					$(this).nextAll().css("display","none");
					$(this).nextAll(".err01").css("display","block");
				}else if(!bln){
					$(this).nextAll().css("display","none");
					$(this).nextAll(".err02").css("display","block");
				}else{
					$(this).nextAll().css("display","none");
				}
			});
			$(comment+' textarea').bind('blur',function(){
				if($(this).val() != '') $(comment+' .err').css("display","none");
			});

			$(cause+' input').bind('click',function(){
				$(cause+' .err').css("display","none");
			});
			$(type+' input').bind('click',function(){
				$(type+' .err').css("display","none");
			});
			$(contact+' input').bind('click',function(){
				$(contact+' .err').css("display","none");
			});
		}
		// INSTANCE ------------------------------------------------
		return {
			//----------------------------------------------------------
			init:function(){that=this;_init()},
			//----------------------------------------------------------
			twoByte:function(t){return _twoByte(t)},
			//----------------------------------------------------------
			oneByte:function(t){return _oneByte(t)},
			//----------------------------------------------------------
			mailAddress:function(t){return _mailAddress(t)},
			//----------------------------------------------------------
			choiceRadio:function(t){return _choiceRadio(t)},
			//----------------------------------------------------------
			totalCheck:function(){return _totalCheck()}
			//----------------------------------------------------------
		}
	}();

	//----------------------------------------------------------------
	//  list
	//----------------------------------------------------------------
	var list;
	var _list = function(){
		var that;
		var handlr = "#check_btn";
		var listID = "#list";
		var data = '<div id="list"></div>';
		var checkError = '<div class="err_text"><p>入力不備の項目があります。ご確認ください。</p><div><button type="button" onclick="formSet.del()">戻る</button></div></div>';
		var contentHead = '<div id="listup"><p>以下の内容でメールを送信します。<br />問題がなければ"送信"ボタン、内容を変更したい場合"戻る"ボタンを押してください。</p><dl>';
		var contentFoot = '</dl><div class="buttons"><button type="submit">送信</button><button type="button" onclick="formSet.del()">戻る</button></div></div>';

		// init
		function _init(){
			$('#content_02 form').append(data);
			list = $(listID);
			button_set();
			resize(that);
			del(that);
		};
		
		// button set
		function button_set(){
			$(handlr).bind('click',function(){
				_modal.disp();
				if(!_check.totalCheck()){
					list.html(checkError);
				}else{
					list.html(listUP);
				};
				var offsetY = $(window).height() / 2 + $(window).scrollTop();
				var offsetX = $(window).width() / 2 + $(window).scrollLeft();
				var _top = offsetY - list.height() / 2;
				var _left = offsetX - list.width() / 2;
				list
					.css({display:'block',opacity:0,top:_top+'px',left:_left+'px'})
					.animate({opacity:1},300,null,resize());
			});
		};

		// listUP
		function listUP(){
			var content = contentHead+'\
				<dt>お問いあわせ先</dt>\
				<dd>'+$(cause+' input[type="radio"]:checked').val()+'</dd>\
				<dt>お名前</dt>\
				<dd>'+$(name).val()+'</dd>\
				<dt>フリガナ</dt>\
				<dd>'+$(hurigana).val()+'</dd>\
				<dt>ユーザータイプ</dt>\
				<dd>'+$(type+' input[type="radio"]:checked').val()+'</dd>';
			if($(ogn).val() !== '') content += '<dt>団体名</dt><dd>'+$(ogn).val()+'</dd>';
			if($(sec).val() !== '') content += '<dt>部署名</dt><dd>'+$(sec).val()+'</dd>';
			if($(zip).val() !== '') content += '<dt>郵便番号</dt><dd>'+$(zip).val()+'</dd>';
			if($(adr1).val() !== '') content += '<dt>都道府県</dt><dd>'+$(adr1).val()+'</dd>';
			if($(adr2).val() !== '') content += '<dt>市町村番地等</dt><dd>'+$(adr2).val()+'</dd>';
			if($(tel).val() !== '') content += '<dt>電話番号</dt><dd>'+$(tel).val()+'</dd>';
			if($(mobi).val() !== '') content += '<dt>携帯電話</dt><dd>'+$(mobi).val()+'</dd>';
			if($(fax).val() !== '') content += '<dt>FAX番号</dt><dd>'+$(fax).val()+'</dd>';
			content += '<dt>e-mailアドレス</dt><dd>'+$(mail).val()+'</dd>';
			var _info = $(info+' input[type="radio"]:checked').val();
			if(typeof _info !== 'undefined') content += '<dt>資料送付</dt><dd>'+_info+'</dd>';
			content += '<dt>コンタクト方法</dt><dd>'+$(contact+' input[type="radio"]:checked').val()+'</dd>';
			var _com = $(comment+' textarea').val();
			_com = _com.replace(/\r\n/g, "<br />");
			_com = _com.replace(/(\n|\r)/g, "<br />");
			content += '<dt>内容</dt><dd>'+_com+'</dd>';
			content += contentFoot;
			return content;
		};


		// INSTANCE
		return {
			//--------------------------------------------
			init:function(){that=this;_init()},
			//--------------------------------------------
			del:function(){list.css("display","none")},
			//--------------------------------------------
			resize:function(){
				var offsetY = $(window).height() / 2 + $(window).scrollTop();
				var offsetX = $(window).width() / 2 + $(window).scrollLeft();
				var _top = offsetY - list.height() / 2;
				var _left = offsetX - list.width() / 2;
				list.css({top:_top+'px',left:_left+'px'});
			}
			//--------------------------------------------
		}
	}();
	
	
	//----------------------------------------------------------------
	//  _init
	//----------------------------------------------------------------
	var _init = function(){
		doc = $(document);
		_modal.init();
		_area.init();
		_check.init();
		_list.init();
		_cancel.init();
		$(window).bind('resize',function(){resize()});
	};
	//----------------------------------------------------------------
	//  resized
	//----------------------------------------------------------------
	var resize = function(){
		var arr = [];
		return function(t){
			if(typeof t === 'object'){
				arr.push(t);
			}else{
				for(var i in arr) arr[i].resize();
			}
		};
	}();
	//----------------------------------------------------------------
	//  del
	//----------------------------------------------------------------
	var del = function(){
		var arr = [];
		return function(t){
			if(typeof t === 'object'){
				arr.push(t);
			}else{
				for(var i in arr) arr[i].del();
			}
		};
	}();
	//===================================
	//  PUBLIC
	//===================================
	return {
		//--------------------------------------------------------------
		//  initialize
		//--------------------------------------------------------------
		init:function(){that=this;_init()},
		//--------------------------------------------------------------
		//  initialize
		//--------------------------------------------------------------
		del:function(){del()}
	}
})();

