if (!window.Tariff) {
    var Tariff = new Object();
}

Tariff.BankForm = Class.create({
	initialize : function(form,url_prefix) {
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target, bankId, bankName, bankLogoPath, bankDescription) { 
		 
		this.form.action = this.url_prefix + action;
		this.form.target = target;
								
		$('bankId').value = bankId;
		$('bankName').value = bankName;
		$('bankLogoPath').value = bankLogoPath;
		$('bankDescription').value = bankDescription;
		this.form.submit();
	}
});

Tariff.BankOfferForm = Class.create({
	initialize : function(form,url_prefix) {
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target) { 
		 
		this.form.action = action;
		this.form.target = target;
		
		this.form.submit();
	}
});

Tariff.MobileForm = Class.create({
	initialize : function(form,url_prefix) {
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target, offerId, providerId, tariffId, locationId, logType) { 
		 
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}
	
		this.form.action = this.url_prefix + action;
		this.form.target = target;
								
		$('offerId').value 		= offerId;
		$('providerId').value 	= providerId;
		$('tariffId').value 	= tariffId;
		$('locationId').value 	= locationId;
		$('logType').value 		= logType;
		
		this.form.submit();
	}
});

Tariff.InternetForm = Class.create({
	initialize : function(form,url_prefix) { 
		this.form = $(form); 	
		this.url_prefix = url_prefix;					
	},

	click : function(action, target, offerCheckAvailable, offerId, providerId, tariffId, locationId, logType, includeTelefonicaCosts) { 
		
		//if (offerCheckAvailable=='false') return false;
		
		//if (window.clipboardData && document.compatMode && !window.XMLHttpRequest) { 
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}
		//}
		
		this.form.action = this.url_prefix + action;
		this.form.target = target;
					
		$('offerId').value 		= offerId;
		$('providerId').value 	= providerId;
		$('tariffId').value 	= tariffId;
		$('locationId').value 	= locationId;
		$('logType').value 		= logType;
		//$('profile.includeTelefonicaCosts').value = includeTelefonicaCosts;
		
		this.form.submit();			
	}
});

Tariff.LoanForm = Class.create({
	initialize : function(form,url_prefix) { //alert(form);
		this.form = $(form); 	
		this.url_prefix = url_prefix;					
	},

	click : function(action, target, profileId, offerId, providerId, tariffId, locationId, logType) { 
		
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}
		
		this.form.action = this.url_prefix + action;
		this.form.target = target;
		
		$('offerId').value 		= offerId;
		$('providerId').value 	= providerId;
		$('tariffId').value 	= tariffId;
		$('locationId').value 	= locationId;
		$('logType').value 		= logType;
		$('profile.id').value   = profileId;
		alert("click " + action);
		this.form.submit();
	},
	
	clickDetails : function(action, target, profileId, offerId, providerId, tariffId, locationId, logType, loanIntervalTimeId, loanIntervalValueId, duration, creditAmount) { 
		alert("click details " + action);
		this.form.action = this.url_prefix + action;
		this.form.target = target;
		
		$('config.loanIntervalTimeId').value   	= loanIntervalTimeId;
		$('config.loanIntervalValueId').value  	= loanIntervalValueId;
		$('config.duration').value  			= duration;
		$('config.creditAmount').value   		= creditAmount;
		$('profile.duration').value  			= duration;
		$('profile.creditAmount').value   		= creditAmount;
		$('offerId').value 						= offerId;
		$('providerId').value 					= providerId;
		$('tariffId').value 					= tariffId;
		$('locationId').value 					= locationId;
		$('logType').value 						= logType;
		$('profile.id').value  					= profileId;
			
		this.form.submit();
	}
});

Tariff.CreditcardForm = Class.create({
	initialize : function(form,url_prefix) {  
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target, offerId, providerId, tariffId, locationId, logType) {
		
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}

		this.form.action = this.url_prefix + action;
		this.form.target = target;
								
		$('offerId').value 		= offerId;
		$('providerId').value 	= providerId;
		$('tariffId').value 	= tariffId;
		$('locationId').value 	= locationId;
		$('logType').value 		= logType;
		
		this.form.submit();
	}
});

Tariff.AccountForm = Class.create({
	initialize : function(form,url_prefix) {  
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target, offerId, providerId, tariffId, locationId, logType) {
		
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}

		this.form.action = this.url_prefix + action;
		this.form.target = target;
								
		$('offerId').value 		= offerId;
		$('providerId').value 	= providerId;
		$('tariffId').value 	= tariffId;
		$('locationId').value 	= locationId;
		$('logType').value 		= logType;
		
		this.form.submit();
	}
});

