window.onload = function() {
	core_onLoad();
	core_admin_onLoad();
	commerce_products_onLoad();
}

/* files/javascript/core.js */

if(window.XMLHttpRequest) {
	var xmlHTTP = new XMLHttpRequest();
}
else {
	var xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP');
}

var variationFields = new Array(), processRunning = null;

if(window.location.pathname == '/about-us/contact-us' || window.location.pathname == '/find-us') {
	document.write('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAwAIMDuPOGdUZWhAt4eBOHhTXOZqWhC-bpkvu8y7veLDZLhVLgxSVNGadIncBEv8KpZ-lwxDo2HJ4zQ"><\/script>');
}

function core_onLoad() {
	if(headingContainer = document.getElementById('headinglarge')) {
		headerImage = headingContainer.getElementsByTagName('img');
		new imagePreloader([headerImage[0].src], headingLoaded);
	}
	setFilterActions();
	setVariationActions();
	setReviewActions();
	setRatingActions();
	setBasketActions();
	checkoutLogin();
	searchAddresses();
	checkoutJoin();
	checkoutDelivery();
	checkoutPayment();
	competitionSignUp();
	magazineIndex();
	viewerFunctions();
	footerNewsletter();
	
	var contactMap = false, findUsMap = false;
	if((contactMap = document.getElementById('contactmap')) || (findUsMap = document.getElementById('findusmap'))) {
		var storeIcon = new GIcon();
		storeIcon.image = '/_files/images/core/icons/map_pointer.png';
		storeIcon.shadow = '/_files/images/core/icons/map_pointer_shadow.png';
		storeIcon.iconSize = new GSize(57, 88);
		storeIcon.shadowSize = new GSize(102, 88);
		storeIcon.iconAnchor = new GPoint(29, 82);
		storeIcon.infoWindowAnchor = new GPoint(0, 0);
		var storeMarker = new GMarker(new GLatLng(53.393643,-1.43245), {icon: storeIcon})
	}
	if(contactMap = document.getElementById('contactmap')) {
		if(GBrowserIsCompatible()) {
			var map = new GMap2(contactMap);
			map.setCenter(new GLatLng(53.393643,-1.43245), 16);
			map.addOverlay(storeMarker);
			map.addControl(new GSmallMapControl());
		}
	}
	if(findUsMap = document.getElementById('findusmap')) {
		if(GBrowserIsCompatible()) {
			var map = new GMap2(findUsMap);
			map.setCenter(new GLatLng(53.393643,-1.43245), 16);
			map.addOverlay(storeMarker);
			map.addControl(new GSmallMapControl());
			GEvent.addListener(storeMarker, 'click', function() {
				map.openInfoWindowHtml(storeMarker.getLatLng(), '<img src="/_files/images/core/logos/maplogo.png" width="190" height="39" alt="Accelerate" /><div style="height: 80px;margin-top: 8px;color: rgb(0,0,0);"><div style="height: 12px;">Accelerate UK</div><div style="height: 12px;">629 Attercliffe Road</div><div style="height: 12px;">SHEFFIELD</div><div style="height: 12px;">S9 3RD</div><div style="height: 12px; margin-top: 8px;">Call us on 0845 862 0276</div><div style="height: 12px;">Send us an e-mail to <a href="mailto:hello@accelerateuk.com" title="send us an e-mail to hello@accelerateuk.com">hello@accelerateuk.com</a></div></div>', {pixelOffset: new GSize(20, -40)});
			});
		}
	}
}

function imagePreloader(loadImages, completeFunction) {
	this.completeFunction = completeFunction;
	
	// initialize internal state.
	this.imagesLoaded = 0;
	this.imagesProcessed = 0;
	this.loadImages = new Array;
	
	// record the number of images.
	this.imagesTotal = loadImages.length;
	
	// for each image, call preload()
	for(var imageCount = 0; imageCount < loadImages.length; imageCount++) {
		this.preload(loadImages[imageCount]);
	}
}

imagePreloader.prototype.preload = function(image) {
	var preloadImage = new Image;
	this.loadImages.push(preloadImage);
	
	preloadImage.onload = imagePreloader.prototype.onload;
	preloadImage.onerror = imagePreloader.prototype.onerror;
	preloadImage.onabort = imagePreloader.prototype.onabort;
	
	preloadImage.imagePreloader = this;
	preloadImage.imageLoaded = false;
	
	preloadImage.src = image;
}

imagePreloader.prototype.onComplete = function() {
	this.imagesProcessed++;
	if(this.imagesProcessed == this.imagesTotal) {
		this.completeFunction(this.loadImages, this.imagesLoaded);
	}
}

imagePreloader.prototype.onload = function() {
	this.imageLoaded = true;
	this.imagePreloader.imagesLoaded++;
	this.imagePreloader.onComplete();
}

imagePreloader.prototype.onerror = function() {
	this.loadError = true;
	this.imagePreloader.onComplete();
}

imagePreloader.prototype.onabort = function() {
	this.loadAbort = true;
	this.imagePreloader.onComplete();
}

function headingLoaded(loadImages, imagesTotal) {
	if(loadImages.length == imagesTotal) {
		if(headingContainer = document.getElementById('headinglarge')) {
			headingContainer.style.backgroundImage = 'none';
			headingImage = headingContainer.getElementsByTagName('img');
			showHeading(headingImage[0], 0);
		}
	}
}

function showHeading(headingImage, imageOpacity) {
	if(imageOpacity < 100) {
		imageOpacity += 5;
		headingImage.style.opacity = imageOpacity / 100;
		headingImage.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ imageOpacity +')';
		setTimeout(function() {showHeading(headingImage, imageOpacity);}, 10);
	}
}

function setFilterActions() {
	if(filterActivity = document.getElementById('filterActivity')) {
		if(filterBrand = document.getElementById('filterBrand')) {
			if(filterCategory = document.getElementById('filterCategory')) {
				if(filterGender = document.getElementById('filterGender')) {
					filterActivity.onchange = function() {
						processFilterSelection(this.value, filterBrand.value, filterCategory.value, filterGender.value, 100, false, 0, 0, true);
					}
					filterBrand.onchange = function() {
						processFilterSelection(filterActivity.value, this.value, filterCategory.value, filterGender.value, 100, false, 0, 0, false);
					}
					filterCategory.onchange = function() {
						processFilterSelection(filterActivity.value, filterBrand.value, this.value, filterGender.value, 100, false, 0, 0, false);
					}
					filterGender.onchange = function() {
						processFilterSelection(filterActivity.value, filterBrand.value, filterCategory.value, this.value, 100, false, 0, 0, false);
					}
				}
			}
		}
	}
}

function processFilterSelection(valueActivity, valueBrand, valueCategory, valueGender, listOpacity, fetchedList, currentHeight, targetHeight, activityChanged) {
	if(resultsList = document.getElementById('resultslist')) {
		if(pageListTop = document.getElementById('pagelisttop')) {
			if(pageListBottom = document.getElementById('pagelistbottom')) {
				if(listOpacity == 100 && !fetchedList) {
					document.getElementById('filterloader').style.visibility = 'visible';
				}
				else if(listOpacity == 100 && fetchedList) {
					document.getElementById('filterloader').style.visibility = 'hidden';
				}
				if(listOpacity > 0 && !fetchedList) {
					listOpacity -= 5;
					if(activityChanged) {
						if(activityHeading = document.getElementById('activityheading')) {
							activityHeading.style.opacity = (listOpacity / 100);
							activityHeading.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
						}
					}
					resultsList.style.opacity = (listOpacity / 100);
					resultsList.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					pageListTop.style.opacity = (listOpacity / 100);
					pageListTop.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					pageListBottom.style.opacity = (listOpacity / 100);
					pageListBottom.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					setTimeout(function() {processFilterSelection(valueActivity, valueBrand, valueCategory, valueGender, listOpacity, fetchedList, currentHeight, targetHeight, activityChanged);}, 10);
				}
				else if(!fetchedList) {
					if(activityChanged) {
						if(activityHeading = document.getElementById('activityheading')) {
							switch(valueActivity) {
								case '3':
									activityHeading.className = 'swatch_bluedrk_border';
									activityHeading.childNodes[0].style.width = '183px';
									activityHeading.childNodes[0].style.backgroundPosition = '-132px 0px';
								break;
								case '4':
									activityHeading.className = 'swatch_bluelgt_border';
									activityHeading.childNodes[0].style.width = '250px';
									activityHeading.childNodes[0].style.backgroundPosition = '-315px 0px';
								break;
								case '10':
									activityHeading.className = 'swatch_red_border';
									activityHeading.childNodes[0].style.width = '276px';
									activityHeading.childNodes[0].style.backgroundPosition = '-565px 0px';
								break;
								default:
									activityHeading.className = 'swatch_orange_border';
									activityHeading.childNodes[0].style.width = '132px';
									activityHeading.childNodes[0].style.backgroundPosition = '0px 0px';
								break;
							}
						}
					}
					xmlHTTP.open('POST', '/_action/local/products/list_filter_products', false);
					xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xmlHTTP.send('productInclude=product_list_item&noneInclude=product_list_noitems&filterActivity='+ valueActivity +'&filterBrand='+ valueBrand +'&filterCategory='+ valueCategory +'&filterGender='+ valueGender);
					fetchedList = true;
					currentHeight = resultsList.offsetHeight;
					resultsList.innerHTML = xmlHTTP.responseText;
					targetHeight = resultsList.offsetHeight;
					resultsList.style.height = currentHeight +'px';
					xmlHTTP.open('POST', '/_action/local/products/list_filter_pages', false);
					xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xmlHTTP.send('selectedInclude=list_page_selected&pageInclude=list_page&filterActivity='+ valueActivity +'&filterBrand='+ valueBrand +'&filterCategory='+ valueCategory +'&filterGender='+ valueGender);
					pageListTop.innerHTML = xmlHTTP.responseText;
					pageListBottom.innerHTML = xmlHTTP.responseText;
					setTimeout(function() {processFilterSelection(valueActivity, valueBrand, valueCategory, valueGender, listOpacity, fetchedList, currentHeight, targetHeight, activityChanged);}, 10);
				}
				else if(currentHeight != targetHeight && fetchedList) {
					if(currentHeight > targetHeight) {
						currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
					}
					else {
						currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
					}
					resultsList.style.height = currentHeight +'px';
					setTimeout(function() {processFilterSelection(valueActivity, valueBrand, valueCategory, valueGender, listOpacity, fetchedList, currentHeight, targetHeight, activityChanged);}, 10);
				}
				else if(listOpacity < 100 && fetchedList) {
					listOpacity += 5;
					if(activityChanged) {
						if(activityHeading = document.getElementById('activityheading')) {
							activityHeading.style.opacity = (listOpacity / 100);
							activityHeading.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
						}
					}
					resultsList.style.height = 'auto';
					resultsList.style.opacity = (listOpacity / 100);
					resultsList.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					pageListTop.style.opacity = (listOpacity / 100);
					pageListTop.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					pageListBottom.style.opacity = (listOpacity / 100);
					pageListBottom.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ listOpacity +')';
					setTimeout(function() {processFilterSelection(valueActivity, valueBrand, valueCategory, valueGender, listOpacity, fetchedList, currentHeight, targetHeight, activityChanged);}, 10);
				}
			}
		}
	}
}

function setVariationActions() {
	if(productQuantity = document.getElementById('_commerce_productQuantity')) {
		childFields = productQuantity.parentNode.parentNode.parentNode.childNodes;
		switch(childFields.length) {
			case 1:
				childFields[0].childNodes[1].childNodes[0].style.width = '237px';
				document.getElementById('productAdd').style.marginLeft = '0px';
			break;
			case 2:
				var selectWidth = productQuantity.parentNode.parentNode.parentNode.parentNode.offsetWidth - (childFields[0].offsetWidth + childFields[1].childNodes[0].offsetWidth + 152);
				childFields[1].childNodes[1].childNodes[0].style.width = selectWidth +'px';
				document.getElementById('productAdd').style.marginLeft = '0px';
			break;
		}
		for(fieldCount = 1; fieldCount < childFields.length; fieldCount++) {
			if(childFields[fieldCount].childNodes[1].childNodes[0].tagName.toLowerCase() == 'select') {
				variationFields[variationFields.length] = childFields[fieldCount].childNodes[1].childNodes[0];
				childFields[fieldCount].childNodes[1].childNodes[0].onchange = function() {
					processVariationSelection(this);
				}
			}
		}
	}
}

function processVariationSelection(selectionField) {
	for(fieldCount = 0; fieldCount < variationFields.length; fieldCount++) {
		if(variationFields[fieldCount] != selectionField) {
			xmlHTTP.open('POST', '/_action/commerce/products/get_variation_values', false);
			xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHTTP.send('productID='+ variationFields[fieldCount].getAttribute('productID') +'&fieldID='+ variationFields[fieldCount].getAttribute('fieldID') +'&selectField='+ selectionField.getAttribute('fieldID') +'&selectValue='+ selectionField.value);
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				var existingValue = variationFields[fieldCount].value;
				while(variationFields[fieldCount].options.length > 0) {
					variationFields[fieldCount].remove(variationFields[fieldCount].options.length - 1);
				}
				var fieldValues = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
				for(valueCount = 0; valueCount < fieldValues.length; valueCount++) {
					if(fieldValues[valueCount] == existingValue) {
						var valueIndex = valueCount;
					}
					variationFields[fieldCount].add(new Option(fieldValues[valueCount].replace(/\.5/, '½'), fieldValues[valueCount]));
					if(valueIndex != null) {
						variationFields[fieldCount].selectedIndex = valueIndex;
					}
					else {
						variationFields[fieldCount].selectedIndex = 0;
					}
				}
			}
		}
	}
}

