$(document).ready(function() {
    
    $(".error_nama").hide();
    $(".error_hp").hide();
    $(".error_email").hide();
    $(".error_password").hide();
    $(".error_umur").hide();
    $(".error_pekerjaan").hide();
    $(".error_bidang").hide();
    $(".error_captcha").hide();
    $(".berhasil_register").hide();
    $(".error_invalid_nama").hide();
    $(".error_invalid_umur").hide();
    $(".loaded").hide();
    
    $("#regist").submit(function() {
        
        $('.loaded').show(300);
        
        $.post("http://www.babastudio.com/registermember/jax/", {
            nama:$("#nama").val(),
            hp:$("#hp").val(),
            email:$("#email").val(),
            password:$("#password").val(),
            job:$("#job:checked").val(),
            bidang:$("#bidang:checked").val(),
            tertarik:$("#tertarik:checked").val(),
            imagecode:$("#imagecode").val(),
            umur:$("#umur").val()
        },
            
        function(data) {
            if(data == 1) {   
                $('.error_nama').html('<div style="color:red;margin-left:85px">maaf nama tidak boleh kosong</div>');
                $('.error_hp').html('<div style="color:red;margin-left:85px">maaf nomor hp tidak boleh kosong</div>');
                $('.error_email').html('<div style="color:red;margin-left:85px">maaf email tidak boleh kosong</div>');
                $('.error_password').html('<div style="color:red;margin-left:85px">maaf password tidak boleh kosong</div>');
                $('.error_umur').html('<div style="color:red;margin-left:85px">maaf umur tidak boleh kosong</div>');
                $('.error_captcha').html('<div style="color:red">maaf kode random tidak boleh kosong</div>');
                $('.error_pekerjaan').html('<div style="color:red">maaf pekerjaan tidak boleh kosong</div>');
                $('.error_bidang').html('<div style="color:red">maaf bidang tidak boleh kosong</div>');
                $(".error_nama").fadeIn('slow');
                $(".error_hp").fadeIn('slow');
                $(".error_email").fadeIn('slow');
                $(".error_password").fadeIn('slow');
                $(".error_umur").fadeIn('slow');
                $(".error_pekerjaan").fadeIn('slow');
                $(".error_bidang").fadeIn('slow');
                $(".error_captcha").fadeIn('slow');
                $(".berhasil_register").hide();
                $('.loaded').hide();
            } else if(data == 2) {   
                $('.error_nama').html('<div style="color:red;margin-left:85px">maaf nama tidak boleh kosong</div>');
                $(".error_nama").fadeIn('slow');
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_email").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 3) {  
                $('.error_hp').html('<div style="color:red;margin-left:85px">maaf nomor hp tidak boleh kosong</div>');
                $(".error_hp").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_email").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();  
                $(".berhasil_register").hide();   
                $(".error_invalid_umur").hide();           
                $('.loaded').hide();
            } else if(data == 4) {
                $('.error_email').html('<div style="color:red;margin-left:85px">maaf email tidak boleh kosong</div>');
                $(".error_email").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".berhasil_register").hide();
                $(".error_captcha").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 5) {
                $('.error_email').html('<div style="color:red;margin-left:85px">email anda tidak valid</div>');
                $(".error_email").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".berhasil_register").hide();
                $(".error_captcha").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 6) { 
                $('.error_umur').html('<div style="color:red;margin-left:85px">maaf umur tidak boleh kosong</div>');
                $(".error_umur").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_email").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 7) { 
                $('.error_captcha').html('<div style="color:red;margin-left:85px">kode random salah</div>');
                $(".error_captcha").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_email").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 8) { 
                $('.error_email').html('<div style="color:red;margin-left:85px">email sudah ada yang menggunakan</div>');
                $(".error_email").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 9) { 
                /*
                $.fancybox.close();
                $("#berhasil_register").dialog({
                    modal: true,
        			buttons: {
        				Close: function() {
        					$( this ).dialog( "close" );
        				}
        			}
                });
                */
                /*
                var str_email_register = $('#email').val();
                var substr_email_register = str_email_register.split('@');
                
                if (substr_email_register[1] == 'yahoo.com') {
                    var redirect_to = 'https://login.yahoo.com/';
                } else if (substr_email_register[1] == 'yahoo.co.id') {
                    var redirect_to = 'https://login.yahoo.com/';
                } else if (substr_email_register[1] == 'ymail.com') {
                    var redirect_to = 'https://login.yahoo.com/';
                } else if (substr_email_register[1] == 'rocketmail.com') {
                    var redirect_to = 'https://login.yahoo.com/';
                } else if (substr_email_register[1] == 'gmail.com') {
                    var redirect_to = 'https://mail.google.com/';
                } else if (substr_email_register[1] == 'hotmail.com') {
                    var redirect_to = 'https://login.live.com/';
                } else {
                    var redirect_to = 'http://www.babastudio.com/';
                }
                
                setTimeout('window.location.href="'+redirect_to+'"', 5000)
                */
                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_email").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
                $(".berhasil_register").show();
                
                $.fancybox.close();
                $("#berhasil_register").dialog({
                    modal: true,
        			buttons: {
        				Close: function() {
        					$( this ).dialog( "close" );
        				}
        			}
                });
                
                setTimeout('window.location.href="http://www.babastudio.com/"', 1000);
            } else if(data == 10) {
                $('.error_password').html('<div style="color:red;margin-left:85px">maaf password tidak boleh kosong</div>');
                $(".error_password").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_umur").hide();
                $(".error_email").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 11) {   
                $('.error_invalid_nama').html('<div style="color:red;margin-left:85px">maaf nama anda tidak valid</div>');
                $(".error_invalid_nama").fadeIn('slow');
                $(".error_nama").hide();
                $(".error_hp").hide();
                $(".error_email").hide();
                $(".error_password").hide();
                $(".error_umur").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $(".error_invalid_umur").hide();
                $('.loaded').hide();
            } else if(data == 12) { 
                $('.error_invalid_umur').html('<div style="color:red;margin-left:85px">maaf umur tidak valid</div>');
                $(".error_invalid_umur").fadeIn('slow');                
                $(".error_nama").hide();
                $(".error_umur").hide();
                $(".error_invalid_nama").hide();
                $(".error_hp").hide();
                $(".error_password").hide();
                $(".error_email").hide();
                $(".error_pekerjaan").hide();
                $(".error_bidang").hide();
                $(".error_captcha").hide();
                $(".berhasil_register").hide();
                $('.loaded').hide();
            }
        })
        return false;
    })
});

$(document).ready(function(){
    $('.tertarik-dengan-bisnis-it').click(function() {
        $('.ya-tidak').show(1500);        
    });
    $('.close-tertarik-dengan-bisnis-it').click(function() {
        $('.close-ya-tidak').hide(1500);        
    });
});
