//	Break out of any framed websites
if (window != top) top.location.href = location.href;

//	jQuery
$(document).ready(function(){
	//	Load links in a external window that validates with W3C
	$('a.external').attr('target', '_blank');
});

//	Alternative to the jQuery methold above
//	Load links in a external window that validates with W3C
//	Also degrades nicely if javascript disabled
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}
window.onload = externalLinks;

//	Removes the Product from the Customers Shopping Basket
function cancel_item($id,$product,$url,$backlink){
	if(confirm("Please confirm:\n\nThis will clear this item from your shopping basket !\n\n("+$product+") ....\n\nClick OK to remove\nClick cancel to keep.\n\n")){
		window.location = ("action_removeproduct.php?action=cancel&url="+$url+"&id="+$id+"&product="+$product+"&backlink="+$backlink+"");
	}
}

//	Empties all shopping basket products
function clear_basket($sessid,$url,$backlink){
	if(confirm("Please confirm:\n\nThis will clear all item's from your shopping basket !\n\nClick OK to empty your basket\nClick cancel to keep the contents of your basket.\n\n")){
		window.location = ("action_clearbasket.php?action=clear&url="+$url+"&customer="+$sessid+"&backlink="+$backlink+"");
	}
}

//	Removes the Products from the Temporary Shopping Basket
//	and Transfers them to the Transactions Shopping Basket
function checkout($fullname,$email,$sessid){
	if(confirm("THANKYOU: "+$fullname+" for Your Order.\n\n\Please check that \""+$email+"\" is your correct email address.\n\nClicking OK will transfer your order details to the Netbanx SECURE SERVER.\n\nYou will need your credit card details.\n\n")){
		document.printorder.submit();
	}
}

//	Check the Quantity of Products to be Added to the Shopping Basket
function check_quantity(){
	if(document.AddProduct.quantity.value == ""){
		alert("WARNING;\n\nYou appear to have left the quantity field blank !\n\nPlease enter a quantity to continue.\n\n");
		document.AddProduct.quantity.focus();
	}else{
		if(isNaN(document.AddProduct.quantity.value)){
			alert("WARNING;\n\nOnly numbers are acceptable !\n\n");
			document.AddProduct.quantity.focus();
		}else{
			if((parseInt(document.AddProduct.quantity.value) > 0) && (parseInt(document.AddProduct.quantity.value) < 100)){
				document.AddProduct.submit();
			}else{
				alert('Invalid number !\n\nMust be more than 0 and less than 100\n\n');
				document.AddProduct.quantity.focus();
			}
		}
	}
}
function check_quantity2(){
	if(document.AddProduct2.quantity.value == ""){
		alert("WARNING;\n\nYou Appear to have left the quantity field blank !\n\n");
		document.AddProduct2.quantity.focus();
	}else{
		if(isNaN(document.AddProduct2.quantity.value)){
			alert("WARNING;\n\nOnly numbers are acceptable !\n\n");
			document.AddProduct2.quantity.focus();
		}else{
			if((parseInt(document.AddProduct2.quantity.value) > 0) && (parseInt(document.AddProduct2.quantity.value) < 100)){
				document.AddProduct2.submit();
			}else{
				alert('Invalid number !\n\nMust be more than 0 and less than 100\n\n');
				document.AddProduct2.quantity.focus();
			}
		}
	}
}
function check_AddProduct(){
	if(document.AddProduct.pid.value == ""){
		alert("WARNING;\n\nPlease select a format for the manual !\n\n");
		document.AddProduct.pid.focus();
	}else{
		if(document.AddProduct.quantity.value == ""){
			alert("WARNING;\n\nYou appear to have left the quantity field blank !\n\n");
			document.AddProduct.quantity.focus();
		}else{
			if(isNaN(document.AddProduct.quantity.value)){
				alert("WARNING;\n\nOnly Numbers Acceptable !\n\n");
				document.AddProduct.quantity.focus();
			}else{
				if((parseInt(document.AddProduct.quantity.value) > 0) && (parseInt(document.AddProduct.quantity.value) < 100)){
					document.AddProduct.submit();
				}else{
					alert('Invalid Number\nMust be More Than 0 and Less Than 100.\n\n');
					document.AddProduct.quantity.focus();
				}
			}
		}
	}
}

