﻿var AlertMsg = "斑马/UPS/FEDEX/DHL/TNT等单号查询";
$(function() {
    $(".indexNews .indexLeftTab dt:first,.indexTools .indexLeftTab dt:first,.indexMiddleLink .indexLeftTab dt:first").addClass("current");
    $(".indexNews .indexLeftTabInfo:first,.indexTools .indexLeftTabInfo:first,.indexMiddleLink .indexLeftTabInfo:first").show();
    $(".indexLeftTab dt").hover(function() {
        $(this).parent().parent().find(".indexLeftTabInfo").hide().eq($(this).parent().find("dt").removeClass().index($(this).addClass("current"))).show();
    });

    $(".indexMiddlePicTab li span").hover(function() {
        $(".indexMiddlePicInfo").hide().eq($(".indexMiddlePicTab li span").removeClass().index($(this).addClass("current"))).show();
    });

    $(".indexMiddlePicInfoTab img").hover(function() {
        for (i = 1; i < 4; i++) {
            $(this).parent().find("img:eq(" + (i - 1) + ")").attr("src", "images/page/index/middleTabPic0" + i + ".gif");
        }
        var _middleBigImg = $(this).attr("bigimg");
        $(this).parent().parent().find("p img").hide();
        $(this).parent().parent().find("p img").fadeIn("fast");
        $(this).parent().parent().find("p img").attr("src", _middleBigImg);
        $(this).parent().parent().find("p img").attr("index", 1 + $(".indexMiddlePicInfoTab img").index($(this))); ///yyy
        var _middleTabIndex = $(".indexMiddlePicInfoTab img").index(this) + 1;
        $(this).attr("src", "images/page/index/middleTabPic0" + _middleTabIndex + "Hover.gif");
    }, function() {
        $(".indexMiddlePicInfo p img").show();
    });

    $($(".indexMiddlePicInfoTab img")).parent().parent().find("p img").css("cursor", "pointer"); //yyy
    $($(".indexMiddlePicInfoTab img")).parent().parent().find("p img").click(function() {//yyy
        var type = $(this).attr("index") == null ? "1" : $(this).attr("index"); //yyy
        LinkTo("DS", type); //yyy
    }); ///yyy


    $(".indexMiddlePicInfoTab2 img").hover(function() {
        for (i = 4; i < 7; i++) {
            $(this).parent().find("img:eq(" + (i - 4) + ")").attr("src", "images/page/index/middleTabPic0" + i + ".gif");
        }
        var _middleBigImg2 = $(this).attr("bigimg");
        $(this).parent().parent().find("p img").hide();
        $(this).parent().parent().find("p img").fadeIn("fast");
        $(this).parent().parent().find("p img").attr("src", _middleBigImg2);
        $(this).parent().parent().find("p img").attr("index", 1 + $(".indexMiddlePicInfoTab2 img").index($(this))); ///yyy
        var _middleTabIndex2 = $(".indexMiddlePicInfoTab2 img").index(this) + 4;
        $(this).attr("src", "images/page/index/middleTabPic0" + _middleTabIndex2 + "Hover.gif");
    }, function() {
        $(".indexMiddlePicInfo p img").show();
    });
    $($(".indexMiddlePicInfoTab2 img")).parent().parent().find("p img").css("cursor", "pointer"); //yyy
    $($(".indexMiddlePicInfoTab2 img")).parent().parent().find("p img").click(function() {//yyy
        var type = $(this).attr("index") == null ? "1" : $(this).attr("index"); //yyy
        LinkTo("CC", type); //yyy
    }); ///yyy

    $(".indexRightTel li").hover(function() {
        $(".indexRightTelInfo").hide().eq($(".indexRightTel li").removeClass().index($(this).addClass("hover"))).show();
    });
    //$("#img_ValidateCode").click();
    $("#getAAEcodeCookie").val("");
});


function LinkTo(GoTo,type)
{
    if (GoTo == "DS") {
        if (type == "0") {
            window.location.href = "/collection";
        } else {
            window.location.href = "/collection/?type=" + type;
        }
    } else if (GoTo == "CC") {
        if (type == "0") {
            window.location.href = "/storage";
        } else {
        window.location.href = "/storage/?type=" + type;
        }
    }
}

function goTracking() {
    var isok = false;
    if ($("#getAAEcode").val() == AlertMsg) {
        alert('请输入追踪号码');
        $("#getAAEcode").focus();
        return false;
    }
    if ($("#getAAEcode").val() != "") {
        var aaecode = $('#getAAEcode').val();
        var reg1 = new RegExp("/\s+/g", "g"); //去除空格
        aaecode = aaecode.replace(reg1, "");
        var reg3 = new RegExp("\n", "g"); //替换成逗号
        aaecode = aaecode.replace(reg3, ",");
        var first = aaecode.substring(0, 1)
        if (first == ",") {
            aaecode = aaecode.substring(1, aaecode.length);
        }
        var end = aaecode.substring(aaecode.length - 1, aaecode.length);
        if (end == ",") {
            aaecode = aaecode.substring(0, aaecode.length - 1);
        }
        var strs = aaecode.split(',');
        if (strs.length > 20) {
            alert("最多输入20个查询号码（每行一个）");
            return false;
        }
        //$.cookie('aaecode', aaecode);
        $("#trackingno").val(aaecode);

    } else {
        alert('请输入追踪号码');
        $("#getAAEcode").focus();
        return false;
    }
    if ($("#getAAEcodeCookie").val() == "") {
        alert("请输入验证码");
        $("#getAAEcodeCookie").focus();
        return false;
    } else {
        var valibatecode = $("#getAAEcodeCookie").val()
        var strl = "/register/register.ashx?methods=sess";
        $.ajax({
            url: strl,
            cache: false, //设置是否缓存,当需要每次刷新都需要执行数据库操作的话，需要设置成为false
            async: false,
            success: function(data) {
                var contenttt = eval(data);
                if (contenttt != valibatecode) {
                    isok = false;
                    alert("验证码有误");
                    $("#getAAEcodeCookie").focus();
                } else {
                    isok = true;
                }
            }
        });
    }
    if (isok == true) {
        var HTML = "<form id='orderStatusForm' action='/program/tracking.aspx' method='post'>" +
                "<input type='hidden' value='" + aaecode + "' name='trackingno' id='trackingno'>" +
                "</form>";
        $("body").append(HTML);
        $("#orderStatusForm").submit();
    }
}

///追踪TextAra添加水印
$(document).ready(function() {
    $("#getAAEcode").val(AlertMsg);
    $("#getAAEcode").css({ "color": "#ccc" });
    $("#getAAEcode").focus(function() {
        if ($(this).val() == AlertMsg) {
            $("#getAAEcode").val("");
            $("#getAAEcode").css({ "color": "#000" });
        }
    });
    $("#getAAEcode").blur(function() {
        if ($.trim($("#getAAEcode").val()) == "") {
            $("#getAAEcode").val(AlertMsg);
            $("#getAAEcode").css({ "color": "#ccc" });
        }
    });
});
$(function(){
$("body").prepend('<div class="indexTopAd"><div class="website"><a href="/news/detail.aspx?id=362" class="detail">查看详情</a><a href="#" class="close">关闭</a></div></div>');
	$(".indexTopAd,.indexTopAd .website").delay(500).slideDown(500);
	$(".indexTopAd a.close").click(function(){
		$(".indexTopAd").slideUp(500);	
	});
});
