<!-- // JavaScript Document
//							:::::::::::::::::::::::::::::::::::::::
//								Support page for fgfMain.cfm
//							:::::::::::::::::::::::::::::::::::::::



window.onload=montre;		
window.name = "winMain";
//////////////////////////////////////////////////////////////////////////////////////////////////

function clearForm()
{
window.open(fgfMainAct.cfm);	
}

//////////////////////////////////////////////////////////////////////////////////////////////////
	
	function update()
	{
		//var vAddress1 = fClean(document.frmAddress.txtAddress1.value);

		//submit
		document.frmFEF.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	=	'/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.frmFEF.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
			}
		}
	}
	
};

