function getCouponDiscount(couponCode, total, url) {
	var callback = {
		success : function(o) {
			eval("var coupon = " + o.responseText + ";");
			var d = (typeof(coupon.discount)=='undefined') ? 1 : coupon.discount;
			for(var i = 0; i < document.forms['payForListingForm'].elements.length ; i++) {
				var el = document.forms['payForListingForm'].elements[i];
				el.disabled = d==0 && el.id != "couponCode" && el.type != 'submit' && el.type !='button';
			}
			if(d < 1) {
				//$('noCouponDiv').style.visibility = 'hidden';
				$('withCouponDiv').style.visibility = 'visible';
				$('spanPercent').innerHTML = Formatter.format((1-d)*100,new Format('number','.##'));
				$('spanDiscount').innerHTML = Formatter.format((1-d)*o.argument[0], new Format('number','.00'));
				$('spanTotal').innerHTML = Formatter.format(d*o.argument[0], new Format('number','.00'));
				$('couponCodeStatusMessage').innerHTML = 'Discount ' + Formatter.format((1-d)*100,new Format('number','.##','','%')); 
			} else {
				//$('noCouponDiv').style.visibility = 'visible';
				$('withCouponDiv').style.visibility = 'hidden';
				$('couponCodeStatusMessage').innerHTML = '';
				$('spanTotal').innerHTML = Formatter.format(o.argument[0], new Format('number','.00'));
			}
		},
		failure : function(o) {
		},
		timeout : 30000,
		argument : [total]
	};
	var transaction = YAHOO.util.Connect.asyncRequest('GET', url+"?couponCode="+escape(couponCode)+"&sum="+total, callback, null);
}

function pingHost(url) {
	var callback = function() {
		var innerCallback = {
			success : function(o) {
			},
			failure : function(o) {
			},
			timeout : 1000,
			argument : []
		};
		var transaction = YAHOO.util.Connect.asyncRequest('GET',url, innerCallback, null);
	};
	pinger = new PeriodicalExecuter(callback, 60);
}

function getReplyForm(id,url) {
	var ids = document.getElementsByTagName("DIV");
	for(var i=0;i<ids.length;i++) {
		if (typeof(ids[i]) != 'undefined' && ids[i] != null && ids[i].id.match(/^formDiv\d+$/)) {
			if (!ids[i].id == ("formDiv" + id)) ids[i].style.display = 'none';
			ids[i].innerHTML = '';
		}
	}

	var element = $("formDiv"+id);
	var hide = function() {
		$("formDiv"+id).innerHTML = '';
		$("formDiv"+id).style.display='none';
	};

	element.style.display = '';
	element.innerHTML = "Please, wait......";

	var callback = {
		success : function(o) {
			o.argument[0].innerHTML = o.responseText;
			o.responseText.evalScripts();
		},
		failure : function(o) {
			o.argument[0].innerHTML = "We are unable to process request at this time. Try again later.";
			window.setTimeout(o.argument[1], 10000);
		},
		timeout : 30000,
		argument : [element, hide]
	};

	var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
}

function sendReply(id, url, formId, upload) {
	var element = $("formDiv"+id);
	var hide = function() {
		$("formDiv"+id).innerHTML = '';
		$("formDiv"+id).style.display='none';
	};

	var callback = {
		success : function(o) {
			o.argument[0].innerHTML = o.responseText;
		},
		upload : function(o) {
			o.argument[0].innerHTML = o.responseText;
			o.responseText.evalScripts();
		},
		failure : function(o) {
			o.argument[0].innerHTML = "We are unable to process request at this time. Try again later.";
			window.setTimeout(o.argument[1], 30000);
		},
		timeout : 30000,
		argument : [element, hide]
	};
	var formObject = document.forms[formId];
	YAHOO.util.Connect.setForm(formObject,upload);
	var transaction = YAHOO.util.Connect.asyncRequest('POST', url, callback);
}

function hideSuggest(showControl, hideControl, placeHolder) {
	hideSelects(false);
	Element.hide(placeHolder);
	Element.show(showControl);
	Element.hide(hideControl);
};
function failSuggest(showControl, hideControl, placeHolder) {
	var ph = $(placeHolder);
	ph.innerHTML = "failSuggest... failed :)";
	setTimeout(hideSuggest.bind(null,showControl, hideControl, placeHolder), 2000);
};
function showSuggest(showControl, hideControl, placeHolder, url) {
	Element.hide(showControl);
	Element.show(hideControl);
	try {
		var ph = $(placeHolder);
		Element.show(ph);
		ph.innerHTML = "please, wait...";
		var callback = {
			success : function(o) {
				hideSelects(true);
				$(o.argument[2]).innerHTML = o.responseText;
			},
			failure : function(o) {
				failSuggest(o.argument[0],o.argument[1],o.argument[2]);
			},
			timeout : 15000,
			argument : [showControl, hideControl, placeHolder]
		};
		var transaction = YAHOO.util.Connect.asyncRequest('GET', url, callback, null);
	} catch(ex) {
		hideSelects(false);
	}
};