var IbericoCheckDslAvailablity = {

	init: function() {
		var ref = this;
	},
	
	isChecked: function(form) {
		new Ajax.Request(form.action,
			{
				method:'post', 
				parameters: Form.serialize(form),
				onSuccess: function(helper){
					var response = helper.responseText || "no hay informaciones del proveedor";
					
					var providerId;
					
					for (var i = 0; i < form.elements.length; i++) {
						if (form.elements[i].name == 'providerId') {
							providerId = form.elements[i].value;
						}
					}
					
					var message = checkMessages[response][providerId];
					
					//alert(message);
					
					var lastIndex = form.id.lastIndexOf('_');
					var fistIndex = form.id.indexOf('_');
					var id = form.id.substring(lastIndex + 1, form.id.length);
					var tipId = form.id.substr(fistIndex + 1, 1);
					
					if (response < 2) {
						$('showCheckText_' + tipId + '_' + id).innerHTML = message;
						
						window.setTimeout('IbericoCheckDslAvailablity.success(' + id + ',' + tipId + ')',4000);
					}
					
					if (response == 2) {
						$('showCheckText_' + tipId + '_' + id).innerHTML = message;
						
						window.setTimeout('IbericoCheckDslAvailablity.failed(' + id + ',' + tipId + ')',4000);
					}
					
					if (response == 3) {
						$('checkMessage_' + tipId + '_' + id).innerHTML = checkMessages[4][providerId] + message + '<br/>';
						
						window.setTimeout('IbericoCheckDslAvailablity.invalid(' + id + ',' + providerId + ',' + tipId + ')',3000);
					}
				},
				onFailure: function() {}
			});
	},
	
	success: function(formId, tipId) {
		tips[tipId][formId].hide();
		$('showCheckText_' + tipId + '_' + formId).innerHTML = text[tipId][formId];
			
		$('forwardOffer_' + tipId + '_' + formId).target = '_self';
		$('forwardOffer_' + tipId + '_' + formId).submit();
		
	},
	
	failed: function(formId, tipId) {
		tips[tipId][formId].hide();
		$('showCheckText_' + tipId + '_'  + formId).innerHTML = text[tipId][formId];
	},
	
	invalid: function(formId, providerId, tipId) {
		$('checkMessage_' + tipId + '_'  + formId).innerHTML = checkMessages[4][providerId];
	}
};

Iberico.addPageLoadModule(IbericoCheckDslAvailablity);