var curUId = 0;
var curUserName = "";
var strUIdCookie="cdb_auth";

function setUserID(){
  //alert("check cookie");
   var frm = get_iframe_object('ifrmlogin');
   
   try{
   		curUId = frm.document.getElementById("_uid").innerText;
   	}catch(e){
   		curUId = 0;
   	}
    
}
function getUserID()
{
	var frm = get_iframe_object('ifrmlogin');
    var uid = 0;
   try{
   		uid = frm.document.getElementById("_uid").innerText;
   		if (typeof(uid) == "undefined")
   			uid = 0;
   		return uid;
   	}catch(e){
   		alert("error");
   		return 0;
   	}
   	
}

// 读取cookie 
function GetCookie(name)
{ 
	var result = null; 
	var myCookie = document.cookie + ";"; 
	var searchName = name + "="; 
	var startOfCookie = myCookie.indexOf(searchName); 
	var endOfCookie; 
	if (startOfCookie != -1)
	{ 
		startOfCookie += searchName.length; 
		endOfCookie = myCookie.indexOf(";", startOfCookie); 
		result = unescape(myCookie.substring(startOfCookie, endOfCookie)); 
	} 
	return result; 
} 

////////////////////////////////////////////////////////////////////////////////////////
function ShopFav(ShopId,UId,claid) {
	this.ShopId = ShopId;
	this.UId = UId;
	this.claid = claid;
	this.AddFav = function ()
	{
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_favorites_add_post.php";
		ajax_post(strURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		
		var strResult = responseText.parseJSON();
	    var result='';
	    vstr='';

	    //alert(strResult);
	     //数据容器设定   
	    var data = {
	        userinfo : [{ imglink: strResult[0][0], namelink: strResult[0][1] }], 
            customer : { first: "John", last: "Public", level: "gold" }
	   		};
	    
	   		for (i = 1; i < strResult.length; i++)
	        {
	        	 data.userinfo.push({ imglink: strResult[i][0], namelink: strResult[i][1] });
	        }
	        
	        alert(strResult[0][2]);
		   result = TrimPath.processDOMTemplate(shoucangtemp, data);
		   document.getElementById('user_shoucang').innerHTML = result;
		   
		   
		}
		
	/*
	this.addCallback = function(responseText)
	{
		var strResult = responseText.parseJSON();
		alert (strResult);
	}*/
	
		this.Addxianqu = function ()
	{
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_favorites_add_post.php";
		ajax_post(strURL, 
			this.toJSONString(), this.addCallbackxiangqu);
	}
	
	this.addCallbackxiangqu = function(responseText)
	{
		var strResult = responseText.parseJSON();
		/*if(strResult.length>1)
		{
			alert (strResult[0][0]);
		}
		else
		{
			alert (strResult);
		}*/
		//alert (strResult.length);
	    var result='';
	    vstr='';

	     //数据容器设定   
	    var data = {
	        userinfo : [{ imglink: strResult[0][0], namelink: strResult[0][1] }], 
            customer : { first: "John", last: "Public", level: "gold" }
	   		};
	    
	   		for (i = 1; i < strResult.length; i++)
	        {
	        	 data.userinfo.push({ imglink: strResult[i][0], namelink: strResult[i][1] });
	        }
	   // alert(data.products[1].name);
	   result = TrimPath.processDOMTemplate(qgtemp, data);
	   //alert(result);
	    document.getElementById('content_block_blog1').innerHTML = result;
		//parent.frames['xiangqu_frame'].location.reload('/_20module/eating/shops_user_show.php?shopid='+strResult+'&claid=2')
	}
	
		this.Addquguo = function ()
	{
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_favorites_add_post.php";
		ajax_post(strURL, 
			this.toJSONString(), this.addCallbackquguo);
	}
	
	this.addCallbackquguo = function(responseText)
	{
		var strResult = responseText.parseJSON();
	    var result='';
	    vstr='';

	     //数据容器设定   
	    var data = {
	        userinfo : [{ imglink: strResult[0][0], namelink: strResult[0][1] }], 
            customer : { first: "John", last: "Public", level: "gold" }
	   		};
	    
	   		for (i = 1; i < strResult.length; i++)
	        {
	        	 data.userinfo.push({ imglink: strResult[i][0], namelink: strResult[i][1] });
	        }
	   result = TrimPath.processDOMTemplate(qgtemp, data);
	   //alert(result); 
	   document.getElementById('content_block_blog2').innerHTML = result;
		}
}
function AddShopFav(shopid,claid)
{
	var uid = GetCookie(strUIdCookie);
	
	if(uid == null)
	{
		alert("您还没有登录无法添加，请先登录");
		return ;
	}
	var myShopFav = new ShopFav(shopid,uid,claid);
	if(claid==1)
	{
		myShopFav.AddFav();
	}
	if(claid==2)
	{
		myShopFav.Addxianqu();
	}
	if(claid==3)
	{
		myShopFav.Addquguo();
	}
}
////////////////////////////////////////////////////////////////////////////////////////

///评论鲜花/////////////////////////////////////////////////////////////////////////////////
function DinapingFlower(Id,UId) {
	this.Id = Id;
	this.UId = UId;

	this.AddFlower = function ()
	{
		var strFlowerURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_dianping_flower_add_post.php";
		ajax_post(strFlowerURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		
		var objResult = responseText.parseJSON();
		
		if(objResult)
		{
			
			alert(objResult.desc);
			if (objResult.no > 0)
			{
				
				document.getElementById('divFlower'+objResult.id).innerHTML = "<a target='' href='javascript:AddFlower(" + 
				objResult.id + ")'>赞同</a>(" + objResult.no + ")"
			}
		}
	}
}

function AddFlower(id)
{
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		uid = -1;
		alert("您还没有登录无法献花，请先登录");
		return ;
	}
	
	var myDinapingFlower = new DinapingFlower(id,uid);
	myDinapingFlower.AddFlower();
}
////////////////////////////////////////////////////////////////////////////////////////

///商铺鲜花/////////////////////////////////////////////////////////////////////////////////
function ShopFlower(Id,UId) {
	this.Id = Id;
	this.UId = UId;

	this.AddFlower = function ()
	{
		var strFlowerURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_flower_add_post.php";
		ajax_post(strFlowerURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		
		var objResult = responseText.parseJSON();
		if(objResult)
		{
			alert(objResult.desc);
			if (objResult.no > 0)
			{
				
				document.getElementById('shopflower').innerHTML = "" + objResult.no + "";
			}
		}
	}
}

function AddShopFlower(id)
{
	
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		uid = -1;
		alert("您还没有登录无法献花，请先登录");
		return ;
	}
	
	var myShopFlower = new ShopFlower(id,uid);
	myShopFlower.AddFlower();
}
////////////////////////////////////////////////////////////////////////////////////////

///商铺板砖/////////////////////////////////////////////////////////////////////////////////
function ShopStone(Id,UId) {
	this.Id = Id;
	this.UId = UId;

	this.AddStone = function ()
	{
		var strFlowerURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_stone_add_post.php";
		ajax_post(strFlowerURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		
		var objResult = responseText.parseJSON();
		
		if(objResult)
		{
			alert(objResult.desc);
			if (objResult.no > 0)
			{
				
				document.getElementById('shopstone').innerHTML = "" + objResult.no + "";
			}
		}
	}
}

function AddShopStone(id)
{
	
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		uid = -1;
		alert("您还没有登录无法献花，请先登录");
		return ;
	}
	var myShopStone = new ShopStone(id,uid);
	myShopStone.AddStone();
}
////////////////////////////////////////////////////////////////////////////////////////

///评论板砖/////////////////////////////////////////////////////////////////////////////////
function DinapingStone(Id,UId) {
	this.Id = Id;
	this.UId = UId;

	this.AddStone = function ()
	{
		
		var strFlowerURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_dianping_stone_add_post.php";
		ajax_post(strFlowerURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		
		var objResult = responseText.parseJSON();

		if(objResult)
		{
			alert(objResult.desc);
			if (objResult.no > 0)
			{
				
				document.getElementById('divStone'+objResult.id).innerHTML = "<a target='' href='javascript:AddStone(" + 
				objResult.id + ")'>鄙视</a>(" + objResult.no + ")"
			}
		}
	}
}

function AddStone(id)
{
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		uid = -1;
		alert("您还没有登录无法献花，请先登录");
		return ;
	}
	
	var myDinapingStone = new DinapingStone(id,uid);
	myDinapingStone.AddStone();
}
////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////
function CommentFlower(Id,UId) {
	this.Id = Id;
	this.UId = UId;

	this.CommentAddFlower = function ()
	{
		var strFlowerURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_Comment_flower_add_post.php";
		ajax_post(strFlowerURL, 
			this.toJSONString(), this.addCallback);
	}
	
	this.addCallback = function(responseText)
	{
		var objResult = responseText.parseJSON();
		if(objResult)
		{
			alert(objResult.desc);
			if (objResult.no > 0)
			{
				
				document.getElementById('divFlower'+objResult.id).innerHTML = "<span><a class='xh' target='' href='javascript:AddFlower(" + 
				objResult.id + ")'>鲜花(" + objResult.no + ")</a></span> |&nbsp; "
			}
		}
	}
}

function CommentAddFlower(id)
{
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		uid = -1;
		alert("您还没有登录无法献花，请先登录");
		return ;
	}
	var myCommentFlower = new CommentFlower(id,uid);
	myCommentFlower.CommentAddFlower();
}
////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////
function ShopIntro(ShopId) {
	this.ShopId = ShopId;
	
	this.getIntro = function ()
	{
		
		var strShopIntroURL = window.location.protocol + "//" + window.location.host + 
				"/_20module/eating/shops_getintro_post.php";
		ajax_post(strShopIntroURL, 
			this.toJSONString(), this.getCallback);
	}
	
	this.getCallback = function(responseText)
	{
		var objResult = responseText.parseJSON();
		if (objResult)
		{
			//alert (objResult.desc);
			document.getElementById('divShopIntro').innerHTML = '[餐厅简介]：' + objResult.desc; 
		}
	}
}
function getShopIntro(shopid)
{
	var myShopIntro = new ShopIntro(shopid);
	myShopIntro.getIntro();
}
////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////


