 var Class = {
   create: function() {
     return function() {
       if (this.initialize) {
         this.initialize();
       }
     }
   }
 }  
 
WebWindow = Class.create();
WebWindow.prototype = {
	initialize: function() {}
}

/* We define a firebug logger and a null logger (for the null logger, when you call WebWindow.log.debug("Your message") it does nothing */

WebFirebugLogger = Class.create();
WebFirebugLogger.prototype = {
	initialize: function() {},
	
	debug: function() {
		if (console != null) {
			console.debug.apply(this, arguments);
		}
	},
	info: function() {
		if (console != null) {
			console.info.apply(this, arguments);
		}
	},
	error: function() {
		if (console != null) {
			console.error.apply(this, arguments);
		}
	}	
	
};

WebNullLogger = Class.create();
WebNullLogger.prototype = {
	initialize: function() {},
	debug: function() {},
	info: function() {},
	error: function() {}
};


/** Install the logger. **/
try
{
	if (console && console.debug)
	{
		WebWindow.log = new WebFirebugLogger();
		WebWindow.log.debug("Log created.");
	} else {
		WebWindow.log = new WebNullLogger();
	}
}
catch(ex)
{
	// Firebug not installed, use null logger.
	WebWindow.log = new WebNullLogger();
	
}


var AddressAjax = {
	searchTimer: null,
	checkPostcode: function(suburbinput,suburbindicator,suburblister, stateinput, categoryId)
	{
		if (AddressAjax.searchTimer != null)
		{
			clearTimeout(AddressAjax.searchTimer);
			AddressAjax.searchTimer = null;
		}					
		var postcode = $(suburbinput).value;	
		$("state_lister").hide()		
		if (!isNaN(postcode) && postcode.length >= 4)
		{
			$(suburbindicator).show();
			AddressAjax.searchTimer = setTimeout(function()
			{		
				new Ajax.Request("/query/suburbs.aspx", {
					method: 'get',
					parameters: $H({postcode: $(suburbinput).value,category: categoryId,listerCtrl: suburblister,suburbCtrl: $(suburbinput).id,stateCtrl:stateinput}).toQueryString(),					
					onSuccess: function(request)
					{
					
						$(suburblister).update(request.responseText).show();						
					},
					onComplete: function(request)
					{
						$(suburbindicator).hide();
						//alert(request.responseText);
					},
					evalScripts: true
				});
				clearTimeout(AddressAjax.searchTimer);
				AddressAjax.searchTimer = null;			
			}, 500);			
		}
		else if (isNaN(postcode))
		{
			$(suburbindicator).show();
			AddressAjax.searchTimer = setTimeout(function()
			{
				new Ajax.Request("/query/suburbs.aspx", {
					method: 'get',
					parameters: $H({suburb: postcode,state:$(stateinput).value, category: categoryId,listerCtrl: suburblister,suburbCtrl: $(suburbinput).id,stateCtrl:stateinput}).toQueryString(),										
					onSuccess: function(request)
					{						
						$(suburblister).update(request.responseText).show();												
					},
					onComplete: function()
					{
						$(suburbindicator).hide();
					},					
					evalScripts: true
				});
				clearTimeout(AddressAjax.searchTimer);
				AddressAjax.searchTimer = null;			
			}, 500);
		
		}
		else
		{
			$(suburbindicator).hide();
			$(suburblister).update('');
		}
	},
	getStreetTypes: function(streettypeinput,streettypeindicator,streettypelister)
	{
		if (AddressAjax.searchTimer != null)
		{
			clearTimeout(AddressAjax.searchTimer);
			AddressAjax.searchTimer = null;
		}							
		$(streettypeindicator).show();
		AddressAjax.searchTimer = setTimeout(function()
		{		
			new Ajax.Request("/street_type.php", {
				method: 'get',parameters: $H({listerCtrl:streettypelister,streetTypeCtrl:$(streettypeinput).id}),					
				onSuccess: function(request)
				{
					$(streettypelister).update(request.responseText).show();						
				},
				onComplete: function(request)
				{
					$(streettypeindicator).hide();
					//alert(request.responseText);
				},
				evalScripts: true
			});
			clearTimeout(AddressAjax.searchTimer);
			AddressAjax.searchTimer = null;			
		}, 500);					
	},
	getStates: function()
	{
		if (AddressAjax.searchTimer != null)
		{
			clearTimeout(AddressAjax.searchTimer);
			AddressAjax.searchTimer = null;
		}
		$("suburb_lister").hide()							
		$("state_indicator").show();
		AddressAjax.searchTimer = setTimeout(function()
		{		
			new Ajax.Request("/query/states.aspx", {
				method: 'get',parameters:'',					
				onSuccess: function(request)
				{
					$("state_lister").update(request.responseText).show();						
				},
				onComplete: function(request)
				{
					$("state_indicator").hide();
					//alert(request.responseText);
				},
				evalScripts: true
			});
			clearTimeout(AddressAjax.searchTimer);
			AddressAjax.searchTimer = null;			
		}, 500);					
	}
}
var Price =
{
	searchTimer: null,	
	getPriceFrom: function()
		{
		if (Price.searchTimer != null)
		{
			clearTimeout(Price.searchTimer);
			Price.searchTimer = null;
		}
		$("state_lister").hide()
		$("suburb_lister").hide()
		Price.searchTimer = setTimeout(function()
		{		
			new Ajax.Request("/query/pricefrom.aspx", {
				method: 'get',parameters:'',					
				onSuccess: function(request)
				{
					$("pricefrom_lister").update(request.responseText).show();						
				},
				onComplete: function(request)
				{					
				},
				evalScripts: true
			});
			clearTimeout(Price.searchTimer);
			Price.searchTimer = null;			
		}, 500);
	},
		getPriceTo: function()
		{
		if (Price.searchTimer != null)
		{
			clearTimeout(Price.searchTimer);
			Price.searchTimer = null;
		}
		Price.searchTimer = setTimeout(function()
		{		
			new Ajax.Request("/query/priceto.aspx", {
				method: 'get',parameters:'',					
				onSuccess: function(request)
				{
					$("priceto_lister").update(request.responseText).show();						
				},
				onComplete: function(request)
				{					
				},
				evalScripts: true
			});
			clearTimeout(Price.searchTimer);
			Price.searchTimer = null;			
		}, 500);
	}						
}
	
