/*++++++++++++++++++++++++++++++++++

Purpose:
Custom Javascript for vodafone.ie (Online Store)

Created by:
Colm McBarron (iQ Content)

++++++++++++++++++++++++++++++++++*/


/*
========================================
	Global variables
========================================
*/

var laser_cc_type_field_value = 'Laser';// the value of the select when laser is selected
var _3d_demo_design_folder ='3dcommerce'; // the path to the folder than contains the design files (.jar) for the 3d demo
var _3d_demo_phones_folder ='3dphones'; // the path to the folder than contains the phone files (.jar) for the 3d demo

/*
========================================
	Ajax references
========================================
*/

var communityvalidation_ajax_call = "/utility/community/ValidPrefix.shtml";

/*
========================================
	Image references
========================================
*/

var _3d_demo_loading_image = "/images/design/applet_loading.gif"; // the image used before the applet is loaded

/*
========================================
	Initialise the shop
========================================
*/

$( 
	function() {
		
		if ($('#priceplan-tab-content').length) {
			setupActivePricePlan();
			$('#priceplan-tab-content input').bind('focus', setActivePricePlan);
		}
		
		if ($('.delivery-address-selection').length) {
			toggleDeliveryFields();
			$('.delivery-address-selection input').bind('click', toggleDeliveryFields);
		}
		
		if ($('.vathome-selection').length) {
			toggleVFatHomeFields();
			$('.vathome-selection input').bind('click', toggleVFatHomeFields);
		}
		
		if ($('#c_ordertracking').length) {
			toggleOrderTrackingNumber();
			$('#c_ordertracking').bind('click', toggleOrderTrackingNumber);
		}
		
		if ($('.newuser-details-selection').length) {
			toggleMultilineFields();
			$('.newuser-details-selection input').bind('click', toggleMultilineFields);
		}
		
		if ($('#modem-somebody-else').length) {
			toggleOtherUser();
			$('#modem-somebody-else input').bind('click', toggleOtherUser);
		}
		
		
		if ($('.card-type-select select').length) {
			toggleCVVFields();
			$('.card-type-select select').bind('change', toggleCVVFields);
		}
		
		if ($('#billPay_wrapper').length) {
			toggleCustomerNumber();
		}
		
		if ($('select#k_currentplan').length) {
			$('select#k_currentplan').bind('change', toggleCustomerNumber);
		}

		if ($('select#pd_occupation').length) {
			toggleJobDetails();
			$('select#pd_occupation').bind('change', toggleJobDetails);
		}		
		
		if ($('.phone-listing .out-of-stock').length) {
			setupOutOfStockLinks();
		}
		
		if ($('#keyfeatures .phone-features-column').length) {
			setupKeyFeaturesHelp();
		}
		
		if ($('.payment-method-wrapper h3').length) {
			setupUpgradePaymentScreens();
		}
		
		
		
		if ($('#phone-features').length) {
			setupPhoneFeatures();	
			setupPhoneFeaturesTable();
		}
		
		if ($('#switch_date').length) {
		Date.firstDayOfWeek = 7;
		$('#switch_date')
				.datePicker(
					{
						createButton:false,
						renderCallback:function($td, thisDate, month, year)
						{
							if (thisDate.isWeekend()) {
								$td.addClass('weekend');
								$td.addClass('disabled');
							}
						}
					}
				)
				.bind('click',
					function()
					{
						$(this).dpDisplay();
						this.blur();
						return false;
					}
				);
				
		}
		
		
		if ($("#customer-number-field").length) {
			$('select#current_plan_type').bind('change', togglePlanType);
			togglePlanType();
		}
		
		if ($(".module-carousel").length) {
			setupShopSwitchers();
		}
		
		if (($(".nba-handset").length) || ($(".nba-vf-handset").length)) {
			collabFilteringShowing();
		}
		
		if ($("#features-explained").length) {
			$("#features-explained a").bind("click", function(){
				GAT("/phonegallery/features-explained-help-link/");
			});
		}
	    
		if (($(".priceplan-js-tab-pane .priceplan-table .price-plan-info").length > 1) && ($(".upgrade-price-detail .priceplan-table .price-plan-info").length == 0) && ($('.iphone-paymonthly-phones').length == 0)) {
		    hideTopPCTariff(); 
		}
		
		if ($('#accessories-manufacturer').length) {
			observeAccessoryForm();
		}
		
		if ($('.community-numbers input[type=text]').length) {
			observeCommunityShowHide();
			observeCommunityNumbers();
		}
		
		if ($('#voucher_code').length) {
			observeVoucherCodeInput();
		}
		
		if ($("#portingoperatorcode-help-text").length) {
			$('select#current_network').bind('change', toggleCurrentNetHelp);
			toggleCurrentNetHelp();
		}
	 
	}
)






