
var userAgent = navigator.userAgent.toLowerCase();
var is_opera = $.browser.opera;
var is_moz = $.browser.mozilla;
var is_ie = $.browser.msie;


if ($.browser.msie&&$.browser.version<"7.0"){
	try {document.execCommand("BackgroundImageCache", false, true);}
	catch(err){}
}

function chk_search_from(index){

	var txt=$("#search_txt").val();
	if(txt==""){
		alert('请输入关键字');
		$("#search_txt").focus();
		return false;
	}

	txt=encodeURIComponent(txt);
	var type=selectRadio('index_search_type');
	type=parseInt(type);

	var para='';
	if( typeof index!='undefined' && index ){
		para="?6a992d5529f459a44fee58c733255e86=1";
	}

	if(type == 2){
		top.location.href="/store/!/k/" + txt + para;
	}
	else if ( type == 1){
		top.location.href="/searchgoods/word/" + txt + para;
	}
	
	return false;
}

function setValue(sw ,field_name, msg){
	var field = document.getElementById(field_name);
	if (sw == 'on'){
		if (field.value.indexOf(msg) > -1) {			
			field.value='';
		}
	} else {
		if (field.value == '') {			
			field.value = msg;
		}
	}
}

function doSearch(){

	var keyword = document.getElementById('keyword');

	var enkeyword = encodeURIComponent(keyword.value);
	
	if (keyword.value != "") {
		
		if( $("#search_type").val() == "store" ){
			//http%3A%2F%2F
			enkeyword=enkeyword.substr(0,13)=="http%3A%2F%2F"?enkeyword.substring(13):enkeyword;
			top.location.href="/store/!/k/" + enkeyword;
		}
		else if( $("#search_type").val() == "cuxiao"  ){
			enkeyword=enkeyword.substr(0,13)=="http%3A%2F%2F"?enkeyword.substring(13):enkeyword;
			top.location.href="/searchcuxiao?q=" + enkeyword;			
		}
		else{
			//top.location.href="/searchgoods/word/" + enkeyword;
			top.open('http://www.youmaima.com/search?q='+enkeyword);
		}
		
	} else {
		alert("关键字不能为空");
	}
	
}

function search_keydown(e,memo){

	var k=window.event?window.event.keyCode:e.which ;

	
	if( k == 13) //Enter key
	{
		//alert( $("#search_img") );
		if( $("#keyword").val() != memo ){
			doSearch();
		}
	}	
}

	//添加书签
	function bookmark(id){
	
		if(!id) return;
	
		//alert(id);
		//return;
		if( !document.getElementById('div_login') ){
			$.get(
				"/user/bookmark/add/",
				{"deal_id":id},
				function (msg){
					//alert("aaaaa");
					//alert(msg);
					if(msg){ alert(msg); }
				}
			);
		}
		else{
			show_login();
		}
		return false;
	}

function getX(obj){
	var ParentObj=obj;
	var left=obj.offsetLeft;
	while(ParentObj=ParentObj.offsetParent){
		left+=ParentObj.offsetLeft;
	}
	return left;
}

function getY(obj){
	var ParentObj=obj;
	var top=obj.offsetTop;
	while(ParentObj=ParentObj.offsetParent){
		top+=ParentObj.offsetTop;
	}
	return top;
}

function GetMousePos(ev){  //ev是事件对象
    if(ev.pageX || ev.pageY){
        return {x:ev.pageX, y:ev.pageY};
    }
    else if(document.documentElement.scrollTop) {
        return {
            x:ev.clientX + document.documentElement.scrollLeft,
            y:ev.clientY + document.documentElement.scrollTop };
        }
        else {
        return {
            x:ev.clientX + document.body.scrollLeft-document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop-document.body.clientTop };
        }
}

//ajax处理中

