function calPrice() {
	var myForm = _('frmAutoSys');
	if(checkAutoSysInput(myForm)) {
		var txtPrice = _('txt_quotedPrice');
		var thisPrice = 0;
		var materialPrice = 1;
		var materialType = 2;
		
		var material = $('#selMaterial').val().split("@@@");
		materialPrice = material[1];
		materialType = material[2] == "Y" ? 1 : 2;
		materialPrice = Math.ceil(materialPrice);
		var selHeight = $('#selHeight').val();
		var selWidth = $('#selWidth').val();
		var selUnit = $('#selUnit').val();
		var selQty = $('#selQty').val();
		
		if(materialType == "1") {
			thisPrice = materialPrice * parseFloat(selQty);
		} else {
			thisPrice = parseFloat(selWidth * parseFloat(selHeight) * materialPrice);
			if(selUnit == "2") {
				thisPrice /= 144;
			} else if (selUnit == "3") {
				thisPrice /= 900;
			}
			thisPrice = Math.ceil(thisPrice);
			if (thisPrice < 10)
				thisPrice = 10 * parseFloat(selQty);
			else
				thisPrice = thisPrice * parseFloat(selQty);
		}
		_('txt_quotedPrice').style.backgroundColor = "#FFFFFF";
		_('txt_quotedPrice').style.color = "#0000FF";
		_('txt_quotedPrice').innerHTML = "HK$ "+number_format(Math.ceil(thisPrice),0);
	}
}

function showPprice(theight, prices){
	if(_('txt_quotedPrice').offsetHeight<theight){
		var hei = _('txt_quotedPrice').offsetHeight+2;
		_('txt_quotedPrice').style.height=hei+"px";
		setTimeout("showPrice(" + theight + ",'"+prices+"')", 100);
	}else{
		_('txt_quotedPrice').style.height = theight + "px";
		_('txt_quotedPrice').innerHTML = prices;
	}
}

function checkAutoSysInput(myForm) {
	var material = $('#selMaterial').val().split("@@@");
	var materialType = material[2] == "Y" ? 1 : 2;
	if ($('#selMaterial').val().Trim() == "") {
		alert("請選擇物料 \n Please select Material");	
		return false;
	}else if ($('#selWidth').val().Trim() == "" && materialType == '2') {
		alert("請選擇橫度 \n Please select Width");
		selWidth.focus();
		return false;
	}else if ($('#selHeight').val().Trim() == "" && materialType == '2') {
		alert("請選擇高度 \n Please select Height");	
		selHeight.focus();
		return false;
	}else if ($('#selQty').val().Trim() == "") {
		alert("請選擇數量 \n Please select Quantity");
		selQty.focus();
		return false;
	}
	return true;
}

function retrieveMType(obj) {
	var myForm = obj.form;
	var material = obj.value.split("@@@");
	var materialType = material[2];
	
	if (materialType == "1") {
		myForm.selWidth.disabled = "disabled";
		myForm.selHeight.disabled = "disabled";
		myForm.selUnit.disabled = "disabled";
		myForm.selQty.focus();
	} else {
		myForm.selWidth.disabled = "";
		myForm.selHeight.disabled = "";
		myForm.selUnit.disabled = "";
	}
}

function submit_to_quick(){
	var myForm = _('frmAutoSys');
	myForm.action = 'quick_order.php';
}
