// callbacks.js
// Insert custom javascript code inside these functions

//
// Editor callbacks
//

// On Editor Pull
// called when editor retreives the record from the backend
//
// for current xmlRecord schema and sample xml, take a look at the Backend Calls / Query Calls / GetRecord command in DAX documentation
function callback_onEditorPull (selectionName, xmlRecord)
{

	// custom code starts here
	
	/*
	
	// get reference to field elements
	var result = xmlRecord.responseXML.getElementsByTagName("queryResult").item(0);
	var row = result.getElementsByTagName('row').item(0);
	var fields = row.getElementsByTagName('field');
	
	// loop through fields
	for (l = 0; l < fields.length; l++) {
		// check if field contains social security number, and if it does, mask it
		if (getField(selectionName, fields[l].getAttribute('id')).fieldname == 'Person_ID')
			fields[l].textContent = 'XXX-XX-XXXX';
	}

	// custom code ends here
	
	*/
	
	// return the xml reply back to the DAX
	return xmlRecord;

}


// On View Query
// called when grid, calendar, or tree view query for multiple records
//
// for current xmlRecord schema and sample xml, take a look at the Backend Calls / Query Calls / Query command in DAX documentation
// viewType can be 'calendar', 'grid', 'datatree'
function callback_onViewQuery (selectionName, xmlRecord, viewType)
{

	// custom code starts here
	
	/*
	
	// get reference to field elements
	var result = xmlRecord.responseXML.getElementsByTagName("queryResult").item(0);
	var rows = result.getElementsByTagName('row');
	
	// loop through rows
	for (k = 0; k < rows.length; k++) {
		// loop through fields
		var fields = rows[k].getElementsByTagName('field');
		for (l = 0; l < fields.length; l++) {
			// check if field contains social security number, and if it does, mask it
			if (getField(selectionName, fields[l].getAttribute('id')).fieldname == 'Name')
				fields[l].textContent = fields[l].textContent.substr(0,1);
		}
	}
	
	*/

	// custom code ends here	
	
	// return the xml reply back to the DAX
	return xmlRecord;

}


function callback_beforeRecordSave(selectionName, recordId, recordData)
{

	// custom code starts here


	// custom code ends here

	//return data array back to the DAX
	return recordData;
}


// After Record Save Success 
// called when record is saved successfully
//
function callback_afterRecordSaveSuccess (selectionName, recordId)
{

	// custom code starts here

	/*
	
		alert ('Record ' + recordId + ' from ' + selectionName + ' saved successfully.');

	*/
	
	// custom code ends here	

}

// On Login Success
// called after user is logged in successfully
//
function callback_onLoginSuccess (username)
{
	// custom code starts here

	/*
	
		alert ('Welcome, ' + username + '.');

	*/
	
	// custom code ends here	
}

// Error handler
function fourdaf_dev_errorTrap (hint, message) 
{


}
