
/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
                
function handleEnter(field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      


function submitAccountForm(){
	if (eval("validate_accountform(document.accountform)")){
		el = eval("document.accountform");
		el.submit();
	}
}
function submitApplicationForm(){
	if (eval("validate_applicationform(document.applicationform)")){
		el = eval("document.applicationform");
		el.submit();
	}
}
function submitOrderForm_a(){
	var method = document.orderform.method_a.value;

	if (parseFloat(document.orderform.ordertotal.value) == 0){
		alert("You have not ordered any items")
		return false;
	} else if (parseFloat(document.orderform.ordertotal.value) < 20 && method == "Delivery"){
		alert("Your order is less than the minimum £20 for delivery. We can prepare your order for pick-up instead.")
		return false;
	} else {
		if (eval("validate_orderform_a(document.orderform)")){
			el = eval("document.orderform");
			el.submit();
		}
	}
}
function submitOrderForm_n(){
	var method = document.orderform.method_n.value;
	if (parseFloat(document.orderform.ordertotal.value) == 0){
		alert("You have not ordered any items")
		return false;
	} else if (parseFloat(document.orderform.ordertotal.value) < 20 && method == "Delivery"){
		alert("Your order is less than the minimum £20 for delivery. We can prepare your order for pick-up instead.")
		return false;
	} else {
		if (eval("validate_orderform_n(document.orderform)")){
			el = eval("document.orderform");
			el.submit();
		}
	}
}

function updateTotal(price,qtyfield,totfield,highest){
	var newqty = document.getElementById(qtyfield).value;
	el = eval("document.orderform."+totfield);
	newsubtotal = parseFloat(newqty * price);
	el.value = newsubtotal.toFixed(2);
	
	var i = 1;
	var newtotal = 0;
	while (i <= highest){
		var mitotal = eval("document.orderform.tot_mi_"+i);
		if (mitotal){
			newtotal += parseFloat(mitotal.value);
		}
		i = i + 1;
	}
	document.orderform.ordertotal.value = newtotal.toFixed(2);
}


function makeToday() {
	d = new Date();
	year = d.getFullYear();
	month = d.getMonth() + 1;
	if (month < 10){
		month = "0" + month;
	}
	day = d.getDate()
	if (day < 10){
		day = "0" + day;
	}
	today = year + '-' + month + '-' + day;
	return today;
}

var xhr = false;

function makeXhr(){
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP")
			}
			catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP")
				
				}			
			catch (e) {}
			}
		}
	}	
}


function getMoreJobs(destination,count){
	makeXhr();
	dest = destination;
	var url = "/php/getmorejobs.php?count="+count+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldnt create an XMLHttpRequest";
	}
}
function getMoreEdu(destination,count){
	makeXhr();
	dest = destination;
	var url = "/php/getmoreedu.php?count="+count+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldnt create an XMLHttpRequest";
	}
}




function getAddress(destination){
	makeXhr();
	dest = destination;
	acc = document.orderform.account_no.value;
	com = document.orderform.account_company.value;
	var url = "/php/getaddress.php?acc="+acc+"&com="+com+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldnt create an XMLHttpRequest";
	}
}

function getForm(type,destination){
	makeXhr();
	dest = destination;
	var url = "/php/getform.php?type="+type+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldnt create an XMLHttpRequest";
	}
}



function showImage() {
	if (xhr.readyState == 4) {
        if (xhr.status == 200) {
			var markup = (xhr.responseXML && xhr.responseXML.contentType == "text/xml") ? xhr.responseXML.getElementsByTagName("imgmarkup")[0].textContent : xhr.responseText;
        } else {
            var markup = "There was a problem with the request " + xhr.status;
        }
        document.getElementById(dest).innerHTML = markup;
    }
}