function setReviewActions() {
	if(submitContainer = document.getElementById('submitreviewcontainer')) {
		submitContainer.style.display = 'none';
	}
	if(submitReview = document.getElementById('frmSubmitReview')) {
		submitReview.onsubmit = function() {
			var submitError = 0;
			if(document.getElementById('txtReviewerName').value == 'your name' || document.getElementById('txtReviewerName').value == '') {
				document.getElementById('txtReviewerName').className = document.getElementById('txtReviewerName').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(document.getElementById('txtReviewerEmail').value == 'your e-mail address' || document.getElementById('txtReviewerEmail').value == '') {
				document.getElementById('txtReviewerEmail').className = document.getElementById('txtReviewerEmail').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(document.getElementById('txtReviewTitle').value == 'your review title' || document.getElementById('txtReviewTitle').value == '') {
				document.getElementById('txtReviewTitle').className = document.getElementById('txtReviewTitle').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(document.getElementById('txtReviewText').value == 'your product review' || document.getElementById('txtReviewText').value == '') {
				document.getElementById('txtReviewText').className = document.getElementById('txtReviewText').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(submitError == 0) {
				if(document.getElementById('txtReviewerEmail').value.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) == -1) {
					document.getElementById('txtReviewerEmail').className = document.getElementById('txtReviewerEmail').className +' swatch_lgtorange_bg';
					submitError = 2;
				}
			}
			if(submitError > 0) {
				var currentHeight = document.getElementById('reviewerror').offsetHeight;
				switch(submitError) {
					case 1:
						document.getElementById('reviewerror').childNodes[1].innerHTML = 'Please fill out all of the fields indicated below';
					break;
					case 2:
						document.getElementById('reviewerror').childNodes[1].innerHTML = 'Please enter a valid e-mail address';
					break;
				}
				document.getElementById('reviewerror').style.opacity = 0;
				document.getElementById('reviewerror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
				var targetHeight = document.getElementById('reviewerror').offsetHeight;
				document.getElementById('reviewerror').style.height = currentHeight +'px';
				showErrorMessage(document.getElementById('reviewerror'), currentHeight, targetHeight, 0, false);
			}
			else {
				xmlHTTP.open('POST', '/_action/local/products/submit_review', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmSubmitReview&'+
					'hdnProductID='+ document.getElementById('_commerce_productID').value +'&'+
					'hdnReviewRating='+ document.getElementById('hdnReviewRating').value +'&'+
					'txtReviewerName='+ document.getElementById('txtReviewerName').value +'&'+
					'txtReviewerEmail='+ document.getElementById('txtReviewerEmail').value +'&'+
					'txtReviewTitle='+ document.getElementById('txtReviewTitle').value +'&'+
					'txtReviewText='+ document.getElementById('txtReviewText').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					showSuccessMessage(document.getElementById('submitreview'), this, 0, 0, 100, false, xmlHTTP.responseText);
				}
			}
			return(false);
		}
	}
}

function openReadReviews() {
	if(readContainer = document.getElementById('readreviews')) {
		if(linkReadReviews = document.getElementById('linkReadReviews')) {
			linkReadReviews.parentNode.style.backgroundImage = 'url(/_files/images/core/icons/bullet_vertical.png)';
		}
		xmlHTTP.open('POST', '/_action/local/products/get_product_reviews', false);
		xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlHTTP.send('productID='+ document.getElementById('_commerce_productID').value +'&listOffset=0&reviewInclude=product_review&dividerInclude=product_review_divider&starFull=product_review_starfull&starEmpty=product_review_starempty&noneInclude=product_noreviews');
		if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
			var currentHeight = readContainer.offsetHeight;
			readContainer.style.opacity = 0;
			readContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			readContainer.innerHTML = xmlHTTP.responseText;
			var targetHeight = readContainer.offsetHeight;
			readContainer.style.height = currentHeight +'px';
			showReadReviews(readContainer, currentHeight, targetHeight, 0);
		}
	}
}

function showReadReviews(readContainer, currentHeight, targetHeight, readOpacity) {
	if(currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		readContainer.style.height = currentHeight +'px';
		setTimeout(function() {showReadReviews(readContainer, currentHeight, targetHeight, readOpacity);}, 10);
	}
	else if(readOpacity < 100) {
		if(readOpacity == 0) {
			readContainer.style.height = 'auto';
		}
		readOpacity += 5;
		readContainer.style.opacity = readOpacity / 100;
		readContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ readOpacity +')';
		setTimeout(function() {showReadReviews(readContainer, currentHeight, targetHeight, readOpacity);}, 10);
	}
}

function openSubmitReview() {
	if(submitContainer = document.getElementById('submitreviewcontainer')) {
		if(customerReviews = document.getElementById('customerreviews')) {
			if(linkSubmitReview = document.getElementById('linkSubmitReview')) {
				linkSubmitReview.parentNode.style.backgroundImage = 'url(/_files/images/core/icons/bullet_vertical.png)';
			}
			var currentHeight = customerReviews.offsetHeight - 20;
			submitContainer.style.display = 'block';
			submitContainer.style.opacity = 0;
			submitContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
			var targetHeight = customerReviews.offsetHeight - 20;
			customerReviews.style.height = currentHeight +'px';
			showSubmitReview(customerReviews, submitContainer, currentHeight, targetHeight, 0);
		}
	}
}

function showSubmitReview(customerReviews, submitContainer, currentHeight, targetHeight, submitOpacity) {
	if(currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		customerReviews.style.height = currentHeight +'px';
		setTimeout(function() {showSubmitReview(customerReviews, submitContainer, currentHeight, targetHeight, submitOpacity);}, 10);
	}
	else if(submitOpacity < 100) {
		if(submitOpacity == 0) {
			customerReviews.style.height = 'auto';
		}
		submitOpacity += 5;
		submitContainer.style.opacity = submitOpacity / 100;
		submitContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ submitOpacity +')';
		setTimeout(function() {showSubmitReview(customerReviews, submitContainer, currentHeight, targetHeight, submitOpacity);}, 10);
	}
}

function showErrorMessage(errorContainer, currentHeight, targetHeight, errorOpacity, fadeBackground, completeFunction) {
	if(completeFunction == undefined) {
		completeFunction = '';
	}
	if(currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		errorContainer.style.height = currentHeight +'px';
		setTimeout(function() {showErrorMessage(errorContainer, currentHeight, targetHeight, errorOpacity, fadeBackground, completeFunction);}, 10);
	}
	else {
		if(errorOpacity == 0 && !fadeBackground) {
			errorContainer.style.height = 'auto';
			errorContainer.childNodes[0].style.height = errorContainer.offsetHeight +'px';
		}
		if(!fadeBackground) {
			if(errorOpacity < 100) {
				errorOpacity += 4;
				errorContainer.style.opacity = errorOpacity / 100;
				errorContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ errorOpacity +')';
			}
			else {
				fadeBackground = true;
			}
			setTimeout(function() {showErrorMessage(errorContainer, currentHeight, targetHeight, errorOpacity, fadeBackground, completeFunction);}, 10);
		}
		else {
			if(errorOpacity > 0) {
				errorOpacity -= 2;
				errorContainer.childNodes[0].style.opacity = errorOpacity / 100;
				errorContainer.childNodes[0].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ errorOpacity +')';
				setTimeout(function() {showErrorMessage(errorContainer, currentHeight, targetHeight, errorOpacity, fadeBackground, completeFunction);}, 10);
			}
			else {
				if(completeFunction != '') {
					eval(completeFunction);
				}
			}
		}
	}
}

function hideErrorMessage(errorContainer, currentHeight, originalHeight, errorOpacity) {
	if(errorOpacity > 0) {
		errorOpacity -= 4;
		errorContainer.style.opacity = errorOpacity / 100;
		errorContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ errorOpacity +')';
		setTimeout(function() {hideErrorMessage(errorContainer, currentHeight, originalHeight, errorOpacity);}, 10);
	}
	else {
		if(currentHeight > 5) {
			if(currentHeight == originalHeight) {
				errorContainer.childNodes[0].style.opacity = 1;
				errorContainer.childNodes[0].style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=100)';
			}
			currentHeight -= Math.ceil(currentHeight / 8);
			errorContainer.style.height = currentHeight +'px';
			setTimeout(function() {hideErrorMessage(errorContainer, currentHeight, originalHeight, errorOpacity);}, 10);
		}
		else {
			errorContainer.childNodes[1].innerHTML = '<!-- -->';
			errorContainer.style.height = 'auto';
		}
	}
}

function showSuccessMessage(reviewContainer, reviewForm, currentHeight, targetHeight, formOpacity, fadeMessage, reviewMessage) {
	if(formOpacity > 0 && !fadeMessage) {
		formOpacity -= 5;
		reviewForm.style.opacity = formOpacity / 100;
		reviewForm.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ formOpacity +')';
		setTimeout(function() {showSuccessMessage(reviewContainer, reviewForm, currentHeight, targetHeight, formOpacity, fadeMessage, reviewMessage);}, 10);
	}
	else if(formOpacity == 0 && currentHeight == 0 && targetHeight == 0) {
		var responseContainer = document.createElement('div');
		responseContainer.id = 'successmessage';
		responseContainer.innerHTML = reviewMessage;
		currentHeight = reviewContainer.offsetHeight - 5;
		while(reviewForm.childNodes.length > 0) {
			reviewForm.removeChild(reviewForm.childNodes[reviewForm.childNodes.length - 1]);
		}
		reviewForm.appendChild(responseContainer);
		targetHeight = reviewContainer.offsetHeight - 5;
		reviewContainer.style.height = currentHeight +'px';
		setTimeout(function() {showSuccessMessage(reviewContainer, reviewForm, currentHeight, targetHeight, formOpacity, fadeMessage, reviewMessage);}, 10);
	}
	else if(formOpacity == 0 && currentHeight != targetHeight) {
		fadeMessage = true;
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		reviewContainer.style.height = currentHeight +'px';
		setTimeout(function() {showSuccessMessage(reviewContainer, reviewForm, currentHeight, targetHeight, formOpacity, fadeMessage, reviewMessage);}, 10);
	}
	else if(formOpacity < 100 && fadeMessage) {
		reviewContainer.style.height = 'auto';
		formOpacity += 5;
		reviewForm.style.opacity = formOpacity / 100;
		reviewForm.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ formOpacity +')';
		setTimeout(function() {showSuccessMessage(reviewContainer, reviewForm, currentHeight, targetHeight, formOpacity, fadeMessage, reviewMessage);}, 10);
	}
}

function setRatingActions() {
	if(reviewRating = document.getElementById('reviewrating')) {
		reviewRating.setAttribute('currentRating', 0);
		var ratingStars = reviewRating.childNodes;
		for(starCount = 0; starCount < 5; starCount++) {
			ratingStars[starCount].setAttribute('starRating', (starCount + 1));
			ratingStars[starCount].onclick = function() {
				if(reviewRating.getAttribute('currentRating') != this.getAttribute('starRating')) {
					var currentRating = this.getAttribute('starRating');
				}
				else {
					var currentRating = 0;
				}
				reviewRating.setAttribute('currentRating', currentRating);
				document.getElementById('hdnReviewRating').value = currentRating;
			}
			ratingStars[starCount].onmouseover = function() {
				for(starCount = 0; starCount < 5; starCount++) {
					if(starCount < this.getAttribute('starRating')) {
						ratingStars[starCount].className = 'star full';
					}
					else {
						ratingStars[starCount].className = 'star empty';
					}
				}
			}
			ratingStars[starCount].onmouseout = function() {
				for(starCount = 0; starCount < 5; starCount++) {
					if(starCount < reviewRating.getAttribute('currentRating')) {
						ratingStars[starCount].className = 'star full';
					}
					else {
						ratingStars[starCount].className = 'star empty';
					}
				}
			}
		}
	}
}

function setBasketActions() {
	if(basketContainer = document.getElementById('basket')) {
		var selectElements = basketContainer.getElementsByTagName('select');
		for(selectCount = 0; selectCount < selectElements.length; selectCount++) {
			if(productCode = selectElements[selectCount].getAttribute('productCode')) {
				selectElements[selectCount].onchange = function() {
					xmlHTTP.open('POST', '/_action/commerce/basket/update_basket', false);
					xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xmlHTTP.send(
						'ajaxSubmit=true&'+
						'_commerce_productCode='+ this.getAttribute('productCode') +'&'+
						'_commerce_productQuantity='+ this.value
					);
					if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
						var updatedPrices = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
						document.getElementById('productPrice_'+ this.getAttribute('productCode')).innerHTML = '&pound; '+ updatedPrices[0];
						document.getElementById('netTotal').innerHTML = '&pound; '+ updatedPrices[1];
					}
				}
			}
		}
	}
	var continueShopping = false;
	if(continueShopping = document.getElementById('btnContinueShopping')) {
		continueShopping.onclick = continueShopping.onkeypress = function() {
			location.href = '/activities';
		}
	}
	var checkoutNow = false;
	if(checkoutNow = document.getElementById('btnCheckoutNow')) {
		checkoutNow.onclick = checkoutNow.onkeypress = function() {
			var pageURL = '/checkout-login';
			xmlHTTP.open('POST', '/_action/local/basket/check_session', false);
			xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHTTP.send('');
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				if(xmlHTTP.responseText == 'BASKET_EMPTY') {
					pageURL = '/activities';
				}
				if(xmlHTTP.responseText == 'SESSION_EXISTS') {
					pageURL = '/checkout-delivery';
				}
			}
			location.href = pageURL;
		}
	}
	if(saveBasket = document.getElementById('frmSaveBasket')) {
		saveBasket.onsubmit = function() {
			var submitError = 0;
			if(document.getElementById('txtSaveEmail').value == 'e-mail address' || document.getElementById('txtSaveEmail').value == '') {
				document.getElementById('txtSaveEmail').className = document.getElementById('txtSaveEmail').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(submitError == 0) {
				if(document.getElementById('txtSaveEmail').value.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) == -1) {
					document.getElementById('txtSaveEmail').className = document.getElementById('txtSaveEmail').className +' swatch_lgtorange_bg';
					submitError = 2;
				}
			}
			if(submitError == 0) {
				xmlHTTP.open('POST', '/_action/local/basket/save_basket', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmSaveBasket&'+
					'txtSaveEmail='+ document.getElementById('txtSaveEmail').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					if(xmlHTTP.responseText == 'NO_BASKET') {
						submitError = 3;
					}
					else {
						showSuccessMessage(document.getElementById('savebasket'), document.getElementById('savebasketcontent'), 0, 0, 100, false, xmlHTTP.responseText);
					}
				}
			}
			if(submitError > 0) {
				var currentHeight = document.getElementById('savebasketerror').offsetHeight;
				document.getElementById('savebasketerror').childNodes[2].innerHTML = '';
				switch(submitError) {
					case 1:
						document.getElementById('savebasketerror').childNodes[1].innerHTML = 'Please fill out your e-mail address below';
					break;
					case 2:
						document.getElementById('savebasketerror').childNodes[1].innerHTML = 'Please enter a valid e-mail address';
					break;
					case 3:
						document.getElementById('savebasketerror').childNodes[1].innerHTML = 'There are no items in your basket';
					break;
				}
				document.getElementById('savebasketerror').style.opacity = 0;
				document.getElementById('savebasketerror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
				var targetHeight = document.getElementById('savebasketerror').offsetHeight;
				document.getElementById('savebasketerror').style.height = currentHeight +'px';
				showErrorMessage(document.getElementById('savebasketerror'), currentHeight, targetHeight, 0, false);
			}
			return(false);
		}
	}
	if(retrieveBasket = document.getElementById('frmRetrieveBasket')) {
		retrieveBasket.onsubmit = function() {
			var submitError = 0;
			if(document.getElementById('txtRetrieveEmail').value == 'e-mail address' || document.getElementById('txtRetrieveEmail').value == '') {
				document.getElementById('txtRetrieveEmail').className = document.getElementById('txtRetrieveEmail').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(submitError == 0) {
				if(document.getElementById('txtRetrieveEmail').value.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) == -1) {
					document.getElementById('txtRetrieveEmail').className = document.getElementById('txtRetrieveEmail').className +' swatch_lgtorange_bg';
					submitError = 2;
				}
			}
			if(submitError == 0) {
				xmlHTTP.open('POST', '/_action/local/basket/retrieve_basket', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmRetrieveBasket&'+
					'txtRetrieveEmail='+ document.getElementById('txtRetrieveEmail').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					if(xmlHTTP.responseText == 'NO_RECORD') {
						submitError = 3;
					}
					else {
						showSuccessMessage(document.getElementById('savebasket'), document.getElementById('savebasketcontent'), 0, 0, 100, false, xmlHTTP.responseText);
						xmlHTTP.open('POST', '/_action/commerce/basket/list_basket', false);
						xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						xmlHTTP.send('_commerce_fieldsInclude=basket_fields&_commerce_itemInclude=basket_item&_commerce_totalInclude=basket_total&_commerce_emptyInclude=basket_empty');
						if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
							reloadBasket(document.getElementById('basketrows'), 0, 0, 100, false, xmlHTTP.responseText);
						}
					}
				}
			}
			if(submitError > 0) {
				var currentHeight = document.getElementById('savebasketerror').offsetHeight;
				document.getElementById('savebasketerror').childNodes[1].innerHTML = '';
				switch(submitError) {
					case 1:
						document.getElementById('savebasketerror').childNodes[2].innerHTML = 'Please fill out your e-mail address below';
					break;
					case 2:
						document.getElementById('savebasketerror').childNodes[2].innerHTML = 'Please enter a valid e-mail address';
					break;
					case 3:
						document.getElementById('savebasketerror').childNodes[2].innerHTML = 'No basket could be found, please try again';
					break;
				}
				document.getElementById('savebasketerror').style.opacity = 0;
				document.getElementById('savebasketerror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
				var targetHeight = document.getElementById('savebasketerror').offsetHeight;
				document.getElementById('savebasketerror').style.height = currentHeight +'px';
				showErrorMessage(document.getElementById('savebasketerror'), currentHeight, targetHeight, 0, false);
			}
			return(false);
		}
	}
}

function reloadBasket(rowContainer, currentHeight, targetHeight, formOpacity, fadeMessage, basketContent) {
	if(formOpacity > 0 && !fadeMessage) {
		formOpacity -= 5;
		rowContainer.style.opacity = formOpacity / 100;
		rowContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ formOpacity +')';
		setTimeout(function() {reloadBasket(rowContainer, currentHeight, targetHeight, formOpacity, fadeMessage, basketContent);}, 10);
	}
	else if(formOpacity == 0 && currentHeight == 0 && targetHeight == 0) {
		fadeMessage = true;
		currentHeight = rowContainer.offsetHeight;
		rowContainer.innerHTML = basketContent;
		targetHeight = rowContainer.offsetHeight;
		rowContainer.style.height = currentHeight +'px';
		setBasketActions();
		setTimeout(function() {reloadBasket(rowContainer, currentHeight, targetHeight, formOpacity, fadeMessage, basketContent);}, 10);
	}
	else if(formOpacity == 0 && currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		rowContainer.style.height = currentHeight +'px';
		setTimeout(function() {reloadBasket(rowContainer, currentHeight, targetHeight, formOpacity, fadeMessage, basketContent);}, 10);
	}
	else if(formOpacity < 100 && fadeMessage) {
		rowContainer.style.height = 'auto';
		formOpacity += 5;
		rowContainer.style.opacity = formOpacity / 100;
		rowContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ formOpacity +')';
		setTimeout(function() {reloadBasket(rowContainer, currentHeight, targetHeight, formOpacity, fadeMessage, basketContent);}, 10);
	}
}

function removeBasketItem(itemRow, currentHeight, targetHeight, rowOpacity, ajaxResult, basketEmpty) {
	var currentHeight = (currentHeight == null) ? false : currentHeight;
	var targetHeight = (targetHeight == null) ? false : targetHeight;
	var rowOpacity = (rowOpacity == null) ? false : rowOpacity;
	var ajaxResult = (ajaxResult == null) ? false : ajaxResult;
	var basketEmpty = (basketEmpty == null) ? false : basketEmpty;
	if(typeof(itemRow) == 'string') {
		var productCode = itemRow;
		if(itemRow = document.getElementById('basketRow_'+ itemRow)) {
			var basketEmpty = false;
			if(itemRow.parentNode.getElementsByTagName('div').length == 3) {
				itemRow = itemRow.parentNode;
				basketEmpty = true;
			}
			xmlHTTP.open('POST', '/_action/commerce/basket/remove_item', false);
			xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHTTP.send(
				'ajaxSubmit=true&'+
				'_commerce_productCode='+ productCode +'&'+
				'emptyInclude=basket_empty'
			);
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				var currentHeight = itemRow.offsetHeight;
				var targetHeight = 0;
				if(basketEmpty) {
					itemRow.innerHTML += xmlHTTP.responseText;
					var targetHeight = itemRow.offsetHeight - currentHeight;
					itemRow.style.height = currentHeight +'px';
				}
				setTimeout(function() {removeBasketItem(itemRow, currentHeight, targetHeight, 100, xmlHTTP.responseText, basketEmpty);}, 10);
			}
		}
	}
	else {
		if(rowOpacity > 0 && currentHeight != targetHeight) {
			rowOpacity -= 5;
			itemRow.style.opacity = rowOpacity / 100;
			itemRow.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ rowOpacity +')';
			if(rowOpacity <= 0) {
				if(basketEmpty) {
					itemRow.innerHTML = ajaxResult;
				}
				else {
					itemRow.style.height = currentHeight +'px';
					itemRow.style.paddingTop = '0px';
					itemRow.style.paddingBottom = '0px';
				}
			}
			setTimeout(function() {removeBasketItem(itemRow, currentHeight, targetHeight, rowOpacity, ajaxResult, basketEmpty);}, 10);
		}
		else if(rowOpacity == 0 && currentHeight != targetHeight) {
			if(currentHeight > targetHeight) {
				currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
			}
			else {
				currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
			}
			itemRow.style.height = currentHeight +'px';
			setTimeout(function() {removeBasketItem(itemRow, currentHeight, targetHeight, rowOpacity, ajaxResult, basketEmpty);}, 10);
		}
		else if(rowOpacity < 100 && currentHeight == targetHeight) {
			if(basketEmpty) {
				rowOpacity += 5;
				itemRow.style.height = 'auto';
				itemRow.style.opacity = rowOpacity / 100;
				itemRow.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ rowOpacity +')';
				setTimeout(function() {removeBasketItem(itemRow, currentHeight, targetHeight, rowOpacity, ajaxResult, basketEmpty);}, 10);
			}
			else {
				itemRow.parentNode.removeChild(itemRow);
				document.getElementById('netTotal').innerHTML = '&pound; '+ ajaxResult;
			}
		}
	}
}

function checkoutLogin() {
	if(checkoutLogin = document.getElementById('frmCheckoutLogin')) {
		if(loginEmail = document.getElementById('txtLoginEmail')) {
			if(loginPassword = document.getElementById('txtLoginPassword')) {
				checkoutLogin.onsubmit = function() {
					xmlHTTP.open('POST', '/_action/local/checkout/login', false);
					xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					xmlHTTP.send(
						'ajaxSubmit=true&'+
						'_hdnSession=frmCheckoutLogin&'+
						'txtLoginEmail='+ document.getElementById('txtLoginEmail').value +'&'+
						'txtLoginPassword='+ document.getElementById('txtLoginPassword').value
					);
					if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
						var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
						switch(responseInfo[0]) {
							case '0':
								location.href = '/checkout-delivery';
							break;
							case '1':
							case '3':
								loginEmail.className = 'halffullwidth swatch_grey_border swatch_lgtorange_bg';
								loginPassword.className = 'halfbuttonwidth swatch_grey_border';
							break;
							case '2':
							case '4':
								loginEmail.className = 'halffullwidth swatch_grey_border';
								loginPassword.className = 'halfbuttonwidth swatch_grey_border swatch_lgtorange_bg';
							break;
						}
						if(parseInt(responseInfo[0]) > 0) {
							var currentHeight = document.getElementById('loginerror').offsetHeight;
							document.getElementById('loginerror').childNodes[1].innerHTML = responseInfo[1];
							document.getElementById('loginerror').style.opacity = 0;
							document.getElementById('loginerror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
							var targetHeight = document.getElementById('loginerror').offsetHeight;
							document.getElementById('loginerror').style.height = currentHeight +'px';
							showErrorMessage(document.getElementById('loginerror'), currentHeight, targetHeight, 0, false);
						}
					}
					return(false);
				}
			}
		}
	}
}

