/* Variable applicative indiquant que la classe KaForm a été chargée */
_KaForm_Loaded = true;

function KaForm() {

	// Déclaration des champs
	this.fFormComponent = null;
	this.fFields = new Array();
	this.fLocalisationFileName = null;


	/****************************************************************************************************
		this.setLocalisationFileName = function setLocalisationFileName(pLocalisationFileName)
		Méthode d'affectation du fichier de localisation
	*/
	this.setLocalisationFileName = function setLocalisationFileName(/*String*/pLocalisationFileName) {
		this.fLocalisationFileName = pLocalisationFileName;
		
		document.write('<script src="' + pLocalisationFileName + '" language="JavaScript" type="text/javascript"></script>');
	}


	/****************************************************************************************************
		this.addField = function addField(pField)
		Méthode d'ajout de champ au formulaire
	*/
	this.addField = function addField(/*KaField*/pField) {
		this.fFields[this.fFields.length] = pField;
	}


	// Initialisation de l'objet KaForm
	this.init(arguments);
}


/*
	Constructeur de la classe KaForm
*/
KaForm.prototype.init = function(pArguments) {
	if ((typeof(pArguments) != 'undefined') && (pArguments.length == 2)) {
		vFormComponent = pArguments[0];
		vLocalisationFileName = pArguments[1];

		if (typeof(vFormComponent) != 'undefined')
			this.fFormComponent = vFormComponent;

		if (typeof(vLocalisationFileName) == 'string')
			this.setLocalisationFileName(vLocalisationFileName);
	}
	else {
		alert('** Erreur d\'instanciation de l\'objet KaForm !');
	}
}


/*
	Méthode de DEBUG
*/
KaForm.prototype.debug = function() {
	for (i = 0; i < this.fFields.length; i++) {
		this.fFields[i].debug();
	}
}


/*
	Méthode de vérification des champs du formulaire
*/
KaForm.prototype.check = function() {
	var vCheckOK = true;
	var vNumField = 0;

	if ((typeof(_Localisation_Loaded) != 'undefined') && (_Localisation_Loaded)) {
		while ((vCheckOK) && (vNumField < this.fFields.length)) {
			vCheckOK = this.fFields[vNumField].check();
			vNumField++;
		}
	}
	else {
		alert('** KaForm : Le fichier de localisation n\'a pas été chargé !');
		return false;
	}
	
	return vCheckOK;
}


/*
	Méthode de vérification des champs du formulaire
*/
KaForm.prototype.getComponents = function() {
	if (this.fFormComponent != null) {
		var vFormComponents = this.fFormComponent.elements;
		
		for (var vNumComponent = 0; vNumComponent < vFormComponents.length; vNumComponent++) {
			// (Button, Checkbox, FileUpload, Hidden, Password, Radio, Reset, Select, Submit, Text, or Textarea object)
			var vMessage = '';
			switch (vFormComponents[vNumComponent].type) {
				case 'button' : vMessage += 'BOUTON'; break;
				case 'checkbox' : vMessage += 'CASE A COCHER'; break;
				case 'file' : vMessage += 'UPLOAD DE FICHIER'; break;
				case 'hidden' : vMessage += 'CHAMP CACHE'; break;
				case 'password' : vMessage += 'MOT DE PASSE'; break;
				case 'text' : vMessage += 'CHAMP DE SAISIE'; break;
				case 'textarea' : vMessage += 'BLOC DE SAISIE'; break;
				case 'radio' : vMessage += 'BOUTON DE SELECTION'; break;
				case 'select-one' : vMessage += 'LISTE DEROULANTE'; break;
				case 'select-multiple' : vMessage += 'LISTE DEROULANTE'; break;
				case 'reset' : vMessage += 'ANNULER'; break;
				case 'submit' : vMessage += 'VALIDER'; break;
			}
			vMessage += '\n';
			vMessage += 'Name: ' + vFormComponents[vNumComponent].name + '\n';
			vMessage += 'Value: ' + vFormComponents[vNumComponent].value + '\n';
			vMessage += 'Type: ' + vFormComponents[vNumComponent].type + '\n';
			vMessage += 'Size: ' + vFormComponents[vNumComponent].size + '\n';
			vMessage += 'MaxLength: ' + vFormComponents[vNumComponent].maxLength + '\n';
			vMessage += 'Style: ' + vFormComponents[vNumComponent].style + '\n';
			alert(vMessage);
/*
				var vMessage = '';
				for (var vObj in vFormComponents[vNumComponent])
					vMessage += vObj + ' : ' + new String(vFormComponents[vNumComponent][vObj]) + '<br>';
				vBrowser = window.open('', 'DOMBrowser', 'scrollbars=yes, width=500, height=600, resizable=yes');
				vBrowser.focus();
				vBrowser.document.open('text/html', 'replace');
				vBrowser.document.writeln('<HTML><HEAD><TITLE>DOM Browser</TITLE></HEAD>');
				vBrowser.document.writeln('<BODY BGCOLOR="BBBBBB" link="FFFFF" vlink="FFFFF">');
				vBrowser.document.writeln(vMessage);
				vBrowser.document.writeln('</BODY></HTML>');
				vBrowser.document.close();
				alert('wait');
*/
			}
		}
/*
	}
*/
}

