var Gezisitesi = window.Gezisitesi || {};

Gezisitesi.ProductPriceDetailsHelper = function( ) {
	this.BookingDetails = {};
	this.ResetPaymentDetails();
};

Gezisitesi.ProductPriceDetailsHelper.prototype.ResetPaymentDetails = function( ) {
	this.BookingDetails.VA = '';
	this.BookingDetails.PaymentType = 'CreditCard';
	this.BookingDetails.Installment = 0;
};

Gezisitesi.ProductPriceDetailsHelper.prototype.StartSale = function( target, lgn ) {
	var url = this.AddPaymentParameters( target );

	if ( lgn ) {
		StartBuyNow( url );
	} else {
		$('#win').block(GezisitesiResources.StaticText.m006 + GezisitesiResources.StaticText.m017, {'font-size':'14px','font-weight':'bold','background-color':'#eff5f7',border:'1px solid #cccccc'});
		window.location.href = url;
	}
};

Gezisitesi.ProductPriceDetailsHelper.prototype.AddItemToShoppingBag = function( target, lgn ) {			
	var url = this.AddPaymentParameters( target );

	if ( lgn ) {
		AddProductShoppingBag( url );
	} else {
		$('#win').block(GezisitesiResources.StaticText.m006 + GezisitesiResources.StaticText.m017, {'font-size':'14px','font-weight':'bold','background-color':'#eff5f7',border:'1px solid #cccccc'});
		window.location.href = url;
	}
};

Gezisitesi.ProductPriceDetailsHelper.prototype.SetPaymentMethod = function( paymentType, vposAccount, installment ) {
	this.ResetPaymentDetails();

	this.BookingDetails.PaymentType = paymentType;
	this.BookingDetails.VA = vposAccount;
	this.BookingDetails.Installment = installment;
};

Gezisitesi.ProductPriceDetailsHelper.prototype.AddPaymentParameters = function( url ) {
	var tempUrl = url;

	if ( this.BookingDetails.VA != '' ) {
		tempUrl += '&vac=' + this.BookingDetails.VA;
	}
	
	if ( this.BookingDetails.PaymentType != 'CreditCard' ) {
		tempUrl += '&pyt=' + this.BookingDetails.PaymentType;
	}
	
	if ( this.BookingDetails.Installment != 0 ) {
		tempUrl += '&ins=' + this.BookingDetails.Installment.toString();
	}
	
	return tempUrl;
};

Gezisitesi.ProductPriceDetailsHelper.prototype.CheckPaymentMethod = function( checkedItem, callbackBase ) {
	var baseHandler = (callbackBase != null && callbackBase != 'undefined') ? callbackBase : this;
	$paymentItems = $('input[name=paymentmethod]');
	
	if ( $paymentItems.length > 0 ) {
		var $installmentItems = $('[pyt=\'CreditCardInstallment\']');
		
		if ( $installmentItems.length < 1 )
		{
			$installmentItems = $('[pyt=\'CreditCard\']');
		}
		
		var $checkedItem = ( checkedItem != null ) ? $(checkedItem) : $installmentItems.eq(0).attr('checked', true);
		
		if ( $checkedItem.length > 0 )
		{
			baseHandler.SetPaymentMethod( $checkedItem.attr('pyt'), $checkedItem.attr('vac'), $checkedItem.attr('ins') );
		}
	} else {
		baseHandler.ResetPaymentDetails();
	}
};

