$(document).ready(function() {
/*	$('body:not(#issues)').overlay({
		content		: '/overlay.php',
		classname	: 'myoverlay',
		events		: function() {
			pageTracker._trackEvent('Overlay', 'open');
			var mo = $('body').data('overlay');
			$('.social a', mo.$content).click(function() {
				mo.close();
				if($(this).is('#email')) {
					addthis_open(this, 'email');
					return false;	
				}
			});
		}
	});	  */ 
						   
	$('form.validate').submit(function(e) {
		var valid = true, val,
			reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,
			$errormsg = $('<div id="resultbox" />'), box = false;
		
		if($(this).hasClass('box'))
			box = true; 

		$('.requiredmsg, .invalidformat', this).hide();
				
		$('.form-error').removeClass('form-error').removeAttr('style')
		.live('focus', function() { $(this).css('background-color', '#FFFFCC');	})
		.live('blur', function() { 
			if($(this).val() == '')
				$(this).css('background-color', '#FF9F9F'); 
		});
		
		$('.required').each(function() {
			if($(this).is(':input')) {
				val = $.trim($(this).val());
				if(val == '') {
					valid = false;
					$(this).addClass('form-error');
					if(box) 
						$errormsg.append($(this).siblings('.requiredmsg').html());
					else
						$(this).siblings('.requiredmsg').show();
						
				} else if( ($(this).hasClass('email') && reg.test(val) == false) || ($(this).hasClass('zip') && (isNaN(val) || val < 5)) ) {
					valid = false;
					$(this).addClass('form-error')
					if(box)
						$errormsg.append($(this).siblings('.invalidformat').html());
					else
						$(this).siblings('.invalidformat').show();
				}
			}			 
		});
		if(!valid) {
			if(box) {
				$('#resultbox').remove();
				$('#speakup').css('background-image', "url('images/bg_speakup-error.gif')");
				$('#errorintro').show().after($errormsg);
				$errormsg.show();
			}
			e.preventDefault();
		}
	});
});

function trackEmbed(el, size) {
	el.select();
	pageTracker._trackEvent("widget", "select", size);
}

function navhighlight(){
	//get url
	var sPath = window.location.pathname;
	//get pageid
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	sPage = sPage.replace(".php", "");
	//bold current page link
	document.getElementById(sPage).style.fontWeight = '700';
}


