var SCHL4oFooter = {
	resources : {
		list1Title : 'School to Home',
		list1 : [
			'<a title="Book Clubs" href="http://clubs.scholastic.com/cool/login.jsp">Book Clubs</a>',
			'<a title="Book Fairs" href="http://www.scholastic.com/bookfairs/teachers/">Book Fairs</a>'
		],
		list2Title : 'Classroom Resources',
		list2 : [
			'<a title="Book Lists" href="http://bookwizard.scholastic.com/tbw/viewBooklistExchangeHomepage.do">Book Lists</a>',
			'<a title="Book Wizard" href="http://www.scholastic.com/bookwizard">Book Wizard</a>',
			'<a title="Instructor Magazine" href="http://teacher.scholastic.com/products/instructor/index.htm">Instructor Magazine</a>',
			'<a title="Lesson Plans" href="http://www.scholastic.com/teachers/lesson-plans/free-lesson-plans">Lesson Plans</a>',
			'<a title="New Books" href="http://teacher.scholastic.com/products/tradebooks/">New Books</a>',
			'<a title="New Teachers" href="http://www.scholastic.com/teachers/teaching-strategies/new-teacher">New Teachers</a>',
			'<a title="Scholastic News Online" href="http://teacher.scholastic.com/activities/scholasticnews/index.html">Scholastic News Online</a>',
			'<a title="Kids Press Corps" href="http://teacher.scholastic.com/scholasticnews/press_corps/index.asp">Kids Press Corps</a>',
			'<a title="Strategies and Ideas" href="http://www.scholastic.com/teachers/teaching-strategies">Strategies and Ideas</a>',
			'<a title="Student Activities" href="http://www.scholastic.com/teachers/student-activities">Student Activities</a>',
			'<a title="Daily Teacher Blogs" href="http://www.scholastic.com/teachers/teaching-ideas">Daily Teacher Blogs</a>',
			'<a title="Videos" href="http://www2.scholastic.com/browse/video.jsp">Videos</a>',
			'<a title="Whiteboard Resources" href="http://teacher.scholastic.com/whiteboards/languagearts.htm">Whiteboard Resources</a>'
		]
	},
	products : {
		list1Title : 'Products &amp; Services',
		list1 : [
			'<a title="Author Visit Program" href="http://teacher.scholastic.com/products/tradebooks/inviteanauthor.htm">Author Visit Program</a>',
			'<a title="Classroom Books" href="http://teacher.scholastic.com/products/classroombooks/index.asp">Classroom Books</a>',
			'<a title="Classroom Magazines" href="http://teacher.scholastic.com/products/classmags.asp">Classroom Magazines</a>',
			'<a title="Find a Sales Representative" href="http://teacher.scholastic.com/products/ae.asp">Find a Sales Representative</a>',
			'<a title="Free Programs and Giveaways" href="http://www.scholastic.com/freeprograms/">Free Programs and Giveaways</a>',
			'<a title="Guided Reading" href="http://teacher.scholastic.com/products/guidedreading/">Guided Reading</a>',
			'<a title="Math Intervention" href="http://teacher.scholastic.com/products/scholastic_math_intervention/">Math Intervention</a>',
			'<a title="Product Information" href="http://teacher.scholastic.com/products/product_info">Product Information</a>',
			'<a title="Read 180" href="http://teacher.scholastic.com/products/read180/">Read 180</a>',
			'<a title="Reading is Fundamental" href="http://rif.scholastic.com/">Reading is Fundamental</a>',
			'<a title="Request a Catalog" href="http://teacher.scholastic.com/products/product_info/contact_us.asp">Request a Catalog</a>',
			'<a title="Scholastic Professional" href="http://teacher.scholastic.com/products/scholasticprofessional/">Scholastic Professional</a>',
			'<a title="Tom Snyder Productions" href="http://www.tomsnyder.com/">Tom Snyder Productions</a>'
		]
	},
	shopping : {
		list1Title : 'Online Shopping',
		list1 : [
			'<a title="List Builder" href="http://listbuilder.scholastic.com">List Builder</a>',
			'<a title="Printables" href="http://www.scholastic.com/premium/">Printables</a>',
			'<a title="Teacher Express" href="http://teacherexpress.scholastic.com/">Teacher Express</a>',
			'<a title="Teacher Store" href="http://shop.scholastic.com/webapp/wcs/stores/servlet/StoreCatalogDisplay?URL=StoreCatalogDisplay&storeId=10001&store=TS&jspStoreDir=TeacherStore&src=BTB000000N0010100000&langId=-1&catalogId=10002">Teacher Store</a>'
		]
	},
	organizer : {
		list1Title : 'My Organizer',
		list1 : [
			'<li class="footer-personalize">Personalize Content</li>',
			'<li class="footer-save">Save &amp; Share With Others</li>',
			'<li class="footer-booklists">Customize Booklists</li>',
			'<li class="footer-calendar">Manage Your Calendar</li>'
		]
	}
};

