// JavaScript Document
/* Copyright Novusweb. All rights reserved. No part of this code may be duplicated or used without permission. */

LoadFunctions = function() {

	// Substitute copyright year for current year.
	
	var CopyDate = new Date();
	yy = CopyDate.getYear();
	
	var CopyYear = (yy < 1000) ? yy + 1900 : yy;
	
	$j("#CopyrightYear").replaceWith("<span>" + CopyYear + "</span>");
	
	// Activate jQuery UI buttons
	
	$j('#Locations button.MoreInfo, a.MoreInfo').button({
		
		icons: {
			primary: 'ui-icon-triangle-1-e'
		}
		
	});
	
	$j("a", "#TellAFriend").button( {
														 
	 icons: {
		 primary: 'ui-icon-mail-closed'
	 }
	 
	 });
	
	$j("button", ".comment-list").button({
		
			icons: {
				primary: 'ui-icon-check'
			}
			
		});
	
	// Set various sections to show/hide based on conditions
	
	var ErrorTest = $j('span.error').text();
	
	if(ErrorTest == "") {
		$j('span.error').hide();
	};
	
	var SubmitErrorTest = $j('div#SubmitError').text();
	
	if(SubmitErrorTest != "") {
		$j('div#SubmitError').show();
	};
	
	//	Add corners to BC elements
	
	$j('.comment-container').addClass('ui-corner-all');
	$j('.blog-comment-container').addClass('ui-corner-all');
	$j('table.productPoplets img').addClass('ui-corner-all');
	
	//	Add corners to Slider wrapper
	
	$j('.SliderWrapper *').addClass('ui-corner-all');
	
	$j('input#CAT_Search').focus(function() {
		
		if($j(this).val() == 'Search') {
		
			$j(this).val('');
			$j(this).css('color','#000000');
			
		};
		
	});

	$j('input#CAT_Search').blur(function() {
		
		if($j(this).val() == '') {
		
			$j(this).val('Search');
			$j(this).css('color','#BE9A4A');
			
		};
		
	});
	
}

	$.fn.replaceText = function( search, replace, text_only ) {  
		return this.each(function(){  
			var node = this.firstChild,  
				val,  
				new_val,  
				remove = [];  
			if ( node ) {  
				do {  
					if ( node.nodeType === 3 ) {  
						val = node.nodeValue;  
						new_val = val.replace( search, replace );  
						if ( new_val !== val ) {  
							if ( !text_only && /</.test( new_val ) ) {  
								$j(node).before( new_val );  
								remove.push( node );  
							} else {  
								node.nodeValue = new_val;  
							}  
						}  
					}  
				} while ( node = node.nextSibling );  
			}  
			remove.length && $j(remove).remove();  
		});  
	};  


