if (!(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6)) {

var v = {
	oForm : Object,
	sUrl : String,
	init : function(formID) {
		v.oForm = $('#'+formID);
		v.oForm.find('input:first')[0].focus();
		if ($("#rgsubmit.error"))
		{
		    $('#rgsubmit').append('<strong id="errCont" class="error" style="display:none;">Your message has not been sent, please review the highlighted parts and re-send</strong>');
		}
        
		//Initialise validator
		v.oForm.validate({
			//To turn on debug mode, uncomment the line below:
			/*debug:true,*/
			rules: {
				sname:{
					required:true,
					nameCheck:true
					//test for existence and if it's just a title...
					//mr;mrs;ms;dr;prof;rev;miss
				},
				email:{
					required:true,
					email:true
				},
				password: {
					required:true,
					minlength:3
				},
				confirmpassword: {
					required:true,
					minlength:3,
					equalTo :'#password'
				},
			    telday:{
					required:false,
			        tel:true
				}
			},
			//declare error messages to be shown
			messages: {
				sname:{
					required:'Name is required',
					nameCheck : 'Name is incomplete. Only the title has been entered'
				},
				email: {
					required: 'Email address is required',
					email: 'Email address is invalid'
				},
				telday: {
					tel: 'Telephone number is invalid'
				},
				password:{
					required: 'Please enter your password',
					minlength : 'Password must be at least 3 characters'
				},
				confirmpassword:{
					required: 'Please confirm your password',
					minlength : 'Password must be at least 3 characters',
					equalTo : 'Password fields must match'
				}
			},
			errorElement : 'strong',
			errorContainer : '#errCont',
			success : function(label){
				//switch the class on the parent div from 'error' to 'valid'
				label.parent().removeClass('error').addClass('valid');
				//$('#rgsubmit').removeClass('error');
				label.text('Valid');
				v.sFader = window.setTimeout(function(){label.fadeOut(1000,function(){label.remove();})},2000);
			},
			highlight : function(elem, errClass) {
				//switch the class on the parent div from 'valid' to 'error'
				//window.clearTimeout(v.sFader);
				if($('#rgsubmit').hasClass('error') == false) { $('#rgsubmit').addClass('error'); }
				$(elem).parent().removeClass('valid').addClass('error');
			}
		});
		//probably not needed....
		$.validator.addMethod('generic', function(){return true;},'');
		//test to see if passwords match
		$.validator.addMethod('confpwd', function(val) {

			if ($('input[name="password"]').val() != $('input[name="confirmpassword"]').val()){
				return false;
			} else {
				return true;
			}
		},'Passwords must match and be at least 3 characters');
		//name method; throws an error if it's only a title...
		$.validator.addMethod('nameCheck', function(val,obj){
				var aTitles = ['mr','mrs','ms','dr','prof','rev','miss'];
				var bValid = true;
				//loop through titles array; if it does, set 'bValid' to false (throws the error) and end the loop
				$.each(aTitles,function(pos,elem){		
					if(val.toLowerCase() == this) {
						bValid = false;
						return false;
					}
				});
				return bValid;
			},'Title only entered; please enter your name'
		);

		$.validator.addMethod('tel',function(val,obj){
			if(val.length<1) {return true;}
			if(val.length<10) {return false;}
			var rePhone = /^([0-9\+\-\(\)\.\s])+$/;
			if(rePhone.test(val) == false) {
				return false;
			}
			return true;
		},'enter a phone number!');

	}
};

//Thanks message and fade out function
var thanks = {
	oThanks : Object,
	oClose : Object,
	init : function(delay){
		thanks.oThanks = $('#thanks');
		thanks.oClose = thanks.oThanks.find('.closeLink');
		thanks.oClose.click(function(){thanks.sweepAway();});
		//Allows for a delay before the fadeout, or instaneous fade
		if(delay){setTimeout(thanks.sweepAway, delay)} else {thanks.sweepAway();};
	},
	sweepAway : function() {
		thanks.oThanks.animate({
			height:0/*,
			opacity:0*/
		},1000,function(){thanks.oThanks.remove();});
	}
};

}

