function check_register() {
	var blnReturn = true;
	
	document.getElementById('pwc_validationerrormessage').innerHTML = '';

	if (document.register.id.value < 0) {
		blnReturn = check_field(strFormBackgroundColour, 'BLfirstname', 'BLlastname', 'BLaddress1', 'BLtelephone', 'BLpostcode', 'EMusername', 'PWcpassword');

		if (blnReturn && document.register.country.value == '826')
			blnReturn = check_field(strFormBackgroundColour, 'PCpostcode');
		
		if (blnReturn && (document.register.username.value != document.register.email.value)) {
			blnReturn = false;
			document.getElementById('pwc_validationerrormessage').innerHTML = 'Your Email and Confirmation do not match';
		}
		if (blnReturn)
			blnReturn = check_password(document.register.cpassword.value, document.register.password.value, conMinimumPasswordLength);
		if (blnReturn)
			blnReturn = check_duplicate('User', 'usName', document.register.username.value, 'usID', document.register.id.value, 'Sorry, the User Name \'' + document.register.username.value + '\' is not unique in the database');
	} else {
		blnReturn = check_field(strFormBackgroundColour, 'BLfirstname', 'BLlastname', 'BLaddress1', 'BLtelephone', 'BLpostcode', 'EMemail');

		if (blnReturn && document.register.country.value == '826')
			blnReturn = check_field(strFormBackgroundColour, 'PCpostcode');		
		
		if (blnReturn && ((document.register.cpassword.value != '') || (document.register.password.value != '') || (document.register.newpassword.value != ''))) {
			blnReturn = check_field(strFormBackgroundColour, 'PWcpassword', 'PWpassword', 'PWnewpassword');
			if (blnReturn)
				blnReturn = check_password(document.register.password.value, document.register.newpassword.value, conMinimumPasswordLength);
		}
	}

	return blnReturn;
}

function calculate_frmShoppingBag(intGiftCost) {
	document.getElementById('deliverycost').innerHTML = (Number(intGiftCost) / 100).toFixed(2);
	document.getElementById('totalcost').innerHTML = ((400 + Number(document.getElementById('productcost').value) + Number(intGiftCost)) / 100).toFixed(2);
}

function copy_frmCheckout() {
	document.frmCheckout.recipient.value = document.frmCheckout.firstname.value + ' ' + document.frmCheckout.lastname.value;
	document.frmCheckout.daddress1.value = document.frmCheckout.address1.value;
	document.frmCheckout.daddress2.value = document.frmCheckout.address2.value;
	document.frmCheckout.daddress3.value = document.frmCheckout.address3.value;
	document.frmCheckout.dpostcode.value = document.frmCheckout.postcode.value;
	document.frmCheckout.dcountry.value = document.frmCheckout.country.value;
	reset_background(document.frmCheckout.recipient);
	reset_background(document.frmCheckout.daddress1);
	reset_background(document.frmCheckout.dpostcode);
	delivery_frmCheckout();
	return false;
}

function check_frmCheckout() {
	var blnReturn = true;
	
	if (wasSubmitted)
		return false;
	wasSubmitted = true;
	
	document.getElementById('pwc_validationerrormessage').innerHTML = '';

	blnReturn = check_field(strFormBackgroundColour, 'BLfirstname', 'BLlastname', 'BLaddress1', 'EMemail', 'BLpostcode', 'BLrecipient', 'BLdaddress1', 'BLdpostcode');

	if (blnReturn && document.frmCheckout.country.value == '826')
		blnReturn = check_field(strFormBackgroundColour, 'PCpostcode');
	
	if (blnReturn && document.frmCheckout.dcountry.value == '826')
		blnReturn = check_field(strFormBackgroundColour, 'PCdpostcode');
	
	if (blnReturn)
		blnReturn = check_field(strFormBackgroundColour, 'BLccname', 'DRcctype', 'CCccnumber', 'DRcctomonth', 'DRcctoyear', 'BLcccode');


	if (!blnReturn)
		document.getElementById('pwc_validationerrormessage').innerHTML = 'Please correct the highlighted errors';
	if (!blnReturn)
		wasSubmitted = false;
	
	return blnReturn;
}

