﻿/*function reDrawMiniBasket(){
	$('.buy .items li').remove();
	$('.buy .items li').addClass('removed');
	$('div.buy .items .title').hide();
	$('div.buy .items ul').hide();
	$('div.buy .items p.total').hide();
	miPrice = 0;
	$("input[name=mobInt]:checked").each(function(){
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="mobint" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +'</li>');
			miPrice = $(this).attr('price');
		}
	});
	planPrice = 0;
	$("input[name=plan]:checked").each(function(){
		planType = '' ;
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="plan" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +''+planType+'</li><li class="plan"><em>QR '+simpackPrice+'</em> - Welcome Pack</li>');
			planPrice = $(this).attr('price');
		}	
	});
	BBPrice = 0;
	$("input[name=blackberry]:checked").each(function(){
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="plan" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +'</li>');
			BBPrice = $(this).attr('price');
		}	
	});
	totalPrice = miPrice*1+planPrice*1+BBPrice*1+phonePrice*1+simpackPrice*1;
	if (miPrice*1+planPrice*1+BBPrice*1!=0)
	{
		$('div.buy .items .title').show();
		$('div.buy .items ul').show();
	$('div.buy .items p.total').show();
	}
	$('.items p.total em').html('QR ' + totalPrice);
	
};


$(document).ready(function(){
	if (typeof $('form[name=addToBasket]').attr('name')== 'undefined') {
			$('input').attr("disabled", "disabled");
			$('input[name=sa]').attr("disabled", false);
			$('input[name=q]').attr("disabled", false);
	}
	planPrice = 0;
	miPrice = 0;
	BBPrice = 0;
	$('input[name=plan][value=]').click();
	$('input[name=mobInt][value=]').click();
	$('input[name=plan]').click(function(){
		if ($(this).val()!=''){
			$('input[name=mobInt][value=]').click();
			$('input[name=mobInt]').attr("disabled", false);
			if ($(this).hasClass('Freedom')){
				$('input#mobIntFreedomRed').attr("disabled", "disabled");
				$('input#mobIntFreedomdom').attr("disabled", false);
				$('input[name=blackberry]').attr("disabled", false);
			}
			else {
				$('input#mobIntFreedomRed').attr("disabled", false);
				$('input#mobIntFreedomdom').attr("disabled", "disabled");
			}
		}
		else {
			$('input[name=mobInt][value=]').click();
			$('input[name=mobInt]').attr("disabled", "disabled");
			$('input[name=blackberry]').attr("disabled", "disabled");
			$('input[name=blackberry]').attr("checked",false);
		}
	});
	$('input').click(function(){
		reDrawMiniBasket();
	});
	$('input[type=checkbox]').click(function(){
		reDrawMiniBasket();
	});
	$('input[name=mobInt]').attr("disabled", "disabled");
	$('input[name=blackberry]').attr("disabled", "disabled");
});
$(document).ready(function(){
	setupPlanPromoBoxes();	
	setupViewAllPlansOnPhoneDetailsPage();
	
	$('.normalPlansContainer .section').hide();
	$('.normalPlansContainerView').show();
});

function setupPlanPromoBoxes()
{	
	$('.plansSpecialOffer').addClass('plansSpecialOfferClosed');
	$('.plansSpecialOfferViewMoreLink').show();
	
	$('.plansSpecialOfferViewMoreLink').click(function(event){
		
		event.preventDefault();
		
		var el = $(this);
		
		el.parent().parent().toggleClass('plansSpecialOfferClosed');
		
		el.find('span').text(el.find('span').text() == '+ View' ? '- Hide' : '+ View');
			
	});
}

function setupViewAllPlansOnPhoneDetailsPage()
{
	$('.normalPlansContainerView a').click(function(event)
	{
		event.preventDefault();

		if('none' == $('.normalPlansContainer .section').css('display'))
		{
			$('.normalPlansContainer .section').show();
			$('.normalPlansContainerView h3 a').text('- Hide extra plans');
		}
		else
		{
			$('.normalPlansContainer .section').hide();
			$('.normalPlansContainerView h3 a').text('+ View all plans');
		}
		
		//$('.normalPlansContainerView').hide();
	});
}
*/
function reDrawMiniBasket(){
	$('.buy .items li').remove();
	$('.buy .items li').addClass('removed');
	$('div.buy .items .title').hide();
	$('div.buy .items ul').hide();
	$('div.buy .items p.total').hide();
	miPrice = 0;
	$("input[name=mobInt]:checked").each(function(){
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="mobint" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +'</li>');
			miPrice = $(this).attr('price');
		}
	});
	planPrice = 0;
	$("input[name=plan]:checked").each(function(){
		planType = '' ;
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="plan" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +''+planType+'</li><li class="plan"><em>QR '+simpackPrice+'</em> - Welcome Pack</li>');
			planPrice = $(this).attr('price');
		}	
	});
	BBPrice = 0;
	$("input[name=blackberry]:checked").each(function(){
		if ($(this).val()!='') {
			$('.buy .items ul').append('<li class="plan" objectid="'+ $(this).val() +'"><em>QR ' + $(this).attr('price')*1 +'</em> - ' + $(this).parent().find('label').attr('label') +'</li>');
			BBPrice = $(this).attr('price');
		}	
	});
	totalPrice = miPrice*1+planPrice*1+BBPrice*1+phonePrice*1+simpackPrice*1;
	if (miPrice*1+planPrice*1+BBPrice*1!=0)
	{
		$('div.buy .items .title').show();
		$('div.buy .items ul').show();
	$('div.buy .items p.total').show();
	}
	$('.items p.total em').html('QR ' + totalPrice);
	
};