function searchAddresses() {
	if(enteredPostcode = document.getElementById('txtPostcode')) {
		if(postcodeSearch = document.getElementById('btnPostcodeSearch')) {
			if(addressList = document.getElementById('sltAddress')) {
				if(addressFields = document.getElementById('addressfields')) {
					addressFields.style.display = 'none';
				}
				enteredPostcode.onkeypress = function() {
					if(window.event.keyCode == 13) {
						postcodeSearch.click();
					}
					return !(window.event && window.event.keyCode == 13);
				}
				postcodeSearch.onclick = function() {
					if(enteredPostcode.value != 'your postcode' && enteredPostcode.value != '') {
						xmlHTTP.open('POST', '/_action/core/paf/search_addresses', false);
						xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						xmlHTTP.send('postCode='+ enteredPostcode.value);
						while(addressList.options.length > 0) {
							addressList.remove(addressList.options.length - 1);
						}
						if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
							var foundAddresses = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
							addressList.add(new Option('SELECT YOUR ADDRESS', ''));
							for(addressCount = 0; addressCount < foundAddresses.length; addressCount++) {
								var addressInfo = foundAddresses[addressCount].split(':');
								addressList.add(new Option(addressInfo[1], addressInfo[0]));
							}
							addressList.add(new Option('ENTER YOUR ADDRESS MANUALLY', ''));
						}
						else {
							addressList.add(new Option('ADDRESS NOT FOUND, PLEASE ENTER MANUALLY', ''));
							if(addressPostcode = document.getElementById('txtAddressPostcode')) {
								addressPostcode.value = enteredPostcode.value;
							}
							if(addressContainer = document.getElementById('addresscontainer')) {
								if(addressFields = document.getElementById('addressfields')) {
									var currentHeight = addressContainer.offsetHeight;
									addressFields.style.opacity = 0;
									addressFields.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
									addressFields.style.display = 'block';
									var targetHeight = addressContainer.offsetHeight;
									addressContainer.style.height = currentHeight +'px';
									showSelectedAddress(addressContainer, currentHeight, targetHeight, addressFields, 0);
								}
							}
						}
						addressList.selectedIndex = 0;
					}
				}
				addressList.onchange = function() {
					if(this.value != '') {
						var addressInfo = this.value.split(',');
						if(addressLine1 = document.getElementById('txtAddressLine1')) {
							addressLine1.value = addressInfo[0];
						}
						if(addressLine2 = document.getElementById('txtAddressLine2')) {
							addressLine2.value = addressInfo[1];
						}
						if(addressLocality = document.getElementById('txtAddressLocality')) {
							addressLocality.value = addressInfo[2];
						}
						if(addressTown = document.getElementById('txtAddressTown')) {
							addressTown.value = addressInfo[3];
						}
						if(addressPostcode = document.getElementById('txtAddressPostcode')) {
							addressPostcode.value = addressInfo[4];
						}
					}
					else {
						if(addressLine1 = document.getElementById('txtAddressLine1')) {
							addressLine1.value = 'address line 1';
						}
						if(addressLine2 = document.getElementById('txtAddressLine2')) {
							addressLine2.value = 'address line 2';
						}
						if(addressLocality = document.getElementById('txtAddressLocality')) {
							addressLocality.value = 'locality';
						}
						if(addressTown = document.getElementById('txtAddressTown')) {
							addressTown.value = 'town';
						}
						if(addressPostcode = document.getElementById('txtAddressPostcode')) {
							addressPostcode.value = 'postcode';
						}
					}
					if(addressContainer = document.getElementById('addresscontainer')) {
						if(addressFields = document.getElementById('addressfields')) {
							var currentHeight = addressContainer.offsetHeight;
							addressFields.style.opacity = 0;
							addressFields.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
							addressFields.style.display = 'block';
							var targetHeight = addressContainer.offsetHeight;
							addressContainer.style.height = currentHeight +'px';
							showSelectedAddress(addressContainer, currentHeight, targetHeight, addressFields, 0);
						}
					}
				}
			}
		}
	}
}

function showSelectedAddress(addressContainer, currentHeight, targetHeight, addressFields, addressOpacity) {
	if(currentHeight != targetHeight) {
		if(currentHeight > targetHeight) {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
		}
		else {
			currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
		}
		addressContainer.style.height = currentHeight +'px';
		setTimeout(function() {showSelectedAddress(addressContainer, currentHeight, targetHeight, addressFields, addressOpacity);}, 10);
	}
	else if(addressOpacity < 100) {
		if(addressOpacity == 0) {
			addressContainer.style.height = 'auto';
		}
		addressOpacity += 5;
		addressFields.style.opacity = addressOpacity / 100;
		addressFields.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ addressOpacity +')';
		setTimeout(function() {showSelectedAddress(addressContainer, currentHeight, targetHeight, addressFields, addressOpacity);}, 10);
	}
}

function hideSelectedAddress(addressContainer, currentHeight, originalHeight, addressFields, addressOpacity) {
	if(addressOpacity > 0) {
		addressOpacity -= 5;
		addressFields.style.opacity = addressOpacity / 100;
		addressFields.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ addressOpacity +')';
		setTimeout(function() {hideSelectedAddress(addressContainer, currentHeight, originalHeight, addressFields, addressOpacity);}, 10);
	}
	else {
		if(currentHeight != originalHeight) {
			if(currentHeight > originalHeight) {
				currentHeight -= Math.ceil((currentHeight - originalHeight) / 8);
			}
			else {
				currentHeight -= Math.floor((currentHeight - taroriginalHeightgetHeight) / 8);
			}
			addressContainer.style.height = currentHeight +'px';
			setTimeout(function() {hideSelectedAddress(addressContainer, currentHeight, originalHeight, addressFields, addressOpacity);}, 10);
		}
		else {
			addressContainer.style.height = 'auto';
			addressFields.style.display = 'none';
			if(searchPostcode = document.getElementById('txtPostcode')) {
				searchPostcode.value = 'your postcode';
			}
			if(addressList = document.getElementById('sltAddress')) {
				while(addressList.options.length > 0) {
					addressList.remove(addressList.options.length - 1);
				}
				addressList.add(new Option('< Please enter your postcode and click the button', ''));
			}
			if(personTitle = document.getElementById('sltTitle')) {
				personTitle.options.selectedIndex = 0;
			}
			if(personFirstName = document.getElementById('txtFirstName')) {
				personFirstName.value = 'first name';
			}
			if(personSurname = document.getElementById('txtSurname')) {
				personSurname.value = 'surname';
			}
			if(addressLine1 = document.getElementById('txtAddressLine1')) {
				addressLine1.value = 'address line 1';
			}
			if(addressLine2 = document.getElementById('txtAddressLine2')) {
				addressLine2.value = 'address line 2';
			}
			if(addressLocality = document.getElementById('txtAddressLocality')) {
				addressLocality.value = 'locality';
			}
			if(addressTown = document.getElementById('txtAddressTown')) {
				addressTown.value = 'town';
			}
			if(addressPostcode = document.getElementById('txtAddressPostcode')) {
				addressPostcode.value = 'postcode';
			}
		}
	}
}

function checkoutJoin() {
	if(checkoutJoin = document.getElementById('frmCheckoutJoin')) {
		checkoutJoin.onsubmit = function() {
			var joinSMS = '';
/*			for(smsCount = 0; smsCount < this.rdbJoinSMS.length; smsCount++) {
				if(this.rdbJoinSMS[smsCount].checked) {
					joinSMS = this.rdbJoinSMS[smsCount].value;
				}
			}*/
			xmlHTTP.open('POST', '/_action/local/checkout/join', false);
			xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHTTP.send(
				'ajaxSubmit=true&'+
				'_hdnSession=frmCheckoutJoin&'+
				'sltJoinTitle='+ document.getElementById('sltJoinTitle').value +'&'+
				'txtJoinFirstName='+ document.getElementById('txtJoinFirstName').value.replace(/&/g, '%26') +'&'+
				'txtJoinSurname='+ document.getElementById('txtJoinSurname').value.replace(/&/g, '%26') +'&'+
				'txtJoinEmail='+ document.getElementById('txtJoinEmail').value.replace(/&/g, '%26') +'&'+
				'txtJoinConfirmEmail='+ document.getElementById('txtJoinConfirmEmail').value.replace(/&/g, '%26') +'&'+
				'txtJoinPassword='+ document.getElementById('txtJoinPassword').value.replace(/&/g, '%26') +'&'+
				'txtJoinConfirmPassword='+ document.getElementById('txtJoinConfirmPassword').value.replace(/&/g, '%26') +'&'+
				'txtJoinTelephone='+ document.getElementById('txtJoinTelephone').value.replace(/&/g, '%26') +'&'+
				'txtJoinMobile='+ document.getElementById('txtJoinMobile').value.replace(/&/g, '%26') +'&'+
				'rdbJoinSMS='+ joinSMS +'&'+
				'txtAddressLine1='+ document.getElementById('txtAddressLine1').value.replace(/&/g, '%26') +'&'+
				'txtAddressLine2='+ document.getElementById('txtAddressLine2').value.replace(/&/g, '%26') +'&'+
				'txtAddressLocality='+ document.getElementById('txtAddressLocality').value.replace(/&/g, '%26') +'&'+
				'txtAddressTown='+ document.getElementById('txtAddressTown').value.replace(/&/g, '%26') +'&'+
				'txtAddressPostcode='+ document.getElementById('txtAddressPostcode').value.replace(/&/g, '%26') +'&'+
				'sltAddressCountry='+ document.getElementById('sltAddressCountry').value
			);
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
				document.getElementById('txtJoinFirstName').className = 'swatch_grey_border';
				document.getElementById('txtJoinSurname').className = 'swatch_grey_border';
				document.getElementById('txtJoinEmail').className = 'swatch_grey_border';
				document.getElementById('txtJoinConfirmEmail').className = 'swatch_grey_border';
				document.getElementById('txtJoinPassword').className = 'swatch_grey_border';
				document.getElementById('txtJoinConfirmPassword').className = 'swatch_grey_border';
				document.getElementById('txtAddressLine1').className = 'swatch_grey_border';
				document.getElementById('txtAddressTown').className = 'swatch_grey_border';
				document.getElementById('txtAddressPostcode').className = 'swatch_grey_border';
				if(parseInt(responseInfo[0]) == 0) {
					location.href = '/checkout-delivery';
				}
				else {
					var errorFields = responseInfo[2].split(':');
					for(fieldCount = 0; fieldCount < errorFields.length; fieldCount++) {
						document.getElementById(errorFields[fieldCount]).className = 'swatch_grey_border swatch_lgtorange_bg';
					}
					if(parseInt(responseInfo[0]) == 7) {
						var currentHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').childNodes[1].innerHTML = responseInfo[1];
						document.getElementById('addresserror').style.opacity = 0;
						document.getElementById('addresserror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').style.height = currentHeight +'px';
						hideErrorMessage(document.getElementById('joinerror'), document.getElementById('joinerror').offsetHeight, document.getElementById('joinerror').offsetHeight, 100);
						showErrorMessage(document.getElementById('addresserror'), currentHeight, targetHeight, 0, false);
					}
					else {
						var currentHeight = document.getElementById('joinerror').offsetHeight;
						document.getElementById('joinerror').childNodes[1].innerHTML = responseInfo[1];
						document.getElementById('joinerror').style.opacity = 0;
						document.getElementById('joinerror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = document.getElementById('joinerror').offsetHeight;
						document.getElementById('joinerror').style.height = currentHeight +'px';
						hideErrorMessage(document.getElementById('addresserror'), document.getElementById('addresserror').offsetHeight, document.getElementById('addresserror').offsetHeight, 100);
						showErrorMessage(document.getElementById('joinerror'), currentHeight, targetHeight, 0, false);
					}
				}
			}
			return(false);
		}
	}
}

function checkoutDelivery() {
	if(checkoutDelivery = document.getElementById('frmCheckoutDelivery')) {
		if(addAddress = document.getElementById('btnAddAddress')) {
			addAddress.onclick = function() {
				xmlHTTP.open('POST', '/_action/local/checkout/add_address', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmCheckoutDelivery&'+
					'sltTitle='+ document.getElementById('sltTitle').value +'&'+
					'txtFirstName='+ document.getElementById('txtFirstName').value.replace(/&/g, '%26') +'&'+
					'txtSurname='+ document.getElementById('txtSurname').value.replace(/&/g, '%26') +'&'+
					'txtAddressLine1='+ document.getElementById('txtAddressLine1').value.replace(/&/g, '%26') +'&'+
					'txtAddressLine2='+ document.getElementById('txtAddressLine2').value.replace(/&/g, '%26') +'&'+
					'txtAddressLocality='+ document.getElementById('txtAddressLocality').value.replace(/&/g, '%26') +'&'+
					'txtAddressTown='+ document.getElementById('txtAddressTown').value.replace(/&/g, '%26') +'&'+
					'txtAddressPostcode='+ document.getElementById('txtAddressPostcode').value.replace(/&/g, '%26') +'&'+
					'sltAddressCountry='+ document.getElementById('sltAddressCountry').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
					document.getElementById('txtFirstName').className = 'swatch_grey_border';
					document.getElementById('txtSurname').className = 'swatch_grey_border';
					document.getElementById('txtAddressLine1').className = 'swatch_grey_border';
					document.getElementById('txtAddressTown').className = 'swatch_grey_border';
					document.getElementById('txtAddressPostcode').className = 'swatch_grey_border';
					if(parseInt(responseInfo[0]) == 0) {
						if(existingAddresses = document.getElementById('existingaddresses')) {
							xmlHTTP.open('POST', '/_action/commerce/checkout/list_addresses', false);
							xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
							xmlHTTP.send('addressInclude=address_option');
							if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
								var currentHeight = existingAddresses.offsetHeight;
								var currentHTML = existingAddresses.innerHTML;
								existingAddresses.innerHTML = xmlHTTP.responseText;
								var targetHeight = existingAddresses.offsetHeight;
								existingAddresses.style.height = currentHeight +'px';
								existingAddresses.innerHTML = currentHTML;
								updateAddressList(existingAddresses, currentHeight, targetHeight, 100, true, xmlHTTP.responseText);
								var addressFields = document.getElementById('addressfields');
								var currentHeight = addressContainer.offsetHeight;
								addressFields.style.display = 'none';
								var originalHeight = addressContainer.offsetHeight;
								addressFields.style.display = 'block';
								hideSelectedAddress(document.getElementById('addresscontainer'), currentHeight, originalHeight, addressFields, 100);
							}
						}
					}
					else {
						var errorFields = responseInfo[2].split(':');
						for(fieldCount = 0; fieldCount < errorFields.length; fieldCount++) {
							document.getElementById(errorFields[fieldCount]).className = 'swatch_grey_border swatch_lgtorange_bg';
						}
						var currentHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').childNodes[1].innerHTML = responseInfo[1];
						document.getElementById('addresserror').style.opacity = 0;
						document.getElementById('addresserror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').style.height = currentHeight +'px';
						showErrorMessage(document.getElementById('addresserror'), currentHeight, targetHeight, 0, false);
					}
				}
			}
		}
		if(continueButton = document.getElementById('btnContinue')) {
			continueButton.onclick = function() {
				var selectedAddress = 0;
				if(checkoutDelivery.rdbSelectAddress.checked) {
					selectedAddress = checkoutDelivery.rdbSelectAddress.value;
				}
				else {
					for(addressCount = 0; addressCount < checkoutDelivery.rdbSelectAddress.length; addressCount++) {
						if(checkoutDelivery.rdbSelectAddress[addressCount].checked) {
							selectedAddress = checkoutDelivery.rdbSelectAddress[addressCount].value;
						}
					}
				}
				var deliveryType = '';
				for(deliveryCount = 0; deliveryCount < checkoutDelivery.rdbDelivery.length; deliveryCount++) {
					if(checkoutDelivery.rdbDelivery[deliveryCount].checked) {
						deliveryType = checkoutDelivery.rdbDelivery[deliveryCount].value;
					}
				}
				xmlHTTP.open('POST', '/_action/local/checkout/delivery', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmCheckoutDelivery&'+
					'rdbSelectAddress='+ selectedAddress +'&'+
					'rdbDelivery='+ deliveryType
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
					if(parseInt(responseInfo[0]) == 0) {
						location.href = '/checkout-payment';
					}
					else {
						if(parseInt(responseInfo[0]) == 1 || parseInt(responseInfo[0]) == 3) {
							previousError = document.getElementById('deliveryerror');
							errorContainer = document.getElementById('selectaddresserror');
						}
						else {
							previousError = document.getElementById('selectaddresserror');
							errorContainer = document.getElementById('deliveryerror');
						}
						var currentHeight = errorContainer.offsetHeight;
						errorContainer.childNodes[1].innerHTML = responseInfo[1];
						errorContainer.style.opacity = 0;
						errorContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = errorContainer.offsetHeight;
						errorContainer.style.height = currentHeight +'px';
						hideErrorMessage(previousError, previousError.offsetHeight, previousError.offsetHeight, 100);
						showErrorMessage(errorContainer, currentHeight, targetHeight, 0, false);
					}
				}
			}
		}
		checkoutDelivery.onsubmit = function() {
			return(false);
		}
	}
}

