﻿/// <reference path="../../jQuery-vsdoc.js" />
function vod(){}

//encodeURIComponent可以还处理utf-8编码
function EncodeURL(str){
	return encodeURIComponent(str).replace(/\+/g,"%2b");
}
function escape2(str){
	return escape(str).replace(/\+/g,"%2b");
}

//获取地区
function getSubAreas(provinces, citys) {
    $("#" + citys).get(0).length = 1;
    if ($("#" + provinces).get(0).selectedIndex == 0 || $("#" + provinces).val() == "") {
		//当一级菜单未选中时，二级菜单仅保留提示项
		return;
	}
	$.ajax({
	    url: "/common/ajax.aspx",
	    type: "GET",
	    cache: false,
	    dataType: "text",
	    data: { action: "getSubAreas", prid: EncodeURL($("#" + provinces).val()) },
	    success: function(transport) {
	        if (transport != "0") {//获取成功后，将数据填充到二级下拉框
	            var _arr = eval("(" + transport + ")");
	            for (var i = 0; i < _arr.length - 1; i += 2)
	            {
	                with ($("#" + citys).get(0))
	                {
	                    options[options.length] = new Option(_arr[i], _arr[i + 1]);
	                }
	            }
	        }
	    }
	});

}

//function getModels() {
//    $("#modelid").get(0).length = 1;
//    if ($("#makeid").get(0).selectedIndex == 0 || $("#makeid").val() == "0") {
//        return;
//    }
//    $.ajax({
//        url: "/common/ajax.aspx",
//        type: "GET",
//        cache: false,
//        dataType: "text",
//        data: { action: "getModels", makeid: EncodeURL($("#makeid").val()) },
//        success: function(transport) {
//            if (transport != "0") {//获取成功后，将数据填充到二级下拉框
//                var _arr = eval("(" + transport + ")");
//                for (var i = 0; i < _arr.length - 1; i += 2) {
//                    with ($("#modelid").get(0)) {
//                        options[options.length] = new Option(_arr[i], _arr[i + 1]);
//                    }
//                }
//            }
//        }
//    });
//}

//function getYears() {
//    $("#kitsid").get(0).length = 1;
//    if ($("#modelid").get(0).selectedIndex == 0 || $("#modelid").val() == "0") {
//        return;
//    }
//    $.ajax({
//        url: "/common/ajax.aspx",
//        type: "GET",
//        cache: false,
//        dataType: "text",
//        data: { action: "getYears", modelid: EncodeURL($("#modelid").val()) },
//        success: function(transport) {
//            if (transport != "0") {//获取成功后，将数据填充到二级下拉框
//                var _arr = eval("(" + transport + ")");
//                for (var i = 0; i < _arr.length - 1; i += 2) {
//                    with ($("#kitsid").get(0)) {
//                        options[options.length] = new Option(_arr[i], _arr[i + 1]);
//                    }
//                }
//            }
//        }
//    });
//}

function getYears() {
    $("#kitsid").get(0).length = 1;
    if ($("#makeid").get(0).selectedIndex == 0 || $("#makeid").val() == "0") {
        return;
    }
    $.ajax({
        url: "/common/ajax.aspx",
        type: "GET",
        cache: false,
        dataType: "text",
        data: { action: "getYears", makeid: EncodeURL($("#makeid").val()) },
        success: function(transport) {
            if (transport != "0") {//获取成功后，将数据填充到二级下拉框
                var _arr = eval("(" + transport + ")");
                for (var i = 0; i < _arr.length - 1; i += 2) {
                    with ($("#kitsid").get(0)) {
                        options[options.length] = new Option(_arr[i], _arr[i + 1]);
                    }
                }
            }
        }
    });
}

function getKits() {
    //    if ($("#kitsid").get(0).selectedIndex == 0 || $("#kitsid").val() == "0") {
    //        $("#kitcontent").html("Please select all options in the top!");
    //        return;
    //    }
    //    $.ajax({
    //        url: "/common/ajax.aspx",
    //        type: "GET",
    //        cache: false,
    //        dataType: "text",
    //        data: { action: "getKits", kitsid: EncodeURL($("#kitsid").val()) },
    //        success: function(transport) {
    //            $("#kitcontent").html(transport);
    //        }
    //    });
    
    if ($("#kitsid").get(0).selectedIndex == 0 || $("#kitsid").val() == "0") {
        $("#kitcontent").html("Please select all options in the top!");
        return;
    }
    //window.location.href = "/catalogues_" + $("#makeid").val() + "_" + $("#kitsid").val() + ".aspx";
    window.location.href = "/catalogues-detail.aspx?makeid=" + $("#makeid").val() + "&kitsid=" + $("#kitsid").val();
}


function savebook() {
    if ($.trim($("#name").val()) == "") {
        alert("Name can't be empty!");
        $("#name").focus();
        return;
    }
    if ($.trim($("#email").val()) == "") {
        alert("Email can't be empty!");
        $("#email").focus();
        return;
    }
    if ($.trim($("#subject").val()) == "") {
        alert("Subject can't be empty!");
        $("#subject").focus();
        return;
    }
    if ($.trim($("#mes").val()) == "") {
        alert("Message can't be empty!");
        $("#mes").focus();
        return;
    }
    if ($.trim($("#checkcode").val()) == "") {
        alert("Code can't be empty!");
        $("#checkcode").focus();
        return;
    }
    $.ajax({
        url: "/common/Ajax.aspx",
        type: "POST",
        cache: false,
        dataType: "text",
        data: { action: "savebook", name: $.trim($("#name").val()), tel: $.trim($("#tel").val()), email: $.trim($("#email").val()), subject: $.trim($("#subject").val()),mes: $.trim($("#mes").val()), checkcode : $.trim($("#checkcode").val()) },
        success: function(transport) {
            if (transport == "1") {
                $("#name").val("");
                $("#email").val("");
                $("#tel").val("");
                $("#subject").val("");
                $("#mes").val("");
                $("#checkcode").val("");
                $("#vcode")[0].src = "/common/ValidateCode.aspx?s=" + Math.random();
                alert("Submitted successfully,Thank you!");
            } else {
                alert("Failure to submit!");
            }
        }
    });  
}