function Ajax_Load_Show(source){
	
	var Ajax_Load_Div="";

	Ajax_Load_Div=document.getElementById('Ajax_Load_Div');

	if(Ajax_Load_Div == "" || Ajax_Load_Div==undefined || !Ajax_Load_Div){

		var Ajax_Load_Div=document.createElement('DIV');
		
		try{
			var src=window.event.srcElement;
			
			var x=getX(src)+parseInt(document.body.scrollLeft);
			var y=getY(src)+parseInt(document.body.scrollTop)+30;		
			
			Ajax_Load_Div.style.color='#00FF00';
			Ajax_Load_Div.style.fontsize='75%';
	
			//alert('top:'+y+' left:'+x);
			
			Ajax_Load_Div.style.top=y;
			Ajax_Load_Div.style.left=x;
			
			//Ajax_Load_Div.style.top=top?top:20;
			//Ajax_Load_Div.style.left=left?left:30;		
			
			Ajax_Load_Div.style.padding=2;
			Ajax_Load_Div.style.position='absolute';
			Ajax_Load_Div.style.background='#000000';
			Ajax_Load_Div.style.zIndex =3;			
		}
		catch(e){
			var src=source;//arguments.callee.caller.arguments[0].target;
			Ajax_Load_Div.style.cssText="color:#00FF00;fontsize:75%;position:absolute;background:#000000;zIndex:3;"+"";
		}

		Ajax_Load_Div.id='Ajax_Load_Div';
		Ajax_Load_Div.innerHTML="正在执行...";
		
		//alert(Ajax_Load_Div.style.top);
		document.body.appendChild(Ajax_Load_Div);

	}
	Ajax_Load_Div.style.display='';
}

//ajax 隐藏

function Ajax_Load_Hidden(){
	
	var Ajax_Load_Div;
	Ajax_Load_Div=document.getElementById('Ajax_Load_Div');
	Ajax_Load_Div.style.display ='none';
	
}

/**
 * 选择Radio，取得值
 */
function selectRadio(radioName)
{
	//alert(radioName);
	var tempRadio = document.getElementsByName(radioName);
	
	for (var i=0; i<tempRadio.length; i++) 
	{
		if (tempRadio[i].checked == true) 
		{
			var tempValue = tempRadio[i].value;
			break;
		}
	}
	//alert(tempValue);
	return tempValue;
}

/**
 * 设置Radio，值
 */
function setRadio(radioName,checked)
{//alert(radioName);
	var tempRadio = document.getElementsByName(radioName);
	var number = "";
	for (var i=0; i<tempRadio.length; i++) 
	{
		if (tempRadio[i].value == checked) 
		{
			tempRadio[i].checked = true;
			number = i;
			break;
		}
	}
	//alert(tempValue);
	return number;
}

/**
 * 使用W3C标准语法为SELECT添加Option
 * addOption
 * @param objSelectNOw
 * @param txt
 * @param val
 * @param s_txt
 */
function addOption(objSelectNow, txt, val, s_txt)
{
	var objOption = document.createElement("OPTION");
	objOption.text = "";
	objOption.value ="";
	objOption.selected = "";

	objOption.text = txt;
	objOption.value = val;
	//alert(s_txt);
	if (val == s_txt){
	  objOption.selected = "selected";
	}else{
	  objOption.selected = "";
	}
	objSelectNow.options.add(objOption);
}

/**
 * 设置cookies值
 * @param name		名
 * @param value		值
 * @param expires	过期时间
 * @param path		路径
 * @param domain	域
 * @param secure 	安全
*/
function setCookie(name, value, expires, path, domain, secure) 
{
	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	if ((name + "=" + escape(value)).length <= 4000)
	{
		document.cookie = curCookie;
	}
	else if (confirm("Cookie exceeds 4KB and will be cut!"))
	{
		document.cookie = curCookie;
	}
		
}

function   getCookie(name)	 //cookies读取 
{ 
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null; 
}

/**
 * 删除cookies值
 * @param delCookie 
 */
function delCookie(cookieName)
{   
	if (!cookieName)
	{
		cookieName = cfg.cookiesName;
	}
	var exp = new Date();exp.setTime(exp.getTime() - 1);
	setCookie(cookieName,null,exp,'/','');
	   
}

/** 
  * 用途：判断一个值是否在数组中,相当于php的in_array 
  * 输入： child：字符串 
  * 返回： 如果通过验证返回true,否则返回false 
  */
Array.prototype.inArray = function (child) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == child) return true;
	}
	return false;
};

