var bb_auth_key;

//==========================================
// Link to a post
//==========================================

function link_to_post(pid)
{
	temp = prompt( ipb_lang_tt_prompt, "http://originxt.com/posts/" + pid );
	return false;
}

//==========================================
// Delete post
//==========================================

function delete_post(pid)
{
	if (confirm( ipb_lang_js_del_1 ))
	{
		window.location.href=ipb_var_base_url+"mod/04/f-"+ipb_input_f+"/t-"+ipb_input_t+"/pid-"+pid+"/auth_key-"+bb_auth_key;
	}
	else
	{
		alert ( ipb_lang_js_del_2 );
	}
}

function profileDropdown(mid, pid, linkObj)
{
	menuObj = my_getbyid("DropDownMenu");
	if(mid > 0)
	{
		menuObj.innerHTML = "<a href='"+ipb_var_base_url+"members/"+mid+"'><div class='dropdown_item'>View public profile</div></a>";
		menuObj.innerHTML+= "<a href=\"javascript:void(PopUp('/profile/showcard/mid-"+mid+"','AddressCard','600','300','0','1','1','1'))\"><div class='dropdown_item'>Show contact card</div></a>";
		menuObj.innerHTML+= "<a href=\"javascript:getData('rpgstats/horizontal-1/mid-"+mid+"','poststats_"+pid+"',0,1);ShowHide('poststats_"+pid+"')\"><div class='dropdown_item'>Display rpg stats</div></a>";
		menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"members/"+mid+"/pm'><div class='dropdown_item'>Send a message</div></a>";
		menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"mail/mid-"+mid+"'><div class='dropdown_item'>Send an email</div></a>";
		menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"search/getalluser/mid-"+mid+"'><div class='dropdown_item'>Find member's posts</div></a>";
	}
	
	disp_menu(linkObj, 'DropDownMenu');
}

function optionsDropdown(linkObj)
{
	menuObj = my_getbyid("DropDownMenu");

	menuObj.innerHTML = "<div><b>View Modes</b></div>";
	menuObj.innerHTML+= "<a href=\"javascript:void(refreshSend(my_setcookie('topicmode','threaded',1)))\"><div class='dropdown_item'>Threaded</div></a>";
	menuObj.innerHTML+= "<a href=\"javascript:void(refreshSend(my_setcookie('topicmode','linear',1)))\"><div class='dropdown_item'>Linear</div></a>";
	menuObj.innerHTML+= "<a href=\"javascript:void(refreshSend(my_setcookie('topicmode','linearplus',1)))\"><div class='dropdown_item'>Linear Plus</div></a>";
	menuObj.innerHTML+= "<div><b>Thread Options</b></div>";
	menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"node/"+ipb_input_t+"/addpoll'><div class='dropdown_item'>Add a poll to this topic</div></a>";
	menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"usercp/start_subs/method-topic/tid-"+ipb_input_t+"'><div class='dropdown_item'>Track this topic</div></a>";
	menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"track/f-"+ipb_input_f+"/type-forum'><div class='dropdown_item'>Track this forum</div></a>";
	menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"forward/f-"+ipb_input_f+"/t-"+ipb_input_t+"'><div class='dropdown_item'>Email / share this topic</div></a>";
	menuObj.innerHTML+= "<a href='/lofi/t"+ipb_input_t+".html'><div class='dropdown_item'>Print this topic</div></a>";
	menuObj.innerHTML+= "<a href='"+ipb_var_base_url+"print/client-choose/f-"+ipb_input_f+"/t-"+ipb_input_t+"'><div class='dropdown_item'>Download this topic</div></a>";
	menuObj.innerHTML+= "<a href='http://digg.com/submit?phase=2&url=http://originxt.com/node/"+ipb_input_t+"'><div class='dropdown_item'>Digg this topic</div></a>";

	disp_menu(linkObj, 'DropDownMenu', 160);
}

