
//生成ajax对象
function ajax(){
	xmlHttp=false;
	if(window.ActiveXObject){//IE
		 try{
		  	xmlHttp=new ActiveXObject("Msxml2.xmlHttp");
		 }catch(e){
			try{
				xmlHttp=new ActiveXobject("Microsoft.xmlHttp");
			}catch(e){}
		 }
	}else{//Mozilla
		 xmlHttp=new XMLHttpRequest();
		 if(xmlHttp.overrideMimeType){//MIME
		 	xmlHttp.overrideMimeType("text/xml");
		 }
	}
	
}

function news(id){
	ajax();
	xmlHttp.open("GET","newsajax.php?id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){	
			if(xmlHttp.status==200){ 
				msg=xmlHttp.responseText;
				var j=eval('('+msg+')');
				document.getElementById("title").innerHTML=j.title;
				document.getElementById("contents").innerHTML=j.contents;
				document.getElementById("adddate").innerHTML=j.adddate;
				document.getElementById("hit").innerHTML=j.hit;
				
			}
		}
	};
	xmlHttp.send(null);
}


function img(obj){
	document.getElementById("goodsimg").src=obj.alt;
	var ii=document.getElementsByName("goodss");
	for(i=0;i<ii.length;i++){
		ii[i].style.border="none";
		
	}
	obj.style.border="solid #FF9AC6 1px";
}

function share(id){
	ajax();
	xmlHttp.open("GET","shareajax.php?id="+id,true);
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4){	
			if(xmlHttp.status==200){ 
				msg=xmlHttp.responseText;
				var j=eval('('+msg+')');
				document.getElementById("title").innerHTML=j.title;
				document.getElementById("jianjie").innerHTML=j.jianjie;
				document.getElementById("share_content").innerHTML=j.contents;
				document.getElementById("name").innerHTML=j.name;
				document.getElementById("img1").src=j.img1;
				if(!j.img2==true){
					document.getElementById("img2").style.display="none";
				}else{
					document.getElementById("img2").style.display="block";
					document.getElementById("img2").src=j.img2;
				}
				var ii=document.getElementsByName("ii");
				for(i=0;i<ii.length;i++){
					ii[i].style.border="none";
					
				}			
				//document.getElementById("i"+id).style.border="#FF9AC6 solid 1px;";
				document.getElementById("share_content").style.display="none";
				document.getElementById("show_img").src="../images/ckxq.gif";
			}
		}
	};
	xmlHttp.send(null);
}

function DrawImage(ImgD,w,h){
  var image=new Image(); 
  image.src=ImgD.src;
  var imgw=image.width; //图片原始宽
  var imgh=image.height; //图片原始高
  
  if(imgw>0 && imgh>0){ 
   		if(imgw /imgh > w/h){ 
			if(imgw>w){
			ImgD.width=w; 
			ImgD.height=(imgh*w)/imgw; 
		   	}else{ 
			ImgD.width=imgw;
			ImgD.height=imgh; 
		   	} 
		}else{ 
		   	if(imgh>h){
			ImgD.height=h; 
			ImgD.width=(imgw*h)/imgh; 
		   	}else{ 
			ImgD.width=imgw;
			ImgD.height=imgh; 
		   	} 
		} 
   }
}


function changeimg(src,to){
	document.getElementById(to).src=src;
	
}
