var Registration = {
	validate: function()
	{
		var message="";
		if($("#firstname").val()=="")
			message+="<li>First Name not supplied";
		if($("#lastname").val()=="")
			message+="<li>Last Name not supplied";
		if($("#address").val()=="")
			message+="<li>Address not supplied";			
		if($("#phone").val()=="")
			message+="<li>Phone not supplied";
		if($("#email").val()=="")
			message+="<li>Email not supplied";
		if($("#upassword").val()=="")
			message+="<li>Password not supplied";
		if(!(document.getElementById("chkAgree").checked))
			message+="<li>You must agree to the terms & conditions of use";
		if($("#upassword").val().length < 8)
			{
				message+="<li>Your password must be at least 8 characters.";
			}			
		if($("#upassword").val() != $("#cpassword").val())
			{
				message+="<li>Your password and confirm password must be the same.";
			}		
		if(message.length > 0)
		{
			$("#validator").html(message).show();	
			window.scrollTo(0,0);
			return false;
		}
		else
		{
			$("#validator").html(message).hide();
			return true;	
		}	
	}
}
var Profile = {
	validate: function()
	{
		var message="";
		if($("#name").val()=="")
			message+="<li>Name not supplied";
		if($("#lastname").val()=="")
			message+="<li>Last Name not supplied";
		if($("#address").val()=="")
			message+="<li>Address not supplied";			
		if($("#phone").val()=="")
			message+="<li>Phone not supplied";
		if($("#email").val()=="")
			message+="<li>Email not supplied";
		if(message.length > 0)
		{
			$("#validator").html(message).show();	
			return false;
		}
		else
		{
			$("#validator").html(message).hide();
			return true;	
		}	
	}
}
var Password = {
	validate: function()
	{
		var message="";
		if($("#npassword").val()!="" || $("#cnpassword").val()!="")
		{	
			if ($("#cpassword").val()!=""){
				if ($("#cpassword").val()!= $("#upassword").val()){
					message+="<li>Your password is incorrect.";
				}
			}
			if($("#npassword").val()!=$("#cnpassword").val())
			{
				message+="<li>Your confirmed password must match your new password";				
			}
			if($("#npassword").val().length < 8 || $("#npassword").val().length > 10)
			{
				message+="<li>Your password must be greater than 8 characters.";
			}	
		}	
		if(message.length > 0)
		{
			$("#validator").html(message).show();	
			return false;
		}
		else
		{
			$("#validator").html(message).hide();
			return true;	
		}	
	}
}
var Login = {
	validate: function()
	{
		var message="";
		if($("#ulid").val()=="")
			message+="<li>User id not supplied";		
		if($("#ulpassword").val()=="")
			message+="<li>Password not supplied";
		if(message.length > 0)
		{
			$("#validator").html(message).show();	
			return false;
		}
		else
		{
			$("#validator").html(message).hide();
			return true;	
		}	
	}
}
var Conditions = {
	validate: function()
	{
	var message="";		
	$("input[@type='checkbox']").each(function() {
	if(!this.checked && this.id !="contract_required"){message="<li>You must agree to all the terms to continue. Please check all boxes!";}});	
		if(message.length > 0)
		{
			$("#validator").html(message).show();	
			return false;
		}
		else
		{
			$("#validator").html(message).hide();
			return true;	
		}	
	}
}
var Bid = {
	bidamount:null,	
	validate: function()
		{
		var message="";		
		if(isNaN(parseInt($("#bidamount").val())))	
		{
		message="<li>You must enter a valid bid as a real number i.e. 300000. Do not include cents.";
		}
		if(parseInt($("#bidamount").val()) < parseInt($("#current_high_bid").val()))
		{
		message="<li>Your bid must be higher than the current bid.";
		}
		if(message.length > 0)
		{
			$("#validator").html(message).show();	 
			return false;
		}
		else
		{
			this.bidamount=$("#bidamount").val();	
			$("#validator").html(message).fadeOut('fast');
			$("#confirmation").html('You are about to bid the amount $'+this.bidamount+', Is this correct? &nbsp; &nbsp; &nbsp;<a href="javascript:$(\'#confirmation\').hide();Bid.place();">Yes</a> &nbsp; &nbsp;| &nbsp; &nbsp;<a href="javascript:$(\'#confirmation\').hide();void(0);">No</a><br><b>Please note: This cannot be undone. Once you click yes your bid is final</b>').fadeIn('fast');
			
			return true;	
		}	
	},
	place: function()
	{
				$.ajax({
				url: 'bidplace.aspx',
				timeout: 4000,
				data:"bid="+this.bidamount,
				error: function(){
					$('#validator').html('Bids on this property are currently not available.<br>Please try again later or feel free to contact us on 1300 111 222');
				},
				success: function(html){
					$('#information').html(html).show();
					//alert(html);
					$('#label_current_minimumbid').hide();
					$('#label_current_bid').show();
					$('#currentbidlabel').html('CURRENT BID');
					setTimeout("$('#information').fadeOut('slow')",20000);
					$('#bidamount').val('');
				}
			});
	}
}
var AutoBid = {
	bidamount:null,	
	validate: function(userid,propertyid)
		{
		var message="";		
		if(isNaN(parseInt($("#autobidamount").val())))	
		{
		message="<li>You must enter a valid bid as a real number i.e. 300000. Do not include cents.";
		}
		if(parseInt($("#autobidamount").val()) < parseInt($("#current_high_bid").val()))
		{
		message="<li>Your bid must be higher than the current bid.";
		}
		if(message.length > 0)
		{
			$("#validator").html(message).show();	 
			return false;
		}
		else
		{
			this.bidamount=$("#autobidamount").val();	
			$("#validator").html(message).fadeOut('fast');
			$("#confirmation").html('You are about to set autobid the amount $'+this.bidamount+', Is this correct? &nbsp; &nbsp; &nbsp;<a href="javascript:$(\'#confirmation\').hide();AutoBid.place(\'' + userid + '\',\'' + propertyid + '\');">Yes</a> &nbsp; &nbsp;| &nbsp; &nbsp;<a href="javascript:$(\'#confirmation\').hide();void(0);">No</a><br><b>Please note: This cannot be undone. Once you click yes your bid is final</b>').fadeIn('fast');
			
			return true;	
		}	
	},
	place: function(userid,propertyid)
	{
				$.ajax({
				url: '/query/addautobid.aspx',
				timeout: 4000,
				data:"uid="+ userid +"&bid=" + this.bidamount + "&pid="+propertyid,
				error: function(){
					//$('#validator').html('Fail to set autobid').show();
					//setTimeout("$('#validator').fadeOut('slow')",3000);
					//$('#validator').html('Bids on this property are currently not available.<br>Please try again later or feel free to contact us on 1300 111 222');
				},
				success: function(html){
					$('#cancelautobid').show();
					$('#information').html(html).show();
					//alert(html);
					setTimeout("$('#information').fadeOut('slow')",3000);
					//$('#autobidamount').val('');
				}
			});
	}
}