/* ********************************
Show/hide functionalities by jQuery
**********************************/
$(document).ready(function() // wait for the DOM to be loaded
{
	$("pre.expand").each(function() // for each <pre> of class "expand"
	{
		var text = $(this).attr("name"); // extract the value of the "name" attribute
		if (!text) text = ''; // if undefined, set it to ""
		// create the trigger paragraph containing text and icon
		$(this).before('<p class="expander"><img src="../include/images/plus.jpg"/> '+ text + '</p>');
	})

	if ($("pre.expand").css('display') != 'none')
		//if ($(this).css('display') != 'none')
		$("pre.expand").hide();
	else
		$("pre.expand").show();
//})
	
	$("p.expander").live('click', function()
	{
		if ($(this).next().css('display') == 'none')
		{
			$(this).next().slideDown('slow');
			$(this).children("img").attr('src', "../include/images/minus.jpg");
		}
		else
		{
			$(this).next().slideUp('slow');	
			$(this).children("img").attr('src', "../include/images/plus.jpg");
		}
	})

/***************************
jQuery Tooltip functionality
***************************/
	$('a.trigger').mouseover(function(e) // OnMouseOver event
	{
		$(this).append('<div id="tooltip">' + $(this).attr('title') + '</div>');	// create the tooltip container
		$(this).attr('title',''); // enpty the title attribute of the anchor (avoiding default browser reaction)
		$('#tooltip').show(); // show the tooltip
	}).mousemove(function(e) // OnMouse mode event
	{
		$('#tooltip').css('top', e.pageY + 20 ); // tooltip 20px below mouse poiunter
		$('#tooltip').css('left', e.pageX - 100);	// tooltip with mouse pointer	
	}).mouseout(function() // OnMouseOut event
	{
		$(this).attr('title',$('#tooltip').html()); // set the title back to initial value
		$(this).children('div#tooltip').remove();	// get rid of the tooltip container	
	});
})

/**********
Print popup
**********/
function PrintPopup(source)
{ 
	var disp_setting="toolbar=0,locationbar=0,directories=0,menubar=1,"; 
		disp_setting+="scrollbars=yes,width=800, height=600, left=100, top=25"; 
  var docprint=window.open(source,"",disp_setting);
}

function checkEmail(email)
{
	invalidChars = " /:,;";
	if (email == "")
	{
		return false;
	}

	for (i = 0; i < invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i);
		if (email.indexOf(badChar,0)!= -1)
		{
			return false;
		}
	}

	atPos = email.indexOf("@",1);

	if (atPos == -1)
	{
		return false;
	}

	if (email.indexOf("@", atPos+1)!= -1)
	{
		return false;
	}
	periodPos = email.indexOf(".", atPos);
	if (periodPos == -1)
	{
		return false;
	}
	if (periodPos+3 > email.length)
	{
		return false;
	}
	return true;
}


