$(function () {
	
	$('html').removeClass('no-js');
	$('html').addClass('js');

    $('a[rel="external"],a[href^="http"]:not([href*="' + window.location.host + '"]),a[href$=".pdf"]').each(function (index) {
        
        $(this).attr({ title: $(this).attr("title") + " (Opens in a new window)" });
        $(this).click(function () {
        	
        	if($(this).parent().parent().attr('id')!='pf-friend' && !$(this).hasClass('addthis_button_email') && !$(this).hasClass('addthis_button_facebook') && !$(this).hasClass('addthis_button_linkedin')){
            window.open($(this).attr('href')); // ... open new window
            return false; // disable default browser functionality so link doesn't open twice
            }                          
        });
    });
    
    $("#faqs .faq").each(		
		function(){		

			
			$(this).find('.faq-full').hide();
			var defaultText = $(this).find('.faq-toggle a').text();
			$(this).find('.faq-toggle a').toggle(function() {
			  $(this).parent().parent().find('.faq-full').slideDown(500);
			  $(this).parent().parent().addClass('less');
			  $(this).text('Close');
			}, function() {
			  $(this).parent().parent().find('.faq-full').slideUp(500);
			  $(this).parent().parent().removeClass('less');
			  $(this).text(defaultText);
			});
			}
		);
	
	
	$('#content-left li').wrapInner('<span/>');
	
	$('input').each(function() {
    var default_value = this.value;
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            this.value = default_value;
        }
    });
});
	
});  

    function required(objField){
	    if(objField.value=='' || objField.defaultValue=='' ) {
		    objField.focus();
		    objField.style['borderColor']='#ff0000';
		    return true
	    } else {
		    objField.style['borderColor']='#666666';
		    return false
	    }
    }



    function validate(){

      var objForm = document.emailsignup;
      var e=1;

      if (required(objForm.fname)){e=0}
      if (required(objForm.sname)){e=0}
      if (required(objForm.emaila)){e=0}

      if (e==0) {
        alert('Alert:\n\nPlease complete all marked fields.\n\n');
        return false;
      } 

     else {

	    if (document.emailsignup.emaila.value.indexOf ('@',0) == -1 || document.emailsignup.emaila.value.indexOf ('.',0) == -1){
	        alert("Your email address does not appear to be valid, please try again.")
	        document.emailsignup.emaila.select();
	        document.emailsignup.emaila.focus();
	        return false;
	    } else {
            
			/* get some values from elements on the page: */
			var $form = $("#emailsignup"),
			tval = $form.find('#title').val(),
			fval = $form.find('#fname').val(),
			sval = $form.find('#sname').val(),
			eval = $form.find('#emaila').val(),
			url = $form.attr( 'action' );

			/* Send the data using post and put the results in a div */
			$.post( url, { title: tval, fname: fval, sname: sval, emaila: eval },
			function( data ) {
			
			$( "#updates" ).empty().append( "<h2>Signup processed</h2><p>Thank you, your signup request has been sent.</p>" );
			}
			);
			
			return false;
        }

      }

    }






