var postFile = "register.php";

$(document).ready(function(){

});

function register(){
    $.post(postFile, $('form[name="registerForm"]').serialize(),function(data){
        if( data.status == 200 ){
            window.location = postFile+"?m=confirmemail&uid="+data.uid;
        }else{
            if( data.data.error != undefined ){
                 $("#notifybox").notify();
                 $("#notifybox").notify("create", {
                     title: 'กรุณาตรวจสอบ',
                     text: data.data.error
                 });
            }
        }
    },"json");
}

function uploadAvatar(){
    var btnUpload = $('#btnUpload');
    var status = $('#statusUpload');
    new AjaxUpload(btnUpload, {
        action: 'uploadavatar.php',
        name: 'uploadavatar',
        responseType: 'json',
        onSubmit: function(file, ext){
            if(!(ext && /^(jpg|jpeg)$/.test(ext))){
                status.text('สามารถอัพโหลดได้เฉพาะไฟล์ jpg เท่านั้น');
                return false;
            }
            status.text('Uploading ...');
        },
        onComplete: function(file, response){
            status.text('');
            if(response.status == 'success'){
                status.text("อัพโหลดไฟล์ชื่อ:"+response.name);
                $('#uploadAvatar').val(response.tmp_name);
                $('#avatarPic').html('<img src="uploads/temp/'+response.tmp_name+'" width="150" height="150"/>');
            }
        }
    });
}

