// JavaScript Document

// rollover/out functions for homepage buttons & image map rollovers
function hbo (btnID) { document.getElementById(btnID + "Btn").style.backgroundImage = "url(images/homeBtn" + btnID + "-o.gif)"; }
function hbn (btnID) { document.getElementById(btnID + "Btn").style.backgroundImage = "url(images/homeBtn" + btnID + "-n.gif)"; }

// set number of items in Shopping Basket Main Menu text
function setMenuBasket (qty) {
	
	var microbasketHTML = "";
	var menucheckoutHTML = "<a href=\"cart.asp\">Checkout</a>"
	
	if (qty > 0) { // something in basket... so do menu display
		// items in basket...
		if (qty == 1) {
			microbasketHTML = "<div align=\"center\"><a href=\"cart.asp\">" + qty + " item in Shopping Basket</a></div>";
		} else {
			microbasketHTML = "<div align=\"center\"><a href=\"cart.asp\">" + qty + " items in Shopping Basket</a></div>";
		}
		// checkout btn...
		
		
		//insert the HTML into the menu DIVs
		document.getElementById('microbasket').innerHTML=microbasketHTML;
	
		if (document.getElementById('menucheckout')) { // normal
			document.getElementById('menucheckout').innerHTML=menucheckoutHTML;
		}
	}
	
	if (document.getElementById('menucheckouton')) { // on
		document.getElementById('menucheckouton').innerHTML=menucheckoutHTML;
	}	
}


function doem () { window.location = "mailto:monica@monicaboxley.co.uk?subject=Enquiry from your website"; }

function doemo () { window.location = "mailto:monica@monicaboxley.co.uk?subject=Order from your website"; }


function validateOrder() {
	document.getElementById('Name').className = 'textField';
	document.getElementById('Email').className = 'textField';
	document.getElementById('Phone').className = 'textField';
	document.getElementById('Items').className = 'textArea';
	document.getElementById('checkboxtxt').className = 'checkbox';	
	
	if (document.getElementById('Name').value == "") {
		alert('Please provide Your Name.');
		document.getElementById('Name').className = 'errored';
		return false;
	}
	
	if (document.getElementById('Email').value != "") {
		var str = document.getElementById('Email').value;
		var address = true;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1) { address = false; }
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { address = false; }
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { address = false; }
		if (str.indexOf(at,(lat+1))!=-1) { address = false; }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { address = false; }
		if (str.indexOf(dot,(lat+2))==-1) { address = false; }
		if (str.indexOf(" ")!=-1) { address = false; }
		if (address == false) {
			alert('The Email Address you supplied contains an error.');
			document.getElementById('Email').className = 'errored';
			return false;
		}		
	}
	
	
	if (document.getElementById('Phone').value == "") {
		alert('Please provide Your Telephone Number.');
		document.getElementById('Phone').className = 'errored';
		return false;
	} else {
		var myNumber = document.getElementById('Phone').value;
		//alert(myNumber);
		var stripped = myNumber.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
		if (isNaN(stripped)) {
			alert('Please only use numbers in the "Phone number" field.');
			document.getElementById('Phone').className = 'errored';
			return false;
		}
		if ((stripped.length <= 6)) {
			alert('The phone number is too short.    \n\nMake sure you include an area code.');
			document.getElementById('Phone').className = 'errored';
			return false;
		}
		if ((stripped.length >= 20)) {
			alert('The phone number is much too long.');
			document.getElementById('Phone').className = 'errored';
			return false;
		}
	}
	
	if (document.getElementById('Items').value == "") {
		alert('Please include the Items Required.');
		document.getElementById('Items').className = 'errored';
		return false;
	}
	if (document.getElementById('Terms').checked == false) {
		alert('Please tick the Checkbox to confirm that you      \nagree to our Terms and Conditions and Privacy Policy.      ');
		document.getElementById('checkboxtxt').className = 'errorcheckbox';
		return false;
	}
	
	return true;
}
