// JavaScript Document

var twsg_p_cache        = new Array();

var twsg_np_cache = new Array();

function MenuGalCat( ID, adm ){
var menu=new Array();
if (adm && adm != '0'){
	menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=21&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_open + '</a>';
	menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=22&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_comments + '</a>';
	menu[2]='<a href="' + dle_root + 'index.php?do=gallery&act=23&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_rating + '</a>';
	menu[3]='<a href="' + dle_root + 'index.php?do=gallery&act=19&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_short + '</a>';
	if (adm == '2'){
		menu[4]='<a href="' + dle_root + 'index.php?do=gallery&act=28&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_disupload + '</a>';
		menu[5]='<a href="' + dle_root + dle_admin + '?mod=twsgallery&act=2&id=' + ID + '" target="_blank">' + menu_full + '</a>';
		menu[6]='<a onClick="confirmact(\'' + menu_confirm3 + '\', \'' + dle_root + dle_admin + '?mod=twsgallery&act=9&id=' + ID + '\'); return false;" href="#">' + menu_recount + '</a>';
		menu[7]='<a onClick="confirmact(\'' + menu_confirm2 + '\', \'' + dle_root + dle_admin + '?mod=twsgallery&act=1\'); return false;" href="#">' + menu_delete + '</a>';
	}
} else {
	menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=24&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '">' + menu_short + '</a>';
	menu[1]='<a onClick="confirmact(\'' + menu_confirm2 + '\', \'' + dle_root + 'index.php?do=gallery&act=27&dle_allow_hash=' + dle_login_hash + '&id=' + ID + '\'); 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&dle_allow_hash=' + dle_login_hash + '&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&dle_allow_hash=' + dle_login_hash + '&si=' + ID + '">' + menu_move + '</a>';
menu[6]='<a onClick="confirmact(\'' + menu_confirm1 + '\', \'' + dle_root + 'index.php?do=gallery&act=13&dle_allow_hash=' + dle_login_hash + '&si=' + ID + '\'); return false;" href="#">' + menu_delete + '</a>';

return menu;
};

function GalUserMenu( url, name, alt ){

var menu=new Array();

	menu[0]='<a onClick="ShowProfile(\'' + name + '\', \'' + url + '\', ' + gallery_admin_editusers + '); return false;" href="' + url +'">' + menu_profile + '</a>';
	menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=4&gal_user=' + name + '">' + menu_allcons + '</a>';
	if (alt == 'yes')
		menu[2]='<a href="' + dle_root + gallery_web_root +'all/user-' + name + '/">' + menu_allfoto + '</a>';
	else
		menu[2]='<a href="' + dle_root + 'index.php?do=gallery&act=15&gal_user=' + name + '">' + menu_allfoto + '</a>';

return menu;
};

function ShortGalFoto( ID, adm, ed, dl ){

var menu=new Array();

if (ed == '1')
	menu[0]='<a href="' + dle_root + 'index.php?do=gallery&act=17&dle_allow_hash=' + dle_login_hash + '&si=' + ID + '">' + menu_short + '</a>';
if (adm != '0')
	menu[menu.length]='<a href="' + dle_root + dle_admin + '?mod=twsgallery&act=24&selected_news=' + ID + '" target="_blank">' + menu_full + '</a>';
if (dl == '1')
	menu[menu.length]='<a onClick="confirmact(\'' + menu_confirm1 + '\', \'' + dle_root + 'index.php?do=gallery&act=13&dle_allow_hash=' + dle_login_hash + '&si=' + ID + '\'); return false;" href="#">' + menu_delete + '</a>';

return menu;
};

function MenuGalComment( com_id ){

var menu=new Array();

menu[0]='<a onclick="twsg_ajax_comm_edit(\'' + com_id + '\'); return false;" href="#">' + menu_short + '</a>';
menu[1]='<a href="' + dle_root + 'index.php?do=gallery&act=3&dle_allow_hash=' + dle_login_hash + '&subaction=comm_edit&com_id=' + com_id + '">' + menu_full + '</a>';

return menu;
};

function doAddTWSGComments(){

	var form = document.getElementById('dle-comments-form');

	if (dle_wysiwyg == "yes") {
		document.getElementById('comments').value = $('#comments').html();
		var editor_mode = 'wysiwyg';
	} else { var editor_mode = ''; }

	if (form.comments.value == '' || form.name.value == '')
	{
		DLEalert ( dle_req_field, dle_info );
		return false;
	}

	if ( form.sec_code ) {

	   var sec_code = form.sec_code.value;

    } else { var sec_code = ''; }

	if ( form.recaptcha_response_field ) {
	   var recaptcha_response_field= Recaptcha.get_response();
	   var recaptcha_challenge_field= Recaptcha.get_challenge();
    } else {
	   var recaptcha_response_field= '';
	   var recaptcha_challenge_field= '';
	}

	ShowLoading('');

	$.post(dle_root + "engine/gallery/ajax/comments.php", { id: form.id.value, comments: form.comments.value, name: form.name.value, mail: form.mail.value, editor_mode: editor_mode, skin: dle_skin, sec_code: sec_code, recaptcha_response_field: recaptcha_response_field, recaptcha_challenge_field: recaptcha_challenge_field, action: 'add' }, function(data){

		if ( form.sec_code ) {
           form.sec_code.value = '';
           reload();
	    }

		HideLoading('');

		RunAjaxJS('dle-ajax-comments', data);

		if (data != 'error' && document.getElementById('blind-animation')) {

			$("html"+( ! $.browser.opera ? ",body" : "")).animate({scrollTop: $("#dle-ajax-comments").position().top - 70}, 1100);
	
			setTimeout(function() { $('#blind-animation').show('blind',{},1500)}, 1100);
		}

	});

};

function twsg_ajax_comm_edit( com_id ){

	if ( ! twsg_p_cache[ com_id ] || twsg_p_cache[ com_id ] == '' )
	{
		twsg_p_cache[ com_id ] = $('#comm-id-'+com_id).html();
	}

	ShowLoading('');

	$.get(dle_root + "engine/gallery/ajax/comments.php", { com_id: com_id, dle_allow_hash: dle_login_hash, action: "edit", skin: dle_skin }, function(data){

		HideLoading('');

		RunAjaxJS('comm-id-'+com_id, data);

		setTimeout(function() {
           $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: $("#comm-id-" + com_id).position().top - 70}, 700);
       }, 100);

	});
	return false;

};

