/* origincrafts.com */

jQuery.noConflict();

function awpUpdatePrice () {

	var price = jQuery("#orderPrice").attr("value");
	var quantity = jQuery("#vwquantity").attr("value");
	var selectElems, selectValue, selectPriceStart, selectPriceEnd, selectPrice;

	if ((typeof quantity == 'undefined') || (quantity == '') || (quantity.indexOf(' ') >= 0)) {
		quantity = 0;
	}

	selectElems = jQuery(".orderOptionSelect").get();
	for (var i=0;i<selectElems.length;i++) {
		if (selectElems[i].selectedIndex != -1) {
			selectValue = selectElems[i].options[selectElems[i].selectedIndex].value;
			selectPriceStart = selectValue.indexOf("(+");
			if ((selectPriceStart != -1) && (selectValue.indexOf("(+0") == -1)) {
				selectPriceEnd = selectValue.indexOf(")", selectPriceStart);
				if (selectPriceEnd != -1) {
					selectPrice = selectValue.substring(selectPriceStart + 2, selectPriceEnd);
					price = (price * 1) + (selectPrice * 1);
				}
			}
		}
	}

	price = price * quantity;
	jQuery("#orderPriceDisplay").html(price.toFixed(2));

}

jQuery(document).ready(function() {
	jQuery("#vwquantity").change(awpUpdatePrice);
	jQuery("#vwquantity").bind("keyup", awpUpdatePrice);
	jQuery(".orderOptionSelect").change(awpUpdatePrice);
	jQuery("#join-mailing-list-form").validate({
		'rules': {
			'email': {
				'required': true,
				'email': true
			},
			'name': {
				'required': true
			}
		},
		'messages': {
			'email': "Please enter a valid email address"
		}
	});
	jQuery("#contact-us-form").validate({
		'rules': {
			'email': {
				'required': true,
				'email': true
			},
			'FirstName': {
				'required': true
			},
			'LastName': {
				'required': true
			},
			'InquiryText': {
				'required': true
			}
		},
		'messages': {
			'email': "Please enter a valid email address"
		}
	});
});