/*
========================================
	Show/hide the help text for the phone detail page
========================================
*/

function setupKeyFeaturesHelp() {
	$.each($('#keyfeatures .phone-features-column li a'), function(i, n){
		var ar = n.href.split('#');
		n.id = ar[1] + '_link';
		n.href='javascript:;';
	});

	$('#keyfeatures .phone-features-column li a').bind('click', function(){
		// get the ID
		$('#keyfeatures .phone-features-column li').removeClass('active-feature');
		var i = $(this).attr('id');
		if ($('.phone-features-column .feature-help-wrapper').length) {
			if ($('#keyfeatures a#' + i).parent('li').children('.feature-help-wrapper').length == 0) {
				hideKeyFeaturesHelp();
				showKeyFeaturesHelp(this);
				$('#' + i).parent().addClass('active-feature');
			} else {
				hideKeyFeaturesHelp();
			}	
		} else {
			showKeyFeaturesHelp(this);
			$('#' + i).parent().addClass('active-feature');
		}
		
	})
}


function showKeyFeaturesHelp(o) {
	var i = $(o).attr('id');
	i = i.substr(0, (i.length - 5));
	w = $(o).width();
	w = w + 25;
	
	$(o).after('<div class="feature-help-wrapper"><div class="feature-help"><div class="close"><a href="javascript:hideKeyFeaturesHelp();">Close</a></div>' + $('#' + i).html() + '</div></div>');
	$('.phone-features-column .feature-help-wrapper').css("left", w + "px");
	h = $('.phone-features-column .feature-help-wrapper').height();
	h = (h / 2) - 10;
	$('.phone-features-column .feature-help-wrapper').css("top", "-" + h + "px");
}

function hideKeyFeaturesHelp() {
	$('.phone-features-column .feature-help-wrapper').remove();
}


/*
========================================
	Show/hide Phone Feature Description
========================================
*/

function setupPhoneFeatures() {
	$.each($('#phone-features ul li a'), function(i, n){
		var ar = n.href.split('#');
		
		// Check to see if there's content for this link, otherwise remove it
		if ($('#phone-features-description #'+ar[1]).length) {
			n.id = ar[1] + '_link';
			n.href='javascript:;';
		}
		else {
			var link_contents = $(this).html();
			$(this).parent().html(link_contents);
		}
	});

	$('#phone-features ul li a').bind('click', function(){
		// get the ID
		$('#phone-features ul li').removeClass('active-feature');
		var i = $(this).attr('id');
		if ($('#phone-features .feature-help-wrapper').length) {
			if ($(this).parent('li').children('.feature-help-wrapper').length == 0) {
				hidePhoneFeaturesHelp();
				showPhoneFeaturesHelp(this);
				$('#' + i).parent().addClass('active-feature');
			} else {
				hidePhoneFeaturesHelp();
			}	
		} else {
			showPhoneFeaturesHelp(this);
			$('#' + i).parent().addClass('active-feature');
		}
		
		GAT("/handset-help/feature-" + i + "/type-overlay/");
		
	})
}

function setupPhoneFeaturesTable() {
	$.each($('#phone-features table th span a'), function(i, n){
		var ar = n.href.split('#');
		
		// Check to see if there's content for this link, otherwise remove it
		if ($('#phone-features-description #'+ar[1]).length) {
			n.id = ar[1] + '_link';
			n.href='javascript:;';
		}
		else {
			var link_contents = $(this).html();
			$(this).parent().html(link_contents);
		}
	});

	$('#phone-features table th span a').bind('click', function(){
		// get the ID
		$('#phone-features table').removeClass('active-feature');
		var i = $(this).attr('id');
		if ($('#phone-features .feature-help-wrapper').length) {
			if ($(this).parent('span').children('.feature-help-wrapper').length == 0) {
				hidePhoneFeaturesHelp();
				showPhoneFeaturesHelp(this);
				$('#' + i).parent().addClass('active-feature');
			} else {
				hidePhoneFeaturesHelp();
			}	
		} else {
			showPhoneFeaturesHelp(this);
			$('#' + i).parent().addClass('active-feature');
		}
		
	})
}