function strlen(str){
	var len = 0;
	var c_len = 2;//charset == 'utf-8' ? 3 : 2;
	for(var i=0;i<str.length;i++){
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? c_len : 1;
	}
	return len;
}
function txt_limit(obj,limit){

	var val=$(obj).val();
	var len=strlen(val);
	if(len>limit){
		$(obj).val( val.substr(0,limit) );
	}
}

	function store_digg( store_id, rating_id ){
	
		if(!store_id || !rating_id) return false;
		
		$("btn_digg_"+rating_id).attr('disabled',true);
		
		//Ajax_Load_Show();
		
		$.get(
		
			"/store/comment/add-digg",
			{"store_id":store_id,"rating_id":rating_id,"useful":selectRadio('useful_'+rating_id)},
			function (data){
				
				//var msg=data;
				//alert(data);				
				//document.writeln(data);
				$("btn_digg_"+rating_id).attr('disabled',false);
				//Ajax_Load_Hidden();
				
				if(data){
					eval("var msg="+data);
					
					if( msg['nologin'] ){
						alert(msg['nologin']);
					}
					else{
						$("#digg_"+rating_id).html( msg['td'] );
					}
					eval("var msg='';");
				}
			}
		);
	}
	
/**
 * getObj
 */ 
function getObj(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    } else {
		return false;
    }
}

function selectAllCheckBox(CheckBoxName, obj)
{
	var tempCheckBox = document.getElementsByName(CheckBoxName);
	var value = obj.checked;

	for (var i=0; i<tempCheckBox.length; i++) 
	{
		if (value)
		{
			if (tempCheckBox[i].checked != true) 
			{
				tempCheckBox[i].checked = true;
			}
		}
		else
		{
			if (tempCheckBox[i].checked == true) 
			{
				tempCheckBox[i].checked = false;
			}
			
		}
	}
	
	return tempCheckBox.length;
}

function selectOptionByValue(name, value ){
	
	var obj=document.getElementsByTagName( 'SELECT' );
	obj=obj[name];

	for (i=obj.options.length-1;i>=0;i--)   
	  {   
		  if(obj.options[i].value==value){
				obj.options[i].selected=true;
				return true;
		  }
	  }
	return false;
}

function selectCheckBox(CheckBoxName)
{
	var tempCheckBox = document.getElementsByName(CheckBoxName);
	var tempValue = Array();
	for (var i=0; i<tempCheckBox.length; i++) 
	{
		if (tempCheckBox[i].checked == true) 
		{
			tempValue.push(tempCheckBox[i].value);
		}
	}
	var tempStr = "["+tempValue.toString()+"]";
	return tempStr;
}
function cfmMsg(msg)
{
	if(confirm(msg))
	{    			
		return true;
	}
	else
	{
		return false;
	}
}

function chkuser(){

	var member=$("#tomember").val();
	
	if(member!=''){

		$.get(
			"/user/index/userisexist/",
			{"user":member},
			function (msg){
				
				//alert(msg);
				if(parseInt(msg) == 0){ 
					
					$("#tomember").attr('error','收件人用户名不存在');
					//$("#tomember").focus();
				}
				else if(parseInt(msg) == 1){
					$("#tomember").attr('error','');
				}
			}
		);
	}
}

function art_favorite(id){

	if(!id) return;

	//alert(id);
	//return;
	if( !document.getElementById('div_login') ){
		$.get(
			"/article/index/favorite/",
			{"art_id":id},
			function (msg){
				//alert("aaaaa");
				//alert(msg);
				if(msg){ alert(msg); }
			}
		);
	}
	else{
		show_login();
	}

	return false;
}

//div登陆
function div_login(){

	var frm=document.div_login_frm;
	var errmsg='';

	if(frm.username.value==''){
		errmsg='请输入用户名\r\n';
	}

	if(frm.password.value==''){
		errmsg=errmsg+'请输入密码';
	}

	if(errmsg!=''){
		alert(errmsg);
		return false;
	}

	if(_login_go_Url!=''){
		frm.from.value='';
	}

	frm.submit();

	return true;

}

