// JavaScript Document

var xmlHttp;
var jstimer_clock = new Array();
var jswltimer = new Array();
var vstatus = new Array();
var vplock = new Array();

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function getModels(str)
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  } 
		var url="js_getmodels.php";
		url=url+"?manufacturer="+str;
		xmlHttp.onreadystatechange=stateChangedModels;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	};
	

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateChangedModels() 
	{ 
		if (xmlHttp.readyState==4)
		{ 
			document.getElementById("modelList").innerHTML=xmlHttp.responseText;
		}
	};
	

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function getMakes(str)
	{ 
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			  {
				  alert ("Your browser does not support AJAX!");
				  return;
			  } 
		var url="js_getmakes.php";
		url=url+"?region="+str;
		xmlHttp.onreadystatechange=stateChangedMakes;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	};

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function stateChangedMakes() 
	{ 
		if (xmlHttp.readyState==4)
			{ 
				if (document.getElementById("makeList"))
					{
						document.getElementById("makeList").innerHTML=xmlHttp.responseText;
					}
			}
	};
	
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttp=new XMLHttpRequest();
		  }
	catch (e)
		  {
		  // Internet Explorer
			try
			{
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
	catch (e)
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
	  	}
	return xmlHttp;
	};
	
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function getTheTimeChosen( until, currentTime, id )
	{
		//var dow = new Array('SUNDAY','MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY');
		var dow = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		now = new Date(currentTime);
		//y2k = new Date("Jan 1 2055 14:00:00");
		thenDate = new Date(until);
		days = (thenDate - now) / 1000 / 60 / 60 / 24;
		daysRound = Math.floor(days);
		var countdown = "";
		if (daysRound >= 1)
			{
				if (daysRound >= 6)
					{
						// more than 7 days, so a skip date must be active
						var when = dow[thenDate.getDay()] + ", " + thenDate.getDate() + "/" + (thenDate.getMonth()+1) + "/" + thenDate.getFullYear();
						var day = '<span class=\"ajax_time\">Ends: </span> <span class=\"ajax_countdown_days\">' + when + '</span>' ;
						return day;
					}
				else
					{
						var dayThen = thenDate.getDay();
						var day = '<span class=\"ajax_time\">Ends: </span> <span class=\"ajax_countdown_days\">' + dow[dayThen] + '</span>' ;
						return day;
					}
			}
		else
			{
				hours = (thenDate - now) / 1000 / 60 / 60 - (24 * daysRound);
				hoursRound = Math.floor(hours);
				minutes = (thenDate - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
				minutesRound = Math.floor(minutes);
				seconds = (thenDate - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
				secondsRound = Math.round(seconds);
				if (days < 0 || (hours <1 && minutes <1 && seconds < 1) )
					{
						//countdown = "Closed";
						countdown_value = "";
						countdown = "<div class=\"ajax_closing\"><span class=\"ajax_closing\">Auction closing</span></div>";
					}
				else
					{
						countdown = "<span class=\"ajax_time\">Ends: </span>" + formatCountdownTimer ( zeroPad(hoursRound,2), zeroPad(minutesRound,2), zeroPad(secondsRound,2) );
					}
				return ( countdown );
			}
	};

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function updateChosenVehicle(ids)
	{
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
				alert ("Your browser does not support AJAX!");
				return;
			}
		var randomnumber=Math.floor(Math.random()*10000000000);
		var url="ajax_update_vehicle.php";
		url=url+"?ids="+ids;
		url=url+"&unique="+randomnumber;
		url=url+"&displaymode=1" ;
		xmlHttp.onreadystatechange=function()
		{ 
		if (xmlHttp.readyState==4)
			{ 
				var text = xmlHttp.responseText;
				var ids = text.split("**");
				for (j=0; j<ids.length; j++)
				{
				var d = ids[j];
				var details = d.split("!!");
				if (document.getElementById('acount'+details[0]) && details !='') 
					{
						var sectionA =  "";
						var sectionB =  "";
						var countdown =  "";
						var minbid = parseInt(details[12]) + 10;
						sectionB = "<input type=\"hidden\" id='minbid' name='minbid' value=\"" + minbid +"\" />";
						if (details[16] == "o")
							{
								// vehicle open
								var updatebuttons = 1;
								var currentvalue = document.getElementById("updatebid").value;
								if (currentvalue == minbid)
									{
										// means buttons have not changed
										updatebuttons = 0;
									}
								// now set the current price in the hidden field
								document.getElementById("updatebid").value = minbid;
								countdown = '<p class=\"countdowntimer\">';
								countdown += getTheTimeChosen(details[4], details[14], details[0]);
								countdown += '</p>';
								document.getElementById('countdown'+details[0]).innerHTML= countdown;
								// if sync time is available, resync now
								if (document.getElementById("servertime_sync_time"))
									{
										document.getElementById("servertime_sync_time").value = details[14];
									}
								// are we logged in
								// 0 = not logged in, 1 = no bids, 2 = winning, 3 = not winning
								if (details[5] != "0")
									{
										var vid = details[0];
										vstatus[vid] = 0;
										var button_start = parseInt(details[12]);
										var firstbid = button_start + 10;
										var secondbid = button_start + 20;
										var thirdbid = button_start + 50;
										var fourthbid = button_start + 100;
										sectionB += "<form id='vehicle_buttons' name='vehicle_buttons'>";
										sectionB += "<div class='vehicle_item_bid_button_holder' ><div class='vehicle_item_bid_button_bid_label'>BID NOW:</div><div class='vehicle_item_bid_buttons'>";
										sectionB += '<span id=\"buttons_' + details[0] + '\">';
										sectionB += "<input type=\"button\" id=\"but1\" name=\"but1\" style=\"width: 70px;\" onclick=\"vd_placeButtonBid('"+ details[0] + "','" + firstbid + "','" + details[18] + "');\" value=\"&pound;" + firstbid +"\" />"; 
										sectionB += "<input type=\"button\" id=\"but2\" name=\"but2\" style=\"width: 70px;\" onclick=\"vd_placeButtonBid('"+ details[0] + "','" + secondbid + "','" + details[18] + "');\" value=\"&pound;" + secondbid +"\" />"; 
										sectionB += "<input type=\"button\" id=\"but3\" name=\"but3\" style=\"width: 70px;\" onclick=\"vd_placeButtonBid('"+ details[0] + "','" + thirdbid + "','" + details[18] + "');\" value=\"&pound;" + thirdbid +"\" />"; 
										sectionB += "<input type=\"button\" id=\"but4\" name=\"but4\" style=\"width: 70px;\" onclick=\"vd_placeButtonBid('"+ details[0] + "','" + fourthbid + "','" + details[18] + "');\" value=\"&pound;" + fourthbid +"\" />"; 
										sectionB += "</div></span></form>";
										// winning section
										if (details[5]=="2") // winning
											{
												sectionA = "<p id=\"winning\" style=\"font-size:0.7em\" >You are winning this auction</p>";
											}
										if (details[5]=="3") // not winning
											{
												sectionA = "<p id=\"notwinning\" style=\"font-size:0.7em\">You are losing this auction</p>";
											}
										if (details[5]=="1" || details[11]==0) // no bids
											{
												sectionA = "<p id=\"nobids\" style=\"font-size:0.7em\">You have not bid</p>";
											}
									} // not logged in
								else
									{
										// not logged in only code
										sectionA = "<p id=\"notloggedin\" style=\"font-size:0.7em\" >You are not logged in</p>";
										// stop timer
										if (chosen_timer)
											{
												clearInterval(chosen_timer);
											}
										
									}
									// this section shows when not logged in
									// highest bid
									if (details[5]=="1" || details[11]==0) // no bids
										{
											sectionA = "<p id=\"nobids\" style=\"font-size:0.7em\">You have not bid</p>";
										}
									// highest bid
									sectionA += "<p id=\"highest\">";
									sectionA += "Highest Bid:<span class=\"ajax_highestbid\">&pound;" + details[6] + "</span>";
									// proxy symbol
									sectionA += "<span style=\"float:right;padding-top:3px;\">";
									if (details[8] == 1)
										{
											sectionA += "<img src=\"images/site_images/proxy.png\" alt=\"Indicates that a higher proxy bid exists\" />";
										}
									if (details[9] == -1) 
										{ 
											sectionA += " <img src=\"/style/images/reserve_unknown.png\" alt=\"\" />";
										}
									if (details[9] == 0)
										{
											sectionA += " <img src=\"/style/images/reserve_notmet.png\" alt=\"\" />";
										}
									if (details[9] == 1) 
										{
											sectionA += " <img src=\"/style/images/reserve_met.png\" alt=\"\" />";
										}
									if (details[18] == 1)
										{
											sectionA += " <img src=\"style/images/ae.png\" alt=\"Indicates that the auction auto extends\" />";
										}
									// view bids
									//sectionA += " <a href=\"javascript:popup_sized('view_bids.php?value="+ details[0] +"', 650, 600)\">View Bids</a>";
									sectionA += " <a href=\"javascript:popup_sized('view_bids.php?value="+ details[0] +"', 650, 600)\"><img src=\"style/images/vb.png\" alt=\"View bids\" /></a>";
									// close wrapper
									// VAT
									if (details[10]=='1')
										{
											sectionA += "<br /><img src=\"style/images/vat.png\" alt=\"Vehicle has VAT\" />";
										}
									sectionA += "</span>";
									sectionA += "</p>";
									sectionA += "<p id=\"yourmax\" >";
									// your max
									if (details[11]!=0)
										{ 
											if (details[5] =="2")
												{
													sectionA += "Your Max Bid" + ':<span class=\"ajax_yourhighestbid\">&pound;' + details[11] + "</span>"; 
												}
											else
												{
													sectionA += "Your Last Bid" + ':<span class=\"ajax_yourlastbid\">&pound;' + details[11] + "</span>"; 
												}
										}
									sectionA += "&nbsp;</p>";
								document.getElementById('acount'+details[0]).innerHTML=sectionA;
								if (updatebuttons == 1)
									{
										document.getElementById('bcount'+details[0]).innerHTML=sectionB;
									}
								// enable all the buttons
								if (details[5] != "0")
									{
										// buttons only exist when logged in....
										document.vehicle_bidding_console.bid_other.disabled = false;
										document.getElementById("bid_now").style.visibility = "visible";
										document.vehicle_buttons.but1.disabled = false;
										document.vehicle_buttons.but2.disabled = false;
										document.vehicle_buttons.but3.disabled = false;
										document.vehicle_buttons.but4.disabled = false;
									}
								document.getElementById("amvisible").value = "1";
							}
						else
							{
								//document.getElementById('count'+details[0]).innerHTML="Closing";
								//disable all the buttons
								var status = document.getElementById("amvisible").value;
								if (status == 1 && details[5] != "0")
									{
										document.vehicle_bidding_console.bid_other.disabled = true;
										document.getElementById("bid_now").style.visibility = "hidden";
										document.vehicle_buttons.but1.disabled = true;
										document.vehicle_buttons.but2.disabled = true;
										document.vehicle_buttons.but3.disabled = true;
										document.vehicle_buttons.but4.disabled = true;
										document.getElementById("amvisible").value = "0";
									}
								clearChosenVehicle(details[0]);
							}
						} 
					}
				}
		};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	};

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function getTimeWatch( id, closingtime, nowtime )
	{
		//var dow = new Array('SUNDAY','MONDAY','TUESDAY','WEDNESDAY','THURSDAY','FRIDAY','SATURDAY');
		var dow = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		//alert(" id = " + id + " closingtime = " + closingtime + " nowtime = " + nowtime);
		now = new Date(nowtime);
		thenDate = new Date(closingtime);
		days = (thenDate - now) / 1000 / 60 / 60 / 24;
		daysRound = Math.floor(days);
		
		if (now.getDate() == thenDate.getDate() && now.getMonth() == thenDate.getMonth() && now.getYear() == thenDate.getYear())
			{
				var displayday = 0;
			}
		else
			{
				var displayday = 1;
			}
				

		// checks if displaying only days
		if (displayday == 1)
			{
				if (daysRound >= 6)
					{
						// more than 7 days, so a skip date must be active
						var when = dow[thenDate.getDay()] + ", " + thenDate.getDate() + "/" + (thenDate.getMonth()+1) + "/" + thenDate.getFullYear();
						var countdown = '<span class=\"ajax_time\">Ends: </span> <span class=\"ajax_countdown_days\">' + when + '</span>' ;
						
					}
				else
					{
						var dayThen = thenDate.getDay();
						var countdown = '<span class=\"ajax_time\">Ends: </span> <span class=\"ajax_countdown_days\">' + dow[dayThen] + '</span>' ;
						
					}
				//var dayThen = thenDate.getDay();
				//var countdown = '<p class=\"countdowntimer\"><span class=\"ajax_time\">Ends: </span> <span class=\"ajax_countdown_days\">' + dow[dayThen] + '</span>' ;
				//countdown += '<span class="ajax_wl_updatenow"><a href="javascript:void(0);" onclick="updateWatchList(' + id + ', 1);" />Update now</a></span></p>';
			}
		else
			{
				hours = (thenDate - now) / 1000 / 60 / 60 - (24 * daysRound);
				hoursRound = Math.floor(hours);
				minutes = (thenDate - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
				minutesRound = Math.floor(minutes);
				seconds = (thenDate - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
				secondsRound = Math.round(seconds);
				
				if ((hoursRound <= 0 && minutesRound <= 0 && secondsRound <= 0) || (daysRound != 0))
					{
						countdown = "<div class=\"ajax_closing\"><span class=\"ajax_closing\">Auction closing</span></div>";
					}
				else
					{
						countdown = "<span class=\"ajax_time\">Ends: </span>" + formatCountdownTimer ( zeroPad(hoursRound,2), zeroPad(minutesRound,2), zeroPad(secondsRound,2) );
					}
			}
			if (countdown)
				{
					document.getElementById("countdown_"+id).innerHTML = countdown;
				}
			return daysRound;
	};
	
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function prepareVehicleCache(ids)
{
	// this function simply prepares new_cache when viewing a vehicle for the first time on mywatchlist
   xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var randomnumber=Math.floor(Math.random()*10000000000);
    var url="ajax_populate_cache.php";
    url=url+"?ids="+ids;
    url=url+"&unique="+randomnumber;
    url=url+"&clear_cache=true";
    xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==4)
        { 
            var text = xmlHttp.responseText;
			//alert(text);
			// do nothing with the text
		}
	};
	xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
};


// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function updateWatchList(ids, displaymode)
	{
		//displaymode 1=update all, 0=only ending
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
				alert ("Your browser does not support AJAX!");
				return;
			}
		var randomnumber=Math.floor(Math.random()*10000000000);
		var url="ajax_update_vehicle.php";
		url=url+"?ids="+ids;
		url=url+"&unique="+randomnumber;
		url=url+"&clear_cache=true";
		url=url+"&displaymode=" + displaymode;
		xmlHttp.onreadystatechange=function()
			{ 
				if (xmlHttp.readyState==4)
					{ 
						var text = xmlHttp.responseText;
						var ids = text.split("**");
						for (j=0; j<ids.length; j++)
							{
								var d = ids[j];
								var details = d.split("!!");
								if (document.getElementById('count'+details[0]+'a')) 
									{
										// means we have a vehicle box on the page to update
										var sectionA =  "";
										var minbid = parseInt(details[12]) + 10;
										var idname = "minbid_" + details[0];
										sectionB = "<input type=\"hidden\" id='" + idname + "' name='" + idname + "' value=\"" + minbid +"\" />";
										if (details[16] == "o")
											{
												// the vehicle is open
												// assume update buttons
												var updatebuttons = 1;
												var updatename = "updatebid_" + details[0];
												// get current button value
												var currentvalue = document.getElementById(updatename).value;
												if (currentvalue == minbid)
													{
														// means buttons have not changed
														updatebuttons = 0;
													}
												// now set the current price in the hidden field
												document.getElementById(updatename).value = minbid;
												// closing time 
												countdown = '<div id="countdown_' + details[0] + '" ></div>';
												countdown += '<input type=\"hidden\" id=\"time_'+details[0]+'\" name="\time_"'+details[0]+'\" value="'+details[4]+'">'; 
												document.getElementById('countdown'+details[0]).innerHTML= countdown;
												lastUpdate = new Date(details[14]);          
												lastUpdateDisplay = zeroPad(lastUpdate.getHours(),2) + ":" + zeroPad(lastUpdate.getMinutes(),2) + ":" + zeroPad(lastUpdate.getSeconds(),2);
												// if server time sync is available, update now
												if (document.getElementById("servertime_sync_time"))
													{
														document.getElementById("servertime_sync_time").value = details[14];
													}
												//var contents = document.getElementById('count'+details[0]+'b').innerHTML;
												//var days = getTimeWatch(details[0], 0);
												var days = getTimeWatch(details[0], details[4], details[14]);
												// buttons section
												var button_start = parseInt(details[12]);
												var firstbid = button_start + 10;
												var secondbid = button_start + 20;
												var thirdbid = button_start + 50;
												var fourthbid = button_start + 100;
												sectionB += "<div class='vehicle_item_bid_button_holder' ><div class='vehicle_item_bid_button_bid_label'>BID NOW:</div><div class='vehicle_item_bid_buttons'>";
												sectionB += '<span id=\"buttons_' + details[0] + '\">';
												sectionB += "<input type=\"button\" name=\"wl_button_" + details[0] + "_1\" id=\"wl_buttons_" + details[0] + "_1\" style=\"width: 70px;\" onclick=\"wl_placeButtonBid('"+ details[0] + "','" + firstbid + "','" + details[18] + "');\" value=\"&pound;" + firstbid +"\" />";
												sectionB += "<input type=\"button\" name=\"wl_button_" + details[0] + "_2\" id=\"wl_buttons_" + details[0] + "_2\" style=\"width: 70px;\" onclick=\"wl_placeButtonBid('"+ details[0] + "','" + secondbid + "','" + details[18] + "');\" value=\"&pound;" + secondbid +"\" />"; 
												sectionB += "<input type=\"button\" name=\"wl_button_" + details[0] + "_3\" id=\"wl_buttons_" + details[0] + "_3\" style=\"width: 70px;\" onclick=\"wl_placeButtonBid('"+ details[0] + "','" + thirdbid + "','" + details[18] + "');\" value=\"&pound;" + thirdbid +"\" />"; 
												sectionB += "<input type=\"button\" name=\"wl_button_" + details[0] + "_4\" id=\"wl_buttons_" + details[0] + "_4\" style=\"width: 70px;\" onclick=\"wl_placeButtonBid('"+ details[0] + "','" + fourthbid + "','" + details[18] + "');\" value=\"&pound;" + fourthbid +"\" />"; 
												sectionB += "</div></span>";
												// winning section
												// 0 = not logged in, 1 = no bids, 2 = winning, 3 = not winning
												if (details[5]=="2")
													{
														if (days > 0)
															{
																sectionA = "<p id=\"winning\" style=\"font-size:0.6em\">You were winning this auction at " + lastUpdateDisplay + "</p>";
															}
														else
															{
																sectionA = "<p id=\"winning\" style=\"font-size:0.7em\">You are winning this auction</p>";
															}
														
													}
												if (details[5]=="3")
													{
														if (days >= 1)
															{
																sectionA = "<p id=\"notwinning\"  style=\"font-size:0.6em\">You were losing this auction at " + lastUpdateDisplay + "</p>";
															}
														else
															{
																sectionA = "<p id=\"notwinning\"  style=\"font-size:0.7em\">You are losing this auction</p>";
															}
															
													}
												if (details[5]=="1" || details[11]==0) // no bids
													{
														sectionA = "<p id=\"nobids\" style=\"font-size:0.7em\">You have not bid</p>";
													}
												// highest bid
												sectionA += "<p id=\"highest\">";
												sectionA += "Highest Bid:<span class=\"ajax_highestbid\">&pound;" + details[6] + "</span>";
												// proxy symbol
												sectionA += "<span style=\"float:right;padding-top:3px;\">";
												if (details[8] == 1)
													{
														sectionA += "<img src=\"images/site_images/proxy.png\" alt=\"Indicates that a higher proxy bid exists\" />";
													}
												if (details[9] == -1) 
													{ 
														sectionA += " <img src=\"/style/images/reserve_unknown.png\" alt=\"\" />";
													}
												if (details[9] == 0)
													{
														sectionA += " <img src=\"/style/images/reserve_notmet.png\" alt=\"\" />";
													}
												if (details[9] == 1) 
													{
														sectionA += " <img src=\"/style/images/reserve_met.png\" alt=\"\" />";
													}
												if (details[18] == 1)
													{
														sectionA += " <img src=\"style/images/ae.png\" alt=\"Indicates that the auction auto extends\" />";
													}
												// view bids
												//sectionA += " <a href=\"javascript:popup_sized('view_bids.php?value="+ details[0] +"', 650, 600)\">View Bids</a>";
												sectionA += " <a href=\"javascript:popup_sized('view_bids.php?value="+ details[0] +"', 650, 600)\"><img src=\"style/images/vb.png\" alt=\"View bids\" /></a>";
												// close wrapper
												// VAT
												if (details[10]=='1')
													{
														sectionA += "<br /><img src=\"style/images/vat.png\" alt=\"Vehicle has VAT\" />";
													}
												sectionA += "</span>";
												sectionA += "</p>";
												// wrapper
												sectionA += "<p id=\"yourmax\" >";
												// your max
												if (details[11]!=0)
													{ 
														if (details[5] =="2")
															{
																sectionA += "Your Max Bid" + ':<span class=\"ajax_yourhighestbid\">&pound;' + details[11] + "</span>"; 
															}
														else
															{
																sectionA += "Your Last Bid" + ':<span class=\"ajax_yourlastbid\">&pound;' + details[11] + "</span>";  
															}
													}
												sectionA += "&nbsp;</p>";
												document.getElementById('count'+details[0]+'a').innerHTML=sectionA;
												if (updatebuttons == 1)
													{
													document.getElementById('count'+details[0]+'b').innerHTML=sectionB;
													}
												var buttonname = "wl_button_" + details[0];
												document.form2[buttonname + "_1"].disabled = false;
												document.form2[buttonname + "_2"].disabled = false;
												document.form2[buttonname + "_3"].disabled = false;
												document.form2[buttonname + "_4"].disabled = false;
												var othername = "bid_other_" + details[0];
												document.form2[othername].disabled = false;
												var othergo = "wl_go_" + details[0];
												document.getElementById(othergo).style.visibility = "visible";
												// sets the button status to visible, so they can be made invisible
												var vis = "amvisible_" + details[0];
												document.getElementById(vis).value = "1";
												var vid = details[0];
												vstatus[vid] = 0;
											} // if (details[16] == "o")
										else
											{
												// vehicle closed or any other condition (not open)
												var vid = details[0];
												var vis = "amvisible_" + details[0];
												var status = document.getElementById(vis).value;
												if (status == 1)
													{
														// if buttons are on page, then disable them.  Stops js errors for non-existent elements
														var buttonname = "wl_button_" + vid;
														document.form2[buttonname + "_1"].disabled = true;
														document.form2[buttonname + "_2"].disabled = true;
														document.form2[buttonname + "_3"].disabled = true;
														document.form2[buttonname + "_4"].disabled = true;
														var othername = "bid_other_" + vid;
														document.form2[othername].disabled = true;
														var othergo = "wl_go_" + vid;
														document.getElementById(othergo).style.visibility = "hidden";
														// sets the visibility status to zero, so we know they have been done already
														document.getElementById(vis).value = "0";
													}
												clearWatchListVehicle(vid);
											} // if (details[16] == "o") or closed
									} // if (document.getElementById('count'+details[0]+'a'))
							} // for (j=0; j<ids.length; j++)
					} // xmlHttp.onreadystatechange=function()
			}; // if (xmlHttp.readyState==4)
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	};
 

