﻿$(function () {
    $("li.slideli").parent('ul').each(function () {
        $(this).children(":first").find("div").show();
    });
    $("li.slideli").mouseover(function () {
        $(this).parent('ul').find("div").hide();
        $(this).find("div").show();
    });
    //左侧弹出客服信息
    $("#clickopen").click(function () {
        var offset = $("#clickopen").offset().top;
        $("#page").css("top", offset + "px");
        $("#clickopen").hide();
        $("#page").animate({
            width: "375px",
            height: "365px",
            left: ($("body").width() / 2 - 200) + "px",
            top: (offset - 100) + "px",
            opacity: 'toggle'
        }, 500);

        return false;
    })

    $("#closepage").click(function () {
        var offset = $("#page").offset().top;
        $("#page").animate({
            width: "0px",
            height: "0px",
            left: "0px",
            top: (offset + 100) + "px",
            opacity: 'toggle'
        }, 500);
        $("#clickopen").show();
        return false;
    })
    //左侧弹出客服信息结束
})


// 滚动脚本 Begin ================================================
// 该脚本实现水平方向和垂直方向的无缝滚动功能
//-- 垂直滚动 --
function MarqueeV()
{
	if(oRollV2.offsetTop - oRollV.scrollTop <= 0)
	{
		oRollV.scrollTop -= oRollV1.offsetHeight;
	}
	else
	{
		oRollV.scrollTop++;
	}
}
function StartRollV()
{
	var rollspeed = 30;
	var myInter;

	if (typeof(oRollV) == "undefined")
	{
		return;
	}
	else
	{
		//alert(parseInt(oRollV.style.height) + ":" + oRollV2.offsetTop);
	}
	
	if (parseInt(oRollV.style.height) >= oRollV2.offsetTop)
	{
		oRollV.style.height = oRollV2.offsetTop;
		return;
	}
	oRollV2.innerHTML = oRollV1.innerHTML;
	myInter = setInterval(MarqueeV,rollspeed);
	oRollV.onmouseover = function() {clearInterval(myInter)};
	oRollV.onmouseout = function() {myInter = setInterval(MarqueeV, rollspeed)};
}
//-- 垂直滚动 --


//-- 水平滚动 --
function MarqueeH()
{
	if(oRollH2.offsetLeft - oRollH.scrollLeft <= 0)
	{
		oRollH.scrollLeft -= oRollH1.offsetWidth;
	}
	else
	{
		oRollH.scrollLeft++;
	}
}
function StartRollH()
{
	var rollspeed = 30;
	var myInter;

	if (typeof(oRollH) == "undefined")
	{
		return;
	}
	else
	{
		//alert(parseInt(oRollH.style.width) + ":" + oRollH2.offsetLeft);
	}
	if (parseInt(oRollH.style.width) >= oRollH2.offsetLeft)
	{
		oRollH.style.width = oRollH2.offsetLeft;
		return;
	}
	oRollH2.innerHTML = oRollH1.innerHTML;
	myInter = setInterval(MarqueeH,		rollspeed);
	oRollH.onmouseover = function() {clearInterval(myInter)};
	oRollH.onmouseout = function() {myInter = setInterval(MarqueeH, rollspeed)};
}
//-- 水平滚动 --

// 滚动脚本 End =================================================



// 显示/隐藏层函数
function showDiv(div)
{
	var el = document.getElementById(div);
	el.style.display = (el.style.display == 'none') ? 'block' : 'none';
}


//字符串连接操作类
function StringBuilder(sString)
{
	this.length=0;
	this.append=function(sString)
	{
		this.length+=(this._parts[this._current++]=String(sString)).length;
		this._string=null;
		return this;
	}

	this.toString = function()
	{
		if(this._string != null) return this._string;
		
		var s = this._parts.join("");
		this._parts		= [s];
		this._current	= 1;
		return this._string = s;
	}
	this._current	= 0;
	this._parts		= [];
	this._string	= null;
	
	if(sString != null) this.append(sString);
}
//var str=new StringBuilder();
//str.append("a");
//str.append("b");
//alert(str.toString());

//============================================
// 查看公告：打开一个自定义的窗口
// url		: 路径
// width	: 窗口的宽度
// height	: 窗口的高度
// condition: 对窗口属性的限制条件
//============================================
function openScript(url, width, height, condition)
{
	var newWindow = window.open(url,"openScript","width=" + width + ",height=" + height + "," + condition);
}


//============================================
// 查看公告：打开一个新的自定义窗口
// id		: 公告ID
//============================================
function ViewAnn(id) {
	var annWindow = window.open("Default/ViewAnn" + id + ".shtml", "ViewAnn","width=550,height=400,left=0,top=0,scrollbars=1,status=1,resizable=0");
	
	annWindow.focus();
}