//登陆div
function show_login( url ){

	var top=0;
	var left=0;
	
	_login_go_Url=(url!=undefined?url:'');

	if(document.documentElement.scrollTop){
		top=document.documentElement.scrollTop;
		}
	else{
		top=document.body.scrollTop;
		}
		
	//alert("left:"+(posx-30));
	//alert("top:"+(top+144));
	//return false;
	//margin-left:-201px; margin-top:-147px; position:absolute;
	//$("#sp_product_id").val(product_id);
	
	//alert($(document).width());
	
	
	$("#div_login").css('left',getWidthmiddle());
	$("#div_login").css('top',(top+156)+"px");
	$("#div_login").css('display','block');
	$("#username").focus();

	return false;
}

function dianping_chk(go_url){

	if( !document.getElementById('div_login') ){
		window.location.href=go_url;
	}
	else{
		var exp = new Date();
		exp.setTime(exp.getTime() + 3600*24*30);

		setCookie('dianping_login','1',exp,'/','');
		show_login(go_url);
	}
	
	return false;
}

function jsSendStore(){
	var store_name = $('#send_store_name').val();
	var store_web =  $('#send_store_web').val();
	
	if( store_name == "" ){alert('请输入网店名称');return;}
	if( store_web == "" ){alert('请输入网址');return;}
	
	$("#sendinfo_submit").attr('disabled',true);
	try{
	Ajax_Load_Show(arguments.callee.caller.arguments[0].target);
	}catch(e){
		Ajax_Load_Show();
	}
			
	$.get(
			"/other/sendstore/add/",
			{"store_name":store_name, "store_web":store_web},
			function (msg) {				
				
				Ajax_Load_Hidden();
				$("#sendinfo_submit").attr('disabled',false);
				
				if (msg) alert(msg);
				
				if(msg == "网店发送成功"){
					$('#send_store_name').val("");
					$('#send_store_web').val("");
				}									
			}	
	);
}

function jsSendDeal(){

	if( !document.getElementById('div_login') ){

		var deal_title = $('#deal_title').val();
		var senddealcontent =  $('#senddealcontent').val();
		if( deal_title == "" ){alert('请输入标题');return;}
		if( senddealcontent == "" ){alert('请输入详细内容');return;}
		$("#sendinfo_submit").attr('disabled',true);
		try{
		Ajax_Load_Show(arguments.callee.caller.arguments[0].target);
		}catch(e){
			Ajax_Load_Show();
		}				
		$.get(
				"/other/senddeal/add/",
				{"title":deal_title, "senddealcontent":senddealcontent},
				function (msg) {
					Ajax_Load_Hidden();
					$("#sendinfo_submit").attr('disabled',false);
														
					if (msg) alert(msg);
					
					if(msg == "信息发送成功"){
						$('#deal_title').val("");
						$('#senddealcontent').val("");
					}									
				}	
		);		
	}
	else{
		show_login();
	}
}

function show_search_hot(){

	//index_search_type
	var type=selectRadio('index_search_type');
	//alert(type);
	type=parseInt(type);

	if(type == 1){
		$("#goods_hot").css('display','');
		$("#store_hot").css('display','none');
	}
	else if (type==2)
	{
		$("#goods_hot").css('display','none');
		$("#store_hot").css('display','');
	}

}