function showPhoneFeaturesHelp(o) {
	var i = $(o).attr('id');
	i = i.substr(0, (i.length - 5));
	w = $(o).width();
	w = w + 15;
	
	$(o).after('<div class="feature-help-wrapper"><div class="feature-help"><div class="close"><a href="javascript:hidePhoneFeaturesHelp();">Close</a></div>' + $('#' + i).html() + '</div></div>');
	$('#phone-features .feature-help-wrapper').css("left", w + "px");
	h = $('#phone-features .feature-help-wrapper').height();
	h = (h / 2) - 10;
	$('#phone-features .feature-help-wrapper').css("top", "-" + h + "px");
}

function hidePhoneFeaturesHelp() {
	$('#phone-features .feature-help-wrapper').remove();
}


/*
========================================
	open 3D popout
========================================
*/

function open3dpopout(jar_name) {
	$('.phone-info-js-tab-pane').hide();
	$('.phone-info-js-tabs .active').removeClass("active");
	$('#phone-images-basket-wrapper').addClass('applet-enabled');
	$("#java-applet-demo-outter-wrapper").show("",initialisePhoneApplet(jar_name));
	GAT('/df/shop/3d-demo/' + jar_name + '/embedded');
}

/*
========================================
	remove 3D popout elements
========================================
*/

function remove3DPopoutElements() {
	$('#java-applet-demo applet, #java-applet-demo .close-link').remove();
	$('#phone-images-basket-wrapper').removeClass('applet-enabled');
}

/*
========================================
	Toggle delivery fields
========================================
*/

function toggleDeliveryFields() {
	if ($('.delivery-address-selection input').fieldValue()[0] == 'no') {
		$('.alt-delivery-address').show();
	} else {
		$('.alt-delivery-address').hide();
	}
}

/*
========================================
	Toggle Vodafone at Home fields
========================================
*/

function toggleVFatHomeFields() {
	if ($('.vathome-selection input').fieldValue()[0] == 'no') {
		$('.alt-vathome-address').show();
	} else {
		$('.alt-vathome-address').hide();
	}
}

/*
========================================
	Toggle Order Tracking Text field
========================================
*/

function toggleOrderTrackingNumber() {
	if ($('#c_ordertracking').fieldValue()[0] == 'yes') {
		$('.order-tracking').show();
	} else {
		$('.order-tracking').hide();
	}
}


/*
========================================
	Toggle multiline details fields
========================================
*/

function toggleMultilineFields() {
	if ($('.newuser-details-selection input').fieldValue()[0] == 'no') {
		$('.alt-newuser-details').show();
	} else {
		$('.alt-newuser-details').hide();
	}

}


/*
========================================
	Toggle multiline details fields
========================================
*/

function toggleOtherUser() {
	if ($('#modem-somebody-else input').fieldValue()[0] == 'yes') {
		$('.modem-somebody-else').show();
	} else {
		$('.modem-somebody-else').hide();
	}

}




/*
========================================
	Toggle CVV fields
========================================
*/

function toggleCVVFields() {
	if ($('.card-type-select select').fieldValue()[0] == laser_cc_type_field_value) {
		$('.cvv-form-row').hide();
	} else {
		$('.cvv-form-row').show();
	}
}

/*
========================================
	Generic toggle
========================================
*/
function toggleElement(e) {
	$(e).toggle();
}

/*
========================================
	open 3D popout
========================================
*/

