$(document).ready(function (){
	$(function (){
		function send2(text){
			$("#star_rating").html(text);
		}
		function send3(text){
			$("#feed_lists").html(text);	
		}

		function sendCand(text){
			if (text!=''){
				$("#shopCandidate").html(text);
				//alert(text);
			}	
		}
		$.get("star_rating.php?"+Math.random(),{pid:$("#pid").val()},send2);
		$.get("feed_lists.php?"+Math.random(),{xid:$("#xid").val()},send3);

		$.get("shopCandidate.php?"+Math.random(),{xid:$("#xid").val()},sendCand);
		
		$(".alt").tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			extraClass: "alertSource",
			fixPNG: true,
			left: 10,
			top:0
		});
		
		/* 促销模板 */
		$('#onSaleRoll').innerfade({
			animationtype: 'slide',
			speed: 300,
			timeout: 10000,
			containerheight: '270px'
		});	
	});
	
	$("#shift_rep").click(function (){
		$("#feedback").toggle('normal');			   
	});
	$("div#feedback img").click(function (){
		$("#feedback").hide(150);
		$("#fb_body").html("吃面");
	});
	$("#sub_feed").click(function (){
		var c = $("#fb_body").val();
		c = c.replace(/(^\s*)|(\s*$)/g,'');
		if (c.length>250){
			alert("留言限制在200个字内！");
			return false;
		}
		var pid = $("#pid").val();
		var pname = $("#pname").val();

		if (c!=''){
			function send(text){
				if (text==1){
					//alert("回复完成！");	
					window.location.reload();
					$("#fb_body").val("");	
				}else{
					alert(text);
				}
			}
			$.get("star_rating.php?"+Math.random(),{xid:$("#xid").val(),pid:pid,cont:c,pname:pname},send);
		}else{
			alert("你还未输入留言，或者点击[快速回复]留言");
		}
	});

})
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));

function IeTrueBody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function GetScrollTop(){
 return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function standard( aid ){
	window.location.href = 'shop_detail.php?aid=' + aid + '&r=' + Math.floor( Math.random()*10000 );
}
var key = true;
function star(o){
	if (!key){
		alert("您已经打过分！");	
		return false;
	}
	if (o!='' && key==true){
		key = false;
		//var xid = $("#xid").val();
		//var pname = $("#pname").val();
		var pid = $("#pid").val()
		function send(text){
			if (text!=1){
			clearInterval(time);
			//showMessage();
			alert("操作成功！");
			$("#star_rating").html(text);
			}else{
				alert("您已经打过分！");	
			}
		}
		$.get("star_rating.php?"+Math.random(),{star:o,pid:pid},send);
	}
}
function standardover(obj){
	$(obj).addClass("standardOver");
}
function standardout(obj){
	$(obj).removeClass("standardOver");
}
function shop_detail(o){
	window.open("shop_detail.php?aid="+o.id,'_blank','');
}
function user_detail(o){
	window.location.href = "home.php?uid="+o.id;
}
var alpha = 90;
var bole  = true;
var time  = '';
function sub_poll(u,x,s){
	if (s==2){
		$(".topBehalfPoll").hide();
	}
	function send(text){
		//alert(text);return false;
		clearInterval(time);
		//showMessage();
		alert("操作成功！");
		//$("#resPoll_"+u+x).html(text);
		$("#rollValue").html(parseFloat($("#rollValue").html())+1);		
	}
	$.get("behalf_poll.php?"+Math.random(),{uid:u,xid:x},send);
}
function showMessage(){
	if (document.getElementById('boxes').style.display="none"){
		document.getElementById('boxes').style.display="block";
	}
	document.getElementById('boxes').filters.alpha.opacity=90;
	alpha = 90;
	bole  = true;
	time = setInterval("recheck()",3000);
}
function recheck(){
	if (bole == true){
		alpha -=5;
	}
	if (alpha == 0){
		bole = false;
	}
	if (document.getElementById('boxes').filters.alpha.opacity!=0){
		document.getElementById('boxes').filters.alpha.opacity=alpha;
	}
	if (alpha==5){
		document.getElementById('boxes').style.display="none";
	}
	if (bole == true){
	setTimeout("recheck()",50);
	}
}
function showBigImg(){
	var pid = $("#pid").val();
	window.open("showBigImg.php?pid="+pid,"_blank","width=550px,height=550px");	
}
function defaultImg(o){
	var s = "";
	var src = o.src;
	var str = src.split("/");
	var img = str[str.length-1].split("_");
	for (i=0;m=str.length,i<m-1;i++){
		s += str[i]+ "/";
	}
	s += "_"+img[1];
	o.src = s;
}
function candidate(){
	var xid = $("#xid").val();
	var id  = $("#pid").val();
	var n_id= "pn_"+id;
	var nid = $("#"+n_id).val();
	var pri = $("#pri_"+id).html();
	var pay = $("#pay_"+id).html();
	var name= $("#"+id+"_t").html();
	var stat= $("#stat_"+id).val();
	var type= $("#type_"+id).val();
	var str = encodeURI(id+"|"+nid+"|"+pri+"|"+pay+"|"+name+"|"+stat+"|"+type);
	window.location.href="candidate.php?str="+str+"&xid="+xid;	
}
function feedLogin(){
	var addr = location.protocol + '//' + location.host + location.pathname + location.search;
	function sendSession(text){
		window.location.href='login.php';
	}
	$.get("include/session.inc.php",{addr:addr},sendSession);
}
function tastSearch(t){
	if (t!=''){
		window.location.href='shop_lists.php?z='+encodeURI(t);
	}	
}
function tagSearch(t){
	if (t!=''){
		window.location.href='shop_lists.php?x='+encodeURI(t);
	}	
}

function put2favor( pid ){
	window.location.href = 'fav.php?p='+pid;
}
