var load_callback = false;
function LoadUrl(url, div_id) {
	new Ajax.Request(url, {
		method : 'get',
		onSuccess : function(transport) {
			$(div_id).update(transport.responseText);
			if (load_callback) {
				eval(load_callback);
				load_callback = false;
			}
		},
		onFailure : function(transport) {
			alert('Communication Error: ' + transport.responseText);
		}

	});
}

function SubmitForm(obj, div_id) {
	obj.request( {
		onComplete : function(transport) {
			$(div_id).innerHTML = transport.responseText;
		}
	})
	return false;
}

function AjaxCheckSpecialAuctionBidAbilityForReminder(AuctionId, CatId) {
	new Ajax.Request('/ajax_check_special_auction.php', {
		parameters : {
			auction_id : AuctionId
		},
		method : 'post',
		onComplete : function(transport) {
			if (transport.responseText != 'ok') {
				ShowTermsAndCondWindow(AuctionId);
			} else {
				EnableReminder(CatId);
			}
		}
	});
}

function AjaxCheckSpecialAuctionBidAbilityForBitbutler(AuctionId) {
	new Ajax.Request('/ajax_check_special_auction.php', {
		parameters : {
			auction_id : AuctionId
		},
		method : 'post',
		onComplete : function(transport) {
			if (transport.responseText != 'ok') {
				ShowTermsAndCondWindow(AuctionId);
			} else {
				if ($('bidbutler_div').style.display == '')
					$('bidbutler_div').style.display = 'none';
				else
					$('bidbutler_div').style.display = '';
			}
		}
	});
}

function AjaxCheckSpecialAuctionBidAbility(AuctionId, TimerObj) {
	new Ajax.Request('/ajax_check_special_auction.php', {
		parameters : {
			auction_id : AuctionId
		},
		method : 'post',
		onComplete : function(transport) {
			if (transport.responseText != 'ok') {
				ShowTermsAndCondWindow(AuctionId);
			} else {
				AjaxBid(AuctionId, TimerObj);
			}
		}
	});
}

function AjaxBid(AuctionId, TimerObj) {
	new Ajax.Request('/make_bid.php', {
		parameters : {
			auction_id : AuctionId
		},
		method : 'post',
		onSuccess : function(transport) {
			GetTimerAndPrice(TimerObj);
			if (transport.responseText != 'ok') {
				alert(transport.responseText);
			} else {
				LoadCreditsAmount();
			}
		}
	});
}
var special_auction_win;
function ShowTermsAndCondWindow(AuctionId) {
	special_auction_win = new Window( {
		className : "alphacube",
		title : "",
		top : 70,
		left : 300,
		width : 600,
		height : 500,
		url : "/ajax_get_terms.php?auction_id=" + AuctionId,
		showEffectOptions : {
			duration : 0.5
		}
	});
	special_auction_win.show();
}
function DestroySpecialAuctionWin() {
	special_auction_win.destroy();
	document.location.reload();
}
function EnableReminder(CatId) {
	new Ajax.Request('/ajax_add_reminder.php', {
		method : 'get',
		parameters : {
			auction_cat_id : CatId
		},
		onSuccess : function(transport) {
			alert(transport.responseText);
		},
		onFailure : function(transport) {
			alert('Communication Error: ' + transport.responseText);
		}

	});
}

function parseAmericanDate(string) {
	var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
	var d = string.match(new RegExp(regexp, "i"));
	if (d == null)
		return Date.parse(string); // at least give javascript a crack at it.
	var offset = 0;
	var date = new Date(d[5], 0, 1);
	if (d[3]) {
		date.setMonth(d[3] - 1);
	}
	if (d[5]) {
		date.setDate(d[1]);
	}
	if (d[7]) {
		date.setHours(parseInt(d[7], 10));
	}
	if (d[8]) {
		date.setMinutes(d[8]);
	}
	if (d[10]) {
		date.setSeconds(d[10]);
	}
	return date;

}

function toAmericanDate(date_value, include_time) {
	str = this.getDate() + "/" + (this.getMonth() + 1) + "/"
			+ this.getFullYear();
	if (include_time) {
		hour = this.getHours();
		str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes()
	}
	return str;
}

function toISODate(date_value, include_time) {
	var hour;
	var str = date_value.getFullYear() + "-"
			+ Date.padded2(date_value.getMonth() + 1) + "-"
			+ Date.padded2(date_value.getDate());
	if (include_time) {
		hour = date_value.getHours();
		str += " " + date_value.getHours() + ":"
				+ date_value.getPaddedMinutes();
	}
	return str;
};