onload = on_body_load;

function on_body_load()
{
	//input field behaviour
	Event.observe( 'cert_no' , 'focus' , on_focus_input_cert_id );
	Event.observe( 'cert_no' , 'keydown' , function(event){ only_integer(event); } );
	//functions for showing the hint for the input field
	Event.observe( 'cert_no' , 'mouseover' , function(event){ document.getElementById("cert_no_hint").style.visibility = "visible"; } );
	Event.observe( 'cert_no' , 'mouseout' , function(event){ document.getElementById("cert_no_hint").style.visibility = "hidden"; } );
	Event.observe( 'cert_no' , 'click' , function(event){ document.getElementById("cert_no_hint").style.visibility = "hidden"; } );
	//functions for showing the hint for the submit button
	Event.observe( 'cert_no_submit' , 'mouseout' , function(event){ document.getElementById("cert_no_submit_hint").style.visibility = "hidden"; } );
	Event.observe( 'cert_no_submit' , 'mouseover' , function(event){ document.getElementById("cert_no_submit_hint").style.visibility = "visible"; } );
	
	Event.observe( 'inputform' , 'submit' , function(event){ validate(event) } );
}

function on_focus_input_cert_id()
{
	$("cert_no_hint").style.visibility = "hidden";
	if ( document.getElementById("cert_no").value == 'Enter IATF No' )
	{
		$("cert_no").value = "";
		$("cert_no").style.color = "black";
	}
}

function validate(event)
{
	value = parseInt( $("cert_no").value , 10 );
	if ( isNaN(value) )
	{
		alert("The IATF number is incorrect!\nOnly numbers are possible. Please correct the value!")
		Event.stop(event);
		$("cert_no").focus();
	}
	else if ( value < 2700 )
	{
		alert("IATF number's bellow 2700 are not possible.")
		Event.stop(event);
		$("cert_no").focus();
	}
}
