/************************************************************************/
/* DOCEBO CORE - Framework												*/
/* ============================================							*/
/*																		*/
/* Copyright (c) 2006													*/
/* http://www.docebo.com												*/
/*																		*/
/* This program is free software. You can redistribute it and/or modify	*/
/* it under the terms of the GNU General Public License as published by	*/
/* the Free Software Foundation; either version 2 of the License.		*/
/************************************************************************/

var light_repo__server_url;
var light_repo_lang;

function setup_light_repo(passed_server_url) {
	light_repo_server_url = passed_server_url;
}

function delete_confirm_request(id_repo) {
	
	var data = "op=confirm_repo_delete&id_repo=" + id_repo;
	var objAjax = new Ajax.Request(
        	light_repo_server_url,
        	{method: 'post', parameters: data, onSuccess: delete_confirm_request_complete}
    );
}

function delete_confirm_request_complete(objReq) {
	
	var re = (objReq.responseText).evalJSON(true);
	
	var w 		= new Window();
	w.id 		= "window_del_repo";
	w.width 	= 400;
	w.height 	= 125;
	
	var forms = document.createElement('form');
	forms.method = 'post';
	forms.action = 'index.php';
	forms.onsubmit = function () {
		var data = "op=delete_repo&id_repo=" + $F('id_repo');
		var objAjax = new Ajax.Request(
	        	light_repo_server_url,
	        	{method: 'post', parameters: data, onComplete: delete_repo_complete}
	    );
		destroyWindow('window_del_repo');
	    return false;
	}
	
	var butt="";
	butt += '<input type="hidden" id="id_repo" name="id_repo" value="' + re.id_repo + '" /> ';
	butt += '<input type="submit" value="' + re.win_confirm + '" /> ';
	butt += '<input type="button" value="'+re.win_undo+'" onclick="destroyWindow(\'window_del_repo\');" />';
	
	w.title 	= re.win_title;
	w.content 	= re.win_text;
	w.form 		= forms;
	w.buttons 	= butt;
	w.show();
}

function delete_repo_complete(objReq) {
	
	var re = (objReq.responseText).evalJSON(true);
	if(re.result) { Effect.Fade('repo_container_' + re.id_repo); }
	if(re.result_text != '' && re.result_text != undefined) {
		NoticeMsg.display(re.result_text, 'light_repo_block', 'success', 30000);
	}
}

// delete a file --------------------------------------------------------------------

function delete_confirm_file(id_file) {
	
	var data = "op=confirm_file_delete&id_file=" + id_file;
	var objAjax = new Ajax.Request(
        	light_repo_server_url,
        	{method: 'post', parameters: data, onSuccess: delete_confirm_file_complete}
    );
}

function delete_confirm_file_complete(objReq) {
	
	var re = (objReq.responseText).evalJSON(true);
	var w 		= new Window();
	w.id 		= "window_del_file";
	w.width 	= 400;
	w.height 	= 125;
	
	var forms = document.createElement('form');
	forms.method = 'post';
	forms.action = 'index.php';
	forms.onsubmit = function () { 
		
		var data = "op=delete_file&id_file=" + $F('id_file');
		var objAjax = new Ajax.Request(
	        	light_repo_server_url,
	        	{method: 'post', parameters: data, onComplete: delete_confirm_complete}
	    );
	    destroyWindow('window_del_file');
	    return false;
	}
	
	var butt="";
	butt += '<input type="hidden" id="id_file" name="id_file" value="' + re.id_file + '" /> ';
	butt += '<input type="submit" value="' + re.win_confirm + '" /> ';
	butt += '<input type="button" value="' + re.win_undo + '" onclick="destroyWindow(\'window_del_file\');" />';
	
	w.title 	= re.win_title;
	w.content 	= re.win_text;
	w.form 		= forms;
	w.buttons 	= butt;
	w.show();
}

function delete_confirm_complete(objReq) {
	
	var re = (objReq.responseText).evalJSON(true);
	
	if(re.result) { 
		Effect.Fade('file_container_' + re.id_file); 
		var table = $('file_container_' + re.id_file).parentNode;
		
		var i = 0;
		for(var j = 1;j < table.rows.length; j++) {
			
			table.rows[j].className = ( i++%2 ? 'line' : 'line-col' );
		}
	}	
	if(re.result_text != '' && re.result_text != undefined) {
		NoticeMsg.display(re.result_text, 'light_repo_block', 'success', 30000);
	}
}