function checkoutPayment() {
	if(checkoutPayment = document.getElementById('frmCheckoutPayment')) {
		if(addAddress = document.getElementById('btnAddAddress')) {
			addAddress.onclick = function() {
				xmlHTTP.open('POST', '/_action/local/checkout/add_address', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmCheckoutPayment&'+
					'sltTitle='+ document.getElementById('sltTitle').value +'&'+
					'txtFirstName='+ document.getElementById('txtFirstName').value.replace(/&/g, '%26') +'&'+
					'txtSurname='+ document.getElementById('txtSurname').value.replace(/&/g, '%26') +'&'+
					'txtAddressLine1='+ document.getElementById('txtAddressLine1').value.replace(/&/g, '%26') +'&'+
					'txtAddressLine2='+ document.getElementById('txtAddressLine2').value.replace(/&/g, '%26') +'&'+
					'txtAddressLocality='+ document.getElementById('txtAddressLocality').value.replace(/&/g, '%26') +'&'+
					'txtAddressTown='+ document.getElementById('txtAddressTown').value.replace(/&/g, '%26') +'&'+
					'txtAddressPostcode='+ document.getElementById('txtAddressPostcode').value.replace(/&/g, '%26') +'&'+
					'sltAddressCountry='+ document.getElementById('sltAddressCountry').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
					document.getElementById('txtFirstName').className = 'swatch_grey_border';
					document.getElementById('txtSurname').className = 'swatch_grey_border';
					document.getElementById('txtAddressLine1').className = 'swatch_grey_border';
					document.getElementById('txtAddressTown').className = 'swatch_grey_border';
					document.getElementById('txtAddressPostcode').className = 'swatch_grey_border';
					if(parseInt(responseInfo[0]) == 0) {
						if(existingAddresses = document.getElementById('existingaddresses')) {
							xmlHTTP.open('POST', '/_action/commerce/checkout/list_addresses', false);
							xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
							xmlHTTP.send('addressInclude=address_option');
							if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
								var currentHeight = existingAddresses.offsetHeight;
								var currentHTML = existingAddresses.innerHTML;
								existingAddresses.innerHTML = xmlHTTP.responseText;
								var targetHeight = existingAddresses.offsetHeight;
								existingAddresses.style.height = currentHeight +'px';
								existingAddresses.innerHTML = currentHTML;
								updateAddressList(existingAddresses, currentHeight, targetHeight, 100, true, xmlHTTP.responseText);
								var addressFields = document.getElementById('addressfields');
								var currentHeight = addressContainer.offsetHeight;
								addressFields.style.display = 'none';
								var originalHeight = addressContainer.offsetHeight;
								addressFields.style.display = 'block';
								hideSelectedAddress(document.getElementById('addresscontainer'), currentHeight, originalHeight, addressFields, 100);
							}
						}
					}
					else {
						var errorFields = responseInfo[2].split(':');
						for(fieldCount = 0; fieldCount < errorFields.length; fieldCount++) {
							document.getElementById(errorFields[fieldCount]).className = 'swatch_grey_border swatch_lgtorange_bg';
						}
						var currentHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').childNodes[1].innerHTML = responseInfo[1];
						document.getElementById('addresserror').style.opacity = 0;
						document.getElementById('addresserror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = document.getElementById('addresserror').offsetHeight;
						document.getElementById('addresserror').style.height = currentHeight +'px';
						showErrorMessage(document.getElementById('addresserror'), currentHeight, targetHeight, 0, false);
					}
				}
			}
		}
		if(finishButton = document.getElementById('btnFinish')) {
			finishButton.onclick = function() {
				for(var childCount = 0; childCount < this.parentNode.parentNode.parentNode.childNodes.length; childCount++) {
					if(this.parentNode.parentNode.parentNode.childNodes[childCount].style != undefined) {
						this.parentNode.parentNode.parentNode.childNodes[childCount].style.visibility = 'hidden';
					}
				}
				this.parentNode.parentNode.parentNode.style.backgroundImage = 'url(/_files/images/core/icons/loader3.gif)';
				this.parentNode.parentNode.parentNode.style.backgroundPosition = 'center center';
				this.parentNode.parentNode.parentNode.style.backgroundRepeat = 'no-repeat';
				var selectedAddress = 0;
				if(checkoutPayment.rdbSelectAddress.checked) {
					selectedAddress = checkoutPayment.rdbSelectAddress.value;
				}
				else {
					for(addressCount = 0; addressCount < checkoutPayment.rdbSelectAddress.length; addressCount++) {
						if(checkoutPayment.rdbSelectAddress[addressCount].checked) {
							selectedAddress = checkoutPayment.rdbSelectAddress[addressCount].value;
						}
					}
				}
				xmlHTTP.open('POST', '/_action/local/checkout/payment', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmCheckoutPayment&'+
					'rdbSelectAddress='+ selectedAddress +'&'+
					'sltCardType='+ document.getElementById('sltCardType').value +'&'+
					'txtCardNumber='+ document.getElementById('txtCardNumber').value +'&'+
					'txtCardName='+  document.getElementById('txtCardName').value +'&'+
					'sltCardStart_Month='+ document.getElementById('sltCardStart_Month').value +'&'+
					'sltCardStart_Year='+ document.getElementById('sltCardStart_Year').value +'&'+
					'sltCardExpiry_Month='+ document.getElementById('sltCardExpiry_Month').value +'&'+
					'sltCardExpiry_Year='+ document.getElementById('sltCardExpiry_Year').value +'&'+
					'txtCardIssue='+ document.getElementById('txtCardIssue').value +'&'+
					'txtCardVerification='+  document.getElementById('txtCardVerification').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
					if(parseInt(responseInfo[0]) == 0) {
						location.href = '/checkout-success';
					}
					else {
						if(parseInt(responseInfo[0]) == 2) {
							previousError = document.getElementById('paymenterror');
							errorContainer = document.getElementById('selectaddresserror');
						}
						else {
							previousError = document.getElementById('selectaddresserror');
							errorContainer = document.getElementById('paymenterror');
						}
						var currentHeight = errorContainer.offsetHeight;
						errorContainer.childNodes[1].innerHTML = responseInfo[1];
						errorContainer.style.opacity = 0;
						errorContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
						var targetHeight = errorContainer.offsetHeight;
						errorContainer.style.height = currentHeight +'px';
						hideErrorMessage(previousError, previousError.offsetHeight, previousError.offsetHeight, 100);
						showErrorMessage(errorContainer, currentHeight, targetHeight, 0, false, 'showFinishButton();');
					}
				}
			}
		}
		checkoutPayment.onsubmit = function() {
			return(false);
		}
	}
}

function showFinishButton() {
	if(finishButton = document.getElementById('btnFinish')) {
		for(var childCount = 0; childCount < finishButton.parentNode.parentNode.parentNode.childNodes.length; childCount++) {
			if(finishButton.parentNode.parentNode.parentNode.childNodes[childCount].style != undefined) {
				finishButton.parentNode.parentNode.parentNode.childNodes[childCount].style.visibility = 'visible';
			}
		}
		finishButton.parentNode.parentNode.parentNode.style.backgroundImage = 'none';
	}
}

function updateAddressList(addressContainer, currentHeight, targetHeight, addressOpacity, fadeAddresses, newHTML) {
	if(fadeAddresses) {
		if(addressOpacity > 0) {
			addressOpacity -= 4;
			addressContainer.style.opacity = addressOpacity / 100;
			addressContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ addressOpacity +')';
		}
		else {
			fadeAddresses = false;
		}
		setTimeout(function() {updateAddressList(addressContainer, currentHeight, targetHeight, addressOpacity, fadeAddresses, newHTML);}, 10);
	}
	else {
		if(currentHeight != targetHeight) {
			if(currentHeight > targetHeight) {
				currentHeight -= Math.ceil((currentHeight - targetHeight) / 8);
			}
			else {
				currentHeight -= Math.floor((currentHeight - targetHeight) / 8);
			}
			addressContainer.style.height = currentHeight +'px';
			setTimeout(function() {updateAddressList(addressContainer, currentHeight, targetHeight, addressOpacity, fadeAddresses, newHTML);}, 10);
		}
		else {
			if(addressOpacity == 0) {
				addressContainer.style.height = 'auto';
				addressContainer.innerHTML = newHTML;
			}
			if(addressOpacity < 100) {
				addressOpacity += 4;
				addressContainer.style.opacity = addressOpacity / 100;
				addressContainer.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ addressOpacity +')';
				setTimeout(function() {updateAddressList(addressContainer, currentHeight, targetHeight, addressOpacity, fadeAddresses, newHTML);}, 10);
			}
		}
	}
}

function competitionSignUp() {
	if(competitionSignUp = document.getElementById('frmCompetitionSignUp')) {
		competitionSignUp.onsubmit = function() {
			xmlHTTP.open('POST', '/_action/local/competition/signup', false);
			xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlHTTP.send(
				'ajaxSubmit=true&'+
				'_hdnSession=frmCompetitionSignUp&'+
				'sltCompTitle='+ document.getElementById('sltCompTitle').value +'&'+
				'txtCompFirstName='+ document.getElementById('txtCompFirstName').value.replace(/&/g, '%26') +'&'+
				'txtCompSurname='+ document.getElementById('txtCompSurname').value.replace(/&/g, '%26') +'&'+
				'txtCompEmail='+ document.getElementById('txtCompEmail').value.replace(/&/g, '%26') +'&'+
				'txtCompConfirmEmail='+ document.getElementById('txtCompConfirmEmail').value.replace(/&/g, '%26') +'&'+
				'txtCompTelephone='+ document.getElementById('txtCompTelephone').value.replace(/&/g, '%26') +'&'+
				'txtCompMobile='+ document.getElementById('txtCompMobile').value.replace(/&/g, '%26')
			);
			if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
				var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
				document.getElementById('txtCompFirstName').className = 'swatch_grey_border';
				document.getElementById('txtCompSurname').className = 'swatch_grey_border';
				document.getElementById('txtCompEmail').className = 'swatch_grey_border';
				document.getElementById('txtCompConfirmEmail').className = 'swatch_grey_border';
				if(parseInt(responseInfo[0]) == 0) {
					location.href = '/competition/sign-up/success';
				}
				else {
					var errorFields = responseInfo[2].split(':');
					for(fieldCount = 0; fieldCount < errorFields.length; fieldCount++) {
						document.getElementById(errorFields[fieldCount]).className = 'swatch_grey_border swatch_lgtorange_bg';
					}
					var currentHeight = document.getElementById('signuperror').offsetHeight;
					document.getElementById('signuperror').childNodes[1].innerHTML = responseInfo[1];
					document.getElementById('signuperror').style.opacity = 0;
					document.getElementById('signuperror').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)';
					var targetHeight = document.getElementById('signuperror').offsetHeight;
					document.getElementById('signuperror').style.height = currentHeight +'px';
					showErrorMessage(document.getElementById('signuperror'), currentHeight, targetHeight, 0, false);
				}
			}
			return(false);
		}
	}
}

function magazineIndex() {
	var layoutFields = document.getElementsByTagName('*');
	for(fieldCount = 0; fieldCount < layoutFields.length; fieldCount++) {
		if(layoutFields[fieldCount].getAttribute('layoutField')) {
			switch(layoutFields[fieldCount].getAttribute('layoutField')) {
				case 'magazineText':
					var marginTop = 0;
					var marginBottom = 0;
					if(layoutFields[fieldCount].childNodes.length > 0) {
						var textContainer = layoutFields[fieldCount].childNodes[0];
						if(window.getComputedStyle) {
							marginTop = parseInt(window.getComputedStyle(textContainer, null).marginTop);
							marginBottom = parseInt(window.getComputedStyle(textContainer, null).marginBottom);
						}
						else {
							marginTop = parseFloat(textContainer.currentStyle.marginTop);
							marginBottom = parseFloat(textContainer.currentStyle.marginBottom);
						}
					}
					else {
						var textContainer = layoutFields[fieldCount];
					}
					var textString = '';
					var textWords = textContainer.innerHTML.split(' ');
					if(window.getComputedStyle) {
						var textHeight = ((6 * parseInt(window.getComputedStyle(layoutFields[fieldCount], null).lineHeight)) + marginTop + marginBottom);
					}
					else {
						// IE issue - Needs more work...
						
						var textHeight = ((10 * parseFloat(layoutFields[fieldCount].currentStyle.lineHeight)) + marginTop + marginBottom);
					}
					for(wordCount = 0; wordCount < textWords.length; wordCount++) {
						layoutFields[fieldCount].innerHTML = '<p>'+ textString +' '+ textWords[wordCount] +'...</p>';
						if(layoutFields[fieldCount].offsetHeight <= textHeight) {
							textString += ' '+ textWords[wordCount];
							textString.replace(/^\s+|\s+$/g, '');
						}
						else {
							layoutFields[fieldCount].innerHTML = '<p>'+ textString.replace(/(,|\.|!|\?)+$/, '') +'...</p>';
						}
					}
				break;
			}
		}
	}
}

function viewerFunctions() {
	var siteCover = false;
	if(siteCover = document.getElementById('sitecover')) {
		var viewerContainer = false;
		if(viewerContainer = document.getElementById('viewercontainer')) {
			var closeTab = false;
			if(closeTab = document.getElementById('viewer_closetab')) {
				closeTab.onclick = function() {
					siteCover.style.top = '-101%';
					siteCover.style.left = '-101%';
					viewerContainer.style.top = '-101%';
					viewerContainer.style.left = '-101%';
				}
			}
		}
	}
}

function footerNewsletter() {
	if(footerNewsletter = document.getElementById('frmFooterNewsletter')) {
		footerNewsletter.onsubmit = function() {
			var submitError = 0;
			if(document.getElementById('txtNewsletterEmail').value == 'e-mail address...' || document.getElementById('txtNewsletterEmail').value == '') {
				document.getElementById('txtNewsletterEmail').className = document.getElementById('txtNewsletterEmail').className +' swatch_lgtorange_bg';
				submitError = 1;
			}
			if(submitError == 0) {
				if(document.getElementById('txtNewsletterEmail').value.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) == -1) {
					document.getElementById('txtNewsletterEmail').className = document.getElementById('txtNewsletterEmail').className +' swatch_lgtorange_bg';
					submitError = 2;
				}
			}
			if(submitError == 0) {
				xmlHTTP.open('POST', '/_action/local/user/newsletter_signup', false);
				xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				xmlHTTP.send(
					'ajaxSubmit=true&'+
					'_hdnSession=frmFooterNewsletter&'+
					'txtNewsletterEmail='+ document.getElementById('txtNewsletterEmail').value
				);
				if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
					var footerformNewsletter = null;
					if(footerformNewsletter = document.getElementById('footerform_newsletter')) {
						footerformNewsletter.innerHTML = '<div style="margin-top: 5px;margin-left: 8px;">'+ xmlHTTP.responseText +'</div>';
					}
				}
			}
			return(false);
		}
	}
}

function openViewer(viewerWidth, viewerHeight, contentType, productID) {
	var siteCover = false;
	if(siteCover = document.getElementById('sitecover')) {
		var viewerContainer = false;
		if(viewerContainer = document.getElementById('viewercontainer')) {
			var viewer = false;
			if(viewer = document.getElementById('viewer')) {
				var viewerImage = false;
				if(viewerImage = document.getElementById('viewerimage')) {
					var availableImages = new Array();
					viewer.style.width = viewerWidth +'px';
					viewer.style.height = viewerHeight +'px';
					viewer.style.marginTop = '-'+ (viewerHeight / 2) +'px';
					viewer.style.marginLeft = '-'+ (viewerWidth / 2) +'px';
					siteCover.style.top = '0px';
					siteCover.style.left = '0px';
					viewerContainer.style.top = '0px';
					viewerContainer.style.left = '0px';
					var viewerPanel = false;
					if(viewerPanel = document.getElementById('viewerpanel')) {
						if(contentType == 'productImages') {
							viewerPanel.style.display = 'block';
							xmlHTTP.open('POST', '/_action/local/products/viewer_images', false);
							xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
							xmlHTTP.send('productID='+ productID);
							if(xmlHTTP.responseText != '' && xmlHTTP.responseText != null) {
								var responseInfo = xmlHTTP.responseText.substr(1, xmlHTTP.responseText.length - 2).split('","');
								for(imageCount = 0; imageCount < responseInfo.length; imageCount++) {
									var imageDetails = responseInfo[imageCount].split(':');
									var imageFile = imageDetails[0];
									var imageSizes = imageDetails[1].split(';');
									var imageDetails = new Array();
									imageDetails[0] = imageFile;
									imageDetails[1] = imageSizes;
									availableImages[availableImages.length] = imageDetails;
								}
								if(availableImages.length > 0) {
									viewerImage.setAttribute('imageID', 0);
									viewerImage.setAttribute('sizeID', 0);
									viewerImage.src = '/_files/images/_commerce/productimages/live/'+ availableImages[0][0] +'_592x466.jpg';
									viewerImage.width = 592;
									viewerImage.height = 466;
									viewerImage.style.top = '0px';
									viewerImage.style.left = '0px';
									if(viewFinder = document.getElementById('viewerpanel_zoomview_finder')) {
										viewFinder.style.width = '62px';
										viewFinder.style.height = '62px';
										viewFinder.style.top = '0px';
										viewFinder.style.left = '0px';
									}
									if(availableImages[0][1].length > 1) {
										document.getElementById('viewerpanel_heading_zoomcontrols').style.display = 'block';
										document.getElementById('viewerpanel_zoomcontrols').style.display = 'block';
										document.getElementById('viewerpanel_heading_pancontrols').style.display = 'none';
										document.getElementById('viewerpanel_pancontrols').style.display = 'none';
									}
									else {
										document.getElementById('viewerpanel_heading_zoomcontrols').style.display = 'none';
										document.getElementById('viewerpanel_zoomcontrols').style.display = 'none';
										document.getElementById('viewerpanel_heading_pancontrols').style.display = 'none';
										document.getElementById('viewerpanel_pancontrols').style.display = 'none';
									}
									var zoomView = false;
									if(zoomView = document.getElementById('viewerpanel_zoomview')) {
										zoomView.style.backgroundImage = 'url(/_files/images/_commerce/productimages/live/'+ availableImages[0][0] +'_64x64.jpg)';
									}
									var otherViews = false;
									if(otherViews = document.getElementById('viewerpanel_otherviews')) {
										while(otherViews.childNodes.length > 0) {
											otherViews.removeChild(otherViews.childNodes[0]);
										}
										for(imageCount = 0; imageCount < availableImages.length; imageCount++) {
											var thumbImage = document.createElement('div');
											thumbImage.setAttribute('imageID', imageCount);
											thumbImage.className = 'viewerpanel_thumb';
											thumbImage.style.backgroundImage = 'url(/_files/images/_commerce/productimages/live/'+ availableImages[imageCount][0] +'_64x64.jpg)';
											thumbImage.onclick = function() {
												if(viewerImage.getAttribute('imageID') != this.getAttribute('imageID')) {
													viewerImage.setAttribute('imageID', this.getAttribute('imageID'));
													viewerImage.setAttribute('sizeID', 0);
													viewerImage.src = '/_files/images/_commerce/productimages/live/'+ availableImages[this.getAttribute('imageID')][0] +'_592x466.jpg';
													viewerImage.width = 592;
													viewerImage.height = 466;
													if(availableImages[this.getAttribute('imageID')][1].length > 1) {
														document.getElementById('viewerpanel_heading_zoomcontrols').style.display = 'block';
														document.getElementById('viewerpanel_zoomcontrols').style.display = 'block';
														document.getElementById('viewerpanel_heading_pancontrols').style.display = 'none';
														document.getElementById('viewerpanel_pancontrols').style.display = 'none';
													}
													else {
														document.getElementById('viewerpanel_heading_zoomcontrols').style.display = 'none';
														document.getElementById('viewerpanel_zoomcontrols').style.display = 'none';
														document.getElementById('viewerpanel_heading_pancontrols').style.display = 'none';
														document.getElementById('viewerpanel_pancontrols').style.display = 'none';
													}
												}
												if(zoomView = document.getElementById('viewerpanel_zoomview')) {
													zoomView.style.backgroundImage = 'url(/_files/images/_commerce/productimages/live/'+ availableImages[this.getAttribute('imageID')][0] +'_64x64.jpg)';
												}
											}
											otherViews.appendChild(thumbImage);
										}
									}
								}
							}
							else {
								var siteCover = false;
								if(siteCover = document.getElementById('sitecover')) {
									var viewerContainer = false;
									if(viewerContainer = document.getElementById('viewercontainer')) {
										siteCover.style.top = '-101%';
										siteCover.style.left = '-101%';
										viewerContainer.style.top = '-101%';
										viewerContainer.style.left = '-101%';
									}
								}
							}
						}
						else {
							viewerPanel.style.display = 'none';
							viewerImage.src = contentType;
						}
					}
					var zoomIn = false;
					if(zoomIn = document.getElementById('viewerpanel_zoom_in')) {
						zoomIn.onclick = function() {
							var currentSize = parseInt(viewerImage.getAttribute('sizeID'));
							if((currentSize + 1) < availableImages[viewerImage.getAttribute('imageID')][1].length) {
								var imageSize = availableImages[viewerImage.getAttribute('imageID')][1][(currentSize + 1)].split('x');
								zoomViewer(viewerImage, availableImages[viewerImage.getAttribute('imageID')][0], viewerImage.width, viewerImage.height, parseInt(imageSize[0]), parseInt(imageSize[1]));
								viewerImage.setAttribute('sizeID', currentSize + 1);
							}
						}
					}
					var zoomOut = false;
					if(zoomOut = document.getElementById('viewerpanel_zoom_out')) {
						zoomOut.onclick = function() {
							var currentSize = parseInt(viewerImage.getAttribute('sizeID'));
							if((currentSize - 1) > -1) {
								var imageSize = availableImages[viewerImage.getAttribute('imageID')][1][(currentSize - 1)].split('x');
								zoomViewer(viewerImage, availableImages[viewerImage.getAttribute('imageID')][0], viewerImage.width, viewerImage.height, parseInt(imageSize[0]), parseInt(imageSize[1]));
								viewerImage.setAttribute('sizeID', currentSize - 1);
							}
						}
					}
					var zoomReset = false;
					if(zoomReset = document.getElementById('viewerpanel_reset_button')) {
						zoomReset.onclick = function() {
							var imageSize = availableImages[viewerImage.getAttribute('imageID')][1][0].split('x');
							zoomViewer(viewerImage, availableImages[viewerImage.getAttribute('imageID')][0], viewerImage.width, viewerImage.height, parseInt(imageSize[0]), parseInt(imageSize[1]));
							viewerImage.setAttribute('sizeID', 0);
						}
					}
					var panUp = false;
					if(panUp = document.getElementById('viewerpanel_pancontrols_up')) {
						panUp.onclick = function() {
							var targetTop = Math.round(((viewerImage.offsetTop / 87) + 1) * 87);
							if(targetTop > -87) {
								targetTop = 0;
							}
							var viewFinder = document.getElementById('viewerpanel_zoomview_finder');
							if(viewFinder.offsetHeight == 30) {
								var viewerIncrement = 8;
							}
							else {
								var viewerIncrement = 5;
							}
							var finderTop = Math.round(((viewFinder.offsetTop / viewerIncrement) - 1) * viewerIncrement);
							if(finderTop < viewerIncrement) {
								finderTop = 0;
							}
							panViewer(viewerImage, viewerImage.offsetTop, viewerImage.offsetLeft, targetTop, viewerImage.offsetLeft, viewFinder, finderTop, viewFinder.offsetLeft);
						}
					}
					var panDown = false;
					if(panDown = document.getElementById('viewerpanel_pancontrols_down')) {
						panDown.onclick = function() {
							var targetTop = Math.round(((viewerImage.offsetTop / 87) - 1) * 87);
							if(targetTop < (466 - viewerImage.height) + 87) {
								targetTop = 466 - viewerImage.height;
							}
							var viewFinder = document.getElementById('viewerpanel_zoomview_finder');
							if(viewFinder.offsetHeight == 30) {
								var viewerIncrement = 8;
							}
							else {
								var viewerIncrement = 5;
							}
							var finderTop = Math.round(((viewFinder.offsetTop / viewerIncrement) + 1) * viewerIncrement);
							if(finderTop > (64 - viewFinder.offsetHeight) - viewerIncrement) {
								finderTop = 64 - viewFinder.offsetHeight;
							}
							panViewer(viewerImage, viewerImage.offsetTop, viewerImage.offsetLeft, targetTop, viewerImage.offsetLeft, viewFinder, finderTop, viewFinder.offsetLeft);
						}
					}
					var panLeft = false;
					if(panLeft = document.getElementById('viewerpanel_pancontrols_left')) {
						panLeft.onclick = function() {
							var targetLeft = Math.round(((viewerImage.offsetLeft / 74) + 1) * 74);
							if(targetLeft > -74) {
								targetLeft = 0;
							}
							var viewFinder = document.getElementById('viewerpanel_zoomview_finder');
							if(viewFinder.offsetWidth == 38) {
								var viewerIncrement = 4;
							}
							else {
								var viewerIncrement = 2.51;
							}
							var finderLeft = Math.round(((viewFinder.offsetLeft / viewerIncrement) - 1) * viewerIncrement);
							if(finderLeft < viewerIncrement) {
								finderLeft = 0;
							}
							panViewer(viewerImage, viewerImage.offsetTop, viewerImage.offsetLeft, viewerImage.offsetTop, targetLeft, viewFinder, viewFinder.offsetTop, finderLeft);
						}
					}
					var panRight = false;
					if(panRight = document.getElementById('viewerpanel_pancontrols_right')) {
						panRight.onclick = function() {
							var targetLeft = Math.round(((viewerImage.offsetLeft / 74) - 1) * 74);
							if(targetLeft < (592 - viewerImage.width) + 74) {
								targetLeft = 592 - viewerImage.width;
							}
							var viewFinder = document.getElementById('viewerpanel_zoomview_finder');
							if(viewFinder.offsetWidth == 38) {
								var viewerIncrement = 4;
							}
							else {
								var viewerIncrement = 2.51;
							}
							var finderLeft = Math.round(((viewFinder.offsetLeft / viewerIncrement) + 1) * viewerIncrement);
							if(finderLeft > (64 - viewFinder.offsetWidth) - viewerIncrement) {
								finderLeft = 64 - viewFinder.offsetWidth;
							}
							panViewer(viewerImage, viewerImage.offsetTop, viewerImage.offsetLeft, viewerImage.offsetTop, targetLeft, viewFinder, viewFinder.offsetTop, finderLeft);
						}
					}
				}
			}
		}
	}
}