function newsee(IsNew,from,newWindow){

	var oktitle='';
	if(IsNew == true){

		var email=$("#email").val();
		var url=$("#url").val();

		if(url == "" || url=="例如：http://item.taobao.com/auction/item_detail-0db1-d3d28dd.jhtml"){
			alert("请输入商品页面链接");
			$("#url").focus();
			return false;
		}

		if(from != 'xiaonei'){

			if(email == "" || email == "例如：yourname@163.com"){
				alert("请输入电子邮箱");
				$("#email").focus();
				return false;
			}
		}
		else{
			email='';
		}

		/*
		if(email == "yourname@163.com"){
			alert("请输入邮箱\t\n请输入商品页面URL");
			return false;
		}
		*/

		oktitle='priceNotice';
	}
	else{
		var id=$("#sp_product_id").val();
		var email=$("#txtEmail").val();
		//var phone=$("#txtMoblie").val();
		var favorite_product=$("#favorite_product").attr('checked');
		var phone='';
		
		//alert(favorite_product);
		//return false;
		
		if(email == ""){
			alert("请输入邮箱");
			$("#txtEmail").focus();
			return false;
		}
		oktitle='sp_ok';
	}

	$("#"+oktitle).val("正在执行...");
	$("#"+oktitle).attr('disabled',true);

	$.get(
		"/store/index/seeprice/",
		{"id":id,"email":email,"phone":phone,"from":(typeof(from)=='undefined'?'':from),"url":IsNew==true?url:'',"xn_uid":$("#userId").val()?$("#userId").val():''},
		function (msg){
			

			$("#"+oktitle).attr('disabled',false);
			$("#"+oktitle).val(IsNew==true?"价格变动时通知我":"确定");
						
			if(parseInt(msg) == 1){
				alert('订阅成功');
				if(!IsNew){
					$("#div_seeprice").css('display','none');
				}
				else{
					$("#url").val('');
				}
				if(newWindow == true){

					window.opener =null;
					window.close();
				}

			}
			else if (parseInt(msg) == 2){
				alert('您已经订阅该商品的价格变动');
			}
			else if (parseInt(msg) == -1){
				alert('订阅失败');
			}
			else if (parseInt(msg) == 3)
			{
				alert('您输入的商品URL暂时无法跟踪\n建议使用迪乐网商品搜索找到相关商品后再使用价格提醒功能\n请查看可监测价格的网店列表');

			}
		}
	);
	return false;
}

function priceNoticeFromRecommend(url){

	var email=$("#priceEmail").val();
	if(email == ""){
		alert('请输入email');
		return false;
	}

	$("#rp_ok").val('正在执行中...');
	$("#rp_ok").attr('disabled',true);
	$.get(
		"/store/index/seeprice/",
		{"email":email,"from":(typeof(from)=='undefined'?'':from),"url":url},
		function (msg){
			
			//alert(msg);

			$("#rp_ok").attr('disabled',false);
			$("#rp_ok").val("确定");
						
			if(parseInt(msg) == 1){
				alert('订阅成功');
				$("#div_recommend_pricenotice").css('display','none');
			}
			else if (parseInt(msg) == 2){
				alert('您已经订阅该商品的价格变动');
			}
			else if (parseInt(msg) == -1){
				alert('订阅失败');
			}
			else if (parseInt(msg) == 3)
			{
				alert('您输入的商品URL暂时无法跟踪\n建议使用迪乐网商品搜索找到相关商品后再使用价格提醒功能\n请查看可监测价格的网店列表');
			}
		}
	);
	return false;

}

function seeprice(product_id,e){

    var top=0;
    var left=0;
    
    if(document.documentElement.scrollTop){
        left=document.documentElement.scrollLeft;
        top=document.documentElement.scrollTop;
        }
    else{
        left=document.body.scrollLeft;
        top=document.body.scrollTop;
        }
        
    //alert("left:"+(posx-30));
    //alert("top:"+(top+144));
    //return false;
    
	$("#sp_product_id").val(product_id);
	
	if(is_moz){
		var left="280px";
	}
	else{
		var left="150px";
	}
	$("#div_seeprice").css('left',left);
	$("#div_seeprice").css('top',(top+156)+"px");
	$("#div_seeprice").css('display','block');
}

var firstUrl=1;
var firstEmail=1;
var txt_show_content="";

function focusTxt(id,value){

	if(txt_show_content=="" && value!="" && typeof(value)!='undefined'){
		txt_show_content=value;
	}

	if(id == "url")
	{
		if( $("#url").val() == "例如：http://item.taobao.com/auction/item_detail-0db1-d3d28dd.jhtml"  ){
			setTxt(id);
		}		
	}
	else if (id == "email")
	{
		if( $("#email").val()	==	"例如：yourname@163.com"){
			setTxt(id);
		}
	}
	
	else if(id == "recommend_store_url"){
		if( $("#recommend_store_url").val()	==	"例如:http://www.360buy.com"){
			setTxt(id);
		}		
	}
	
	else{
		if( $("#"+id).val() == txt_show_content  ){
			setTxt(id);
		}
	}
}

