// JavaScript Document



function __save_ok_callback()
{
	window.location.reload();
}
function __cancel_save_callback()
{
	removeIframeDiv() ;
}
function show_edit_item_frame(item_id,s_title)
{
	if (s_title != ""){
		var title = s_title;	
	}else{
		var title = '修改属性';
	}
	var url = 'item_edit_items.php?op=edit&tpl_name=iframe&item_ids[]=' + item_id;
	var width = 590;
	var height = 230;
		createIframeDiv(url ,title , width, height) 
}

function show_item_ext_details_frame(item_id)
{
	var title = '作品引用转载信息';
	var url = 'item_display_ext_details.php?tpl_name=iframe&item_id=' + item_id;
	var width = 590;
	var height = 280;
	createIframeDiv(url ,title , width, height) 
}

function show_add_item_frame(item_type,tag_name,set_hash)
{
	var title = '添加';
	var url = 'item_edit_items.php?op=add&item_type=' + item_type;
	if (typeof(tag_name)!='undefined')
	{
		if (tag_name!='')
		{
			url += '&tag_name=' + tag_name;
		}
	}

	if (typeof(set_hash)!='undefined')
	{
		if (set_hash!='')
		{
			url += '&set_hash=' + set_hash;
		}
	}

	var width = 720;
	var height = 560;
	//createIframeDiv(url ,title , width, height) 
	window.location=url;
}



function __hide_show_item_ext_details_callback()
{
	removeIframeDiv() ;
}


function pushToList(id)
{
	var form_obj = $('item_act_form');
	form_obj.title.value = $('item_link_'+id).innerHTML;
	form_obj.link_url.value = $('item_link_'+id).href;
	try
	{
		form_obj.img_url.value = $('item_thumbnail_'+id).src;
	}
	catch(e){};
	form_obj.description.value = '';
	if(form_obj.title.value && form_obj.link_url.value)
	{
		showMsgBox('保存','正在提交操作。。。',{},'_empty');
		$('item_push_'+id).disabled=true;
		$('item_push_'+id).href='javascript:;';
		form_obj.action = 'http://my.poco.cn/v2/mypoco_push_to_list_act.php';
		form_obj.target = 'item_act_frame_'+id;
		form_obj.submit();
	}
}

function set_user_face(id,item_type)
{
	var form_obj = $('item_act_form');
	form_obj.item_id.value = id;
	form_obj.item_type.value = item_type;
	
	if(id>0)
	{
		showMsgBox('保存','正在提交操作。。。',{},'_empty');
		$('item_set_face_'+id).disabled=true;
		$('item_set_face_'+id).href='javascript:;';
		form_obj.action='item_act.php?act=face';
		form_obj.target = 'item_act_frame_'+id;
		form_obj.submit();
	}	
}

function set_user_set_thumbnail(item_id, set_name)
{
	var iframe_obj = $('item_act_frame_'+item_id);
	$('item_set_user_set_thumbnail_'+item_id).disabled=true;
	iframe_obj.src = 'http://my.poco.cn/items/item_edit_set_act.php?act=set_thumbnail_img&set_name='+set_name+'&item_id='+item_id;
}


function if_some_item_selected()
{
	var _selected_count=false;
	var chkbox_objs = document.getElementsByTagName('input');
	for(var i=0;i<chkbox_objs.length;i++)
	{
		if (chkbox_objs[i].getAttribute('type')=='checkbox')
		{
			if (chkbox_objs[i].disabled!=true &&
				chkbox_objs[i].id=='item_id_checkbox' &&
				chkbox_objs[i].checked==true)
			{
				_selected_count=_selected_count*1 + 1;
			}
		}
	}
	return _selected_count;
}

function new_publish()
{
	if (!if_some_item_selected())
	{
		alert('请先选择');
		return false;
	}
	
	
	var form_obj = $('post_form');
	form_obj.action = 'http://entry4.poco.cn/mypoco/blog/blog_add.php';
	form_obj.target = '_self';
	form_obj.submit()
}	


