/*厂商机型列表*/
function SetPhoneList(brand,phone) {
    var brand = $("#"+brand).val();
    var phoneObject = document.getElementById(phone);
    phoneObject.options.length = 0;
    phoneObject.options[0] = new Option("手机型号", "");

    for (i = 0; i < plist.length; i++) {
        if (brand == plist[i][0]) {
            for (j = 0; j < plist[i][1].length; j++) {
                phoneObject.options[j + 1] = new Option(plist[i][1][j][1], plist[i][1][j][0]);
            }
        }
    }
}
function ShowBrand(brand,phone,select, boxid) {
    var selObj = document.createElement("select");
    selObj.name = brand;
    selObj.id = brand;
    selObj.onchange = function() {
        SetPhoneList(brand, phone);
    };
    document.getElementById(boxid).appendChild(selObj);
    selObj.options.length = 0;
    selObj.options[0] = new Option("手机厂商", "");
    for (i = 0; i < blist.length; i++) {
        selObj.options[i+1] = new Option(blist[i][1], blist[i][0]);
    }
    $("#"+brand).val(select);
}
function ShowPhone(brand,phone,select, boxid) {

    var selObj = document.createElement("select");
    selObj.name = phone;
    selObj.id = phone;
    selObj.onchange = function() {
        SetPhoneImage(brand,phone);
    };
    document.getElementById(boxid).appendChild(selObj);
    SetPhoneList(brand, phone);
    //设置选中
    $("#" + phone).val(select);
    SetPhoneImage(brand, phone);

}
function SetPhoneImage(brand,phone) {
        var b = $("#" + brand), p = $("#" + phone);
        if (p.val() > 0) {
            $("#phoneName").text(p.find("option:selected").text());
            $("#phoneImage").find('img').attr('src', '/images/ajax_load.gif');
            $.getJSON(softDomain + '/phone.php?act=phoneimage&phoneid=' + p.val() + '&phonename=' + p.find("option:selected").text() + "&callback=?", function(data) {
                $("#phoneImage").find('img').attr('src', data[0]);
                if (p.val() == "") { $("#state").html("设置机型"); } else { $("#state").html("当前机型"); }
            });
            $.getJSON(softDomain + '/soft.php?act=softcount&callback=?', function(data) {
                $(".g2c a").each(function(i) {
                    $(this).html(data[i]);
                });
            });
        }
}
function SetPhone() {
    var p = $("#phone");
    if (p.val() != "") {
        $.post(softDomain+"/phone.php", { "act": "set", "phoneid": p.val(), "r": Math.random() }, function(data) {
            if (data == "1") {  window.location.reload(); } else { alert('网络错误，请重试'); }
        });
    }
    else {
        alert("请选择您的手机型号");
    }
}
function ClearPhone() {
    $.post(softDomain + "/phone.php", { "act": "clear", "r": Math.random() }, function(data) {
        if (data == "1") { window.location.reload(); } else { alert('网络错误，请重试'); }
    });
}
function ChangePhone() {
    $("#hasPhone").hide(); $("#noPhone").show();
}
function AddSoftCom() {
    var content = $('#content').val();
    if (content != "" && content != $('#content').attr('title')) {
        $.getJSON(softDomain + '/soft.php', { "act": 'addcomment', "id": $('#softid').val(), "content": content, "r": Math.random() }, function(data) {
            $("#comment_list").load(softDomain+'/soft.php?act=softcomment&id=' + $('#softid').val() + '&r=' + Math.random()); 
        });
    }
}
function UserLogin(callback) {
    $("#loginform").validate({
        onfocusout: false,
        errorPlacement: function(error, element) {
            $("#tishi").html(error.html());
        },
        submitHandler: function(form) {
            var autologin = $("#autologin").attr("checked") ? 1 : 0;
            var u = $('#username').val();
            var p = $('#password').val();
            var url = $('#r').val();
            $.getJSON(wwwDomain + "/login.php?act=ajax&u=" + encodeURI(u) + "&p=" + p + "&url=" + url + "&auto=" + autologin + "&callback=?",
             function(json) {
                 if (!json[0]) {
                     if (json[1] == -8) {
                         $("#tishi").html('用户名不存在，请重新输入');
                         return;
                     }
                     if (json[1] == -9) {
                         $("#tishi").html('用户名密码不匹配，请重新输入');
                         return;
                     }
                     if (json[1] <= 0 && json[1] > -7) {
                         location.href = wwwDomain + "/login.php?act=bbsimport&userid="+json[2];
                         return;
                     }
                 }
                 else {

                     if (callback == 1) { $.reloadPopupLayer('down_step'); $("body").append(json[1]); }
                     else { location.href = wwwDomain + "/redirect.php?redirectURL=" + $('#r').val() + "&do=login"; }

                 }
             });
        },
        rules: {
            username: { required: true },
            password: { required: true }
        },
        messages: {
            username: { required: "请输入用户名" },
            password: { required: "请输入密码" }
        }
    });
    
}
function SoftSearch() {
    window.location.href = softDomain + '/soft.php?act=search&key=' + $("#key").val();
}
function FixPNG(myImage) {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5) && (version < 7) && (document.body.filters)){
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
        var imgTitle = (myImage.title) ? "title='" + myImage.title   + "' " : "title='" + myImage.alt + "' ";
        var imgStyle = "display:inline-block;" + myImage.style.cssText;
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + myImage.width
         + "px; height:" + myImage.height
         + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
       myImage.outerHTML = strNewHTML;
    } 
}