var strSCHL4oFooter = '<div id="footer-wrapper-4o">';
if ( jQuery('body').hasClass('schlTeachers4o') ) {
	strSCHL4oFooter += '<div id="footer-teacher" class="schl-group">';
	strSCHL4oFooter += '<div class="footer4o-links" id="footer-resources">';
	strSCHL4oFooter += '<a href="http://www.scholastic.com/home/" class="footer-teacher-logo">Scholastic</a>';
	strSCHL4oFooter += '<h2>' + SCHL4oFooter.resources.list1Title + '</h2>';
	strSCHL4oFooter += '<ul class="first-list"><li>' + SCHL4oFooter.resources.list1.join('</li><li>') + '</li></ul>';
	strSCHL4oFooter += '<h2>' + SCHL4oFooter.resources.list2Title + '</h2>';;
	strSCHL4oFooter += '<ul><li>' + SCHL4oFooter.resources.list2.join('</li><li>') + '</li></ul>';
	strSCHL4oFooter += '</div>';
	strSCHL4oFooter += '<div class="footer4o-links" id="footer-products">';
	strSCHL4oFooter += '<h2>' + SCHL4oFooter.products.list1Title + '</h2>';
	strSCHL4oFooter += '<ul><li>' + SCHL4oFooter.products.list1.join('</li><li>') + '</li></ul>';
	strSCHL4oFooter += '</div>';
	strSCHL4oFooter += '<div class="footer4o-links" id="footer-col3">';
	strSCHL4oFooter += '<div id="footer-shopping">';
	strSCHL4oFooter += '<h2>' + SCHL4oFooter.shopping.list1Title + '</h2>';
	strSCHL4oFooter += '<ul class="first-list"><li>' + SCHL4oFooter.shopping.list1.join('</li><li>') + '</li></ul>';
	strSCHL4oFooter += '</div>';
	strSCHL4oFooter += '<div id="footer-sharefeedback"><a href="#"><img alt="share feedback" src="' + DOTCOM_HOST + '/global_resources/universal/layout/images/sharefeedback_icon.png" border="0" /></a></div>';
	strSCHL4oFooter += '</div>';
	strSCHL4oFooter += '<div class="footer4o-links" id="footer-col4">';
	strSCHL4oFooter += '<div id="footer-newsletter">';
	strSCHL4oFooter += '<h2>Email Newsletter</h2>';
	strSCHL4oFooter += '<form action="http://www.scholastic.com/browse/PrefCenterServlet" method="post" id="frmFooterNewsletter" name="frmFooterNewsletter" onsubmit="return frmChckNewsletter(this);">';
	strSCHL4oFooter += '<p>Get updates, savings, and more</p><input type="hidden" value="" name="successURL" class="footer-newsletter-success"><input type="hidden" value="" name="failureURL" class="footer-newsletter-failure"><input type="hidden" value="" name="cancelURL"><input type="hidden" value="" name="appid"><input type="hidden" value="TNL" name="AppType"><input type="hidden" value="" name="finalSuccessURL"><input type="hidden" value="" name="redirectURL"><input type="hidden" value="on" name="AGREE_TO_TERMS"><div id="newsletter-errors"></div><p><input type="text" class="footer-frmTxt" size="20" value="Enter Email Address" name="EMAIL_KEY"></p><p><select class="footer-frmSelect" name="PAGE_CODES"><option value="Select Grade">Select Grade</option><option value="PKK">PreK-K</option><option value="12">1-2</option><option value="35">3-5</option><option value="68">6-8</option><option value="912">9-12</option></select></p><p class="footer-btn"><input type="image" src="' + DOTCOM_HOST + '/global_resources/universal/layout/images/footer-btnSignUp.gif" alt="Sign Up" border="0" /> <a href="http://teacher.scholastic.com/newsletter/signup.htm" class="footer-sample">See a sample &gt;</a></p>';
	strSCHL4oFooter += '</form>';
	strSCHL4oFooter += '</div></div>';
	//strSCHL4oFooter += '<div class="footer4o-links" id="footer-myOrganizer">';
	//strSCHL4oFooter += '<h2>' + SCHL4oFooter.organizer.list1Title + '</h2>';
	//strSCHL4oFooter += '<p>Register and sign in to get all kinds of extras like:</p>';
	//strSCHL4oFooter += '<ol>' + SCHL4oFooter.organizer.list1.join('') + '</ol>';
	//strSCHL4oFooter += '<p class="footer-btn"><a href="#"><img src="/global_resources/universal/layout/images/footer-btnRegisterSignIn.gif" alt="Register or Sign In" border="0" /></a></p>';
	//strSCHL4oFooter += '</div>';	
	strSCHL4oFooter += '</div>';
}
strSCHL4oFooter += '<div id="footer-corporate" class="schl-group"><div class="footer4o-links" id="footer-about"><h2>About Scholastic</h2><ul><li><a title="" href="http://www.scholastic.com/aboutscholastic/index.htm">Who We Are</a></li><li><a title="" href="http://www.scholastic.com/aboutscholastic/corporateresponsibility.htm">Corporate Responsibility</a></li><li><a title="" href="http://mediaroom.scholastic.com/">Media Room</a></li><li><a title="" href="http://investor.scholastic.com/">Investor Relations</a></li><li><a title="" href="http://www.scholastic.com/aboutscholastic/international/">International</a></li><li><a title="" href="http://www.scholastic.com/aboutscholastic/espanol/">Scholastic en Espa&ntilde;ol</a></li><li><a title="" href="http://www.scholastic.com/aboutscholastic/jobs.htm">Careers</a></li></ul></div><div class="footer4o-links" id="footer-website"><h2>Our Website</h2><ul><li><a title="" href="http://www.scholastic.com/teachers/">Teachers</a></li><li><a title="" href="http://www.scholastic.com/parents/">Parents</a></li><li><a title="" href="http://www.scholastic.com/kids/stacks/">The Stacks (Ages 8-12)</a></li><li><a title="" href="http://www.scholastic.com/parents/play/">Family Playground (Ages 3-7)</a></li><li><a title="" href="http://www.scholastic.com/librarians/">Librarians</a></li><li><a title="" href="http://www.scholastic.com/administrator/">Administrators</a></li><li><a title="" href="http://teacher.scholastic.com/products/product_info/">Product Information</a></li></ul></div><div class="footer4o-links" id="footer-help"><h2>Need Help?</h2><ul><li><a title="" href="http://www.scholastic.com/custsupport/">Customer Service</a></li><li><a title="" href="http://www.scholastic.com/custsupport/contact_us.htm">Contact Us</a></li></ul></div>';
if ( (typeof schlKids != 'undefined' && schlKids) || jQuery('#schlStacksHeader').length || jQuery('#schlStacksSlimHeader').length || readCookie('header') == 'bigKids' ) {}
else {
	strSCHL4oFooter += '<div id="footer-social" class="footer4o-links"><div id="footer-join-us-online"> <h2>Join Us Online</h2><ol><li><a href="http://twitter.com/Scholastic" target="_blank"><img src="http://www.scholastic.com/global_resources/universal/layout/images/icon-twitter.gif" border="0" alt="twitter" /></a></li><li><a href="http://www.facebook.com/Scholastic" target="_blank"><img src="http://www.scholastic.com/global_resources/universal/layout/images/icon_facebook.gif" border="0" alt="facebook" /></a></li><li><a href="http://onourmindsatscholastic.blogspot.com/" target="_blank"><img src="http://www.scholastic.com/global_resources/universal/layout/images/icon-rss.gif" border="0" alt="rss" /></a></li><li><a href="http://www.youtube.com/TheScholasticChannel" target="_blank"><img src="http://www.scholastic.com/global_resources/universal/layout/images/icon-youtube.gif" border="0" alt="youtube" /></a></li></ol></div></div>';
}
strSCHL4oFooter += '</div><!-- end of #footer-corporate --><div id="footer-global"> <a href="http://www.scholastic.com/privacy.htm" class="footer-global-pp">PRIVACY POLICY</a> &middot; <a href="http://www.scholastic.com/terms.htm">Terms of Use</a> &middot; TM &reg; &amp; &copy; ' + new Date().getFullYear() + ' Scholastic Inc. All Rights Reserved.</div></div>';
document.writeln(strSCHL4oFooter);