$(document).ready(function(){
	/*if (typeof $('form[name=addToBasket]').attr('name')== 'undefined') {
			$('input').attr("disabled", "disabled");
			$('input[name=sa]').attr("disabled", false);
			$('input[name=q]').attr("disabled", false);
	}*/		
	$('input[name=plan][value=]').trigger('click', [true]);
	$('input[name=mobInt][value=]').click();
	$('span.redAddon').hide();
	$('span.freedomAddon').hide();
	$('li.addonListMI.red').mouseenter(function () {
		if ($('input[id*=RedFlexi]').is (':checked'))  {
			$('span.redAddon').hide();
		} else {
			$('span.redAddon').show();
			
		}
	});	
	
	$('li.addonListMI.freedom').mouseenter(function () {
	if ($('input[id*=freedomFlexi]').is (':checked') || $('input[id*=freedomControl]').is (':checked')) {
			$('span.freedomAddon').hide();
		} 	else {
			$('span.freedomAddon').show();
		}	
	});	
	
	$('li.addonListMI').mouseleave(function () {
		$('span.redAddon').hide();
		$('span.freedomAddon').hide();
	});

	$('input[name=plan]').click(function(ev, bInit){
		var $this = $(this);
		
		if (typeof bInit == 'undefined') {
			bInit = false;
		}
	
		if ($(this).val()!=''){
			if (!bInit) {
				$('.options .section').show();
			}
			
			$('input[name=mobInt]').attr("checked",false);
			$('input[name=blackberry]').attr("checked",false);
			$('input[name=mobInt]').attr("disabled", false);
			$('input[name=blackberry]').attr("disabled", false);
			
			//$.each($('.options .section li input'), function() {
			//	if (parseInt$this.attr('price')
			//});
		}
		else {
			$('input[name=mobInt]').attr("checked",false);
			$('input[name=blackberry]').attr("checked",false);
			$('input[name=mobInt]').attr("disabled", "disabled");
			$('input[name=blackberry]').attr("disabled", "disabled");
		}
	});
	$('input').click(function(){
		reDrawMiniBasket();
	});
	$('input[type=checkbox]').click(function(){
		reDrawMiniBasket();
	});
	$('input[name=mobInt]').attr("disabled", "disabled");
	$('input[name=blackberry]').attr("disabled", "disabled");
});
$(document).ready(function(){
	setupPlanPromoBoxes();	
	setupViewAllPlansOnPhoneDetailsPage();
	
	$('.normalPlansContainer .section').hide();
	$('.normalPlansContainerView').show();
	
	/*
	 * handle click event on Plan group tabs - show/hide plan values
	 */
	$('input[id=noPlan]').trigger('click', [true]);
	$('input[name=mobInt]').attr('checked', false);
	$('input[name=mobInt]').attr("disabled", "disabled");
	$('.planGroups a').each(function(i) {
		$(this).click(function(e) {		
			$('input[id=noPlan]').trigger('click', [true]);
			$('input[name=mobInt]').attr('checked', false);
			$('input[name=mobInt]').attr("disabled", "disabled");
			if(e.target.className !== 'selected' ) 
			{
				if (e.target.className =='freedom selected')
					{}
				else if (e.target.className =='red selected')						
					{}
				else
					{						
					$('.planGroups a.selected').toggleClass('selected');
					$(this).toggleClass('selected');
					$('.planTypes:visible, .planTypes:eq('+i+')').toggle();
					}
			}			
			if($(e.target).hasClass('freedom')) {	
				if( e.target.id != 'limit')
				{
				$('.planAddons').show();
				$('.control').hide();
				
				}
				else
				{				
				$('.planAddons').hide();
				$('.control').hide();				
				}
				$('div.section.planAddons ul li.red').hide();
				$('div.section.planAddons ul li').find('input').attr('checked', false);
				$('div.section.planAddons ul li.freedom').show();
			}
			else if ($(e.target).hasClass('red')) {
				$('.planAddons').show();
				$('div.section.planAddons ul li.red').show();
				$('div.section.planAddons ul li').find('input').attr('checked', false);
				$('div.section.planAddons ul li.freedom').hide();
			} else {
				$('.options .section').hide();
				$('.planAddons').hide();
				$('div.section.planAddons ul li').find('input').attr('checked', false);
				$('div.section.planAddons ul li').find('input').attr("disabled", "disabled");
				$('input[id=noPlan]').attr("checked", true);
				reDrawMiniBasket();
			}
			return false;
		});				
	});
	
});

function setupPlanPromoBoxes()
{	
	$('.plansSpecialOffer').addClass('plansSpecialOfferClosed');
	$('.plansSpecialOfferViewMoreLink').show();
	
	$('.plansSpecialOfferViewMoreLink').click(function(event){
		
		event.preventDefault();
		
		var el = $(this);
		
		el.parent().parent().toggleClass('plansSpecialOfferClosed');
		
		el.find('span').text(el.find('span').text() == '+ View' ? '- Hide' : '+ View');
			
	});
}

function setupViewAllPlansOnPhoneDetailsPage()
{
	$('.normalPlansContainerView a').click(function(event)
	{
		event.preventDefault();

		if('none' == $('.normalPlansContainer .section').css('display'))
		{
			$('.normalPlansContainer .section').show();
			$('.normalPlansContainerView h3 a').text('- Hide extra plans');
		}
		else
		{
			$('.normalPlansContainer .section').hide();
			$('.normalPlansContainerView h3 a').text('+ View all plans');
		}
		
		//$('.normalPlansContainerView').hide();
	});
}
/*
$("#freedom_no_limit").click(function () {
	$('ul.section.planAddons li').hide();
    otherElements = $('ul.section.planAddons').find('li.' + $(this).attr('freedom_no_limit'));
	otherElements.show();
});*/
