var showd = function(){
var str=$("#tradewd").val();
if (str=="" || str=="Product/Buying Lead No."){
	alert('Please input Product/Buying Lead No.');
	$("#tradewd").select().focus();
	return false;
}
str=$.trim(str).toUpperCase();
var pattens=/^(TEN|BEN)\d{0,11}$/;
	if (pattens.test(str))
	{
			if (str.substring(0,1)=="T")
			{
			var url='http://d.gongchang.com/product/'+str.substring(3);
			}
			else
			{
			var url='http://d.gongchang.com/buy/'+str.substring(3);	
			}
			window.open(url,"");
	}
	else
	{
		alert('The Product or Buying Lead No. you entered is incorrect.');
		$("#tradewd").select().focus();
		return false;
	}
}
$(function(){		   
	//为右侧表单添加点击和提交事件
	$('#tradewd').parent('form').submit(function(){
		return showd();
	})
	//为右侧表单的输入框添加事件
	$('#tradewd').click(function(){
		var val = $(this).val();
		if( (val == 'Product/Buying Lead No.')||($(this).attr('defaultvalues')) == 'true'){
			$(this).val('');
		}
		$(this).css('color','#000').attr('defaultvalues','false');
	}).blur(function(){
		var val = $(this).val();
		if( val == ''){
			$(this).val('Product/Buying Lead No.').css('color','#666');
		}
	})	
	$(".sideElement").hover(
		 function(){
			$(this).removeClass();
			$(this).addClass("sideElement zindex");
			var setop = $(this).offset().top;
			//console.log(setop);
			var ul = $(this).find("ul");
			//var x = $(document).height() - setop;
			//页面滚卷部分高度
			var scrolltop = $(document).scrollTop();
			//页面显示部分高度
			var windowheight = $(window).height();
			var x = (setop+ul.height())-(scrolltop+windowheight);
			//x = Math.round(x/26)*26;
			x = x+4;
			if(x > 0) {
				ul.css({
				   top: -x+"px", 
				   "border-top":"3px solid #5F7EAA"
				});
			} else {
				ul.css({
					 top: "0px",
					 "border-top":"0px solid #5F7EAA"
				});
			}			
		},
	function(){
			$(this).removeClass();
			$(this).addClass("sideElement");
		})
})
//鼠标悬停后切换图片
$(function(){
	$("#cStab>ul>li").mouseover(function(){
		var sib = $(this).prevAll().size();
		$(this).addClass('select').siblings('li').removeClass('select');
		$("#cSimg").children('a').eq(sib).show().siblings().hide();
	})
})
//webSiteTab
$(document).ready(function() {
	//When page loads...
	$(".tabContents").hide(); //Hide all content
	$("ul.websiteInfoTabsBox li:first").addClass("active first").show(); //Activate first tab
	$("ul.websiteInfoTabsBox li:last").addClass("last").show();
	$(".tabContents:first").show(); //Show first tab content
 
	//On Click Event
	$("ul.websiteInfoTabsBox li").mouseover(function() {
		$("ul.websiteInfoTabsBox li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tabContents").hide(); //Hide all tab content
 
		var activeTab = $(this).find("a").attr("id"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content  $(activeTab).fadeIn();
 
	});
});
//index scroll
(function($){
     var ELMS = [];
     $.fn.jdNewsScroll = function(settings) {
        settings = $.extend({}, arguments.callee.defaults, settings);
    $(this).css({"overflow":"hidden","width":settings.divWidth,"height":settings.divHeight});
    $(this).find("ul").css({"list-style-type":"none","font-size":settings.fontSize,"margin":"0px"});
    //$(this).find("li").css({"line-height":"130%","margin":"0px","padding":"2px 10px 1px 10px"});
	$(this).find("li:even").addClass('even');
        $(this).each(function(){
            this.$settings    = settings;
            this.$pause = false;
            this.$counter    = settings.beginTime;
            $(this).hover(function(){ $(this).jdNewsScrollPause(true) }, function(){ $(this).jdNewsScrollPause(false) });
            ELMS.push(this);
        });
        return this;
    };
    $.fn.jdNewsScroll.defaults = {
        beginTime: 0,
        fontSize: '9pt',
        divWidth: '237px',
        divHeight: '150px',
        lineHeight: '',
        delay:20,
        step:2
    };
    $.fn.jdNewsScrollPause = function(pause) {
        return this.each(function() {
            this.$pause = pause;
        });
    }
    function outerHeight(options) {
        if (!this[0]) 0;
        options = $.extend({ margin: false }, options || {});
        return this[0] == window || this[0] == document ?
            this.height() : this.is(':visible') ?
                this[0].offsetHeight + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0) :
                this.height() 
                    + num(this,'borderTopWidth') + num(this, 'borderBottomWidth') 
                    + num(this, 'paddingTop') + num(this, 'paddingBottom')
                    + (options.margin ? (num(this, 'marginTop') + num(this, 'marginBottom')) : 0);
    }
    setInterval(scroll, 80);
    function scroll() {
        for (var i = 0; i < ELMS.length; i++) {
            var elm = ELMS[i];
            if (elm && !elm.$pause) {
                if (elm.$counter == 0) {
                    var ul     = $('> ul', elm)[0];
                    if (!elm.$steps) {
                        elm.$steps = $('> li:first-child', ul).outerHeight();
                        elm.$step    = 0;
                    }
                    if ((elm.$steps + elm.$step) <= 0) {
                        elm.$counter     = elm.$settings.delay;
                        elm.$steps         = false;
                        $(ul).css('top', '0').find('> li:last-child').after($('> li:first-child', ul));
                        $('> *', ul).not('li').remove();
                    } else {
                        elm.$step -= elm.$settings.step;
                        if (-elm.$step > elm.$steps) {
                            elm.$step = -elm.$steps;
                        }
                        ul.style.top = elm.$step + 'px';
                    }
                } else {
                    elm.$counter--;
                }
            }
        }
    };
})(jQuery);
$(function() {
$('#LastSellColumnBox1').jdNewsScroll({divWidth:237,divHeight:150,fontSize:'12px'});
$('#LastSellColumnBox2').jdNewsScroll({divWidth:240,divHeight:150,fontSize:'12px',beginTime:20});
var color;
$(".hotkey-content a").hover(function(){
	color = $(this).css('color');    
	$(this).css({'color':'#22700A'})
},function(){
	$(this).css({'color':color})
})
});