function delivery_frmCheckout() {
	var http;
	var doc;
	var element;
	var params = '';
	var blnReturn = false;
	
	document.getElementById('pwc_validationerrormessage').innerHTML = '';
	document.getElementById('nextdaycell').style.visibility = 'hidden';

	if (document.frmCheckout.wholesale.value == 'Y') {
		document.getElementById('postagecost').value = 0;
		document.getElementById('postgroup').value = 12;
		return totalcost_frmCheckout();
	}
	
	http = create_xmlhttprequest();
	if (http) {
		http.onreadystatechange = function() { 
			if (http.readyState == 4) {
				if (http.status == 200) {
					doc = http.responseXML;
					element = doc.getElementsByTagName('result').item(0);
					document.getElementById('postgroup').value = unescape(element.firstChild.data);
					switch (Number(unescape(element.firstChild.data))) {
					case 1:
						document.getElementById('postagecost').value = 400;
						document.getElementById('nextdaycell').style.visibility = 'visible';
						document.getElementById('deliverytext').innerHTML = 'Standard UK delivery costs &pound;4.00 and items will be despatched 1st Class.&nbsp;&nbsp;&nbsp;If you require Next Day Delivery please check the box above which will add a further &pound;4.00 to your order.&nbsp;&nbsp;&nbsp;Please note that Next Day Orders must be placed before 2:00pm Monday to Thursday.&nbsp;&nbsp;&nbsp;Next Day Orders placed on Friday will be despatched the same day but will be delivered on Monday.<br /><b>&pound;4.00/&pound;8.00</b>';
						break;
					case 2:
						document.getElementById('postagecost').value =800;
						document.getElementById('deliverytext').innerHTML = 'Delivery to Europe costs &pound;10.00.&nbsp;&nbsp;&nbsp;Orders will be despatched via our international courier service.&nbsp;&nbsp;&nbsp;Please allow up to 14 days for delivery.<br /><b>&pound;8.00</b>';
						break;
					case 3:
						document.getElementById('postagecost').value = 1200;
						document.getElementById('deliverytext').innerHTML = 'Delivery to Rest of the World costs &pound;12.00.&nbsp;&nbsp;&nbsp;Orders will be despatched via our international courier service.&nbsp;&nbsp;&nbsp;Please allow up to 28 days for delivery.<br /><b>&pound;12.00</b>';
						break;
					default:
						document.getElementById('postagecost').value = 1200;
						document.getElementById('pwc_validationerrormessage').innerHTML = 'Sorry, unable to find details of the Delivery Country ' + unescape(element.firstChild.data);
						break;
					}
					totalcost_frmCheckout();
				} else 
					document.getElementById('pwc_validationerrormessage').innerHTML = 'Error code: ' + http.status;
			}
		};
		params = params + 'type=' + escape('get_postgroup');
		params = params + '&country=' + escape(document.getElementById('dcountry').value);
//		http.open('POST', 'https://www.securepaymentprocesses.com/TN/includes/fnXMLHttpRequest.ASP', false); 
		http.open('POST', escape('includes/fnXMLHttpRequest.ASP'), false); 
		http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
		http.setRequestHeader('Content-length', params.length);
		http.send(params);
	} else
		document.getElementById('pwc_validationerrormessage').innerHTML = 'Unable to Create XMLHttpRequest';	
	
	if (document.getElementById('pwc_validationerrormessage').innerHTML == '')
		blnReturn = true;
	
	return blnReturn;
}

function totalcost_frmCheckout() {
	var intTotalCost = 0;
	
	if ((document.frmCheckout.nextday.checked == true) && (Number(document.getElementById('postgroup').value) == 1))
		intTotalCost = 400;
	intTotalCost += Number(document.getElementById('postagecost').value);

	document.getElementById('unitdeliverycost').innerHTML = '&pound;' + (Number(intTotalCost) / 100).toFixed(2);
	document.getElementById('deliverycost').innerHTML = '&pound;' + (Number(intTotalCost) / 100).toFixed(2);
	
	if (document.frmCheckout.giftwrapped.value == 'Y')
		intTotalCost += 500;
	
	intTotalCost += Number(document.getElementById('productcost').value) - Number(document.getElementById('productdiscount').value);
	
	document.getElementById('totalcost').innerHTML = 'Total Cost:&nbsp;&pound;' + (Number(intTotalCost) / 100).toFixed(2);
	
	return false;
}
	
	

