//var fckpath='http://brandjr/template/js/fckeditor/';
var fckpath='http://www.brandsjuniorclub.com/template/js/fckeditor/';
var base_url='/';
var option={path: fckpath, height:250, width: 700 };
var option2={path: fckpath, height:250, width: 500 };
var comoption={path: fckpath, toolbar:'Basic',
                 height:250, width: 370,
                config:{
                        LinkDlgHideTarget:true,
                        LinkDlgHideAdvanced:true,
                        ImageDlgHideLink:true,
                        ImageDlgHideAdvanced:true,
                        LinkBrowser:false,
                        ImageBrowser:false,
                        LinkUpload:false,
                        ImageUpload:false
                        }
                };
$(document).ready(function(){
    
    //$(".fck").fck(option);
    //$(".fck2").fck(option2);
    //$(".comfck").fck(comoption);
    
    $("a.delete").click(function(){
    return confirm('Please click OK if you want to delete this data');
    });
    
    $("input[type='text']").css({"width":"160px"});
    $("input[type='password']").css({"width":"160px"});
    $("textarea").css({"width":"160px","height":"80px"});

    /*
    $("#submit_btn").hover(
    function(){
        $(this).addClass("submit_login-hover");
    },
    function(){
        $(this).removeClass("submit_login-hover");
    });    
    
    $("#logout_btn").hover(
    function(){
        $(this).attr('src',"/template/images/inner2-bt2.png");
    },
    function(){
        $(this).attr('src',"/template/images/inner2-bt1.png");
    });    
    */
    $("#submit_faq_btn").hover(
    function(){
        $(this).addClass("submit_faq-hover");
    },
    function(){
        $(this).removeClass("submit_faq-hover");
    });      
    
    $("#cancel_faq_btn").hover(
    function(){
        $(this).addClass("cancel_faq-hover");
    },
    function(){
        $(this).removeClass("cancel_faq-hover");
    });  
    
    $("#submit_faq_btn").click(function (){
        var uname = $("#name").val();
        var uemail = $("#email").val();
        var utopic = $("#topic").val();
        
        $("#name").siblings('em').remove();
        $("#email").siblings('em').remove();
        $("#topic").siblings('em').remove();
        
        if (checkEmail(uemail) && uname != "" && utopic != "" ){
            $("#divFaq").html('');
            $("#divFaq").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td><img src="/template/images/loading.gif"></td></tr></table></center>');
            $.post("/faqs/send", { name: uname, topic: utopic, email: uemail },
              function(data){
                $("#name").siblings('em').remove();
                $("#topic").siblings('em').remove();
                $("#email").siblings('em').remove();
                if (data.error == "false"){
                    msg = '<br><font color="red">ขอบคุณสำหรับคำถามของคุณค่ะ</font><br>';
                }else{
                    msg = '<br><font color="red">ไม่สามารถส่งข้อมูลของคุณได้  กรุณาลองใหม่อีกครั้ง ขอบคุณค่ะ</font><br>';
                }
                $("#divFaq").html('');
                $("#divFaq").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td>'+msg+'</td></tr></table></center>');
              }, "json");
              
        }else{
            if (uname == ""){
                $("#name").siblings('em').remove();
                $("#name").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลชื่อด้วยค่ะ");
            }
            if (!checkEmail(uemail)){
                $("#email").siblings('em').remove();
                $("#email").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลอีเมลล์ให้ถูกต้องด้วยค่ะ");
            }
            if (utopic == ""){
                $("#topic").siblings('em').remove();
                $("#topic").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลคำถามด้วยค่ะ");
            }
        }
    });
    
    $("#cancel_faq_btn").click(function (){
        $("#name").attr("value",'');
        $("#email").attr("value",'');
        $("#topic").attr("value",'');
    });
    
    $("#submit_contact_btn").hover(
    function(){
        $(this).addClass("submit_contact-hover");
    },
    function(){
        $(this).removeClass("submit_contact-hover");
    });      
    
    $("#cancel_contact_btn").hover(
    function(){
        $(this).addClass("cancel_contact-hover");
    },
    function(){
        $(this).removeClass("cancel_contact-hover");
    });  
    
    $("#submit_contact_btn").click(function (){
        var uname = $("#name").val();
        var uemail = $("#email").val();
        var utopic = $("#topic").val();
        var udetail = $("#detail").val();
        
        $("#name").siblings('em').remove();
        $("#email").siblings('em').remove();
        $("#topic").siblings('em').remove();
        $("#detail").siblings('em').remove();
        
        if (checkEmail(uemail) && uname != "" && utopic != "" && udetail != ""){
            $("#divContact").html('');
            $("#divContact").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td><img src="/template/images/loading.gif"></td></tr></table></center>');
            $.post("/contactus/send", { name: uname, topic: utopic, detail: udetail, email: uemail },
              function(data){
                $("#name").siblings('em').remove();
                $("#topic").siblings('em').remove();
                $("#detail").siblings('em').remove();
                $("#email").siblings('em').remove();
                if (data.error == "false"){
                    msg = '<br><font color="red">ขอบคุณสำหรับข้อมูลของคุณค่ะ</font><br>';
                }else{
                    msg = '<br><font color="red">ไม่สามารถส่งข้อมูลของคุณได้  กรุณาลองใหม่อีกครั้ง ขอบคุณค่ะ</font><br>';
                }
                $("#divContact").html('');
                $("#divContact").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td>'+msg+'</td></tr></table></center>');
              }, "json");
              
        }else{
            if (uname == ""){
                $("#name").siblings('em').remove();
                $("#name").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลชื่อด้วยค่ะ");
            }
            if (utopic == ""){
                $("#topic").siblings('em').remove();
                $("#topic").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลหัวข้อด้วยค่ะ");
            }
            if (udetail == ""){
                $("#detail").siblings('em').remove();
                $("#detail").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลรายละเอียดด้วยค่ะ");
            }
            if (!checkEmail(uemail)){
                $("#email").siblings('em').remove();
                $("#email").after('<em></em>').siblings('em').html("กรุณากรอกข้อมูลอีเมลล์ให้ถูกต้องด้วยค่ะ");
            }
        }
    });
    
    $("#cancel_contact_btn").click(function (){
        $("#name").attr("value",'');
        $("#email").attr("value",'');
        $("#topic").attr("value",'');
        $("#detail").attr("value",'');
    });
    
    $("#submit_register_btn").hover(
    function(){
        $(this).addClass("submit_register-hover");
    },
    function(){
        $(this).removeClass("submit_register-hover");
    });      
    
    $("#cancel_register_btn").hover(
    function(){
        $(this).addClass("cancel_register-hover");
    },
    function(){
        $(this).removeClass("cancel_register-hover");
    });  
    
    $("#submit_login_btn").hover(
    function(){
        $(this).addClass("submit_login-hover");
    },
    function(){
        $(this).removeClass("submit_login-hover");
    });      
    
    $("#cancel_login_btn").hover(
    function(){
        $(this).addClass("cancel_login-hover");
    },
    function(){
        $(this).removeClass("cancel_login-hover");
    });  
    
    $("#cancel_login_btn").click(function (){
        $("#username").attr("value",'');
        $("#password").attr("value",''); 
    });
    
    $("#submit_forgot_btn").hover(
    function(){
        $(this).addClass("submit_forgot-hover");
    },
    function(){
        $(this).removeClass("submit_forgot-hover");
    });      
    
    $("#cancel_forgot_btn").hover(
    function(){
        $(this).addClass("cancel_forgot-hover");
    },
    function(){
        $(this).removeClass("cancel_forgot-hover");
    });  
    
    $("#submit_forgot_btn").click(function (){
        var uemail = $("#email").val();
        
        $("#email").siblings('em').remove();
        
        if (checkEmail(uemail)){
            $("#divForgot").html('');
            $("#divForgot").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td><img src="/template/images/loading.gif"></td></tr></table></center>');
            $.post("/member/sendForgot", { email: uemail },
              function(data){
                $("#email").siblings('em').remove();
                if (data.error == "false"){
                    msg = '<br><font color="red">ระบบได้จัดส่งข้อมูล  Password ไปยังอีเมล์ของท่านเรียบร้อยแล้วค่ะ</font><br>';
                }else{
                    if (data.msg == "3"){
                        msg = '<br><font color="red">ไม่มี อีเมล์ของคุณอยู่ในระบบ  กรุณาลองใหม่อีกครั้ง ขอบคุณค่ะ</font><br>';
                    //}else if (data.msg == "4"){
                        //msg = '<br><font color="red">ไม่มี อีเมล์ของคุณอยู่ในระบบ  กรุณาลองใหม่อีกครั้ง ขอบคุณค่ะ</font><br>';
                    }else{
                        msg = '<br><font color="red">ไม่สามารถส่งข้อมูลได้  กรุณาลองใหม่อีกครั้ง ขอบคุณค่ะ</font><br>';
                    }
                }
                $("#divForgot").html('');
                $("#divForgot").html('<center><table width="100%" height="180" border="0" cellspacing="10" cellpadding="0"><tr><td>'+msg+'</td></tr></table></center>');
              }, "json");
              
        }else{
            if (!checkEmail(uemail)){
                $("#email").siblings('em').remove();
                $("#email").after('<em></em>').siblings('em').html("กรุณากรอกอีเมล์ด้วยค่ะ");
            }
        }
    });
    
    $("#cancel_forgot_btn").click(function (){
        $("#email").attr("value",'');
    });
    
    $("#junior_main1_btn").hover(
    function(){
        $(this).attr('src',"/template/images/inner2-bt1.png");
    },
    function(){
        $(this).attr('src',"/template/images/inner2-bt1.png");
    });    
    
    $("#junior_main2_btn").hover(
    function(){
        $(this).attr('src',"/template/images/inner2-bt2.png");
    },
    function(){
        $(this).attr('src',"/template/images/inner2-bt2.png");
    });      
    
    $("#print_ads_2007").hover(
    function(){
        $(this).attr('src',"/template/images/bt-2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt-1.png");
    });      
    
    $("#print_ads_2008").hover(
    function(){
        $(this).attr('src',"/template/images/bt3-2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt3-1.png");
    });       
    
    $("#candidate_prev").hover(
    function(){
        $(this).attr('src',"/template/images/bt-inner6L2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt-inner6L.png");
    });       
    
    $("#candidate_next").hover(
    function(){
        $(this).attr('src',"/template/images/bt-inner6-2.jpg");
    },
    function(){
        $(this).attr('src',"/template/images/bt-inner6.jpg");
    });        
    
    $("img[id^='candidate_preview']").hover(
    function(){
        $(this).attr('src',"/template/images/bt-d3-2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt-d3-1.png");
    });      
    
    $("img[id='view_btn']").hover(
    function(){
        $(this).attr('src',"/template/images/bt-d3-2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt-d3-1.png");
    });  
    
    /*$('#btn_application').click( function() {
        window.open($(this).attr('href'),'','left=0,top=0,width=1240,height=1754,scrollbars=1,toolbar=1,resizable=0');
        return false;
    });*/
    
    $('#print_ads_2007_btn').click( function() {
        window.open($(this).attr('href'),'','left=0,top=0,width=855,height=1108,scrollbars=1,toolbar=1,resizable=0');
        return false;
    });
    
    $('#print_ads_2008_btn').click( function() {
        window.open($(this).attr('href'),'','left=0,top=0,width=792,height=612,scrollbars=1,toolbar=1,resizable=0');
        return false;
    });   
    
    $("#download_application").hover(
    function(){
        $(this).attr('src',"/template/images/bt-Dow2.png");
    },
    function(){
        $(this).attr('src',"/template/images/bt-Dow1.png");
    }); 
    
    $("div[id^='ans']").css({"display":"none"}); 
                                           
    
    $("#logout_btn").hover(
    function(){
        $(this).attr('src',"/template/images/submit-logout2.jpg");
    },
    function(){
        $(this).attr('src',"/template/images/submit-logout1.jpg");
    });  
    
       
    if (typeof($($.datepicker))!=='undefined'){
    $("#datepicker").datepicker({yearRange: '2007:2015',dateFormat: 'yy-mm-dd'});
        //$("#datepicker").datepicker({yearRange: '2550:2558',dateFormat: 'yy-mm-dd',dayNamesMin: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],monthNames: ['มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฏาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'] });
    }
    /**/
    
    $("#register_form").each(function(event){
        DisableField();
    });
    
    $("#check_user").click(function(event){
        
        var uname = $("#username").val();
        var uemail = $("#email").val();
        
        $("#username").siblings('em').remove();
        $("#email").siblings('em').remove();
        
        $("#check_user").siblings('span').remove();
        $("#divCheckuser").css({"display":"block"});
        
        var regex=/^[0-9\-_A-Za-z]+$/;
        if (checkEmail(uemail) && (uname.length >= 6 && uname.length <= 20 && regex.test(uname))){
            
            $.post("/member/checkuser", { username: uname, email: uemail },
              function(data){
                ncode = data.msg;
                if (data.error == "false"){
                    $("#check_user").siblings('<span class="star-red"></span>').remove();
                    $("#check_user").after('<span class="star-red"></span>').siblings('span').html(" ชื่อผู้ใช้นี้ \""+uname+"\" ใช้ได้ค่ะ");
                    DisableMainField();
                    EnableField();
                    $("#divCheckuser").css({"display":"none"});
                }else{
                    $("#divCheckuser").css({"display":"none"});
                    switch(ncode){
                        case "2":
                                $("#username").siblings('em').remove();
                                $("#username").after('<em></em>').siblings('em').html("ชื่อผู้ใช้นี้ \""+uname+"\" มีผู้ใช้แล้ว");
                            break;
                        case "3":
                                $("#email").siblings('em').remove();
                                $("#email").after('<em></em>').siblings('em').html("อีเมล์นี้ \""+uemail+"\" มีผู้ใช้แล้ว");
                            break;
                        case "4":
                                $("#username").siblings('em').remove();
                                $("#username").after('<em></em>').siblings('em').html("กรุณากรอกชื่อผู้ใช้ด้วยค่ะ");
                                $("#email").siblings('em').remove();
                                $("#email").after('<em></em>').siblings('em').html("กรุณากรอกอีเมล์ด้วยค่ะ");
                            break;
                    }
                }
              }, "json");
              
        }else{
            $("#divCheckuser").css({"display":"none"});
            if (uname.length < 6 || uname.length > 20){
                $("#username").siblings('em').remove();
                $("#username").after('<em></em>').siblings('em').html("ชื่อผู้ใช้ มีขนาดความยาวตัวอักษรตั้งแต่ 6 - 20 ตัวอักษร เท่านั้น");
            }
            if (!regex.test(uname)){
                $("#username").siblings('em').remove();
                $("#username").after('<em></em>').siblings('em').html("ชื่อผู้ใช้ เป็นตัวอักษรภาษาอังกฤษ ตัวเลข (0-9 A-Z a-z) เท่านั้น");
            }
            if (!checkEmail(uemail)){
                $("#email").siblings('em').remove();
                $("#email").after('<em></em>').siblings('em').html("กรุณากรอกอีเมล์ให้ถูกต้องด้วยค่ะ");
            }
        }
    });
    
    $("#submit_vote").hover(
    function(){
        $(this).attr('src',"/template/images/submit-okhover.jpg");
    },
    function(){
        $(this).attr('src',"/template/images/sumit-ok.jpg");
    });  
    
    $("#submit_bigvote").hover(
    function(){
        $(this).attr('src',"/template/images/submit-okhover.jpg");
    },
    function(){
        $(this).attr('src',"/template/images/sumit-ok.jpg");
    });  
    
    $("#submit_vote").click(function (){
        
    });
    
    $("#submit_bigvote").click(function (){
        
    });
    
    $("#voteLogin").click(function (){
        self.parent.tb_remove();
        
        url = '/member/login';
        
        var browser_type=navigator.appName
        var browser_version=parseInt(navigator.appVersion) 
        if (browser_type=="Microsoft Internet Explorer"&&browser_version<=6){  
            parent.window.location.replace(url);
        }else if (browser_type=="Microsoft Internet Explorer"&&browser_version==7){
            parent.window.location = url;
        }else{
            parent.window.location = url;
        }    
    });
    
    $("#voteLogin_btn").click(function (){ 
        self.parent.tb_remove();
        
        url = '/member/login';
        
        var browser_type=navigator.appName
        var browser_version=parseInt(navigator.appVersion) 
        if (browser_type=="Microsoft Internet Explorer"&&browser_version<=6){  
            parent.window.location.replace(url);
        }else if (browser_type=="Microsoft Internet Explorer"&&browser_version==7){
            parent.window.location = url;
        }else{
            parent.window.location = url;
        }    
    });
    
    $("#submit_vote").click(function (){
        //cid = $("#vote_btn").attr("value");
        //alert('normal vote '+cid);
        cid = $("#candidate_id").val();
        cname = $("#candidate_name").val();
        ccaptcha = $("#captcha").val();
        
        $.post('/candidate/voteprocess',{ id: cid, captcha: ccaptcha }, 
              function(data){
                if (data.status == "true"){
                    alert("โหวตเรียบร้อยแล้ว");
                    self.parent.tb_show(cname,"/candidate/profile/id:"+cid+"?KeepThis=true&TB_iframe=true&width=710&height=545&modal=true","/template/images/"); 
                }else{
                    switch (data.mcode){
                        case "1":
                                alert("อักษรที่คุณพิมพ์ไม่ถูกต้อง");
                                $("#captcha").siblings('em').remove();
                                $("#captcha").after('<em></em>').siblings('em').html("โปรดพิมพ์อักษรที่คุณเห็นข้างบน");
                            break;
                        case "2":
                                alert("คุณไม่ได้รับอนุญาติ");
                            break;
                        case "3":
                                alert("ขณะนี้ได้ทำการปิดโหวตแล้วค่ะ");
                            break;
                        default:
                                alert("คุณได้ทำการโหวตไปแล้ว กรุณากลับมาโหวตใหม่อีกหนึ่งชั่วโมง");
                                self.parent.tb_show(cname,"/candidate/profile/id:"+cid+"?KeepThis=true&TB_iframe=true&width=710&height=545&modal=true","/template/images/");   
                            break;
                    }       
                }
              }, "json");
        
    });
    
    $("#submit_bigvote").click(function (){
        //cid = $("#vote_btn").attr("value");
        //alert('big vote '+cid);
        cid = $("#candidate_id").val();
        cname = $("#candidate_name").val();
        ccaptcha = $("#captcha").val();
        cbcode = $("#bigcode").val();
        
        $.post('/candidate/bigvoteprocess',{ id: cid, captcha: ccaptcha, bcode: cbcode }, 
              function(data){
                if (data.status == "true"){
                    alert("โหวตเรียบร้อยแล้ว");
                    self.parent.tb_show(cname,"/candidate/profile/id:"+cid+"?KeepThis=true&TB_iframe=true&width=710&height=545&modal=true","/template/images/"); 
                }else{
                    switch (data.mcode){
                        case "1":
                                alert("อักษรที่คุณพิมพ์ไม่ถูกต้อง");
                                $("#captcha").siblings('em').remove();
                                $("#captcha").after('<em></em>').siblings('em').html("โปรดพิมพ์อักษรที่คุณเห็นข้างบน");
                            break;
                        case "2":
                                alert("รหัส Big Vote นี้ถูกใช้ไปแล้วหรือไม่มีอยู่ในระบบ");
                                $("#bigcode").siblings('em').remove();
                                $("#bigcode").after('<em></em>').siblings('em').html("กรุณากรอกรหัส Big Vote ใหม่");
                            break;
                        case "3":
                                alert("คุณไม่ได้รับอนุญาติ");
                            break;
                        case "4":
                                alert("ขณะนี้ได้ทำการปิดโหวตแล้วค่ะ");
                            break;
                        /*default:
                                alert("คุณได้ทำการโหวตไปแล้ว กรุณากลับมาโหวตใหม่อีกหนึ่งชั่วโมง");
                                self.parent.tb_show(cname,"/candidate/profile/id:"+cid+"?KeepThis=true&TB_iframe=true&width=710&height=545&modal=true","/template/images/");   
                            break;*/
                    }       
                }
              }, "json");
        
        
    });
    
    //************** scrollable **************//
    // initialize scrollable
    if (window.location.pathname != "" && window.location.pathname != "/"){
        api = $("#scrollable").scrollable({size: 1, clickable: false}).navigator({navi: '#htabs', naviItem: 'a', api: true});
    }
    
});

