var iTypologyList_PrevSelIndex = 0;

function CheckTypology (theMainForm, theTypologyForm)
{
	var theObjList = theMainForm.TypologyList;
	var szEmpty = theMainForm.name == "UpdateDoc" ? "" : szNoChange;

	if (theTypologyForm.HasBeenFilled.value == '1')  {
		if (!confirm (szDocProf_ProfileChanged)) {
			//I restore the old index value of the select list.
			theObjList.selectedIndex = iTypologyList_PrevSelIndex;
			return;
		}
		else {
			//I clean all the variables that contain the documents profiling values.
			theMainForm.Numbers.value = "";
			theMainForm.Texts.value = "";
			theMainForm.Blobs.value = "";
			theMainForm.Dates.value = "";
			theTypologyForm.Numbers.value = szEmpty;
			theTypologyForm.Texts.value = szEmpty;
			theTypologyForm.Blobs.value = szEmpty;
			theTypologyForm.Dates.value = szEmpty;
			theTypologyForm.HasBeenFilled.value = '0';
		}
	}
	//I save the current selected index.
	iTypologyList_PrevSelIndex = theObjList.selectedIndex;
}

function CheckTypologyRequired (theMainForm, theTypologyForm)
{
	var theTypologyListObj = theMainForm.TypologyList;
	var szValue = theTypologyListObj.options[theTypologyListObj.selectedIndex].value;
	var theParseObj = new ParseObj (null, N_PARSE_DOCTYP, szValue);
	theParseObj = parseString (theParseObj);
	if (theParseObj.List[DOCTYP_REQUIRED] == '1') {
		if (theTypologyForm.HasBeenFilled.value == '0')
			return (true);
	}
	return (false);
}

function GetTypologyID (theMainForm, bTestExistField)
{
	var theTypologyListObj = theMainForm.TypologyList;
	var szValue = theTypologyListObj.options[theTypologyListObj.selectedIndex].value;
	var theParseObj = new ParseObj (null, N_PARSE_DOCTYP, szValue);
	theParseObj = parseString (theParseObj);
	if (bTestExistField) {
		if (theParseObj.List[DOCTYP_EXISTFIELD] == '1')
			return (theParseObj.List[DOCTYP_ID]);
		else
			return (0);
	}
	else
		return (theParseObj.List[DOCTYP_ID]);
}

function SelectTypologyIndex (theMainForm, theTypologyForm)
{
	var i;
	var szValue;

	var theTypologyListObj = theMainForm.TypologyList;
	for (i = 0; i < theTypologyListObj.options.length; i++) {
		szValue = theTypologyListObj.options[i].value;
		var theParseObj = new ParseObj (null, N_PARSE_DOCTYP, szValue);
		theParseObj = parseString (theParseObj);
	
		if (theMainForm.TypologyID.value == theParseObj.List[DOCTYP_ID]) {
			theTypologyListObj.selectedIndex = i;
			iTypologyList_PrevSelIndex = i;
			return;
		}
	}
}

function SetHasBeenFilled (theMainForm, theTypologyForm)
{
	var theTypologyListObj = theMainForm.TypologyList;
	var iSelected = theTypologyListObj.selectedIndex;
	var szValue = theTypologyListObj.options[iSelected].value;
	var theParseObj = new ParseObj (null, N_PARSE_DOCTYP, szValue);
	theParseObj = parseString (theParseObj);
	if (theParseObj.List[DOCTYP_REQUIRED] == '1')
		theTypologyForm.HasBeenFilled.value = '1';
	else {
		if (theParseObj.List[DOCTYP_EXISTFIELD] == '1')
			theTypologyForm.HasBeenFilled.value = '1';
		else
			//Case of STANDARD Typology
			theTypologyForm.HasBeenFilled.value = '0';
	}	
}






