// JavaScript Document

var np_cache        = new Array();
var p_cache        = new Array();
var post_id;
var post_edit_id;

function MenuTopicActions( top_ID, event, post_id ){

var menu=new Array();

menu[0]='<a href="#">ID: ' + top_ID + '</a>';
menu[1]='<a onclick="ForCards(\'' + top_ID + '\', \'' + event + '\'); return false;" href="#">' + menu_close + '</a>';
menu[2]='<a onclick="DeleteTopic(\'' + top_ID + '\'); return false;" href="' + dle_root + 'index.php?do=forum&subaction=deletetopic_Q&id=' + top_ID + '">' + menu_delete + '</a>';
menu[3]='<a href="' + dle_root + 'index.php?do=forum&subaction=editpost&id=' + post_id + '">' + menu_edit + '</a>';
menu[4]='<a href="' + dle_root + 'index.php?do=forum&subaction=movetopic&id=' + top_ID + '">' + menu_move + '</a>';
menu[5]='<a href="' + dle_root + 'index.php?do=forum&subaction=split&id=' + top_ID + '">' + menu_split + '</a>';

return menu;
};

function MenuPostEBuild( m_id ){

var menu=new Array();

menu[0]='<a onclick="ajax_post_edit(\'' + m_id + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + 'index.php?do=forum&subaction=editpost&id=' + m_id + '">' + menu_full + '</a>';

return menu;
};

function ForWatch( id, event )
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "id=" + id;
	ajax.setVar("action", event);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/forum/ajax/watch.php";
	ajax.method = 'GET';
	ajax.element = 'w-id-'+id;
	ajax.sendAJAX(varsString);

	return false;
};

function ForFavorites( fav_id, event )
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "fav_id=" + fav_id;
	ajax.setVar("action", event);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/forum/ajax/favorites.php";
	ajax.method = 'GET';
	ajax.element = 'fav-id-'+fav_id;
	ajax.sendAJAX(varsString);

	return false;
};

function ForCards( id, event, secondid )
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "id=" + id;
	ajax.setVar("secondid", secondid);
	ajax.setVar("action", event);
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/forum/ajax/cards.php";
	ajax.method = 'GET';
	ajax.element = 'cardt-'+id+event;
	ajax.sendAJAX(varsString);

	return false;
};

function getICQ( icq, i ){
		var ajax = new dle_ajax();	
		var varsString = "icq=" + icq;
		ajax.setVar("skin", dle_skin);
		ajax.requestFile = dle_root + "engine/forum/ajax/icq.php";
		ajax.method = 'GET';
		ajax.element = 'icq-layer-'+icq+i;
		ajax.sendAJAX(varsString);
};

function confirmDeleteTop(url){

    var agree=confirm( menu_delt );

    if (agree)
    document.location=url;
};

function dle_for_ins(name) 
{
var input=document.getElementById('entryform').short_story;
var finalhtml = "";

	if (dle_wysiwyg == "no") {
		if (dle_txt!= "") {
			input.value += dle_txt;
		}
		else { 
			input.value += "[b]"+name+"[/b],"+"\n";
		}
	} else {
		if (dle_txt!= "") {
			finalhtml = dle_txt;
		}
		else { 
			finalhtml = "<b>"+name+"</b>,"+"<br />";
		}	
	oUtil.obj.insertHTML(finalhtml);
	}

};

function DeletePost( id ) {
if(confirm(menu_delp))
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "id=" + id;
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/forum/ajax/deletepost.php";
	ajax.method = 'GET';
	ajax.element = 'fullpost-' + id;
	ajax.sendAJAX(varsString);
} 

return false;

};

function DeleteTopic( id ) {
if(confirm(menu_delt))
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "id=" + id;
	ajax.setVar("skin", dle_skin);
	ajax.requestFile = dle_root + "engine/forum/ajax/deletetopic.php";
	ajax.method = 'GET';
	ajax.element = 'topic-' + id;
	ajax.sendAJAX(varsString);
} 

return false;

};

function doAddPost(){

	var form = document.getElementById('entryform');
    var dle_post_ajax = new dle_ajax();

	if (dle_wysiwyg == "yes") {
	document.getElementById('short_story').value = oEdit1.getXHTMLBody();
	form.submit();
	}
	else {
	if ( form.send ){

	closeall();

	if (form.short_story.value == '' || form.name.value == '')
	{
		alert ( dle_req_field );
		return false;
	}

	dle_post_ajax.onShow ('');
	var varsString = "id=" + form.id.value;
	dle_post_ajax.setVar("short_story", dle_post_ajax.encodeVAR(form.short_story.value));
	dle_post_ajax.setVar("skin", dle_skin);
	dle_post_ajax.setVar("textvers", textversion);
	dle_post_ajax.setVar("name", dle_post_ajax.encodeVAR(form.name.value));
	dle_post_ajax.setVar("mail", dle_post_ajax.encodeVAR(form.mail.value));
	dle_post_ajax.setVar("wsbb", '0');

	if ( form.allow_sig ){
	var checksig = document.getElementById('allow_sig');
	if(checksig.checked) { dle_post_ajax.setVar("allow_sig", '1'); }
	}
	
	if ( form.lock ){
	var checklock = document.getElementById('lock');
	if(checklock.checked) { dle_post_ajax.setVar("lock", '1'); }
	}
	
	if ( form.status ) { dle_post_ajax.setVar("status", form.status.value); }
	if ( form.sec_code ) { dle_post_ajax.setVar("sec_code", form.sec_code.value); }
	
	dle_post_ajax.requestFile = dle_root + "engine/forum/ajax/newmessage.php";
	dle_post_ajax.method = 'POST';
	dle_post_ajax.execute = true;
	dle_post_ajax.element = 'dle-ajax-forumpost';
	dle_post_ajax.sendAJAX(varsString);

	} else { form.submit(); }
	
	}
	
};

