// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

///////////////////////////////////////////////////////////////////////////
// Javascript Cookie Management
///////////////////////////////////////////////////////////////////////////
function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

///////////////////////////////////////////////////////////////////////////
// Miscellaneous Helpful Functions
///////////////////////////////////////////////////////////////////////////

// Makes the ALERT messages fade out automatically
Event.observe(window, 'load', function() { 
  $A(document.getElementsByClassName('alert')).each(function(o) {
    o.opacity = 100.0
    Effect.Fade(o, {duration: 4.0})
  });
});

 
// Allows forms to disable the enter key
// Usage: Add the attribute onKeyPress="return disableEnterKey(event);"
function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}

// Helper function to open a single URL in a new windows
function open_url(url, name, params) {
	window.open(url, name, params);
}	

// Set the caret position within a text field
function setCaretPos(oField, iCaretPos)
{
	if (Prototype.Browser.IE)
	{
		var oSel = document.selection.createRange();
		oSel.moveStart ('character', -oField.value.length);
		oSel.moveStart ('character', iCaretPos);
		oSel.moveEnd ('character', 0);
		oSel.select();
	} else {
		oField.selectionStart = iCaretPos;
		oField.selectionEnd = iCaretPos;
		oField.focus();
	}
}
