function createAJAX() {
	try {
		return window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
		alert('Object creation falied');
		return false;
	}
}

function loadAJAX(sURL, sProcessor) {
	var aHTTP = createAJAX();
	
	aHTTP.onreadystatechange = function() {
		if ((aHTTP.readyState == 4) && (aHTTP.status == 200))
			eval(sProcessor + '(aHTTP.responseXML);');
	}
	aHTTP.open("GET", sURL, true);
	aHTTP.send(null);
}

function cartAdd(oForm) {
	var sURL = sURLPrefix + '/scripts/xml_call.asp?CallID=3&OrderCodeID=' + oForm.OrderCodeID.value + 
				  '&SourceCodeID=' + oForm.SourceCodeID.value +
				  '&SubDefinitionID=' + oForm.SubDefinitionID.value +
				  '&Quantity=' + oForm.Quantity.value;

	var sXML = loadAJAX(sURL, 'cartRefresh');
}

function cartRefresh(oXML) {
	alert(oXML.getElementsByTagName('result')[0].innerHTML);

	document.getElementById('basket_price').innerHTML = '&pound;' + oXML.getElementsByTagName('result')[0].xml;
}

function toggleAddress(sLayerName) {
	var sLabel;

	if (document.layers)
		oLayer = document.layers[sLayerName];
	else
		oLayer = document.getElementById(sLayerName);
		
	if (oLayer.style.display == 'none') {
		oLayer.style.display = 'block';
		sLabel = 'remove this address.';
	} else {
		oLayer.style.display = 'none';
		sLabel = 'add a ' + sLayerName + ' address different from your details.';
	}
	
	if (document.layers)
		oLayer = document.layers[sLayerName + '_label'];
	else
		oLayer = document.getElementById(sLayerName + '_label');
		
	oLayer.innerHTML = sLabel;
}
function promoView(iPromoID) {
	openWindowMove(sURLPrefix + '/promo.asp?PromoID=' + iPromoID, 'promo', '', '500', '300', 'middle', 'middle', false);
}
function emaf(sLink) {
	openWindowMove(sURLPrefix + '/emaf.asp?link=' + escape(sLink), 'emaf', 'scrollbars=yes', '500', '420', 'middle', 'middle', false);
}
function tandc() {
	openWindowMove(sURLPrefix + '/stub.asp?StubID=29&popup=true', 'tandc', 'scrollbars=yes', '700', '500', 'middle', 'middle', false);
}
function privacyPolicy() {
	openWindowMove(sURLPrefix + '/stub.asp?StubID=30&popup=true', 'privacyPolicy', 'scrollbars=yes', '700', '500', 'middle', 'middle', false);
}
function reviewProduct(iProductID) {
	openWindowMove(sURLPrefix + '/review.asp?ProductID=' + iProductID, 'review', 'scrollbars=yes', '500', '420', 'middle', 'middle', false);
}
function checkPassword(oForm) {
	if (!isFilled(oForm.uPasswordOld.value) || !isFilled(oForm.uPassword.value) || !isFilled(oForm.uPasswordConfirm.value)) {
		alert('Please fill in all fields.')
		return false;
	}
	
	if (oForm.uPassword.value != oForm.uPasswordConfirm.value) {
		alert('The new passwords do not match.')
		return false;
	}
	
	return true;
}
function addEMAF(oTable, iIndex) {
	var oRow = oTable.insertRow(iIndex);
	oRow.insertCell(0).innerHTML = '';
	oRow.insertCell(1).innerHTML = '<input class="input01" type="text" name="their_email" />';
}
function checkTandC(oForm) {
	if (!oForm.termsandconditions)
		return false;
		
	if (!oForm.termsandconditions.checked) {
		alert('\n * You cannot continue without agreeing to the terms and conditions.');
		return false;
	}
	
	return true;
}
function productDownload(sURL) {
	window.open(sURL, '_new');
	//document.getElementById('download').innerHTML = '<iframe width="0" height="0" src="' + sURL + '"></iframe>';
}
function closeRedirect(sURL) {
	window.opener.location = sURL;
	//window.opener.focus();
	window.close();
}
function emailWarning(oCheck) {
	if (oCheck.checked)
		openWindowMove(sURLPrefix + '/stub.asp?StubID=455&popup=true', 'tandc', 'scrollbars=yes', '400', '225', 'middle', 'middle', false);
}
function showHideDiv(oDiv) {
	if(oDiv.style.display=='none')
		oDiv.style.display='block';
	else
		oDiv.style.display='none';
}
function checkEmail(oForm) {
	if (!isEmail(oForm.uEmailAddress.value)) {
		alert("please enter a valid email address.")
		return false;
	} else
		return true;
}