function initialisePhoneApplet(jar_name) {
	var applet_html;
	applet_html = '<div class="close-link"><a href="javascript:toggletab(\'phone-info\', \'phone-key-features\');">Close demo</a></div>';
	applet_html += '<div id="applet-loading"><img src="' + _3d_demo_loading_image + '" /></div>';
	$('#java-applet-demo').append(applet_html);
	applet_loader=setTimeout(function() {
	
	applet_html = '<applet width="627" height="451" name="Vodafone Ireland" code="Player_3Dimerce.class" mayscript codebase="." >';
	applet_html += '<param value="Created by 3Dimerce B.V. - http://www.3dimerce.com" name="info">';
	applet_html += '<param value="' + _3d_demo_design_folder + '/loadgfx.jar,' + _3d_demo_design_folder + '/startup6.jar,' + _3d_demo_design_folder + '/core6.jar,' + _3d_demo_design_folder + '/3D_Scene-4.0.jar,' + _3d_demo_design_folder + '/classes.jar" name="archive">';
	applet_html += '<param value="Registered version" name="license">';
	applet_html += '<param value="4.1.20" name="version">';
	applet_html += '<param value="" name="resourcefolder">';
	applet_html += '<param value="' + _3d_demo_design_folder + '/design.jar, ' + _3d_demo_phones_folder + '/' + jar_name + '.jar" name="preloadfile">';
	applet_html += '<param value="2201-21" name="regid">';
	applet_html += '<param value="192620-loadbg.gif" name="loadbgimage">';
	applet_html += '<param value="151445-loadbar.gif" name="loadbarimage">';
	applet_html += 'You need Java(tm) to view this presentation. <a href="http://www.java.com">Download Java</a>';
	applet_html += '</applet> ';
	document.getElementById('applet-loading').innerHTML = applet_html;		
	}
	,1000);
}

/*
========================================
	highlight the current price plan in the pay monthly details page
========================================
*/

function setupActivePricePlan()
{
	var planChild = $('#priceplan-tab-content table').find("input:checked");
	planChild.parents('tr').toggleClass('selected-row');
}

function setActivePricePlan() 
{
	$('#priceplan-tab-content table tr.selected-row').removeClass('selected-row');
	$(this).parents('tr').addClass('selected-row');
}

/*
========================================
	load an image into the phone area (if a demo isn't available)
========================================
*/

function loadPhoneImage(img_location) {
	$('#product-image img').attr("src", img_location);
}

/*
========================================
	Checks a hidden form variable for the connection type
========================================
*/



/*
========================================
	Toggle the customer number field in the checkout process.
========================================
*/

function toggleCustomerNumber() {
	if ($('#k_currentplan').val() == 'Bill Pay') {
		$('#billPay_wrapper').show();
	} else {
		$('#billPay_wrapper').hide();
	}
}

/*
========================================
	open 3D popup
========================================
*/

function open3dpopup(url) {
	var theWindow = window.open(url, '3d_popup', 'height=520,width=630,top=50,left=50,scrollbars=no');
	theWindow.focus();
	return theWindow;
}


/*
========================================
	Sets up the links for the Out of stock links
========================================
*/

function setupOutOfStockLinks() {
	var total_links = $('.phone-listing .out-of-stock a').length;
	var c = 0;
	var parent_id;
	while(c < total_links) {
		parent_id = $('.phone-listing .out-of-stock:eq(' + c + ')').attr('id');
		
		$('.phone-listing .out-of-stock a:eq(' + c + ')').attr('href', "javascript:toggleEmailOutOfStock('" + parent_id + "')");
		c = c + 1;
	}

}

/*
========================================
	Show/hide the Email when out of stock
========================================
*/

function toggleEmailOutOfStock(id) {
	if ($('#' + id + ' .email-when-avail-wrapper').length) {
		$('.email-when-avail-wrapper').remove();
	} else {
		if ($('.email-when-avail-wrapper').length) {
			$('.email-when-avail-wrapper').remove();
		}
		var email_html = '<div class="email-when-avail-wrapper"><div class="email-when-avail"><form action="#"><input type="hidden" name="phone_id" value="' + id + '" /><div class="email-address-label"><label for="email_' + id + '">Your email address</label></div><div class="email-address-input"><input type="text" name="email_address" id="email_' + id + '" /></div><div class="action-row"><div class="cancel-link"><a href="javascript:toggleEmailOutOfStock(\'' + id + '\')">Cancel</a></div><div class="email-btn"><input type="image" src="/images/design/shop_email_me_btn.png" alt="Email me" title="Email me" width="63" height="21" /></div></form></div></div>'
		$('#' + id).append(email_html);
	}
	
}

/*
========================================
	Upgrade payment screen
========================================
*/

function setupUpgradePaymentScreens() {
	// one open
	$(".payment-method-wrapper h3 input:checked").parent('h3').parent('.payment-method-wrapper').children('.payment-method').show();
	$(".payment-method-wrapper h3 input:checked").parent('h3').parent('.payment-method-wrapper').addClass('active-method');

	// click
	$('.payment-method-wrapper h3').click(function(){
		if ($(this).parent('.payment-method-wrapper').children('.payment-method:visible').length == 0) {
			$('.payment-method-wrapper .payment-method').hide();
			$('.payment-method-wrapper').removeClass('active-method');
			$(this).parent('.payment-method-wrapper').children('.payment-method').show();
			$(this).parent('.payment-method-wrapper').addClass('active-method');
		}
	});
	
	// mouseover
	$('.payment-method-wrapper h3').mouseover(function(){
		$(this).parent('.payment-method-wrapper').addClass('rollover-method');
	});
	
	// mouseout
	$('.payment-method-wrapper h3').mouseout(function(){
		$(this).parent('.payment-method-wrapper').removeClass('rollover-method');
	});
}