(function($) {
  $.QueryString = (function(a) {
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i)
    {
      var p=a[i].split('=');
      if (p.length != 2) continue;
      b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
  })(window.location.search.substr(1).split('&'))
})(jQuery);

jQuery(function(){
	if ( jQuery('body').hasClass('schlTeachers4o') ) {
		var newsletterField = jQuery(".footer-frmTxt"), newsletterText = newsletterField[0].defaultValue, finalURL,
		clearNewsletterValue = function(){
		    if (newsletterField.val() === newsletterText) {
		      newsletterField.val("");
		    }
	  	};
		newsletterField.bind("focus", function(){
			clearNewsletterValue();
		});
		
		newsletterField.bind("blur", function(){
			if (newsletterField.val().length === 0) {
			  newsletterField.val(newsletterText);
			}
		});
		var finalURL;
		if ( window.location.search == '?module=y&subscribeSuccess=true&' ) {
			finalURL = window.location.href.split('?')[0];
		}
        else if ( location.href.indexOf('?module') != -1 && location.href.indexOf('errors') ) {
            finalURL = window.location.href.split('?')[0];
        }
		else if ( location.href.indexOf('errors') != -1 ) {
			finalURL = window.location.href.substring(0, window.location.href.indexOf('errors') - 1);
		}
		else {
			finalURL = window.location.href;
		}

		jQuery('.footer-newsletter-success, .footer-newsletter-failure').val(finalURL);
		
		if ( typeof jQuery.QueryString['errors'] != 'undefined' && jQuery.QueryString['errors'] != '' && typeof jQuery.QueryString['module'] == 'undefined' ) {
			jQuery('#newsletter-errors').addClass('newsletter-error').html(jQuery.QueryString['errors'].split('|').join('<br />'));
			jQuery(function(){
				jQuery(document).scrollTop(jQuery('#footer-newsletter').offset().top);
			});
		}
		
		if ( typeof jQuery.QueryString['subscribeSuccess'] != 'undefined' && jQuery.QueryString['subscribeSuccess'] == 'true' && typeof jQuery.QueryString['module'] == 'undefined' ) {
			jQuery('#frmFooterNewsletter').replaceWith('<p><strong>Thank you!</strong> We\'ve processed your information and you will receive your first issue of the Teacher Update Newsletter shortly.</p>');
			jQuery(function(){
				jQuery(document).scrollTop(jQuery('#footer-newsletter').offset().top);
			});
		}	
		
		
		// share feedback
		jQuery('#footer-sharefeedback a').click(function(e){
			e.preventDefault();
			showSchlOverlay();
			showShareFeedback();
		});		
		
		
		if ( location.hash == '#feedbackSuccess') {
			showSchlOverlay();
			showShareFeedbackSuccess();			
		}
	}	
	
});

