/* 
 Copyright CodeCogs 2006-2008
 Written by Will Bateman.
*/
function 	$$(name) 
{ return document.getElementById(name); }

// returns currency formatted string (xxx.xx) for given amount
function formatCurr(x)
{
  x = (   parseInt(  (parseFloat(x) + 0.005) * 100  )   )/100;
  s = x+'';
  if(s.indexOf('.') < 0) 
    s += '.00';
  if(s.indexOf('.') == (s.length - 2)) 
    s += '0';
  return s;
} 


// sets a menu's selected item to the value specified, if it exists in the menu
// returns boolean indicating whether item exists or not
function menuSelect(menuName, optionValue)
{
  menu = document.getElementById(menuName);
  if (menu) 
  {  
    for (i=0; i<menu.options.length; i++)
      if (menu.options[i].value == optionValue)
      {
	      menu.selectedIndex = i;
	      return true;
	    }
  }	
  return false;  
}

// manually toggles the display of a layer, and changes its button image, both passed as objects
function toggleLayer( lyr, img, show )
{
  //if (lyr) lyr.style.display = (show)? 'block':'none';
	var v=$(lyr);
	if(show) $(lyr).slideDown("slow"); else $(lyr).slideUp("slow");
	
	img.src = str.replace(/arrow_.*?\.gif/,((show)?"arrow_up.gif":"arrow_down.gif")); 
	img.alt = ((show)?'-':'+'); 
}

// given string <id> auto-toggles the display of a layer '<id>LYR' and changes its button image '<id>IMG'
function toggle( id )
{ 
  var img=$('#'+id+'IMG' );
	var lyr=$('#'+id+'LYR' );
  if( !img || !lyr ) alert('Missing tag');
	var show = (lyr.css("display")=='none');
  img.attr('src','/images/browser/arrow_'+((show)?'up':'down' )+'.gif');
	img.attr('alt',((show)?'up':'down'));
  lyr.slideToggle("slow"); 
}


// Auto resize text areas 
var ttextarea=null;
function adjustRows(textarea, minheight) 
{
  if(document.all) {
  textarea.style.height = Math.min(Math.max(minheight,textarea.scrollHeight+10), 1000) + "px";
	} else 
	{
	// slow down the updating and when it occurs
		if(ttextarea===null)
		{
			// create a temporary text area into which we push text to get its size
		  ttextarea = document.createElement('textarea');
			document.body.appendChild(ttextarea);
		  ttextarea.style.height = 0;
			ttextarea.style.border = '0 none #fff';
		}
		ttextarea.value=textarea.value;
		ttextarea.style.width=textarea.offsetWidth+"px";
		textarea.style.height = Math.min(Math.max(minheight,ttextarea.scrollHeight+10), 1000) + "px";	
	}
	
}

var popupwindows = new Array();
function popupnr( url, windowname, refocus, width, height ) {
	if(typeof(popupwindows[windowname])!='undefined') newwindow = popupwindows[windowname];
	else newwindow=null;
	if (newwindow===null || newwindow.closed || !newwindow.location) 
	{ 
	  newwindow=window.open(url,windowname,'width='+width+',height='+height+',status=1,scrollbars=no,resizable=1'); 
		if (!newwindow.opener) newwindow.opener = self; 
	popupwindows[windowname]=newwindow; 
	}
	if (window.focus) newwindow.focus();
	return false;
}

$(document).ready(function() 
{
	$('#minilogin input').bind('keypress', function(e) { 
	  var code=(e.keyCode ? e.keyCode : e.which);
		if(code==13) { $('#minilogin').submit(); }
	});
	
});
