/**
 * OAQQ script by flywolf (ircman@163.com, qq:16414766)
 */
 
function SaveImage(img){
	 img = img.attr('src');
	 window.win = open(img);
	 setTimeout(function() {win.document.execCommand('SaveAs')}, 200);
}

function vote(id) {
	$.post('/ajax/handler.php', {'action':'vote', 'id':id, 'point':$('#point').val()}, function(res){
		alert('评分成功!');
		$('#spnPoint').text(res);
	});
}

function upbq(id) {
	$.post('/ajax/handler.php', {'action':'upbq', 'id':id}, function(res){
		if (res == '-1') {
			alert('您已经顶过了! 请过一段时间再来顶顶吧!');
		} else {
			alert('操作成功!');
			$('#spnUpCnt').text(res);
		}
	});	
}

function addbaidu()
{
	d=document;
	t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');
	void(vkey=window.open('http://cang.baidu.com/do/add?it='+encodeURIComponent(d.title)+'&iu='+encodeURIComponent(d.location.href)+'&fr=ien#nw=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes'));
	vkey.focus();
}
function addqq()
{
	d=document;
	t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');
	void(vkey=window.open('http://shuqian.qq.com/post?title='+encodeURIComponent(d.title)+'&uri='+encodeURIComponent(d.location.href)+'&jumpback=2&noui=1','favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes'));
	vkey.focus();
}
function addfav() {
	var name='QQ表情,QQ头像,QQ表情下载,在线制作';
	var url='http://www.fm80.cn';
	if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
	{
		//  firefox
		window.sidebar.addPanel(name,url, '' );

	}
	else if ( document.all && "object" == typeof( window.external ) )
	{

		//  ie                
		window.external.addFavorite(url, name);
	}
}

function downbq(id) {
	$.post('/ajax/handler.php', {'action':'downbq', 'id':id}, function(res){
		if (res == '-1') {
			alert('您已经踩过了!请过一段时间再来顶踩吧!');
		} else {
			alert('操作成功!');
			$('#spnDownCnt').text(res);
		}
	});	
}

function showPop() {
	$("img.imgPop")
		.mouseover(function(){
			$('#popup')
				.css({
					'left':$(this).offset().left+$('#popup').width()-20,
					'top':$(this).offset().top
				})
				.show();
				$('#curImgPop').val($(this)[0].id);
		})
		.mouseout(function(){
			$('#popup').hide();
		});
}

function CopyImg(img) {
	if (img == undefined) {
		alert('请先选择图片!');
		return;
	}
	var ctrl = document.body.createControlRange();
	 img.contentEditable = true;
	 ctrl.addElement(img);
	 ctrl.execCommand('Copy');
	 img.contentEditable = false;
	 alert('复制完成，到QQ对话框里按Ctrl-V就可以啦！\n\n若不能粘贴请重复尝试或用鼠标右键选复制');	
}

function CopyPopImg() {
	img = $('#'+$('#curImgPop').val())[0];
	if (img == undefined) {
		alert('请先选择图片!');
		return;
	}
	var ctrl = document.body.createControlRange();
	 img.contentEditable = true;
	 ctrl.addElement(img);
	 ctrl.execCommand('Copy');
	 img.contentEditable = false;
	 alert('复制完成，到QQ对话框里按Ctrl-V就可以啦！\n\n若不能粘贴请重复尝试或用鼠标右键选复制');	
}

function editbq() {
	var imgid = $('#curImgPop').val(); // popimg13
	imgid = imgid.substring(6);
	if (isNaN(imgid))
		return;
	window.open ('/biaoqing/edit'+imgid+'.html', "newwindow", "");
}

function jsgobq() {
	var imgid = $('#curImgPop').val(); // popimg13
	imgid = imgid.substring(6);
	if (isNaN(imgid))
		return;
	window.open ('/biaoqing/'+imgid+'.html', "newwindow", "");	
}

function fontPreview(v)
{
	document.getElementById('fontImg').src = "/images/" + v + ".jpg";
}

function fontPreview2(v)
{
	document.getElementById('fontImg2').src = "/images/" + v + ".jpg";
}

function showEffect(v)
{
	v == "0" ? $('#spnEffect').hide() : $('#spnEffect').show();
}

function showJump(v)
{
	v == "0" ? $('#spnJump').hide() : $('#spnJump').show();
}

function showPicBorder(v)
{
	v == "0" ? $('#spnPicBorder').hide() : $('#spnPicBorder').show();
}

function showPicRoundCorners(v)
{
	v == "0" ? $('#spnPicRoundCorners').hide() : $('#spnPicRoundCorners').show();
}

function showTextBgColor(v)
{
	v == "0" ? $('#spnTextBgColor').hide() : $('#spnTextBgColor').show();
}

function setCpColor(e) {
	$(this).colorPicker({ setValue:'input[@name='+e+']' })
}

function doGenerate()
{
	$('#backImage')[0].src = "../images/wait.gif";
//	$('#btnGenerate')[0].disabled = true;
//	$('#btnGenerate').val('正在生成图片');
	$('#demoTab').hide();
	params = {'action':'generateImage', 
		'img':$('#imgAddr').val(),
		'fontFamily':$('#sltFontFamily').val(),
		'fontSize':$('#sltFontsize').val(),
		'fontColor':$('#fontColor').val(),
		'effectColor':$('#effectColor').val(),
		'isTextBgColor':$('select[@name=sltTextBgColor]').val(),
		'textBgColor':$('input[@name=textBgColor]').val(),		
		'effect':$('#effect').val(),
		'fontBorderColor':$('#fontBorderColor').val(),
		'effectBorderColor':$('#effectBorderColor').val(),
		'jump':$('select[@name=jump]').val(),
		'jumpWidth':$('select[@name=jumpWidth]').val(),
		'isPicCorner':$('select[@name=sltPicCorner]').val(),
		'cornerRadian':$('select[@name=cornerradian]').val(),
		'isPicBorder':$('select[@name=sltPicBdr]').val(),
		'borderWidth':$('select[@name=bdrWidth]').val(),
		'picBorderColor':$('input[@name=picBorderColor]').val(),
		'isgif':$('input[@name=isGIF]').val(),
		'xpos':$('#xpos').val(),
		'ypos':$('#ypos').val(),
		'text':$('#txtContent').val(),
		'faceid':$('#bqid').val(),
		'categoryid':$('input[@name=categoryid]').val()
		};
	$.post('/ajax/generate_image.php', params, function(res) {
			eval('var o='+res);			
			$('#backImage')[0].src = o.genimg;
			$('#btnCopy2QQ')[0].disabled = false;
			$('#btnGenerate').val('生成图片');
		});
}

function search_box() {
	t = $('select[@name=con]').val();
	w = $.trim($('input[@name=kword]').val());
	if (w.length <= 0) {
		alert('关键字不能为空!');
		return false;
	}
//	alert(encodeURI(w));
	window.open ('/search.php?t='+t+'&w='+encodeURI(w), "newwindow", "");
}