function popJunior(jid,jname){
    // Call function of thickbox (jquery plugin)
    self.tb_show(jname,"/junior/profile/"+jid+"?KeepThis=true&TB_iframe=true&width=423&height=555","/template/images/");        
}

function popCandidate(cid,cname){
    // Call function of thickbox (jquery plugin)
    self.tb_show(cname,"/candidate/profile/id:"+cid+"?KeepThis=true&TB_iframe=true&width=710&height=545","/template/images/");        
}

function popVote(cid,cname){
    // Call function of thickbox (jquery plugin)
    /*$("#TB_window").css({"width":"423px","height":"555px"});
    $("#TB_content").css({"width":"423px","height":"555px"});
    $("#TB_iframe").css({"width":"423px","height":"555px"});
    $("#divContentProfile").css({"width":"423px","height":"555px"});*/
    self.parent.tb_show(cname,"/candidate/vote/id:"+cid+"?KeepThis=true&TB_iframe=true&width=423&height=555&modal=true",false); 
}

function popBigVote(cid,cname){
    // Call function of thickbox (jquery plugin)
    self.parent.tb_show(cname,"/candidate/bigvote/id:"+cid+"?KeepThis=true&TB_iframe=true&width=423&height=555&modal=true",false); 
}

function showAns(qid){
    $('#ans'+qid).slideToggle('fast');
}

