$(document).ready(function(){

	// 키 추출
	var private = $('#private').text() ;
	var public = $('#public').text() ;
		
	// Javascript RSA 객체 생성
	var rsa = new ssRsa(public);

	// 폼 전송 전에 암호화 처리를 한다.
	$('form[rsa]').submit(function(){
		$(this).find(':input[name*=ssRsaForm]').remove();
		$(this).find(':input').each(function(){
			var $obj	= $(this) ,
				type	= $obj.attr('type') ,
				name	= $obj.attr('name') ,
				value	= $.trim($obj.val()) ;
			if ( value == '' )
				return ;
			if ( type == undefined )
				type	= $obj[0].nodeName ;
			switch ( type.toLowerCase() )
			{
				case 'submit' :
				case 'button' :
				case 'file' :
					break ;
				case 'select' :
					$obj.children('[value=' + value + ']').attr('value',rsa.encrypt(value));
					break ;
				case 'radio' :
				case 'checkbox' :
					if ( $obj.prop('checked') )
						$obj.val(rsa.encrypt(value));
					break ;
				default :
					$obj.val(rsa.encrypt(value));
					break ;
			}
		});
		$(this).append('<input type="hidden" name="ssRsaForm" value="1">');
	});

});