//前後台專用 javascript/*--- 陣列編碼 ---*/function msgEncode(msg){  return encodeURIComponent($.base64.encode($.toJSON(msg)));}/*--- 陣列解碼 ---*/function msgDecode(msg){  return $.evalJSON($.base64.decode(decodeURIComponent(msg)));}/*--- 字串編碼 ---*/function strEncode(msg){  return encodeURIComponent($.base64.encode(msg));}/*--- 字串解碼 ---*/function strDecode(msg){  return $.base64.decode(decodeURIComponent(msg));}/** * 判斷是否為數字 */function isNumber(number,obj) {    var check =  /^[0-9]*\.?[0-9]*$/;    if(check.test(number)){        if(obj==null){            return true;        }else{            return $(obj).val();        }    }    else{        if(obj==null){            return false;        }else{            $(obj).val(0);            return 0;        }    }}/** * 檢查庫存數是否可以讓此筆成為訂單 */function CheckProductStock(type,relevance_id,num) {    var response = Login('./_plugin/ajax.php?method=CheckProductStock&type='+strEncode(type)+'&relevance_id='+strEncode(relevance_id)+'&num='+strEncode(num));    return response;}/** * 取得此專案的第二層分類資訊 */function GetSecondCategoriesData(obj,layer) {    if(layer==''){        var data = Login('../login.php?method=GetSecondCategoriesData&id='+encodeURIComponent($(obj).val()));    } else {        var data = Login('ajax.php?method=GetSecondCategoriesData&id='+encodeURIComponent($(obj).val()));    }    if($('#second_categories_id').size()){        var tmp = data.split('-||-');        if(tmp[0]){            $('#second_categories_id')[0].options.length = 0;            for(var i=0;i<tmp.length;i++){                var temp = tmp[i].split("-|-");                var x = document.createElement("option");                x.text = temp[1];                x.value = temp[0];                try{                    $('#second_categories_id')[0].add(x,null);                }catch(ex){                    $('#second_categories_id')[0].add(x);                }                if(layer!=''){                    GetThirdCategoriesData($('#second_categories_id'),layer);                }            }        }    }else{        alert('找不到第二層分類下拉選單');    }}/** * 取得此專案的第三層分類資訊 */function GetThirdCategoriesData(obj,layer) {    if(layer==''){        var data = Login('../login.php?method=GetThirdCategoriesData&id='+encodeURIComponent($(obj).val()));    } else {        var data = Login('ajax.php?method=GetThirdCategoriesData&id='+encodeURIComponent($(obj).val()));    }    if($('#third_categories_id').size()){        var tmp = data.split('-||-');        if(tmp[0]){            $('#third_categories_id')[0].options.length = 0;            for(var i=0;i<tmp.length;i++){                var temp = tmp[i].split("-|-");                var x = document.createElement("option");                x.text = temp[1];                x.value = temp[0];                try{                    $('#third_categories_id')[0].add(x,null);                }catch(ex){                    $('#third_categories_id')[0].add(x);                }            }        }    }else{        alert('找不到第三層分類下拉選單');    }}/** * 功能說明：將驗證碼 轉成中文字顯示於圖片的alt和title * 資料輸入：自動取得 $_SESSION['Secure'] * 資料輸出：轉成中文字顯示該數字 例如123 => 一二三 */function SecureStr(location){    if(location =='private'){        var number = Login('ajax.php?method=getSecure');    }else{        var number = Login('login.php?method=getSecure');    }    var count = 0;    var result = '';    var tmp = '';    while(count < number.length){        tmp = number.substring(count,count+1);        switch(tmp){            case '-':                result += '負';                break;            case '1':                result += '一';                break;            case '2':                result += '二';                break;            case '3':                result += '三';                break;            case '4':                result += '四';                break;            case '5':                result += '五';                break;            case '6':                result += '六';                break;            case '7':                result += '七';                break;            case '8':                result += '八';                break;            case '9':                result += '九';                break;            case '0':                result += '零';                break;        }        count++;    }    $('#secure').attr('title','驗證碼請輸入阿拉伯數字：'+result);    $('#secure').attr('alt','驗證碼請輸入阿拉伯數字：'+result);}/** * 功能說明：取得城市索引，找出該城市下的鄉鎮 * 資料輸入：城市索引 * 資料輸出：鄉鎮選項 */function GetVillage(city_id,location) {    if(location=='back'){        var data = msgDecode(Login('../login.php?method=getVillage&city_id='+encodeURIComponent(city_id)));        var obj = $('#village_id');    }else{        var data = msgDecode(Login('ajax.php?method=getVillage&city_id='+encodeURIComponent(city_id)));        if(location=='contact'){            var obj = $('#village_id_contact');        }else{            var obj = $('#village_id_ship');        }    }    obj.html('');    $.each(data,function(key,val){        obj.append('<option value=\'' +key +'\'>' +val +'</option>');    })    GetZipCode(location);}function GetZipCode(location) {    if(location=='back'){        var tmp = '';        var zipCode = Login('../login.php?method=getZipCode&city_id='+encodeURIComponent($('#city_id'+tmp).val())+'&village_id='+encodeURIComponent($('#village_id'+tmp).val()));    }else{        var tmp = '_'+location;        var zipCode = Login('ajax.php?method=getZipCode&city_id='+encodeURIComponent($('#city_id'+tmp).val())+'&village_id='+encodeURIComponent($('#village_id'+tmp).val()));    }    if($('#city_id'+tmp).size()==1 && $('#village_id'+tmp).size()==1){        $('#zip'+tmp).val(zipCode);        $('#address'+tmp).val($('#city_id'+tmp+' :selected').html()+$('#village_id'+tmp+' :selected').html());    }}