function zoomViewer(viewerImage, imageFile, currentWidth, currentHeight, targetWidth, targetHeight) {
	var loopFunction = false;
	if(currentWidth != targetWidth) {
		if(currentWidth < targetWidth) {
			currentWidth += Math.ceil((targetWidth - currentWidth) / 4);
		}
		else {
			currentWidth -= Math.ceil((currentWidth - targetWidth) / 4);
		}
		loopFunction = true;
	}
	viewerImage.width = currentWidth;
	viewerImage.style.left = ((592 - currentWidth) / 2) +'px';
	if(currentHeight != targetHeight) {
		if(currentHeight < targetHeight) {
			currentHeight += Math.ceil((targetHeight - currentHeight) / 4);
		}
		else {
			currentHeight -= Math.ceil((currentHeight - targetHeight) / 4);
		}
		loopFunction = true;
	}
	viewerImage.height = currentHeight;
	viewerImage.style.top = ((466 - currentHeight) / 2) +'px';
	if(loopFunction) {
		setTimeout(function() {zoomViewer(viewerImage, imageFile, currentWidth, currentHeight, targetWidth, targetHeight);}, 10);
	}
	else {
		viewerImage.src = '/_files/images/_commerce/productimages/live/'+ imageFile +'_'+ targetWidth +'x'+ targetHeight +'.jpg';
		if(currentWidth == 592 && currentHeight == 466) {
			document.getElementById('viewerpanel_heading_pancontrols').style.display = 'none';
			document.getElementById('viewerpanel_pancontrols').style.display = 'none';
			if(viewFinder = document.getElementById('viewerpanel_zoomview_finder')) {
				viewFinder.style.width = '62px';
				viewFinder.style.height = '62px';
				viewFinder.style.top = '0px';
				viewFinder.style.left = '0px';
			}
		}
		else {
			document.getElementById('viewerpanel_heading_pancontrols').style.display = 'block';
			document.getElementById('viewerpanel_pancontrols').style.display = 'block';
			var viewFinder = false;
			if(currentWidth == 1036 && currentHeight == 816) {
				if(viewFinder = document.getElementById('viewerpanel_zoomview_finder')) {
					viewFinder.style.width = '36px';
					viewFinder.style.height = '28px';
					viewFinder.style.top = '17px';
					viewFinder.style.left = '14px';
				}
			}
			else {
				if(viewFinder = document.getElementById('viewerpanel_zoomview_finder')) {
					viewFinder.style.width = '30px';
					viewFinder.style.height = '20px';
					viewFinder.style.top = '21px';
					viewFinder.style.left = '16px';
				}
			}
		}
	}
}

function panViewer(viewerImage, currentTop, currentLeft, targetTop, targetLeft, viewFinder, finderTop, finderLeft) {
	var loopFunction = false;
	if(currentTop != targetTop) {
		if(currentTop < targetTop) {
			currentTop += Math.ceil((targetTop - currentTop) / 4);
		}
		else {
			currentTop -= Math.ceil((currentTop - targetTop) / 4);
		}
		loopFunction = true;
	}
	viewerImage.style.top = currentTop +'px';
	if(currentLeft != targetLeft) {
		if(currentLeft < targetLeft) {
			currentLeft += Math.ceil((targetLeft - currentLeft) / 4);
		}
		else {
			currentLeft -= Math.ceil((currentLeft - targetLeft) / 4);
		}
		loopFunction = true;
	}
	viewerImage.style.left = currentLeft +'px';
	if(loopFunction) {
		setTimeout(function() {panViewer(viewerImage, currentTop, currentLeft, targetTop, targetLeft, viewFinder, finderTop, finderLeft);}, 10);
	}
	else {
		viewFinder.style.top = finderTop +'px';
		viewFinder.style.left = finderLeft +'px';
	}
}

function openWeekPic() {
	var weekPic = false;
	if(weekPic = document.getElementById('weekpic')) {
		picImage = weekPic.getElementsByTagName('img');
		openViewer(picImage[0].width, picImage[0].height, picImage[0].src, 0);
	}
}

/*function showPicViewer(siteCover, coverAlpha, viewerContainer, picViewer, currentWidth, currentHeight, targetWidth, targetHeight, closeTab, tabPosition, viewerImage, imageAlpha) {
	if(processRunning == null || processRunning == 'openViewer') {
		processRunning = 'openViewer';
		var loopFunction = false;
		siteCover.style.top = '0px';
		siteCover.style.left = '0px';
		if(coverAlpha < 80) {
			coverAlpha += Math.ceil((80 - coverAlpha) / 2);
			siteCover.style.opacity = (coverAlpha / 100);
			siteCover.style.filter = 'alpha(opacity='+ coverAlpha +')';
			loopFunction = true;
		}
		else {
			viewerContainer.style.top = '0px';
			viewerContainer.style.left = '0px';
			if(currentWidth < targetWidth) {
				currentWidth += Math.ceil((targetWidth - currentWidth) / 8);
				loopFunction = true;
			}
			picViewer.style.width = currentWidth +'px';
			picViewer.style.marginLeft = '-'+ Math.floor(currentWidth / 2) +'px';
			if(currentHeight < targetHeight) {
				currentHeight += Math.ceil((targetHeight - currentHeight) / 8);
				loopFunction = true;
			}
			picViewer.style.height = currentHeight +'px';
			picViewer.style.marginTop = '-'+ Math.floor(currentHeight / 2) +'px';
			if(currentWidth == targetWidth && currentHeight == targetHeight) {
				if(tabPosition > 0) {
					closeTab.style.display = 'block';
					tabPosition -= Math.ceil(tabPosition / 4);
					closeTab.style.top = '-'+ tabPosition +'px';
					loopFunction = true;
				}
				else {
					if(imageAlpha < 100) {
						imageAlpha += Math.ceil((100 - imageAlpha) / 2);
						viewerImage.style.opacity = (imageAlpha / 100);
						viewerImage.style.filter = 'alpha(opacity='+ imageAlpha +')';
						loopFunction = true;
					}
				}
			}
		}
		if(loopFunction) {
			setTimeout(function() {showPicViewer(siteCover, coverAlpha, viewerContainer, picViewer, currentWidth, currentHeight, targetWidth, targetHeight, closeTab, tabPosition, viewerImage, imageAlpha);}, 10);
		}
		else {
			processRunning = null;
		}
	}
}

function closePicViewer() {
	if(weekPic = document.getElementById('weekpic')) {
		picImage = weekPic.getElementsByTagName('img');
		if(siteCover = document.getElementById('sitecover')) {
			if(viewerContainer = document.getElementById('viewercontainer')) {
				if(picViewer = document.getElementById('viewer')) {
					if(closeTab = document.getElementById('v_closetab')) {
						if(viewerImage = document.getElementById('v_image')) {
							hidePicViewer(siteCover, 80, viewerContainer, picViewer, picImage[0].width, picImage[0].height, picImage[0].width, picImage[0].height, closeTab, 0, viewerImage, 100);
						}
					}
				}
			}
		}
	}
}

function hidePicViewer(siteCover, coverAlpha, viewerContainer, picViewer, currentWidth, currentHeight, incrementWidth, incrementHeight, closeTab, tabPosition, viewerImage, imageAlpha) {
	if(processRunning == null || processRunning == 'closeViewer') {
		processRunning = 'closeViewer';
		var loopFunction = false;
		if(imageAlpha > 0) {
			imageAlpha -= Math.ceil(imageAlpha / 2);
			viewerImage.style.opacity = (imageAlpha / 100);
			viewerImage.style.filter = 'alpha(opacity='+ imageAlpha +')';
			loopFunction = true;
		}
		else {
			if(tabPosition < 31) {
				tabPosition += Math.ceil((31 - tabPosition) / 4);
				closeTab.style.top = '-'+ tabPosition +'px';
				loopFunction = true;
			}
			else {
				closeTab.style.display = 'block';
				if(currentWidth > 0) {
					incrementWidth -= Math.ceil(incrementWidth / 4);
					currentWidth = incrementWidth;
					loopFunction = true;
				}
				picViewer.style.width = currentWidth +'px';
				picViewer.style.marginLeft = '-'+ Math.floor(currentWidth / 2) +'px';
				if(currentHeight > 0) {
					incrementHeight -= Math.ceil(incrementHeight / 4);
					currentHeight = incrementHeight;
					loopFunction = true;
				}
				picViewer.style.height = currentHeight +'px';
				picViewer.style.marginTop = '-'+ Math.floor(currentHeight / 2) +'px';
				if(currentWidth == 0 && currentHeight == 0) {
					viewerContainer.style.top = '-101%';
					viewerContainer.style.left = '-101%';
					if(coverAlpha > 0) {
						coverAlpha -= Math.ceil(coverAlpha / 2);
						siteCover.style.opacity = (coverAlpha / 100);
						siteCover.style.filter = 'alpha(opacity='+ coverAlpha +')';
						loopFunction = true;
					}
				}
			}
		}
		if(loopFunction) {
			setTimeout(function() {hidePicViewer(siteCover, coverAlpha, viewerContainer, picViewer, currentWidth, currentHeight, incrementWidth, incrementHeight, closeTab, tabPosition, viewerImage, imageAlpha);}, 10);
		}
		else {
			processRunning = null;
			siteCover.style.top = '-101%';
			siteCover.style.left = '-101%';
		}
	}
}*/


/*
function closeViewer() {
	if(processRunning == null || processRunning == 'closeViewer') {
		processRunning = 'closeViewer';
		if(document.getElementById('v_desc_'+ displayedDescription)) {
			loopFunction = true;
			if(descriptionPosition < document.getElementById('v_desc_'+ displayedDescription).offsetHeight) {
				descriptionPosition += Math.ceil((document.getElementById('v_desc_'+ displayedDescription).offsetHeight - descriptionPosition) / 8);
			}
			else {
				descriptionPosition = document.getElementById('v_desc_'+ displayedDescription).offsetHeight;
				while(document.getElementById('v_features').childNodes[0]) {
					document.getElementById('v_features').removeChild(document.getElementById('v_features').childNodes[0]);
				}
				document.getElementById('v_desc_'+ displayedDescription).style.display = 'none';
				if(closePosition < 25) {
					closePosition += Math.ceil((25 - closePosition) / 4);
				}
				else {
					closePosition = 25;
				}
				document.getElementById('v_closetab').style.top = '-'+ closePosition +'px';
				if(imageAlpha > 0) {
					imageAlpha -= Math.ceil(imageAlpha / 4);
				}
				else {
					imageAlpha = 0;
					if(document.getElementById('v_image').childNodes[0]) {
						document.getElementById('v_image').removeChild(document.getElementById('v_image').childNodes[0]);
					}
					sizeCount++;
					var viewerWidthCount = viewerWidths.length - sizeCount;
					if(viewerWidths[viewerWidthCount]) {
						viewerWidth = viewerWidths[viewerWidthCount];
					}
					else {
						viewerWidth = 100;
					}
					document.getElementById('viewer').style.width = viewerWidth +'px';
					document.getElementById('viewer').style.marginLeft = '-'+ Math.floor(viewerWidth / 2) +'px';
					var viewerHeightCount = viewerHeights.length - sizeCount;
					if(viewerHeights[viewerHeightCount]) {
						viewerHeight = viewerHeights[viewerHeightCount];
					}
					else {
						viewerHeight = 100;
					}
					document.getElementById('viewer').style.height = viewerHeight +'px';
					document.getElementById('viewer').style.marginTop = '-'+ Math.floor(viewerHeight / 2) +'px';
					if(closePosition == 25 && (viewerWidth == 100 || viewerHeight == 100)) {
						viewerWidth = 100;
						viewerHeight = 100;
						document.getElementById('viewercontainer').style.top = '-101%';
						document.getElementById('viewercontainer').style.left = '-101%';
						if(siteCoverAlpha > 0) {
							siteCoverAlpha -= Math.ceil(siteCoverAlpha / 2);
						}
						else {
							siteCoverAlpha = 0;
							document.getElementById('sitecover').style.top = '-101%';
							document.getElementById('sitecover').style.left = '-101%';
							document.getElementById('v_desc_'+ displayedDescription).style.display = 'block';
							document.getElementById('v_desc_'+ displayedDescription).style.visibility = 'hidden';
							viewerWidths = new Array();
							viewerHeights = new Array();
							sizeCount = 1;
							loadingImage = false;
							viewerImage = new Image();
							descriptionPosition = -1;
							loopFunction = false;
							processRunning = null;
						}
						document.getElementById('sitecover').style.opacity = (siteCoverAlpha / 100);
						document.getElementById('sitecover').style.filter = 'alpha(opacity='+ siteCoverAlpha +')';
					}
				}
				if(document.getElementById('v_image').childNodes[0]) {
					document.getElementById('v_image').childNodes[0].style.opacity = (imageAlpha / 100);
					document.getElementById('v_image').childNodes[0].style.filter = 'alpha(opacity='+ imageAlpha +')';
				}
			}
			if(descriptionPosition >= 0) {
				document.getElementById('v_desc_'+ displayedDescription).style.bottom = '-'+ descriptionPosition +'px';
			}
			if(loopFunction) {
				setTimeout(function() {closeViewer();}, 10);
			}
		}
	}
}*/

/* ../arxcore/modules/core/1.0.0/files/javascript/core_admin.js */

if(window.XMLHttpRequest) {
	var _core_xmlHTTP = new XMLHttpRequest();
}
else {
	var _core_xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP');
}

var _core_oldMouseMove, _core_oldMouseUp, _core_cursorOrigX, _core_cursorOrigY;
var _core_dialogButtons = new Array(), _core_calendarResultFunction;

function core_admin_onLoad() {
	if(navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
		if(iconContainer = document.getElementById('_core_icon_container')) {
			var iconHolders = new Array();
			loginIcons = iconContainer.getElementsByTagName('div');
			for(iconCount = 0; iconCount < loginIcons.length; iconCount++) {
				if(loginIcons[iconCount].getAttribute('iconName') != 'core') {
					iconHolders[iconHolders.length] = loginIcons[iconCount];
				}
				else {
					coreIcon = loginIcons[iconCount];
				}
			}
			loginIcons = new Array();
			loginIcons[0] = coreIcon;
			for(iconCount = 0; iconCount < iconHolders.length; iconCount++) {
				loginIcons[loginIcons.length] = iconHolders[iconCount];
			}
			setTimeout(function(){_core_showIcons(loginIcons, (loginIcons.length - 1), true, -25, 62, 2, 2);}, 1000);
		}
		if(dockHori = document.getElementById('_core_dock_hori')) {
			dockHori.style.marginLeft = '-'+ Math.round(dockHori.offsetWidth / 2) +'px';
			dockHori.style.visibility = 'visible';
		}
	}
}