/*
========================================
	Show/Hide Job Details
========================================
*/

function toggleJobDetails() {
	
	var occupation = $('#pd_occupation').val();
	
	// Check if selected occupation is in the list of Excluded jobs
	if (
		occupation == ''           ||
		occupation == 'Homemaker'  ||
		occupation == 'Retired'    ||
		occupation == 'Unemployed' ||
		occupation == 'Student'
		) {
		// If the job details are visible, hide them
		$('#job-details').hide();
		$('#work-number-wrapper').hide();
	} else {
		$('#job-details').show();
		$('#pd_jobstatus').focus();
		$('#work-number-wrapper').show();
	}                                   
	                   
	if (occupation == 'Self-Employed') {    	
		$("#business-phone-checkbox").show();
	} else {
	    $("#business-phone-checkbox").hide(); 
	}
	
}


/*
========================================
	show/hide the customer number
========================================
*/

function togglePlanType() {
	if ($("#current_plan_type").val() == 'Pay Monthly') {
		$("#customer-number-field").show();
	} else {
		$("#customer-number-field").hide();
	}
}


/*
============================================
	show/hide the curent network helptext
===========================================
*/

function toggleCurrentNetHelp() {
	if ($("#current_network").val() == '17685') {
		$("#portingoperatorcode-help-text").show();
	} else {
		$("#portingoperatorcode-help-text").hide();
	}
}

/*
========================================
	Shop homepage switchers
========================================
*/

function setupShopSwitchers() {
	
	$(".module-carousel ul>li").removeClass("hidden");
	
	if ($("#paymonthly-phones-carousel").length) { 
		$('#paymonthly-phones-carousel').jcarousel({
			scroll: 1,
			animation: "slow"
		});
	}
	
	if ($("#prepay-phones-carousel").length) { 
		$('#prepay-phones-carousel').jcarousel({
			scroll: 1,
			animation: "slow"
		});
	}
	
	if ($("#accessories-carousel").length) { 
		$('#accessories-carousel').jcarousel({
			scroll: 1,
			animation: "slow"
		});
	}
	

	$(".jcarousel-next").attr("alt", "View next phone").attr("title", "View next phone").mouseover(function(){
		$(this).addClass("jcarousel-next-horizontal-hover");
	}).mouseout(function(){
		$(this).removeClass("jcarousel-next-horizontal-hover");
	});
	
	$(".jcarousel-prev").attr("alt", "View previous phone").attr("title", "View previous phone").mouseover(function(){
		$(this).addClass("jcarousel-prev-horizontal-hover");
	}).mouseout(function(){
		$(this).removeClass("jcarousel-prev-horizontal-hover");
	});
}




function collabFilteringShowing(){
	var h = $("h1").text().replace(/\s+/g, "");
	if ($(".nba-vf-handset").length) {
		var t = 'VF';
	} else if  ($(".nba-handset").length) {
		var t = 'NoVF';
	}
	GAT("/CF/Current-" + h + "/Served-" + t +"/");
	$(".nba-vf-handset a, .nba-handset a").bind("click", function(){
		if ($(this).parent(".nba-vf-handset").length) {
			var ct = 'VF';
		} else if ($(this).parent(".nba-handset").length) {
			var ct = 'intelligent';
		}
		var ch = $(this).children("p").children("strong").text().replace(/\s+/g, "");
		GAT("/CF/Current-" + h +"/Served-" + t +"/Type-" + ct + "/Clicked-" + ch + "/");
		return true;
	});
}


/*
========================================
	Hide top Pefect Choice tariff
========================================
*/
    
function hideTopPCTariff() {
   $(".priceplan-js-tab-pane .priceplan-table .price-plan-info:eq(0)").parent().remove();
	price_plans_removed = false;
	x = 0;
	while ((x < 10) && (price_plans_removed == false)) {	   	
		if ($(".priceplan-js-tab-pane .priceplan-table tr:eq(1) td:first").hasClass("price-plan-info")) {
		   	price_plans_removed = true;
		} else { 
			 $(".priceplan-js-tab-pane .priceplan-table tr:eq(1)").remove(); 
		}
		x++;                            
	}  
}                  


