function setRowsPerPage(redirect)
{
	var limit = document.getElementById('rowsperpage').value;
	window.location.href=redirect+"&limit="+escape(limit);
}

function openWindow(url,window_name,params)
{
	window.open(url,'ImageView',params+',toolbar=0');
	return false;
}

function nciUrl()
{
	window.open("http://www.cancer.gov","NationalCancerInstitute");
}

function iconLegend(action)
{
	document.getElementById('icon-legend-container').style.display = "none";
	
	if(action == 'show')
	{
		document.getElementById('icon-legend-container').style.display = "block";
	}
}


function getStyle(div_id,styleProp)
{
	
	if( !document.getElementById(div_id) ) alert(div_id+" not found!");
	
	var x = document.getElementById(div_id);
	
	
	
	if (x.currentStyle)
	{
		var y = x.currentStyle[styleProp];
	}
	else if (window.getComputedStyle)
	{
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	}
	
	return y;
}



function manageMenuBlock(menu_id)
{
	var link_id = menu_id;
	menu_id = 'menu-'+menu_id;
	
	var currentState = getStyle(menu_id,'display');	
	if(currentState == "none")
	{
		open_close = 'show';
	}
	else
	{
		open_close = 'hide';
	}

	
	if(open_close == 'show')
	{
		//Effect.Appear(block);
		Effect.BlindDown(menu_id);
	}
	else if(open_close == "hide")
	{
		Effect.Fade(menu_id);
		Effect.BlindUp(menu_id);
	}

	var display_action = (open_close == 'show') ? '[hide details]' : '[show details]';
	document.getElementById(link_id).innerHTML = display_action;


}




var old_block = false;
var global = false;
function showDataBlock(block,global)
{
	// open or close?
	var currentState = getStyle(block,'display');
	if(global != true)
	{
		if(currentState == "block")
		{
			open_close = 'close';
		}
		else if(currentState == "none")
		{
			open_close = 'open';
		}
	}

	

	//document.getElementById(menu_to_hide).style.display = "none";	
	//document.getElementById(menu_to_show).style.display = "block";
	
	if(open_close == 'open')
	{
		//Effect.Appear(block);
		Effect.BlindDown(block);
	}
	else if(open_close == "close")
	{
		Effect.Fade(block);
		Effect.BlindUp(block);
	}
}



var antibodyCount = 0;
function showAllAntigenDataBlock(open_close,antibodyCount)
{
	var div_id = new Array;
	var menu_up = new Array;
	var menu_down = new Array;
	
	

	var antibody_groups = new Array;
	
	for( i = 0; i <= antibodyCount; ++i)
	{
		if( document.getElementById('antibody-'+i) )
		{
			antibody_groups[i] = 'antibody-'+i;
		}
	}

	for(i = 1; i <= antibody_groups.length; i++)
	{
		if( document.getElementById(antibody_groups[i]))
		{
			showDetailDataBlock(antibody_groups[i],open_close);
			showDetailDataBlock('menu-top-antibody-'+i,open_close);

			var display_action = (open_close == 'open') ? '[hide details]' : '[show details]';
			document.getElementById('top-antibody-'+i).innerHTML = display_action;
			
		}	
	}
	
	showDetailDataBlock('menu-top-antigen',open_close);
	showDetailDataBlock('block-antigen',open_close);
	document.getElementById('top-antigen').innerHTML = display_action;
	
}

function showDetailDataBlock(block,open_close)
{
	
	
	
	if(open_close == 'open')
	{
		//Effect.Appear(block);
		Effect.BlindDown(block);
	}
	else if(open_close == "close")
	{
		Effect.Fade(block);
		Effect.BlindUp(block);
	}
}



var old_antibodies_group_id = false;
function showAntibodies(group_id)
{
	if(old_antibodies_group_id == group_id)
	{
		Effect.BlindUp('antigen_antibodies_'+group_id);		
		document.getElementById('antibody_menu_'+group_id).className = "antigen_antibodies_link";
		document.getElementById('antibody_menu_'+group_id).innerHTML = "Show Antibodies";
		old_antibodies_group_id = false;
		return;
	}
	else
	{
		Effect.Appear('antigen_antibodies_'+group_id);
		Effect.BlindDown('antigen_antibodies_'+group_id);
		document.getElementById('antibody_menu_'+group_id).className = "antigen_antibodies_link_expanded"; 
		document.getElementById('antibody_menu_'+group_id).innerHTML = "Hide Antibodies";
	}
	old_antibodies_group_id = group_id;
}


