// JavaScript Document
var np_cache        = new Array();
var p_cache        = new Array();
var post_id;
var post_edit_id;


function AddImages(id, id_name, id_type, id_style, id_class) {
	var tbl = document.getElementById(id);
	var lastRow = tbl.rows.length;
	var iteration = lastRow+1;
	var row = tbl.insertRow(lastRow);

	var cellRight = row.insertCell(0);
	var el = document.createElement('input');
	el.setAttribute('type', id_type);
	el.setAttribute('name', id_name + '_' + iteration);
	el.style.setAttribute('cssText', id_style);
	el.setAttribute('className', id_class);
	cellRight.appendChild(el);
};

function RemoveImages(id) {
	var tbl = document.getElementById(id);
	var lastRow = tbl.rows.length;
	if (lastRow > 1){
	  tbl.deleteRow(lastRow - 1);
	}
};

function show_rules( id ) {

	if ( id != '0' ){
		var ajax = new dle_ajax();
		ajax.onShow ('');
		var varsString = "id=" + id;
		ajax.setVar("skin", dle_skin);
		ajax.requestFile = dle_root + "engine/gallery/ajax/rules.php";
		ajax.method = 'GET';
		ajax.element = 'rules-layer';
		ajax.sendAJAX(varsString);
	} else {
		document.getElementById('rules-layer').innerHTML = menu_chose;
	}

};

function GalRate( rate, id, mode ) {
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "go_rate=" + rate;
	ajax.setVar("id", id);
	ajax.setVar("skin", dle_skin);
	ajax.setVar("mode", mode);
	ajax.requestFile = dle_root + "engine/gallery/ajax/rating.php";
	ajax.method = 'GET';
	ajax.element = 'galratig-layer-' + id;
	ajax.sendAJAX(varsString);
};

function MenuGalCat( ID, adm ){

var menu=new Array();

menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=21&acs=' + acscode + '&id=' + ID + '">' + menu_open + '</a>';
menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=22&acs=' + acscode + '&id=' + ID + '">' + menu_comments + '</a>';
menu[2]='<a href="' + dle_root + 'index.php?do=gallery&act=23&acs=' + acscode + '&id=' + ID + '">' + menu_rating + '</a>';
menu[3]='<a href="' + dle_root + 'index.php?do=gallery&act=19&acs=' + acscode + '&id=' + ID + '">' + menu_short + '</a>';

if (adm == '1'){

	menu[4]='<a href="' + dle_root + dle_admin + '?mod=twsgallery&act=2&id=' + ID + '" target="_blank">' + menu_full + '</a>';
	menu[5]='<a onClick="confirmact(\'' + menu_confirm3 + '\', \'' + dle_root + dle_admin + '?mod=twsgallery&act=9&id=' + ID + '\'); return false;" href="#">' + menu_recount + '</a>';
	menu[6]='<a onClick="confirmact(\'' + menu_confirm2 + '\', \'' + dle_root + dle_admin + '?mod=twsgallery&act=1\'); return false;" href="#">' + menu_delete + '</a>';

}

return menu;
};

function MenuGalFoto( ID ){

var menu=new Array();

menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=17&acs=' + acscode + '&si=' + ID + '">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + dle_admin + '?mod=twsgallery&act=24&selected_news=' + ID + '" target="_blank">' + menu_full + '</a>';
menu[2]='<a onClick="doFotoSet(\'1\', ' + ID + '); return false;" href="#">' + menu_approve + '</a>';
menu[3]='<a onClick="doFotoSet(\'2\', ' + ID + '); return false;" href="#">' + menu_comments + '</a>';
menu[4]='<a onClick="doFotoSet(\'3\', ' + ID + '); return false;" href="#">' + menu_rating + '</a>';
menu[5]='<a href="' + dle_root + 'index.php?do=gallery&act=7&acs=' + acscode + '&si=' + ID + '">' + menu_move + '</a>';
menu[6]='<a onClick="confirmact(\'' + menu_confirm1 + '\', \'' + dle_root + 'index.php?do=gallery&act=13&acs=' + acscode + '&si=' + ID + '\'); return false;" href="' + dle_root + 'index.php?do=gallery&act=8&acs=' + acscode + '&si=' + ID + '">' + menu_delete + '</a>';

return menu;
};

