﻿var xmlHttp;
function S_xmlhttprequest(){
try{ 
　　if( window.ActiveXObject ){ 
　　for( var i = 5; i; i-- ){ 
　　try{ 
　　if( i == 2 ){ 
　　xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" ); }
　　else{ 
　　xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" ); 
　　xmlHttp.setRequestHeader("Content-Type","text/xml"); 
　　xmlHttp.setRequestHeader("Charset","gb2312"); }
　　break;} 
　　catch(e){ 
　　xmlHttp = false; } } }
　　else if( window.XMLHttpRequest )
　　{ xmlHttp = new XMLHttpRequest(); 
　　if (xmlHttp.overrideMimeType) 
　　{ xmlHttp.overrideMimeType('text/xml'); } } }
  　catch(e){ xmlHttp = false; } 
}
function count_click(shopid){
	S_xmlhttprequest();
	xmlHttp.open("GET","/count.php?shopid=" + shopid + "&method=c_click",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
			document.getElementById('num_click_'+shopid).innerHTML=mm;
		}
	}
}
	xmlHttp.send(null);
}
function count_useful(commentid,count){
	S_xmlhttprequest();
	xmlHttp.open("GET","count.php?shopid=" + commentid + "&method=c_useful",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 0){
				document.getElementById('comment_useful_'+commentid).innerHTML='有用';
				document.getElementById('comment_useless_'+commentid).innerHTML='没用';
    		}
    		else{
				document.getElementById('comment_useful_'+commentid).innerHTML='有用';
				document.getElementById('comment_useless_'+commentid).innerHTML='没用';
				count++;
				document.getElementById('count_useful_'+commentid).innerHTML=count;
			}
		}
	}
}
	xmlHttp.send(null);
}
function count_useless(commentid,count){
	S_xmlhttprequest();
	xmlHttp.open("GET","count.php?shopid=" + commentid + "&method=c_useless",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 0){
				document.getElementById('comment_useful_'+commentid).innerHTML='有用';
				document.getElementById('comment_useless_'+commentid).innerHTML='没用';
    		}
    		else{
				document.getElementById('comment_useful_'+commentid).innerHTML='有用';
				document.getElementById('comment_useless_'+commentid).innerHTML='没用';
				count++;
				document.getElementById('count_useless_'+commentid).innerHTML=count;
			}
		}
	}
}
	xmlHttp.send(null);
}
function count_like(itemid,count,title,writerid,name){
	document.getElementById('text_like_'+itemid).innerText=" 已喜欢";
	S_xmlhttprequest();
	xmlHttp.open("GET","count.php?itemid=" + itemid + "&method=c_like&title=" + title + "&writerid=" + writerid + "&name=" + name,true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 3){
    		}
    		else if(mm == 2){
				count++;
				document.getElementById('num_like_'+itemid).innerText=count;
			}
		}
	}
}
	xmlHttp.send(null);
}
function follow(fuid,name){
	document.getElementById('follow_' + fuid).value="正在关注..";
	S_xmlhttprequest();
	xmlHttp.open("GET","follow.php?id=" + fuid + "&method=follow&name=" + name,true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
			var mm = xmlHttp.responseText;
			if(mm == 3){
				document.getElementById('follow_' + fuid).value="取消关注";
				document.getElementById('follow_' + fuid).onclick= function(){cfollow(fuid,name)};
				var fans = document.getElementById('fans_' + fuid).innerText;
				if(fans) document.getElementById('fans_' + fuid).innerText = " " + ( parseInt(fans) + 1);
			}
		}
	}
	}
	xmlHttp.send(null);
}
function cfollow(fuid,name){
	if(window.confirm("真要取消对 "+ decodeURIComponent(name)+" 的关注吗？")){
		document.getElementById('follow_' + fuid).value="正在取消..";
		S_xmlhttprequest();
		xmlHttp.open("GET","follow.php?id=" + fuid + "&method=cancel&name=" + name,true);
		xmlHttp.onreadystatechange = function x(){
			if(xmlHttp.readyState == 4)
    		{
    			if(xmlHttp.status == 200)
    			{
					var mm = xmlHttp.responseText;
					if(mm == 3){
						document.getElementById('follow_' + fuid).value="关注";
						document.getElementById('follow_' + fuid).onclick= function(){follow(fuid,name)};
						var fans = document.getElementById('fans_' + fuid).innerText;
						if(fans) document.getElementById('fans_' + fuid).innerText = " " + (parseInt(fans) - 1);
    				}				
				}
			}
		}
		xmlHttp.send(null);
	}
}
function item_delete(itemid){
	if(window.confirm("真的要删除？")){
	S_xmlhttprequest();
	xmlHttp.open("GET","delete.php?id=" + itemid + "&method=item",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 2){
				$(".item_"+itemid).remove();
			}
		}
	}
	}
}
	xmlHttp.send(null);
}
function shop_delete(shopid){
	if(window.confirm("真的要取消收藏？")){
	S_xmlhttprequest();
	xmlHttp.open("GET","delete.php?id=" + shopid + "&method=shop",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 2){
				$(".shop_"+shopid).remove();
			}
		}
	}
	}
}
	xmlHttp.send(null);
}
function message_delete(mid){
	if(window.confirm("真的要删除这条评论？")){
	S_xmlhttprequest();
	xmlHttp.open("GET","delete.php?id=" + mid + "&method=message",true);
	xmlHttp.onreadystatechange = function x(){
	if(xmlHttp.readyState == 4)
    {
    	if(xmlHttp.status == 200)
    	{
    		var mm = xmlHttp.responseText;
    		if(mm == 2){
				$(".message_"+mid).remove();
			}
		}
	}
	}
}
	xmlHttp.send(null);
}
