// JavaScript Document

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

function ShowNewBild(sPicURL) {
	window.open(dle_root + 'engine/modules/imagepreview.php?image='+sPicURL, '', 'resizable=1,HEIGHT=200,WIDTH=200, scrollbars=yes');
}

function ckeck_uncheck_foto(){

	var frm = document.fotoedit;
	for (var i=0;i<frm.elements.length;i++) {
		var elmnt = frm.elements[i];
		if (elmnt.type=='checkbox') {
			if(!frm.master_fa_box.checked){
				elmnt.checked=false;
			} else {
				elmnt.checked=true;
			}
		}
	}

    if (!frm.master_fa_box.checked){
		frm.master_fa_box.checked = false;
	} else {
		frm.master_fa_box.checked = true;
	}

};

function MenuFotoAlbum( ID ){

var menu=new Array();

menu[0]='<a href="' + dle_root + 'index.php?do=fotoalbum&subaction=create&id=' + ID + '">' + menu_edit + '</a>';
menu[1]='<a onclick="confirmDeleteAlb(\'' + dle_root + 'index.php?do=fotoalbum&subaction=delete&id=' + ID + '\'); return false;" href="' + dle_root + 'index.php?do=fotoalbum&subaction=delete&id=' + ID + '">' + menu_delete + '</a>';

return menu;
};

function MenuFotoComment( ID ){

var menu=new Array();

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

return menu;
};

function MenuFotoPicture( ID ){

var menu=new Array();

menu[0]='<a onclick="SetFotoParams(\'' + ID + '\', \'setcover\'); return false;" href="' + dle_root + '">' + menu_cover + '</a>';
menu[1]='<a onclick="SetFotoParams(\'' + ID + '\', \'viewall\'); return false;" href="' + dle_root + '">' + menu_view1 + '</a>';
menu[2]='<a onclick="SetFotoParams(\'' + ID + '\', \'viewnoguests\'); return false;" href="' + dle_root + '">' + menu_view2 + '</a>';
menu[3]='<a onclick="SetFotoParams(\'' + ID + '\', \'viewfriends\'); return false;" href="' + dle_root + '">' + menu_view3 + '</a>';
menu[4]='<a onclick="SetFotoParams(\'' + ID + '\', \'viewnothumb\'); return false;" href="' + dle_root + '">' + menu_nothumb + '</a>';
menu[5]='<a onclick="SetFotoParams(\'' + ID + '\', \'viewintim\'); return false;" href="' + dle_root + '">' + menu_intim + '</a>';
menu[6]='<a href="' + dle_root + 'index.php?do=fotoalbum&subaction=editfoto&id=' + ID + '">' + menu_fedit + '</a>';
menu[7]='<a href="' + dle_root + 'index.php?do=fotoalbum&subaction=movefoto&id=' + ID + '">' + menu_freplace + '</a>';
menu[8]='<a onclick="confirmDeleteFoto(\'' + dle_root + 'index.php?do=fotoalbum&subaction=deletefoto&id=' + ID + '\'); return false;" href="' + dle_root + 'index.php?do=fotoalbum&subaction=deletefoto&id=' + ID + '">' + menu_fdelete + '</a>';

return menu;
};

function doAddFaComments(){

	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/fotoalbum/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.requestFile = dle_root + "engine/fotoalbum/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.requestFile = dle_root + "engine/fotoalbum/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.requestFile = dle_root + "engine/fotoalbum/ajax/comments.php";
	ajax.method = 'POST';
	ajax.element = 'comm-id-'+c_id;
	ajax.onCompletion = whenCompletedSavePost;
	ajax.sendAJAX(varsString);

	return false;
};

function confirmDeleteAlb(url){

    var agree=confirm( menu_delete_s );

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

function confirmDeleteFoto(url){

    var agree=confirm( menu_fdelete_s );

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

function SetFotoParams( 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/fotoalbum/ajax/setfoto.php";
	ajax.method = 'GET';
	ajax.element = 'foto-id-'+id;
	ajax.sendAJAX(varsString);

	return false;
};

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

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

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

	return false;
};