//============================================
// 查看投票：打开一个新的自定义窗口
// id		: 投票ID
//============================================
function ViewVote(id) {
	var voteWindow = window.open("Default/Vote" + id + ".shtml?action=view", "Vote","width=500,height=400,left=0,top=0,scrollbars=1,status=1,resizable=0");
	
	voteWindow.focus();
}


//============================================
// 输出导航菜单
// img:导航菜单项目间隔图片
//============================================
function writeMenu(img)
{
	var outstr = "";

	for( var i = 0; i < myaClass1.classID.length; i++ )
	{
		var index = 0;
		var items = new Array();
		
		var blank = "";
		var color = "";
		
		blank = ( myaClass1.newWin[i] == "1" ? "_blank" : "" );
		color = ( myaClass1.color[i] != "" ? myaClass1.color[i] : "" );

		for( var j = 0; j < myaClass2.classID.length; j++ )
		{
			if( myaClass2.parentID[j] == myaClass1.classID[i] )
			{
				if( index == 0)
				{
					outstr += "<a href=\"" + ( (myaClass1.cUrl[i] == "") ? (getCURL(myaClass1.classID[i])) : myaClass1.cUrl[i] ) + "\" class=\"navlink\" target=\"" + blank + "\">";
					outstr += "<font style=\"color:" + color + "\" onmouseover=\"showmenu(event," + myaClass1.classID[i] + ",1,false)\" onmouseout=\"delayhidemenu()\">" + myaClass1.className[i] + "</font></a>";
					
					if( i != myaClass1.classID.length - 1)
					{
						outstr += " <img src=\""+ img +"\" alt=\"\" /> ";
					}
					
					var cid			= myaClass1.classID[i];
					linkset[cid]	= new Array();
				}
				
				blank = ( myaClass2.newWin[j] == "1" ? "_blank" : "" );
				color = ( myaClass2.color[j] != "" ? myaClass2.color[j] : "" );

				linkset[cid][index] = "<div class=\"menuitems\"><a href=\"" + getCURL(myaClass2.classID[j]) + "\" target=\"" + blank + "\"><font style=\"color:" + color + "\">" + myaClass2.className[j] + "</font></a></div>";
				
				index++;
			}
		}
			
		if( index == 0 )
		{
			outstr += "<a class=\"navlink\" href=\"" + ( (myaClass1.cUrl[i] == "") ? getCURL(myaClass1.classID[i]) : myaClass1.cUrl[i] ) + "\" target=\"" + blank + "\"><font style=\"color:" + color + "\">" + myaClass1.className[i] + "</font></a>";
			
			if( i != myaClass1.classID.length - 1)
			{
				outstr += " <img src=\""+ img +"\" alt=\"\" /> ";
			}
		}
	}

	return (outstr);
}

//============================================
// 分类页的分页
// cid		: 当前分类的ID
// page		: 当前页
// pagenum	: 总页数
// strResult: 相对路径
// staticFileExt: 网站所使用的扩展名
//============================================
function csplitpage(cid, page, pagenum, strResult, staticFileExt, str) {
    if (str == null)
        str = "";
    var outstr = "";
    if (pagenum <= 1) {
        outstr += "<font color=#c0c0c0>首页 | 上页 | 下页 | 尾页</font>";
    }
    else {
        if (page == 1)
            outstr += "<font color=#c0c0c0>首页 | 上页</font> | <a href=" + getCPageURL(cid, page + 1, strResult, staticFileExt) + str + ">下页</a> | <a href=" + getCPageURL(cid, pagenum, strResult, staticFileExt) + str + ">尾页</a>";
        else if (page == pagenum)
            outstr += "<a href=" + getCPageURL(cid, 1, strResult, staticFileExt) + str + ">首页</a> | <a href=" + getCPageURL(cid, page - 1, strResult, staticFileExt) + str + ">上页</a> | <font color=#c0c0c0>下页 | 尾页</font>";
        else
            outstr += "<a href=" + getCPageURL(cid, 1, strResult, staticFileExt) + str + ">首页</a> | <a href=" + getCPageURL(cid, page - 1, strResult, staticFileExt) + str + ">上页</a> | <a href=" + getCPageURL(cid, page + 1, strResult, staticFileExt) + str + ">下页</a> | <a href=" + getCPageURL(cid, pagenum, strResult, staticFileExt) + str + ">尾页</a>";
    }

    return outstr;
}

