// Rate this page for support articles 
var feedBack = {};

feedBack.init = function () {
    // hide the options
    $('#feedBackContainer,#feedBackOptions').hide();
 
    // apply click handler to links
    $('#feedBackLinks').click(function (e) {
        var target = $(e.target);
        var type = $(target).attr('id');
        feedBack.displayForm(type);
        return false;
    });
};

feedBack.displayForm = function (type) {
    $('.feedback').hide();
    $('.feedback.' + type).show();
    $('#feedBackContainer').slideDown();
};

$(document).ready(function() {			   
	if( typeof( SWFObject ) != 'undefined') {
		var so = new SWFObject("/images/brand_refresh/pn_topbanner.swf", "banner2009usw", "946", "110", "7");
		so.addParam("wmode", "transparent");
		so.addVariable("cloudMove", "on");// Cloud animation off/on
		so.addVariable("flakeMove", "on");// Snowflake animation off/on
		so.addVariable("birdMove", "on");// Bird animation off/on
		so.write("flashcontent");
	};
    if ($('#rateThisPage').length > 0) {
        feedBack.init();
    }
	//Bundles page selector script
	if($('#bundles_picker_outer').length > 0){
		$('#bundles_picker_outer').removeClass('hidden');
		$('#no_javascript').addClass('hidden');
		$('form#bundleConfigure')[0].reset();
		buildURL();
		if ($.browser.msie) { 
			$('input[type=radio]').click(function(){
				this.blur();
				this.focus();
			});
		}
		$('input[type=radio].productCompare').change(function(){
			var theName = $(this).attr('name');
			$('input[name='+theName+']').parents('.optionSurround').toggleClass('selected');									 
			priceStar.calculate(theName);
			priceStar.throb();
			buildURL();
		});
	};
	if ($('div#content').hasClass('switchPage')) {
		// Code for the Switch page
		setupPage();
		$('#tabBroadband').click(function(){
			$('#broadbandInitialState,#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandInitialState').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine,#tabBroadband,#tabBroadbandAndHomePhone').removeClass('active');
			$('#tabBroadband').addClass('active');
			return false;
		});
		$('#tabBroadbandAndHomePhone').click(function(){
			$('#broadbandInitialState,#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandHomePhoneInitialState').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine,#tabBroadband,#tabBroadbandAndHomePhone').removeClass('active');
			$('#tabBroadbandAndHomePhone').addClass('active');
			return false;
		});
		$('#buttonIHave').click(function(){
			$('#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandStateOne,.switchProductBox,.hrArrows').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine').removeClass('active');
			$('#buttonIHave').toggleClass('active');
			return false;
		});
		$('#buttonIDontHave').click(function(){
			$('#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandStateTwo,.switchProductBox,.hrArrows').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine').removeClass('active');
			$('#buttonIDontHave').toggleClass('active');
			return false;
		});
		$('#buttonWhatIs').click(function(){
			$('#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandStateThree,.switchProductBox,.hrArrows').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine').removeClass('active');
			$('#buttonWhatIs').toggleClass('active');
			return false;
		});
		$('#buttonIHaveAnExistingPhoneLine').click(function(){
			$('#broadbandInitialState,#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandHomePhoneStateOne,.switchProductBox,.hrArrows').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine').removeClass('active');
			$('#buttonIHaveAnExistingPhoneLine').toggleClass('active');
			return false;
		});
		$('#buttonIDontHaveAPhoneLine').click(function(){
			$('#broadbandInitialState,#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,#broadbandHomePhoneStateOne,#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').addClass('hidden');
			$('#broadbandHomePhoneStateTwo,.switchProductBox,.hrArrows').toggleClass('hidden');
			$('#buttonIHave,#buttonIDontHave,#buttonWhatIs,#buttonIHaveAnExistingPhoneLine,#buttonIDontHaveAPhoneLine').removeClass('active');
			$('#buttonIDontHaveAPhoneLine').toggleClass('active');
			return false;
		});
		$('.theisp').change(function(){ispNumber(this);});
		// End of code for the switch page
	}
	
	// Code for the Comparison page
	if ($('div#compareISPs').hasClass('main-content')) {
		$('ul.tabs li a').click(function(){
			$('ul.tabs li a img').each(function(){
				var tabName = $(this).parent('a').attr('id');		
				$(this).attr('src','/images/compare/'+tabName+'.png');						
			});
			var tabName = $(this).attr('id');
			var tabTarget = $(this).attr('href').substr(1);
			$(this).children('img').attr('src','/images/compare/'+tabName+'Active.png');
			$('.comparison_table').addClass('hidden');
			$('#'+tabTarget).removeClass('hidden');
			return false;
		});
		$('ul.tabs li a:first').trigger('click');
				
		$('a.compareISPsSummary').click(function(){
			$('ul.tabs li a#tabAll').trigger('click');
			return false;
		});
	}
	// End of code for the comparison page
	// Contact us page expandable content
	if($('#content').hasClass('support')){
		$('.expandableRow').hide();
		$('.expandableHead').click(function(){
			$('.expandableHead').removeClass('arrowUp');
			if(!$(this).parent().children('.expandableRow').is(':hidden')){
				$(this).removeClass('arrowUp').parent().children('.expandableRow').hide();
			} else {
				$('.expandableRow').hide();
				$(this).addClass('arrowUp').parent().children('.expandableRow').show();
			}
	    });
   }
   //end of contact us page
});

