﻿$(document).ready( function()
{
	var s0 = $('#selectnum').get(0)
	var s1 = $('#selectsection').get(0)

	$('table.list tbody tr').mouseover( function()
	{
		$(this).css('background-color','rgb(255,205,10)')
	})
	$('table.list tbody tr').mouseout( function()
	{
		$(this).css( 'background-color','#ddf')
	})
	$('#selectnum').change( function()
	{
		s1.options[ s1.length - 1 ].selected = 'selected'
		if( s0.options[ s0.selectedIndex ].value == 'all' )
		{
			$('table.list tbody tr').show()
		} else
		{
			$('table.list tbody tr').hide()
			$('table.list tbody tr:lt(' + s0.options[ s0.selectedIndex ].value + ')').show()
		}
	})
	$('#high').click( function()
	{
		$('#broadcast').get(0).src = 'http://viewer.dacast.com/b/5455/c/7009'
	})
	$('#regular').click( function()
	{
		$('#broadcast').get(0).src = 'http://viewer.dacast.com/b/5455/c/7008'
	})
	$('#selectsection').change( function()
	{
		s0.options[ s0.length - 1 ].selected = 'selected'
		if( s1.options[ s1.selectedIndex ].value == 'all' )
		{
			$('table.list tbody tr').show()
		} else
		{
			$('table.list tbody tr').hide()
			$('tr.' + s1.options[ s1.selectedIndex ].value ).show()
		}
	})
	$('#sendemail').click( function()
	{
		var email = $( '#email' ).get(0).value
		$( '#sendemail' ).hide()
		$( '#l0' ).show()
		if( !/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test( email ))
		{
			$( '#l0' ).hide()
			$( '#sendemail' ).show()
			alert( $( '#eb01' ).get(0).value )
			return
		}
		$.get( 'register.php', 'a='+email, function( response, status )
		{
			if( status == 'success' )
			{
				alert( $( '#eb02' ).get(0).value )
				window.location.assign('.')
			} else
			{
				$( '#l0' ).hide()
				$( '#sendemail' ).show()
				alert( 'unexpected problem' )
			}
		})
	})
	$('#sendmessage').click( function()
	{
		var message = $( '#message' ).get(0).value
		if( !message )
		{
			return
		}
		$( '#sendmessage' ).hide()
		$( '#l0' ).show()
		$.post( 'contact.php', 'a='+ encodeURI( message ), function( response, status )
		{
			if( status == 'success' )
			{
				alert( $( '#eb02' ).get(0).value )
				window.location.assign('.')
			} else
			{
				$( '#l0' ).hide()
				$( '#sendmessage' ).show()
				alert( 'unexpected problem' )
			}
		})
	})
	$('table.list tbody tr').hide()
	$('table.list tbody tr:lt(5)').show()
	$('#l0').hide()
	$('table.list tbody tr:lt(1)').css( 'font-weight', 'bold' )
	$( '#broadcast' ).get(0).src = 'http://viewer.dacast.com/b/5455/c/7008'
});

