// Petals Network Javascript Library


 //////////// ALL PAGES ////////////

	 // Reworks AdminWS Links to add spacer and changes My Account link
		$(document).ready(function($) {
			$('.adminTxt:contains("CART")').after('<span class="adminline">|</span>');
			$('.adminTxt:contains("ACCOUNT")').attr('href','http://www.petalsnetwork.com/club/crm_login.htm');
			$('.adminTxt:contains("ACCOUNT")').attr('target','_blank');
			$('.adminTxt:contains("ACCOUNT")').after('<span class="adminline">|</span>');
			$('.adminTxt:contains("CART")').prepend('<img id="pngcart" src="/skins/806/images/cart.png">');
		});
	
	// Replaces all links to /sitemap.asp with the custom html page /petalssitemap.asp	
		$("a[href*='sitemap']").attr("href","/petalssitemap.asp");
		$(document).ready(function() {
			$("a[href*='sitemap']").attr("href","/petalssitemap.asp");
		});
		
	 // Add class of parent_nav to top nav items with dropdowns
		$(document).ready(function($) {
			$(".top_nav").not(".top_nav:only-child").addClass("parent_nav");
		});
	
	// Changes top nav header items that have dropdown children to default their href to the first link in the dropdown
		$(document).ready(function($) {
			$(".menu li").has(".parent_nav").addClass("parent_box");
			$(".parent_box").each(function () {
				var childlink = $(this).find("ul li a").attr("href");
				$(this).find(".parent_nav").attr("href",childlink);
			});
		});

	 // Adds the classes .searchclicked to the search bar input and .emailclicked to the email bar input when typed in
		$(document).ready(function($) {
			$('#searchtext').keydown(function () {
				$(this).addClass('searchclicked');
			});
			
			$('.emailInput').keydown(function () {
					$(this).addClass('emailclicked');
			});	
			
			$('.nameInput').keydown(function () {
					$(this).addClass('emailclicked');
			});	
		});
		
	 // Adds a span with a class of caps to the first letter of words in Left Nav Header items.
		$(document).ready(function($) {
			$('.leftNavHeader1,.leftNavHeader2').each(function() {
				var $this = $(this);
				var text = $this.html();
					$this.html(text.replace(/\b([A-Za-z0-9])/g,'<span class="caps">$1</span>'));
			});
		});
		
	 // Removes title tags that say Los Angeles and CA
		$(document).ready(function($) {
			$("a[title*='CA']").removeAttr('title');
			$("img[title*='CA']")
				.removeAttr('title')
				.removeAttr('alt');
		});
 //////////////////////////////////////


	
	
 //////////// PRODUCT DETAIL PAGE ////////////
	 // If there is more than one option for a product's price point, default to the second price.
		$(document).ready(function($) {
			if(s.channel=="Product"){
				if ($('.step-content .price	.priceselect input').length>1) {
					$('.step-content .price	.priceselect input:eq(1)').attr('checked','checked');	
				}
			}
		});
 //////////////////////////////////////




 //////////// BASKET PAGE ////////////
//	  Removes the link to My Account on the Basket page	
//	 	Removed for now in favor of css
//		$(document).ready(function($) {
//			if(s.pageName=="Checkout: Shopping Cart"){
//				$('#basketwrapper form #returningcustomer').remove();
//			}
//		});
 //////////////////////////////////////
	
	


 //////////// CHECKOUT ////////////

	// DELIVERY INFO PAGE - Remove prices and replace with graphic
		$(document).ready(function($) {
			if(s.pageName=="Checkout: Delivery"){
				function intlPopUp() {
					var url = "/popups/custom.asp?popupid=8713";
					var width = 500;
					var height = 380;
					var winleft = 0;
					var wintop = 0;
					var winprops = 'height='+height+',width='+width+',top='+wintop+',left='+winleft+',scrollbars=yes';
					var win = window.open(url, 'win', winprops);}
				$('td select[name*="country_1"]').after("<a href='javascript: intlPopUp()' tabindex=-1><u><b>Need delivery outside Australia?</b></a></u>");
				$('input[name*="update_address_book_1"]').parent().remove();
				$('select[name*="locationtype_1"]').bind('mouseenter mouseleave', function() {
				if(locationtype=="APARTMENT"){
					document.getElementById("address1lbl_"+ctr).innerHTML = "* Apt. or Unit No.:";
					document.getElementById("address2lbl_"+ctr).innerHTML = "* Address 1:";
				}
				});
			}
		});
		
	// PAYMENT PAGE - Change wording and make note of required items
		$(document).ready(function($) {
			if(s.pageName=="Checkout: Billing"){
				$('.shopcart-VIEW4').text('Items marked with an asterisk (*) are required.');
				$('#payment_title_phone1 div').text('* Daytime Phone');
				$('#tr8:has("#payment_value_state")').remove();
				$('input[name*="bill_saveCCinfo"]').attr('checked','');
				$('#tr13:has("td #cscSection3")').remove();
			}
		});

 //////////////////////////////////////
