var pricecalc = {
	calc_cb: function (res, status, headers) {
		if (200 != status) return;
		if (0 == res.length) return;
		var val = res.split('\t');
		if (3 != val.length) return;
		var price = $('price');
		var width = $('width');
		var height = $('height');
		width.value = ''+val[0];
		height.value = ''+val[1];
		price.innerHTML = val[2];
	},

	valueChange: function (evt) {
		evt = util.uni_event(evt, true);
		var width = $('width');
		var height = $('height');
		var prod = $('prod');
		if (evt && evt.which) {
			if (34 > evt.which || 122 < evt.which) return;
		}
		if (0 < width.value.length && 0 < height.value.length && 0 != prod.selectedIndex) {
			channel.send(false, '/_/pricecalc?pricecalc=1&prod=prod'+prod.selectedIndex+'&width='+width.value+'&height='+height.value, 'GET', pricecalc.calc_cb, false);
		}
	},

	onReady: function () {
		// show pricecalc
		var pcf = $('pricecalcForm');
		if (pcf) {
			pcf.style.display = 'block';
			var width = $('width');
			var height = $('height');
			var prod = $('prod');
			if (width && height && prod) {
				util.add_event( width, 'keyup', function(evt) { pricecalc.valueChange(evt); } );
				util.add_event( height, 'keyup', function(evt) { pricecalc.valueChange(evt); } );
				util.add_event( prod, 'change', function(evt) { pricecalc.valueChange(evt); } );
			}
		}
	}
};
util.add_event(window, 'load', pricecalc.onReady);
