// JavaScript Document

_$ = jQuery.noConflict(false);

_$('body').ready(
				function(){
					postalCheck();
					indisCheck()
				}
				);

function postalCheck() {
    _$('#postal_num')
	.bind('keyup',
		  function(e) {
			 this.value = f2h(_$(this).attr('value'));
			 
		     AjaxZip2.zip2addr(this,'city_name','town_name',null,this);
　　　　　　　}
		  );
}
function indisCheck() {
	_$('.indis')
	 .bind('blur',
		   function(e) {
			  if(_$(this).attr('id') == 'postal_num'){ _$('#cust_add2').removeClass('error').parent().children('div.attention').remove(); }
			 
			  if((_$(this).val() == '' || _$(this).val() == '入力ください。') || (_$(this).attr('id') == 'email_check' && _$('#email_check').val() != _$('#cust_email').val())) {
				  var alertMess = '必須項目です。<br />ご入力お願いします。';
				   _$(this).attr('class','indis error');
				   if (_$(this).attr('id') == 'email_check') {
					   if(_$(this).val() != _$('#cust_email').val()) {
					   alertMess = 'メールアドレスが<br />一致しておりません。';
					   }
				   }
				   var elm = '<div class="attention">' + alertMess + '</div>';
				   _$(this).val('入力ください。');
				   if(_$(this).parent().children('div.attention').length >= 0) {
				   _$('div.attention').remove();
				   _$(this).parent().children('label').before(elm);
				   _$(this).parent()
				   .css({'position':'relative'})
				   .children('div.attention')
				   .css({'position':'absolute','top':'-3.1em','left':'-115px','font-size':'11px','color':'#996600','background-image':'url(/common/act/images/attention_bg.png)','background-repeat':'no-repeat','padding':'6px 20px 24px 12px','line-height':'1.25'});
				   }
			  } else {
					  _$(this).parent().children('div.attention').remove();
					  _$(this).attr('class','indis');
			  }
		   })
	 .bind('focus',
		   function(e) {
			 _$(this).parent()
			.children('div.attention')
			.remove();
			_$(this).removeClass('error');
			 if(_$(this).val() == '入力ください。') {
				_$(this).val('');
			 }
		   });
	 
	 _$('#cust_add2')
	 .bind('change',
		   function(e) {
			 _$(this).removeClass('error');  
		   });
}

function f2h(bs) {;
var ns="";
	for(i=0;i<bs.length;i++) {
		if(bs.charCodeAt(i)>=0xff01&&bs.charCodeAt(i)<=0xff5e)
		ns+=String.fromCharCode(0x0021+(bs.charCodeAt(i)-0xff01));
		else if(bs.charCodeAt(i) == 0x30fc)
		 ns+=String.fromCharCode(0x002d);
		else
		ns+=bs.charAt(i);
	}
return ns;
ns = '';
}

function h2f(bs) {;
var ns="";
	for(i=0;i<bs.length;i++) {
		if(bs.charCodeAt(i)>=0x0021&&bs.charCodeAt(i)<=0x007e)
		ns+=String.fromCharCode(0xff01+(bs.charCodeAt(i)-0x0021));
		else
		ns+=bs.charAt(i);
	}
return ns;
}
