$(document).ready(function(){
	
	slideSwitch();
	
	// Yhteydenoton lähetys

	$("#yhteydenottopyynto").submit(function(event) {
			
			event.preventDefault();
			
			virhe = 0;
			
			vari = "#fce1e0";
			
			
			
			if($("#nimi").val() == "") {
			
				$("#nimi").css({ background: vari });
				virhe++;
				
			} else {
				
				$("#nimi").css({ background: "#ffffff" });
				
			}
			
			$("#nimi").focus(function() { $(this).css({ background: "#ffffff" }); });
			
			// ---------------------------------------------------------------
			 
			if($("#osoite").val() == "") {
				
					$("#osoite").css({ background: vari });
					virhe++;
					
				} else {
					
					$("#osoite").css({ background: "#ffffff" });
					
				}
				
				$("#osoite").focus(function() { $(this).css({ background: "#ffffff" }); });
				
			// ---------------------------------------------------------------
				
			if($("#postinro").val() == "") {
				
					$("#postinro").css({ background: vari });
					virhe++;
					
				} else {
					
					$("#postinro").css({ background: "#ffffff" });
					
				}
				
				$("#postinro").focus(function() { $(this).css({ background: "#ffffff" }); });
				
			// ---------------------------------------------------------------
			
			if($("#postitoimipaikka").val() == "") {
				
					$("#postitoimipaikka").css({ background: vari });
					virhe++;
					
				} else {
					
					$("#postitoimipaikka").css({ background: "#ffffff" });
					
				}
				
				$("#postitoimipaikka").focus(function() { $(this).css({ background: "#ffffff" }); });
				
			// ---------------------------------------------------------------		
	
			if($("#puhnum").val() == "") {
				
					$("#puhnum").css({ background: vari });
					virhe++;
					
				} else {
					
					$("#puhnum").css({ background: "#ffffff" });
					
				}
				
				$("#puhnum").focus(function() { $(this).css({ background: "#ffffff" }); });
				
			// ---------------------------------------------------------------
			
			if(virhe == 0) {
	
				var rakentaminen = "";
				
				$('input:checkbox[name="Rakentaminen"]:checked').each(function() { 
					
					
					if($(this).attr("value") == "jokin_muu") {
					
						rakentaminen = rakentaminen + $("#RakentaminenOther").attr("value");
						
					} else {
						
						rakentaminen = rakentaminen + $(this).attr("value") + ", ";
					}

				});
				
				var teollisuus = "";
				
				$('input:checkbox[name="Teollisuus"]:checked').each(function() { 
					
					
				if($(this).attr("value") == "jokin_muu") {
					
						teollisuus = teollisuus + $("#TeollisuusOther").attr("value");
						
					} else {
					
						teollisuus = teollisuus + $(this).attr("value") + ", ";
						
					}

				});		

				var laivapalvelut = "";
				
				$('input:checkbox[name="Laivapalvelut"]:checked').each(function() { 
					
					
					if($(this).attr("value") == "jokin_muu") {
					
						laivapalvelut = laivapalvelut + $("#LaivapalvelutOther").attr("value");
						
					} else {
					
						laivapalvelut = laivapalvelut + $(this).attr("value") + ", ";
						
					}

				});
				
				rakentaminen = rakentaminen.substring(0, rakentaminen.length-2);	
				teollisuus = teollisuus.substring(0, teollisuus.length-2);	
				laivapalvelut = laivapalvelut.substring(0, laivapalvelut.length-2);						

				var palaute = 'lomake=yhteyspyynto' + '&rakentaminen='+ rakentaminen + '&teollisuus=' + teollisuus + '&laivapalvelut=' + laivapalvelut + '&nimi=' + $("#nimi").val()  
				+ '&yritys=' + $("#yritys").val() + '&osoite=' + $("#osoite").val()  + '&postinro=' + $("#postinro").val() + '&postitoimipaikka=' + $("#postitoimipaikka").val() + '&puhnum=' + $("#puhnum").val() 
				+ '&sposti=' + $("#sposti").val() + '&jasentunnus=' + $("#jasentunnus").val();
	
				$.ajax({  
					  type: "GET",  
					  url: osoite + "index.php",  
					  data: palaute,  
					  success: function() {			
				
							$("#yhteydenottopyynto").animate({
								
								opacity: 0
								
							}, 500, function () {
									
									$("#yhteydenottopyynto").replaceWith("<h2 style='text-align: center; margin: 25px;'> Kiitos yhteydenotosta! </h2>");
							
							});
							
					  }
				
				});

			}
	 
	});	
	
	// PALAUTELOMAKE
	
	$("#palaute").submit(function(event) {
			
			event.preventDefault();
			
			virhe = 0;
			
			vari = "#fce1e0";
			
			if($("#viesti").val() == "") {
			
				$("#viesti").css({ background: vari });
				virhe++;
				
			} else {
				
				$("#viesti").css({ background: "#ffffff" });
				
			}
			
			$("#viesti").focus(function() { $(this).css({ background: "#ffffff" }); });
			
			if(virhe == 0) {

				var palaute = 'lomake=palaute' + '&viesti=' + $("#viesti").val() + '&nimi=' + $("#nimi").val() + '&osoite=' + $("#osoite").val()  + '&postinro=' + $("#postinro").val() + '&postitoimipaikka=' 
								+ $("#postitoimipaikka").val() + '&puhnum=' + $("#puhnum").val() + '&sposti=' + $("#sposti").val() + '&jasentunnus=' + $("#jasentunnus").val();
		
					$.ajax({  
						  type: "GET",  
						  url: osoite + "index.php",  
						  data: palaute,  
						  success: function() {			
					
								$("#palaute").animate({
									
									opacity: 0
									
								}, 500, function () {
										
										$("#palaute").replaceWith("<h2 style='text-align: center; margin: 25px;'> Kiitos palautteesta! </h2>");
								
								});
								
						  }
					
					});				
	
			}
			
	});
	
	// Kielilinkit

	$("#fi_hover").hover(function() {
								
		$(this).attr("src",osoite + "kuvat/fi_hover.png");
		
	}, function() {
				
		$(this).attr("src",osoite + "kuvat/fi.png");
		
	});
	
	$("#se_hover").hover(function() {
								
		$(this).attr("src",osoite + "kuvat/se_hover.png");
		
	}, function() {
				
		$(this).attr("src",osoite + "kuvat/se.png");
		
	});
	
	$("#en_hover").hover(function() {
								
		$(this).attr("src",osoite + "kuvat/en_hover.png");
		
	}, function() {
				
		$(this).attr("src",osoite + "kuvat/en.png");
		
	});
	
});

