﻿/* Contact_Box Javascript class */

var contact = {
	
	/**
	 * Check to see that we are on the contact page
	 *
	 */
	_init : function (){
		if (document.getElementById('contact_box')){
			document.getElementById('EMail').onblur 	= function(){ contact._email(); };
			document.getElementById('Retype').onchange 	= function(){ contact._retype(); };
		}
		
	},
	
	/**
	 * Now we are going to check to make sure that the email is valid
	 *
	 */
	_email : function (){
		var email = document.getElementById('EMail');
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email.value)) {
			alert('Please provide a valid email address');
			email.focus
			return false;		
		}
		
	},
	
	/**
	 * Now we are going to check to make sure that the emails match
	 *
	 */
	_retype : function (){
		var EMail	= document.getElementById('EMail').value;
		var Retype	= document.getElementById('Retype').value;
		
		if (EMail != Retype){
			document.getElementById('submit').onclick 	= function(){ alert('Emails don\'t match.'); return false; };
			document.getElementById('information').innerHTML	= 'Emails don\'t match.';
		} else {
			document.getElementById('submit').onclick 	= function(){  };
			document.getElementById('information').innerHTML	= '';
		}
		
	}
	
}

window.onload = contact._init();