// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
$(document).ready(function()
{
	formatPercent = function(num) {
		return ('% ' + num.toString().replace(/[^0-9]/g,''));
	}
	formatNumber = function(num) {
		return (num.toString().replace(/[^0-9]/g,''));
	}
	formatCurrency = function(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
			num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10)
			cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
			num = num.substring(0,num.length-(4*i+3))+','+
				num.substring(num.length-(4*i+3));
		return (((sign)?'':'-') + '$ ' + num );
	}
	checkHazzards = function()	{
		if ($('#app_has_stunts').is(':checked')
			|| $('#app_has_stunts').is(':checked')
			|| $('#app_has_pyro').is(':checked')
			|| $('#app_has_animals').is(':checked')
			|| $('#app_has_aircraft').is(':checked')
			|| $('#app_has_watercraft').is(':checked')
			|| $('#app_has_rail').is(':checked')
			|| $('#app_has_motorcycles').is(':checked'))
			$('#stunts').show();
		else
			$('#stunts').hide();
	
	}
	isselFilm = function() {
		$('input[name="fastapp[EO]"]')[0].checked = true;
		$('input[name="fastapp[Comm]"]')[0].checked = true;
		$('input[name="fastapp[EV]"]')[0].checked = true;
		checkFastApp();
	}
	isselEO = function() {
		$('input[name="fastapp[Film]"]')[0].checked = true;
		$('input[name="fastapp[Comm]"]')[0].checked = true;
		$('input[name="fastapp[EV]"]')[0].checked = true;
		checkFastApp();
	}
	isselComm = function() {
		$('input[name="fastapp[Film]"]')[0].checked = true;
		$('input[name="fastapp[EO]"]')[0].checked = true;
		$('input[name="fastapp[EV]"]')[0].checked = true;
		checkFastApp();
	}
	isselEV = function() {
		$('input[name="fastapp[Film]"]')[0].checked = true;
		$('input[name="fastapp[EO]"]')[0].checked = true;
		$('input[name="fastapp[Comm]"]')[0].checked = true;
		checkFastApp();
	}
	checkForOther = function() {
		var mysel = $('#app_type_of_production :selected').text();
		if ( mysel == 'Other' )
			$('#other_def').show();
		else
			$('#other_def').hide();
	}
	checkFastApp	= function() {
		
		var filmsel = $('input[name="fastapp[Film]"]:checked').val();
		var eosel = $('input[name="fastapp[EO]"]:checked').val();
		var commsel = $('input[name="fastapp[Comm]"]:checked').val();
		var evsel = $('input[name="fastapp[EV]"]:checked').val();
		if (( filmsel == 'none' && eosel == 'none' && commsel == 'none' && evsel == 'none' ) ||
			  (filmsel == undefined && eosel == undefined && commsel == undefined && evsel == undefined)) {
			$('#fastapp_prod_co').hide();
		}
		else {
			$('#fastapp_prod_co').show();
			if (filmsel == 'Student')
				$('#contact').hide();
			else
				$('#contact').show();
		}
		if ( filmsel != 'none' ) {
			$('#pc').show();
			if (filmsel == 'Feature' || filmsel == 'MOW' || filmsel == 'TVSeries' || filmsel == 'MiniSeries' || filmsel == 'PilotSpec') {
				$('#pcdesc').html("Gross Budget&nbsp;")
				$('#nop').show();
				$('#ppsd').show();
			}
			else {
				$('#pcdesc').html("Annual Gross Prod. Cost&nbsp;")
				$('#nop').hide();
				$('#ppsd').hide();
			}
			if (filmsel == 'Student')
				$('#codesc').html("* Student Name&nbsp;");
			else
				$('#codesc').html("* Production Company&nbsp;");		
		}
		else {
			$('#pc').hide();
			$('#nop').hide();
			$('#ppsd').hide();
		}
		if ( eosel != 'none' ) {
			$('#codesc').html("* Company Name&nbsp;");
			if ($('input[name="fastapp[EO]"]:checked').val() == 'Producer') {
				$('#eoprod').show();
				$('#nop').show();
			}
			else {
				$('#eoprod').hide();
				$('#nop').hide();
			}
			if ($('input[name="fastapp[EO]"]:checked').val() == 'Auth') {
				$('#eoauth').show();
				$('#nop').show();
				$('#titledesc').html("Title&nbsp;");
			}
			else {
				$('#eoauth').hide();
			}
			
		} else {
				$('#eoprod').hide();
				$('#eoauth').hide();				
		}
		if ( evsel != 'none' ) {
			$('#codesc').html("* Company Name&nbsp;");

			if ($('input[name="fastapp[EV]"]:checked').val() == 'Theatrical' ) {
				$('#nop').show();
				$('#titledesc').html("Title&nbsp;");
			}
      if ($('input[name="fastapp[EV]"]:checked').val() == 'Concert' ) {
				$('#nop').show();
				$('#titledesc').html("Group Name&nbsp;");
			}
		}
		if ( commsel != 'none' ) {
			$('#codesc').html("* Company Name&nbsp;");			
		}
		return true;
	}	
	checkHazzards();
  $('input.phonemask').mask("(999) 999-9999",{placeholder:" "});
	checkFastApp();
});

