function changeImgSize(obj,width,height) {
  if ( obj.width > width || obj.height > height ) {
    var scale;
    var scale1 = obj.width / width;
    var scale2 = obj.height / height;
    if(scale1 > scale2){
        scale = scale1;
    }else{
        scale = scale2;
    }
    obj.width = obj.width / scale;
    //  obj.height = obj.height / scale;
  }
}
function changeImgSetSize(obj,width,height){
    var imgs = obj.getElementsByTagName("'IMG'");
    if (imgs.length>0){
	    for(var i =0;i<=imgs.length-1;i++){
	        changeImgSize(imgs[i],width,height);
	    }
    }
}
function sethomepage(url) {
    this.homepage.style.behavior = 'url(#default#homepage)'; 
    this.homepage.sethomepage(url);
}
function addfav(url, title) {
    window.external.addfavorite(url, title);
}

function check()
{
   if(checkspace(document.searchform.searchkey.value !='请输入关键字'))  {
	document.searchform.searchkey.focus();
	alert("请输入查询关键字！");
	return false;
  }
  if(checkspace(document.searchform.searchkey.value))  {
	document.searchform.searchkey.focus();
	alert("请输入查询关键字！");
	return false;
  }
   document.searchform.submit();
}
function checkspace(checkstr) {
  var str = '';
  for(i = 0; i < checkstr.length; i++) {
    str = str + ' ';
  }
  return (str == checkstr);
}

function loadData(boxid,n,catid,tab){
	var box = $(boxid);
	var request=new Request.JSON({
	 url:'/json_hotprod.asp?n='+ n +'&catid='+catid,
	 onSuccess:function(json){
	 var html="";
	 if(json.pros.length>0){
	    html += "<ul class=\"pro_list\">";
	    for (i=0;i<json.pros.length;i++){
		    var pro = json.pros[i];
		    var name = pro.name;
		    //var name1 = name;
		    //if(name.length>20){
			    //name1=name.substring(0,7)+"...";
		    //}
		    html+="<li><span class=\"pro_img_s\"><a href=\"/sp"+ pro.id +".asp\"><img src=\""+ pro.img +"\" alt=\""+ name +"\" width=\"68\"/></a></span><span class=\"pro_name_s\"><a href=\"/sp"+ pro.id +".asp\">"+ name +"</a><br/>批发价:"+ pro.price +"</span></li>";
	    }
	    html+"</ul>";
	}else{
	   html +="暂时没有数据";
	}
	box.set('html',html);
	//tab.className='selected';
},
	 onRequest:function(){box.set('text',"正在读取中...");},
	 onFailure:function(){box.set('text',"读取失败");}
	 }).send();
}

function slideLine(ul, delay, speed, lh) {
var slideBox = (typeof ul == 'string')?document.getElementById(ul):ul;
var delay = delay||1000, speed=speed||20, lh = lh||20;
var tid = null, pause = false;
var start = function() {
tid=setInterval(slide, speed);
}
var slide = function() {
if (pause) return;
slideBox.scrollTop += 2;
if (slideBox.scrollTop % lh == 0) {
clearInterval(tid);
slideBox.appendChild(slideBox.getElementsByTagName('li')[0]);
slideBox.scrollTop = 0;
setTimeout(start, delay);
}
}
slideBox.onmouseover=function(){pause=true;}
slideBox.onmouseout=function(){pause=false;}
setTimeout(start, delay);
}

function GetCookie(sName) 
{
 	var cookieValue = "";
  	var search = sName + "=";
  	if(document.cookie.length > 0) 
	{ 
    	offset = document.cookie.indexOf(search);
    	if (offset != -1){ 
      		offset += search.length;
      		end = document.cookie.indexOf(";", offset);
      		if (end == -1) end = document.cookie.length;
      		cookieValue = unescape(document.cookie.substring(offset, end));
    	}
  	}
  	return cookieValue;
}
function SetCookie (name, value) { 
    var argv = SetCookie.arguments; 
    var argc = SetCookie.arguments.length; 
    var expires = (argc > 2) ? argv[2] : null; 
    var path = (argc > 3) ? argv[3] : null; 
    var domain = (argc > 4) ? argv[4] : null; 
    var secure = (argc > 5) ? argv[5] : false; 
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) + 
    ((domain == null) ? "" : ("; domain=" + domain)) + 
    ((secure == true) ? "; secure" : "");
}
function DelCookie(sName,sValue){
	var Then = new Date();　　　　  
　　Then.setTime(Then.getTime() - 60*1000);
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + Then.toGMTString();
	self.location.reload();
}
function showTip(obj,txt){
		if(obj.init) return;
	    obj.init = function(){
		var thisObj = this;
		var str = thisObj.innerHTML;
		thisObj.style.position = "relative";
		var div = document.createElement("div");
		div.className = "tip-bg";
		div.innerHTML = "<div class=\"tip-hd\"></div><div class=\"tip-cont\">&nbsp;" + txt + "&nbsp;</div><div class=\"tip-bt\"></div>";
		thisObj.insertBefore(div,thisObj.firstChild);
		thisObj.getElementsByTagName ('div')[0].style.display = 'none';
		thisObj.showTip();
		thisObj.onmouseover = thisObj.showTip;
		thisObj.onmouseout = thisObj.hideTip;
	}
	obj.showTip = function(){
		var thisObj = this;
		clearTimeout(thisObj.timeout);
		thisObj.timeout = setTimeout(function(){
			thisObj.getElementsByTagName ('div')[0].style.display='block';
		},200);
	}
	obj.hideTip = function(){
		var thisObj = this;
		clearTimeout(thisObj.timeout);
		thisObj.getElementsByTagName ('div')[0].style.display='none'
	}
	obj.init();
}
function showMark(obj,dan){
    var req = new Request({
		url: "/getdeliverymark.asp?dan="+dan,
		onSuccess:function(txt){showTip(obj,txt);},
		//onRequest:function(){showTip(obj,"正在获取");},
		onFailure: function(){showTip(obj,"获取出错");}
	}).send();
}