function populateDropdown(pid, edit_perm, delete_perm, ip_perm, linkObj)
{
	menuObj = my_getbyid("DropDownMenu");
	menuObj.innerHTML = "<a href='"+ipb_var_base_url+"report/t-"+ipb_input_t+"/st-"+ipb_var_st+"/pid-"+pid+"'><div class='dropdown_item'>Report Post</div></a>";
	menuObj.innerHTML+= "<a href='javascript:void(link_to_post("+pid+"))'><div class='dropdown_item'>Link to Post</div></a>";
	
	if(edit_perm != '0')
	{
		menuObj.innerHTML += "<a href='javascript:void(quickEdit("+pid+"))'><div class='dropdown_item'>Quick Edit</div></a>";
		menuObj.innerHTML += "<a href='"+ipb_var_base_url+"posts/"+pid+"/edit'><div class='dropdown_item'>Normal Edit</div></a>";
	}
	
	if(delete_perm != '0')
	{
		bb_auth_key = delete_perm;
		menuObj.innerHTML += "<a href='javascript:void(delete_post("+pid+"))'><div class='dropdown_item'>Delete Post</div></a>";
	}
	
	if(ip_perm != '0')
	{
		menuObj.innerHTML += "<a href='"+ipb_var_base_url+"usercp/iptool/ip-"+ip_perm+"'><div class='dropdown_item'>Inspect&nbsp;"+ip_perm+"</div></a>";
	}
	
	disp_menu(linkObj, 'DropDownMenu');
}

function quickEdit(pid)
{
	if (getData("/getrawpost-"+pid,document.getElementById("postarea"),true))
	{
		// do some yay!ing
	}
	
	my_hide_div(my_getbyid("DropDownMenu"));

	document.REPLIER.CODE.value = '09';
	document.REPLIER.p.value = pid;
	document.REPLIER.submit.value = "Save Post";
	document.REPLIER.Post.focus();
}

function multiquote_quick()
{
	saved = new Array();
	clean = new Array();

	//-----------------------------------
	// Get any saved info
	//-----------------------------------

	if ( tmp = my_getcookie('mqtids') )
	{
		saved = tmp.split(",");

		for( i = 0 ; i < saved.length; i++ )
			changeImgSrc("mad_"+saved[i], addquotebutton);

		if (getData("getmulti",document.getElementById("postarea"),true))
		{
		// do some yay!ing
		}
	}

	document.REPLIER.Post.focus();
}

//==========================================
// Multi quote
//==========================================

function multiquote_add(id)
{
	saved = new Array();
	clean = new Array();
	add   = 1;

	//-----------------------------------
	// Get any saved info
	//-----------------------------------

	if ( tmp = my_getcookie('mqtids') )
	{
		saved = tmp.split(",");
	}

	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------

	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != "" )
		{
			if ( saved[i] == id )
			{
				 add = 0;
			}
			else
			{
				clean[clean.length] = saved[i];
			}
		}
	}

	//-----------------------------------
	// Add?
	//-----------------------------------

	if ( add )
	{
		clean[ clean.length ] = id;
		changeImgSrc("mad_"+id, removequotebutton);
	}
	else
	{
	 	changeImgSrc("mad_"+id, addquotebutton);
	}

	my_setcookie( 'mqtids', clean.join(','), 0 );

	return false;
}

//==========================================
// Check delete
//==========================================

function checkdelete()
{
	if ( ! document.modform.selectedpids.value )
	{
		return false;
	}

	isDelete = document.modform.tact.options[document.modform.tact.selectedIndex].value;

	if (isDelete == 'delete')
	{
		formCheck = confirm( lang_suredelete );

		if (formCheck == true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}


//==========================================
// Toggle selection
//==========================================

function topic_toggle_pid( pid )
{
	//-----------------------------------
	// Got a number?
	//-----------------------------------

	if ( isNaN( pid ) )
	{
		return false;
	}

	saved = new Array();
	clean = new Array();
	add   = 1;

	//-----------------------------------
	// Get form info
	//-----------------------------------

	tmp = document.modform.selectedpids.value;

	saved = tmp.split(",");

	//-----------------------------------
	// Remove bit if exists
	//-----------------------------------

	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != "" )
		{
			if ( saved[i] == pid )
			{
				add = 0;
			}
			else
			{
				clean[clean.length] = saved[i];
			}
		}
	}

	//-----------------------------------
	// Add?
	//-----------------------------------

	if ( add )
	{
		clean[ clean.length ] = pid;
		changeImgSrc("img"+pid, selectedbutton);
	}
	else
	{
		changeImgSrc("img"+pid, unselectedbutton);
	}

	newvalue = clean.join(',');

	my_setcookie( 'modpids', newvalue, 0 );

	document.modform.selectedpids.value = newvalue;

	newcount = stacksize(clean);

	document.modform.gobutton.value = lang_gobutton + ' (' + newcount + ')';

	return false;
}