function _core_showIcons(loginIcons, iconCount, fadeIcon, iconLeft, iconOpacity, imageWidth, imageHeight) {
	currentIcon = loginIcons[iconCount];
	currentIcon.style.left = '50%';
	currentIcon.style.marginLeft = iconLeft;
	if(fadeIcon) {
		iconOpacity = iconOpacity + Math.ceil((100 - iconOpacity) / 2);
		imageWidth = imageWidth + Math.ceil((40 - imageWidth) / 2);
		imageHeight = imageHeight + Math.ceil((40 - imageHeight) / 2);
		
		if(imageWidth >= 40 && imageHeight >= 40) {
			fadeIcon = false;
			iconOpacity = 100;
			imageWidth = 40;
			imageHeight = 40;
		}
		
		iconImages = currentIcon.getElementsByTagName('img');
		for(imageCount = 0; imageCount < iconImages.length; imageCount++) {
			iconImages[imageCount].style.width = imageWidth;
			iconImages[imageCount].style.height = imageHeight;
			iconImages[imageCount].style.marginLeft = '-'+ (imageWidth / 2);
		}
		currentIcon.style.opacity = iconOpacity / 100;
		currentIcon.style.filter = 'alpha(opacity='+ iconOpacity +')';
	}
	else {
		iconPosition = Math.ceil(iconCount / 2);
		if(iconCount % 2 == 0) {
			iconLeft = iconLeft + Math.ceil((((iconPosition * 50) + -25) - iconLeft) / 2);
			if(iconLeft >= (iconPosition * 50) + -25) {
				iconCount--;
				fadeIcon = true;
				iconOpacity = 62;
				imageWidth = 2;
				imageHeight = 2;
				iconLeft = (iconPosition * 50) + -25;
			}
		}
		else {
			iconLeft = iconLeft + Math.floor((((iconPosition * -50) + -25) - iconLeft) / 2);
			if(iconLeft <= (iconPosition * -50) + -25) {
				iconCount--;
				fadeIcon = true;
				iconOpacity = 62;
				imageWidth = 2;
				imageHeight = 2;
				iconLeft = (iconPosition * -50) + -25;
			}
		}
		currentIcon.style.marginLeft = iconLeft;
		if(fadeIcon) {
			iconLeft = -25;
		}
	}
	if(iconCount >= 0) {
		setTimeout(function(){_core_showIcons(loginIcons, iconCount, fadeIcon, iconLeft, iconOpacity, imageWidth, imageHeight);}, 30);
	}
	else {
		if(loginContainer = document.getElementById('_core_logincontainer')) {
			targetWidth = loginContainer.offsetWidth;
			loginContainer.style.width      = '0px';
			loginContainer.style.visibility = 'visible';
			_core_openLoginContainer(loginContainer, targetWidth, 0);
		}
	}
}

function _core_openLoginContainer(loginContainer, targetWidth, fieldOpacity) {
	if(loginContainer.offsetWidth < targetWidth) {
		loginContainer.style.width      = loginContainer.offsetWidth + Math.round((targetWidth - loginContainer.offsetWidth) / 2) +'px';
		loginContainer.style.marginLeft = '-'+ Math.round(loginContainer.offsetWidth / 2) +'px';
		setTimeout(function(){_core_openLoginContainer(loginContainer, targetWidth, fieldOpacity);}, 60);
	}
	else {
		document.getElementById('_core_loginerror').style.visibility  = 'visible';
		document.getElementById('_core_loginfields').style.visibility = 'visible';
	}
}

function _core_submitLoginForm(loadedIcons, iconCount, iconOpacity) {
	iconOpacity -= 10;
	loadedIcons[iconCount].style.opacity = iconOpacity / 100;
	loadedIcons[iconCount].style.filter  = 'alpha(opacity='+ iconOpacity +')';
	if(iconOpacity > 0) {
		setTimeout(function(){_core_submitLoginForm(loadedIcons, iconCount, iconOpacity);}, 20);
	}
	else {
		if(iconCount < (loadedIcons.length - 1)) {
			setTimeout(function(){_core_submitLoginForm(loadedIcons, (iconCount + 1), 100);}, 20);
		}
		else {
			document.getElementById('frmLogin').submit();
		}
	}
}

/* ../arxcore/modules/commerce/1.0.0/files/javascript/commerce_products.js */

var _commerce_xmlHTTP, _commerce_formErrors = new Object();

function commerce_products_onLoad() {
	if(window.XMLHttpRequest) {
		_commerce_xmlHTTP = new XMLHttpRequest();
	}
	else {
		_commerce_xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if(addProductForm = document.getElementById('_commerce_frmProduct')) {
		addProductForm.onsubmit = function() {
			if(productImages = document.getElementById('_commerce_uplImages')) {
				var imagesParent = productImages.parentNode.parentNode;
				for(childCount = 1; childCount < imagesParent.childNodes.length; childCount++) {
					imagesParent.childNodes[childCount].childNodes[0].name = '_commerce_uplImages['+ (childCount - 1) +']';
					if(imagesParent.childNodes[childCount].childNodes[4] != undefined) {
						imagesParent.childNodes[childCount].childNodes[4].name = '_commerce_hdnImages['+ (childCount - 1) +']';
					}
				}
			}
			if(productFeatures = document.getElementById('_commerce_sltFeatures')) {
				var featuresParent = productFeatures.parentNode.parentNode;
				for(childCount = 1; childCount < featuresParent.childNodes.length; childCount++) {
					featuresParent.childNodes[childCount].childNodes[0].name = '_commerce_sltFeatures['+ (childCount - 1) +']';
					_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_feature', false);
					_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					_commerce_xmlHTTP.send('featureID='+ featuresParent.childNodes[childCount].childNodes[0].value);
					if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
						var featureInfo = _commerce_xmlHTTP.responseText.split(':');
						switch(featureInfo[1]) {
							case 'MULTIPLE_CHOICE':
								var arrayCount = 0;
								for(valueCount = 3; valueCount < featuresParent.childNodes[childCount].childNodes.length; valueCount++) {
									if(featuresParent.childNodes[childCount].childNodes[valueCount].childNodes[0].checked) {
										featuresParent.childNodes[childCount].childNodes[valueCount].childNodes[0].name = '_commerce_featureValues['+ (childCount - 1) +']['+ arrayCount +']';
										arrayCount++;
									}
								}
							break;
							case 'SINGLE_VALUE':
							case 'TEXT':
								for(valueCount = 3; valueCount < featuresParent.childNodes[childCount].childNodes.length; valueCount++) {
									featuresParent.childNodes[childCount].childNodes[valueCount].name = '_commerce_featureValues['+ (childCount - 1) +']';
								}
							break;
						}
					}
				}
			}
			if(productGroups = document.getElementById('_commerce_sltGroups')) {
				var groupsParent = productGroups.parentNode.parentNode;
				for(childCount = 1; childCount < groupsParent.childNodes.length; childCount++) {
					groupsParent.childNodes[childCount].childNodes[0].name = '_commerce_sltGroups['+ (childCount - 1) +']';
				}
			}
			if(variationFields = document.getElementById('_commerce_sltVariations')) {
				var fieldsParent = variationFields.parentNode.parentNode;
				var fieldValues = new Array();
				for(childCount = 1; childCount < fieldsParent.childNodes.length; childCount++) {
					fieldsParent.childNodes[childCount].childNodes[0].name = '_commerce_sltVariations['+ (childCount - 1) +']';
					if(fieldsParent.childNodes[childCount].childNodes[0].value != '') {
						fieldValues[fieldValues.length] = fieldsParent.childNodes[childCount].childNodes[0].value;
					}
				}
				if(variationCode = document.getElementById('_commerce_txtVariationCode')) {
					var variationsList = variationCode.parentNode.parentNode;
					for(listCount = 1; listCount < variationsList.childNodes.length; listCount++) {
						variationsList.childNodes[listCount].childNodes[0].name = '_commerce_txtVariationCode['+ (listCount - 1) +']';
						variationsList.childNodes[listCount].childNodes[1].name = '_commerce_txtVariationPrice['+ (listCount - 1) +']';
						for(valueCount = 0; valueCount < fieldValues.length; valueCount++) {
							variationsList.childNodes[listCount].childNodes[(valueCount + 4)].name = '_commerce_txtVariationValue'+ fieldValues[valueCount] +'['+ (listCount - 1) +']';
						}
					}
				}
			}
		}
	}
	
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_errors', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var errorFields = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(errorCount = 0; errorCount < errorFields.length; errorCount++) {
			var errorField = errorFields[errorCount].split(':');
			_commerce_formErrors[errorField[0]] = errorField[1];
		}
	}
	
	if(hasVariationsNo = document.getElementById('_commerce_rdbHasVariations_No')) {
		hasVariationsNo.onchange = function() {
			_commerce_toggleProductVariations(this.value);
		}
		if(hasVariationsNo.checked) {
			_commerce_toggleProductVariations(hasVariationsNo.value);
		}
	}
	if(hasVariationsYes = document.getElementById('_commerce_rdbHasVariations_Yes')) {
		hasVariationsYes.onchange = function() {
			_commerce_toggleProductVariations(this.value);
		}
		if(hasVariationsYes.checked) {
			_commerce_toggleProductVariations(hasVariationsYes.value);
		}
	}
	
	if(productImages = document.getElementById('_commerce_uplImages')) {
		_commerce_imagesJacker(productImages);
	}
	if(productFeatures = document.getElementById('_commerce_sltFeatures')) {
		_commerce_featuresJacker(productFeatures);
		_commerce_checkProductFeature(productFeatures);
		productFeatures.onchange = function() {
			_commerce_checkProductFeature(productFeatures);
		}
	}
	if(productGroups = document.getElementById('_commerce_sltGroups')) {
		_commerce_groupsJacker(productGroups);
	}
	if(productVariations = document.getElementById('_commerce_sltVariations')) {
		_commerce_variationsJacker(productVariations);
	}
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/remove_form_session', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct');
}

/* Delete Product */

function _commerce_deleteProduct() {
	if(productID = document.getElementById('_commerce_hdnProductID')) {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/delete_product', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('productID='+ productID.value);
		location.href = '/_admin/commerce/index.page';
	}
}

/* Toggle Product Variations */

function _commerce_toggleProductVariations(hasVariations) {
	if(withoutVariations = document.getElementById('_commerce_withoutvariations')) {
		if(withVariations = document.getElementById('_commerce_withvariations')) {
			if(hasVariations == 'Yes') {
				withoutVariations.style.display = 'none';
				withVariations.style.display = 'block';
			}
			else {
				withoutVariations.style.display = 'block';
				withVariations.style.display = 'none';
			}
		}
	}
}

/* Product Images */

function _commerce_imagesJacker(imageInput) {
	var _commerce_imageAdd = document.createElement('input');
	_commerce_imageAdd.type = 'button';
	_commerce_imageAdd.className = '_core_selectbutton';
	_commerce_imageAdd.value = '+';
	
	var _commerce_imageRemove = document.createElement('input');
	_commerce_imageRemove.type = 'button';
	_commerce_imageRemove.className = '_core_selectbutton';
	_commerce_imageRemove.value = '-';
	
	var _commerce_imageCopy = imageInput.parentNode.cloneNode(true);
	
	imageInput.parentNode.appendChild(_commerce_imageAdd.cloneNode(false));
	imageInput.parentNode.appendChild(_commerce_imageRemove.cloneNode(false));
	imageInput.parentNode.childNodes[1].onclick = function(){_commerce_addImage(this)};
	imageInput.parentNode.childNodes[2].style.visibility = 'hidden';
	
	function _commerce_addImage(callingElement, addToEnd) {
		var addToEnd = (addToEnd == null) ? false : addToEnd;
		
		var imageParent = _commerce_imageCopy.cloneNode(true);
		while(imageParent.childNodes.length > 1) {
			imageParent.removeChild(imageParent.lastChild);
		}
		imageParent.appendChild(_commerce_imageAdd.cloneNode(false));
		imageParent.appendChild(_commerce_imageRemove.cloneNode(false));
		imageParent.childNodes[1].onclick = function(){_commerce_addImage(this)};
		imageParent.childNodes[2].onclick = function(){_commerce_removeImage(this)};
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode || addToEnd) {
			callingElement.parentNode.parentNode.appendChild(imageParent);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(imageParent, callingElement.parentNode.nextSibling);
		}
	}
	
	function _commerce_removeImage(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
	}
	
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_hdnImages');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var processedImages = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(imageCount = 0; imageCount < processedImages.length; imageCount++) {
			if(processedImages[imageCount] != '') {
				var imageParent = imageInput.parentNode.parentNode;
				var imagePreview = document.createElement('img');
				imagePreview.src = '/_files/images/_commerce/productimages/preview/'+ processedImages[imageCount] +'.jpg';
				imagePreview.className = '_commerce_productdetails_images';
				imageParent.childNodes[(imageCount + 1)].appendChild(imagePreview);
				var valuePreview = document.createElement('input');
				valuePreview.type = 'hidden';
				valuePreview.value = processedImages[imageCount];
				imageParent.childNodes[(imageCount + 1)].appendChild(valuePreview);
			}
			if(imageCount < processedImages.length - 1) {
				_commerce_addImage(imageInput, true);
			}
		}
	}
}

/* Product Features */

function _commerce_openFeaturesList() {
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Add', 'Add Feature', 'javascript:_commerce_openShowFeature();');
	dialogButtons[1] = new Array('Edit', 'Edit Feature', 'javascript:_commerce_openEditFeature();');
	_core_openDialogBox('commerce', 'Features List', 'This is where you can add and update features for your products. To add a new feature simply click on the button marked \'Add Feature\'; to update an existing feature, first select it from the list followed by clicking on the button marked \'Edit Feature\'.', dialogButtons, true, '/_include/_admin/commerce/features_list.include', 'Close');
	if(featuresList = document.getElementById('_commerce_featureslist')) {
		_commerce_xmlHTTP.open('GET', '/_action/commerce/products/list_features', false);
		_commerce_xmlHTTP.send('');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var liveFeatures = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(featureCount = 0; featureCount < liveFeatures.length; featureCount++) {
				var featureInfo = liveFeatures[featureCount].split(':');
				var featureID = featureInfo[0];
				var featureType = featureInfo[1];
				featureInfo.splice(0, 2);
				var featureName = featureInfo.join(':');
				var listItem = document.createElement('div');
				listItem.id = '_commerce_tempFeature'+ featureID;
				listItem.className = '_commerce_listitem';
				listItem.setAttribute('featureID', featureID);
				listItem.onclick = function() {
					this.style.color = 'rgb(255,255,255)';
					this.style.backgroundColor = 'rgb(170,0,0)';
					var currentItem = document.getElementById('_commerce_featureslist').getAttribute('currentItem');
					if(currentItem != '' && currentItem != null) {
						document.getElementById(currentItem).style.color = 'rgb(25,25,25)';
						document.getElementById(currentItem).style.backgroundColor = 'transparent';
					}
					document.getElementById('_commerce_featureslist').setAttribute('currentItem', this.id);
				}
				var itemName = document.createElement('div');
				itemName.className = '_commerce_itemname';
				itemName.innerHTML = featureName;
				listItem.appendChild(itemName);
				var itemType = document.createElement('div');
				itemType.className = '_commerce_itemtype';
				itemType.innerHTML = 'Type: '+ featureType;
				listItem.appendChild(itemType);
				featuresList.appendChild(listItem);
				if(featureCount < liveFeatures.length - 1) {
					var listDivider = document.createElement('div');
					listDivider.className = '_commerce_listdivider _core_swatch_greylgt_bg';
					featuresList.appendChild(listDivider);
				}
			}
		}
	}
}

function _commerce_openEditFeature() {
	var currentItem = document.getElementById('_commerce_featureslist').getAttribute('currentItem');
	if(currentItem != '' && currentItem != null) {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_feature', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('featureID='+ document.getElementById(currentItem).getAttribute('featureID'));
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var existingValues = new Object;
			var featureInfo = _commerce_xmlHTTP.responseText.split(':');
			existingValues['featureID'] = featureInfo[0];
			existingValues['featureType'] = featureInfo[1];
			featureInfo.splice(0, 2);
			existingValues['featureName'] = featureInfo.join(':');
			if(existingValues['featureType'] == 'MULTIPLE_CHOICE') {
				_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_feature_options', false);
				_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				_commerce_xmlHTTP.send('featureID='+ document.getElementById(currentItem).getAttribute('featureID'));
				if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
					existingValues['featureOptions'] = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
				}
			}
			_commerce_openShowFeature(existingValues);
		}
		else {
			_commerce_openFeaturesList();
		}
	}
	else {
		_commerce_openFeaturesList();
	}
}

function _commerce_openShowFeature(existingValues, warningText) {
	var existingValues = (existingValues == null) ? null : existingValues;
	var warningText = (warningText == null) ? '' : '<br /><br /><b>'+ warningText +'</b>';
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Save', 'Save Feature', 'javascript:_commerce_saveFeature();');
	_core_openDialogBox('commerce', 'Product Feature', 'Make your changes by filling out the boxes below followed by clicking on the button marked \'Save Feature\'.'+ warningText, dialogButtons, true, '/_include/_admin/commerce/features_form.include');
	var featureOptions = null;
	if(existingValues) {
		if(existingValues['featureID'] != null && existingValues['featureID'] != '') {
			document.getElementById('_commerce_hdnFeatureID').value = existingValues['featureID'];
		}
		if(existingValues['featureName'] != null && existingValues['featureName'] != '') {
			document.getElementById('_commerce_txtFeatureName').value = existingValues['featureName'];
		}
		if(existingValues['featureType'] != null && existingValues['featureType'] != '') {
			document.getElementById('_commerce_sltFeatureType').value = existingValues['featureType'];
		}
		featureOptions = existingValues['featureOptions'];
	}
	if(featureOption = document.getElementById('_commerce_txtFeatureOption')) {
		_commerce_featureOptionsJacker(featureOption, featureOptions);
	}
	if(featureType = document.getElementById('_commerce_sltFeatureType')) {
		checkFeatureType(featureType.value);
		featureType.onchange = function() {
			checkFeatureType(this.value);
		}
	}
}

function checkFeatureType(typeValue) {
	switch(typeValue) {
		case 'MULTIPLE_CHOICE':
			if(featureOptions = document.getElementById('_commerce_featureOptions')) {
				featureOptions.style.display = 'inline';
			}
		break;
		default:
			if(featureOptions = document.getElementById('_commerce_featureOptions')) {
				featureOptions.style.display = 'none';
			}
	}
}

function _commerce_featureOptionsJacker(featureSelect, featureOptions) {
	var featureOptions = (featureOptions == null) ? new Array() : featureOptions;
	var featureAdd = document.createElement('input');
	featureAdd.type = 'button';
	featureAdd.className = '_core_selectbutton';
	featureAdd.value = '+';
	
	var featureRemove = document.createElement('input');
	featureRemove.type = 'button';
	featureRemove.className = '_core_selectbutton';
	featureRemove.value = '-';
	
	var featureParent = featureSelect.parentNode.cloneNode(true);
	featureParent.appendChild(featureAdd);
	featureParent.appendChild(featureRemove);
	
	featureSelect.parentNode.appendChild(featureAdd.cloneNode(false));
	featureSelect.parentNode.childNodes[1].onclick = function(){addFeature(this)};
	
	if(featureOptions.length > 0) {
		for(optionCount = 1; optionCount < featureOptions.length; optionCount++) {
			addFeature(featureSelect);
		}
		var optionElements = featureSelect.parentNode.parentNode.childNodes;
		for(optionCount = 1; optionCount < optionElements.length; optionCount++) {
			optionElements[optionCount].childNodes[0].value = featureOptions[optionCount - 1];
		}
	}
	
	function addFeature(callingElement) {
		var parentCopy = featureParent.cloneNode(true);
		parentCopy.childNodes[1].onclick = function(){addFeature(this)};
		parentCopy.childNodes[2].onclick = function(){removeFeature(this)};
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode) {
			callingElement.parentNode.parentNode.appendChild(parentCopy);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(parentCopy, callingElement.parentNode.nextSibling);
		}
	}
	
	function removeFeature(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
	}
}

