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 ) {
   this.CheckCampaigns();
	var url = this.AddCampaignParameter( target );
	    url = this.AddPaymentParameters( url );

	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 ) {			
	
	this.CheckCampaigns();
	var url = this.AddCampaignParameter( target );
	    url = this.AddPaymentParameters( url );
    
	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.CheckCampaigns = function( checkedItem ) {
	
	var oldBookingPrice = this.BookingDetails.Price;
	var $campaignItems = $('input[name=list]');
	
	if ( $campaignItems.length > 0 ) {
		$checkedItem = ( checkedItem != null ) ? $(checkedItem) : 'NA';
		
		if ( $checkedItem != 'NA' && $checkedItem.attr('checked') == true ) {
			$campaignItems.not('[value=\''+$checkedItem.val()+'\']').attr('checked',false);
		} else {
			var $earlyReservationItem = $campaignItems.filter('[value=\'earlyreservation\']');
			
			if ( $earlyReservationItem.length > 0 ) {
				$earlyReservationItem.attr('checked',true);
			}
		}
		
		var $selectedItem = $campaignItems.filter('[checked]');
		
		if ( $selectedItem.length > 0 ) {
			this.BookingDetails.CampaignId = parseInt( $selectedItem.attr('campaignid') );
			this.BookingDetails.Price = $selectedItem.attr('price');
			this.BookingDetails.PriceUnit = $selectedItem.attr('priceunit');
			this.BookingDetails.MP = $selectedItem.attr('mp');
			
			$('.gPrice').html( $selectedItem.attr('pricetext') );
			$('.gPriceDescription').html( $selectedItem.attr('description') );
			
			var $eftPrice = $('#EFTPrice');
			
			if ( $eftPrice.length > 0 ) {
				$('.ePrice').html( $selectedItem.attr('eftpricetext') );
			}
			
			//this.AssignSupplierPrice();
		} else {
			//this.AssignDefaultPrice();
		}
		
	} else {
		//this.AssignDefaultPrice();
	}

	/*if ( oldBookingPrice != 0 && oldBookingPrice != this.BookingDetails.Price )
	{
		this.GetBasicInstallments( this.GetCurrentVA() );
	}*/
	
};

Gezisitesi.ProductPriceDetailsHelper.prototype.AddCampaignParameter = function( url ) {
	var tempUrl = url;
	
	//if ( this.BookingDetails.PriceQualifier == 'PACKAGE' && this.BookingDetails.CampaignId != 0 ) 
	if ( this.BookingDetails.CampaignId=='' ||  typeof(this.BookingDetails.CampaignId) =="undefined" || this.BookingDetails.CampaignId=='NA' || this.BookingDetails.CampaignId=='NaN')
	{
		
		return tempUrl;
		
	}
	if(this.BookingDetails.CampaignId != 0)
	{
	 
	    tempUrl += '&cp=' + this.BookingDetails.CampaignId.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();
	}
};


