// yay, let's deal with MySql date types, at least a little bit...
// NOTE: supports only default date formatting YYYY-MM-DD HH:MM:SS or YY-MM-DD HH:MM:SS
mysqlDateToJsDate = function(inMysqlDateTime, inDateDelim, inTimeDelim) {
	var dt = inMysqlDateTime.split(' '), d = dt[0], t = dt[1], r;
	d = d&&d.split(inDateDelim||'-');
	t = t&&t.split(inTimeDelim||':');
	if (d && d.length == 3) {
		r = new Date();
		r.setYear(d[0]);
		r.setMonth(parseInt(d[1])-1);
		r.setDate(d[2]);
	}
	if (t && t.length == 3) {
		r = r || new Date();
		r.setHours(t[0]);
		r.setMinutes(t[1]);
		r.setSeconds(t[2]);
	}
	return r || new Date(inMysqlDateTime);
}

jsDateToMySqlDate = function(inDate) {
	var
		d = new Date(inDate),
		y = d.getFullYear(),
		m = dojo.string.pad(d.getMonth() + 1),
		dd = dojo.string.pad(d.getDate())
	return dojo.string.substitute("${0}-${1}-${2}",[y, m, dd]);
};

// custom simple MySql date formatter
formatMySqlDate = function(inDatum) {
	return inDatum != dojox.grid.na ? dojo.date.locale.format(mysqlDateToJsDate(inDatum), this.constraint) : dojox.grid.na;
}

// custom simple MySql date editor
dojo.declare("mySqlDateEditor", dojox.grid.editors.DateTextBox, {
	format: function(inDatum, inRowIndex){
		inDatum = mysqlDateToJsDate(inDatum);
		return this.inherited(arguments, [inDatum, inRowIndex]);
	},
	getValue: function(inRowIndex){
		var v = this.editor.attr('value'), fv = jsDateToMySqlDate(v);
		return fv;
	}
});

function waitMessage() {
	alert('Edit in progress, please wait.');
}

function getDefaultRow(id) {
	return ['0',id, '','0','','0' ];
}
function addRow(id) {
	if(model.canModify()||model2.canModify()){
		inRowIndex=1
		grid.addRow(getDefaultRow(id));
	}else{
		waitMessage();
	}	
}

function removeSelected(id){
	if(model2.canModify() ||model.canModify()){
		if(id==2)
		{grid2.removeSelectedRows();}
		else{grid.removeSelectedRows();}
	}else{
		waitMessage();
	}
}