function whenCompletedPostEdit(){

	var post_main_obj = document.getElementById( 'post-id-' + post_id );
	var post_box_top  = _get_obj_toppos( post_main_obj );

			if ( post_box_top )
			{
				scroll( 0, post_box_top - 70 );
			}

};

function ajax_post_edit( ñ_id )
{
	if ( ! p_cache[ ñ_id ] || p_cache[ ñ_id ] == '' )
	{
		p_cache[ ñ_id ] = document.getElementById( 'post-id-'+ñ_id ).innerHTML;
	}

	var ajax = new dle_ajax();
	post_id = ñ_id;
	ajax.onShow ('');
	var varsString = "";
	ajax.setVar("id", ñ_id);
	ajax.setVar("action", "edit");
	ajax.requestFile = dle_root + "engine/forum/ajax/editpost.php";
	ajax.method = 'GET';
	ajax.element = 'post-id-'+ñ_id;
	ajax.onCompletion = whenCompletedPostEdit;
	ajax.sendAJAX(varsString);
	return false;
};

function ajax_cancel_post_edit( c_id )
{
	if ( np_cache[ c_id ] != "" )
	{
		document.getElementById( 'post-id-'+c_id ).innerHTML = p_cache[ c_id ];
	}
	
	return false;
};

function whenCompletedSavePost(){
p_cache[ post_edit_id ] = '';
}

function ajax_save_post_edit( c_id )
{
	var ajax = new dle_ajax();
	post_edit_id = c_id;
	ajax.onShow ('');
	var post_txt = ajax.encodeVAR( document.getElementById('edit-post-'+c_id).value );
	var post_title = ajax.encodeVAR( document.getElementById('edit-title-'+c_id).value );
	var post_subject = ajax.encodeVAR( document.getElementById('edit-subject-'+c_id).value );
	var post_alt = ajax.encodeVAR( document.getElementById('edit-alt-'+c_id).value );
	var varsString = "post_txt=" + post_txt;
	ajax.setVar("id", c_id);
	ajax.setVar("title", post_title);
	ajax.setVar("subject", post_subject);
	ajax.setVar("alt_name", post_alt);
	ajax.setVar("action", "save");
	ajax.requestFile = dle_root + "engine/forum/ajax/editpost.php";
	ajax.method = 'POST';
	ajax.element = 'post-id-'+c_id;
	ajax.onCompletion = whenCompletedSavePost;
	ajax.sendAJAX(varsString);

	return false;
};

function doInviteFriend( id )
{
	var form = document.getElementById('invite');
    var dle_post_ajax = new dle_ajax();
	
	if (form.name.value == '')
	{
		alert ( dle_req_field );
		return false;
	}
	
	dle_post_ajax.onShow ('');
	var varsString = "id=" + id;
	dle_post_ajax.setVar("skin", dle_skin);
	dle_post_ajax.setVar("name", dle_post_ajax.encodeVAR(form.name.value));
	dle_post_ajax.setVar("mail", dle_post_ajax.encodeVAR(form.mail.value));
	
	dle_post_ajax.requestFile = dle_root + "engine/forum/ajax/invite.php";
	dle_post_ajax.method = 'POST';
	dle_post_ajax.execute = true;
	dle_post_ajax.element = 'invite-div';
	dle_post_ajax.sendAJAX(varsString);

	return false;
};

function totranslit()
{
var obj_ta = fombj.short_story;

if ( (ua_vers >= 4) && is_ie && is_win)
{
if (obj_ta.isTextEdit)
{
obj_ta.focus();
var sel = document.selection;
var rng = sel.createRange();
rng.colapse;
if((sel.type == "Text" || sel.type == "None") && rng != null)
{
rng.text = dotranslate(rng.text);
}
}
else
{
obj_ta.value = dotranslate(obj_ta.value);
}
}
else
{
obj_ta.value = dotranslate(obj_ta.value);
}

obj_ta.focus();

return;
};


function ForumUserMenu( url, m_id, group ){

var menu=new Array();

	menu[0]='<a ' + url +' >' + menu_profile + '</a>';
	menu[1]='<a href="' + dle_root + 'index.php?do=pm&doaction=newpm&user=' + m_id + '">' + menu_send + '</a>';
	menu[2]='<a href="' + dle_root + 'index.php?do=lastcomments&userid=' + m_id + '">' + menu_fcomments + '</a>';

	if (group == '1') {
		menu[3]='<a onclick="window.open(\'' + dle_root + 'admin.php?mod=editusers&action=edituser&id=' + m_id + '\', \'User\',\'toolbar=0,location=0,status=0, left=0, top=0, menubar=0,scrollbars=yes,resizable=0,width=540,height=500\'); return false;" href="#">' + menu_uedit + '</a>';
	}

return menu;
};