//区域选择
function selectprovince(code)
{
	var	ran		=	Math.random();
	$.post(APP+'/Public/selectcity',{code:code,ran:ran},function(flid){
	    if(flid){
			$("#citys").html(flid);
		}
	});
}

//城市选择
function selectcityok(code,name)
{
	$("#address").html(name);
	$("#changearea").val(code);
	$.facebox.close();
}

//下级分类选择
function selectdowncat(id){
	var	ran		=	Math.random();
	$.post(APP+'/Public/selectdowncat',{id:id,ran:ran},function(flid){
	    if(flid){
			$("#downcat").html(flid);
		}
	});
}
//选定分类
function selectcatok(id,name){
	$("#cat").html(name);
	$("#syscatid").val(id);
	$.facebox.close();
}

//申请加为好友
function friendsend(fid){
	var	ran		=	Math.random();
	$.post(APP+'/User/friendaction',{action:'add',fid:fid,ran:ran},function(flid){
	    if(flid){
			switch(flid){
				case '-1':
					$('#js_f_info').html('此用户未加入俱乐部');
				break;
				
				case '0':
					$('#js_f_info').html('您已经发送过请求，等侍验证中...');
				break;
				
				case '1':
					$('#js_f_info').html('你们已经是好友');
				break;
				
				case '2':
					$('#js_f_info').html('操作成功');
				break;
				
				case '3':
					$('#js_f_info').html('操作失败');
				break;
			}
		}else{
			$('#js_f_info').html('操作失败');
		}
		setTimeout(function(){$.facebox.close();},700);
	});
}

//全选反选
function checkall(thisabout,pointname){
	if(thisabout.checked){
	    $("input[@id='"+pointname+"']").each(function() {     
	        $(this).attr("checked", true);    
	    });
	}else{
    $("input[@id='"+pointname+"']").each(function() {     
	        $(this).attr("checked", false);    
	    });
	}
}

//
function messagesend(touid){
	var title = $.trim($('#js_m_title').val());
	var content = $.trim($('#js_m_content').val());
	if(title==''){
		$('#js_m_info').html('标题不能为空');
		return false;
	}
	if(content==''){
		$('#js_m_info').html('内容不能为空');
		return false;
	}
	
	var	ran		=	Math.random();
	$.post(APP+'/User/messageaction',{action:'sendmessage',title:title,content:content,touid:touid,ran:ran},function(flid){
	    if(flid){
			$("#js_m_info").html('发送成功..');
			setTimeout(function(){$.facebox.close();},250);
		}
	});
	
}

function invitesend(touid){
	var title = $.trim($('#js_g_title').val());
	var content = $.trim($('#js_g_content').val());
	var ran = Math.random();
	$.post(APP+'/User/invitesend',{title:title,content:content,touid:touid,ran:ran},function(flid){
	    if(flid){
			$("#js_g_info").html('邀请信息发送成功..');
			setTimeout(function(){$.facebox.close();},600);
		}
	})
}

/*------------------- 附件上传 ------------*/
var upfilenum=1;
var image=new Image();
var selectupfiles = new Array();
function selectFile(obj){
	if(checkimg(obj)){
		file = $(obj).val();
		var  index1 =file.lastIndexOf('\\');
	    filesname = file.substring(index1 + 1);
		
		$(obj).hide();	
		$('#html_'+upfilenum).html('<a href="javascript:void(0)" onclick="delfile('+upfilenum+')">[删除]</a> <a href="javascript:void(0);" onclick="imginsert('+upfilenum+')">[插入]</a> ['+upfilenum+'] <a href="javascript:void(0)" rel="'+file+'" onmouseover="tooltip(this)" onmouseout="tooltipout()">'+filesname+'</a>');
		$('#html_'+upfilenum).show();
		
		upfilenum++;
	
		$('#selectfiles').append('<li id="file_'+upfilenum+'"><span id="html_'+upfilenum+'" style="display:none"></span><input name="upfiles['+upfilenum+']" type="file" id="fileField" size="30" onchange="selectFile(this)" /></li>');
		selectupfiles[upfilenum] = file;
	}
}

//删除
function delfile(id){
	$("#file_"+id).remove(); 
}

//插入到文章
function imginsert(id){
	FCKeditorAPI.GetInstance("editor").InsertHtml("[local]"+id+"[/local]");
}

