var commentMaxLength = 125;

Event.observe(document, 'dom:loaded', function(e) {

	if ($('form1')) {
		
		ocv = new OCValidator('form1', 'validate', 'required', 'optional');
	}
	

	$$('#txtComment1', '#txtComment2', '#txtComment3').each(function(x) {
	
		
		
		x.observe('keyup', function(e) {
			
			commentLength = $F(x).length;
			
			if ( commentLength >= commentMaxLength ) {
				
				x.value = x.value.substring(0, 125);
				
				commentLength = $F(x).length;
			}
			
			
			x.next('span').innerHTML = (commentMaxLength - commentLength)+' characters remaining for response.';
									
		});
																	 
	});


	if ( $$('.send-friends')[0] ) {
		
		certificatesRemaining($('gr').innerHTML)
		
	}
	
	$$('.popitup').each(function(x) {
		
		x.observe('click', function(e) {
			Event.stop(e);
			popUp(Event.element(e));									
									});
		
	});
	
});


function getEmail() {
	return $('userEmail').innerHTML;	
}

function certificatesRemaining(certificates) {
	

	emailBoxes = $$('.email-box');
	
	//Cheapest way possible, I know.
	

	if (certificates == 2) {
		emailBoxes[2].hide();
	}
	else if (certificates == 1) {
		emailBoxes[2].hide();
		emailBoxes[1].hide();
	}
	else if (certificates == 0) {
		$$('.send-friends')[0].hide();
		$('none-remaining').show();
		
	}
	
}

function popUp(x) {
	
	window.open(x.href,"FeedItForward",
"menubar=no,toolbar=no, scrollbars=yes, width=1010");	
	
}