function frmChckNewsletter(frm) {
	var flag = true, msg = '';
	if ( frm.EMAIL_KEY.value == '' || !validateEmail(frm.EMAIL_KEY.value) ) {
		flag = false;
		msg += 'The e-mail information you entered is not in the proper format for an e-mail address. Please update your information using the following format: Name@companyname.com<br />';
	}
	if ( frm.PAGE_CODES.value == 'Select Grade' ) {
		flag = false;
		msg += 'You must select at least one grade.';
	}
	
	if ( flag ) return true;
	else {
		jQuery('#newsletter-errors').addClass('newsletter-error').html(msg);
		return false;
	} 
}

function validateEmail(email) { 
 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
 return email.match(re) 
}

function showShareFeedback() {
	if ( !jQuery('#site-feedback').length ) {
		jQuery('body').append('<div id="site-feedback"></div>');
	}
	var refURL = location.href.split('#')[0],
		content = '<a href="#" id="feedback-close">Close</a><div class="sf-hdr"><h3>Teacher Site Feedback</h3></div><div class="sf-content"><p class="blurb">Your feedback is very important to us!<br />Please let us know what you think about our new Teacher site.</p><form action="' +  DOTCOM_HOST + '/scripts/share_feedback.asp" method="post" id="t-share-feedback"><input type="hidden" name="refURL" value="' + refURL + '" /><label for="feedback-email"><span>*</span> Email</label><input type="text" value="Enter your email address" id="feedback-email" name="feedback-email" /><label for="feedback-about"><span>*</span> My feedback is about</label><select id="feedback-about" name="feedback-about"><option value="">choose one...</option><option value="Design">Design</option><option value="Technical">Technical</option><option value="Accessibility">Accessibility</option><option value="Registration / Login / Account">Registration / Login / Account</option><option value="Search">Search</option><option value="Products / Purchases">Products / Purchases</option><option value="Other">Other</option></select><label for="feedback-message"><span>*</span> Your Message</label><textarea id="feedback-message" name="feedback-message" rows="7"></textarea><p><a href="#" id="feedback-submit"><img src="' + DOTCOM_HOST + '/global_resources/universal/layout/images/btn-submit-feedback.gif" alt="Submit Feedback" border="0" align="middle" /></a> or <a href="#" id="feedback-cancel">Cancel</a></p><p>Click here for <a href="http://www.scholastic.com/custsupport" target="_blank">customer service</a> issues.</p></form></div>';
	jQuery('#site-feedback').html(content).center().show();
	jQuery('#feedback-close, #feedback-cancel').click(function(e){
		e.preventDefault();		
		jQuery('#site-feedback').hide();
		hideSchlOverlay();
		jQuery('#t-share-feedback')[0].reset();
	});	
	jQuery('#feedback-submit').click(function(e){
		e.preventDefault();
		jQuery('#t-share-feedback .error').remove();
		var errors = false, emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if ( jQuery('#feedback-email').val() == '' ) {
			jQuery('#feedback-email').prev('label').append('<span class="error">Please enter a valid email address using the following format: Name@companyname.com</span>');
			errors = true;
		}
		else if ( !emailReg.test(jQuery('#feedback-email').val()) ) {
			jQuery('#feedback-email').prev('label').append('<span class="error">Please enter a valid email address using the following format: Name@companyname.com</span>');
			errors = true;
		}
		if ( jQuery('#feedback-about').val() == '' ) {
			jQuery('#feedback-about').prev('label').append('<span class="error">Please select a category.</span>');
			errors = true;
		}
		if ( jQuery('#feedback-message').val() == '' ) {
			jQuery('#feedback-message').prev('label').append('<span class="error">Please enter your comments.</span>');
			errors = true;
		}
		
		if ( !errors ) {
			jQuery('#t-share-feedback').submit();
		}
		
	});
	clearValue = function () {
		if (searchField.val() === originalText) {
		  searchField.val("");
		}
	};

	var searchField = jQuery("#feedback-email"), originalText = searchField[0].defaultValue;

	  searchField.bind("focus", function () {
		clearValue();
	  });
	
	  searchField.bind("blur", function () {
		if (searchField.val().length === 0) {
		  searchField.val(originalText);
		}
	  });
}
function showShareFeedbackSuccess() {
	if ( !jQuery('#site-feedback').length ) {
		jQuery('body').append('<div id="site-feedback"></div>');
	}
	var content = '<a href="#" id="feedback-close">Close</a><div class="sf-hdr"><h3>Teacher Site Feedback</h3></div><div class="sf-content2"><p class="thanks">Thank you for your comments! Your feedback has been submitted.</p><p class="btn"><a href="#" id="feedback-close2"><img src="' + DOTCOM_HOST + '/global_resources/universal/layout/images/btnClose.gif" alt="Close" border="0" /></a><p>Click here for <a href="http://www.scholastic.com/custsupport" target="_blank">customer service</a> issues.</p></div>';
	jQuery('#site-feedback').html(content).center().show();
	jQuery('#feedback-close, #feedback-close2').click(function(e){
		e.preventDefault();		
		jQuery('#site-feedback').hide();
		hideSchlOverlay();
		jQuery('<a href="#"></a>').click(function(e){e.preventDefault();window.location.hash=this.hash;}).click().remove();
	});
}

