// make shit look like buttons

$(document).ready(
	function() {
		$(".blueBox").css( { "position":"relative" } );

		$(".blueBox").hover(
			function() {
			 $(this).css( { "top":"-1px" } );
			},
			function() {
			 $(this).css( { "top":"0px" } );
			}
		);

		$(".blueBox").mousedown(
			function() {
			 $(this).css( { "top":"1px" } );
			}
		);

		$(".blueBox").mouseup(
			function() {
			 $(this).css( { "top":"-1px" } );
			}
		);
	}
);


// show/hide shit

function expandRel( id )
{
	$("#relS" + id ).hide( 200 );
	$("#relE" + id ).show( 400 );
}

function shrinkRel( id )
{
	$("#relE" + id ).hide( 125 );
	$("#relS" + id ).show( 150 );
}

function expandTrk( id )
{
	$("#trkS" + id ).hide( 333 );
	$("#trkE" + id ).show( 500 );
}

function shrinkTrk( id )
{
	$("#trkE" + id ).hide( 150 );
	$("#trkS" + id ).show( 200 );
}


//
// AJAX shit
//

function GetXmlHttpObject()
{
	var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
	return xml;
}

function stateChanged()
{
	if( xmlHttp.readyState == 4 )
	{
		$("#mailBusy").hide(); // first hide the busy icon

		switch( xmlHttp.responseText )
		{
		case "OK":
			$("#mailInput").hide( 200 );
			$("#mailOk").show( 333 );
			setTimeout( function() { $("#mailOk").fadeOut( 3000 ); }, 5000 );
			break
			
		case "DUPLICATE":
			$("#mailButton").show( 400 );
			$("#mailDuplicate").show( 333 );
			setTimeout( function() { $("#mailDuplicate").fadeOut( 3000 ); }, 5000 );
			break
			
		case "INVALID":
			$("#mailButton").show( 333 );
			$("#mailInvalid").show( 333 );
			setTimeout( function() { $("#mailInvalid").fadeOut( 3000 ); }, 5000 );
			break
			
		case "EMPTY":
			$("#mailButton").show( 200 );
			$("#mailEmpty").show( 200 );
			setTimeout( function() { $("#mailEmpty").fadeOut( 3000 ); }, 5000 );
			break
		}
	}
}

function addEmail()
{
	// show the busy animation
	$("#mailBusy").show();
	
	// hide the sign-up button
	$("#mailButton").hide( 100 );
	
	// hide any errors/warnings which may already be there
	$("#mailDuplicate").hide( 100 );
	$("#mailEmpty").hide( 100 );
	$("#mailInvalid").hide( 100 );

	// get the email address from the text input control and format the ajax url
	var url = "addEmail.php?e=" + document.getElementById('mailInput').value;
	
	// start-up the ajax
	xmlHttp = GetXmlHttpObject();
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET", url ,true );
	xmlHttp.send( null );	
}