function _commerce_saveFeature() {
	var saveFeature = true;
	var errText = '';
	var featureID = document.getElementById('_commerce_hdnFeatureID').value;
	var featureName = '';
	if(document.getElementById('_commerce_txtFeatureName').value != 'feature name' && document.getElementById('_commerce_txtFeatureName').value != '' && document.getElementById('_commerce_txtFeatureName').value != null) {
		var featureName = document.getElementById('_commerce_txtFeatureName').value;
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/check_feature', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('featureID='+ featureID +'&featureName='+ featureName);
		if(_commerce_xmlHTTP.responseText != 'continue') {
			saveFeature = false;
			errText = 'The name entered has already been taken, please enter a different name';
		}
	}
	else {
		saveFeature = false;
		errText = 'Please ensure all fields are filled out before saving the feature';
	}
	var featureType = document.getElementById('_commerce_sltFeatureType').value;
	var optionList = new Array();
	if(featureType == 'MULTIPLE_CHOICE') {
		var featureOptions = document.getElementById('_commerce_txtFeatureOption').parentNode.parentNode.childNodes;
		for(optionCount = 1; optionCount < featureOptions.length; optionCount++) {
			if(featureOptions[optionCount].childNodes[0].value != null && featureOptions[optionCount].childNodes[0].value != '') {
				optionList[optionList.length] = featureOptions[optionCount].childNodes[0].value;
			}
			else {
				saveFeature = false;
				errText = 'Please ensure all fields are filled out before saving the feature';
			}
		}
	}
	if(!saveFeature) {
		var existingValues = new Object;
		existingValues['featureID'] = featureID;
		existingValues['featureName'] = featureName;
		existingValues['featureType'] = featureType;
		existingValues['featureOptions'] = optionList;
		_commerce_openShowFeature(existingValues, errText);
	}
	else {
		optionList.sort();
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/save_feature', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('featureID='+ featureID +'&featureName='+ featureName +'&featureType='+ featureType +'&featureOptions="'+ optionList.join('","') +'"');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var featureList = new Array();
			var liveFeatures = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(featureCount = 0; featureCount < liveFeatures.length; featureCount++) {
				var featureFields = new Object();
				var featureInfo = liveFeatures[featureCount].split(':');
				featureFields['featureID'] = featureInfo[0];
				featureFields['featureType'] = featureInfo[1];
				featureInfo.splice(0, 2);
				featureFields['featureName'] = featureInfo.join(':');
				featureList[featureList.length] = featureFields;
			}
			if(productFeatures = document.getElementById('_commerce_sltFeatures')) {
				var featureParent = productFeatures.parentNode.parentNode;
				for(childCount = 1; childCount < featureParent.childNodes.length; childCount++) {
					var oldSelectedOption = featureParent.childNodes[childCount].childNodes[0].options[featureParent.childNodes[childCount].childNodes[0].selectedIndex].value;
					while(featureParent.childNodes[childCount].childNodes[0].options.length > 0) {
						featureParent.childNodes[childCount].childNodes[0].remove(featureParent.childNodes[childCount].childNodes[0].options.length - 1);
					}
					for(featureCount = 0; featureCount < featureList.length; featureCount++) {
						if(featureList[featureCount]['featureID'] == oldSelectedOption) {
							var newSelectedOption = featureCount;
						}
						featureParent.childNodes[childCount].childNodes[0].add(new Option(featureList[featureCount]['featureName'] +' ('+ featureList[featureCount]['featureType'] +')', featureList[featureCount]['featureID']));
					}
					if(newSelectedOption != null) {
						featureParent.childNodes[childCount].childNodes[0].selectedIndex = newSelectedOption;
					}
					else {
						featureParent.childNodes[childCount].childNodes[0].selectedIndex = 0;
					}
					featureParent.childNodes[childCount].childNodes[0].onchange();
				}
			}
		}
		_commerce_openFeaturesList();
	}
}

function _commerce_featuresJacker(featureSelect) {
	var _commerce_featureAdd = document.createElement('input');
	_commerce_featureAdd.type = 'button';
	_commerce_featureAdd.className = '_core_selectbutton';
	_commerce_featureAdd.value = '+';
	
	var _commerce_featureRemove = document.createElement('input');
	_commerce_featureRemove.type = 'button';
	_commerce_featureRemove.className = '_core_selectbutton';
	_commerce_featureRemove.value = '-';
	
	featureSelect.parentNode.appendChild(_commerce_featureAdd.cloneNode(false));
	featureSelect.parentNode.appendChild(_commerce_featureRemove.cloneNode(false));
	featureSelect.parentNode.childNodes[1].onclick = function(){_commerce_addFeature(this)};
	featureSelect.parentNode.childNodes[2].style.visibility = 'hidden';
	
	function _commerce_addFeature(callingElement, addToEnd) {
		var addToEnd = (addToEnd == null) ? false : addToEnd;
		
		var featureParent = callingElement.parentNode.cloneNode(true);
		while(featureParent.childNodes.length > 1) {
			featureParent.removeChild(featureParent.lastChild);
		}
		featureParent.childNodes[0].onchange = function() {
			_commerce_checkProductFeature(this);
		}
		featureParent.appendChild(_commerce_featureAdd.cloneNode(false));
		featureParent.appendChild(_commerce_featureRemove.cloneNode(false));
		featureParent.childNodes[1].onclick = function(){_commerce_addFeature(this)};
		featureParent.childNodes[2].onclick = function(){_commerce_removeFeature(this)};
		_commerce_checkProductFeature(featureParent.childNodes[0]);
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode || addToEnd) {
			callingElement.parentNode.parentNode.appendChild(featureParent);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(featureParent, callingElement.parentNode.nextSibling);
		}
	}
	
	function _commerce_removeFeature(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
	}
	
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_sltFeatures');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var selectedFeatures = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(featureCount = 0; featureCount < selectedFeatures.length; featureCount++) {
			var featureParent = featureSelect.parentNode.parentNode;
			featureParent.childNodes[(featureCount + 1)].childNodes[0].value = selectedFeatures[featureCount];
			_commerce_checkProductFeature(featureParent.childNodes[(featureCount + 1)].childNodes[0]);
			if(featureCount < selectedFeatures.length - 1) {
				_commerce_addFeature(featureSelect, true);
			}
		}
	}
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_featureValues');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var featureValues = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(valueCount = 0; valueCount < featureValues.length; valueCount++) {
			var featureParent = featureSelect.parentNode.parentNode;
			if(featureValues[valueCount].indexOf('[') == 0) {
				var multipleValues = featureValues[valueCount].substr(1, featureValues[valueCount].length - 2).split('][');
				for(multipleCount = 0; multipleCount < multipleValues.length; multipleCount++) {
					for(elementCount = 3; elementCount < featureParent.childNodes[(valueCount + 1)].childNodes.length; elementCount++) {
						if(multipleValues[multipleCount] == featureParent.childNodes[(valueCount + 1)].childNodes[elementCount].childNodes[0].value ) {
							featureParent.childNodes[(valueCount + 1)].childNodes[elementCount].childNodes[0].checked = true;
						}
					}
				}
			}
			else {
				featureParent.childNodes[(valueCount + 1)].childNodes[3].value = featureValues[valueCount];
			}
		}
	}
}

function _commerce_checkProductFeature(productFeatures) {
	var existingValues = new Array();
	if(productFeatures.parentNode.childNodes.length > 3) {
		while(productFeatures.parentNode.childNodes.length > 3) {
			switch(productFeatures.getAttribute('previousType')) {
				case 'MULTIPLE_CHOICE':
					if(productFeatures.parentNode.lastChild.childNodes[0].checked) {
						existingValues[existingValues.length] = productFeatures.parentNode.lastChild.childNodes[0].value;
					}
				break;
				case 'SINGLE_VALUE':
				case 'TEXT':
					existingValues[existingValues.length] = productFeatures.parentNode.lastChild.value;
				break;
			}
			productFeatures.parentNode.removeChild(productFeatures.parentNode.lastChild);
		}
	}
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_feature', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('featureID='+ productFeatures.value);
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var featureInfo = _commerce_xmlHTTP.responseText.split(':');
		switch(featureInfo[1]) {
			case 'MULTIPLE_CHOICE':
				_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_feature_options', false);
				_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				_commerce_xmlHTTP.send('featureID='+ productFeatures.value);
				if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
					var featureOptions = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
					for(optionCount = 0; optionCount < featureOptions.length; optionCount++) {
						var optionContainer = document.createElement('span');
						optionContainer.className = '_core_option _commerce_productfeatures_option';
						var optionElement = document.createElement('input');
						optionElement.className = '_core_checkbox';
						optionElement.type = 'checkbox';
						for(valueCount = 0; valueCount < existingValues.length; valueCount++) {
							if(featureOptions[optionCount] == existingValues[valueCount]) {
								optionElement.checked = true;
							}
						}
						optionElement.value = featureOptions[optionCount];
						optionContainer.appendChild(optionElement);
						var optionValue = document.createElement('span');
						optionValue.className = '_core_option_value _commerce_productfeatures_optionvalue';
						optionValue.innerHTML = featureOptions[optionCount];
						optionContainer.appendChild(optionValue);
						productFeatures.parentNode.appendChild(optionContainer);
					}
				}
			break;
			case 'SINGLE_VALUE':
				var singleValueElement = document.createElement('input');
				singleValueElement.className = '_core_textbox _commerce_productfeatures_singlevalue';
				singleValueElement.type = 'text';
				if(existingValues[0] != undefined) {
					singleValueElement.value = existingValues[0];
				}
				productFeatures.parentNode.appendChild(singleValueElement);
			break;
			case 'TEXT':
				var textElement = document.createElement('textarea');
				textElement.className = '_core_textarea _commerce_productfeatures_text';
				if(existingValues[0] != undefined) {
					textElement.value = existingValues[0];
				}
				productFeatures.parentNode.appendChild(textElement);
			break;
		}
		productFeatures.setAttribute('previousType', featureInfo[1]);
	}
}

/* Product Groups */

function _commerce_groupsJacker(groupSelect) {
	var _commerce_groupAdd = document.createElement('input');
	_commerce_groupAdd.type = 'button';
	_commerce_groupAdd.className = '_core_selectbutton';
	_commerce_groupAdd.value = '+';
	
	var _commerce_groupRemove = document.createElement('input');
	_commerce_groupRemove.type = 'button';
	_commerce_groupRemove.className = '_core_selectbutton';
	_commerce_groupRemove.value = '-';
	
	groupSelect.parentNode.appendChild(_commerce_groupAdd.cloneNode(false));
	groupSelect.parentNode.appendChild(_commerce_groupRemove.cloneNode(false));
	groupSelect.parentNode.childNodes[1].onclick = function(){_commerce_addGroup(this)};
	groupSelect.parentNode.childNodes[2].style.visibility = 'hidden';
	
	function _commerce_addGroup(callingElement, addToEnd) {
		var addToEnd = (addToEnd == null) ? false : addToEnd;
		
		var groupParent = callingElement.parentNode.cloneNode(true);
		while(groupParent.childNodes.length > 1) {
			groupParent.removeChild(groupParent.lastChild);
		}
		groupParent.appendChild(_commerce_groupAdd.cloneNode(false));
		groupParent.appendChild(_commerce_groupRemove.cloneNode(false));
		groupParent.childNodes[1].onclick = function(){_commerce_addGroup(this)};
		groupParent.childNodes[2].onclick = function(){_commerce_removeGroup(this)};
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode || addToEnd) {
			callingElement.parentNode.parentNode.appendChild(groupParent);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(groupParent, callingElement.parentNode.nextSibling);
		}
	}
	
	function _commerce_removeGroup(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
	}
	
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_sltGroups');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var selectedGroups = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(groupCount = 0; groupCount < selectedGroups.length; groupCount++) {
			var groupParent = groupSelect.parentNode.parentNode;
			groupParent.childNodes[(groupCount + 1)].childNodes[0].value = selectedGroups[groupCount];
			if(groupCount < selectedGroups.length - 1) {
				_commerce_addGroup(groupSelect, true);
			}
		}
	}
}

function _commerce_openGroupsList() {
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Add', 'Add Group', 'javascript:_commerce_openShowGroup();');
	dialogButtons[1] = new Array('Edit', 'Edit Group', 'javascript:_commerce_openEditGroup();');
	_core_openDialogBox('commerce', 'Groups List', 'This is where you can add and update groups for your products. To add a new group simply click on the button marked \'Add Group\'; to update an existing group, first select it from the list followed by clicking on the button marked \'Edit Group\'.', dialogButtons, true, '/_include/_admin/commerce/groups_list.include', 'Close');
	if(groupsList = document.getElementById('_commerce_groupslist')) {
		_commerce_xmlHTTP.open('GET', '/_action/commerce/products/list_groups', false);
		_commerce_xmlHTTP.send('');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var liveGroups = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			var typeList = new Object();
			_commerce_xmlHTTP.open('POST', '/_action/commerce/products/list_group_types', false);
			_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			_commerce_xmlHTTP.send('');
			if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
				var liveTypes = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
				for(typeCount = 0; typeCount < liveTypes.length; typeCount++) {
					var typeInfo = liveTypes[typeCount].split(':');
					var typeID = typeInfo[0];
					typeInfo.splice(0, 1);
					typeList[typeID] = typeInfo.join(':');
				}
			}
			for(groupCount = 0; groupCount < liveGroups.length; groupCount++) {
				var groupInfo = liveGroups[groupCount].split(':');
				var groupID = groupInfo[0];
				var groupType = groupInfo[1];
				groupInfo.splice(0, 2);
				var groupName = groupInfo.join(':');
				var listItem = document.createElement('div');
				listItem.id = '_commerce_tempGroup'+ groupID;
				listItem.className = '_commerce_listitem';
				listItem.setAttribute('groupID', groupID);
				listItem.onclick = function() {
					this.style.color = 'rgb(255,255,255)';
					this.style.backgroundColor = 'rgb(170,0,0)';
					var currentItem = document.getElementById('_commerce_groupslist').getAttribute('currentItem');
					if(currentItem != '' && currentItem != null) {
						document.getElementById(currentItem).style.color = 'rgb(25,25,25)';
						document.getElementById(currentItem).style.backgroundColor = 'transparent';
					}
					document.getElementById('_commerce_groupslist').setAttribute('currentItem', this.id);
				}
				var itemName = document.createElement('div');
				itemName.className = '_commerce_itemname';
				itemName.innerHTML = groupName;
				listItem.appendChild(itemName);
				var itemType = document.createElement('div');
				itemType.className = '_commerce_itemtype';
				itemType.innerHTML = 'Type: '+ typeList[groupType];
				listItem.appendChild(itemType);
				groupsList.appendChild(listItem);
				if(groupCount < liveGroups.length - 1) {
					var listDivider = document.createElement('div');
					listDivider.className = '_commerce_listdivider _core_swatch_greylgt_bg';
					groupsList.appendChild(listDivider);
				}
			}
		}
	}
}

function _commerce_openEditGroup() {
	var currentItem = document.getElementById('_commerce_groupslist').getAttribute('currentItem');
	if(currentItem != '' && currentItem != null) {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_group', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('groupID='+ document.getElementById(currentItem).getAttribute('groupID'));
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var existingValues = new Object;
			var groupInfo = _commerce_xmlHTTP.responseText.split(':');
			existingValues['groupID'] = groupInfo[0];
			existingValues['groupType'] = groupInfo[1];
			groupInfo.splice(0, 2);
			existingValues['groupName'] = groupInfo.join(':');
			_commerce_openShowGroup(existingValues);
		}
		else {
			_commerce_openGroupsList();
		}
	}
	else {
		_commerce_openGroupsList();
	}
}

function _commerce_openShowGroup(existingValues, warningText) {
	var existingValues = (existingValues == null) ? null : existingValues;
	var warningText = (warningText == null) ? '' : '<br /><br /><b>'+ warningText +'</b>';
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Save', 'Save Group', 'javascript:_commerce_saveGroup();');
	_core_openDialogBox('commerce', 'Product Group', 'Make your changes by filling out the box below followed by clicking on the button marked \'Save Group\'.'+ warningText, dialogButtons, true, '/_include/_admin/commerce/groups_form.include');
	if(existingValues) {
		if(existingValues['groupID'] != null && existingValues['groupID'] != '') {
			document.getElementById('_commerce_hdnGroupID').value = existingValues['groupID'];
		}
		if(existingValues['groupName'] != null && existingValues['groupName'] != '') {
			document.getElementById('_commerce_txtGroupName').value = existingValues['groupName'];
		}
		if(existingValues['groupType'] != null && existingValues['groupType'] != '') {
			document.getElementById('_commerce_sltGroupType').value = existingValues['groupType'];
		}
	}
}

function _commerce_saveGroup() {
	var saveGroup = true;
	var errText = '';
	var groupID = document.getElementById('_commerce_hdnGroupID').value;
	var groupName = '';
	if(document.getElementById('_commerce_txtGroupName').value != 'group name' && document.getElementById('_commerce_txtGroupName').value != '' && document.getElementById('_commerce_txtGroupName').value != null) {
		var groupName = document.getElementById('_commerce_txtGroupName').value;
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/check_group', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('groupID='+ groupID +'&groupName='+ groupName);
		if(_commerce_xmlHTTP.responseText != 'continue') {
			saveGroup = false;
			errText = 'The name entered has already been taken, please enter a different name';
		}
	}
	else {
		saveGroup = false;
		errText = 'Please ensure all fields are filled out before saving the group';
	}
	var groupType = document.getElementById('_commerce_sltGroupType').value;
	if(!saveGroup) {
		var existingValues = new Object;
		existingValues['groupID'] = groupID;
		existingValues['groupType'] = groupType;
		existingValues['groupName'] = groupName;
		_commerce_openShowGroup(existingValues, errText);
	}
	else {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/save_group', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('groupID='+ groupID +'&groupName='+ groupName +'&groupType='+ groupType);
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var groupList = new Array();
			var liveGroups = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(groupCount = 0; groupCount < liveGroups.length; groupCount++) {
				var groupFields = new Object();
				var groupInfo = liveGroups[groupCount].split(':');
				groupFields['groupID'] = groupInfo[0];
				groupFields['groupType'] = groupInfo[1];
				groupInfo.splice(0, 2);
				groupFields['groupName'] = groupInfo.join(':');
				groupList[groupList.length] = groupFields;
			}
			if(productGroups = document.getElementById('_commerce_sltGroups')) {
				var typeList = new Object();
				_commerce_xmlHTTP.open('POST', '/_action/commerce/products/list_group_types', false);
				_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				_commerce_xmlHTTP.send('');
				if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
					var liveTypes = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
					for(typeCount = 0; typeCount < liveTypes.length; typeCount++) {
						var typeInfo = liveTypes[typeCount].split(':');
						var typeID = typeInfo[0];
						typeInfo.splice(0, 1);
						typeList[typeID] = typeInfo.join(':');
					}
				}
				var groupParent = productGroups.parentNode.parentNode;
				for(childCount = 1; childCount < groupParent.childNodes.length; childCount++) {
					var oldSelectedOption = groupParent.childNodes[childCount].childNodes[0].options[groupParent.childNodes[childCount].childNodes[0].selectedIndex].value;
					while(groupParent.childNodes[childCount].childNodes[0].options.length > 0) {
						groupParent.childNodes[childCount].childNodes[0].remove(groupParent.childNodes[childCount].childNodes[0].options.length - 1);
					}
					groupParent.childNodes[childCount].childNodes[0].add(new Option('Please select...', ''));
					for(groupCount = 0; groupCount < groupList.length; groupCount++) {
						if(groupList[groupCount]['groupID'] == oldSelectedOption) {
							var newSelectedOption = groupCount;
						}
						groupParent.childNodes[childCount].childNodes[0].add(new Option(groupList[groupCount]['groupName'] +' ('+ typeList[groupList[groupCount]['groupType']] +')', groupList[groupCount]['groupID']));
					}
					if(newSelectedOption != null) {
						groupParent.childNodes[childCount].childNodes[0].selectedIndex = newSelectedOption + 1;
					}
					else {
						groupParent.childNodes[childCount].childNodes[0].selectedIndex = 0;
					}
				}
			}
		}
		_commerce_openGroupsList();
	}
}