function loseTxt(id, indexpage){

	var url=$("#url").val();
	var email=$("#email").val();

	if(id == "url")
	{
		if(url==''){
			$("#url").val("例如：http://item.taobao.com/auction/item_detail-0db1-d3d28dd.jhtml");
			if(indexpage==true){
			document.getElementById(id).className='trackurl_side';
			document.getElementById(id).style.color='#A9A9A9';
			}
			else{
			document.getElementById(id).className='tracktext';
			document.getElementById(id).style.color='#A9A9A9';
			}
		}
		else{
		}
	}
	else if (id == "email")
	{
		if(email==''){
			$("#email").val("例如：yourname@163.com");
			if(indexpage==true){
			document.getElementById(id).className='trackurl_side';
			document.getElementById(id).style.color='#A9A9A9';
			}
			else{
			document.getElementById(id).className='tracktext';
			document.getElementById(id).style.color='#A9A9A9';
			}
		}
		else{
		}
	}	
	else if(id == "recommend_store_url"){
		if($("#recommend_store_url").val()==''){
			$("#recommend_store_url").val("例如:http://www.360buy.com");

			if(indexpage==true){
			document.getElementById(id).className='trackurl_side';
			document.getElementById(id).style.color='#A9A9A9';
			}
			else{
			document.getElementById(id).className='tracktext';
			document.getElementById(id).style.color='#A9A9A9';
			}
		}		
	}
	else if( id == "q" ){
		if($("#"+id).val()==''){
			$("#"+id).val("搜索网店");
			
			document.getElementById(id).style.color='#A9A9A9';
		}		
	}	
	else{
		if($("#"+id).val()==''){
			$("#"+id).val(txt_show_content);
			//document.getElementById(id).className='tracktext';
			document.getElementById(id).style.color='#A9A9A9';
		}		
	}
}

function setTxt(id){
	document.getElementById(id).value='';
	document.getElementById(id).style.color='#000000';
}

function getWidthmiddle(obj_width){
	
	$("#openwin").css('height','auto');

	if( typeof(obj_width)== 'undefined' ) {
		var obj_width=325;
	}
	var width;
    if(document.documentElement.clientWidth){
        width=document.documentElement.clientWidth;
        }
    else{
        width=document.body.clientWidth;
        }
	width=width-obj_width;
	return (parseInt(width/2))+"px";
}

function deal_subscribe(store_id){

    var top=0;
    var left=0;
    
    if(document.documentElement.scrollTop){
        top=document.documentElement.scrollTop;
        }
    else{
        top=document.body.scrollTop;
        }
    
	$("#deal_subscribe_store_id").val(store_id);
	
	$("#div_deal_subscribe").css('left',getWidthmiddle());
	$("#div_deal_subscribe").css('top',(top+156)+"px");
	$("#div_deal_subscribe").css('display','block');
}

function new_deal_subscribe(){

	var id=$("#deal_subscribe_store_id").val();
	var email=$("#deal_subscribe_email").val();
	
	//alert(favorite_product);
	//return false;
	
	if(email == ""){
		alert("请输入邮箱");
		$("#deal_subscribe_email").focus();
		return false;
	}

	var oktitle='deal_subscribe_ok';
	$("#"+oktitle).val("正在执行...");
	$("#"+oktitle).attr('disabled',true);
	
	$.get(
		"/store/index/dealsubscribe/",
		{"store_id":id,"email":email},
		function (msg){
			
			//alert(msg);

			$("#"+oktitle).attr('disabled',false);
			$("#"+oktitle).val("确定");
						
			if(parseInt(msg) == 1){
				alert('订阅成功');
				$("#div_deal_subscribe").css('display','none');			
			}
			else if (parseInt(msg) == 2){
				alert('您已经订阅该网店的促销');
			}
			else if (parseInt(msg) == -1){
				alert('订阅失败,请稍候再试');
			}
			else if(parseInt(msg) == -2){
				alert('请输入正确的邮件地址');
			}
			else if (parseInt(msg) == 3)
			{
				alert('');
			}
		}
	);
	return false;
}