function joinfriend(friendid)
{
	var uid = GetCookie(strUIdCookie);
	if(uid == null)
	{
		alert("您还没有登录无法添加好友，请先登录");
		return ;
	}
	var myShopFav = new ShopFri(friendid,uid);
	myShopFav.AddFri();
}
////////////////////////////////////////////////////////////////////////////////////////

function ShopFri(friendid,UId) {
	this.friendid = friendid;
	this.UId = UId;
	this.AddFri = function ()
	{
		
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/outing/shops_friend_add_post.php";
			
		ajax_post(strURL, 
			this.toJSONString(), this.addCallback);
			
	}
	
	this.addCallback = function(responseText)
	{
		var strResult = responseText.parseJSON();
		alert (strResult);
	}
}
////////////////////////////////////////////////////////////////////////////////////////
//点评展示
////////////////////////////////////////////////////////////////////////////////////////
function ShopDianping(ShopId,Pageid,Orderid) {
	this.ShopId = ShopId;
	this.Pageid = Pageid;
	this.Orderid = Orderid;
	//读取数据中前台显示
	
	
	
	this.AddDianping = function ()
	{
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_ajax_dianping_show.php";
		ajax_post(strURL, 
			this.toJSONString(), this.DPCallback);
	}
	
	this.DPCallback = function(responseText)
	{
		
		var strResult = responseText.parseJSON();
	    var result='';
	   // alert(strResult[1][4]);
	  // data = strResult;
	     
	     //数据容器设定
	    var data = {
	        dpinfo : [], 
            pageinfo : { page: strResult[0][16], inforow: strResult[0][17]}
	   		};
	   		
	   		for (i = 0; i < strResult.length; i++)
	        {
	        	 data.dpinfo.push({ shoplink: strResult[i][0], imgLink: strResult[i][1], nameLink: strResult[i][2],
	  				      message: strResult[i][3], tesevalue: strResult[i][4], fenleivalue: strResult[i][5],
	    			      dianpinglink: strResult[i][6], fuwu: strResult[i][7], tese: strResult[i][8],
	       				  jiaotong: strResult[i][9], shopname: strResult[i][10], createdate: strResult[i][11],
	        			  id: strResult[i][12], replys: strResult[i][13], flowers: strResult[i][14],
	      				  renjun: strResult[i][15], estones: strResult[i][18], xingjiabi: strResult[i][19], tuijian: strResult[i][20]});
	        }
	   //dqwer[www][0]
	  
	  // new TrimPath;
	  
	   result = TrimPath.processDOMTemplate(dptemp4, data);
	   //alert(result);
	   document.getElementById('dpshow121').innerHTML = result;
	}
	
}
	
