/* contact form */
var globalZIndex = 200;
function checkForm(form) {
	var els = form.getElementsByTagName('*');
	var inps = {};
	var requiredField = false;
	for (var i = 0, j = els.length; i < j && !requiredField; i++)
		if (els[i].offsetWidth > 0) with (els[i])
			if (tagName && (tagName.toLowerCase() === 'input' || tagName.toLowerCase() === 'select' || tagName.toLowerCase() === 'textarea')) {
				if (getAttribute('type') && getAttribute('type').toLowerCase() === 'checkbox') {
					inps[getAttribute('name')] = checked;
				} else {
					inps[getAttribute('name')] = value;
				}
				if (className.match(/\brequired\b/i) && (!inps[getAttribute('name')] ||
				  els[i].value === els[i].defaultValue)) requiredField = els[i];
			}
	if (requiredField) {
		requiredField.focus();
		var showHint = true;
		for (var i = 0, j = els.length; i < j; i++) if (els[i].className.match(/\brequiredHint\b/)) showHint = false;
		if (showHint) with (requiredField.parentNode) {
			var anchor = document.createElement('div');
			anchor.className = 'requiredHintAnchor';
			anchor.style.zIndex = globalZIndex++;
			var a = document.createElement('div');
			a.className = 'requiredHint';
			a.appendChild(document.createTextNode('Please fill in this required field'));
			var b = document.createElement('div');
			a.appendChild(b);
			a.onmouseout = function () { this.parentNode.removeChild(this); }
			anchor.appendChild(a);
			appendChild(anchor);
		}
		return false;
	}
	return true;
}

function initDeliverSelect() {
	var deliveryLocationType = SC.$('deliveryLocationType');
	if (deliveryLocationType)
		SC.addEvt(deliveryLocationType, 'change', function(e) {
			var tgt = SC.getTarget(e),
			    otherInput = SC.$('otherLocationInput');
			if (tgt && otherInput && /^Other$/i.test(tgt.value)) {
				SC.removeClass(otherInput, 'hidden');
			} else SC.addClass(otherInput, 'hidden');
		});
};
