// JavaScript Document

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	}
	else {
		return true;
	}
}

function clearText(field){
			if (field.defaultValue == field.value) field.value = '';
			else if (field.value == '') field.value = field.defaultValue;
		}


function colourSearch(colour) {
	document.getElementById('var_value').value = colour;
	document.var_search.submit();
}

function loadAttributeOptions () {
	var attribute_id = $('attribute_id').value;
	url = 'shop/ajaxgetattribute/'+attribute_id;
	new Ajax.Request(url, {
		method:'get',
		onFailure: function(){ alert('Something went wrong... at '+url)},
		onSuccess: function (oReq, oJSN) {
						var options = eval(oReq.responseText);
						clearOptions($('attribute_options'));
						addSelectOption($('attribute_options'), " - Attribute Option - ", 0);
						for (var i=0; i<options.length; i++) {
							//all_categories[categories[i].category_id] = categories[i];
							addSelectOption($('attribute_options'), options[i], options[i]);
						}
					}
	});
}

function addSelectOption(selectObj, text, value) {
	if (selectObj != null && selectObj.options != null)	{
		selectObj.options[selectObj.options.length] = new Option(text, value);
	}
}

function clearOptions(selectObj) {
	selectObj.options.length = 0;
}