// menu loader
function imgOnover(id){  
	//alert('#'+id+'_d');
	var def_class	=	'#'+id+'_d';
	var hover_class	=	id+'_o';
	$(def_class).attr('class', hover_class);
}

function imgOnOut(id){
	var def_class	=	'#'+id+'_d';
	var hover_class	=	id+'_d';
	$(def_class).attr('class', hover_class);	
}
function swap_class(ele,class_1,class_2){
	if(class_1 && class_2){
		if(ele.className == class_1){
			ele.className = class_2;
		}else{
			ele.className = class_1;
		}
	}
}
 var poll_flag=0;
$(document).ready(function(){
	$('#buy_btn').click(function (){		
	if(!$.trim($('#desc').val())){
        alert('Products are not available. Please contact administrator');
    }else if(!$.trim($('#name').val())){
        alert('Please enter first name');
        $('#name').focus();
    }else if(!$.trim($('#surname').val())){
        alert('Please enter surname');
        $('#surname').focus();
    }else if(!$.trim($('#house_no').val())){
        alert('Please enter house number');
        $('#house_no').focus();
    }else if(!$.trim($('#street').val())){
        alert('Please enter street name');
        $('#street').focus();
    }else if(!$.trim($('#town').val())){
        alert('Please enter town');
        $('#town').focus();
    }else if(!$.trim($('#county').val())){
        alert('Please enter county');
        $('#county').focus();
    }else if(!$.trim($('#postcode').val())){
        alert('Please enter postcode');
        $('#postcode').focus(); 
    }else if(!$.trim($('#vehicle_make').val())){
        alert('Please enter vehicle make');
        $('#vehicle_make').focus();
    }else if(!$.trim($('#vehicle_model').val())){
        alert('Please enter vehicle model');
        $('#vehicle_model').focus();   
    }else if(!$.trim($('#reg_no').val())){
        alert('Please enter registration number');
        $('#reg_no').focus();  
    }else if(!$.trim($('#inception_date').val())){
        alert('Please enter inception date');
        $('#inception_date').focus();
    }else if(!isValidEmail($.trim($('#email').val()))){
        alert('Please enter a valid Email Id');
        $('#email').focus();   
    }else if(($.trim($('#email').val())) != ($.trim($('#confirm_email').val()))){
        alert('The email address and confirm email address should be same.');
        $('#confirm_email').focus();
    }else if($('#terms').is(':checked') == false){
    	alert('Please agree terms and conditions');
        $('#terms').focus();   
    }
    else{
        $('#BuyForm').attr('action','https://select-test.wp3.rbsworldpay.com/wcc/purchase');
        //$('#BuyForm').attr('action','https://secure-test.wp3.rbsworldpay.com/wcc/purchase?instId=211616&cartId=abc123&amount=40.00&currency=GBP&desc=WorldPay+Test&testMode=100');
        //$('#BuyForm').attr('action',base_url+'insurancepayment/save');
        $('#BuyForm').submit();
    }
});
	$('#contact_btn').click(function (){		
		if(!$.trim($('#name').val())){
            alert('Please enter name');
            $('#name').focus();
        }else if(!$.trim($('#telephone').val())){
            alert('Please enter telephone');
            $('#telephone').focus();
        }else if(!$.trim($('#address').val())){
            alert('Please enter address');
            $('#address').focus();
        }else if(!isValidEmail($.trim($('#email').val()))){
            alert('Please enter a valid Email Id');
            $('#email').focus();
        }else if(!$.trim($('#city').val())){
            alert('Please enter city');
            $('#city').focus();
        }else if(!$.trim($('#postcode').val())){
            alert('Please enter Postcode');
            $('#postcode').focus();        
        }else if(!$.trim($('#enquiry').val())){
            alert('Please enter enquiry');
            $('#enquiry').focus();
        }else{
            $('#frm_contactus').attr('action',base_url+'contactus/send_email');
            $('#frm_contactus').submit();
        }
	});
	$('#btn_garage_search').click(function (){
		if($.trim($('#txt_garage_search').val())){

            setCookie('how_hear_status','not_set',1);
			$('#frm_garage_search').attr('action',base_url+'garage/search/p');

			$('#frm_garage_search').submit();
		}
	});
	$('.search_tab_postcode').click(function (){
		if($.trim($('#txt_garage_search').val())){
			var page_num 	= $.trim($(this).attr("lang"));
			//$('#frm_garage_search').attr('action',base_url+'garage/search/p/'+page_num);
			//$('#frm_garage_search').submit();
			$('#txt_garage_filter').val($.trim($('#txt_garage_search').val()));
			$('#frm_garage_filter').attr('action',base_url+'garage/search/p/'+page_num);
			$('#frm_garage_filter').submit();
		}
	});
	$('#search_tab_postcode').click(function (){
		if($.trim($('#txt_garage_search').val())){
			$('#frm_garage_search').attr('action',base_url+'garage/search/p');
			$('#frm_garage_search').submit();
		}
	});
	$('#search_tab_garage').click(function (){
		if($.trim($('#txt_garage_search').val())){
			$('#frm_garage_search').attr('action',base_url+'garage/search/g');
			$('#frm_garage_search').submit();
		}
	});
	$('#search_tab_town').click(function (){
		if($.trim($('#txt_garage_search').val())){
			$('#frm_garage_search').attr('action',base_url+'garage/search/t');
			$('#frm_garage_search').submit();
		}
	});
	$('.search_town_postcode').click(function (){
		var postcode 	= $.trim($(this).attr("rel"));
		if(postcode){
			$('#txt_garage_search').val(postcode);
			$('#frm_garage_search').attr('action',base_url+'garage/search/p');
				$('#frm_garage_search').submit();
		}
	});
	
	$('.navigate_town_list').click(function (){
		var offset 	= $.trim($(this).attr("id"));
		if(offset){
			$('#frm_garage_search').attr('action',base_url+'garage/search/t/'+offset);
			$('#frm_garage_search').submit();
		}
	});
	$('.navigate_garage_list').click(function (){
		var offset 	= $.trim($(this).attr("id"));
		if(offset){
			$('#frm_garage_search').attr('action',base_url+'garage/search/g/'+offset);
			$('#frm_garage_search').submit();
		}
	});
	
	$('#btn_garage_search_bottom').click(function (){
		if($.trim($('#txt_garage_search_bottom').val())){
			$('#txt_garage_filter').val($.trim($('#txt_garage_search_bottom').val()));
			$('#frm_garage_filter').attr('action',base_url+'garage/search/p');
			$('#frm_garage_filter').submit();
		}else{
			$('#txt_garage_search_bottom').focus();
		}
	});
	
	$('#btn_filter_manufacture').click(function (){
		submit_bottom_filter();
	});
	$('#btn_filter_online').click(function (){
		if(1 == $('#online_booking').val()){
			$('#online_booking').val(0);
		}else{
			$('#online_booking').val(1);
		}
		submit_bottom_filter();
	});
	$('#btn_filter_service').click(function (){
		submit_bottom_filter();
	});
        /* Postcode Search from Other Pages*/
        
        $('.input_search_right').click(function (){
            if($.trim($('#txt_garage_filter').val())){
                $('#frm_garage_search_page').submit();
            }
        });
        
        /* Feedback Page */
        $('.feedback_star').mouseover(function (){
            var fb_category =   $.trim($(this).attr('name'));
            var fb_level    =   Number($.trim($(this).attr('lang')));
            var max_length  =   5;
            for(var i=1;i<=fb_level;i++){
                $('#'+fb_category+'_'+i).attr('src',image_path+'gold_star.png');
            }
            for(var j=Number(fb_level+1);j<=max_length;j++){
                $('#'+fb_category+'_'+j).attr('src',image_path+'grey_star.png');
            }
        });
        $('.feedback_star').click(function (){
            var fb_category =   $.trim($(this).attr('name'));
            var fb_level    =   Number($.trim($(this).attr('lang')));
            $('#'+fb_category+'_selected').val(fb_level);
        });
        $('.feedback_star').mouseout(function (){
            var fb_category =   $.trim($(this).attr('name'));
            var fb_level    =   Number($.trim($('#'+fb_category+'_selected').val()));
            var max_length  =   5;
            for(var i=1;i<=fb_level;i++){
                $('#'+fb_category+'_'+i).attr('src',image_path+'gold_star.png');
            }
            for(var j=Number(fb_level+1);j<=max_length;j++){
                $('#'+fb_category+'_'+j).attr('src',image_path+'grey_star.png');
            }
        });

        $('#add_bookmark').click(function (){
            var url     =   location.href;
            var title   =   document.title;
            if(window.sidebar){
		window.sidebar.addPanel(title,url,"");
		return;
            }
            if(window.external)
                    window.external.AddFavorite(url,title );
        });
        /* Contact Page */
         $('#contact_form_opener').click(function (){
            $('#contact_email_container').slideUp('slow');
            $('#contact_address_container').slideUp('slow');
            $('#contact_telephone_container').slideUp('slow');
            $('#contact_form_container').slideDown('slow');
            scrollBottom();
        });
        $('#telephone_opener').click(function (){
            $('#contact_form_container').slideUp('slow');
            $('#contact_address_container').slideUp('slow');
            $('#contact_email_container').slideUp('slow');
            $('#contact_telephone_container').slideDown('slow');
            scrollBottom();
        });
        $('#address_opener').click(function (){
            $('#contact_form_container').slideUp('slow');
            $('#contact_telephone_container').slideUp('slow');
            $('#contact_email_container').slideUp('slow');
            $('#contact_address_container').slideDown('slow');
            scrollBottom();
        });
        $('#email_opener').click(function (){
            $('#contact_form_container').slideUp('slow');
            $('#contact_telephone_container').slideUp('slow');
            $('#contact_address_container').slideUp('slow');
            $('#contact_email_container').slideDown('slow');
            scrollBottom();
        });
         $('#action_mailme').click(function (){        	

                if(!$.trim($('#name').val())){
                        alert('Please enter First Name');
                        $('#name').focus();
                }else if(!isValidEmail($.trim($('#email').val()))){
                        alert('Please enter a valid Email Id');
                        $('#email').focus();
                }else if(!($.trim($('#captch_txt').val()))){
                        alert('Please enter code as shown');
                        $('#captch_txt').focus();
                }else{
                		if($('#txt_offers').is(':checked') == true){
         					$("#txt_offers").attr('value', '1');
                		}
                        $('#frm_mailme').attr('action',base_url+'garage/emaildetails');
                        $('#frm_mailme').submit();
                }
         });
        $('#back_to_map').click(function (){
            if($.trim($('#current_postcode').val())){
                $('#txt_garage_search').val($.trim($('#current_postcode').val()));
                $('#frm_garage_search').attr('action',base_url+'garage/search/p');
                $('#frm_garage_search').submit();
            }
        });
        $('#back_to_garage_details').click(function (){
            if($.trim($('#current_garage').val())){
                $('#frm_garage_search').attr('action',base_url+'garage/details/'+$.trim($('#current_garage').val()));
                $('#frm_garage_search').submit();
            }
        });
        
        /* <Book online> */
       /* $('#action_book_1').click(function (){ $('#frm_book_1').submit();
                if(!$.trim($('#vehicle_reg_num').val())){
            		alert('Please enter vehicle registration number');
            		$('#vehicle_reg_num').focus();
            	}else{
	            if($.trim($('#current_garage').val())){
                        $('#frm_book_1').attr('action',base_url+'bookonline/step2/'+$.trim($('#current_garage').val()));
                        $('#frm_book_1').submit();
                    }
                }
        });*/
        $('#frm_book_1').submit(function (){
                if(!$.trim($('#vehicle_reg_num').val())){
            		alert('Please enter vehicle registration number');
            		$('#vehicle_reg_num').focus();return false;
                        
            	}else{
	            if($.trim($('#current_garage').val())){
                        $('#frm_book_1').attr('action',base_url+'bookonline/step2/'+$.trim($('#current_garage').val()));
                        $('#frm_book_1').submit();
                    }
                }
        });
        $('#action_book_2').click(function (){
            if($.trim($('#current_garage').val())){
            	if(!$.trim($('#title').val())){
            		alert('Please enter Title');
            		$('#title').focus();
            	}
            	else if(!$.trim($('#sur_name').val())){
            		alert('Please enter Surname');
            		$('#sur_name').focus();
            	}else if(!$.trim($('#first_name').val())){
            		alert('Please enter First Name');
            		$('#first_name').focus();
            	}
            	else if(!isValidEmail($.trim($('#email').val()))){
            		alert('Please enter a valid Email Id');
            		$('#email').focus();
            	}else if(!$.trim($('#day_tel').val())){
            		alert('Please enter Daytime Telephone');
            		$('#day_tel').focus();
            	}else if(!$.trim($('#eve_tel').val())){
            		alert('Please enter Evening  Telephone');
            		$('#eve_tel').focus();
            	}
            	else if(!$.trim($('#mobile_tel').val())){
            		alert('Please enter Mobile  Telephone');
            		$('#mobile_tel').focus();
            	}
            	else if(!$.trim($('#preffered_date').val())){
            		alert('Please enter Preferred Date');
            		$('#preffered_date').focus();
            	}
            	else{
            		$('#frm_book_2').attr('action',base_url+'bookonline/step2/'+$.trim($('#current_garage').val()));
                	$('#frm_book_2').submit();
            	}
            }
        });
         /* </Book online>*/
         /*< Leave feedback >*/
         $('#action_leave_feedback').click(function (){         	
            var patt1=/[^0-9\s]/g;
            var phone = ($.trim($('#telephone').val()));
            if(!$.trim($('#name').val())){
                alert('Please enter Name');
                $('#name').focus();
            }else if(!isValidEmail($.trim($('#email').val()))){
                alert('Please enter a valid Email Id');
                $('#email').focus();
            }else if(!$.trim($('#postcode').val())){
                alert('Please enter Postcode');
                $('#postcode').focus();
            }else if(!$.trim($('#telephone').val())){
                alert('Please enter Telephone');
                $('#telephone').focus();
            }else if(phone.match(patt1)){
				alert("There is a problem with the data that you have input into the telephone number field, please use only numbers and  spaces.");
				$('#telephone').focus();
			}else if(!$.trim($('#garage_name').val())){
                alert('Please enter Garage Name');
                $('#garage_name').focus();
            }else if(!$.trim($('#date_of_work').val())){
                alert('Please enter Date of Work');
                $('#date_of_work').focus();
            }else if(!$.trim($('#location').val())){
                alert('Please enter Location');
                $('#location').focus();
            }else if($('#help_selected').val()==0 ||
     		$('#quality_selected').val()==0 ||
     		$('#standard_selected').val()==0 ||
     		$('#general_selected').val()==0){
     			alert("Please indicate your satisfaction levels with this garage by clicking the number of stars between 1 and 5 for each subject.");
     		}else if("0" == $.trim($('#recommend').val())){
                    alert('Please select whether you recommend our garage to others?');
                    $('#recommend').focus();
            }else if("0" == $.trim($('#use_again').val())){
                    alert('Please select whether you would use our garage again?');
                    $('#use_again').focus();
            }else{
                    $('#frm_leave_feedback').attr('action',base_url+'feedback');
                    $('#frm_leave_feedback').submit();
            }
         });
         /*< /Leave feedback >*/
         /*< Reminder >*/
            $('#action_reminder').click(function (){
                if(!isValidEmail($.trim($('#email').val()))){
                   alert('Please enter a valid Email Id');
                   $('#email').focus();
                }else if(!($.trim($('#registration_no').val()))){
                   alert('Please enter your Vehicle Registration Number');
                   $('#registration_no').focus();
                }else if($('#reminder_sms').attr('checked') && (!($.trim($('#mobile_number').val()))) ){
                   alert('Please enter Mobile Number for SMS Reminder');
                   $('#mobile_number').focus();
                }else if((!$('#mot_due_check').attr('checked')) && (!$('#service_due_check').attr('checked')) && (!$('#car_tax_due_check').attr('checked'))){
                    alert('Please select one of the Reminder service you need');
                }else if((!$('#reminder_email').attr('checked')) && (!$('#reminder_sms').attr('checked'))){
                    alert('Please select Reminder Type');
                }else if((!$('#terms').attr('checked'))){
                    alert('Please agree with terms of service, Privacy Policy and Terms & Conditions of the Good Garage Scheme reminder service');
                }else{
                    $('#frm_reminder_service').attr('action',base_url+'reminder');
                    $('#frm_reminder_service').submit();
                }
            });

         /*</Reminder>*/
         /* < Memebership enquiry >*/
         $('#action_membership').click(function (){
            if(!($.trim($('#garage_name').val()))){
               alert('Please enter Garage Name');
               $('#garage_name').focus();
            }else if(!($.trim($('#address_1').val())) && !($.trim($('#address_2').val()))){
               alert('Please enter Garage Address');
               $('#address_1').focus();
            }else if(!($.trim($('#city').val()))){
               alert('Please enter Town/City');
               $('#city').focus();
            }else if(!($.trim($('#postcode').val()))){
               alert('Please enter Postcode');
               $('#postcode').focus();
            }else if(!($.trim($('#telephone').val()))){
               alert('Please enter Telephone');
               $('#telephone').focus();
            }else if(!isValidEmail($.trim($('#email').val()))){
               alert('Please enter a valid Email Id');
               $('#email').focus();
            }else if(!($.trim($('#contact_name').val()))){
               alert('Please enter Contact Name');
               $('#contact_name').focus();
            }else if(!($.trim($('#business_year').val()))){
               alert('Please enter Number of years in business');
               $('#business_year').focus();
            }else{
                $('#frm_membership_enquery').attr('action',base_url+'membership');
                $('#frm_membership_enquery').submit();
            }
         });
         /* < /Memebership enquiry >*/
         /* <  Complaint Form >*/
         $('#action_complaint_form').click(function (){
	    var patt1=/[^0-9\s]/g;
            var phone = ($.trim($('#telephone').val()));
            if(!($.trim($('#name').val()))){
               alert('Please enter the Name');
               $('#name').focus();
            }else if(!($.trim($('#telephone').val()))){
               alert('Please enter Telephone Number');
               $('#telephone').focus();
            }else if(phone.match(patt1)){
				alert("There is a problem with the data that you have input into the telephone number field, please use only numbers and  spaces.");
				$('#telephone').focus();
			}
		else if(!($.trim($('#address_1').val()))){
               alert('Please enter Address');
               $('#address_1').focus();
            }else if(!isValidEmail($.trim($('#email').val()))){
               alert('Please enter a valid Email Id');
               $('#email').focus();
            }else if(!($.trim($('#town').val()))){
               alert('Please enter Town/City');
               $('#town').focus();
            }else if(!($.trim($('#postcode').val()))){
               alert('Please enter Postcode');
               $('#postcode').focus();
            }else if(!($.trim($('#date_of_work').val()))){
               alert('Please enter Date of Work');
               $('#date_of_work').focus();
            }else if(!($.trim($('#complaint_date').val()))){
               alert('Please enter Complaint Date');
               $('#complaint_date').focus();
            }else if(!($.trim($('#garage_name').val()))){
               alert('Please enter Garage Name');
               $('#garage_name').focus();
            }else if(!($.trim($('#complaint_person').val()))){
               alert('Please enter Complaint Person Name');
               $('#complaint_person').focus();
            }else if(!($.trim($('#complaint_details').val()))){
               alert('Please enter Complaint details');
               $('#complaint_details').focus();
            }else{
                $('#frm_complaint').attr('action',base_url+'complaints');
                $('#frm_complaint').submit();
            }
         });
         /* </ Complaint Form >*/


          /*<Phone app registration>*/
        $('#app_reg_submit').click(function (){
            if(!($.trim($('#first_name').val()))){
               alert('Please enter First Name');
               $('#first_name').focus();
            }else if(!($.trim($('#last_name').val()))){
               alert('Please enter Last Name');
               $('#last_name').focus();
            }else if(!($.trim($('#address1').val()))){
               alert('Please enter Address line 1');
               $('#address1').focus();
            }else if(!($.trim($('#address2').val()))){
               alert('Please enter Address line 2');
               $('#address2').focus();
            }else if(!($.trim($('#address3').val()))){
               alert('Please enter Address line3');
               $('#address3').focus();
            }else if(!($.trim($('#post_code').val()))){
               alert('Please enter Postcode');
               $('#post_code').focus();
            }else if(!isValidEmail($.trim($('#email').val()))){
               alert('Please enter a valid Email');
               $('#email').focus();
            }else if(!($.trim($('#phone_number').val()))){
               alert('Please enter Phone number');
               $('#phone_number').focus();
            }else if(!($.trim($('#dob').val()))){
               alert('Please enter Date of Birth');
               $('#dob').focus();
            }else if(isValidDate($.trim($('#dob').val())) == false ){
               $('#dob').focus();
            }else{       
                $('#app_reg').attr('action',base_url+'appregistrationdecfeb11');
                $('#app_reg').submit();
            }
        });

     /*</Phone app registration>*/




         /* <   New Page >*/
         $('.news_archive_year').click(function (){
             var year_div_id =   $.trim($(this).attr("lang"));
             if(year_div_id){
                 if('news_archive_year news_archive_year_closed' == $('#news_archive_year_'+year_div_id).attr('class')){
                     $('#news_archive_year_'+year_div_id).attr('class','news_archive_year news_archive_year_open');
                 }else{
                     $('#news_archive_year_'+year_div_id).attr('class','news_archive_year news_archive_year_closed');
                 }
                 $('#archive_year_container_'+year_div_id).slideToggle();
             }
         });
         $('.news_archive_month').click(function (){
             var month_div_id =   $.trim($(this).attr("lang"));
             if(month_div_id){
                 if('news_archive_month news_archive_month_closed' == $('#news_archive_month_'+month_div_id).attr('class')){
                     $('#news_archive_month_'+month_div_id).attr('class','news_archive_month news_archive_month_open');
                 }else{
                     $('#news_archive_month_'+month_div_id).attr('class','news_archive_month news_archive_month_closed');
                 }
                 $('#archive_month_container_'+month_div_id).slideToggle();
             }
         });

         /*   reset password  */

	//	var password =  $('#benefits_password').val();
      
		$('#password_reset').click(function (){
            
            var garage_id = escape($.trim($('#hidden_garage_id').val()));
            if(garage_id){
                $('#loaderaa_image').show();
                $.ajax({
                        type: "POST",
                        url: base_url+"admin/garage/changepassword",
                        data:"garage_id="+garage_id,
                        success: password_update_success
                        }
                   );
            }
            		  
                              
        });
        function password_update_success(ret){
            $('#pwd_msg').html(ret);
        }


	         //$('#password_reset').click(function(){
               //  aler
//
//	         	if(poll_flag==0){
//		            $.ajax({
//						   type: "POST",
//						   url: base_url+"poll/save/yes/"+poll_id,
//						   success: poll_success
//						 });
//
//	         	}else{
//	         		alert("You have already voted.");
//	         	}
		         //});

/* < Polling>*/
        
        
      
		var poll_id =  $('#poll_qn_id').val();
		
	         $('#poll_yes').click(function(){
	         	
	         	if(poll_flag==0){		
		            $.ajax({
						   type: "POST",
						   url: base_url+"poll/save/yes/"+poll_id+"/",
						   success: poll_success
						 }); 
					
	         	}else{
	         		alert("You have already voted.");
	         	}
		         });

	         $('#poll_no').click(function(){
	         	if(poll_flag==0){
		         	$.ajax({
						   type: "POST",
						   url: base_url+"poll/save/no/"+poll_id+"/",
						   success: poll_success
						 }); 
	         	}else{
	         		alert("You have already voted.");
	         	}		 
	         });
	         
		 
         /* < /Polling>*/
         /***/
         $('#privacy_policy').colorbox({href:base_url+"privacy_policy",width:'900',height:'100%'});
         $('#tersms_conditions').colorbox({href:base_url+"terms/",width:'900',height:'100%'});
         $('#acceptable_use_policy').colorbox({href:base_url+"user_policy/",width:'900',height:'100%'});
         $('#ipad_terms_conditions').colorbox({href:base_url+"win_terms/",width:'900',height:'100%'});
        $('#cboxClose').remove();
});
function poll_success(resp){
//    var answer = resp.split('#');
//    var yes = parseInt(answer[0]);
//    var no  = parseInt(answer[1]);
//    var total = yes+no;
//    var yes_percentage =Math.round( (yes/total)*100);
//    var no_percentage = Math.round((no/total)*100);

	if(resp){
		poll_flag++;
	    var theURL=base_url+'poll/show_graph/'+resp;
	    var winName="Poll Graph";
	    var features='scrollbars=yes,width=490,height=420';	
	    $('#graph_body').html(resp);
		$('#graph_id').fadeIn(600);

		//window.open(theURL,winName,features); 	 
	}

//	if(resp>0){
//		poll_flag++;
//		alert("Your vote saved successfully.");
//	}
}
function close_graph(){
	$('#graph_id').fadeOut(600);
}
function submit_bottom_filter(){
	if($.trim($('#txt_garage_search').val())){
		$('#txt_garage_filter').val($.trim($('#txt_garage_search').val()));
		$('#frm_garage_filter').attr('action',base_url+'garage/search/p');
		$('#frm_garage_filter').submit();
	}else{
		$('#txt_garage_search_bottom').focus();
	}
}
function __fncShowprivacypolicyPopUp(page){
		URL = page;
		day = new Date();
		id1 = day.getTime();
		eval("page" + id1 + " = window.open(URL, '" + id1 + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=840,height=700,left = 10,top = 10');");
	}
    function scrollBottom(){
        window.scroll(0,$(document).height());
    }
    function go_misfuelling(){
        if(confirm('You are now being redirected to an external website\nPlease click OK to continue')) return true; else return false;
    }
    
    function isValidDate(dateStr) {
		// Checks for the following valid date formats:
		// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
		// Also separates date into month, day, and year variables
		
		//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
		
		// To require a 4 digit year entry, use this line instead:
	    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		
		var matchArray = dateStr.match(datePat); // is the format ok?
		if (matchArray == null) {
		alert("Date is not in a valid format.")
		return false;
		}
		month = matchArray[3]; // parse date into variables
		day = matchArray[1];
		year = matchArray[4];
		
		if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		return false;
		}
		
		if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		return false;
		}
		
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
		return false
		}
		if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
		alert("February " + year + " doesn't have " + day + " days!");
		return false;
		   }
		}
		return true;  // date is valid
	}

