$(document).ready(function(){

	$("a")
		.filter(".openInfo")
     	.click(function()
     	{
       		openInfo(this);
       		return false;
     	}
     	).end();
     	
	$("a")
		.filter(".openWindow")
     	.click(function()
     	{
       		openWindow(this);
       		return false;
     	}
     	).end();     
     	
	$("a")
		.filter(".readMore")
     	.click(function()
     	{
			toggleReadMore(this);
       		return false;
     	}
     	).end();     	
     	
	$("a")
		.filter(".readLess")
     	.click(function()
     	{
     		var anchor = $(this).parent().parent().parent().
     			children("div.linkDiv").children("a.readMore");
			toggleReadMore(anchor);
       		return false;
     	}
     	).end();     	
});

function toggleReadMore ( anchor ) {
	$(anchor).hide();
	var readMoreDiv = $(anchor).parent().parent().children("div.readMore");
	readMoreDiv.slideToggle( "fast", function() {
		if( !readMoreDiv.is(":visible") ) {
			$(anchor).show();
		}
	} );
}
 
function openInfo ( anchor )
{
	var url = anchor.href;
	
	var heightWidthArr = null;
	
	if( anchor.title )
	{
		var heightWidth = anchor.title;
		anchor.title = "";
		heightWidthArr = heightWidth.split("x");
		// Storing the window size to the anchor
		anchor.heightWidthArr = new Array();
		anchor.heightWidthArr[0] = heightWidthArr[0];
		anchor.heightWidthArr[1] = heightWidthArr[1];
	}
	else if( anchor.heightWidthArr )
	{
		// Grab the window size from the anchor
		heightWidthArr = new Array();
		heightWidthArr[0] = anchor.heightWidthArr[0];
		heightWidthArr[1] = anchor.heightWidthArr[1];
	}
	
	if( !heightWidthArr )
	{
		heightWidthArr = new Array();
		heightWidthArr[0] = 350;
		heightWidthArr[1] = 400;
	}
	
	
	var newWindow = window.open(url, "", "width="+heightWidthArr[1]+",height="+heightWidthArr[0]+",status=yes,scrollbars=yes,resizable=yes");
	var x = 200;
	var y = 100;
	newWindow.moveTo(x,y);
}

function openWindow ( anchor )
{
	var url = anchor.href;
	window.open(url, "");
}

function isNullOrEmpty( str )
{
	if( str && str != null && str != "" )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function isFieldNullOrEmpty( field )
{
	if( !isNullOrEmpty(field.value) && field.value != new String("NONE") )
	{
		return false;
	}
	else
	{
		return true;
	}
}

function validate_email( email, confirm )
{	
	if( isNullOrEmpty(email) || isNullOrEmpty(confirm) )
		return false;
		
	if( email != confirm )
		return false;
		
	var str = email;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)	

	if (str.indexOf(at)==-1){
	    return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	    return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	
	if (str.indexOf(" ")!=-1){
		return false
	}	

	return true;
}