/*
========================================
	Accessory form (23/03/2010)
========================================
*/

function observeAccessoryForm(){ 
	$('#accessories-manufacturer select').bind("change", function(){                   
		var id = $(this).attr('id'); 
		GAT('/virtual/df/accessoryfilter/' + id + '/' + $(this).val()); 
		$.each($('#accessories-manufacturer select'), function(){ 
			if ($(this).attr('id') != id) { 
				$(this).val(''); 
			} 
		}) 
		$('#accessories-manufacturer form').submit();   
	}); 
}

/*
========================================
	Community validation
========================================
*/

function observeCommunityShowHide() {  

	if ($('tr#community-addon').hasClass('selected')) {
		$('.community-numbers').show();
	}
	
	$('#free-extras table.white-table input[type=radio], .paymonthly-addons table input[type=radio]').change(function(){
		if ($(this).parent().parent('tr#community-addon').length) {
			$('.community-numbers').show();
		} else {
			$('.community-numbers').hide();
		}
	});
	
	$('#free-extras table.white-table tr *, .paymonthly-addons table tr *').click(function(){
		if ($('#community-addon').hasClass('selected')) {
			$('.community-numbers').show();
		} else {
			$('.community-numbers').hide();
		}
	});
}      

function observeCommunityNumbers() {
	$('.community-numbers input[type="text"]').blur(function(){
		// validate the number via ajax
		$.ajax({
			type: "GET",
			url: communityvalidation_ajax_call,
			data: "number=" + escape($(this).val()) + "&element=" + this.id,
			success: function(msg) {	
				msg = jQuery.trim(msg);
				id_status_message = msg.split('][');
				id = jQuery.trim(id_status_message[0].substr(1));
				validation_status = jQuery.trim(id_status_message[1]);
				message = jQuery.trim(id_status_message[2].substr(0, (id_status_message[2].length -1)));
				updateCommunityNumberStatus(id, validation_status, message);
			}
		});
	});
}  

function updateCommunityNumberStatus(i, s, m) {
	
	b  = '';
	sr = '';
	
	$('input#' + i).parent().parent().removeClass('failed-test');
	$('input#' + i).parent().parent().children('.message-wrapper').remove();
	if ($(".button-row .button input").length) {
		b = ".button-row .button input";
	} else if ($(".text-right input.rollover").length) {
		b = ".text-right input.rollover";
	}
	
	if ($(b).length) {
		sr = $(b).attr("src");
	}
	
	if (s == 'fail') {
		if ($('#community-numbers-area .info-text').length) {
			$('#community-numbers-area .info-text').hide();
		}
		$('input#' + i).parent().parent().addClass('failed-test').append('<div class="message-wrapper"><div class="message">' + m + '</div></div>');
//		if (sr.substring((sr.length -13), sr.length) != '_disabled.png') {
//			sr_disabled = sr.substring(0, (sr.length - 4)) + '_disabled.png';
//			$(b).attr("src", sr_disabled).css("cursor", "default");
//			$(b).parents('form').submit(function() { return false; });
//		}
	} else {
		if ($('#community-numbers-area .failed-test').length == 0) {
			$('#community-numbers-area .info-text').show();
			if ($('.community-numbers input[type=checkbox]:checked').length >= allowed_community_options) {
				$('#community-numbers-area #max-community-nums-selected').show();
			} else {
				$('#community-numbers-area .info-text').show();
			}
			
  //  		if (sr.substring((sr.length -13), sr.length) == '_disabled.png') {
  //  			sr_disabled = sr.substring(0, (sr.length - 13)) + '.png';
  //  			$(b).attr("src", sr_disabled).css("cursor", "pointer");
  //  		}
  //  		$(b).parents('form').unbind();
			
		}
	}
}
                 

function observeVoucherCodeInput(){
	$('input#voucher_code').bind('blur', trimVoucherCodeInput);
	$('#vouchers form').bind('submit', trimVoucherCodeInput);
}          

function trimVoucherCodeInput() {
	var vc_value = jQuery.trim($('input#voucher_code').val());
	$('input#voucher_code').val(vc_value);
	return true;
}