// Script for bundles page selector wizzard
var priceStar = {};
priceStar.throb = function(){
	$('#price_star').stop().animate({opacity: "0.5"},250).animate({opacity: "1"},125);
}
priceStar.calculate = function(theName){
	var price1 = parseFloat($('input[type=radio].productCompare[name='+theName+']:checked').val());
	var price2 = parseFloat($('input[type=radio].productCompare:not([name='+theName+']):checked').val());
	var totalPrice = price1 + price2;
	totalPrice = totalPrice.toFixed(2);
	priceStar.insertPrice(totalPrice);
};
priceStar.insertPrice = function(totalPrice){
	var priceSplit = totalPrice.split('.');
	$('span#priceMajor').text(priceSplit[0]);
	$('span#priceMinor').text(priceSplit[1]);	
};
function buildURL(){
	var broadbandProduct = $('input[type=radio].productCompare[name=bb]:checked').attr('id');
	var phoneProduct = $('input[type=radio].productCompare[name=phone]:checked').attr('id').substr(1);
	if($('#bbch4choiceOffer').length > 0) {
		var formURL = 'https://www.plus.net/residential/signup/index.php/'+broadbandProduct+'?bundle='+phoneProduct+'&code=4choice&offer=ACTIVATION';
	} else if($('#hpchNewLine').length > 0) {
		var formURL = 'https://www.plus.net/residential/signup/index.php/'+broadbandProduct+'?bundle='+phoneProduct+'&code=4choice&offer=ACTIVATION&newLine=1'
	} else {
		var formURL = 'https://www.plus.net/residential/signup/index.php/'+broadbandProduct+'?bundle='+phoneProduct+''
	}
	$('form#bundleConfigure').attr('action', formURL);
}

// Functions for the switch page
function setupPage(){
	$('#broadbandStateOne,#broadbandStateTwo,#broadbandStateThree,.switchProductBox,.hrArrows,#broadbandHomePhoneInitialState,#broadbandHomePhoneStateOne, #broadbandHomePhoneStateTwo, .jsDisabledContent').addClass('hidden');
	$('.jsEnabledContent').removeClass('hidden');
}
function ispNumber(object){
	var textElement = $(object).parent('form').find('.theISPNumber');
	var tempNumber = $(object).val();
	$(textElement).text(tempNumber);
}
// End of functions for the switch page