<?php
	require_once '../../../library_html/base/comm/send_data.php';
?>

<script>

function acc_ins_ent_submit() {
    var day = $('#acc-ins-ent-day')[0].value;
    var from = $('#acc-ins-ent-from')[0].value.substr(0,8);
    var to = $('#acc-ins-ent-to')[0].value.substr(0,8);
    var ammount = $('#acc-ins-ent-ammount')[0].value;
    var descr = $('#acc-ins-ent-description')[0].value;
    send_data('acc_insert_entry', {day: day, from: from, to: to, ammount: ammount, description: descr});
}

function acc_ins_ent_cancel(data) {
    $('#acc-ins-ent-day')[0].value = data;
    $('#acc-ins-ent-from')[0].value = '';
    $('#acc-ins-ent-to')[0].value = '';
    $('#acc-ins-ent-ammount')[0].value = '';
    $('#acc-ins-ent-description')[0].value = '';
}

var return_text = "";

function textareaonkeydown(e) {
	if (e.keyCode == 13) {
		return_text = "";
	    var text = $('#temp-area')[0].value;
	    var ent_id = 1;
	    var pos_end = 0;
	    while (text.indexOf(');') > 0) {
	    	pos_end = text.indexOf(');');
	    	var new_line = text.substr(0, (pos_end + 1));
	    	return_text += seperate(new_line, ent_id);
	    	ent_id++;
	    	text = text.substr((pos_end + 2), (text.length - pos_end - 2));
	    }
	    $('#temp-area')[0].value = return_text;
	}
}

/*function seperate(data, ent_id) {
    var pos1 = data.indexOf(',');
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var year = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var month = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var day = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var from = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var to = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(',');
    var ammount = parseFloat(data.substr(1,pos1-1));
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));
    pos1 = data.indexOf(')');
    var description = data.substr(0,pos1);
    data = data.substr(pos1 + 2, (data.length - pos1 - 2));

    var result = '';
    var idx = 1;
    if (from != "'__NONE__'") {
    	result += 'INSERT INTO `acc_entries` VALUES(' + ent_id + ',' + idx + ',' + from + ',' + year + ',' + month + ',' + day + ',' + (ammount*-1) + ',' + description + ');\n';
    	idx++;
    }
    if (to != "'__NONE__'") {
    	result += 'INSERT INTO `acc_entries` VALUES(' + ent_id + ',' +idx + ',' + to + ',' + year + ',' + month + ',' + day + ',' + ammount + ',' + description + ');\n';
    }
    return result;
}*/

</script>
<!--<textarea onkeydown="textareaonkeydown(event);" id="temp-area" style="width:95%; height:400px;">

</textarea>-->