﻿function AutoSize(ImgD,MaxWidth,MaxHeight)
{
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0)
   {
    flag=true;
    if(image.width/image.height>= MaxWidth/MaxHeight)
    {
     ImgD.width=MaxWidth;
     ImgD.height=(image.height*MaxWidth)/image.width;
     }
    else
    {
     ImgD.height=MaxHeight;
     ImgD.width=(image.width*MaxHeight)/image.height;     
     }
   }
} 
function clear_cart(){
	if(!confirm("确定要清空购物车吗？"))
		window.location.href=cart.php;
	else
		window.location.href="?clear_cart=1";
}
//去掉左右空格函数
function trim(m){   
	 while((m.length>0)&&(m.charAt(0)==' '))   
	 m   =   m.substring(1, m.length);   
	 while((m.length>0)&&(m.charAt(m.length-1)==' '))   
	 m = m.substring(0, m.length-1);   
	 return m;   
} 
//留言区js
function chkinput(form){
	if(trim(form.word_info.value) == ""){
		alert("留言不能为空！");
		form.word_info.focus();
		return false;
	}else{ return true; }
}
//搜索区js
function chkkeyword(form){
	if(trim(form.keyword.value) == ""){
		alert("搜索关键词不能为空！");
		form.keyword.focus();
		return false;
	}else{ return true; }
}