/* Product Variations */

function _commerce_variationsJacker(variationSelect) {
	var _commerce_variationAdd = document.createElement('input');
	_commerce_variationAdd.type = 'button';
	_commerce_variationAdd.className = '_core_selectbutton';
	_commerce_variationAdd.value = '+';
	
	var _commerce_variationRemove = document.createElement('input');
	_commerce_variationRemove.type = 'button';
	_commerce_variationRemove.className = '_core_selectbutton';
	_commerce_variationRemove.value = '-';
	
	variationSelect.parentNode.appendChild(_commerce_variationAdd.cloneNode(false));
	variationSelect.parentNode.appendChild(_commerce_variationRemove.cloneNode(false));
	variationSelect.parentNode.childNodes[0].onchange = function(){_commerce_checkVariationFields();};
	variationSelect.parentNode.childNodes[1].onclick = function(){_commerce_addVariation(this)};
	variationSelect.parentNode.childNodes[2].style.visibility = 'hidden';
	
	function _commerce_addVariation(callingElement, addToEnd) {
		var addToEnd = (addToEnd == null) ? false : addToEnd;
		
		var variationParent = callingElement.parentNode.cloneNode(true);
		while(variationParent.childNodes.length > 1) {
			variationParent.removeChild(variationParent.lastChild);
		}
		variationParent.appendChild(_commerce_variationAdd.cloneNode(false));
		variationParent.appendChild(_commerce_variationRemove.cloneNode(false));
		variationParent.childNodes[0].onchange = function(){_commerce_checkVariationFields();};
		variationParent.childNodes[1].onclick = function(){_commerce_addVariation(this)};
		variationParent.childNodes[2].onclick = function(){_commerce_removeVariation(this)};
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode || addToEnd) {
			callingElement.parentNode.parentNode.appendChild(variationParent);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(variationParent, callingElement.parentNode.nextSibling);
		}
		_commerce_checkVariationFields();
	}
	
	function _commerce_removeVariation(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
		_commerce_checkVariationFields();
	}
	
	if(variationCode = document.getElementById('_commerce_txtVariationCode')) {
		_commerce_variationsListJacker(variationCode, false);
	}
	_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
	_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_sltVariations');
	if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
		var selectedVariations = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
		for(variationCount = 0; variationCount < selectedVariations.length; variationCount++) {
			var variationParent = variationSelect.parentNode.parentNode;
			variationParent.childNodes[(variationCount + 1)].childNodes[0].value = selectedVariations[variationCount];
			if(variationCount < selectedVariations.length - 1) {
				_commerce_addVariation(variationSelect, true);
			}
		}
	}
	
	_commerce_checkVariationFields();
	if(variationCode = document.getElementById('_commerce_txtVariationCode')) {
		_commerce_variationsListJacker(variationCode, true);
	}
}

function _commerce_openVariationsList() {
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Add', 'Add Variation', 'javascript:_commerce_openShowVariation();');
	dialogButtons[1] = new Array('Edit', 'Edit Variation', 'javascript:_commerce_openEditVariation();');
	_core_openDialogBox('commerce', 'Variations List', 'This is where you can add and update variation fields for your products. To add a new variation field simply click on the button marked \'Add Variation\'; to update an existing variation field, first select it from the list followed by clicking on the button marked \'Edit Variation\'.', dialogButtons, true, '/_include/_admin/commerce/variations_list.include', 'Close');
	if(variationsList = document.getElementById('_commerce_variationslist')) {
		_commerce_xmlHTTP.open('GET', '/_action/commerce/products/list_variation_fields', false);
		_commerce_xmlHTTP.send('');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var liveVariations = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(variationCount = 0; variationCount < liveVariations.length; variationCount++) {
				var variationInfo = liveVariations[variationCount].split(':');
				var variationID = variationInfo[0];
				variationInfo.splice(0, 1);
				var variationName = variationInfo.join(':');
				var listItem = document.createElement('div');
				listItem.id = '_commerce_tempVariation'+ variationID;
				listItem.className = '_commerce_listitem';
				listItem.setAttribute('variationID', variationID);
				listItem.onclick = function() {
					this.style.color = 'rgb(255,255,255)';
					this.style.backgroundColor = 'rgb(170,0,0)';
					var currentItem = document.getElementById('_commerce_variationslist').getAttribute('currentItem');
					if(currentItem != '' && currentItem != null) {
						document.getElementById(currentItem).style.color = 'rgb(25,25,25)';
						document.getElementById(currentItem).style.backgroundColor = 'transparent';
					}
					document.getElementById('_commerce_variationslist').setAttribute('currentItem', this.id);
				}
				var itemName = document.createElement('div');
				itemName.className = '_commerce_itemname';
				itemName.innerHTML = variationName;
				listItem.appendChild(itemName);
				variationsList.appendChild(listItem);
				if(variationCount < liveVariations.length - 1) {
					var listDivider = document.createElement('div');
					listDivider.className = '_commerce_listdivider _core_swatch_greylgt_bg';
					variationsList.appendChild(listDivider);
				}
			}
		}
	}
}

function _commerce_openEditVariation() {
	var currentItem = document.getElementById('_commerce_variationslist').getAttribute('currentItem');
	if(currentItem != '' && currentItem != null) {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_variation_field', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('variationID='+ document.getElementById(currentItem).getAttribute('fieldID'));
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var existingValues = new Object;
			var variationInfo = _commerce_xmlHTTP.responseText.split(':');
			existingValues['variationID'] = variationInfo[0];
			variationInfo.splice(0, 1);
			existingValues['variationName'] = variationInfo.join(':');
			_commerce_openShowVariation(existingValues);
		}
		else {
			_commerce_openVariationsList();
		}
	}
	else {
		_commerce_openVariationsList();
	}
}

function _commerce_openShowVariation(existingValues, warningText) {
	var existingValues = (existingValues == null) ? null : existingValues;
	var warningText = (warningText == null) ? '' : '<br /><br /><b>'+ warningText +'</b>';
	var dialogButtons = new Array();
	dialogButtons[0] = new Array('Save', 'Save Variation', 'javascript:_commerce_saveVariation();');
	_core_openDialogBox('commerce', 'Product Variation', 'Make your changes by filling out the box below followed by clicking on the button marked \'Save Variation\'.'+ warningText, dialogButtons, true, '/_include/_admin/commerce/variations_form.include');
	if(existingValues) {
		if(existingValues['variationID'] != null && existingValues['variationID'] != '') {
			document.getElementById('_commerce_hdnVariationID').value = existingValues['variationID'];
		}
		if(existingValues['variationName'] != null && existingValues['variationName'] != '') {
			document.getElementById('_commerce_txtVariationName').value = existingValues['variationName'];
		}
	}
}

function _commerce_saveVariation() {
	var saveVariation = true;
	var errText = '';
	var variationID = document.getElementById('_commerce_hdnVariationID').value;
	var variationName = '';
	if(document.getElementById('_commerce_txtVariationName').value != 'variation name' && document.getElementById('_commerce_txtVariationName').value != '' && document.getElementById('_commerce_txtVariationName').value != null) {
		var variationName = document.getElementById('_commerce_txtVariationName').value;
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/check_variation_field', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('variationID='+ variationID +'&variationName='+ variationName);
		if(_commerce_xmlHTTP.responseText != 'continue') {
			saveVariation = false;
			errText = 'The name entered has already been taken, please enter a different name';
		}
	}
	else {
		saveVariation = false;
		errText = 'Please ensure all fields are filled out before saving the variation';
	}
	if(!saveVariation) {
		var existingValues = new Object;
		existingValues['variationID'] = variationID;
		existingValues['variationName'] = variationName;
		_commerce_openShowVariation(existingValues, errText);
	}
	else {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/save_variation_field', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('variationID='+ variationID +'&variationName='+ variationName);
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var variationList = new Array();
			var liveVariations = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(variationCount = 0; variationCount < liveVariations.length; variationCount++) {
				var variationFields = new Object();
				var variationInfo = liveVariations[variationCount].split(':');
				variationFields['variationID'] = variationInfo[0];
				variationInfo.splice(0, 1);
				variationFields['variationName'] = variationInfo.join(':');
				variationList[variationList.length] = variationFields;
			}
			if(productVariations = document.getElementById('_commerce_sltVariations')) {
				var variationParent = productVariations.parentNode.parentNode;
				for(childCount = 1; childCount < variationParent.childNodes.length; childCount++) {
					var oldSelectedOption = variationParent.childNodes[childCount].childNodes[0].options[variationParent.childNodes[childCount].childNodes[0].selectedIndex].value;
					while(variationParent.childNodes[childCount].childNodes[0].options.length > 0) {
						variationParent.childNodes[childCount].childNodes[0].remove(variationParent.childNodes[childCount].childNodes[0].options.length - 1);
					}
					for(variationCount = 0; variationCount < variationList.length; variationCount++) {
						if(variationList[variationCount]['variationID'] == oldSelectedOption) {
							var newSelectedOption = variationCount;
						}
						variationParent.childNodes[childCount].childNodes[0].add(new Option(variationList[variationCount]['variationName'], variationList[variationCount]['variationID']));
					}
					if(newSelectedOption != null) {
						variationParent.childNodes[childCount].childNodes[0].selectedIndex = newSelectedOption;
					}
					else {
						variationParent.childNodes[childCount].childNodes[0].selectedIndex = 0;
					}
				}
			}
		}
		_commerce_openVariationsList();
	}
}

function _commerce_variationsListJacker(variationTextbox, populateVariations) {
	var _commerce_variationListAdd = document.createElement('input');
	_commerce_variationListAdd.type = 'button';
	_commerce_variationListAdd.className = '_core_selectbutton';
	_commerce_variationListAdd.value = '+';
	
	var _commerce_variationListRemove = document.createElement('input');
	_commerce_variationListRemove.type = 'button';
	_commerce_variationListRemove.className = '_core_selectbutton';
	_commerce_variationListRemove.value = '-';
	
	if(populateVariations) {
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_txtVariationCode');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var variationCodes = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(codeCount = 0; codeCount < variationCodes.length; codeCount++) {
				var listParent = variationTextbox.parentNode.parentNode;
				if(_commerce_formErrors['err__commerce_txtVariationCode_'+ codeCount] != undefined) {
					listParent.childNodes[(codeCount + 1)].childNodes[0].className = '_core_textbox _commerce_variationdetails_code _core_texterr';
				}
				listParent.childNodes[(codeCount + 1)].childNodes[0].value = variationCodes[codeCount];
				if(codeCount < variationCodes.length - 1) {
					_commerce_addVariationList(variationTextbox, true);
				}
			}
		}
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_txtVariationPrice');
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var variationCodes = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(priceCount = 0; priceCount < variationCodes.length; priceCount++) {
				var listParent = variationTextbox.parentNode.parentNode;
				if(_commerce_formErrors['err__commerce_txtVariationPrice_'+ priceCount] != undefined) {
					listParent.childNodes[(priceCount + 1)].childNodes[1].className = '_core_textbox _commerce_variationdetails_price _core_texterr';
				}
				listParent.childNodes[(priceCount + 1)].childNodes[1].value = variationCodes[priceCount];
			}
		}
		_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
		_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_sltVariations');
		var listedFields = new Array();
		if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
			var selectedVariations = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
			for(variationCount = 0; variationCount < selectedVariations.length; variationCount++) {
				var addField = true;
				for(listCount = 0; listCount < listedFields.length; listCount++) {
					if(listedFields[listCount] == selectedVariations[variationCount]) {
						addField = false;
					}
				}
				if(addField) {
					listedFields[listedFields.length] = selectedVariations[variationCount];
				}
			}
		}
		for(listCount = 0; listCount < listedFields.length; listCount++) {
			_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_session_value', false);
			_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			_commerce_xmlHTTP.send('formName=_commerce_frmProduct&fieldName=_commerce_txtVariationValue'+ listedFields[listCount]);
			if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
				var listParent = variationTextbox.parentNode.parentNode;
				var variationValues = _commerce_xmlHTTP.responseText.substr(1, _commerce_xmlHTTP.responseText.length - 2).split('","');
				for(valueCount = 0; valueCount < variationValues.length; valueCount++) {
					if(_commerce_formErrors['err__commerce_txtVariationValue'+ listedFields[listCount] +'_'+ valueCount] != undefined) {
						listParent.childNodes[(valueCount + 1)].childNodes[(listCount + 4)].className = '_core_textbox _commerce_variationdetails_variationfield _core_texterr';
					}
					listParent.childNodes[(valueCount + 1)].childNodes[(listCount + 4)].value = variationValues[valueCount];
				}
			}
		}
	}
	else {
		variationTextbox.parentNode.appendChild(_commerce_variationListAdd.cloneNode(false));
		variationTextbox.parentNode.appendChild(_commerce_variationListRemove.cloneNode(false));
		variationTextbox.parentNode.childNodes[2].onclick = function(){_commerce_addVariationList(this)};
		variationTextbox.parentNode.childNodes[3].style.visibility = 'hidden';
		
		_commerce_addVariationFields(variationTextbox.parentNode);
	}
	
	function _commerce_addVariationList(callingElement, addToEnd) {
		var addToEnd = (addToEnd == null) ? false : addToEnd;
		
		var variationListParent = callingElement.parentNode.cloneNode(true);
		while(variationListParent.childNodes.length > 2) {
			variationListParent.removeChild(variationListParent.lastChild);
		}
		variationListParent.appendChild(_commerce_variationListAdd.cloneNode(false));
		variationListParent.appendChild(_commerce_variationListRemove.cloneNode(false));
		variationListParent.childNodes[0].className = '_core_textbox _commerce_variationdetails_code';
		variationListParent.childNodes[0].value = 'variation code';
		variationListParent.childNodes[1].className = '_core_textbox _commerce_variationdetails_price';
		variationListParent.childNodes[1].value = 'variation price';
		variationListParent.childNodes[2].onclick = function(){_commerce_addVariationList(this)};
		variationListParent.childNodes[3].onclick = function(){_commerce_removeVariationList(this)};
		_commerce_addVariationFields(variationListParent);
		if(callingElement.parentNode.parentNode.lastChild == callingElement.parentNode || addToEnd) {
			callingElement.parentNode.parentNode.appendChild(variationListParent);
		}
		else {
			callingElement.parentNode.parentNode.insertBefore(variationListParent, callingElement.parentNode.nextSibling);
		}
	}
	
	function _commerce_removeVariationList(callingElement) {
		callingElement.parentNode.parentNode.removeChild(callingElement.parentNode);
	}
}

function _commerce_addVariationFields(productVariations) {
	if(selectedFields = document.getElementById('_commerce_sltVariations')) {
		var variationFields = selectedFields.parentNode.parentNode.childNodes;
		for(fieldCount = 1; fieldCount < variationFields.length; fieldCount++) {
			_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_variation_field', false);
			_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			_commerce_xmlHTTP.send('fieldID='+ variationFields[fieldCount].childNodes[0].value);
			if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
				var variationInfo = _commerce_xmlHTTP.responseText.split(':');
				variationInfo.splice(0, 1);
				var fieldValue =  document.createElement('input');
				fieldValue.type = 'text';
				fieldValue.className = '_core_textbox _commerce_variationdetails_variationfield';
				fieldValue.value = 'variation '+ variationInfo.join(':').toLowerCase();
				fieldValue.setAttribute('variationID', variationFields[fieldCount].childNodes[0].value);
				fieldValue.setAttribute('default', fieldValue.value);
				fieldValue.onfocus = function() {
					if(this.value == this.getAttribute('default')) {
						this.value = '';
					}
				}
				fieldValue.onblur = function() {
					if(this.value == '') {
						this.value = this.getAttribute('default');
					}
				}
				productVariations.appendChild(fieldValue);
			}
		}
	}
}

function _commerce_checkVariationFields() {
	if(selectedFields = document.getElementById('_commerce_sltVariations')) {
		var listedFields = new Array();
		var variationFields = selectedFields.parentNode.parentNode.childNodes;
		for(fieldCount = 1; fieldCount < variationFields.length; fieldCount++) {
			_commerce_xmlHTTP.open('POST', '/_action/commerce/products/get_variation_field', false);
			_commerce_xmlHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			_commerce_xmlHTTP.send('fieldID='+ variationFields[fieldCount].childNodes[0].value);
			if(_commerce_xmlHTTP.responseText != '' && _commerce_xmlHTTP.responseText != null) {
				var addField = true;
				var variationInfo = _commerce_xmlHTTP.responseText.split(':');
				var variationField = new Object();
				variationField['variationID'] = variationInfo[0];
				variationInfo.splice(0, 1);
				variationField['variationName'] = variationInfo.join(':');
				for(listCount = 0; listCount < listedFields.length; listCount++) {
					if(listedFields[listCount]['variationID'] == variationField['variationID']) {
						addField = false;
					}
				}
				if(addField) {
					listedFields[listedFields.length] = variationField;
				}
			}
		}
		if(variationCode = document.getElementById('_commerce_txtVariationCode')) {
			var variationList = variationCode.parentNode.parentNode.childNodes;
			for(listCount = 1; listCount < variationList.length; listCount++) {
				var existingValues = new Object();
				for(fieldCount = 4; fieldCount < variationList[listCount].childNodes.length; fieldCount++) {
					existingValues[variationList[listCount].childNodes[fieldCount].getAttribute('variationID')] = variationList[listCount].childNodes[fieldCount].value;
				}
				while(variationList[listCount].childNodes.length > 4) {
					variationList[listCount].removeChild(variationList[listCount].lastChild);
				}
				for(fieldCount = 0; fieldCount < listedFields.length; fieldCount++) {
					var fieldValue =  document.createElement('input');
					fieldValue.type = 'text';
					fieldValue.className = '_core_textbox _commerce_variationdetails_variationfield';
					if(existingValues[listedFields[fieldCount]['variationID']] == undefined) {
						fieldValue.value = 'variation '+ listedFields[fieldCount]['variationName'].toLowerCase();
					}
					else {
						fieldValue.value = existingValues[listedFields[fieldCount]['variationID']];
					}
					fieldValue.setAttribute('variationID', listedFields[fieldCount]['variationID']);
					fieldValue.setAttribute('default', fieldValue.value);
					fieldValue.onfocus = function() {
						if(this.value == this.getAttribute('default')) {
							this.value = '';
						}
					}
					fieldValue.onblur = function() {
						if(this.value == '') {
							this.value = this.getAttribute('default');
						}
					}
					variationList[listCount].appendChild(fieldValue);
				}
			}
		}
	}
}