//============================================
// 通用分页程序
// cid		: 当前分类的ID
// page		: 当前页
// pagenum	: 总页数
//============================================
function common_splitpage(url, page, pagenum)
{
	var outstr = "";
	if(pagenum <= 1)
	{
		outstr += "<font color=#c0c0c0>首页 | 上页 | 下页 | 尾页</font>";
	}
	else
	{
		if(page == 1)
			outstr += "<font color=#c0c0c0>首页 | 上页</font> | <a href=\"" + url + "page=" + (page + 1) + "\">下页</a> | <a href=\"" + url + "page=" + pagenum + "\">尾页</a>";
		else if(page == pagenum)
			outstr += "<a href=\"" + url + "page=1\">首页</a> | <a href=\"" + url + "page=" + (page - 1) + "\">上页</a> | <font color=#c0c0c0>下页 | 尾页</font>";
		else
			outstr += "<a href=\"" + url + "page=1\">首页</a> | <a href=\"" + url + "page=" + (page - 1) + "\">上页</a> | <a href=\"" + url + "page=" + (page + 1) + "\">下页</a> | <a href=\"" + url + "page=" + pagenum + "\">尾页</a>";
	}
	
	return outstr;
}

//============================================
// 分类页的分页
// cid		: 当前分类的ID
// page		: 当前页
// strResult: 相对路径
// staticFileExt: 网站所使用的扩展名
//============================================
function getCPageURL(cid, page, strResult, staticFileExt)
{
    if( page == 1 )
        strResult += cid + staticFileExt ;
    else
        strResult += cid + "_" + page + staticFileExt;
        
    return strResult;
}

//============================================
// 输出 Flash 或 图片 文件(自动识别)
// file		: 文件地址
// w		: 宽度
// h		: 高度
//============================================
function Flash_IMG(file, w, h)
{
		var extName = file.split(".")
		var ext = extName[extName.length - 1];
		file = file.Trim();
		
		switch( ext )
		{
			case "swf"	:
				document.write("<div style=\"padding:0px\"><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=6,0,0,0\" width=\"");
				document.write(w);
				document.write("\" height=\"");
				document.write(h);
				document.write("\"><param name=\"wmode\" value=\"transparent");
				document.write("\"><param name=\"movie\" value=\"");
				document.write(file);
				document.write("\"> <param name=\"quality\" value=\"high\"><embed src=\"");
				document.write(file);
				document.write("\" loop=\"false\" menu=\"false\" quality=\"high\" width=\"");
				document.write(w);
				document.write("\" height=\"");
				document.write(h);
				document.write("\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></embed></object></div>");
			default		:
				if( 
					ext == "gif" || 
					ext == "jpg" || 
					ext == "bmp" ||
					ext == "png"
				)
				{
					document.write("<img src=\"" + file + "\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\">");
				}
		}
}

//============================================
// 输出图片产品列表(有缩微图)
// img		: 缩微图地址
// url		: 产品路径
// alt		: 产品标题全称
// blank	: 是否新窗口打开
// highlight: 是否高亮
//============================================
function WriteThumb(img, url, alt, blank, highlight)
{
	if (blank == null) blank = false;
	
	if (highlight == null) highlight = false;
	
	with(document){
		write("<table class='thumbnail'>");
		write("<tr><td>");
		if(url != null)
		{
			write("<a href='");
			write(url);
			if (blank)
				write("' target='_blank'>");
			else
				write("'>");
		}
		write("<img src='");
		write(img);
		write("' alt='");
		write(alt);
		write("' ");
		if (highlight){
			if (thumbHWidth>0){
				write(" width='");
				write(thumbHWidth);
				write("' ");
			}
			if (thumbHHeight>0){
				write(" height='");
				write(thumbHHeight);
				write("' ");
			}
		}else{
			if (thumbWidth>0){
				write(" width='");
				write(thumbWidth);
				write("' ");
			}
			if (thumbHeight>0){
				write(" height='");
				write(thumbHeight);
				write("' ");
			}
		}
		write("></a></td></tr></table>");
	}

}

function regInput(obj, reg, inputStr)
{
	var docSel	= document.selection.createRange()
	if (docSel.parentElement().tagName != "INPUT")	return false
	oSel = docSel.duplicate()
	oSel.text = ""
	var srcRange	= obj.createTextRange()
	oSel.setEndPoint("StartToStart", srcRange)
	var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
	return reg.test(str)
}

//============================================
// 显示产品打印页面内容
//============================================
function __doPrint()
{
	var adBegin = "<!--SEAShop_ADV_BEGIN-->";
	var adEnd	= "<!--SEAShop_ADV_END-->";
	var body;
	var css;
	var str		= "<html>\r\n";
	str += "<head>\r\n";
	str += "<meta http-equiv=\"content-type\" content=\"text/html; charset="+document.charset+"\">\r\n";
	str += "<title>"+document.title+"</title>\r\n";
	str += "<link rel=\"stylesheet\" href=\"Images/print.css\" type=\"text/css\"/>\r\n";
	str += "<body bgcolor=\"#ffffff\" topmargin=\"20\" leftmargin=\"5\" marginheight=\"50\" marginwidth=\"5\" onLoad=\"window.print();\">\r\n";
	//str += document.all.printScript.innerHTML;
	//str += "\n<script type=\"text/javascript\">\r\nfunction doPrint(){window.print();}\r\n</script>\r\n";
	str += "<table>";
	document.all.printHide.style.display='none';
	body = document.all.printBody.innerHTML;
	
	//去掉广告
	if ( body.indexOf(adBegin) >= 0 )
	{
		str += body.substr(0,body.indexOf(adBegin));
		str += body.substr(body.indexOf(adEnd)+adEnd.length,body.length);
	}
	else
	{
		str += body;
	}
	str += "</table><p style=\"text-align:right\">源地址：" + document.location.href + "</p>";
	str += "\r\n</body>\r\n</html>";
	document.write(str);
	document.close();
}

