function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
	request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_type = new XMLHttpRequest();
	}
		return request_type;
}
//Creating httpRequest Variables to used in home page "index.php"
var http = createObject();

function getCheckedValue(radioObj) {
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function sendrequest() {
q = document.getElementById('name').value;
r = document.getElementById('company').value;
s = document.getElementById('telephone').value;
t = document.getElementById('email').value;
u = document.getElementById('location').value;
v = document.getElementById('staff').value;
w = document.getElementById('textarea').value;
x = getCheckedValue(document.forms['enquiry'].elements['currently']);
// Set te random number to add to URL request
nocache = Math.random();
// Set te random number to add to URL request
nocache = Math.random();
http.open('get', 'ajax/send.php?q='+q+'&nocache = '+nocache+'&r='+r+'&s='+s+'&t='+t+'&u='+u+'&v='+v+'&w='+w+'&x='+x);
http.onreadystatechange = Reply;
http.send(null);

}

function Reply() {
if(http.readyState == 4){
window.location='thankyou.php';
}
}

//positioning the menu
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupWidth2 = document.getElementById('submenu').style.width;
	var popupHeight = document.getElementById('submenu').style.height;
	var popupWidth2=parseInt(popupWidth2);
	//centering
	$("#submenu").css({
		"position": "absolute",
		"top": 219,
		"left": (windowWidth/2-popupWidth2/2)+diff
	});
	$("#logo").css({
		"position": "absolute",
		"left": windowWidth/2-popupWidth2/2-350
	});
	//only need force for IE6
	
}
//Menu code ends


var popupStatus = 0;
var closetimer = 0;

function showmenu(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		window.clearTimeout(closetimer);
		$("#submenu").fadeIn("fast");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function starttime(){

	closetimer = window.setTimeout(hidemenu, 2000);		
		popupStatus = 1;

}
function hidemenu(){
	//disables popup only if it is enabled
	if(popupStatus==1){

		$("#submenu").fadeOut("fast");
				popupStatus = 0;

	}
}

function canceltimer()
{
	if(closetimer)
   {  window.clearTimeout(closetimer);

   popupStatus = 1;
      closetimer = null;}}
	  
$(document).ready(function()
{  centerPopup();

$("#fruitguide").mouseover(function(){
		//centering with css
							showmenu();

					canceltimer();

		//load popup
});
$("#fruitguide").mouseout(function(){
		//centering with css
		
			starttime();
	//load popup
});

$(".buttoselected").mouseover(function(){
		//centering with css
			canceltimer();
	//load popup
});
$(".buttoselected").mousemove(function(){
		//centering with css
			canceltimer();
	//load popup
});

$("#submenu").mousemove(function(){
		//centering with css
			canceltimer();
	//load popup
});

$("#submenu").mouseover(function(){
		//centering with css
			canceltimer();
	//load popup
});


$("#submenu").mouseout(function(){
		//centering with css
			starttime();
	//load popup
});

$("img").error(function () {
  $(this).unbind("error").attr("src", "images/noimage.jpg");
});
   });
