/*
 * jQuery event and object bindings
 * Synthesis
 * 
 */
  	j=jQuery.noConflict();
	j(document).ready(function(j){
		/*j( '#accordion' ).accordion({
				collapsible: true,
				active: 'false', 	
				autoHeight: false
			});*/
		
			// validate signup form on keyup and submit
			j("form#ValidateForm").validate({
				rules: {
					firstname: "required",
					lastname: "required",
					username: {
						required: true,
						minlength: 2
					},
					password: {
						required: true,
						minlength: 5
					},
					confirm_password: {
						required: true,
						minlength: 5,
						equalTo: "#password"
					},
					email: {
						//required: true,
						email: true
					},
					topic: {
						required: "#newsletter:checked",
						minlength: 2
					},
					agree: "required"
				},
				messages: {
					firstname: "Please enter your firstname",
					lastname: "Please enter your lastname",
					username: {
						required: " Please enter a username",
						minlength: "Your username must consist of at least 2 characters"
					},
					password: {
						required: "&nbsp;Please provide a password",
						minlength: "&nbsp;Your password must be at least 5 characters long"
					},
					confirm_password: {
						required: "&nbsp;Please provide a password",
						minlength: "&nbsp;Your password must be at least 5 characters long",
						equalTo: "&nbsp;Please enter the same password as above"
					},
					cate: "&nbsp;Please select a category",
					language: "&nbsp;Please select a language",
					title: "&nbsp;Please enter a title",
					email: "&nbsp;Please enter a valid email address",
					agree: "Please accept our policy"
				}
			});
			
			
			j("form#ValidateBookForm").validate({
				rules: {
					fullname: "required",
					mobile: "required",
					city: "required",
					email: {
						//required: true,
						email: true
					},
					topic: {
						required: "#newsletter:checked",
						minlength: 2
					},
					agree: "required"
				},
				messages: {
					fullname: "&nbsp;!",
					mobile: "&nbsp;!",
					city: "&nbsp;&nbsp;!",
					email: "&nbsp;!",
					agree: "Please accept our policy"
				}
			});


			// Other configurations here
			//alert("Other Specifications");
			
			j(".carModels").change(function(){
				
				var selectedModel=j(".carModels option:selected").val();
				
				if(j(".carModels option:selected").attr("id")=="ES Hybrid"){
					j("#galleryLink").attr("href","site-gallery-16-en.php");
					}
				
				var carID=j(".carID").html();
    			var data="modelID="+selectedModel+"&action=getAllGrades&carID="+carID; 
				  j.ajax({
				  url: "actionController.php",
				  type:"POST",
				  data:data,
				  success: function(a){
					  
					  j(".allGradesPlace").html(a);
					  }
				  });
			});
		}
	);
	
	function refreshSpecs(){
		
		if(j("#CRVTYPE").length>0){
			var selectedModel=j(".carModels option:selected").attr('id');
			var fuelType=j("#grades option:selected").attr('id');
			
			if(selectedModel=="EX"){
				if(j("#grades option:selected").hasClass("SP")){
					j(".GradeDescription").html("<u>In addition to the EX features, the EX Safety Pack comes with the following</u>:<ul><li>Adaptive cruise control</li><li>Collision Mitigation Breaking System</li><li>AFS Lights</li></ul>");
				
					j(".GradeDescription").show();
				}
				else{
					j(".GradeDescription").hide();
					/*if(fuelType=="Petrol"){
						//j(".GradeDescription").html("").show();
						j(".GradeDescription").html("<u>In addition to the EX features the EX Safety Pack comes with</u>:<ul><li>Adaptive cruise control</li><li>Collision Mitigation Breaking System</li><li>AFS Lights</li></ul>").show();
					}else if(fuelType=="Diesel"){
						//j(".GradeDescription").html("").show();
						j(".GradeDescription").html("<u>in addition to the EX features the EX Safety Pack comes with Adaptive cruise control</u>:<ul><li>Adaptive cruise control</li><li>Collision Mitigation Breaking System</li><li>AFS Lights</li>	<li>Leather seats</li><li>Heated front seats</li><li>Automatic headlights with dusk sensors</li><li>Rain sensing windscreen wipers</li><li>Panoramic roof</li></ul>").show();
					}*/
					
				}
			}
			else {
				j(".GradeDescription").hide();
			}
		}
			
			
		var selectedVal=j("#grades option:selected").val();
		var data="gradeID="+selectedVal+"&action=refreshSpecs";
		var refreshSp=j.ajax({
		  url: "actionController.php",
		  type:"POST",
		  data:data,
		  success: function(a){
		  refreshBros(selectedVal);
		  j(".demo").html("");
		  j(".demo").html(a);
		  j( '#accordion' ).accordion({
			collapsible: true,
			active: 'false', 	
			autoHeight: false
			});
		  }
		});
		j("").ajaxStart(function(){
		j(".demo").html("<img src='template/images/loading.gif'>");
			});
		}
	function refreshBros(selectedVal){
		var data="gradeID="+selectedVal+"&action=refreshBros";
		
		
		var refreshSp=j.ajax({
		  url: "actionController.php",
		  type:"POST",
		  data:data,
		  success: function(a){
		  j(".bros").html(a);
		  }
		});

		}	
		
		
	function changeImage(path,imgSelected){
		j("#"+path).html("<img src='"+imgSelected+"' />");
	}	