var BidRegister = 
{
	secondsTimer: null,
	timeRemaining: null,
	stage2Timer:null,
	currentBidder:null,
	getBids: function(propertyId,sale_or_auction,price_prefix) // 'Sale' or 'Auction'
		{	
			if(!sale_or_auction){sale_or_auction = 'Auction'}
			if(!price_prefix){price_prefix = 'Asking Price'}
			BidRegister.clearTimer();			
			$.ajax({
				url: 'bidregister.aspx',
				cache: false,
				timeout: 500,
				data:"id="+propertyId,
				error: function(){
					$('#bidregister').html('<img src="images/ajaxloader2.gif" style="position:relative;top:40px;left:115px;"> ');					
				},
				success: function(html){				
					$('#bidregister').html(html);
					WebWindow.log.debug('Call Get Bids : Success');	
					WebWindow.log.debug('Total Seconds Remaining: ' + $('#total_seconds_remaining').val());	
					WebWindow.log.debug('True Time Remaining: ' + $('#true_time_remaining').val());				
					WebWindow.log.debug('Stage: ' + $('#auction_stage').val());															
					WebWindow.log.debug('--------------------------------------------------------------------');
					//Determine the stage of the auction.
																			
					if($('#total_seconds_remaining').val() > 30)
					{
						$('#gavel').hide();				
					}
					if($('#started').val()=="False")
					{
						WebWindow.log.debug('Call Auction Advertised');
						BidRegister.auctionAdvertised(sale_or_auction,price_prefix);	
						return 0;
					}
					
	/*
					if($('#auction_stage').val()=="ThreeHour")
					{
						WebWindow.log.debug('Call Three Hour');					
						BidRegister.threeHourTimer();
					}
					else if($('#auction_stage').val()=="TenMinute")
					{
						WebWindow.log.debug('Call Ten Minute');					
						BidRegister.threeHourTimer();
					}	
					else if($('#auction_stage').val() =="FirstCall")
					{
						WebWindow.log.debug('Call FirstCall');					
						BidRegister.firstCall();
					}
					else if($('#auction_stage').val() =="SecondCall")
					{
						WebWindow.log.debug('Call Three Hour');					
						BidRegister.threeHourTimer();									
					}
					else if($('#auction_stage').val() =="ThirdCall")
					{
						WebWindow.log.debug('Call Auction Commenced');					
						BidRegister.auctionCommenced();									
					}
					
					if($('#auction_stage').val() =="ThreeHour")
					{
						BidRegister.stage2Timer=true;
					}
					else
					{
						BidRegister.stage2Timer=null;	
					}	
	*/
	
	
					if($('#true_time_remaining').val() <=0 || ($("#hasofferaccepted").val() == 'True' && $("#hasofferconfirmed").val() == 'True'))
					{
						WebWindow.log.debug('Call Auction End');					
						BidRegister.auctionEnd(sale_or_auction,price_prefix);
					}
					else if($('#true_time_remaining').val() <= 10800 && $('#total_seconds_remaining').val() > 600)
					{
						WebWindow.log.debug('Call Three Hour');					
						BidRegister.threeHourTimer(sale_or_auction,price_prefix);									
					}
					else if($('#true_time_remaining').val() <= 600 && $('#total_seconds_remaining').val() > 90)
					{
						WebWindow.log.debug('Call Ten Minute');					
						BidRegister.tenMinuteTimer(sale_or_auction,price_prefix);									
					}
					else if($('#true_time_remaining').val() >= 10800)
					{
						WebWindow.log.debug('Call Auction Commenced');					
						BidRegister.auctionCommenced(sale_or_auction,price_prefix);									
					}
					
					if($('#true_time_remaining').val() <= 600)
					{
						BidRegister.stage2Timer=true;
					}
					else
					{
						BidRegister.stage2Timer=null;	
					}					
	/**/
	
					
					
	/* old style calls

																			
					if($('#total_seconds_remaining').val() <=0)
					{
						WebWindow.log.debug('Call Auction End');					
						BidRegister.auctionEnd();
					}
					else if($('#total_seconds_remaining').val() <= 10800 && $('#total_seconds_remaining').val() > 90)
					{
						WebWindow.log.debug('Call Three Hour');					
						BidRegister.threeHourTimer();									
					}
					else if($('#total_seconds_remaining').val() >= 10800)
					{
						WebWindow.log.debug('Call Auction Commenced');					
						BidRegister.auctionCommenced();									
					}
					
					if($('#true_time_remaining').val() <= 600)
					{
						BidRegister.stage2Timer=true;
					}
					else
					{
						BidRegister.stage2Timer=null;	
					}					
	*/
	
					
					BidRegister.setCurrentBid();
					
					BidRegister.setTimeRemaining();
								
					BidRegister.timer(sale_or_auction,price_prefix);
				}
			});
		},
	setCurrentBid: function()
		{
			$('#label_current_bid').html($('#current_bid').val());
		},
	setCurrentBidder: function(bidder)
		{
			if(bidder=="bidder999999999")
			{
				this.currentBidder="Vendor";
			}
			else
			{
				this.currentBidder=bidder;
			}
		},			
	clock: function()
		{				
			$.ajax({
				url: '/query/clock.aspx',
				timeout: 500,
				error: function(){
					//$('#auctionstatusbox').html('');
					BidRegister.clock();
				},
				success: function(html){
					$('#auctionstatusbox').html(html);					
				}
			});
		},
	timer: function(sale_or_auction,price_prefix)
		{			
							
			BidRegister.secondsTimer = setInterval(function()
				{
					WebWindow.log.debug('Call Timer');	
					//if(!((parseInt($('#seconds_remaining').val()) != 0) && (parseInt($('#minutes_remaining').val()) >= 0) && (parseInt($('#hours_remaining').val() >= 0))))
					//if(!(parseInt($('#hours_remaining').val()) == 0 && parseInt($('#minutes_remaining').val()) == 0 && parseInt($('#seconds_remaining').val()) == 0 ))
					//{					
					//	BidRegister.timeRemaining.setSeconds(BidRegister.timeRemaining.getSeconds()-1);	
					//}
					
					var currentsecondstring="";
					var currentminutestring="";
					var currenthourstring="";
					//alert(secondstring.length);
					currentsecondstring=BidRegister.timeRemaining.getSeconds().toString();
					currentminutestring=BidRegister.timeRemaining.getMinutes().toString();
					currenthourstring=BidRegister.timeRemaining.getHours().toString();	
					
					if(!(parseInt(currentsecondstring) == 0 && parseInt(currentminutestring) == 0 && parseInt(currenthourstring) == 0 ))
					{					
						BidRegister.timeRemaining.setSeconds(BidRegister.timeRemaining.getSeconds()-1);	
					}
					//WebWindow.log.debug(parseInt($('#seconds_remaining').val()) & " " & parseInt($('#minutes_remaining').val()) & " " & parseInt($('#hours_remaining').val()));		
					WebWindow.log.debug($('#seconds_remaining').val() + " - " + $('#minutes_remaining').val() + " - " + $('#hours_remaining').val());		
					//alert(BidRegister.timeRemaining);
					var secondstring="";
					var minutestring="";
					var hourstring="";
					//alert(secondstring.length);
					secondstring=BidRegister.timeRemaining.getSeconds().toString();
					minutestring=BidRegister.timeRemaining.getMinutes().toString();
					hourstring=BidRegister.timeRemaining.getHours().toString();	
					if (isNaN(BidRegister.timeRemaining.getSeconds()))
					{
					secondstring = "0";
					minutestring = "0";
					hourstring = "0";
					}
													
					if($('#auction_stage').val()=="ThreeHour")
					{	
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Call Ten Minute Timer');	
							BidRegister.adjustTimer(0,10,0);							
							secondstring=BidRegister.timeRemaining.getSeconds().toString();
							minutestring=BidRegister.timeRemaining.getMinutes().toString();
							hourstring=BidRegister.timeRemaining.getHours().toString();								
							$('#auction_stage').val("TenMinute");
							BidRegister.tenMinuteTimer(sale_or_auction,price_prefix);									
						}
						else
						{
							WebWindow.log.debug('Call Three Hour Timer');
							BidRegister.threeHourTimer(sale_or_auction,price_prefix);
						}																			
					}
					else if($('#auction_stage').val()=="TenMinute")
					{
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Call First Call Timer');	
							BidRegister.adjustTimer(0,0,30);							
							secondstring=BidRegister.timeRemaining.getSeconds().toString();
							minutestring=BidRegister.timeRemaining.getMinutes().toString();
							hourstring=BidRegister.timeRemaining.getHours().toString();								
							$('#auction_stage').val("FirstCall");
							BidRegister.firstCall(sale_or_auction,price_prefix);			
						}
						else
						{
							WebWindow.log.debug('Call Ten Minute Timer');
							BidRegister.tenMinuteTimer(sale_or_auction,price_prefix);
						}
					}	
					else if($('#auction_stage').val() =="FirstCall")
					{
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							// TO place the odd even second check
							WebWindow.log.debug('Call Second Call Timer');	
							BidRegister.adjustTimer(0,0,30);							
							secondstring=BidRegister.timeRemaining.getSeconds().toString();
							minutestring=BidRegister.timeRemaining.getMinutes().toString();
							hourstring=BidRegister.timeRemaining.getHours().toString();								
							$('#auction_stage').val("SecondCall");
							BidRegister.secondCall(sale_or_auction,price_prefix);			
						}
						else
						{
							WebWindow.log.debug('Call First Call Timer');
							BidRegister.firstCall(sale_or_auction,price_prefix);
						}
					}
					else if($('#auction_stage').val() =="SecondCall")
					{
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Call Third Call Timer');	
							BidRegister.adjustTimer(0,0,30);							
							secondstring=BidRegister.timeRemaining.getSeconds().toString();
							minutestring=BidRegister.timeRemaining.getMinutes().toString();
							hourstring=BidRegister.timeRemaining.getHours().toString();	
							$('#auction_stage').val("ThirdCall");							
							BidRegister.thirdCall(sale_or_auction,price_prefix);		
						}
						else
						{
							WebWindow.log.debug('Call Second Call Timer');
							BidRegister.secondCall(sale_or_auction,price_prefix);
						}
					}
					else if($('#auction_stage').val() =="ThirdCall")
					{
						if(secondstring > 0 && secondstring <=15 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Last 15 second on Third Call');								
							$('#clockheader').html('All Finished?');	
						}							
					}
					else if($('#auction_stage').val() =="ThirdCall")
					{
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Call Auction End');								
							secondstring=BidRegister.timeRemaining.getSeconds().toString();
							minutestring=BidRegister.timeRemaining.getMinutes().toString();
							hourstring=BidRegister.timeRemaining.getHours().toString();
							$('#auction_stage').val("AuctionEnd");								
							BidRegister.auctionEnd(sale_or_auction,price_prefix);		
						}
						else
						{
							WebWindow.log.debug('Call Third Call Timer');
							BidRegister.thirdCall(sale_or_auction,price_prefix);
						}							
					}
					else if($('#auction_stage').val() =="AuctionEnd") //not really required
					{
						if(secondstring <=0 && minutestring<=0 && hourstring<=0)
						{
							WebWindow.log.debug('Call Auction End');														
							//BidRegister.auctionEnd();		
						}
					
					}
					 					
					//alert(secondstring.length);
					if(secondstring.length < 2)
						secondstring= "0" + secondstring;
					if(minutestring.length < 2)
						minutestring= "0" + minutestring;
					if(hourstring.length < 2)
						hourstring= "0" + hourstring;		
					
					$('#second').html(secondstring);
					$('#minute').html(minutestring);
					$('#hour').html(hourstring);
				},1000);			
		},
	setTimeRemaining: function()
		{
			BidRegister.timeRemaining = new Date($('#time_remaining').val()) ;
			//alert($('#time_remaining').val());
			if ($('#hours_remaining').val() != "")
			{
				if($('#hours_remaining').val().toString().length < 2)						
					$('#hour').html("0" + $('#hours_remaining').val().toString());
				else
					$('#hour').html($('#hours_remaining').val().toString());	
			}
			if ($('#minutes_remaining').val() != "")
			{
				if($('#minutes_remaining').val().toString().length < 2)						
					$('#minute').html("0" + $('#minutes_remaining').val().toString());
				else
					$('#minute').html($('#minutes_remaining').val().toString());											
			}
			if ($('#seconds_remaining').val() != "")
			{
				if($('#seconds_remaining').val().toString().length < 2)						
					$('#second').html("0" + $('#seconds_remaining').val().toString());
				else
					$('#second').html($('#seconds_remaining').val().toString());						
			}
		},	
	adjustTimer: function(hours,minutes,seconds)
		{
			BidRegister.timeRemaining.setHours(hours);
			BidRegister.timeRemaining.setSeconds(seconds);
			BidRegister.timeRemaining.setMinutes(minutes);
			$('#hour').html("00");
			$('#minutes_remaining').val(minutes);
			$('#seconds_remaining').val(seconds);
					
		},		
	clearTimer: function(timer)
		{
			clearInterval(BidRegister.secondsTimer);
			clearTimeout(BidRegister.secondsTimer);	
		},
	auctionAdvertised: function(sale_or_auction,price_prefix)
		{
			$('#bidregisterwrap').hide();
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction+' has not yet commenced</div>');
			$('#starts').html("Starts: " + $('#start_time').val() + " AEST").css("color","#00286b");
			$('#clock').hide();
			$('#finalbids').html('');			
			$('#clockheader').html('TIME REMAINING');
			$('#clockheader').css('color','#ea7501');			
			//$("#currentbidpanel").css("background-image","none");			
			$(".currentbid").css("color","#00286b");
			//$(".auctionstatusbox").css("background-color","#ea7501");
			$(".buttonbid").css("background-image","url(/images/btn1c.gif)");			
			BidRegister.setBidColor();				
		},		
	auctionCommenced: function(sale_or_auction,price_prefix)
		{
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' COMMENCED</div>').show();
			$('#clock').hide();
			$('#finalbids').html('');
			$('#clockheader').html('TIME REMAINING');
			$('#clockheader').css('color','#ea7501');			
			//$("#currentbidpanel").css("background-image","none");			
			$(".currentbid").css("color","#00286b");
			//$(".auctionstatusbox").css("background-color","#ea7501");
			$(".buttonbid").css("background-image","url(/images/btn1c.gif)");			
			BidRegister.setBidColor();			
		},		
	threeHourTimer:	function(sale_or_auction,price_prefix)
		{
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' CLOSING NOW!</div>').show();
			$('#clock').show();
			$('#clockwrapper').show("slow");
			$('#finalbids').html('FINAL BIDS').show();
			//$('#clockheader').html('< 3 HOURS REMAINING');
			$('#clockheader').html('TIME REMAINING');			
			$('#clockheader').css('color','#ffff00');			
			//$("#currentbidpanel").css("background-image","none");			
			$(".currentbid").css("color","#00286b");
			//$(".auctionstatusbox").css("background-color","#ea7501");
			$(".buttonbid").css("background-image","url(/images/bidnowblue_button.png)");			
			BidRegister.setBidColor();		
		},
	tenMinuteTimer:	function(sale_or_auction,price_prefix)
		{
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' CLOSING NOW!</div>').show();
			$('#clock').show();
			$('#clockwrapper').show("slow");
			$('#finalbids').html('FINAL BIDS').show();
			//$('#clockheader').html('< TEN MINUTES LEFT');	
			$('#clockheader').html('TIME REMAINING');			
			$('#clockheader').css('color','#ffff00');			
			$("#currentbidpanel").css("background-image","none");			
			$(".currentbid").css("color","#00286b");
			//$(".auctionstatusbox").css("background-color","#ea7501");
			//$(".buttonbid").css("background-image","url(/images/bidnowblue_button.png)");	
			if ((parseInt($('#minutes_remaining').val()) >= 2) && ($("#timeremaining").val()!= "10")) {	
				$("#lessthan2minute").val("10");
				$("#bidnow").css("background-image","url(/images/animated_bidnow.gif)");
			}
			if ((parseInt($('#minutes_remaining').val()) < 2) && ($("#timeremaining").val()!= "2")) {	
				$("#lessthan2minute").val("2");
				$("#bidnow").css("background-image","url(/images/animated_bidnow2.gif)");	
			}
			BidRegister.setBidColor();			
		},										
	firstCall:	function(sale_or_auction,price_prefix)
		{
			BidRegister.callReset(sale_or_auction,price_prefix);
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' CLOSING NOW!</div>').show();
			$('#clock').show();
			$('#clockwrapper').show("slow");
			$('#finalbids').html('FIRST CALL').show();
			$('#clockheader').html('FIRST CALL');
			$('#clockheader').css('color','#FFFF00');			
			//$(".auctionstatusbox").css("background-color","#FF0000");
			//$("#currentbidpanel").css("background-image","url(/images/fbg.gif)");			
			//$(".currentbid").css("color","#ffff00");
			//$(".auctionstatusbox").css("background-color","#FF0000");
			if ($("#timeremaining").val()!= "1") {	
				$("#lessthan2minute").val("1");
				$("#bidnow").css("background-image","url(/images/bidnowred_button_flashing.gif)");
			}
			$("#BidDisplayPlace").css("background-image","url(http://sale-ezy.com.au/images/auction_bid_place_background3.png)");			
			BidRegister.setBidColor();	
		},
	secondCall:	function(sale_or_auction,price_prefix)
		{
			$('#clock').show();
			$('#clockwrapper').show("slow");		
			$('#finalbids').html('SECOND CALL').css('font-size','36px').css('line-height','40px').show();
			$('#clockheader').html('SECOND CALL');
			$('#clockheader').css('color','#FFFF00');			
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' CLOSING NOW!</div>').show();
			//$(".auctionstatusbox").css("background-color","#FF0000");
			//$("#currentbidpanel").css("background-image","url(/images/fbg.gif)");			
			//$(".currentbid").css("color","#ffff00");
			//$(".auctionstatusbox").css("background-color","#FF0000");
			//$("#bidnow").css("background-image","url(/images/bidnowred_button_flashing.gif)");	
			$("#BidDisplayPlace").css("background-image","url(http://sale-ezy.com.au/images/auction_bid_place_background3.png)");			
			BidRegister.setBidColor();		
		},
	thirdCall:	function(sale_or_auction,price_prefix)
		{
			$('#clock').show();
			$('#clockwrapper').show("slow");
			$('#finalbids').html('THIRD & FINAL CALL').css('font-size','36px').css('line-height','40px').show();
			$('#clockheader').html('All Done?');
			$('#clockheader').css('color','#FFFF00');
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' CLOSING NOW!</div>').show();
			//$(".auctionstatusbox").css("background-color","#FF0000");
			//$("#currentbidpanel").css("background-image","url(/images/fbg.gif)");			
			//$(".currentbid").css("color","#ffff00");
			//$(".auctionstatusbox").css("background-color","#FF0000");
			//$("#bidnow").css("background-image","url(/images/bidnowred_button_flashing.gif)");
			$("#BidDisplayPlace").css("background-image","url(http://sale-ezy.com.au/images/auction_bid_place_background3.png)");				
			BidRegister.setBidColor();	
			$('#bidregisterwrap').hide();			
			var showgavel;														
			showgavel = $('#gavel:visible').length;
			if(showgavel==0)
			{
			$('#gavel').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="335" height="200" id="gavelswf" align="middle" VIEWASTEXT><param name="allowFullScreen" value="false" /><param name="wmode" value="transparent"><param name="movie" value="/images/gavel_hover.swf" /><param name="quality" value="best" /><param name="bgcolor" value="#faedc7" /><embed src="/images/gavel_hover.swf" quality="best" wmode="transparent" bgcolor="#faedc7" width="335" height="200" name="gavelswf" align="middle" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>').show();
			}													
		},
	auctionEnd: function(sale_or_auction,price_prefix)
		{
			$('#auctionstatusbox').html('<div class="auctioncommenced">'+sale_or_auction.toUpperCase()+' IS COMPLETED</div>');
			//$(".auctionstatusbox").css("background-color","#ea7501");
			$('#clock').hide();
			$('#clockwrapper').hide();
			$('#bid_button').hide();				
			$("#currentbidpanel").css("background-image","none");
			$(".currentbid").css("color","#ea7501");
			if ($("#nobid").val()!="true")
			{
				$('#currentbidlabel').html('FINAL BID').css('color','#00286b');
			}
			$('#finalbids').css('text-align','center').show();
			$("#BidDisplayPlace").css("background-image","url(/images/auction_bid_place_background1.png)");	
			$("#bidplacewrapper").hide();
			$("#clockwrapper").hide();
			$('#finalbids').css('line-height','36px');
			if($('#hasofferaccepted').val() == "False"){	
				if($('#reservemet').val()=="True")
				{
					$('#finalbids').html('SOLD');
					$('#finalbids').css('font-size','36px');
					$('#gavel').html('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="335" height="200" id="gavelswf" align="middle" VIEWASTEXT><param name="allowFullScreen" value="false" /><param name="wmode" value="transparent"><param name="movie" value="http://sale-ezy.com.au/images/gavel2.swf?' + Math.floor(Math.random()*100001) + '" /><param name="quality" value="best" /><param name="bgcolor" value="#faedc7" /><embed src="http://sale-ezy.com.au/images/gavel2.swf?' + Math.floor(Math.random()*100001) + '" quality="best" wmode="transparent" bgcolor="#faedc7" width="335" height="200" name="gavelswf" align="middle" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');	
				}
				else
				{
					if($('#hasofferaccepted').val()=="False"){
						$('#finalbids').html('FOR NEGOTIATION&nbsp;');
						$('#finalbids').css('font-size','36px').css('line-height','42px');
					}
				}
			}
			if ($("#hasofferaccepted").val() == 'True' && $("#hasofferconfirmed").val() == 'True'){
				$('#currentbidlabel').html('SOLD').css('color','#00286b');
			}
			BidRegister.setBidColor();
			$(".price").css("color","#00286b");
			$(".currentbid").css("color","#00286b");
			$(".currentbid").css("background-color","#ffffff");
			
			
			
			$('#onmarket').html("To "+this.currentBidder);
										
			$('#clockheader').css('color','#FF0000');			
			
			BidRegister.clearTimer(timer1);	
			clearInterval(timer1);			
		},
	setBidColor: function()
	{
		if($('#reservemet').val()!="True")
		{
			if ($("#vendor_bid").val()!="True")
			{
				$(".price").css("color","#00286b");
				$(".currentbid").css("color","#00286b");
				$(".currentbid").css("background-color","#ffffff");
				$('#onmarket').html("");
			}
			else
			{
				$(".currentbid").css("color","#ea7501");
				$(".currentbid").css("background-color","#000000");
				$(".price").css("color","#ea7501");
				$('#onmarket').html("Vendor Bid").css("display","inline")
			}			
		}
		else
		{			
			$(".currentbid").css("color","#33cc33");
			$(".currentbid").css("background-color","#000000");
			$('#onmarket').html("On the market").css("display","inline")
			$(".price").css("color","#33cc33");			
		}	
	},	
	callReset: function(sale_or_auction,price_prefix)
	{
			if(sale_or_auction == 'Sale'){
				$('#currentbidlabel').html(price_prefix.toUpperCase());
			}else{
				$('#currentbidlabel').html('GUIDE PRICE');
			}
			$('#finalbids').css('font-size','48px').css('line-height','40px');
			$('#bid_button').show();
			$('#bidregisterwrap').show();
	}															
}