function DisableMainField(){

    $("#username").attr("readonly","true");
    $("#email").attr("readonly","true");
    $("#check_user").attr("disabled","disabled");
    
}

function EnableField(){
    // disable field of register form
    
    $("#password").attr("disabled","");
    $("#re_password").attr("disabled","");
    $("#firstname").attr("disabled","");
    $("#lastname").attr("disabled","");
    $("#address").attr("disabled","");
    $("#telephone").attr("disabled","");
    $("#mobile").attr("disabled","");
    $("#captcha_txt").attr("disabled","");
    
}

function DisableField(){
    // disable field of register form
    
    $("#password").attr("disabled","disabled");
    $("#re_password").attr("disabled","disabled");
    $("#firstname").attr("disabled","disabled");
    $("#lastname").attr("disabled","disabled");
    $("#address").attr("disabled","disabled");
    $("#telephone").attr("disabled","disabled");
    $("#mobile").attr("disabled","disabled");
    $("#captcha_txt").attr("disabled","disabled");
    
}
function registerValid(){
    var username = $("#username").val();
    var email = $("#email").val();
    var password = $("#password").val();
    var password2 = $("#re_password").val();
    var firstname = $("#firstname").val();
    var lastname = $("#lastname").val();
    var address = $("#address").val();
    var telephone = $("#telephone").val();
    var mobile = $("#mobile").val();
    var captcha = $("#captcha_txt").val();
    
    var verror = true;
    var regex=/^[0-9\-_A-Za-z]+$/;
    
    if (username.length < 6 || username.length > 20){
        $("#username").siblings('em').remove();
        $("#username").after('<em></em>').siblings('em').html("ชื่อผู้ใช้ มีขนาดความยาวตัวอักษรตั้งแต่ 6 - 20 ตัวอักษร เท่านั้น");
        verror = false;
    }
    if (!regex.test(uname)){
        $("#username").siblings('em').remove();
        $("#username").after('<em></em>').siblings('em').html("ชื่อผู้ใช้ เป็นตัวอักษรภาษาอังกฤษ ตัวเลข (0-9 A-Z a-z) เท่านั้น");
    }
    if (!checkEmail(email)){
        $("#email").siblings('em').remove();
        $("#email").after('<em></em>').siblings('em').html("กรุณากรอกอีเมล์ให้ถูกต้องด้วยค่ะ");
        verror = false;
    }
    if (password == ""){
        $("#password").siblings('em').remove();
        $("#password").after('<em></em>').siblings('em').html("กรุณากรอก รหัสผ่านด้วยค่ะ");
        verror = false;
    }
    if (password.length < 6){
        $("#password").siblings('em').remove();
        $("#password").after('<em></em>').siblings('em').html("รหัสผ่าน ต้องมีความยาวอักษร อย่างน้อย 6 ตัวอักษร");
        verror = false;
    }else{
        if (password2 == ""){
            $("#re_password").siblings('em').remove();
            $("#re_password").after('<em></em>').siblings('em').html("กรุณากรอก ยืนยันรหัสผ่านด้วยค่ะ");
            verror = false;
        }
        if (password != password2){
            $("#re_password").siblings('em').remove();
            $("#re_password").after('<em></em>').siblings('em').html("รหัสผ่านและยืนยันรหัสผ่านต้องเหมือนกัน");
            verror = false;
        }
    }
    if (firstname == ""){
        $("#firstname").siblings('em').remove();
        $("#firstname").after('<em></em>').siblings('em').html("กรุณากรอก ชื่อด้วยค่ะ");
        verror = false;
    }
    if (lastname == ""){
        $("#lastname").siblings('em').remove();
        $("#lastname").after('<em></em>').siblings('em').html("กรุณากรอก นามสกุลด้วยค่ะ");
        verror = false;   
    }
    if (address == ""){
        $("#address").siblings('em').remove();
        $("#address").after('<em></em>').siblings('em').html("กรุณากรอก ที่อยู่ด้วยค่ะ");
        verror = false;   
    }
    if (telephone == ""){
        $("#telephone").siblings('em').remove();
        $("#telephone").after('<em></em>').siblings('em').html("กรุณากรอกโทรศัพท์บ้านด้วยค่ะ");
        verror = false;   
    }
    if (isNaN(telephone)){
        $("#telephone").siblings('em').remove();
        $("#telephone").after('<em></em>').siblings('em').html("โทรศัพท์บ้าน ต้องเป็นตัวเลขเท่านั้น");
        verror = false;
    }
    if (mobile == ""){
        $("#mobile").siblings('em').remove();
        $("#mobile").after('<em></em>').siblings('em').html("กรุณากรอกโทรศัพท์มือถือด้วยค่ะ");
        verror = false;   
    }
    if (isNaN(mobile)){
        $("#mobile").siblings('em').remove();
        $("#mobile").after('<em></em>').siblings('em').html("โทรศัพท์มือถือ ต้องเป็นตัวเลขเท่านั้น");
        verror = false;
    }
    if (captcha == ""){
        $("#captcha_txt").siblings('em').remove();
        $("#captcha_txt").after('<em></em>').siblings('em').html("กรุณาพิมพ์ตัวอักษรที่เห็นในภาพด้วยค่ะ");
        verror = false;   
    }

    return verror;
}