CSDialog = function(){
	this.imgRoot = './images/';
	this.escapeCapture = true;

	this.cSMessage = new CSMessage();
	this.cSMessage.setShadowOffset(5);
	this.modalH = 100;
	this.modalW = 300;
	this.buttonH = 30;
	this.modalSource = false;
	this.modalShadow = true;
	this.modalClass = false;

	// NE PAS MODIFIER LES PARAMETRES SUIVANTS
	this.keyBoardCaptureFuncOk = '';
	this.keyBoardCaptureFuncAnnuler = '';
	this.isOpen = false;

	this.init = function(){
		this.imgHtmlCode = '<a href=\'javascript:[lien]\' id=\'[id]\'><img src=\'[image]\' alt=\'\' title=\'\'/></a>';

		// Génération des images des boîtes de dialogue
		this.alertHtmlCode = '<div id=\'cs_object_img\'>'+this._getLienImage(this.imgRoot+'alert.gif', 'void(0)')+'</div>';

		// Génération des boutons
		// this.closeButtonHtmlCode = '<div id=\'cs_object_close\'>'+this._getLienImage(this.imgRoot+'close.gif', 'cSDialog.cSCloseMsg(false, false)', 'cs_object_close')+'</div>';
		this.closeButtonHtmlCode = '';
		this.okButtonHtmlCode = this._getLienImage(this.imgRoot+'ok.gif', '[ok:lien]', 'cs_object_ok');
		this.annulerButtonHtmlCode = this._getLienImage(this.imgRoot+'annuler.gif', '[annuler:lien]', 'cs_object_annuler');

		// Champ texte
		this.inputHtmlCode = '<tr><td colspan=\'2\'><input id=\'cs_object_input\' value=\'[input:value]\'/></td></tr>';

		// Création des lignes du tableau
		this.messageHtmlCode = '<div id=\'cs_object_msg\'>[message]</div>';
		this.line1_1 = '<tr height=\''+(this.modalH-((this.buttonH-5)*2))+'\'><td width=\'0%\'>[image]</td><td width=\'100%\'>'+this.messageHtmlCode+'</td></tr>'
		this.line1_2 = '<tr height=\''+(this.modalH-((this.buttonH-5)*2))+'\'><td width=\'100%\' colspn=\'2\'>'+this.messageHtmlCode+'</td></tr>'
		this.line2 = '[input]';
		this.line3 = '<tr height=\''+this.buttonH+'\' valign=\'top\'><td colspan=\'2\' id=\'cs_object_actions\'>[ok]&nbsp;[annuler]</td></tr>';

		// Génération du message
		this.tableHtmlCode = '<table cellspacing=\'0\' cellpadding=\'0\' border=\'0\'>[line1][line2][line3]</table>';
		this.htmlCode = '<div id=\'cs_object_global\'>[close]'+this.tableHtmlCode+'</div>';
	}

	this.cSAlert = function(string){
		tmpHtmlCode = this.htmlCode;
		tmpHtmlCode = this._replace('[line1]', this.line1_1, tmpHtmlCode);
		tmpHtmlCode = this._replace('[message]', string, tmpHtmlCode);
		tmpHtmlCode = this._replace('[line2]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[line3]', this.line3, tmpHtmlCode);
		tmpHtmlCode = this._replace('[image]', this.alertHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok]', this.okButtonHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('&nbsp;[annuler]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[close]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok:lien]', 'cSDialog.cSCloseMsg(false, false)', tmpHtmlCode);
		this.cSDisplayContent(tmpHtmlCode);
		this._setFocus('cs_object_ok');
	}

	this.cSConfirm = function(string, okExecute, annulerExecute){
		tmpHtmlCode = this.htmlCode;
		tmpHtmlCode = this._replace('[line1]', this.line1_2, tmpHtmlCode);
		tmpHtmlCode = this._replace('[message]', string, tmpHtmlCode);
		tmpHtmlCode = this._replace('[line2]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[line3]', this.line3, tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok]', this.okButtonHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[annuler]', this.annulerButtonHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[close]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok:lien]', 'cSDialog.cSCloseMsg(true, false)', tmpHtmlCode);
		if(annulerExecute){
			tmpHtmlCode = this._replace('[annuler:lien]', 'cSDialog.cSCloseMsg(false, true)', tmpHtmlCode);
			this.keyBoardCaptureFuncAnnuler = annulerExecute+'()';
		}
		else{
			tmpHtmlCode = this._replace('[annuler:lien]', 'cSDialog.cSCloseMsg(false, false)', tmpHtmlCode);
		}
		this.keyBoardCaptureFuncOk = okExecute+'()';
		this.cSDisplayContent(tmpHtmlCode);
		this._setFocus('cs_object_ok');
	}

	this.cSPrompt = function(stringTxt, stringDflt, execute){
		tmpHtmlCode = this.htmlCode;
		tmpHtmlCode = this._replace('[line1]', this.line1_2, tmpHtmlCode);
		tmpHtmlCode = this._replace('[message]', stringTxt, tmpHtmlCode);
		tmpHtmlCode = this._replace('[line2]', this.inputHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[line3]', this.line3, tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok]', this.okButtonHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[annuler]', this.annulerButtonHtmlCode, tmpHtmlCode);
		tmpHtmlCode = this._replace('[close]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[ok:lien]', 'cSDialog.cSCloseMsg(true, false)', tmpHtmlCode);
		tmpHtmlCode = this._replace('[annuler:lien]', 'cSDialog.cSCloseMsg(false, false)', tmpHtmlCode);
		tmpHtmlCode = this._replace('[input:value]', stringDflt, tmpHtmlCode);
		tmpHtmlCode = this._replace('height=\''+(this.modalH-((this.buttonH-5)*2))+'\'', 'height=\''+(this.modalH-(this.buttonH*2))+'\'', tmpHtmlCode);
		this.keyBoardCaptureFuncOk = execute+'(cSDialog.cSPromptValue(\''+stringDflt+'\'))';
		this.cSDisplayContent(tmpHtmlCode);
		this._setFocus('cs_object_input');
		this._setSelect('cs_object_input');
	}

	this.cSDisplay = function(string){
		tmpHtmlCode = this.htmlCode;
		tmpHtmlCode = this._replace('[line1]', this.line1_2, tmpHtmlCode);
		tmpHtmlCode = this._replace('[message]', string, tmpHtmlCode);
		tmpHtmlCode = this._replace('[line2]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[line3]', '', tmpHtmlCode);
		tmpHtmlCode = this._replace('[close]', this.closeButtonHtmlCode, tmpHtmlCode);
		this.cSDisplayContent(tmpHtmlCode);
	}

	this.cSPromptValue = function(strOld){
		var strReturn = document.getElementById('cs_object_input').value;
		if(strReturn==strOld){
			// Si aucune valeur n'a été saisie
// 			strReturn = '';
		}
		return strReturn;
	}

	this.cSDisplayContent = function(string){
		this.cSMessage.setHtmlContent(string);
		this.cSMessage.setSize(this.modalW, this.modalH);
		this.cSMessage.setCssClassMessageBox(this.modalClass);
		this.cSMessage.setSource(this.modalSource);
		this.cSMessage.setShadowDivVisible(this.modalShadow);
		this.cSMessage.display();
		this.isOpen = true;
	}

	this.cSCloseMsg = function(okExecute, annulerExecute){
		var tmpFuncOk = this.keyBoardCaptureFuncOk;
		var tmpFuncAnnuler = this.keyBoardCaptureFuncAnnuler;
		this.keyBoardCaptureFuncOk = '';
		this.keyBoardCaptureFuncAnnuler = '';
		if(this.isOpen){
			if(okExecute&&tmpFuncOk!=''){
				eval(tmpFuncOk);
			}
			if(annulerExecute&&tmpFuncAnnuler!=''){
				eval(tmpFuncAnnuler);
			}
			this.cSMessage.close();
		}
		this.isOpen = false;
	}

	this.setShadow = function(bool){
		this.modalShadow = false;
		if(bool){
			this.modalShadow = true;
		}
	}

	this.setShadowOffset = function(intVar){
		if(intVar){
			this.cSMessage.setShadowOffset(intVar);
		}
	}

	this.setHeight = function(intVar){
		this.modalH = parseInt(intVar);
	}

	this.setWidth = function(intVar){
		this.modalW = parseInt(intVar);
	}

	this.setImgRoot = function(string){
		this.imgRoot = string;
	}

	this._replace = function(strToReplace, strReplace, string){
		string1 = string.substring(0, string.indexOf(strToReplace, 0));
		string2 = string.substring((string.indexOf(strToReplace, 0)+strToReplace.length), string.length);
		string = string1+''+strReplace+''+string2;
		return string;
	}

	this._setFocus = function(id){
		document.getElementById(id).focus();
	}

	this._setSelect = function(id){
		document.getElementById(id).select();
	}

	this._setKeyboardCapture = function(){
		document.onkeydown = this._keyboardCapture;
	}

	this._keyboardCapture = function(keyStroke){
		var IE = navigator.appName.indexOf("Microsoft") != -1;
		if (!keyStroke) e = window.event;
		if (IE){
			clavier = e.keyCode;
		}
		else{
			var clavier = (window.Event) ? keyStroke.which : keyStroke.keyCode;
		}
		if(parseInt(clavier)==13){
			cSDialog.cSCloseMsg(true, false);
		}
		if(parseInt(clavier)==27&&cSDialog.escapeCapture){
			cSDialog.cSCloseMsg(false, true);
		}
	}

	this._getLienImage = function(image, lien, id){
		var tmp = this.imgHtmlCode;
		tmp = this._replace('[lien]', lien, tmp);
		tmp = this._replace('[image]', image, tmp);
		tmp = this._replace('[id]', id, tmp);
		return tmp;
	}

	this._setKeyboardCapture();

}