//已上传的插入到文章
function upimginsert(id){
	FCKeditorAPI.GetInstance("editor").InsertHtml("[attachment]"+id+"[/attachment]");
}

//上传前检查
function checkimg(obj){
	var allowext = ['JPG','GIF','PNG'];
	file = $(obj).val();
	var  index1 =file.lastIndexOf('\\');
    filesname = file.substring(index1 + 1);
    var imgext = filesname.split('.');
    imgext = imgext[1].toUpperCase();
    if(jQuery.inArray(imgext,allowext)=='-1'){
    	alert('图片格式只能为'+allowext);
    	return false;
    }
    
    if(jQuery.inArray(file,selectupfiles)!='-1'){
    	alert('此图片已经选择');
    	return false;
    }
    
    return true;
    
}


function tooltip(e){
	$("#screenshot").remove();
	xOffset = 10;
	yOffset = 30;
	$("body").append("<p id='screenshot'><img src='"+ e.rel +"' alt='url preview' width='120' /></p>");								 
	$("#screenshot")
		.css("top",(event.y - xOffset) + "px")
		.css("left",(event.x + yOffset) + "px")
		.fadeIn("fast");						
}

function tooltipout(){
	$("#screenshot").remove();
}

/***  附件上传结束 ****/


/***** 表情加载 ****/
//加载表情
function loademot(type,obj){
	$('#emot').html('<li style="width:100%;margin-top:50px;"><img src="'+PUBLIC+'/Images/loading.gif" height="20" align="absmiddle"> <font color="red">表情加载中...</font></li>');
	$('#b_c_emot_num').html('<a class="b_c_emot_num2">分页加载中...</a>');
	
    if(obj!='NULL'){
	    $("div[@id='type']").each(function() {     
	        $(this).attr("class",'b_c_emotli2 b black');
	    });	
	    $(obj).attr("class",'b_c_emotli1 b black');
    }
    
	var	ran		=	Math.random();
	$.post(APP+'/Form/loademot',{type:type},function(flid){
	    if(flid){
	        $('#emot').html(flid);
		}
	});
	
	$.post(APP+'/Form/loademot',{ran:ran,type:type,loadpage:'1'},function(flid){
	    if(flid){
	        $('#b_c_emot_num').html(flid);
		}
	});	
}

//加载分页
function loademotpage(type,page,obj){
	$('#emot').html('<li style="width:100%;margin-top:50px;"><img src="'+PUBLIC+'/Images/loading.gif" height="20" align="absmiddle"> <font color="red">表情加载中...</font></li>');
	var	ran		=	Math.random();
	$.post(APP+'/Form/loademot',{page:page,type:type},function(flid){
	    if(flid){
	        $('#emot').html(flid);
	        if(obj!=''){
			    $("a[@id='emotpage']").each(function() {     
			        $(this).attr("class",'b_c_emot_num2');
			    });	
			    $(obj).attr("class",'b_c_emot_num1');
	        }
		}
	});
}

/**** 表情完毕 ****/

function groupmessage(gid){
	var title = $.trim($('#js_m_title').val());
	var content = $.trim($('#js_m_content').val());
	if(title==''){
		$('#js_m_info').html('标题不能为空..');
		return false;
	}
	if(content==''){
		$('#js_m_info').html('内容不能为空..');
		return false;
	}
	
	var	ran		=	Math.random();
	$.post(APP+'/Public/groupmessageok',{title:title,content:content,gid:gid,ran:ran},function(flid){
	    if(flid){
			$("#js_m_info").html('发送成功..');
			setTimeout(function(){$.facebox.close();},250);
		}
	});
	
}

function edit_groupcomment(id){
	var content = $.trim($('#commentinfo').val());
	if(content==''){
		$('#js_m_info').html('内容不能为空..');
		return false;
	}
	
	var	ran		=	Math.random();
	$.post(APP+'/Public/editok_groupcomment',{content:content,id:id,ran:ran},function(flid){
	    if(flid){
			$("#js_m_info").html('发送成功..');
			window.location.reload();
		}
	});
	
}

function searchpagepost(loginname,page){
	var	ran		=	Math.random();
	$.post(APP+'/Public/searchuserpost/',{loginname:loginname,page:page,ran:ran},function(flid){
	    if(flid){
	    	$('#page1').hide();
	    	$('#page').show(flid);
			$('#page').html(flid);
		}
	});	
}