jQuery(function($) {
	
	// near you form
	$('#step2').hide();
	$('#ctl00_cphHomepage_FilterMenu1_btn_Next').click(function() {
		$('#step1').hide();
		$('#step2').show();
	});
	
	$('#back-to-step1').click(function() {
		$('#step1').show();
		$('#step2').hide();
	});	
	
	// events near you form
	$('#advanced').hide();  
	$('#ctl00_cphGeneric_rtsSearch_rtsBasic').addClass("selected");
	
	$('#ctl00_cphGeneric_rtsSearch_rtsBasic').click(function() {
		$('#basic').show(); 
		$(this).addClass("selected");
		$('#advanced').hide();
		$('#ctl00_cphGeneric_rtsSearch_rtsAdvanced').removeClass("selected"); 
    });

	$('#ctl00_cphGeneric_rtsSearch_rtsAdvanced').click(function() {
		$('#basic').hide();
		$('#ctl00_cphGeneric_rtsSearch_rtsBasic').removeClass("selected"); 
		$('#advanced').show();
		$(this).addClass("selected");    
    });

	$('#ctl00_cphGeneric_lnk_Advanced').click(function() {
		$('#basic').hide();
		$('#ctl00_cphGeneric_rtsSearch_rtsBasic').removeClass("selected"); 
		$('#advanced').show();
		$('#ctl00_cphGeneric_rtsSearch_rtsAdvanced').addClass("selected");
    });
	
	// add a class of “external” to all external links (those beginning with http://), then add target=“_blank” for good measure. 
	//$('a[@href^="http://"]').addClass('external').attr('target', '_blank');
	
	// add counter to textarea
   	$('#comment').keyup(function(){
		limitChars('comment', 500, 'characters');
   	})
    
	// remove dash from last nav item
	$('#navlist li:first').addClass('first');  
	$('#navlist li:last').addClass('last');
	
	
	// add class='text' to input type='text'
	text = jQuery('input')
	text.each(function() {
		if(jQuery(this).attr('type')=="text")jQuery(this).attr("class", "text");
		if(jQuery(this).attr('value') != "")jQuery(this).addClass("value");
	});
	
	// add class='text' to input type='submit'
	password = jQuery('input')
	password.each(function() {
	   if(jQuery(this).attr('type')=="password")jQuery(this).attr("class", "text");
	});

	// add class='text' to input type='submit'
	image = jQuery('input')
	image.each(function() {
	   if(jQuery(this).attr('type')=="image")jQuery(this).attr("class", "image");
	});
	
	// add class='radio' to input type='radio'
	radio = jQuery('input')
	radio.each(function() {
		if(jQuery(this).attr('type')=="radio")jQuery(this).attr("class", "radio");
	});
	
	// add class='checkbox' to input type='checkbox'
	checkbox = jQuery('input')
	checkbox.each(function() {
		if(jQuery(this).attr('type')=="checkbox")jQuery(this).attr("class", "checkbox");
	});
	
	// add title content to required spans
	required = jQuery('.required')
	required.each(function() {
		(jQuery(this).attr("title", "This field is required")); 
	});
	
});

function limitChars(textid, limit, infodiv) {

 	var text = $('#'+textid).val(); 
    var textlength = text.length;

	if(textlength > limit) {
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));      
		return false;
	} else {
    	$('#' + infodiv).html((limit - textlength) +' characters remaining.');
    	return true;
    }                                                                                                    
}




