//---Search Results Functions-----
function Cart(ItemCode, ImageRef, Quantity){
	var CartFORM = eval("document.CartForm");
	if(ImageRef.src!="http://www.bracon.co.uk/pic/cart_added.gif"){
		ImageRef.src="pic/cart_added.gif";
		if (!Quantity){
			Quantity = "1";
		}
		document.getElementById('CartIcon').src = "pic/icon_throbber.gif";
		CartFORM.target="CartFrame";
		CartFORM.action="PROCESS_cart.php";
		CartFORM.ItemCode.value=ItemCode;
		CartFORM.ItemQuantity.value=Quantity;
		//console.log(CartFORM);
		CartFORM.submit();
	}
}
//-/-Search Results Functions-----



//---Shopping Cart Functions-----
var FORM1 = eval("document.Form1");
var FieldName = "ash";

function NumbersOnly(Field, E, Dec){
	var Key;
	var KeyChar;
	if (window.event){
		Key = window.event.keyCode;
	}else if(E){
		Key = E.which;
	}else{
		return true;
	}
	KeyChar = String.fromCharCode(Key);
	if ((Key==null) || (Key==0) || (Key==8) || (Key==9) || (Key==13) || (Key==27)){//Control Keys
		return false;
	}else if ((("0123456789").indexOf(KeyChar) > -1)){//Numbers
		return true;
	}else if (Dec && (KeyChar == ".")){//Decimal Point Jump
		Field.form.elements[Dec].focus();
		return false;
	}else{
		return false;
	}
}

function Recalculate(FieldNumber, FieldValue, ItemCode, Price){
	SetSession(ItemCode, FieldValue, FieldNumber);
	eval("document.Form1.SubTotal"+FieldNumber).value = (eval(Price).toFixed(2) * eval(FieldValue).toFixed(2)).toFixed(2);
	document.getElementById('Price'+FieldNumber).innerHTML = (eval(Price).toFixed(2) * eval(FieldValue).toFixed(2)).toFixed(2);
	UpdateTotal();
}

function Add(FieldNumber, Price, ItemCode){
	var FORMQ = eval("document.Form1.Q"+FieldNumber);
	M = FORMQ.value;
	if (M!=9999){
		M++;
		FORMQ.value = M;
		SetSession(ItemCode, M, FieldNumber);
		document.getElementById('Price'+FieldNumber).innerHTML = (Price * M.toFixed(2)).toFixed(2);
		eval("document.Form1.SubTotal"+FieldNumber).value = (Price * M.toFixed(2)).toFixed(2);
		UpdateTotal();
	}
	FieldName = FieldNumber;
}

function Minus(FieldNumber, Price, ItemCode){
	var FORMQ = eval("document.Form1.Q"+FieldNumber);
	M = FORMQ.value;
	if (M!=1){
		M--;
		FORMQ.value = M;
		SetSession(ItemCode, M, FieldNumber);
		document.getElementById('Price'+FieldNumber).innerHTML = (Price * M.toFixed(2)).toFixed(2);
		eval("document.Form1.SubTotal"+FieldNumber).value = (Price * M.toFixed(2)).toFixed(2);
		UpdateTotal();
	}
}

function UpdateTotal(){
	var SubTotal = 0;
	var FORM1 = eval("document.Form1");
	for(var i = 0; i < FORM1.length; i++){
		if ((FORM1.elements[i].type == "hidden") && (FORM1.elements[i].name.indexOf("SubTotal")!=-1)){
			M = eval(SubTotal) + eval(FORM1.elements[i].value)
			SubTotal = M.toFixed(2);
		}
	}
	FORM1.Total.value = SubTotal;
	document.getElementById('PriceTotal').innerHTML = SubTotal;
}

function RemoveItem(ItemCode){
	self.location.href="orders.php?Remove="+ItemCode;
}
//-/-Shopping Cart Functions-----



