﻿/// <reference path="../../Common/js/JQuery/jquery-1.3.2-vsdoc2.js" />

$(document).ready(function() {

    var $kw = $('#keyword');
    var lastKw = initKeyWord();
    //var lastKw = encodeURI($('#keyword').val());
    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() {
    $('#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;
    });
});

function trimStr(str) { if (str == undefined || str == null) return ''; return str.replace(/(^\s*)|(\s*$)/g, ''); }
function isEmptyStr(obj) { return '' == trimStr(obj); }

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;
}

function search(id) {
    var selKey = document.getElementById(id).value;
    if (selKey == '') {
        window.location = '/Search/search2.aspx';
        return;
    }
    window.location = '/Search/search2.aspx?wd=' + encodeURI(selKey);
}