﻿var timer_count = 0;
function GetCookie(cookiename)
{
    var thebigcookie = document.cookie;
    var firstchar = thebigcookie.indexOf(cookiename);
    if (firstchar != -1) {
        firstchar += cookiename.length + 1;
        lastchar = thebigcookie.indexOf(";",firstchar);
        if(lastchar == -1) lastchar = thebigcookie.length;
        return unescape(thebigcookie.substring(firstchar, lastchar));
    }
    return "";
}
function SetCookie(cookiename,cookievalue,cookieexpdate,domainname)
{
    document.cookie = cookiename + "=" + escape(cookievalue)
    + "; domain=" + domainname
    + "; path=" + "/"
    + "; expires=" + cookieexpdate.toGMTString();
}

Date.prototype.format = function(format)
{ 
var o = { 
"M+" : this.getMonth()+1,
"d+" : this.getDate(),
"h+" : this.getHours(),
"m+" : this.getMinutes(),
"s+" : this.getSeconds(),
"q+" : Math.floor((this.getMonth()+3)/3),
"S" : this.getMilliseconds()
} 
if(/(y+)/.test(format)) format=format.replace(RegExp.$1, 
(this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
for(var k in o)if(new RegExp("("+ k +")").test(format)) 
format = format.replace(RegExp.$1, 
RegExp.$1.length==1 ? o[k] : 
("00"+ o[k]).substr((""+ o[k]).length)); 
return format; 
}

function CheckImg(o,img, txt,img1)
{
	if (!/\.((jpg)|(bmp)|(gif)|(png))$/ig.test(o.value))
	{
		alert('只能上传jpg,bmp,gif,png格式图片!');
		o.outerHTML = o.outerHTML;
	}
	else
	{
	    $(img).hide();
		$(img1).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=o.value;
		$(img1).show();
		$(txt).value = o.value;
	}
}
function CheckPrice(o)
{
    var v=parseFloat(o.value);
    v=isNaN(v)?'0.0':v.toFixed(2);    
    if (o.value!=v)
    {
        o.value=v;
        //alert('金额只能保留到两位小数，例如：123.45');
    }    
}
function CheckImgCss(o,img)
{
	if (!/\.((jpg)|(bmp)|(gif)|(png))$/ig.test(o.value))
	{
		alert('只能上传jpg,bmp,gif,png格式图片!');
		o.outerHTML = o.outerHTML;
	}
	else
	{
		$(img).filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=o.value;
	}
}

function GetProduct()
{
    var str = GetCookie('history');
    var obj = [];
    if (str != null && str != '') obj = str.evalJSON();
    return obj;
}
function AddProduct(id,pic,name)
{
    var obj = GetProduct();
    for (var i=0;i<obj.length;i++)
        if (id==obj[i][0])break;
    if (i==obj.length)
        obj.push([id,pic,name]);
    while(obj.length>6)
        obj.shift();
    var d = new Date();
    d.setYear(d.getYear()+1);
    SetCookie('history', obj.toJSON(), d, 'yef88.com');
}

function GetXY(score)
{
	if (score<4)return [0,0];
	var arr=[[10,40,90,150,250],[500,1000,2000,5000,10000],[20000,50000,100000,200000,500000]];
	for(var i=0;i<arr.length;i++)
	for(var j=0;j<arr[i].length;j++)
	{
		if (score<=arr[i][j])return [i,j+1];
	}
	
}
var timer_count = 30;
var comment_timer;


function DrawImage(ImgD,imgwidth,imgheight){  
     if(ImgD.src.indexOf('none.gif')<0){       
        var f = ImgD.width/ImgD.height;
		if (ImgD.width>imgwidth){ImgD.width=imgwidth;ImgD.height=imgwidth/f;}
		if (ImgD.height>imgheight){ImgD.height=imgheight;ImgD.width=imgheight*f;}
        //addHref(ImgD);
     }
}   
function addHref(element)//参数就是img的实例
{
     var link1 = document.createElement("a");
     link1.href = element.src;
     link1.target='_blank';
     element.parentNode.insertBefore(link1,element);
     link1.appendChild(element);
}
function DrawImage1(ImgD,imgwidth,imgheight){   
     if(ImgD.src.indexOf('none.gif')<0){
        var f = ImgD.width/ImgD.height;
		if (ImgD.width>imgwidth){ImgD.width=imgwidth;ImgD.height=imgwidth/f;}
		if (ImgD.height>imgheight){ImgD.height=imgheight;ImgD.width=imgheight*f;}
     }
} 
function closeall()
{
    Element.hide("ddd0");
    Element.hide("ddd1");
    Element.hide("ddd2");
    Element.hide("ddd3");
    $("ha0").className = "";
    $("ha1").className = "";
    $("ha2").className = "";
    $("ha3").className = "";
}
function toit(obj,tag)
{    
    closeall();
    obj.className = "cur";
    Element.toggle("ddd"+tag);
}
function CheckNum(o)
{
    var v=parseFloat(o.value);
    v=isNaN(v)?'0':v; 
    o.value = v;   
   //alert(1);
}
function CheckPrice(o)
{
    var v=parseFloat(o.value);
    v=isNaN(v)?'0':v.toFixed(2);    
    if (o.value!=v)
    {
        o.value=v;
        //alert('金额只能保留到两位小数，例如：123.45');
    }    
}
function showprice(price,showprice,tuanp,counts)
{
    var xiajia = counts==0?"<span class=\"xiajia\">【缺货】</span>":"";
    var uname = GetCookie("username");
    if(uname==""&&showprice=='False')
    { 
        
        var newprice = parseInt(price)*2;
        document.write("零售：<span class=\"price1\">"+newprice+"</span>元<br/><a href=\"/login.aspx?ReturnUrl="+document.location.href+"\">登录查看批发价</a>"+xiajia);
    }
    else
    {
        document.write("批发价：<span class=\"price1\">"+price+"</span>"+xiajia);
    }
    if(tuanp=='1')//爆款
    {
       document.write("<img src='/images/bao.gif' width='32' height='17'/>");
    }
}

function showpricegift(price, showprice, tuanp, counts) {
    var xiajia = counts == 0 ? "<span class=\"xiajia\">【缺货】</span>" : "";

    document.write("一口价 ：<span class=\"price1\">" + price + "</span>" + xiajia);

 
}

function showprice1(price,showprice,strTuanp1,tday,vipstatus,viprice)
{
    var uname = GetCookie("username");
    var rt = GetCookie("rolec");
    if(uname==""&&showprice=='False')
    {
        var newprice = parseInt(price)*2;
        //document.write("<a href=\"/login.aspx?ReturnUrl="+document.location.href+"\">请登录查看价格</a>");
        document.write("零售：<span class=\"price\">"+newprice+"</span>元   <a href=\"/login.aspx?ReturnUrl="+document.location.href+"\">登录查看批发价</a>");
    }
    else
    {
        //alert(rt);
        if((rt.indexOf("daili,yp")!=-1 || rt.indexOf("daili,jp")!=-1) && vipstatus==1)
        {
            document.write("普通代理批发价：<span class=\"price\">"+price+"</span>元<br/>您是高级代理，因此您的价格是<span class=\"price\">"+viprice+"</span>");
        }
        else
            document.write("批发价：<span class=\"price\">"+price+"</span>元");
    }
    if(strTuanp1=='1')//爆款
    {
        document.write("<img src='/images/bao.gif' width='32' height='17'/>");
    }
    if(tday=='1')//三天无理由退换货
    {
        document.write("<a href='/freeTrade_0_1.shtml' target='_blank'><img src='/images/3.png' width='25' height='24'/></a>");
    }
}
function redaili()
{
    var uname = GetCookie("username");
    if(uname=="")
    {
       window.location.href='/help/h_34.shtml';
    }
    else
    {
        window.location.href='/user/wangdaisq.aspx';
    }
}

function showcg(obj)
{
	    document.getElementById("picdiv").innerHTML = "<img src='"+obj.src+"'/>";
    	
	    document.getElementById("picdiv").style.left = cumulativeOffset(obj)[0];
	    document.getElementById("picdiv").style.top =cumulativeOffset(obj)[1];
}
function closeshow()
{
	document.getElementById("picdiv").innerHTML = "";
	document.getElementById("picdiv").style.left = "0";
	document.getElementById("picdiv").style.top = "0";
}
function   cumulativeOffset(element)   {   
var   valueT   =   0,   valueL   =   0;   
do   {   
  valueT   +=   element.offsetTop     ||   0;   
  valueL   +=   element.offsetLeft   ||   0;   
  element   =   element.offsetParent;   
}   while   (element);   
return   [valueL,   valueT];   
} 
function rand1(number) {
return Math.floor(Math.random() * number);
}

function kd()
{
if(event.keyCode==13){seac();}
}
function seac()
{
    document.location='/search.aspx?key='+escape(document.getElementById("key").value);
}
String.prototype.trim = function() 
{ 
return this.replace(/(^[\s]*)|([\s]*$)/g, ""); 
} 