
    // sub - email
    var ol_email = $('#btn_edm_email').overlay({
        mask: {
            color: '#ebecff',
            loadSpeed: 300,
            opacity: 0.9
        },
        onLoad:function(event) {
            var r_email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if(!r_email.test($('#edm_email').val()))
                $('#dialog_email p:nth(0)').text(dia_desc2_email);
            else {
                $.ajax({
                    url:'_if/edm_reg.php',
                    type:'POST',
                    dataType:'json',
                    data:{
                        'email':$('#edm_email').val()
                    },
                    success:function(json){
                        try
                        {
                            if(json.retcode == 0) {
                                $('#dialog_email p:nth(0)').text(dia_desc1_email);
                            } else {
                                $('#dialog_email p:nth(0)').text(json.retstr);
                            }
                        } catch(err) {
                            $('#dialog_email p:nth(0)').text(dia_error);
                        }
                    },
                    error:function() {
                        $('#dialog_email p:nth(0)').text(dia_error);
                    }
                });
            }
        },
        onClose:function() {
            $('#dialog_email p:nth(0)').text('');
        },
        closeOnClick: false
    });

    $('#btn_email_ok').click(function() {
        ol_email.overlay().close();
    });



    // sub - sms
    $('#btn_sms_ok').hide();
    $('#btn_check').hide();
    $('#btn_sms_cancel').hide();

    var ol_sms = $('#btn_edm_sms').overlay({
        mask: {
            color: '#ebecff',
            loadSpeed: 300,
            opacity: 0.9
        },
        onLoad:function(event) {
            var r_sms = /^1[0-9]{10}$/;
            if(!r_sms.test($('#edm_sms').val())) {
                $('#dialog_sms p:nth(0)').text(dia_desc2_sms);
                $('#btn_sms_ok').show();
            }
            else {
                $.ajax({
                    url:'_if/edm_reg.php',
                    type:'POST',
                    dataType:'json',
                    data:{
                        'phone':$('#edm_sms').val()
                    },
                    success:function(json){
                        try
                        {
                            if(json.retcode == 0) {
                                $('#dialog_sms p:nth(1)').show();
                                $('#btn_sms_ok').hide();
                                $('#btn_check').show();
                                $('#btn_sms_cancel').show();
                                $('#dialog_sms p:nth(0)').text(dia_desc1_sms);
                            } else {
                                $('#btn_sms_ok').show();
                                $('#btn_check').hide();
                                $('#btn_sms_cancel').hide();
                                $('#dialog_sms p:nth(0)').text(json.retstr);
                            }
                        } catch(err) {
                            $('#btn_sms_ok').show();
                            $('#dialog_sms p:nth(0)').text(dia_error);
                        }
                    },
                    error:function() {
                        $('#btn_sms_ok').show();
                        $('#dialog_sms p:nth(0)').text(dia_error);
                    }
                });
            }
        },
        onClose:function() {
            $('#dialog_sms p:nth(0)').text('');
            $('#dialog_sms p:nth(1)').hide();
            $('#btn_sms_ok').hide();
            $('#btn_check').hide();
            $('#btn_sms_cancel').hide();
        },
        closeOnClick: false
    });
    
    $('#btn_check').click(function() {
        $.ajax({
            url:'_if/edm_reg_sms_check.php',
            type:'POST',
            dataType:'json',
            data:{
                'phone':$('#edm_sms').val(),
                'cc':$('#sms_checkcode').val()
            },
            success:function(json){
                try
                {
                    if(json.retcode == 0) {
                        $('#btn_sms_ok').show();
                        $('#btn_check').hide();
                        $('#btn_sms_cancel').hide();
                        $('#dialog_sms p:nth(1)').hide();
                        $('#dialog_sms p:nth(0)').text(dia_desc3_sms);
                    } else {
                        $('#dialog_sms p:nth(0)').text(json.retstr);
                    }
                } catch(err) {
                    $('#btn_sms_ok').show();
                    $('#dialog_sms p:nth(0)').text(dia_error);
                }
            },
            error:function() {
                $('#btn_sms_ok').show();
                $('#dialog_sms p:nth(0)').text(dia_error);
            }
        });
    });

    $('#btn_sms_ok').click(function() {
        ol_sms.overlay().close();
    });

    $('#btn_sms_cancel').click(function() {
        ol_sms.overlay().close();
    });




	// unsub
    $('#btn_unsub_ok').hide();
    $('#btn_unsub_check').hide();
    $('#btn_unsub_cancel').hide();

	var ol_unsub = $('#btn_unsub').overlay({
        mask: {
            color: '#ebecff',
            loadSpeed: 300,
            opacity: 0.9
        },
        onLoad:function(event) {
			var r_email = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            var r_sms = /^1[0-9]{10}$/;
            if(!(r_email.test($('#edm_unsub').val()) || r_sms.test($('#edm_unsub').val()))) {
                $('#dialog_unreg p:nth(0)').text(dia_check_err);
                $('#btn_unsub_ok').show();
            }
            else {
                $.ajax({
                    url:'_if/edm_unreg.php',
                    type:'POST',
                    dataType:'json',
                    data:{
                        'key':$('#edm_unsub').val()
                    },
                    success:function(json){
                        try
                        {
                            if(json.retcode == 0) {
								if(json.mode == 1) {
									$('#dialog_unreg p:nth(0)').text(dia_desc4_unsub);
									$('#btn_unsub_ok').show();
								} else if(json.mode == 2) {
									$('#dialog_unreg p:nth(1)').show();
									$('#btn_unsub_ok').hide();
									$('#btn_unsub_check').show();
									$('#btn_unsub_cancel').show();
									$('#dialog_unreg p:nth(0)').text(dia_desc1_sms);
								}
                            } else {
                                $('#btn_unsub_ok').show();
                                $('#btn_unsub_check').hide();
                                $('#btn_unsub_cancel').hide();
                                $('#dialog_unreg p:nth(0)').text(json.retstr);
                            }
                        } catch(err) {
                            $('#btn_unsub_ok').show();
                            $('#dialog_unreg p:nth(0)').text(dia_error);
                        }
                    },
                    error:function() {
                        $('#btn_unsub_ok').show();
                        $('#dialog_unreg p:nth(0)').text(dia_error);
                    }
                });
            }
        },
        onClose:function() {
            $('#dialog_unreg p:nth(0)').text('');
            $('#dialog_unreg p:nth(1)').hide();
            $('#btn_unsub_ok').hide();
            $('#btn_unsub_check').hide();
            $('#btn_unsub_cancel').hide();
        },
        closeOnClick: false
    });


    $('#btn_unsub_check').click(function() {
        $.ajax({
            url:'_if/edm_reg_unsub_check.php',
            type:'POST',
            dataType:'json',
            data:{
                'phone':$('#edm_unsub').val(),
                'cc':$('#unsub_checkcode').val()
            },
            success:function(json){
                try
                {
                    if(json.retcode == 0) {
                        $('#btn_unsub_ok').show();
                        $('#btn_unsub_check').hide();
                        $('#btn_unsub_cancel').hide();
                        $('#dialog_unreg p:nth(1)').hide();
                        $('#dialog_unreg p:nth(0)').text(dia_desc5_unsub);
                    } else {
                        $('#dialog_unreg p:nth(0)').text(json.retstr);
                    }
                } catch(err) {
                    //$('#btn_unsub_ok').show();
                    $('#dialog_unreg p:nth(0)').text(dia_error);
                }
            },
            error:function() {
                //$('#btn_unsub_ok').show();
                $('#dialog_unreg p:nth(0)').text(dia_error);
            }
        });
    });

    $('#btn_unsub_ok').click(function() {
        ol_unsub.overlay().close();
    });

    $('#btn_unsub_cancel').click(function() {
        ol_unsub.overlay().close();
    });




    function inputips(obj, tip) {
        var _this = $(obj);
        var _tip  = tip;

        _this.val(tip);

        _this.focusin(function() {
            if($(this).val() == _tip)
                $(this).val('');
        });
        _this.focusout(function() {
            if($(this).val() == '')
                $(this).val(_tip);
        });
    }