//---AJAX Functions-----
function CreateRequestObject(){
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

var http = CreateRequestObject();

function HandleResponse(){
	if(http.readyState == 4){
		var response = http.responseText;
		var update = new Array();
		if(response.indexOf('|' != -1)){
			update = response.split('|');
			//document.getElementById('Price'+FieldName).innerHTML = update[1];
		}
	}
}

function SetSession(Code, Quantity){
	http.open('get', 'PROCESS_cart.php?UseAJAX=1&ItemCode='+Code+'&ItemQuantity='+Quantity);
	http.onreadystatechange = HandleResponse;
	http.send(null);
}
//-/-AJAX Functions-----



//---Checkout Functions-----
function ValidateOrder(){
	var OrderForm = eval("document.OrderForm");
	OrderForm.DeliveryContactName.style.backgroundColor="";
	OrderForm.DeliveryLabName.style.backgroundColor="";
	OrderForm.DeliveryAddress.style.backgroundColor="";
	OrderForm.DeliveryPostCode.style.backgroundColor="";
	OrderForm.InvoiceLabName.style.backgroundColor="";
	OrderForm.InvoiceAddress.style.backgroundColor="";
	OrderForm.InvoicePostCode.style.backgroundColor="";
	OrderForm.InvoicePhone.style.backgroundColor="";

	if(OrderForm.DeliveryContactName.value.length<5){
		OrderForm.DeliveryContactName.style.backgroundColor="#FFC0C0";
		alert("ERROR: Name not Entered\n\nPlease enter the name of the person who will receive the order.");
		OrderForm.DeliveryContactName.select();
		return false;
	}
	if(OrderForm.DeliveryLabName.value.length<3){
		OrderForm.DeliveryLabName.style.backgroundColor="#FFC0C0";
		alert("ERROR: Laboratory Name not Entered\n\nPlease enter the name of the laboratory where the order will be delivered.");
		OrderForm.DeliveryLabName.select();
		return false;
	}
	if(OrderForm.DeliveryAddress.value.length<20){
		OrderForm.DeliveryAddress.style.backgroundColor="#FFC0C0";
		alert("ERROR: Laboratory Address not Entered\n\nPlease enter the address of the laboratory where the order will be delivered.");
		OrderForm.DeliveryAddress.select();
		return false;
	}
	if(OrderForm.DeliveryPostCode.value.length<5){
		OrderForm.DeliveryPostCode.style.backgroundColor="#FFC0C0";
		alert("ERROR: Laboratory Post Code not Entered\n\nPlease enter the post code of the laboratory where the order will be delivered.");
		OrderForm.DeliveryPostCode.select();
		return false;
	}
	if(OrderForm.InvoiceLabName.value.length<3){
		OrderForm.InvoiceLabName.style.backgroundColor="#FFC0C0";
		alert("ERROR: Laboratory Name not Entered\n\nPlease enter the name of the laboratory where the order will be invoiced.");
		OrderForm.InvoiceLabName.select();
		return false;
	}
	if(OrderForm.InvoiceAddress.value.length<20){
		OrderForm.InvoiceAddress.style.backgroundColor="#FFC0C0";
		alert("ERROR: Invoice Address not Entered\n\nPlease enter the address of the laboratory where the order will be invoiced.");
		OrderForm.InvoiceAddress.select();
		return false;
	}
	if(OrderForm.InvoicePostCode.value.length<5){
		OrderForm.InvoicePostCode.style.backgroundColor="#FFC0C0";
		alert("ERROR: Invoice Post Code not Entered\n\nPlease enter the post code of the laboratory where the order will be invoiced.");
		OrderForm.InvoicePostCode.select();
		return false;
	}
	if(OrderForm.InvoicePhone.value.length<5){
		OrderForm.InvoicePhone.style.backgroundColor="#FFC0C0";
		alert("ERROR: Invoice Phone Number not Entered\n\nPlease enter the phone number of the laboratory where the order will be invoiced.");
		OrderForm.InvoicePhone.select();
		return false;
	}
	document.getElementById('ProcessingImage_Order').style.visibility="Visible";
	OrderForm.ButtonOrder.style.cursor="Wait";
	OrderForm.ButtonOrder.value="Please Wait";
	OrderForm.ButtonOrder.disabled=true;
	OrderForm.action="PROCESS_checkout.php";
	OrderForm.Process.value="Checkout";
	setTimeout("document.OrderForm.submit();",1000);
}
//-/-Checkoutt Functions-----




















