$(function() {
	$('.nonjavascriptpollsubmit').hide();
	$('.javascriptpollsubmit').show();
	innitLogin();
}
);

$(document).ready(function(){
	//$('#debugcontainer').empty().append("<pre></pre>");
	//$('#debugcontainer pre').append("jQuery ready\n");
	$("#inpPercentageRevenueFromServices").bind('focus',function(){
		var servicesValue = $(this).attr('value');
		
		var productsValue = $('#inpPercentageRevenueFromProducts').attr('value');
		//$('#debugcontainer pre').append("focus gained\n");	
		if(servicesValue == 0){
			//$('#debugcontainer pre').append("servicesValue is zero\n");
			if(productsValue > 0){
				var newValue = 100 - productsValue;
				//$('#debugcontainer pre').append("productsValue is not zero\n");
				//$('#debugcontainer pre').append("newvalue: " + newValue + "\n");
				$(this).attr('value',newValue);
			}
		}
	});
});

$(document).ready(function(){
	$('#channelprev').click(function(){
		$('#go_previous').val('prev');
	});
	
	
	// Strip single spaces from forms
	$('textarea').each( function() {
		if (' '==$(this).text())
		$(this).text('');
	});
});

function getID(strID)
{
	return strID.replace(/[^0-9]/gi, '');
}

// sets up the login form so that the labels appear on top of the inputs 
// (keeps it accessible)
function innitLogin()
{
	if ($('#login'))
	{
		
		// on focus on an input, remove the label
		$('#login .inputline input').focus(function()
			{
				$("#login .inputline label[@for='"+$(this).attr('id')+"']").hide();
			}
		).blur(function()
			{
				// on blur, if there is no value in the input, replace the label
				if (jQuery.trim($(this).val()) == '')
				{
					$("#login .inputline label[@for='"+$(this).attr('id')+"']").show();
				}
			}
		).change(function(){
					// on blur, if there is no value in the input, replace the label
				if (jQuery.trim($(this).val()) == '')
				{
					$("#login .inputline label[@for='"+$(this).attr('id')+"']").show();
				}
		});
	}
}

function hideLabels(){

	$('#login .inputline label').addClass('ontop').click(function()
			{
				// when clicked, find the input element, and focus it
				$('#'+$(this).attr('for')).focus();
				// now hide the label
				$(this).hide();
			}
		).each(function()
			{
				// if the input has a value to start with, hide the lable
				if (jQuery.trim($('#'+$(this).attr('for')).val()) != '')
				{
					$(this).hide();
				}
			}
		);
}