function recommend_favorite(id,opt,obj){

	if(!id) return;

	//alert(id);
	//return;
	if( !document.getElementById('div_login') ){
		$.get(
			"/recommend/index/favorite/",
			{"recommend_id":id,"opt":opt},
			function (msg){
				//alert("aaaaa");
				//alert(msg);
				if(msg){ 
					alert(msg);
					if(msg == "收藏推荐成功"){
						$("#favorite_recommend").html("已收藏(取消)");
						$("#favorite_recommend").unbind("click");
						$("#favorite_recommend").bind("click",function(){ return recommend_favorite(id,'remove');});
					}
					else if( msg == "成功删除该推荐收藏"){
						$("#favorite_recommend").html("收藏该商品");
						$("#favorite_recommend").unbind("click");
						$("#favorite_recommend").bind("click",function(){ return recommend_favorite(id,'');});						
					}
				}
			}
		);
	}
	else{
		show_login();
	}

	return false;
}

function recommend_sendemail(id){
	
	var toEmail=$("#toEmail").val();
	var fromEmail=$("#fromEmail").val();
	var err='';
	if(toEmail==''){
		err="请输入您朋友的email地址";
	}
	if(fromEmail==''){
		err=err+"\r\n"+"请输入您的email地址";
	}

	if(err==''){
		$.get(
			"/recommend/index/sendmail",
			{"recommend_id":id,"toemail":toEmail,"fromemail":fromEmail,"memo":$("#sendmail_txt").val()},
			function (msg){
				if(msg){
					alert(msg);
					if(msg == "发送成功"){
						$("#div_recommend_sendmail").css('display','none');
					}
				}
			}			
		);
	}
	else{
		alert(err);
		return false;
	}
}

function agreeRecommend(id,flag){
	
	if(!id || id==null){
		return ;
	}

	var action=(flag==true?"agree":"agree_no");
	var memo=(flag==true?"已投票":"已投票");
	var html=$("#"+action+"_"+id).html();

	if( html.split("已投票").length>1 || html.split("已投票").length>1 ){	
		return false;
	}

	$.get(
		"/recommend/index/ajax",
		{"do":action,"id":id},
		function (msg){
			//alert(msg);
			$("#"+action+"_"+id).html(memo+"("+msg+")");
		}
	);
	return false;
}

function chk_submit_recommend(){
	
	var url=$("#recommend_url").val();
	if( url == '' || url =='输入您要推荐的商品页面链接URL'){
		$("#recommend_url").focus();
		return false;
	}

	return true;

}

function recommendation_full(id){

	var div_full	=$("#content_"+id+"_full");
	var div_short	=$("#content_"+id+"_short");
	var img			=$("#img_show_"+id);
	var short_html	=div_short.html();

	if( img.attr("alt") == "展开" ){

		//alert(short_html.substr(short_html.length-3,3));

		if( short_html.substr(short_html.length-2,2) == ".."){

			if( div_full.html() == "" ){
				
				$.get(
						"/recommend/index/ajax",
						{"id":id,"do":"recommendation_full"},
						function (data){

							//eval("var tmp_content="+data);
							div_full.html(data);
							div_short.hide();
							div_full.show();
						}
					);
			}
			else{
				div_short.hide();
				div_full.show();
			}
		}
		img.attr("alt","缩进");
		//img.css("filter","FlipV");
		img.attr('src','/images/icon/up.jpg');
	}
	else{		
		div_full.hide();
		div_short.show();
		img.attr("alt","展开");
		//img.css("filter","");
		img.attr('src','/images/icon/iconlaw.gif');
	}
	return false;
}

function chk_recommend_search(){

	var words=$("#words").val();

	if(words == "输入商品关键字进行搜索"){
		$("#words").val('');
	}
	return true;
}

function recommend_store(url){
	
	if(url == "" || url == "例如:http://www.360buy.com"){
		alert("请输入网店网址进行推荐");
		return false;
	}

	var www=encodeURIComponent(url);

	var date	=	new Date();
	date.setTime(date.getTime()+3600*24*30);
	setCookie('open_store_recommend','1',date,"/","");
	window.location.href="/recommendStore?url="+www;
}

