<!-- // JavaScript Document
//							:::::::::::::::::::::::::::::::::::::::
//								Support page for fgfMain.cfm
//							:::::::::::::::::::::::::::::::::::::::



// window.onload=montre;		
window.name = "winMain";
//////////////////////////////////////////////////////////////////////////////////////////////////

function clearForm()
{
window.open(fgfMainAct.cfm);	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
	
	function update()
	{
		// set local variable
		var fgfChanged				=	false;
		var txtPersonActionValue	=	'FALSE';
		var txtNameActionValue		=	'FALSE';
		var txtBirthActionValue		=	'FALSE';
		var txtDeathActionValue		=	'FALSE';
		var txtSpouseChangeAllValue	=	'FALSE';
		var txtChildChangeAllValue	=	'FALSE';
		
		// check if anything has changed on FGF
		var txtPersonActionField	=	document.getElementById('txtPersonAction');
		if(txtPersonActionField)
		{
			txtPersonActionValue	=	txtPersonActionField.value;
		}
		var txtNameActionField		=	document.getElementById('txtNameAction');
		if(txtNameActionField)
		{
			txtNameActionValue	=	txtNameActionField.value;
		}
		var txtBirthActionField		=	document.getElementById('txtBirthAction');
		if(txtBirthActionField)
		{
			txtBirthActionValue	=	txtBirthActionField.value;
		}
		var txtDeathActionField		=	document.getElementById('txtDeathAction');
		if(txtDeathActionField)
		{
			txtDeathActionValue	=	txtDeathActionField.value;
		}
		var txtSpouseChangeAllField	=	document.getElementById('txtSpouseChangeAll');
		if(txtSpouseChangeAllField)
		{
			txtSpouseChangeAllValue	=	txtSpouseChangeAllField.value;
		}
		var txtChildChangeAllField	=	document.getElementById('txtChildChangeAll');
		if(txtChildChangeAllField)
		{
			txtChildChangeAllValue	=	txtChildChangeAllField.value;
		}
		
		if((txtPersonActionValue		==	'TRUE')	||
			(txtNameActionValue			==	'TRUE')	||
			(txtBirthActionValue		==	'TRUE')	||
			(txtDeathActionValue		==	'TRUE')	||
			(txtSpouseChangeAllValue	==	'TRUE')	||
			(txtChildChangeAllValue		==	'TRUE'))
		{
			fgfChanged	=	true;
		}
						
		
		// submit
		if(fgfChanged	==	true)
		{
			document.frmFGF.submit();
		}

	}

//////////////////////////////////////////////////////////////////////////////////////////////////


//End
//-->


/* ============================================================================================*/
/*
This function focuses a new person on FGF.
*/
/* ============================================================================================*/

var setPersonVariables = function(id,name,gender)
{
	// set proxy information
	var fgfFunctions	=	new fgfFunctionsProxy();
	fgfFunctions.setHTTPMethod("GET");
	fgfFunctions.setReturnFormat("PLAIN");

	fgfFunctions.setPersonVariables(id,name,gender);
};

/* ============================================================================================*/
/*
This function focuses a new person on FGF.
*/
/* ============================================================================================*/

var focusThisPerson = function(idPerson,isParentWindow,isNewPerson,path_FGF)
{
	var jsIdPerson			=	idPerson;
	if (isNewPerson)
	{
		var jsIsNewPerson	=	isNewPerson;
	}
	else
	{
		var jsIsNewPerson	=	0;
	}

	if (path_FGF)
	{
		var jsPath_FGF	=	path_FGF + '/fgfMain.cfm';
	}
	else
	{
		var jsPath_FGF	=	'https://www.ages-online.com/application/fgf/fgfMain.cfm';
	}


	// set proxy information
	var refocus	=	new fgfFunctionsProxy();
	refocus.setHTTPMethod("POST");
	refocus.setReturnFormat("PLAIN");
	refocus.focusThisPerson(jsIdPerson,jsIsNewPerson);
	
	if ((isParentWindow)	&&	(isParentWindow	==	1))
	{
		window.opener.location.pathname	=	jsPath_FGF;
	}
	else
	{
		location.href	=	jsPath_FGF	;
	}
};

/* ============================================================================================*/
/*
This function validates data fields on FGF.
*/
/* ============================================================================================*/

var validateFGFdata = function()
{
	// set up local variables
	var errorCode			=	0;
	var jsNumSpouses		=	0;
	var jsNumChildren		=	0;
	var jsNumSpousesField	=	document.getElementById('numSpouses');
	var jsNumChildrenField	=	document.getElementById('numChildren');
	var dateFrom			=	'';
	var dateTo				=	'';
	var dateCertainty		=	'';
	
	if(jsNumSpousesField)
	{
		jsNumSpouses		=	jsNumSpousesField.value;
	}
	if(jsNumChildrenField)
	{
		jsNumChildren		=	jsNumChildrenField.value;
	}
	
	// validate focus person birth dates
	errorCode			=	validateDates('txtBD_IdDetail_Date_Certainty_Type','txtBD_Detail_Date','txtBD_Detail_Date_To','Birth Date', 'Birth Date To');
	
	if(errorCode === 0)
	{
		// validate focus person death date from field
		errorCode		=	validateDates('txtDD_IdDetail_Date_Certainty_Type','txtDD_Detail_Date','txtDD_Detail_Date_To','Death Date', 'Death Date To');
	}
	
	// validate spouse marriage dates
	if((errorCode === 0) && (jsNumSpouses > 0))
	{
		for(i = 1; i <= jsNumSpouses; i++)
		{
			dateField	=	document.getElementById(i);
			if((dateField) && (dateField.value > ''))
			{
				errorCode	=	validateDateField(1,dateField.value);
			}
			if(errorCode > 0)
			{
				break;
			}
		}
	}
	
	// validate children birth dates
	if((errorCode === 0) && (jsNumChildren > 0))
	{
		for(i = 1; i <= jsNumChildren; i++)
		{
			dateField	=	document.getElementById('txtChild_BirthDate[' + i + ']');
			if((dateField) && (dateField.value > ''))
			{
				errorCode	=	validateDateField(1,dateField.value);
			}
			if(errorCode > 0)
			{
				break;
			}
		}
	}

	// if no errors, submit form
	if(errorCode === 0)
	{
		populateDateTimeFields('txtDateTime');
		document.frmFGF.submit();
	}
};

/* ============================================================================================*/
/*
This function populates the Loc State/Provinces, for the Census source type in the Source and 
Citation pages, based on the selection in the Country dropdown box.
*/
/* ============================================================================================*/

var getFGFStateProvinces = function(jsStatesByCountry,jsIdCountry,jsLocCountry,jsIdDetailType)
{
	// set variables for the birth or death fields to be populated
	var countryField = '';
	var stateProvinceField = '';
	
	if(jsIdDetailType == 14)
	{
		countryField = 'txtBD_Country';
		stateProvinceField = 'txtBD_State';
	}
	else
	{
		countryField = 'txtDD_Country';
		stateProvinceField = 'txtDD_State';
	}
	
	// set country hidden field
	if(jsLocCountry)
	{
		var numCountries = jsLocCountry.length;
		for(i=0;i<numCountries;i++)
		{
			if(jsLocCountry[i][0] == jsIdCountry)
			{
				document.getElementById(countryField).value = jsLocCountry[i][1];
				break;
			}
		}
	}
	
	// get Loc State/Province dropdown box
	var stateOptions = document.getElementById(stateProvinceField);
	stateOptions.options.length = 0;
	
	// set first option to Select
	var newOption=document.createElement('option');
	newOption.value='';
	newOption.text='Select';
	try
	{
		stateOptions.add(newOption,null); // standards compliant
	}
	catch(ex)
	{
		stateOptions.add(newOption); // IE only
	}

	// set second option to dashes
	newOption=document.createElement('option');
	newOption.value='';
	newOption.text='-----';
	try
	{
		stateOptions.add(newOption,null); // standards compliant
	}
	catch(ex)
	{
		stateOptions.add(newOption); // IE only
	}

	if (jsStatesByCountry)
	{
		for(var i=0;i<jsStatesByCountry.length;i++)
		{
			newOption=document.createElement('option');
			newOption.value=jsStatesByCountry[i];
			newOption.text=jsStatesByCountry[i];
			try
			{
				stateOptions.add(newOption,null); // standards compliant
			}
			catch(ex)
			{
				stateOptions.add(newOption); // IE only
			}
		}
	}
	
};

/* ============================================================================================*/
/*
This function updates change hidden field variables for spouses or children.
Inputs:	fieldId			-	Individual field to update
		fieldValue		-	Value to update individual field
		spouseOrChild	-	"Spouse" if updating spouse fields, "Child" if updating child fields.
		rowNumber		-	Indicates which spouse or child was updated in the list
*/
/* ============================================================================================*/

var updateChangeFields = function(fieldId,fieldValue,spouseOrChild,rowNumber)
{
	// update individual field
	setHiddenField(fieldId,fieldValue);
	
	// update spouse or child change fields
	if(spouseOrChild		==	'Spouse')
	{
		// set spouse row change field
		var spouseIndividualField	=	'txtSpouseChange[' + rowNumber + ']';
		setHiddenField(spouseIndividualField,fieldValue);
		
		// set spouse overall change field
		setHiddenField('txtSpouseChangeAll',fieldValue);
	}
	else if (spouseOrChild	==	'Child')
	{
		var childIndividualField	=	'txtChildChange[' + rowNumber + ']';
		setHiddenField(childIndividualField,fieldValue);
		
		// set spouse overall change field
		setHiddenField('txtChildChangeAll',fieldValue);
	}
	
};

/* ============================================================================================*/
/*
This function calls a Coldfusion function to update idFamily_Unit and idOtherParent based on
clicking a spouse radio button on FGF.  This function will then call validateFGFdata to 
validate date fields and save the data on FGF.

Inputs:	idFamily_Unit	-	the new idFamily_Unit based on the selected spouse
		idOtherParent	-	the idPerson of the selected spouse
*/
/* ============================================================================================*/

var selectSpouse = function(idFamily_Unit,idOtherParent)
{
	// set proxy information
	var fgfFunctions	=	new fgfFunctionsProxy();
	fgfFunctions.setHTTPMethod("POST");
	fgfFunctions.setSpousalFamilyVariables(idFamily_Unit,idOtherParent);
	
	// validate, save and refresh FGF
	validateFGFdata();
};

