//引入驗證function
document.write("<script language=javascript src='" + xoopsjsurl + "/modules/neillibrary/js/checkpattern.js'></script>");
var jstextArr = JSON.parse(jstext);

//管理後台-選單按鈕收合
$(document).ready(function() {
    $(".boxbuteach").each(function(index) {
        var index = index + 1;
        var $boxbut = ".box" + index + "";
        var $boxbutton = ".boxbutton" + index + "";
        // alert($boxbut);
        $($boxbutton).click(function() {
            $($boxbut).slideToggle("fast");
            var $openboxtextvar = $($boxbutton).text();
            if ($openboxtextvar == "展開") {
                $($boxbutton).text("收合");
            } else {
                $($boxbutton).text("展開");
            }
        });
    });
});
//區塊管理
$(document).ready(function() {
    //區塊連結開啟
    $("body").on("change", "#enablebtn", function() {
        if ($(this).val() == 1) {
            $("#enablebox1,#enablebox2").slideToggle("fast");
        } else {
            $("#enablebox1,#enablebox2").slideToggle("fast");
        }
    })
    $("body").on("change", "#inlineRadio", function() {
        if ($(this).val() == 'text') {
            $("#topboxny").slideToggle("fast");
            $("#boxwidth").slideToggle("fast");
        } else {
            $("#topboxny").slideToggle("fast");
            $("#boxwidth").slideToggle("fast");
        }
    })
});
//系統設定
$(document).ready(function() {
    //line區塊
    $("body").on("change", "#linebtnny", function() {
        if ($(this).val() == 1) {
            $("#linebox").slideToggle("fast");
        } else {
            $("#linebox").slideToggle("fast");
        }
    })
    //FB-簡訊區塊
    $("body").on("change", "#fbmessagesbtnny", function() {
        if ($(this).val() == 1) {
            $("#fbmessagesbox").slideToggle("fast");
        } else {
            $("#fbmessagesbox").slideToggle("fast");
        }
    })
    //FB-連結區塊
    $("body").on("change", "#fbbtnny", function() {
        if ($(this).val() == 1) {
            $("#fburlbox").slideToggle("fast");
        } else {
            $("#fburlbox").slideToggle("fast");
        }
    })
    //聯絡我們區塊
    $("body").on("change", "#contactusbtnny", function() {
        if ($(this).val() == 1) {
            $("#contactusbox").slideToggle("fast");
        } else {
            $("#contactusbox").slideToggle("fast");
        }
    })
});





