function recorder() {
	'use strict';
	//Recording a record
	//This function will read HTML and then call database function to save it
	//Read HTML parameters
	var number = document.getElementById('recordNumber').innerHTML;
	var date = DOMReader('Date');
	var name = DOMReader('Name');
	var part = DOMReader('Part');
	var printNumber = DOMReader('PrintNumber');
	var partNumber = DOMReader('PartNumber');
	var description = DOMReader('Description');
	var material = DOMReader('Material');
	var process = DOMReader('Process');
	var note = DOMReader('Note');
	var photo = GRAND['pb'].join(',');
	var related = DOMReader('Related');
	//Process database
	var date = date.substr(0,4) + date.substr(5,2) + date.substr(8,2); //Tanslate into database function time format
	if (/[^0-9]/.test(number)) { //Record Number could only be number, if not (HTML for new record says 'N/A'), that means this is a new record
		var databaseParameter = date; //Database function parameter 'record'
	}
	else var databaseParameter = date + number; //Old record
	database('write',databaseParameter,[name,part,printNumber,partNumber,description,material,process,note,photo,related]); //Call database to write
	//Process Photo logs
	GRAND['pbDel'].map(function(x){GRAND['fs'].unlinkSync(x);}); //Unlink all files should be delete
	GRAND['pbAdd'].splice(0,GRAND['pbAdd'].length); //Those photo are already added into libeary, so, ignor them
	GRAND['pbDel'].splice(0,GRAND['pbDel'].length);
	console.log('SUCCESS, photo files processed');
	//Update index buffer
	var monthAgo = new Date(Date.now()-2592000000).toJSON();
	var timeFormat = monthAgo.substr(0,4) + monthAgo.substr(5,2) + monthAgo.substr(8,2);
	document.getElementsByTagName('main')[0].innerHTML = 'Refereshing index buffer...';
	index(timeFormat,'','','','','','');
	pageloader('index'); //Return to index page
	return true;
	function DOMReader(HTMLId) { //Read HTML elements
		return document.getElementById('record'+HTMLId).value;
	}
}

function recordPrintPreview() {
	'use strict';
	//This function is used to load the Print (Blueprint) previewer in recorder table
	var value = document.getElementById('recordPrintNumber').value; //Get print number
	var fileName = 'database/print/' + value; //Target print number file name
	if (GRAND['fs'].existsSync(fileName) && /[A-Za-z0-9]/.test(value)) { //If print in database
		document.getElementById('recordPrintPreview').innerHTML = '<img onclick="mask(\''+ fileName +'\')" src="' + fileName + '" />'; //Shown that print
	}
	else document.getElementById('recordPrintPreview').innerHTML = '<img onclick="mask(\'app/buleprint.png\')" src="app/buleprint.png" />'; //If not, show error picture
}

function recordPhotoUpload() {
	'use strict';
	//This function is used to upload photo
	var files = document.getElementById('recordPhotoUpload').value.split(';'); //Get new upload photo
	console.log('Import file: '+files);
	var fileNumber = files.length;
	for (var i = 0; i < fileNumber; i++) {
		var data = GRAND['fs'].readFileSync(files[i]); //Read file
		do {
			var fileName = 'database/photo/' + new Date().toJSON().substr(0,10) + '-' + Math.floor(Math.random()*900000000+100000000); //Genarete a name
		} while (GRAND['fs'].existsSync(fileName)) //If name already exist, try again
		GRAND['fs'].writeFileSync(fileName,data); //Write file to photo libeary
		GRAND['pbAdd'].push(fileName); //Log this action, if revert, delete files in this array
		GRAND['pb'].push(fileName); //Push the name into current photo workspace
	}
	console.log('Files imported');
	document.getElementById('recordPhoto').innerHTML = GRAND['pb'].map(function(x){return '<a onclick="recordPhotoDelete(\'' + x + '\')"><img src="' + x + '" /></a>';}).join(''); //Photo workspace to HTML code
	console.log('SUCCESS, files imported to buffer');
	return true;
}

function recordPhotoDelete(fileName) {
	'use strict';
	//This function is used to delete a photo
	GRAND['pbDel'].push(fileName); //Log this action, delete files if submit
	var index = GRAND['pb'].indexOf(fileName);
	GRAND['pb'].splice(index,1); //Delete that photo in photo workspace buffer
	document.getElementById('recordPhoto').innerHTML = GRAND['pb'].map(function(x){return '<a onclick="recordPhotoDelete(\'' + x + '\')"><img src="' + x + '" /></a>';}).join(''); //Photo workspace to HTML code
	console.log('SUCCESS, file delete from buffer');
	return true;
}