function ShopDianpingshow(ShopId,Pageid,Orderid)
{
	var myShopdp = new ShopDianping(ShopId,Pageid,Orderid);
	myShopdp.AddDianping();
}
////////////////////////////////////////////////////////////////////////////////////////
//评论展示
////////////////////////////////////////////////////////////////////////////////////////
function ShopPinglun(ShopId,Pageid,Orderid) {
	this.ShopId = ShopId;
	this.Pageid = Pageid;
	this.Orderid = Orderid;
	//读取数据中前台显示
		this.AddPinglun = function ()
	{
		
		//alert(Orderid);
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_ajax_pinglun_show.php";
		ajax_post(strURL, 
			this.toJSONString(), this.PLCallback);
	}
	
	this.PLCallback = function(responseText)
	{
		var strResult = responseText.parseJSON();
		//alert(strResult);
		/*if(strResult.length>1)
		{
			alert (strResult[0][0]);
		}
		else
		{
			alert (strResult);
		}*/
		//alert (strResult.length);
	    var result='';
	    vstr='';
	     //数据容器设定   
	    var data1 = {
	        plinfo : [], 
            pageinfo : { page: strResult[0][16],  inforow: strResult[0][17]}
	   		};
	   // alert(data1.plinfo[0].shoplistlink);
	   		for (i = 0; i < strResult.length; i++)
	        {
	        	 data1.plinfo.push({ shopname1: strResult[i][0], imgLink: strResult[i][1], nameLink: strResult[i][2],
	  				    shoplistlink: strResult[i][3], commentid: strResult[i][4], smiles: strResult[i][5],
	  				     contt: strResult[i][6], sdate: strResult[i][7]});
	        }
	   
	   // alert(data.products[1].name);
	 //  new TrimPath;
	  result = TrimPath.processDOMTemplate(pltemp, data1);
	 
	 // alert(result);
	  document.getElementById('dpshow122').innerHTML = result;
	}
	
}
	
