/************************************************************************/
/* 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 assessment_server_url = '';
var _PA = new Array();

function setup_assessment(passed_server_url) {
	assessment_server_url = passed_server_url;
	
	var data = "op=getLang";
	var objAjax = new Ajax.Request(
        	assessment_server_url,
        	{method: 'post', parameters: data, onComplete: setup_assessment_complete}
    );
}

function setup_assessment_complete(ObjReq) {
	var langText = ObjReq.responseText;
	_PA = langText.evalJSON(true);
}

function del_pre_assessment(id, assess_name) {

	var butt="";
	butt += '<input type="hidden" id="id_assessment" name="id_assessment" value="' + id +'" />';
	butt += '<input type="submit" value="'+_PA._YES+'" /> ';
	butt += '<input type="button" value="'+_PA._NO+'" onclick="destroyWindow(\'window_del_assess\');"; return false;" />';
	
	var forms = document.createElement('form');
	forms.method = 'post';
	forms.action = 'index.php?modname=preassessment&op=delassessment';
	
	var w = new Window();
	w.id 		= "window_del_assess";
	w.width 	= 400;
	w.height 	= 125;
	w.title 	= _PA._DEL_TITLE;
	w.content 	= _PA._DEL_CONFIRM + '<br /><b>' + assess_name + '</b>';
	w.form 		= forms;
	w.buttons 	= butt;
	w.show();	
	
}


function del_assessment_rule(id, rule_name) {

	var name = "window_del_assess";
	var title = _PA._DEL_TITLE_RULE;
	
	var str="";
	str += _PA._DEL_CONFIRM_RULE + '<br /><b>' + rule_name + '</b>';
	var butt="";
	butt += '<form method="post" action="index.php?modname=preassessment&amp;op=delrule">';
	butt += '<input type="hidden" id="id_rule" name="id_rule" value="' + id +'" />';
	butt += '<input type="submit" value="'+_PA._YES+'" /> ';
	butt += '<input type="button" value="'+_PA._NO+'" onclick="destroyWindow(\'window_del_assess\');"; return false;" />';
	butt += '</form>';
	
	var w = new Window();
	w.id = name;
	w.width = 400;
	w.height = 125;
	w.title = title;
	w.content = str;
	w.buttons = butt;
	w.show();
}

function add_rule_mask(id_assessment, usedef) {
	
	var data = "op=modruleform&id_assessment=" + id_assessment + "&usedef=" + usedef;
	
	var objAjax = new Ajax.Request(
        	assessment_server_url,
        	{method: 'post', parameters: data, onComplete: add_rule_mask_callback}
    );
}


function mod_rule_mask(id_assessment, id_rule) {
	
	var data = "op=modruleform&id_assessment=" + id_assessment + "&id_rule=" + id_rule;
	
	var objAjax = new Ajax.Request(
        	assessment_server_url,
        	{method: 'post', parameters: data, onComplete: mod_rule_mask_callback}
    );
}

function add_rule_mask_callback(ObjReq) {
	
	var name = "window_add_rule";
	var title = _PA._NEW_RULE;
	
	var forms = document.createElement('form');
	forms.method = 'post';
	forms.action = 'index.php?modname=preassessment&op=saverule';
	
	var str = ObjReq.responseText;
	
	var but = '<input type="submit" id="addrule" name="addrule" value="' + _PA._CONFIRM + '" /> ';
	but += '<input type="button" value="' + _PA._UNDO + '" onclick="destroyWindow(\'' + name +'\');" />';
	
	var w = new Window();
	w.id = name;
	w.width = 600;
	w.title = title;
	w.content = str;
	w.buttons = but;
	w.form = forms;
	w.show();
}

function mod_rule_mask_callback(ObjReq) {
	
	var name = "window_add_rule";
	var title = _PA._NEW_RULE;
	
	var forms = document.createElement('form');
	forms.method = 'post';
	forms.action = 'index.php?modname=preassessment&op=saverule';
	
	var str = ObjReq.responseText;
	
	var but = '<input type="submit" id="modrule" name="modrule" value="' + _PA._CONFIRM + '" /> ';
	but += '<input type="button" value="' + _PA._UNDO + '" onclick="destroyWindow(\'' + name +'\');" />';
	
	var w = new Window();
	w.id = name;
	w.width = 600;
	w.title = title;
	w.content = str;
	w.buttons = but;
	w.form = forms;
	w.show();
}

function rule_type_change(rule_type, id_score_type_one, id_score_type_two) {

	var elem = $(rule_type).selectedIndex;
	if(elem == 0) {
		$(id_score_type_one).disabled = false;
		$(id_score_type_two).disabled = true;
	}
	if(elem == 1) {
		$(id_score_type_one).disabled = false;
		$(id_score_type_two).disabled = true;
	}
	if(elem == 2) {
		$(id_score_type_one).disabled = false;
		$(id_score_type_two).disabled = false;
	}
	if(elem == 3) {
		$(id_score_type_one).disabled = true;
		$(id_score_type_two).disabled = true;
	}
}
