function createWindow(page,height,width) {

	var url = '/' + page + '.htm';

	if (document.all || document.getElementById) {
		var xMax = screen.width;
		var yMax = screen.height;
	}
	else if (document.layers) {
		var xMax = window.outerWidth; 
		    var yMax = window.outerHeight;
	}
	else {
		var xMax = 800;
		var yMax=600;
	}

	var xOffset = (xMax - width)/2, yOffset = (yMax - height)/2;
	tag6 = window.open(url,'newWin',config='width='+width+',height='+height+',resizable=no,scrollbars=yes,menubar=no,toolbar=no,status=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');

}

function zoomWin(id) {

		var url = '/apps/zoom.cgi?' + id;

		if (document.all || document.getElementById) {
			var xMax = screen.width;
			var yMax = screen.height;
		}
		else if (document.layers) {
			var xMax = window.outerWidth; 
		    	var yMax = window.outerHeight;
		}
		else {
			var xMax = 800;
			var yMax=600;
		}

		var xOffset = (xMax - 330)/2, yOffset = (yMax - 400)/2;
		tag = window.open(url,'zoomWin',config='width=330,height=400,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
		window.tag.focus();

}


function colours(id) {

		var url = '/apps/swatches.cgi?style=' + id;

		if (document.all || document.getElementById) {
			var xMax = screen.width;
			var yMax = screen.height;
		}
		else if (document.layers) {
			var xMax = window.outerWidth; 
		    	var yMax = window.outerHeight;
		}
		else {
			var xMax = 800;
			var yMax=600;
		}

		var xOffset = (xMax - 460)/2, yOffset = (yMax - 280)/2;
		tag3 = window.open(url,'zoomWin',config='width=460,height=280,resizable=no,scrollbars=no,menubar=no,toolbar=no,status=no,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
		window.tag3.focus();

}

function checkValid(count) {


	if (document[count].colour.options[document[count].colour.selectedIndex].value == 0) {
		alert('Please select a Colour');
		document[count].colour.focus();
	}
	else if (document[count].size.options[document[count].size.selectedIndex].value == 0) {
		alert('Please select a Size');
		document[count].size.focus();
	}
	else if (document[count].stoma.options[document[count].stoma.selectedIndex].value == 0) {
		alert('Please select a Stoma Position');
		document[count].stoma.focus();
	}
	else if (document[count].quantity.options[document[count].quantity.selectedIndex].value == 0) {
		alert('Please select the Quantity you require');
		document[count].quantity.focus();
	}
	else {
		document[count].submit();
	}
}

function validateCheckout() {

	if (document.checkout.Name.value == '') {
		alert('Please enter your Full Name');
		document.checkout.Name.focus();
	}
	else if (document.checkout.Address1.value == '') {
		alert('Please enter the Delivery Address');
		document.checkout.Address1.focus();
	}
	else if (document.checkout.City.value == '') {
		alert('Please enter your Town/City');
		document.checkout.City.focus();
	}
	else if (document.checkout.Postcode.value == '') {
		alert('Please enter your Postal/Zip Code');
		document.checkout.Postcode.focus();
	}
	else if (tCheck(document.checkout.Telephone.value) == false) {
		alert('Please enter a valid Telephone number');
		document.checkout.Telephone.focus();
	}
	else if (eCheck(document.checkout.Email.value) == false) {
		alert('Please enter a valid Email Address');
		document.checkout.Email.focus();
	}
	else if (document.checkout.Cardnum.value == '') {
		alert('Please enter your Card Number');
		document.checkout.Cardnum.focus();
	}
	else if (document.checkout.Expirymonth.options[document.checkout.Expirymonth.selectedIndex].value == 0) {
		alert('Please select your card\'s Expiry Month');
		document.checkout.Expirymonth.focus();
	}
	else if (document.checkout.Expiryyear.options[document.checkout.Expiryyear.selectedIndex].value == 0) {
		alert('Please select your card\'s Expiry Year');
		document.checkout.Expiryyear.focus();
	}
	else if ((document.checkout.Type.value == 'Switch') && (document.checkout.Switch.value == '')) {
		alert('Please enter your Switch card\'s Issue Number');
		document.checkout.Switch.focus();
	}
	else if (document.checkout.Security.value == '') {
		alert('Please enter your Card\'s Security Number (the last 3 or 4 digits that appears on the back of your credit or debit card)');
		document.checkout.Security.focus();
	}
	else if (document.checkout.Holder.value == '') {
		alert('Please enter the Card Holder\'s Name');
		document.checkout.Holder.focus();
	}
	else if (document.checkout.Disabled[4].checked) {
		if (confirm('You have specified that you do not have a disabling condition  - this means you will be charged 17.5% VAT on your order total. Press Cancel if you need to change this.')) {
			document.checkout.submit();
		}
	}
	else {
		document.checkout.submit();
	}

}


function validateBrochure() {

	if (document.brochure.Name.value == '') {
		alert('Please enter your Full Name');
		document.brochure.Name.focus();
		return false;
	}
	else if (document.brochure["Address 1"].value == '') {
		alert('Please enter your Address');
		document.brochure["Address 1"].focus();
		return false;
	}
	else if (document.brochure["Town/City"].value == '') {
		alert('Please enter your Town/City');
		document.brochure["Town/City"].focus();
		return false;
	}
	else if (document.brochure["Post/Zip Code"].value == '') {
		alert('Please enter your Postal/Zip Code');
		document.brochure["Post/Zip Code"].focus();
		return false;
	}
	else {
		return true;
	}

}


function tCheck(str) {
	var valid = 1;
	var GoodChars = "0123456789()-+ ";
	var i = 0;
	if ((str=='') || (str.length < 6)) {
		// Return false if number is empty
		valid = 0;
	}
	for (i =0; i <= str.length -1; i++) {
		if (GoodChars.indexOf(str.charAt(i)) == -1) {
			valid = 0;
		} // End if statement
	} // End for loop
	return valid;
}


function eCheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
  		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
	return true					
}


function notify() {
	if (!document.checkout.Disabled.checked) {
		alert('By selecting this option (no disabling condition) you will be charged 17.5% VAT on your order total. The total amount will be confirmed on the next page.');
	}
}