//右下浮動廣告空欄位判斷
function neothemesadmin_lowerrightad() {	
	
  //預設判斷
    if ($("[name=title]").val()) {
        $("#helpBlocktitle").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    }
    //廣告標題
    $("body").on("change", "[name=title]", function() {
        if ($(this).val()) {
            $("#helpBlocktitle").hide().text(true);
        } else {
            $("#helpBlocktitle").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    })    	
    	
    	
   //預設判斷
    if ($("#imgidbox").length == '1') {
        $("#helpBlockimgid").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    }
    //選擇圖片
    $("body").on("change", "[name=upfile2]", function() {
        if ($(this).val()) {
            $("#helpBlockimgid").hide().text(true);
        } else {
            $("#helpBlockimgid").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    })
    
    
    //預設判斷
    if ($("#mydate1").val()) {
        $("#helpBlockmaturity").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    }
    //必填欄位-到期日期
    $("body").on("change", "#mydate1", function() {
        if ($(this).val()) {
            $("#helpBlockmaturity").hide().text(true);
        } else {
            $("#helpBlockmaturity").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach6', $id = '#lowerrightadbox');
    })   
}








//彈出廣告空欄位判斷
function neothemesadmin_popupadsform() {	
	
  //預設判斷
    if ($("[name=title]").val()) {
        $("#helpBlocktitle").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    }
    //廣告標題
    $("body").on("change", "[name=title]", function() {
        if ($(this).val()) {
            $("#helpBlocktitle").hide().text(true);
        } else {
            $("#helpBlocktitle").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    })    	
    	
    	
   //預設判斷
    if ($("#imgidbox").length == '1') {
        $("#helpBlockimgid").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    }
    //選擇圖片
    $("body").on("change", "[name=upfile]", function() {
        if ($(this).val()) {
            $("#helpBlockimgid").hide().text(true);
        } else {
            $("#helpBlockimgid").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    })
    
    
    //預設判斷
    if ($("#mydate1").val()) {
        $("#helpBlockmaturity").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    }
    //必填欄位-到期日期
    $("body").on("change", "#mydate1", function() {
        if ($(this).val()) {
            $("#helpBlockmaturity").hide().text(true);
        } else {
            $("#helpBlockmaturity").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    })   
    	
    	
    	
  //預設判斷
    if ($("[name=imgwidth]").val()) {
        $("#helpBlockimgwidth").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    }
    //廣告標題
    $("body").on("change", "[name=imgwidth]", function() {
        if ($(this).val()) {
            $("#helpBlockimgwidth").hide().text(true);
        } else {
            $("#helpBlockimgwidth").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach5', $id = '#popupadsbox');
    })   
    	
    	
}




//簡介區塊空欄位判斷
function neothemesadmin_textblockform() {
    //預設判斷
    if ($("[name=title]").val()) {
        $("#helpBlocktitle").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    }
    //區塊標題
    $("body").on("change", "[name=title]", function() {
        if ($(this).val()) {
            $("#helpBlocktitle").hide().text(true);
        } else {
            $("#helpBlocktitle").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    })
    //預設判斷
    if ($("#imgidbox").length == '1') {
        $("#helpBlockimgid").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    }
    //選擇圖片
    $("body").on("change", "[name=upfile]", function() {
        if ($(this).val()) {
            $("#helpBlockimgid").hide().text(true);
        } else {
            $("#helpBlockimgid").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    })
    //預設判斷
    if (CKEDITOR.instances.content.getData()) {
        $("#helpBlockcontent").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    }
    //內容
    $("body").on("click", $(this), function() {
        if (CKEDITOR.instances.content.getData()) {
            $("#helpBlockcontent").hide().text(true);
        } else {
            $("#helpBlockcontent").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach4', $id = '#textblockbox');
    })
}




//全國據點空欄位判斷
function neothemesadmin_nationalbaseform() {
    //預設判斷
    if ($("[name=unit]").val()) {
        $("#helpBlockunit").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    }
    //單位名稱
    $("body").on("change", "[name=unit]", function() {
        if ($(this).val()) {
            $("#helpBlockunit").hide().text(true);
        } else {
            $("#helpBlockunit").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    })
    //預設判斷
    if ($("[name=phone]").val()) {
        $("#helpBlockphone").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    }
    //單位電話
    $("body").on("change", "[name=phone]", function() {
        if ($(this).val()) {
            $("#helpBlockphone").hide().text(true);
        } else {
            $("#helpBlockphone").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    })
    //預設判斷
    if ($("[name=of_cityid2]").val()) {
        $("#helpBlockaddress").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    }
    //單位地址
    $("body").on("change", "[name=of_cityid2]", function() {
        if ($(this).val()) {
            $("#helpBlockaddress").hide().text(true);
        } else {
            $("#helpBlockaddress").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    })
    //預設判斷
    if ($("[name=remark]").val()) {
        $("#helpBlockremark").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    }
    //備註說明
    $("body").on("change", "[name=remark]", function() {
        if ($(this).val()) {
            $("#helpBlockremark").hide().text(true);
        } else {
            $("#helpBlockremark").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach3', $id = '#nationalbasebox');
    })
}
//聯絡我們表單驗證
function neothemesadmin_contactusform() {
    //必填欄位-姓名
    $("body").on("change", "#name_user", function() {
        if ($(this).val()) {
            $("#helpBlockname_user").hide().text(true);
        } else {
            $("#helpBlockname_user").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach1', $id = '#contactusform');
    })
    //必填欄位-E-MAIL
    $("body").on("change", "#email_user", function() {
        $Emailchecking = IsEmail($(this).val());
        if ($Emailchecking == false) {
            swal(jstextArr['mailtext']);
            $("#email_user").blur(); //離開焦點	
            $("#helpBlockemail_user").show().text(jstextArr['required']);
        } else {
            $("#helpBlockemail_user").hide().text(true);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach1', $id = '#contactusform');
    })
    //必填欄位-手機
    $("body").on("change", "#tel_user", function() {
        $Ephonechecking = Isphone($(this).val());
        if ($Ephonechecking == false) {
            swal(jstextArr['phonetext']);
            $("#tel_user").blur(); //離開焦點
            $("#helpBlocktel_user").show().text(jstextArr['required']);
        } else {
            $("#helpBlocktel_user").hide().text(true);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach1', $id = '#contactusform');
    })
    //必填欄位-說明事項
    $("body").on("change", "#texe_user", function() {
        if ($(this).val()) {
            $("#helpBlocktexe_user").hide().text(true);
        } else {
            $("#helpBlocktexe_user").show().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach1', $id = '#contactusform');
    })
    //我不是機器人
    $("body").on("change", ".notarobot1", function() {
        $(".checkboxmycheck1").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach1', $id = '#contactusform');
    })
}
//聯絡我們區塊表單驗證
function neothemesadmin_contactusblocksform() {
    //必填欄位-姓名
    $("body").on("change", "#blockname_user", function() {
        if ($(this).val()) {
            $("#help-blockblockname_user").hide().text(true);
        } else {
            $("#help-blockblockname_user").hide().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach2', $id = '#onlineconsultationblock');
    })
    //必填欄位-手機
    $("body").on("change", "#blocktel_user", function() {
        $Ephonechecking = Isphone($(this).val());
        if ($Ephonechecking == false) {
            swal(jstextArr['phonetext']);
            $("#blocktel_user").blur(); //離開焦點
            $("#help-blockblocktel_user").hide().text(jstextArr['required']);
        } else {
            $("#help-blockblocktel_user").hide().text(true);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach2', $id = '#onlineconsultationblock');
    })
    //必填欄位-E-MAIL
    $("body").on("change", "#blockemail_user", function() {
        $Emailchecking = IsEmail($(this).val());
        if ($Emailchecking == false) {
            swal(jstextArr['mailtext']);
            $("#blockemail_user").blur(); //離開焦點	
            $("#help-blockblockemail_user").hide().text(jstextArr['required']);
        } else {
            $("#help-blockblockemail_user").hide().text(true);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach2', $id = '#onlineconsultationblock');
    })
    //必填欄位-說明事項
    $("body").on("change", "#blocktexe_user", function() {
        if ($(this).val()) {
            $("#help-blockblocktexe_user").hide().text(true);
        } else {
            $("#help-blockblocktexe_user").hide().text(jstextArr['required']);
        }
        neothemesadmin_emptyfield($blockeach = 'blockeach2', $id = '#onlineconsultationblock');
    })
    //我不是機器人
    $("body").on("change", ".notarobot2", function() {
        $(".checkboxmycheck2").hide().text(true);
        neothemesadmin_emptyfield($blockeach = 'blockeach2', $id = '#onlineconsultationblock');
    })
}
//欄位空值判斷-模組
function neothemesadmin_emptyfield($blockeach, $id) {
    $("" + $id + "  ." + $blockeach + "").each(function(index) {
        if ($(this).text() == 'true') {
            $contactusresult = true;
        } else {
            $contactusresult = false;
            return false;
        }
    });
    if ($contactusresult == true) {
        $("" + $id + " .contentbtn").attr('disabled', false);
        $("#help-blocktext").hide();
    } else {
        $("" + $id + " .contentbtn").attr('disabled', true);
        $("#help-blocktext").show();
    }
    //防重複提交表單
    $("body").on("click", "" + $id + " .contentbtn", function() {
        $(this).hide();
    })
}

/*
//E-MAIL格式檢查
function IsEmail(email) {
    var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!regex.test(email)) {
        return false;
    } else {
        return true;
    }
}
//手機格式檢查
function Isphone(phone) {
    var regex = /^[0-9]+$/;
    if (!regex.test(phone)) {
        return false;
    } else {
        return true;
    }
}

*/