function updateSearch()
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var randomnumber=Math.floor(Math.random()*10000000000);
    var url="js_updatesearch.php";
    url=url+"?unique="+randomnumber;
    url=url+"&SpecialistAuction="+document.getElementById("SpecialistAuction").value;
    url=url+"&region="+document.getElementById("region").value;
    url=url+"&make="+document.getElementById("make").value;
    url=url+"&fueltype="+document.getElementById("fueltype").value;
    url=url+"&transmission="+document.getElementById("transmission").value;
    url=url+"&freetext="+document.getElementById("freetext").value;
    url=url+"&orderby="+document.getElementById("orderby").value;
    url=url+"&catcode="+document.getElementById("catcode").value;
    xmlHttp.onreadystatechange=function()
	{ 
        if (xmlHttp.readyState==4)
        { 
            document.getElementById('searchBoxes').innerHTML=xmlHttp.responseText;
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
};


function updateTimeLeftSingle(id)
{
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var randomnumber=Math.floor(Math.random()*10000000000);
    var url="closingtimesingle.php";
    url=url+"?ID="+id;
    url=url+"&unique="+randomnumber;
    xmlHttp.onreadystatechange=function()
	{ 
        if (xmlHttp.readyState==4)
        { 
            document.getElementById('timeleftsingle').innerHTML=xmlHttp.responseText;
        }
    };
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    setTimeout("updateTimeLeftSingle(" + id + ")",1000);
};


function vd_placeButtonBid(value, bid, ae )
{
    //document.getElementById('buttons_'+value).innerHTML='Please wait...';
	//document.getElementById('buttons_'+value).innerHTML='<img src="/images/ajax/ajax1.png" alt="" />';
    //document.getElementById('bid_other_'+value).innerHTML='..';
    xmlHttp2=GetXmlHttpObject();
    if (xmlHttp2==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var randomnumber=Math.floor(Math.random()*10000000000);
    var url="ajax_place_bid.php";
    url=url+"?value="+value;
    url=url+"&bid="+bid;
	url=url+"&p=1";
	url=url+"&ae="+ae;
    url=url+"&unique="+randomnumber;
    xmlHttp2.onreadystatechange=function()
	{
        if (xmlHttp2.readyState==4)
        {
         // nothing returned 
        }
    };
    xmlHttp2.open("GET",url,true);
    xmlHttp2.send(null);
	pausecomp(1000);
	// tell clock to resync
	if (document.getElementById("servertime_sync"))
		{
			document.getElementById("servertime_sync").value == 1;
		}
};


function vd_placeOtherBid(value, bid, ae )
{
	//alert ("Got Value: " + value + " Got Bid: " + bid + " Got Minbid: " + minbid);
	var minbid = document.getElementById("minbid").value;
	var maxbid = document.getElementById("maxbid_" + value).value;

    //document.getElementById('buttons_'+value).innerHTML='Please wait...' + minbid;
	//document.getElementById('buttons_'+value).innerHTML='Please wait...';
	//document.getElementById('buttons_'+value).innerHTML='<img src="/images/ajax/ajax1.png" alt="" />';
    //document.getElementById('bid_other_'+value).innerHTML='..';
	xmlHttp3=GetXmlHttpObject();
    if (xmlHttp3==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
	
	if (!IsNumeric (bid))
		{
			alert("Your bid must be a number");
			return
		}
		
	bid = parseInt(bid);
	minbid = parseInt(minbid);
	
	if (bid < minbid)
	   {
		   alert("Your bid must be at least \u00a3" + minbid);
		   return;
	   }
	   
	if (minbid < maxbid)
		{
			if (bid > maxbid)
			   {
				   alert("Your bid cannot exceed \u00a3" + maxbid);
				   return;
			   }
		}

	   
	if (bid%10 > 0)
       {
         alert("Your bid must be a multiple of \u00a310");
		 return;
       }
    
	if (bid > 0)
          {
             var randomnumber=Math.floor(Math.random()*10000000000);
             var url="ajax_place_bid.php";
             url=url+"?value="+value;
             url=url+"&bid="+bid;
             url=url+"&p=2";
			 url=url+"&ae="+ae;
             url=url+"&unique="+randomnumber;
             xmlHttp3.onreadystatechange=function()
			 {
                 if (xmlHttp3.readyState==4)
                 {
                  //   updateTimeLeft();
                  //document.getElementById('mpw').innerHTML=xmlHttp2.responseText; 
                 }
             };
             xmlHttp3.open("GET",url,true);
             xmlHttp3.send(null);
			 pausecomp(1000);
			 // tell clock to resync
			if (document.getElementById("servertime_sync"))
				{
					document.getElementById("servertime_sync").value == 1;
				}
          }
          else
          {
             alert ("Invalid Bid");
          }
	
    //document.getElementById('buttons_'+value).innerHTML='Please wait...';
	
};


function wl_placeOtherBid(value, bid, ae)
{
	var idname = "minbid_" + value;
	var minbid = document.getElementById(idname).value;
	var maxbid = document.getElementById("maxbid_" + value).value;
	xmlHttp3=GetXmlHttpObject();
    if (xmlHttp3==null)
		{
			alert ("Your browser does not support AJAX!");
			return;
		}
	
	if (!IsNumeric (bid))
		{
			alert("Your bid must be a number");
			return
		}
		
	bid = parseInt(bid);
	minbid = parseInt(minbid);
	
	if (bid < minbid)
	   {
		   alert("Your bid must be at least \u00a3" + minbid);
		   return;
	   }
	
	if (minbid < maxbid)
		{
			if (bid > maxbid)
			   {
				   alert("Your bid cannot exceed \u00a3" + maxbid);
				   return;
			   }
		}
	   
	if (bid%10 > 0)
       {
         alert("Your bid must be a multiple of \u00a310");
		 return;
       }
    
	if (bid > 0)
          {
             var randomnumber=Math.floor(Math.random()*10000000000);
             var url="ajax_place_bid.php";
             url=url+"?value="+value;
             url=url+"&bid="+bid;
			 url=url+"&p=4";
			 url=url+"&ae="+ae;
             url=url+"&unique="+randomnumber;
             xmlHttp3.onreadystatechange=function()
			 {
                 if (xmlHttp3.readyState==4)
                 {
					// do nothing...
				}
             };
             xmlHttp3.open("GET",url,true);
             xmlHttp3.send(null);
			 pausecomp(1000);
			 // tell clock to resync
			if (document.getElementById("servertime_sync"))
				{
					document.getElementById("servertime_sync").value = 1;
				}
			// update in one second (used in cases where vehicle is over one day old and will never update automatically
			vstatus[value] = 0;
			setTimeout("updateWatchList(" + value + ", 1)", 1500);
          }
          else
          {
             alert ("Invalid Bid");
          }
};


function wl_placeButtonBid(value, bid, ae )
{
    //document.getElementById('buttons_'+value).innerHTML='Please wait...<br />(or press refresh)';
    //document.getElementById('bid_other_'+value).innerHTML='..';
    xmlHttp2=GetXmlHttpObject();
    if (xmlHttp2==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var randomnumber=Math.floor(Math.random()*10000000000);
    var url="ajax_place_bid.php";
    url=url+"?value="+value;
    url=url+"&bid="+bid;
	url=url+"&p=3";
	url=url+"&ae="+ae;
    url=url+"&unique="+randomnumber;
    xmlHttp2.onreadystatechange=function()
	{
        if (xmlHttp2.readyState==4)
        {
			// do nothing as such 
        }
    };
    xmlHttp2.open("GET",url,true);
    xmlHttp2.send(null);
	//clearWatchListButtons(value);
	pausecomp(1000);
	// tell clock to resync
	if (document.getElementById("servertime_sync"))
		{
			document.getElementById("servertime_sync").value == 1;
		}
	// update in one second (used in cases where vehicle is over one day old and will never update automatically
	// we wait one second in order for the CRON job to update the records
	// 1200 works on IE, 1000 doesn't....
	setTimeout("updateWatchList(" + value + ", 1)", 1200);
	setTimeout("updateWatchList(" + value + ", 1)", 2500);
	// set vehicle status to zero
	vstatus[value] = 0;
};

function clearWatchListVehicle(id)
	{
		// we check the vehicle status to see if we are called several times
		// so it will take two goes through this code before clearout occurs
		//document.getElementById("countdown" + id).innerHTML="cwlv: " + vstatus[id];
		if (typeof vstatus[id] == "number")
			{
				if (vstatus[id] < 2)
					{
						vstatus[id]++;
					}
				else
					{
						var update = "show_closed_status_" + id;
						var updatestatus = document.getElementById(update).value;
						if (updatestatus == 0)
							{
								//alert("clearWatchListVehicle with id " + id);
								document.getElementById("countdown" + id).innerHTML="";
								// closes the winning / losing section
								document.getElementById('count'+id+'a').innerHTML = "";
								// closes the buttons sections
								document.getElementById('count'+id+'b').innerHTML = "";
								// closes the placeotherbid

								document.getElementById("watchlist_placeotherbid_" + id).innerHTML = "";
								// calls the display won / lost / closed / not logged in panel
								showClosedStatus( id, 'count' + id + 'b', 2);
							}
					}
			}
		else	
			{
				//no record, so set first one to zero
				vstatus[id] = 0;
			}
	};
	
function clearChosenVehicle(id)
	{
		// we check the vehicle status to see if we are called several times
		// so it will take two goes through this code before clearout occurs
		//document.getElementById('count'+id).innerHTML="cwlv: " + vstatus[id];
		if (typeof vstatus[id] == "number")
			{
				if (vstatus[id] < 2)
					{
						vstatus[id]++;
					}
				else
					{
						var update = "show_closed_status_" + id;
						var updatestatus = document.getElementById(update).value;
						// only update if required
						if (updatestatus == 0)
							{
								document.getElementById('acount'+id).innerHTML="";
								document.getElementById('bcount'+id).innerHTML="";
								document.getElementById('countdown'+id).innerHTML="";
								document.getElementById('vehicle_detail_page_bidother').innerHTML = "";
								showClosedStatus( id, "acount" + id, 2);
								if (chosen_timer)
									{
										clearInterval(chosen_timer);
									}
							}
					}
			}
		else	
			{
				//no record, so set first one to zero
				vstatus[id] = 0;
			}
	};
	
function showClosedStatus ( id, panel, where )
	{
		// if panel exists
		var update = "show_closed_status_" + id;
		var updatestatus = document.getElementById(update).value;
		// only update if required
		if (updatestatus == 0)
			{
				if (document.getElementById(panel))
					{
						xmlHttp2=GetXmlHttpObject();
						if (xmlHttp2==null)
						{
							alert ("Your browser does not support AJAX!");
							return;
						}
						var randomnumber=Math.floor(Math.random()*10000000000);
						var url="ajax_show_closed_status.php";
						url=url+"?id="+id;
						url=url+"&panel="+panel;
						url=url+"&where="+where;
						url=url+"&unique="+randomnumber;
						xmlHttp2.onreadystatechange=function()
						{
						if (xmlHttp2.readyState==4)
							{
								// populate panel
								document.getElementById(panel).innerHTML = xmlHttp2.responseText;
								document.getElementById(update).value = 1;
							}
						};
						xmlHttp2.open("GET",url,true);
						xmlHttp2.send(null);
					}
			}
	};
	
function popup_sized(thefile, w, h)
	{
	   appString = "height="+h+","+"width="+w+",alwaysRaised=yes,scrollbars=yes,status=no,toolbar=no,resizable=yes";
	   newWin = window.open(thefile, "Window1", appString);
	   newWin.focus()
	};
	
function formatCountdownTimer( hrs, mins, secs )
	{
		if (hrs < 1)
			{
				var time = "<span class=\"ajax_countdown_1hr\">";
			}
		else
			{
				var time = "<span class=\"ajax_countdown\">";
			}
		time += hrs + ":" + mins + ":" + secs;
		time +="</span>";
		return time;
	};
	
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------
function get_sc(code)
	{
		fade_vl(0);
		if (code == "sort")
			{
				document.getElementById("search_update").className = "search_update_go";
				return;
			}
		//document.getElementById("vs_sa_count").innerHTML = "----";
		wd("vs_sa_count", "0");
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
			{
				document.getElementById("vs_sa_count").innerHTML = "N/A";
				return;
			}
		var r = Math.floor(Math.random()*10000000000);
		var url = "/js_searchcount.php";
		url = url + "?r=" + r;
		url = url + "&code=" + code;
		var types = 0;
		if (document.getElementById("t0").checked == true)
			{
				url = url + "&t0=" + document.getElementById("t0").value;
				types++;
			}
		if (document.getElementById("t1").checked == true)
			{
				url = url + "&t1=" + document.getElementById("t1").value;
				types++;
			}
		if (document.getElementById("t2").checked == true)
			{
				url = url + "&t2=" + document.getElementById("t2").value;
				types++;
			}
		if (document.getElementById("t3").checked == true)
			{
				url = url + "&t3=" + document.getElementById("t3").value;
				types++;
			}
		if (document.getElementById("t4").checked == true)
			{
				url = url + "&t4=" + document.getElementById("t4").value;
				types++;
			}
		//if (types == 0)
			//{
				//document.getElementById("vs_sa_count").innerHTML = "0";
				//wd("vs_sa_count", "1");
				//return;
			//}
		url = url + "&mk=" + document.getElementById("mk").value;
		url = url + "&tr=" + document.getElementById("tr").value;
		url = url + "&fl=" + document.getElementById("fl").value;
		url = url + "&cat=" + document.getElementById("cat").value;
		url = url + "&member=" + document.getElementById("member").value;
		url = url + "&site=" + document.getElementById("site").value;
		url = url + "&d=" + document.getElementById("d").value;
		url = url + "&s=" + document.getElementById("s").value;
		url = url + "&pc=" + document.getElementById("pc").value;
		url = url + "&gn=" + document.getElementById("gn").value;
		url = url + "&ge=" + document.getElementById("ge").value;
		url = url + "&member_site=" + document.getElementById("member_site").value;
		
		xmlHttp.onreadystatechange=function()
			{ 
				if (xmlHttp.readyState==4)
					{
						document.getElementById("vs_sa_count").innerHTML = xmlHttp.responseText;
						wd("vs_sa_count", "1");
						document.getElementById("search_update").className = "search_update_go";
					}
			};
		xmlHttp.open("GET",url,true);
		setTimeout("xmlHttp.send(null);", 250);
		//xmlHttp.send(null);
	};
	
function wd(divid, mode)
	{
		if (mode == "0")
			{
				if (document.getElementById(divid))
					{
						// for firefox / etc
						document.getElementById(divid).style.opacity = "0.3";
						// for ie
						document.getElementById(divid).style.filter = 'alpha(opacity=30)';
					}
			}
		if (mode == "1")
			{
				if (document.getElementById(divid))
					{
						// for firefox /etc
						document.getElementById(divid).style.opacity = "1";
						// for ie
						document.getElementById(divid).style.filter = 'alpha(opacity=100)';
					}
			}
	};
	
function fade_vl(nada)
	{
		// for firefox / etc
		document.getElementById("vehicle_list_area").style.opacity = "0.2";
		// for ie
		document.getElementById("vehicle_list_area").style.filter = 'alpha(opacity=20)';
	};