String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function gocheck(form, num)
{
    if(num < 2)
    {
        var obj = form.keyword;
        var s = "";
        for(i=0; i<obj.length; i++)
        {
            if(obj[i].checked)
            {
                s = obj[i].value;
            }
        }
        
        if(s.length==0)
        {
            alert("请先选择" + (num==0 ? "价格区间" : "品牌") + "！");
            obj[0].focus();
            return false;
        }
        return true;
    }
}

function switchActive()
{
    var sidebar = document.getElementById('mgrLeft');
    var maincontent = document.getElementById('maincontent');
    
    //展开左边栏
	if (sidebar.style.display == 'none'){
	    sidebar.style.display = 'block';
	    sidebar.style.width = '180px';
		maincontent.style.width ='780px';
	}else{
	//隐藏左边栏
		maincontent.style.width ='100%';
		sidebar.style.display = 'none';
	}
}

function checkFormAll(oForm, chk)
{
	for( var i = 0; i < oForm.elements.length; i++ )
	{
		if( oForm.elements[i].type=="checkbox" )
		{
			oForm.elements[i].checked = chk;
		}
	}
}

function Buy(pid, lowlimit, lessThanPriceAdd, carturl) {
    var values = "";
    var i = 0;
    //遍历所有表元素
    for (; i < 10; i++) {
        var obj = $("input[name='ats" + pid + "_" + i + "']:checked");
        if (obj.length == 0) {
            obj = $("#ats" + pid + "_" + i);
            if (obj.length == 0) {
                break;
            }
        }        
        values += escape(obj.val() + " ");
    }

    //检查起订数量是否符合系统要求
    var orderNumObj = $("#ats" + pid + "_" + (i - 1));
    if (parseInt(orderNumObj.val()) < parseInt(lowlimit)) {
        if (!confirm("您的定购数量小于该商品的最低起订数量[" + lowlimit + "]；\n产品价格将自动加价[" + lessThanPriceAdd + "]元；\n确定订购数量为[" + orderNumObj.value + "]吗？")) {
            orderNumObj.value = lowlimit;
            return;
        }
    }

    carturl = carturl + "?ats={1}";
    window.location = carturl.replace("{0}", pid).replace("{1}", values);
}

function getstock(arr, productid, unit) {
    var as = "";
    var obj;
    var i = 0;
    for (; i < 4; i++) {
        obj = document.getElementById("ats" + productid + "_" + i);
        if (obj) {
            as += obj.value;
        } else {
            break;
        }
    }
    if (as.length < 2) {
        return;
    }

    //去掉数量属性
    as = as.replace(document.getElementById("ats" + productid + "_" + (i - 1)).value, "");

    obj = document.getElementById("stock_" + productid);
    //检查库存
    if (arr == null || arr.length == 0) {
        if (obj)
            obj.innerHTML = "此商品暂无库存信息可查！";
        return;
    }

    for (i = 0; i < arr.length; i++) {
        if (arr[i][1] + arr[i][2] == as) {
            var q = parseInt(arr[i][4])
            if (q < 1) {
                obj.innerHTML = as + "暂缺，<span style='color:red; font-size:14px; font-weight:bold;'>" + arr[i][5] + "</span> 日内到货!";
            }
            else {
                obj.innerHTML = as + "，<span style='color:red; font-size:14px; font-weight:bold;'>" + q + "</span> " + unit + " [" + arr[i][6] + "] 更新";
            }
            return;
        }
    }

    obj.innerHTML = as + " 暂无库存信息";
}


function showSpan(span) {
    var obj = document.getElementById("attach").getElementsByTagName("span");
    for (i = 0; i < obj.length; i++) {
        obj[i].style.display = "none";
    }

    obj = document.getElementById(span);
    obj.style.display = "";
}

function searchCheck(form) {
    var obj = document.getElementById("keyword");

    if (obj.value.length == 0) {
        alert("请填写搜索关键字！");
        obj.focus();
        return false;
    }

    obj = document.getElementById("where");
    if (obj.value == "topic") {
        form.action = "/may/bbs/topicshow.shtml";
    } else {
        form.action = "/may/search.shtml";
    }

    form.submit();
}
