  function   DrawImage(ImgD){  
        var   flag=false;  
        var   image=new   Image();   
        image.src=ImgD.src;   
        if(image.width>0   &&   image.height>0){   
          flag=true;   
          if(image.width/image.height>=   150/140){   
            if(image.width>150){       
            ImgD.width=150;   
            ImgD.height=(image.height*150)/image.width;   
            }else{   
            ImgD.width=image.width;       
            ImgD.height=image.height;   
            }   
            }   
          else{   
            if(image.height>140){       
            ImgD.height=140;   
            ImgD.width=(image.width*140)/image.height;             
            }else{   
            ImgD.width=image.width;       
            ImgD.height=image.height;   
            }   
            }   
          }   
  } 

function CheckPic(imgObj, productId)
{
if (isImgALink(imgObj)) // 如果图片已经被系统加上了链接，那么不做任何操作
	{ 
	}
else
	{
		try
		{		 
				var curObj=imgObj;
				var imageUrl = 'http://image.2688.com/Product/' + productId.substring(0 ,3) + '/' + productId + '.jpg';
				if (xmlhttp_requestExistence(imageUrl))
				{				 
					reloadPic(curObj, imageUrl);
				}
				else
				{ 				 
				}		 
		}
		catch (e)
		{
			}
	}
}

//重新图片加入链接
function reloadPic(imgObj, imgUrl){
		try{ 
				var sourceSrc=imgObj.src; 				 
				var nod=document.createElement("SPAN");
				var tt="<a target='_blank' title='点击此处察看大图' href='"+imgUrl+"' width=" + imgObj.style.width + " height=" +imgObj.style.height + "><img border='0' src='"+sourceSrc+"' ></a>";				 
				nod.innerHTML = tt;
				if (imgObj.parentNode!=null && imgObj.parentNode.tagName=="A"){				
					imgObj.parentNode.insertAdjacentElement("afterEnd",nod);	
				}else{ 
					imgObj.insertAdjacentElement("afterEnd", nod);
				} 	
				 imgObj.style.visibility = 'hidden';
				 imgObj.style.display = 'none';
        }catch (e){}
}			

//图片是否有链接。
function isImgALink(imgObj){
	try{
		var parentObj=imgObj.parentNode;
		
		if (parentObj && parentObj.tagName=="A"){
			return true;	
		} 
		return false;		
	}catch (e){}
}


function xmlhttp_requestExistence( URL )
{		 
var oXmlHttp = null;
	
	if( window.XMLHttpRequest )		// Gecko
	{ 
		oXmlHttp = new XMLHttpRequest();
	}
		
	if( window.ActiveXObject ) 
	{	// IE
		oXmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
		if( oXmlHttp == null )
			oXmlHttp = new ActiveXObject( 'Msxml2.XmlHttp' );
		if( oXmlHttp == null )
			oXmlHttp = new ActiveXObject( 'Msxml2.ServerXmlHttp' );
	}
	
	if( oXmlHttp ) 
	{ 
		  oXmlHttp.Open("GET",URL, false); 			   
	    oXmlHttp.Send();    
			var result = oXmlHttp.status; 	 
			
		  if(result==200) 
		  {  
		    return true; 
		  }   
			else
				{
					return false; 
				}
  }
	else
	{ 
		return false;
	}

}