function showCompare(antigen_id)
{
	
	
	document.getElementById('antibody_compare_details').innerHTML = 'Loading...';
	Effect.Appear('antibody-compare-background', { to: 0.3 });
	document.getElementById('antibody_compare_details').id = 'load-compare-window';
	Effect.Appear('load-compare-window');
	
	
	
	// disable scrolling
	scroll(0,0);
	/*
	window.onscroll=function()
	{
		window.scrollTo(0,0)
	}
	*/
	
	var req = ajaxConnect();
	
	req.open("GET", "/antibodies/detail/compare_antibodies.php?id="+escape(antigen_id), true);
	
	req.onreadystatechange = function()
	{
		if ( req.readyState == 4 ) 
		{
			if ( req.status == 200 )
			{
				document.getElementById('load-compare-window').id = 'antibody_compare_details';
				document.getElementById('antibody_compare_details').innerHTML = req.responseText;
				
				Effect.Appear('compare-data-container');
				
				Effect.Appear('antibody-compare-background', { to: 0.6 });
				Effect.Appear('antibody_compare_details');
				Effect.BlindDown('compare-data-container', { duration: .5 } ); // ,{ duration: 1.0 , scaleFrom: 15 , scaleTo: 80 } 
			} 
			else
			{
				alert("ERROR: "+req.statusText);
			}
		}
	}
	req.send(null);
}


function closeCompareWindow()
{
	Effect.Fade('antibody-compare-background');
	Effect.Fade('antibody_compare_details');
	document.getElementById('compare-original-images').innerHTML = '';

}



function showValidation(divId,titleId)
{
	
	
	document.onmousemove = getMouseXY;
	
	// open or closed?
	var currentState = getStyle(divId,'display');
	
	if(currentState == "block")
	{
		Effect.BlindUp(divId);
		document.getElementById(titleId).className = 'compare_validations';

	}
	else if(currentState == "none")
	{
		Effect.BlindDown(divId);
		document.getElementById(titleId).className = 'compare_validations-collapse';		
	}

}


function showOrigValidation(divId,imageId)
{
	
	makeOrigImages(divId,imageId);
	
	var x = document.getElementById('mouseX').value;
	var y = document.getElementById('mouseY').value;
	
	var xPos = x;
	var yPos = (y-100);
	
	
	/* right*/
	if( x > 200 && x < 475 )
	{
		xPos = 500;	
	}
	
	/* center */
	if( x > 485 && x < 750 )
	{
		xPos = 125;	
	}	
	
	/* left */
	if( x > 750)
	{
		xPos = 400;	
	}
	
	
	var xPos = x-200;
	var yPos = (y-300);
	
	
	var imageDiv = document.getElementById(divId);
	imageDiv.setAttribute('style','left:'+xPos+'px;top:'+yPos+'px;');	
	
	Effect.Appear(divId, { duration: 1 } );
}


function hideOrigValidation(divId)
{
	Effect.Fade(divId, { duration: 0 } );
}




function ajaxConnect()
{
	try
	{
		result = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			result = new ActiveXObject("MSXML2.XMLHTTP.3.0");
		}
		catch(e2)
		{
		result = false;
		alert("Unable to connect");
		}
	}
	return result;
}




function getMouseXY(e)
{
	
	var tempX = 0;
	var tempY = 0;
	var IE = document.all ? true : false;
	
	if (IE)
	{
		// grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else
	{
		// grab the x-y pos.s if browser is NS
	tempX = e.pageX;
	tempY = e.pageY;
	}
	
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	
	document.getElementById('mouseX').value = tempX;
	document.getElementById('mouseY').value = tempY;
	
	return true;
}

function makeOrigImages(divId,image_id)
{
	
   var div_contents = '';

   div_contents += '<div ondblclick="hideOrigValidation(\''+divId+'\');">';
   div_contents += '<img onmouseover="this.style.cursor=\'move\'" title="Drag to position.  Double click to close" src="/antibodies/detail/image.php?image_id='+image_id+'&field=file_orig" />';
   div_contents += '</div>';
   
   	var targetDiv = document.getElementById('compare-original-images');
	var newDiv = document.createElement('div');
	newDiv.setAttribute('id',divId);
	newDiv.setAttribute('class','validation-orig');
	targetDiv.appendChild(newDiv);
  	
	document.getElementById(divId).innerHTML = div_contents;
	new Draggable(divId, { scroll: window } );
}
