
$(document).ready(function(){  

	
	$.preloadCssImages(); 
						   
	  attachRollOverEvent = function(imageId){
		  $(imageId).mouseover( function(){ $(this).attr("src", $(this).attr("src").split('_off').join('_on')) } );
		  $(imageId).mouseout( function(){ $(this).attr("src", $(this).attr("src").split('_on').join('_off')) } );
      }				   

	  
      attachRollOverEvent(".morelink a img");
	  
	 
	
// #newsletter_input is the id of the textbox
// This uses the value of the title attribute to pre-fill input field
//(useful for user instruction eg 'Search ..')
// The field is then emptied onclick
// and re-inserted onblur 
$('#newsletter_input').focus(function() {
  // See if the input field is the default
  if ($(this).val() == $(this).attr('title')) {
    $(this).val('');
  }
})
.blur(function() {
  if ($(this).val() == '') {
    $(this).val($(this).attr('title'));
  }
});	

	// validate newsletter subsccriber email form on keyup and submit
	$("#newsletter_form").validate({
								   
	// #messageBox holds the all encompassing message at the top to let all the users know  there is a problem.
         //errorContainer:"#messageBox",
// This is very important for manipulating the placement and styles of the error message for individual cases, such as first name or zip. I'll explain this later.
         errorClass: "formError",
// wrapper is only needed if you want to wrap the error message in something. If you  want a list the errors it can be a <li>. I didn't really find any need for this  unless you were listing all the errors at the top.
         wrapper: null,
// errorPlacement is very important. It is where in the DOM you want the error of each  idividual case to appear. I wanted each error to be placed at the beginning of each  form element list item. See HTML example below. 
         errorPlacement: function(error, element) { 
          //  error.insertBefore(element);
			error.insertAfter( element.next() );

        },							   
		
	   rules: {
				newsletter_input: {
				   required: true,
				   email: true
					}
		},
	   messages: {
				newsletter_input: {
				   required: "We need your email address to contact you",
				   email: "Email address must be like name@domain.com"
				   }
				}
	})
	
	
	
	
	// validate newsletter subsccriber email form on keyup and submit
	$("#unsubscribe").validate({
								   
	// #messageBox holds the all encompassing message at the top to let all the users know  there is a problem.
         //errorContainer:"#messageBox",
// This is very important for manipulating the placement and styles of the error message for individual cases, such as first name or zip. I'll explain this later.
         errorClass: "formError",
// wrapper is only needed if you want to wrap the error message in something. If you  want a list the errors it can be a <li>. I didn't really find any need for this  unless you were listing all the errors at the top.
         wrapper: null,
// errorPlacement is very important. It is where in the DOM you want the error of each  idividual case to appear. I wanted each error to be placed at the beginning of each  form element list item. See HTML example below. 
         errorPlacement: function(error, element) { 
          //  error.insertBefore(element);
			error.insertAfter( element.next() );

        },							   
		
	   rules: {
				newsletter_input: {
				   required: true,
				   email: true
					}
		},
	   messages: {
				newsletter_input: {
				   required: "We need your email address to contact you",
				   email: "Email address must be like name@domain.com"
				   }
				}
	})
	
						   
	// validate signup form on keyup and submit
	/*
	$("#quoteform").validate({
		
	   rules: {
				enq_company_name: "required",
				enq_contact_name: "required",
				enq_surname: "required",
				enq_position: "required",
				enq_firm_name: "required",
				enq_address1: "required",
				enq_contact_email: {
				   required: true,
				   email: true
					},
				enq_telephone: "required",
				enq_trained_crew_require:{ 							
					required: function(element) {
						return $("#enq_trained_crew").val()=="yes";
						}
					  },
				
				enq_hard_standing_require: {
					required: function(element) {
					return $("#enq_hard_standing").val()=="yes";
						}
					},
				enq_service_pits_require: {
					required: function(element) {
					return $("#enq_service_pits").val()=="yes";
						}
					},
				enq_well_install_require: {
					required: function(element) {
					return $("#enq_well_install").val()=="yes";
						}
					},
				enq_well_require: {
					required: function(element) {
					return $("#enq_well").val()=="yes";
						}
					},
				enq_inside_require: {
					required: function(element) {
					return $("#enq_inside").val()=="yes";
						}
					},
				enq_ppe_require_other: {
					required: "#enq_ppe_require_0:checked"
					},
				enq_add_equip_other: {
					required: "#enq_add_equip_16:checked"
					}
		},
	   messages: {
				enq_company_name: "Please enter your company's name",
				enq_contact_name: "Please enter your name",
				enq_surname: "Please enter your lastname",
				enq_position: "Please specify your job title",
				enq_firm_name: "Please enter the name of your firm",
				enq_address1: "Please add address details",
				enq_contact_email: {
				   required: "We need your email address to contact you",
				   email: "Email address must be like name@domain.com"
				   },
				enq_telephone: "Please enter your telephone number",
				enq_trained_crew_require:"Please make a selection from this list",
				enq_hard_standing_require:"Please make a selection from this list",
				enq_service_pits_require:"Please make a selection from this list",
				enq_well_install_require:"Please make a selection from this list",
				enq_well_require:"Please make a selection from this list",
				enq_inside_require:"Please make a selection from this list",
				enq_ppe_require_other:"Please include your requirements",
				enq_add_equip_other:"Please specify alternative requirements"
				}
	})
	
	*/
	




}); 	