var User = 
{
	login: function()
		{				
			$.ajax({
				type: "POST",
				url: 'userlogin.aspx',
				timeout: 5000,
				data:$("#frmlogin").serialize(),
				error: function(){
					$('#validator').html("<li>User does not exist!</li>").show();
				},
				success: function(html){
					$('#login').html('<script>window.location.reload();</script>');
					$('#menuItemMyAuction').show();									
				}
			});
		},
	addBookmark: function(propertyId)
		{	var currentTime = new Date();				
			$.ajax({				
				url: '/query/addwatch.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#watchauction_button").html('<a href="javascript:User.removeBookmark(\''+propertyId+'\');">Remove Bookmark</a>');
				}
			});
		},
	removeBookmark: function(propertyId)
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/removewatch.aspx',
				data: 'dummy='+currentTime.getTime(),
				data:"id="+propertyId,
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#watchauction_button").html('<a href="javascript:User.addBookmark(\''+propertyId+'\');">Bookmark this auction</a>');
				}
			});
		},
	addWatch: function()
		{	var currentTime = new Date();				
			$.ajax({				
				url: '/query/addwatch.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#watchauction_button").html(html);
				}
			});
		},
	removeWatch: function(propertyId)
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/removewatch.aspx',
				data: 'dummy='+currentTime.getTime(),
				data:"id="+propertyId,
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
				User.getWatched();	
				}
			});
		},
	getWatched: function()
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/watching.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#myauctions").html(html);
				}
			});
		},
	addAutobid: function(userid,propertyId,autobid)
		{				
			$.ajax({				
				url: '/query/addautobid.aspx',
				data:"uid"+ userid +"&bid=" + autobid + "&pid="+propertyId,
				timeout: 5000,				
				error: function(){
					$('#validator').html("Fail to set autobid<br>" + html).show();
					setTimeout("$('#validator').fadeOut('slow')",5000);
				},
				success: function(html){
					$('#validator').html(html).show();
					setTimeout("$('#validator').fadeOut('slow')",5000);
				}
			});
		},
	removeAutobid: function(userid,propertyId)
		{				
			$.ajax({				
				url: '/query/removeautobid.aspx',
				timeout: 4000,
				data:"uid="+ userid +"&id="+propertyId,				
				error: function(){
					//$('#validator').html('Fail to cancel autobid').show();
					//setTimeout("$('#validator').fadeOut('slow')",3000);
				},
				success: function(html){
					$('#cancelautobid').hide();
					$('#autobidamount').val('');
					$('#information').html("You autobid has been cancelled").show();
					setTimeout("$('#information').fadeOut('slow')",3000);	
				}
			});
		},
	getAuctions: function()
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/bidding.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#myauctions").html(html);
				}
			});
		},
	getWon: function()
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/won.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#myauctions").html(html);
				}
			});
		},
	getNotWon: function()
		{	var currentTime = new Date();			
			$.ajax({				
				url: '/query/notwon.aspx',
				data: 'dummy='+currentTime.getTime(),
				timeout: 5000,				
				error: function(){
					
				},
				success: function(html){
					$("#myauctions").html(html);
				}
			});
		},
	alertSubscribe: function(email,mobile,property)
		{				
			$.ajax({				
				url: '/query/alert_subscribe.aspx',
				timeout: 5000,
				cache: false,
				timeout: 500,
				data:"id="+property+"&mobile="+mobile+"&email="+email,				
				error: function(){
					WebWindow.log.debug('Error' + this);
					$('#validator').html("This email already exists for this property").show();
					setTimeout("$('#validator').fadeOut('slow')",5000);
				},
				success: function(html){
					$('#information').html(html).show();
					$('#auction_alert').hide();
					setTimeout("$('#information').fadeOut('slow')",5000);
				}
			});
		}	
								
}