function uncom_ajax_cancel_comm_edit( com_id )
{
	if (twsg_p_cache[ com_id ] != "" ){
		$("#comm-id-"+com_id).html(twsg_p_cache[ com_id ]);
	}
	return false;
};

function uncom_ajax_save_comm_edit( com_id )
{

	var comm_txt = '';

	if (dle_wysiwyg == "yes") {
		comm_txt = $('#dleeditcomments'+com_id).html();
	} else {
		comm_txt = $('#dleeditcomments'+com_id).val();
	}

	ShowLoading('');

	$.post(dle_root + "engine/gallery/ajax/comments.php", { com_id: com_id, comm_txt: comm_txt, dle_allow_hash: dle_login_hash, action: "do_edit", skin: dle_skin }, function(data){

		HideLoading('');
		twsg_p_cache[ com_id ] = '';
		$("#comm-id-"+com_id).html(data);

	});
	return false;

};

function AddImages(id, id_name, id_type, id_size) {
	var tbl = document.getElementById(id);
	var lastRow = tbl.rows.length;
	if (!gallery_max_once_upload) gallery_max_once_upload = 50;
	if (lastRow < gallery_max_once_upload){
		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.setAttribute('size', id_size);
		cellRight.appendChild(el);
	}
};

function RemoveImages(id) {
	var tbl = document.getElementById(id);
	var lastRow = tbl.rows.length;
	if (lastRow > 1){
	  tbl.deleteRow(lastRow - 1);
	}
};



function DeleteComment( id ) {

    DLEconfirm( dle_del_agree, dle_confirm, function () {

		ShowLoading('');
	
		$.get(dle_root + "engine/gallery/ajax/comments.php", { com_id: id, dle_allow_hash: dle_login_hash, action: "delete", skin: dle_skin }, function(data){

			HideLoading('');//$("#comment-" + id).html(data);
			$("html"+( ! $.browser.opera ? ",body" : "")).animate({scrollTop: $("#comment-" + id).position().top - 70}, 700);
			setTimeout(function() { $("#comment-" + id).hide('blind',{},1400)}, 700);

		});

	});

};

function confirmact(text, url) {
DLEconfirm(text, dle_confirm, function (){
	document.location=url;
} );
}

function show_rules( id ){
	if ( id != '0' ){
		ShowLoading('');
		$.get(dle_root + "engine/gallery/ajax/rules.php", { id: id, skin: dle_skin }, function(data){
			HideLoading('');
			$("#rules-layer").html(data);
		});
	} else {
		$("#rules-layer").html(menu_chose);
	}
};

function doFotoSet(ev, ID){
	ShowLoading('');
	$.get(dle_root + "engine/gallery/ajax/foto.php", { si: ID, skin: dle_skin, act: ev, dle_allow_hash: dle_login_hash }, function(data){
		HideLoading('');
		$("#fotoedit-"+ID).html(data);
	});
	return false;
};

function GalRate( rate, id, mode ){
	ShowLoading('');
	$.get(dle_root + "engine/gallery/ajax/rating.php", { go_rate: rate, id: id, skin: dle_skin, mode: mode, dle_allow_hash: dle_login_hash }, function(data){
		HideLoading('');
		$("#ratig-layer-"+id).html(data);
	});
};