function GalUserMenu( url, name ){

var menu=new Array();

	menu[0]='<a href="' + url +'">' + menu_profile + '</a>';
	menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=4&gal_user=' + name + '">' + menu_allcons + '</a>';
	menu[2]='<a href="' + dle_root + 'index.php?do=gallery&act=15&gal_user=' + name + '">' + menu_allfoto + '</a>';

return menu;
};

function ShortGalFoto( ID, full ){

var menu=new Array();

menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=17&acs=' + acscode + '&si=' + ID + '">' + menu_short + '</a>';

if (full != '0'){
	menu[1]='<a href="' + dle_root + dle_admin + '?mod=twsgallery&act=24&selected_news=' + ID + '" target="_blank">' + menu_full + '</a>';
}

return menu;
};

function MenuGalComment( ID ){

var menu=new Array();

menu[0]='<a onclick="faajax_comm_edit(\'' + ID + '\'); return false;" href="' + dle_root + 'index.php?do=gallery&act=3&acs=' + acscode + '&subaction=comm_edit&com_id=' + ID + '">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=3&acs=' + acscode + '&subaction=comm_edit&com_id=' + ID + '">' + menu_full + '</a>';

return menu;
};

function doAddGaComments(){

	var form = document.getElementById('dle-comments-form');
    var dle_comments_ajax = new dle_ajax();

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

	closeall();

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

	dle_comments_ajax.onShow ('');
	var varsString = "id=" + form.id.value;
	dle_comments_ajax.setVar("comments", dle_comments_ajax.encodeVAR(form.comments.value));
	dle_comments_ajax.setVar("name", dle_comments_ajax.encodeVAR(form.name.value));
	dle_comments_ajax.setVar("mail", dle_comments_ajax.encodeVAR(form.mail.value));
	dle_comments_ajax.setVar("skin", dle_skin);
	dle_comments_ajax.setVar("action", "add");

	if ( form.sec_code ) {

	   dle_comments_ajax.setVar("sec_code", form.sec_code.value);

    }

	dle_comments_ajax.requestFile = dle_root + "engine/gallery/ajax/comments.php";
	dle_comments_ajax.method = 'POST';
	dle_comments_ajax.execute = true;
	dle_comments_ajax.element = 'dle-ajax-comments';
	dle_comments_ajax.sendAJAX(varsString);

	}
};

function DeleteComment( id ) {
if(confirm(dle_del_agree))
{
	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "com_id=" + id;
	ajax.setVar("skin", dle_skin);
	ajax.setVar("action", "delete");
	ajax.setVar("acs", acscode);
	ajax.requestFile = dle_root + "engine/gallery/ajax/comments.php";
	ajax.method = 'GET';
	ajax.element = 'comment-' + id;
	ajax.sendAJAX(varsString);
}

return false;

};


function whenCompletedPostEdit(){

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

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

};

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

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

function uncom_ajax_cancel_comm_edit( c_id )
{
	if ( np_cache[ c_id ] != "" )
	{
		document.getElementById( 'comm-id-'+c_id ).innerHTML = p_cache[ c_id ];
	}

	return false;
};

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

function uncom_ajax_save_comm_edit( c_id )
{
	var ajax = new dle_ajax();
	post_edit_id = c_id;
	ajax.onShow ('');
	var comm_txt = ajax.encodeVAR( document.getElementById('edit-comm-'+c_id).value );
	var varsString = "comm_txt=" + comm_txt;
	ajax.setVar("com_id", c_id);
	ajax.setVar("action", "do_edit");
	ajax.setVar("acs", acscode);
	ajax.requestFile = dle_root + "engine/gallery/ajax/comments.php";
	ajax.method = 'POST';
	ajax.element = 'comm-id-'+c_id;
	ajax.onCompletion = whenCompletedSavePost;
	ajax.sendAJAX(varsString);

	return false;
};

function confirmact(text, url) {
    var agree=confirm(text);
    if (agree)
    document.location=url;
}

function doFotoSet(ev, ID)
{

	var ajax = new dle_ajax();
	ajax.onShow ('');
	var varsString = "si=" + ID;
	ajax.setVar("skin", dle_skin);
	ajax.setVar("act", ev);
	ajax.setVar("acs", acscode);
	ajax.requestFile = dle_root + "engine/gallery/ajax/foto.php";
	ajax.method = 'GET';
	ajax.element = 'fotoedit-' + ID;
	ajax.sendAJAX(varsString);
	return false;

};