function ShopPinglunshow(ShopId,Pageid,Orderid)
{
	var myShoppl = new ShopPinglun(ShopId,Pageid,Orderid);
	myShoppl.AddPinglun();
}
////////////////////////////////////////////////////////////////////////////////////////
//文章搜索展示
////////////////////////////////////////////////////////////////////////////////////////
function ShopNews(Searchstr,Pageid,Orderid) {
	this.Searchstr = Searchstr;
	this.Pageid = Pageid;
	this.Orderid = Orderid;
	//读取数据中前台显示
		this.AddNews = function ()
	{
		//alert("ajax post:" + this.ShopName);
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_ajax_news_show.php";
		ajax_post(strURL, 
			this.toJSONString(), this.NewsCallback);
	}
	
	this.NewsCallback = function(responseText)
	{
		var strResult = responseText.parseJSON();
		//alert(strResult);
		if(strResult==false)
		{
			document.getElementById('shopsnews1').innerHTML = '';
		}else
		{
			document.getElementById('shopsnews1').innerHTML = strResult;
		}
			
	}
	
}
	
function ShopNewsshow(Searchstr,Pageid,Orderid)
{
	//
	document.getElementById('news_but').className="click";
	document.getElementById('blog_but').className="normal";
	document.getElementById('shop_but').className="normal";
	document.getElementById('shoplist').style.display="none";
	document.getElementById('shopsnews').style.display="block";
	document.getElementById('shopsnews1').innerHTML = '<img src="http://food.gootrip.com/_20module/eating/loading.gif">';
	document.getElementById('shopsSpaces').style.display="none";
	var myShopNews = new ShopNews(Searchstr,Pageid,Orderid);
	myShopNews.AddNews();
}