//	Check the Customer Name, Address and Delivery Details
//	This is for Entry into the Transactions Database
function checkform($backlink){
	if(document.orderdetails.basket.value == ""){
		alert("SORRY;\n\nYou cannot progress with an empty shopping basket!\n\n");
		document.orderdetails.action="./";
		document.orderdetails.submit();
	}else{
		terms();
	}
}
function terms(){
	if(!document.orderdetails.terms.checked){
		alert("WARNING;\n\nYou must accept our terms and conditions!\n\n");
		document.orderdetails.terms.focus();
	}else{
		ordername();
	}
}
function ordername(){
	if(document.orderdetails.fullname.value == ""){
		alert("WARNING;\n\nYou appear to have left your name field blank!\n\n");
		document.orderdetails.fullname.focus();
	}else{
		orderaddress();
	}
}
function orderaddress(){
	if(document.orderdetails.address.value == ""){
		alert("WARNING;\n\nYou must provide your address!\n\n");
		document.orderdetails.address.focus();
	}else{
		orderpostcode();
	}
}
function orderpostcode(){
	if(document.orderdetails.postcode.value == ""){
		alert("WARNING;\n\nPostcode is required!\n\n");
		document.orderdetails.postcode.focus();
	}else{
		ordercountry();
	}
}
function ordercountry(){
	if(document.orderdetails.countrycode.value == ""){
		alert("WARNING;\n\nYour country is required!\n\n");
		document.orderdetails.countrycode.focus();
	}else{
		orderemail();
	}
}
function orderemail(){
	if(document.orderdetails.email.value == ""){
		alert("WARNING;\n\nYou MUST provide your email address!\n\nThis is extremely important and MUST be correct otherwise you may not recieve any products ordered via email...!\n\n");
		document.orderdetails.email.focus();
	}else{
		if (document.orderdetails.email.value.indexOf("@") == -1){
			alert("Please enter a valid email address\n\n(you have not entered a @ sign).\n\n");
			document.orderdetails.email.focus();
			return false;
		}
		if (document.orderdetails.email.value.indexOf(".") == -1){
			alert("Please enter a valid email address\n\n(you have not entered a full stop anywhere).\n\n");
			document.orderdetails.email.focus();
			return false;
		}else{
			ordercompleted();
		}
	}
}
function ordercompleted(){
	if(confirm("Please check your information:\n\nClick \"OK\" to continue to the next page\n\nClick \"Cancel\" to double check the details.\n\n")){
		document.orderdetails.submit();
	}
}

//	Check the Add My Link Details
function checklink(){
	if(document.linkentry.contact.value == ""){
		alert("SORRY;\n\nYou appear to have left the contact name field blank!\n\n");
		document.linkentry.contact.focus();
	}else{
		linkemail();
	}
}
function linkemail(){
	if(document.linkentry.email.value == ""){
		alert("SORRY;\n\nYou MUST provide your email address!\n\nThis is extremely important and MUST be correct otherwise you will not recieve the validation email...!\n\n");
		document.linkentry.email.focus();
	}else{
		if (document.linkentry.email.value.indexOf("@") == -1){
			alert("SORRY;\n\nEmail address is incorrect.\n\n");
			document.linkentry.email.focus();
			return false;
		}
		if (document.linkentry.email.value.indexOf(".") == -1){
			alert("SORRY;\n\nEmail address is incorrect.\n\n");
			document.linkentry.email.focus();
			return false;
		}else{
			linkurl();
		}
	}
}
function linkurl(){
	if(document.linkentry.url.value == ""){
		alert("SORRY;\n\nYou MUST provide the FULL and Correct URL!\n\nThis is should be in the following format...\n\nhttp://www.sportsrevent.com\nInclude the HTTP etc....\nOtherwise When we Visit Your Link,\nWe will not be able to Assess the Link Correctly,\nand the Link will be Declined...!\n\n");
		document.linkentry.url.focus();
	}else{
		if (document.linkentry.url.value.indexOf("http://") == -1){
			alert("SORRY;\n\nPlease Enter a Valid URL\nYou Have Not Entered \"http://\" Anywhere.\n\n");
			document.linkentry.url.focus();
			return false;
		}
		if (document.linkentry.url.value.indexOf(".") == -1){
			alert("SORRY;\n\nPlease enter a valid URL\nYou must enter the full URL.\n\n");
			document.linkentry.url.focus();
			return false;
		}else{
			linkcategory();
		}
	}
}
function linkcategory(){
	if(document.linkentry.category.value == "Other" && document.linkentry.altcategory.value == ""){
		alert("SORRY;\n\nYou must type in your suggested category.\n\n");
		document.linkentry.altcategory.focus();
	}else{
		linktitle();
	}
}
function linktitle(){
	if(document.linkentry.sitename.value == ""){
		alert("SORRY;\n\nType in a title for the link!\n\nSomething descriptive about your site.\nPlease limit this to less than 50 characters...!\n\n");
		document.linkentry.sitename.focus();
	}else{
		linktext();
	}
}
function linktext(){
	if(document.linkentry.text.value == ""){
		alert("SORRY;\n\nType in text to display for the link!\n\nSomething more descriptive about your site.\nPlease limit this to less than 170 characters...!\n\n");
		document.linkentry.text.focus();
	}else{
		linkcomplete();
	}
}
function linkcomplete(){
	if(confirm("Please check your information:\n\nClick \"OK\" to submit your link details\nClick \"Cancel\" to double check the details.\n\n")){
		document.linkentry.submit();
	}
}