var contact = { 

	width : 500,

	init : function() {

		//if the form items are filled in then validate
		if( $('name').value.length > 0 ) form_tools.validate_input( $('name'), regexp.name );
		if( $('email').value.length > 0 ) form_tools.validate_input( $('email'), regexp.email );
		if( $('telephone').value.length > 0 ) form_tools.validate_input( $('telephone'), regexp.telephone );
		if( $('message').value.length > 0 ) form_tools.validate_input( $('message'), regexp.message );
		
		// turn off autocomplete
		$('cf').setAttribute("autocomplete", "off");
		
		//stop the enter key submitting the form
		$('name').onkeypress = form_tools.cancel_enter;
		$('email').onkeypress = form_tools.cancel_enter;
		$('telephone').onkeypress = form_tools.cancel_enter;

	},

	check_form : function() {
		
		//check everything
		if( $('name').value.length == 0 ) contact.show_error( "You haven't entered your name" );
		else if( !$('name').value.match( regexp.name ) ) contact.show_error( "You haven't entered a valid name" );
		else if( $('email').value.length == 0 ) contact.show_error( "You haven't entered an email address" );
		else if( !$('email').value.match( regexp.email ) ) contact.show_error( "You haven't entered a valid email address" );
		else if( $('telephone').value.length == 0 ) contact.show_error( "You haven't entered your telephone" );
		else if( !$('telephone').value.match( regexp.telephone ) ) contact.show_error( "You haven't entered a valid telephone number" );
		else if( $('message').value.length == 0 ) contact.show_error( "You haven't entered a message" );
		else return true;
	
		return false;
	
	},
	
	show_error : function( text ) {

		var html = '<h1 style="background-image: url(images/headings/sorry.png); width: 285px;"><span>Sorry, there was an error</span></h1><strong>' + text + '</strong>';
		popup_tools.open( html, contact.width );
	
	}

}

contact.init();