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

if (Ajax != null) {
	Ajax.Responders.register({
		onFailure: function(response){
			alert('Request failed: ' + response.responseText);
		}
	});
}

//this function is used to show or hide full text when it is cropped to the first few
//characters. This is used by the text_expander method in application_helper
function textToggle( id )
{
	$( id + "_short" ).toggle();
	$( id + "_full" ).toggle();
}

function highlight_application_notices()
{
	Event.observe( window, 'load', function() {
		$$( '#notices li:not(li.messages) span' ).each( function( element ) {
			new Effect.Highlight( element, { endcolor: '#EBEFF4',
				duration: 4, keepBackgroundImage: true } );
		} );
	} );
}

function numbersonly(myfield, e, allowdec)
{
    var key;
    var keychar;
    
    if (e.ctrlKey==1) return true;

    if (window.event)
        key = window.event.keyCode;
    else if (e)
        key = e.which;
    else
        return true;
    
   // control keys
    if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) || (key==46)
        || (key==35) || (key==36) // home/end
        || (key==37) || (key==38) || (key==39)|| (key==40) ) // arrow keys
        return true;
        
    if (e.shiftKey==1) return false;
    
    keychar = String.fromCharCode(key);

    if ( (("0123456789").indexOf(keychar) > -1) || (key >= 96 && key <= 105) )// numbers && keypad
        return true;
    else if (allowdec && (keychar == "." || key == 110 || key == 190 )) // decimal point
        return ( myfield.value.indexOf( "." ) < 0 );  //make sure there is not already a decimal
    else
    {
        return false;
    }
}
