


//
// Drop-Down List based jump navigation, handled in Basic_Page.cs for NOSCRIPT
//
// usage : assign to the onclick a "go" submit button passing in (select.id)
// if the client does not support javascript, or this returns false the postback
// should read ?jump=DEST from the querystring and act accordingly
//
// (note: hack for explorer, Basic_Page also checks for "jump1" and "jump2"!)
// 
function cm_jump( ddlID )
{
	var h = document.getElementById( ddlID );
	
	if( h && h.value && h.value != '' )
	{
		location.href = h.value;
		return false;
	}
	
	return true;
}



//
// AutoThumbnail
//
// Call from an inline script block at the bottom of the html
// and any IMG tags with a class of "AutoThumb" and it will
// shrink it to a 200x200 (max) image.
//

function cm_autothumbnail()
{
	var className = "AutoThumb";
	var a = document.getElementsByTagName( 'IMG' );
	var ii = 0;
	var ni = a.length;
	var img = null;

	
	for( ; ii < ni ; ii++ )
	{
		img = a[ii];
		
		if( img.className.indexOf( className ) == -1 )
			continue;
		
		img.style.cursor = "pointer";		
		img.onclick = cm_thumb_toggle;
		img.onload = cm_thumb_img;	
	}
}


//
// Shrinks an image, accepts either an
// IMG DOM handle or an event
// 
function cm_thumb_img( img )
{	
	if( !img || !img.src )
	{
		var event = img;		
		if( !event )
			var event = window.event;
	
		img = event.target ? event.target : event.srcElement;		
	}
	
	var tt = "200";
	var iw = 0;
	var ih = 0;
	var ff = 0.0;
	
	iw = 1.0 * img.clientWidth;
	ih = 1.0 * img.clientHeight;
	ff = iw/ih;
	
	if( ff > 1.0 )
	{
		img.style.width = tt + "px";
		img.style.height = (tt / ff) + "px";
	}
	else
	{
		img.style.width = (tt * ff) + "px";
		img.style.height = tt + "px";			
	}	
}

//
// Toggle an image's size between thumb / full
// accepts either an IMG DOM handle or 
// an event
//
function cm_thumb_toggle( img )
{
	if( !img || !img.src )
	{
		var event = img;		
		if( !event )
			var event = window.event;
	
		img = event.target ? event.target : event.srcElement;		
	}
	
	if( img.style.width == "" )
	{
		cm_thumb_img( img );
	}
	else
	{
		img.style.width = "";
		img.style.height = "";
	}
}