Tariff.DepositForm = Class.create({
	initialize : function(form,url_prefix) {  
		this.form = $(form); 
		this.url_prefix = url_prefix;		
	},

	click : function(action, target, offerId, providerId, tariffId, locationId, logType, depositAmount, depositDuration) {
		
		try {
			[$('submitEditorialTips0'), $('submitEditorialTips1')].each(function(item){				
				var parent = item.parentNode;
				if (parent.nodeName == 'FORM') {
					parent.parentNode.appendChild(item);
					parent.parentNode.removeChild(parent);
				}
			});
		} catch (e) {}

		this.form.action = this.url_prefix + action;
		this.form.target = target;
								
		$('offerId').value 				= offerId;
		$('providerId').value 			= providerId;
		$('tariffId').value 			= tariffId;
		$('locationId').value 			= locationId;
		$('logType').value 				= logType;
		$('depositAmount').value 		= depositAmount;
		$('depositDuration').value   	= depositDuration;
		
		this.form.submit();
	}
});

Tariff.TooltipHelper = Class.create({
	initialize : function(url_prefix) {
		this.url_prefix = url_prefix;
	},
	
	createAjax : function(element, url, id, page) { 
		if (page=='undefined' || page=='') {
			url = this.url_prefix + url + "?offerId=" + id;
		} else {
			url = this.url_prefix + url + "?offerId=" + id + "&page=" + page;
		}	 
		new Tip(element, { 
			ajax: {
				url: url,
				options: {
					onComplete: function(result) { 
						if (result.responseText.indexOf('AN_ERROR_OCCURRED')>0) {
							//alert("Sorry, an error occurred!");
							Tips.remove(element);
						} 
					}					
				} 
			}, width: 'auto'});		
	},
	
	createLoanAjax : function(element, url, offerId, loanIntervalTimeId, loanIntervalValueId, duration, creditAmount, page) {
		creditAmount = creditAmount.replace(/\./,",");
		if (page=='undefined' || page=='') {
			url = this.url_prefix + url + "?offerId=" + offerId + "&config.loanIntervalTimeId=" + loanIntervalTimeId + "&config.loanIntervalValueId=" + loanIntervalValueId + "&config.duration=" + duration + "&config.creditAmount=" + creditAmount;
		} else {
			url = this.url_prefix + url + "?offerId=" + offerId + "&config.loanIntervalTimeId=" + loanIntervalTimeId + "&config.loanIntervalValueId=" + loanIntervalValueId + "&config.duration=" + duration + "&config.creditAmount=" + creditAmount + "&page=" + page;
			//alert("url:" + url);
		}	
		new Tip(element, { 
			ajax: {
				url: url,
				options: {
					onComplete: function(result) { 
						if (result.responseText.indexOf('AN_ERROR_OCCURRED')>0) {
							//alert("Sorry, an error has occurred");
							Tips.remove(element);
						} 
					}					
				} 
			}, width: 'auto'});		
	},
	
	createDepositAjax : function(element, url, offerId, depositDuration, depositAmount, page) {
		depositAmount = depositAmount.replace(/\./,",");
		if (page=='undefined' || page=='') {
			url = this.url_prefix + url + "?offerId=" + offerId + "&depositAmount=" + depositAmount + "&depositDuration=" + depositDuration;
		} else {
			url = this.url_prefix + url + "?offerId=" + offerId + "&depositAmount=" + depositAmount + "&depositDuration=" + depositDuration + "&page=" + page;
		}	 
		new Tip(element, { 
			ajax: {
				url: url,
				options: {
					onComplete: function(result) { 
						if (result.responseText.indexOf('AN_ERROR_OCCURRED')>0) {
							//alert("Sorry, an error occurred!");
							Tips.remove(element);
						} 
					}					
				} 
			}, width: 'auto'});		
	},
	
	createCarAjax : function(element, url, profileIdKey , page) {
		if (page=='undefined' || page=='') {
			url = this.url_prefix + url + "?carSearchProfileKey=" + profileIdKey;
		} else {
			url = this.url_prefix + url + "?carSearchProfileKey=" + profileIdKey + "&page=" + page;
		}	 
		new Tip(element, { 
			ajax: {
				url: url,
				options: {
					onComplete: function(result) { 
						if (result.responseText.indexOf('AN_ERROR_OCCURRED')>0) {
							//alert("Sorry, an error occurred!");
							Tips.remove(element);
						} 
					}					
				} 
			}, width: 'auto'});		
	}
});


