function processOrderFormChange(form_id) {
    if (form_id && document.getElementById(form_id)) {
		$('add_configger_to_cart').disabled = true;
        $(form_id).request({
            parameters: {
                title: 'no-title'
            },
            requestHeaders: {
                Accept: 'application/json'
            },
            onComplete: function(transport) {
                var json = transport.responseText.evalJSON(true);
                if (json != null) {
                    Object.keys(json.content_updates).each(function(key) {
                        $(key).update(json.content_updates[key]);
                    });
                    Object.keys(json.property_updates).each(function(key) {
                        $(key).writeAttribute(json.property_updates[key]);
                    });
                } else {
                    alert('Unable to parse response');
                }
            }
        });
    }
return(true);}
var timers = [];
function delayProcessOrderFormChange(id) {
	if (timers[id]) {
		clearTimeout(timers[id]);
	}
	timers[id] = setTimeout(function(){
		processOrderFormChange(id);
	}, 800);
}

function checkIsCoherentToBeSelectedOrUnselectedSingle(min, max, fieldset)
{
    var list = fieldset.getElementsByTagName('input');
    var nb = 0;
    for (i = 0; i < list.length; i++)
        {
            if (list[i].checked)
                nb++;
        }
    if (nb == max)
        {
            for (i = 0; i < list.length; i++)
                {
                    if (!list[i].checked)
                        list[i].disabled = true;
               }
        }
    else if (nb < max)
        {
            for (i = 0; i < list.length; i++)
                {
                    if (!list[i].checked)
                        list[i].disabled = false;
                }
        }
    if (nb > max)
        return false;
    return true;
}
function checkIsCoherentToBeSelectedOrUnselectedMultiple(select_changed, min, max, fieldset)
{
    var list = fieldset.getElementsByTagName('select');
    var nb = 0;
    for (i = 0; i < list.length; i++)
        {
            nb = nb + parseInt(list[i].options[list[i].selectedIndex].value);
        }
    if (nb > max)
        {
            var too_much = nb - max;
            var index = (select_changed.options.selectedIndex) - too_much;
            select_changed.options[index].selected = true;
        }
    return true;
}
var AquaToolTip = Class.create( {
	initialize: function(idbutton, idtooltip) {
		this.button = idbutton;
		this.tooltip = idtooltip;
		this.setEvents();
    },
	setEvents: function() {
		$(this.button).observe('mouseover', this.onMouseOverEventHandler.bind(this));
		$(this.button).observe('mouseout', this.onMouseOutEventHandler.bind(this));
	},
	onMouseOverEventHandler: function() {
		var topleft = $(this.button).positionedOffset();
		$(this.tooltip).style.left = (5+topleft.left +$(this.button).getWidth())+"px";
		$(this.tooltip).style.top = (3+topleft.top + $(this.button).getHeight())+"px";
		$(this.tooltip).style.visibility = 'visible';
	},
	onMouseOutEventHandler: function() {
		$(this.tooltip).style.visibility = 'hidden';
	}
}
);
var AvailibilityResponseHandler = Class.create({
	initialize: function(baseid, requestUrl) {
		document.observe("domainfinder:newrequest", function(event) {
		  console.log("Element with ID (" + event.target.id +
		   ") frobbed widget #" + event.memo.widgetNumber + ".");
		});



		this.baseid  = baseid;
		new Ajax.Request(requestUrl, {
			method: 'get',
			requestHeaders: {
			    Accept: 'application/json'
			},
			onSuccess: this.handleResponse.bind(this)
		});
	},
	handleResponse:	function(transport) {
		var json = transport.responseText.evalJSON(true);
		if (json != null) {
                    $(this.baseid+'_availibility').removeClassName('centerActivityIndicator');
			if (json.afnicisdown) {
				$(this.baseid).toggleClassName('not_available_row');
				$(this.baseid+'_input_cell').update(this._afnicIsDown);
				$(this.baseid+'_availibility').update(this._shortNotAvailable);
			} else if (json.invalid) {
				$(this.baseid).toggleClassName('not_available_row');
				$(this.baseid+'_input_cell').update(this._invalidMessage);
				$(this.baseid+'_availibility').update(this._shortNotAvailable);
			} else {
			 	if (!json.availibility) {
					$(this.baseid).toggleClassName('not_available_row');
					$(this.baseid+'_input_cell').insert({
						'top': new Element('label', { 'for': this.baseid+'_input'}).update(
							this._alreadyExistsMessage
						)
					});
					$(this.baseid+'_availibility').insert({
						'top': new Element('label', { 'for': this.baseid+'_input' }).update(this._shortNotAvailable)
					});
				} else {
					$(this.baseid).writeAttribute('class', 'available_row');
					$(this.baseid+'_availibility').insert({'top': new Element('label', { 'for': this.baseid+'_input'}).update(this._shortAvailable)});
				}
				var a = new Element('input', { 'class': '', 'id':this.baseid+'_input', 'type': 'checkbox', 'name': 'domain_finder[alternatives][]', 'value': json.domain});
				$(this.baseid+'_input_cell').insert({'top': a});
			}
		} else {
			alert('Unable to parse response');
		}
	}
});
var AppearObjectAndBlink = Class.create({
	initialize: function(obj) {
		this.obj = obj;
		jQuery("#"+this.obj).show("clip", 500, this.callback.bind(this));
        jQuery('html,body').animate({scrollTop: (jQuery("#"+this.obj).offset().top - 20)}, 'slow');	
	},
	callback: function() {
		jQuery("#"+this.obj).effect("pulsate", { times: 3}, 250);
	}
});
// var LoadingOverlay = Class.create( {
// 	initialize: function(onTopOfDiv) {
// 		this.onTopOfDiv = onTopOfDiv;
// 		this.overlayDiv = new Element('div', {
// 			'style':'background-color:#fff;display:none;position:absolute;top:0;left:0;overflow:auto;z-index:998;'
// 		});
// 		this.loadingImage = new Element('img', {
// 			'style': 'width:32px;height:32px;position:absolute;top:0;left:0;overflow:auto;z-index:999',
// 			'src': '/images/indicator.gif',
// 			'alt': 'loading'
// 		});
// 
// 		document.body.appendChild(this.overlayDiv);
// 		this.overlayDiv.appendChild(this.loadingImage);
// 
// 		Element.clonePosition(this.overlayDiv, this.onTopOfDiv);
// 		var topleft = this.overlayDiv.positionedOffset();
// 		this.overlayDiv.style.opacity = 0.0;
// 		this.loadingImage.style.left = Math.round(topleft.left + this.overlayDiv.getWidth()/2 - this.loadingImage.getWidth()/2)+"px";
// 		this.loadingImage.style.top = Math.round(topleft.top + this.overlayDiv.getHeight()/2 - this.loadingImage.getHeight()/2)+"px";
// 
// 		this.overlayDiv.show();
// 
// 		new Effect.Opacity(this.overlayDiv, { from: 0.0, to: 1.0, duration: 1});
//     },
// 	hide: function() {
// 		new Effect.Opacity(this.overlayDiv, {from: 1.0, to:0.0, duration: 1, afterFinish: this.removeFromDOM.bind(this)});
// 	},
// 	removeFromDOM: function(effect) {
// 		this.overlayDiv.remove();
// 		alert('Div removed');
// 	}
// });
Ajax.Request.addMethods({
	abort:		function()   {
		// alert('aborting');
	    this.transport.onreadystatechange = Prototype.emptyFunction;     
	    this.transport.abort();     
	    this._complete = true;     
	    this.aborted = true;     
	    var response = new Ajax.Response(this);     
	    Ajax.Responders.dispatch('onAbort', this, response, response.headerJSON);
	}
});

