﻿/// <reference path="../../Common/js/JQuery/jquery-1.3.2-vsdoc2.js" />

$(document).ready(function() {

    var $kw = $('#keyword');
    var lastKw = initKeyWord();
    if (lastKw != "")
        $kw.val(lastKw);
    if ($kw.val() != '请输入您要搜索商品的关键字 如：联想') {
        $kw.css('color', '#444');
    }

    $('#keyword').click(function() {
        if ($kw.val() == '请输入您要搜索商品的关键字 如：联想') {
            this.value = '';
        }
        $(this).css('color', '#444');
        return false;
    });
    $('.submit').mouseover(function() {
        $(this).css('cursor', 'pointer');
    }).click(function() {
        $(this).blur();
    });

    $('.arrowlistmenu>ul').each(function() {
        $(this).children('li').filter(':gt(4)').hide();
        if ($(this).children('li').size() > 4) {
            $(this).append('<li class="b"><a href=\"javascript:void(0);\">更多&raquo;</a></li>');
            $(this).children('li:last').show().toggle(
            function() {
                $(this).html('<a href="javascript:void(0);">&laquo;收起</a>');
                $(this).siblings().show();
            },
            function() {
                $(this).html('<a href="javascript:void(0);">更多&raquo;</a>');
                $(this).siblings().filter(':gt(4)').hide();
            }
            );
        }
    });

    $('#searchSort').change(function() {
        location.href = $(this).find('option').filter(':selected').val();
    });

});

$(document).ready(function() {
    if ($.trim($('.product_title').html()) == '请先选择商品') {
        $('.selectcity').hide();
    }
    $('#selProvince>select').change(function() {
        if ($(this).find('option').filter(':selected').val() != '0') {
            var selValue = $(this).find('option').filter(':selected').val();
            $('#selCity').html('&nbsp;-&nbsp;' + addressajax.GetCity(selValue).value);
            $('#agentshop').html(xgoushopajax.GetProvinceAgentShop(selValue).value);
            $('#userInfo').hide();
            $('#selTown').html('');
        }
        else {
            $('#selCity').html('');
            $('#selTown').html('');
        }
        AgGangChangeHeight();
        //$(this).append(addressajax.GetCity($(this).find('option').filter(':selected').val()).value);
    });
});

$(document).ready(function() {
    $('#selProvince_View>select').change(function() {
        if ($(this).find('option').filter(':selected').val() != '0') {
            var selValue = $(this).find('option').filter(':selected').val();
            $('#selCity_View').html('&nbsp;-&nbsp;' + addressajax.GetCity_View(selValue).value);
            $('#selTown_View').html('');
            $('#agentshop').html(xgoushopajax.GetProvinceAgentShop_View(selValue).value);
        }
        else {
            $('#selCity').html('');
            $('#selTown').html('');
        }
        AgGangChangeHeight();
        //$(this).append(addressajax.GetCity($(this).find('option').filter(':selected').val()).value);
    });
    if ($('#selProvince_View').size() > 0) {
        if ($('#selProvince_View>select').find('option').filter(':selected').val() != '0') {
            var selValue = $(this).find('option').filter(':selected').val();
            $('#selCity_View').html('&nbsp;-&nbsp;' + addressajax.GetCity_View(selValue).value);
            $('#selTown_View').html('');
            $('#agentshop').html(xgoushopajax.GetProvinceAgentShop_View(selValue).value);
        }
        else {
            $('#selCity').html('');
            $('#selTown').html('');
        }
        AgGangChangeHeight();
    }
});

