var mNumber = 10;		//Number of Menus
var mPrefix = "menu";	// Menu element prefix
var nPrefix = "nav";	//  Nav element prefix
var pPrefix = "navpic";	//  Pic element prefix
var mTimer = new Array(mNumber);

function holdmenu(menuid)
{
	if (mTimer[menuid])
	{
		window.clearTimeout(mTimer[menuid]);
	}
	mTimer[menuid] = window.setTimeout("hidemenu('"+menuid+"')",1500);
}

function hideothermenus(menuid)
{
	for(i=1;i<=mNumber;i++)
	{
		if (i != menuid)
		{
			hidemenu(i);
			if (mTimer[i])
			{
				window.clearTimeout(mTimer[i]);
			}
		}
	}
}

function donav(navid,ismenu){
	holdmenu(navid);
	hideothermenus(navid);
	if(ismenu=="Y")
	{
		showmenu(navid);
	}
	dopic(navid,'set');
}
function showmenu(menuid){
	mymenu = document.getElementById(mPrefix+menuid);
	mymenu.style.visibility = "visible";
}
function hidemenu(menuid){
	mymenu = document.getElementById(mPrefix+menuid);
	mymenu.style.visibility="hidden";
	dopic(menuid,'reset');
}
function dopic(navid,action){
	mypic = document.getElementById(pPrefix+navid);
	if (action == "set")
	{
		mypic.style.backgroundPosition = "0px 45px";
	}
	else if (action == "reset")
	{
		mypic.style.backgroundPosition = "0px 0px";
	}
}

/*  Common Functions  */

function APHpopup(veh_id) {
	var gotoURL = "popup.php?veh_id=" + veh_id;
	popWin=window.open(gotoURL,"", "left=200,top=200,width=10,height=10,resizable=yes,scrollbars=no");
	popWin.focus();
}

function APHNewpopup(veh_id) {
	var gotoURL = "popupnew.php?veh_id=" + veh_id;
	popWin=window.open(gotoURL,"", "left=200,top=200,width=10,height=10,resizable=yes,scrollbars=no");
	popWin.focus();
}

function APHOffpopup(veh_id) {
	var gotoURL = "popupoffer.php?offer_id=" + veh_id;
	popWin=window.open(gotoURL,"", "left=200,top=200,width=10,height=10,resizable=yes,scrollbars=no");
	popWin.focus();
}

function checkphone(input){
	var teststring = ("1234567890 ");
	var pass = true;
	for (var i = 0; i < input.length; i++)	{
		var found = false;
		for (var j = 0; j < teststring.length; j++)		{
			if (input.charAt(i) == teststring.charAt(j)) found = true;	}
			if (!found) pass = false;	}
   return (pass);
 }

function checkenquiry(myForm) 
{
	var myalertstring = "";

	if (myForm.firstname.value=="")
	{
		myalertstring = myalertstring + "Please enter your first name or an initial\n" ;
	}

	if (myForm.lastname.value=="")
	{
		myalertstring = myalertstring +  "Please enter your last name\n" ;
	}

	if (myForm.address1.value=="")
	{
		myalertstring = myalertstring +  "Please enter the first line of your address\n" ;
	}

	if (myForm.city.value=="")
	{
		myalertstring = myalertstring +  "Please your city\n" ;
	}

	if (myForm.postcode.value=="")
	{
		myalertstring = myalertstring +  "Please enter your postcode\n" ;
	}

	if (!(checkphone(myForm.tel_day.value)))
	{
		myalertstring = myalertstring +  "Daytime telephone number must contain only digits 0-9 or spaces\n" ;
	}

	if (!(checkphone(myForm.tel_eve.value)))
	{
		myalertstring = myalertstring +  "Evening telephone number must contain only digits 0-9 or spaces\n" ;
	}

	if (myalertstring != "")
		{
		alert(myalertstring + "Please correct your entries and try again.");
		return (false);
		}
	return (true);
}

function swap(imgIndex) {
    document.main_img.src = document.arrayImages[imgIndex];
}

function preloadImages()
{
	var numpics = arguments.length;
	document.arrayImages = new Array(numpics) 
	for (var i=0; i < numpics; i++)
	{
    	var preload = new Image();
		document.arrayImages[i] = arguments[i];
    	preload.src = document.arrayImages[i];
	}
}