Ajax.currentRequests = new Array();

Ajax.abortRequests = function() {
	// alert('Ajax.currentRequests');
	if (Ajax.currentRequests instanceof Array) {
		Ajax.currentRequests.each(function(req) {
				req.abort();
        });
	}
};

Ajax.Responders.register({
	onCreate: function(request) {
		// if (request.options.onlyLatestOfClass && Ajax.currentRequests[request.options.onlyLatestOfClass]) {
		// 	// if a request of this class is already in progress, attempt to abort it before launching this new request
		// 	try { Ajax.currentRequests[request.options.onlyLatestOfClass].transport.abort(); } catch(e) {}
		// }
		// keep note of this request object so we can cancel it if superceded
		// Ajax.currentRequests[request.options.onlyLatestOfClass] = request;
		Ajax.currentRequests.push(request);
	},
	onComplete: function(request) {
		// if (request.options.onlyLatestOfClass) {
		// 	// remove the request from our cache once completed so it can be garbage collected
		// 	Ajax.currentRequests[request.options.onlyLatestOfClass] = null;
		// }
		Ajax.currentRequests = Ajax.currentRequests.without(request);
	}
});

function addslashes(str) {
     str=str.replace(/\'/g,'\\\'');
     str=str.replace(/\"/g,'\\"');
     str=str.replace(/\\/g,'\\\\');
     str=str.replace(/\0/g,'\\0');
     return str;
}