$(document).ready(function() {
    $('#pricebtn').click(function() {
        var $low = $('#pricelow');
        var $high = $('#pricehigh');
        if (isEmptyStr($low.val()) && isEmptyStr($high.val())) {
            alert('请输入价格！');
            $low.focus();
            return;
        }
        if (!isEmptyStr($low.val()) && !isInteger($low.val())) {
            alert('请输入整数！');
            $low.focus();
            return;
        }
        if (!isEmptyStr($high.val()) && !isInteger($high.val())) {
            alert('请输入整数！');
            $high.focus();
            return;
        }
        if (!isEmptyStr($low.val()) && !isEmptyStr($high.val()) && parseInt($high.val()) < parseInt($low.val())) {
            alert('请按从小到大的顺序输入价格区间');
            return;
        }
        var url;
        if ($('#priceurl').val().indexOf('?') == -1) {
            url = $('#priceurl').val() + '?price=' + $low.val() + '-' + $high.val();
        }
        else {
            url = $('#priceurl').val() + '&price=' + $low.val() + '-' + $high.val();
        }
        window.location.href = url;
    });
});

var CheckForm = function() {
    if ($("input[name='radioAgent']:checked").val() == undefined) {
        alert('请选择经销商');
        return false;
    }
    if (isEmptyStr($('#txtName').val())) {
        alert('请输入用户名');
        $('#txtName').focus();
        return false;
    }

    if ($("input[name='radioType']:checked").val() == undefined) {
        alert('请选择用户类型');
        return false;
    }

    if (isEmptyStr($('#txtTelPhone').val()) && isEmptyStr($('#txtMobilePhone').val())) {
        alert('请输入电话或手机');
        $('#txtTelPhone').focus();
        return false;
    }

    if (isEmptyStr($('#txtAddress').val())) {
        alert('请输入地址');
        $('#txtAddress').focus();
        return false;
    }
    return true;
};

function trimStr(str) { if (str == undefined || str == null) return ''; return str.replace(/(^\s*)|(\s*$)/g, ''); }
function isEmptyStr(obj) { return '' == trimStr(obj); }

var FillCity = function() {
    if ($('#selCity>select').find('option').filter(':selected').val() != '0') {
        var selValue = $('#selCity>select').find('option').filter(':selected').val();
        //$('#selTown').html('&nbsp;-&nbsp;' + addressajax.GetTown(selValue).value);
        $('#agentshop').html(xgoushopajax.GetCityAgentShop(selValue).value);
        $('#userInfo').hide();
    }
    else {
        $('#selTown').html('');
    }
    AgGangChangeHeight();
};

var FillTown = function() {
    if ($('#selTown>select').find('option').filter(':selected').val() != '0') {
        var selValue = $('#selTown>select').find('option').filter(':selected').val();
        $('#agentshop').html(xgoushopajax.GetTownAgentShop(selValue).value);
        $('#userInfo').hide();
    }
    AgGangChangeHeight();
};

var FillCity_View = function() {
    if ($('#selCity_View>select').find('option').filter(':selected').val() != '0') {
        var selValue = $('#selCity_View>select').find('option').filter(':selected').val();
        //$('#selTown_View').html('&nbsp;-&nbsp;' + addressajax.GetTown_View(selValue).value);
        $('#agentshop').html(xgoushopajax.GetCityAgentShop_View(selValue).value);
    }
    else {
        $('#selTown').html('');
    }
    AgGangChangeHeight();
};

var FillTown_View = function() {
    if ($('#selTown_View>select').find('option').filter(':selected').val() != '0') {
        var selValue = $('#selTown_View>select').find('option').filter(':selected').val();
        $('#agentshop').html(xgoushopajax.GetTownAgentShop_View(selValue).value);
    }
    AgGangChangeHeight();
};

var checkSubmit = function() {
    if (isEmptyStr($('#keyword').val()) || $('#keyword').val() == '请输入您要搜索商品的关键字 如：联想') {
        alert('请输入关键词');
        return false;
    }
    return true;
};

var isInteger = function(strInteger) {
    return strInteger.match(/^\d+$/);
}

var ShowSubmit = function() {
    $('#userInfo').show();
    AgGangChangeHeight();
}

var initKeyWord = function() {
    var t = window.location.href;
    var kw = "";
    var re = new RegExp("[\?&](wd=[^\&]{1,})", "ig");
    var arr = re.exec(t);
    if (arr != null) {
        kw = RegExp.$1.split('=')[1];
        kw = decodeURI(kw);
    }
    return kw;
}