﻿//产品分类js
function showLay(divId){
	var objDiv = eval(divId);
	if (objDiv.style.display=="none"){
		eval("sp"+divId+".innerHTML='<img src=/public/js/productClass/open.gif border=0>'");
		objDiv.style.display="";
	}else{
		eval("sp"+divId+".innerHTML='<img src=/public/js/productClass/close.gif border=0>'");
		objDiv.style.display="none";
	}
}
//产品分类点击跳转
function product_c(getpid,cid)
{
window.open("/c/"+cid+"/product_list.htm?bid=0&cpid="+getpid,"_self");
};


//iframe高度随内容自动调整
function pagestyle(fid)
{		$(fid).load(function(){
		var WebRightheight =  $(fid).contents().find("body").attr('scrollHeight'); //获得WebRigh高度
		$(fid).height(WebRightheight);					
		});  
};




//设置cookie
//cookie (名,值)
function setCookie(name, value) {   
	 var expires = "";   //设置cookie生存时间
	
		 var date = new Date();   
		 date.setTime(date.getTime()+365*24*3600*1000);  //设置cookie的有效期为1年 
		 expires = "; expires="+date.toGMTString();   
	 document.cookie = name+"="+escape(value)+expires+"; path=/";   //转码并赋值  
}

//取得cookie  (名)
function getCookie(name) {   
 var nameEQ = name + "=";   
 var ca = document.cookie.split(';');    //把cookie分割成组   
 
 for(var i=0;i < ca.length;i++) {   
	 var c = ca[i];                      //取得字符串   
	 while (c.charAt(0)==' ') {          //判断一下字符串有没有前导空格   
	 	c = c.substring(1,c.length);      //有的话，从第二位开始取   
 	 }   
	 if (c.indexOf(nameEQ) == 0) {       //如果含有我们要的name   
	 	return unescape(c.substring(nameEQ.length,c.length));    //解码并截取我们要值
		  
	 }   
 }   
 return 0;
}


//Time:2011-05-05 10:17
//Author:QUAN
//js获取url参数的function
//paras:URL参数
function GetURLParam(paras){ 
var url = location.href;   
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");   
var paraObj = {}   
for (i=0; j=paraString[i]; i++){   
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf 
("=")+1,j.length);   
}   
var returnValue = paraObj[paras.toLowerCase()];   
if(typeof(returnValue)=="undefined"){   
return "";   
}else{   
return returnValue;   
}   
} 
//var theurl 
//theurl=request("url"); 
//if (theurl!=''){ 
//location=theurl 
//} 


/*
**************图片预加载插件******************
///作者：没剑(2008-06-23)
///http://regedit.cnblogs.com

///说明：在图片加载前显示一个加载标志，当图片下载完毕后显示图片出来
可对图片进行是否自动缩放功能
此插件使用时可让页面先加载，而图片后加载的方式，
解决了平时使用时要在图片显示出来后才能进行缩放时撑大布局的问题
///参数设置：
scaling     是否等比例自动缩放
width       图片最大高
height      图片最大宽
loadpic     加载中的图片路径
*/
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){
   // if(loadpic==null)loadpic="/public/skins/Default/Images/no_pic.gif";
    if(loadpic==null)loadpic="";
	return this.each(function(){
		var t=$(this);
		var src=$(this).attr("src")
		var img=new Image();
		//alert("Loading...")
		img.src=src;
		//自动缩放图片
		var autoScaling=function(){
			if(scaling){
			
				if(img.width>0 && img.height>0){ 
			        if(img.width/img.height>=width/height){ 
			            if(img.width>width){ 
			                t.width(width); 
			                t.height((img.height*width)/img.width); 
			            }else{ 
			                t.width(img.width); 
			                t.height(img.height); 
			            } 
			        } 
			        else{ 
			            if(img.height>height){ 
			                t.height(height); 
			                t.width((img.width*height)/img.height); 
			            }else{ 
			                t.width(img.width); 
			                t.height(img.height); 
			            } 
			        } 
			    } 
			}	
		}
		//处理ff下会自动读取缓存图片
		if(img.complete){
		    //alert("getToCache!");
			autoScaling();
		    return;
		}
		$(this).attr("src","");
		var loading=$("<img src=\""+loadpic+"\" width=150 height=120 border=0/>");
		
		t.hide();
		t.after(loading);
		$(img).load(function(){
			autoScaling();
			loading.remove();
			t.attr("src",this.src);
			t.show();
			//alert("finally!")
		});
		
	});
}


//Time:2011-11-21 16:30
//Author:FUYONG
//设置最近浏览cookie
//cookie (名,值)
function setRecentlyViewedCookie(name, value) { 
    if(getRecentlyViewedCookie(name)!=0)//判断cookie是否存在
    {  
        var cookieValue= getRecentlyViewedCookie(name);//得到cookie值
		var n=(cookieValue.split(',')).length-1;//计算 , 出现的次数
        if(cookieValue!="")
        {
            if(cookieValue.indexOf(value)!=-1)
            {
                return false;
            }
            else
            {
				if(n==4)//如果出现了四次 表示cookie中有了5个数据 去掉最后的一个数据
				{
					cookieValue=cookieValue.substring(0,cookieValue.lastIndexOf(","));
					
				}
                value=value+","+cookieValue;
               
            }
        }
        
	    document.cookie = name+"="+escape(value)+"; path=/";   //转码并赋值  
	    
	}
	else
	{
	    document.cookie = name+"="+escape(value)+"; path=/"; 
	}
}

//取得cookie  (名)
function getRecentlyViewedCookie(name) {   
 var nameEQ = name + "=";   
 
 var ca = document.cookie.split(';');    //把cookie分割成组   
 
 for(var i=0;i < ca.length;i++) {   
	 var c = ca[i];                      //取得字符串   
	 while (c.charAt(0)==' ') {          //判断一下字符串有没有前导空格   
	 	c = c.substring(1,c.length);      //有的话，从第二位开始取   
 	 }   
	 if (c.indexOf(nameEQ) == 0) {       //如果含有我们要的name   
	 	return unescape(c.substring(nameEQ.length,c.length));    //解码并截取我们要值
		
	 }   
 }   
 return 0;
}


//Time:2011-11-21 16:30
//Author:FUYONG
//图片自动大小
function DrawImage(ImgD,FitWidth,FitHeight){ 
    var image=new Image(); 
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){ 
        if(image.width/image.height>= FitWidth/FitHeight){ 
            if(image.width>FitWidth){ 
                ImgD.width=FitWidth;
                ImgD.height=(image.height*FitWidth)/image.width;
            }else{ 
                ImgD.width=image.width;
                 ImgD.height=image.height;
            }
        }else{
             if(image.height>FitHeight){ 
                 ImgD.height=FitHeight; 
                 ImgD.width=(image.width*FitHeight)/image.height; 
             }else{
                  ImgD.width=image.width; 
                  ImgD.height=image.height; 
             }
         }
    }
}