////////////////////////////////////////////////////////////////////////////////////////
//文章搜索展示
////////////////////////////////////////////////////////////////////////////////////////
function ShopSpaces(Searchstr,Pageid,Orderid) {
	this.Searchstr = Searchstr;
	this.Pageid = Pageid;
	this.Orderid = Orderid;
	//读取数据中前台显示
		this.AddSpaces = function ()
	{
		
		//alert("ajax post:" + this.ShopName);
		
		var strURL = window.location.protocol + "//" + window.location.host + 
			"/_20module/eating/shops_ajax_spaces_show.php";
		ajax_post(strURL, 
			this.toJSONString(), this.SpacesCallback);
	}
	
	this.SpacesCallback = function(responseText)
	{
		//document.getElementById('shopsSpaces').innerHTML = 'rrrrrrrrrrrrrrrr';
		var strResult = responseText.parseJSON();
		//alert(strResult);
		if(strResult==false)
		{
			document.getElementById('shopsSpaces1').innerHTML = '';
		}else
		{
			document.getElementById('shopsSpaces1').innerHTML = strResult;
		}
		
	  
	}
	
}
	
function ShopSpacesshow(Searchstr,Pageid,Orderid)
{
	//
	document.getElementById('blog_but').className="click";
	document.getElementById('news_but').className="normal";
	document.getElementById('shop_but').className="normal";
	document.getElementById('shoplist').style.display="none";
	document.getElementById('shopsnews').style.display="none";
	document.getElementById('shopsSpaces').style.display="block";
	document.getElementById('shopsSpaces1').innerHTML = '<img src="http://food.gootrip.com/_20module/eating/loading.gif">';
	//document.getElementById('shopsSpaces1').innerHTML = '<img src="loading.gif">';
	var myShopSpaces = new ShopSpaces(Searchstr,Pageid,Orderid);
	myShopSpaces.AddSpaces();
}

function ShopSpacesshow22(Searchstr,Pageid,Orderid)
{
	//
	document.getElementById('blog_but').className="click";
	document.getElementById('news_but').className="normal";
	document.getElementById('shop_but').className="normal";
	document.getElementById('shoplist').style.display="none";
	document.getElementById('shopsnews').style.display="none";
	document.getElementById('shopsSpaces').style.display="block";
	
	var myShopSpaces = new ShopSpaces(Searchstr,Pageid,Orderid);
	myShopSpaces.AddSpaces();
}

function Shopsshow()
{
	//
	document.getElementById('blog_but').className="normal";
	document.getElementById('news_but').className="normal";
	document.getElementById('shop_but').className="click";
	document.getElementById('shoplist').style.display="block";
	
	document.getElementById('shopsnews').style.display="none";
	document.getElementById('shopsSpaces').style.display="none";

}

////////////////////////////////////////////////////////////////////////////////////////