function store_recommend(store_id,content){

	if(content==""){

		alert('请输入推荐语');
		return false;
	}

	$.post(
			"/store/index/ajax",
			{"content":content,"do":"store_recommend","store_id":store_id},
			function (data){
				if(parseInt(data) == 1){
					window.location.href="/store/"+store_id+"/recommend";
				}
				else{
					alert(data);
				}
			}
		);	
}
//copy code
function copycode(val) 
{
	//var clipBoardContent=window.document.title;
	
	window.clipboardData.setData("Text",val);
	alert("复制成功，请按CTRL+V粘贴到合适的位置！");
}

function postSolution(){

	var solution=$("#a").val();
	var game_id=$("[name=game_id]").val();

	if(solution==''){
		alert('请输入答案');
		$("#a").focus();
	}
	else{

		if( !document.getElementById('div_login') ){

			$("#submitsolution").val("正在提交...");
			$("#submitsolution").attr('disabled',true);
			$.getJSON(
				"/compete",
				{"solution":solution,"game_id":game_id},
				function (result){

					$("#submitsolution").val("提交你的回答");
					$("#submitsolution").attr('disabled',false);

					if(result.html){
						$("#a").remove();
						$("#te").html("你已经提交了答案，抢答结束后回到该页面，查看抢答结果");
						$("#submitsolution").remove();
					}
					else if(result.err){
						alert(result.msg);
					}
				}
			);
		}
		else{
			var exp = new Date();
			exp.setTime(exp.getTime() + 3600*24*30);
			if(solution!=''){					
				setCookie('compete_solution',escape(solution),exp,"/",'');
			}
			show_login();
		}
	}
	return false;
}

function track(link){
	$("#url").focus();
	$("#url").val(link);
}

var document_title=$(document).attr('title');
var show_mail=1;
function mail_tips(){
$(document).attr('title',(show_mail==1?'【新消息】- ':"【　　　】- ")+document_title);
show_mail==1?show_mail=0:show_mail=1;
}

$(document).ready(

	function (){
		var mail=$(".mail").html();
		if(mail){
			var num=mail.match(/\d+/);
			//【新消息】
			if(num>0){
				setInterval("mail_tips()",1000);
			}
		}
	}
);

function searchstores(){
	
	var q=$("#q").val();
	if(q!='' && q!='搜索网店'){
		q=encodeURIComponent(q);
		window.location.href="/store/!/k/" + q;
	}
	else{
		$("#q").focus();
	}
	
	return false;
}

var currentSection = "1-pane"; // The default loaded section on the page
var tabTag = "-tab";
var paneTag = "-pane";

// Scroll the page manually to the position of element "link", passed to us.

function ScrollSection(link, scrollArea, offset)
{

	// Store the last section, and update the current section

	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state

    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = "active";
    if (lastSection) {
	    lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";
	}
    
	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
	// return false;
}

// Scroll the page using the arrows

function ScrollArrow(direction, toolbar, scrollArea, offset) {

	toolbarElem = document.getElementById(toolbar);
	toolbarNames = new Array();
    
	// Find all the <li> elements in the toolbar, and extract their id's into an array.
    
	if (toolbarElem.hasChildNodes())
	{
		var children = toolbarElem.childNodes;
		for (var i = 0; i < children.length; i++) 
		{
			if (toolbarElem.childNodes[i].tagName == "LI") {
				toolbarNames.push(toolbarElem.childNodes[i].id.split("-")[0]);
			}
		}
	}

	// Now iterate through our array of tab names, find matches, and determine where to go.

	for (var i = 0; i < toolbarNames.length; i++) {
		if (toolbarNames[i] == currentSection.split("-")[0]) {
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = toolbarNames[toolbarNames.length - 1];
				} else {
					gotoTab = toolbarNames[i - 1];
				}
			} else {
				if ((i + 1) > (toolbarNames.length - 1)) {
					gotoTab = toolbarNames[0];
				} else {
					gotoTab = toolbarNames[i + 1];
				}
			}
		}
	}
	
	// Go to the section name!
	
	ScrollSection(gotoTab+paneTag, scrollArea, offset);

}

//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 25;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}
function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}
function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}