function blog_this_item(item_ids_arr)
{
	if (typeof(item_ids_arr)=='object')
    {
		var item_ids_param='';

		for(var i=0;i<item_ids_arr.length;i++)
		{	
			item_ids_param+='&item_ids[]='+item_ids_arr[i];
		}
		var url='http://entry4.poco.cn/mypoco/blog/blog_add.php?'+item_ids_param;
		window.open(url);
	}
	else
	{
		alert('参数错误，不是数组');	
	}
}	



function edit_batch()
{
	if (!if_some_item_selected())
	{
		alert('请先选择');
		return false;
	}
	
	var form_obj = $('post_form');
	form_obj.action = 'item_edit_items.php?op=edit&item_type=album&redirect_url=' +  encodeURIComponent(window.location.href);
	form_obj.target = '';
	
	form_obj.submit();
}	


function new_pzm()
{
	if (if_some_item_selected()*1<3)
	{
		alert('请至少选择三张图片');
		return false;
	}
	
	
	if (confirm('要对所选的图片生成杂志吗？'))
	{
		var form_obj = $('post_form');
		form_obj.action = 'add_pzm.act.php';
		form_obj.target = 'post_frame';
		
		
		showMsgBox('一键生成杂志','正在生成杂志。。。',{},'_empty');
		
		form_obj.submit();
	}
}	


function del_items()
{
	if (!if_some_item_selected())
	{
		alert('请先选择');
		return false;
	}
	
	if (confirm('确定删除所选的素材吗？'))
	{
		var form_obj = $('post_form');
		form_obj.action= 'item_list_act.php?op=del';
		form_obj.target= 'post_frame';
		
	
		showMsgBox('删除','正在删除。。。',{},'_empty')
		form_obj.submit();
	}
}


function put_to_music_playlist(item_id,b_put)
{
	var the_frame = $('item_act_frame_' + item_id);
	
	var date_obj=new Date;

	if (b_put==true)
	{
		the_frame.src= 'item_list_act.php?op=put_to_music_playlist&item_id='+item_id + '&t=' + date_obj.getTime();
	}
	else
	{
		the_frame.src= 'item_list_act.php?op=remove_from_music_playlist&item_id='+item_id + '&t=' + date_obj.getTime();
	}
}

function copy_item(item_id)
{
	var the_frame = $('item_act_frame_' + item_id);
	
	var date_obj=new Date;


	the_frame.src= 'http://my.poco.cn/items/item_list_act.php?op=copy_item&item_id='+item_id + '&t=' + date_obj.getTime();

}

function commend_item(item_id)
{
	var the_frame = $('item_act_frame_' + item_id);
	var date_obj=new Date;
	the_frame.src= 'http://my.poco.cn/items/item_list_act.php?op=commend_item&item_id='+item_id + '&t=' + date_obj.getTime();

}


function check_all(checkobj)
{
	var chkbox_objs = document.getElementsByTagName('input');
	for(var i=0;i<chkbox_objs.length;i++)
	{
		if (chkbox_objs[i].getAttribute('type')=='checkbox')
		{
			if (chkbox_objs[i].disabled!=true && chkbox_objs[i]!=checkobj)
			{
				chkbox_objs[i].checked=checkobj.checked;
			}
		}
	}
}

function move_set_batch()
{
	if (!if_some_item_selected())
	{
		alert('请先选择');
		return false;
	}

	var item_ids_obj = document.getElementsByName('item_ids[]');

	var query = '';
	for(var i=0; i<item_ids_obj.length; i++)
	{
		if(item_ids_obj[i].checked==true) query+='item_ids[]='+item_ids_obj[i].value+'&';
	}
	
	var url = 'item_move_items.php?'+query;
	createIframeDiv(url ,'移动相册', 400, 145); 
}	