$(document).ready(function() {
	initform();
});

function initform() {

	if (document.getElementById("colmatch")) {

		// colour match
		$("#colmatch").hide(0);
		$("#dooityourself").hide(0);

		// set a flag on the hidden element
		document.getElementById("colmatch").amioff = true;
		document.getElementById("dooityourself").amioffnow = true;

		// set the onchange handler for the colour match option
		$("#fmdesign").change(function () {

			// colour match block
			if ($("#fmdesign").attr("value") == "ReverseKnot" || $("#fmdesign").attr("value") == "PersonalPics" ||	$("#fmdesign").attr("value") == "ButterflyBreeze" || $("#fmdesign").attr("value") == "ChocolateParadise" || $("#fmdesign").attr("value") == "SummerKnot") {
				if (document.getElementById("colmatch").amioff) {
					$("#colmatch").fadeIn("slow");
					document.getElementById("colmatch").amioff = false;
				}
			}
			else if (!document.getElementById("colmatch").amioff) { 
				$("#colmatch").fadeOut("slow");
				document.getElementById("colmatch").amioff = true;
				document.getElementById("colcheck").checked = false;
			}

			// DIY block
			if ($("#fmdesign").attr("value") == "ElegantLily" || $("#fmdesign").attr("value") == "PinkGerbera" ||	$("#fmdesign").attr("value") == "OrangeGerbera" || $("#fmdesign").attr("value") == "VelvetRose" || $("#fmdesign").attr("value") == "WhiteRose" || $("#fmdesign").attr("value") == "PinkHearts" || $("#fmdesign").attr("value") == "RedHearts" || $("#fmdesign").attr("value") == "Daisy" || $("#fmdesign").attr("value") == "BlackWhiteDaisy" || $("#fmdesign").attr("value") == "PinkRoses" || $("#fmdesign").attr("value") == "PurpleHaze" || $("#fmdesign").attr("value") == "RedKnot" || $("#fmdesign").attr("value") == "MoodIndigo" || $("#fmdesign").attr("value") == "PurplePassion" || $("#fmdesign").attr("value") == "RedPassion" || $("#fmdesign").attr("value") == "Cosmopolitan" || $("#fmdesign").attr("value") == "PinkMelt") {
				if (document.getElementById("dooityourself").amioffnow) {
					$("#dooityourself").fadeIn("slow");
					document.getElementById("dooityourself").amioffnow = false;
				}
			}
			else if (!document.getElementById("dooityourself").amioffnow) { 
				$("#dooityourself").fadeOut("slow");
				document.getElementById("dooityourself").amioffnow = true;
				if (document.getElementById("wordingsection").amioffcheck) { 
					$("#wordingsection").fadeIn("slow");
					document.getElementById("wordingsection").amioffcheck = false;
					document.getElementById("diycheck").checked = false;
				}
			}

		});

	}

	if (document.getElementById("fontmatch")) {

		// fonts
		$("#fontmatch").hide(0);

		// set a flag on the hidden element
		document.getElementById("fontmatch").amiofffonts = true;

		// set the onchange handler for the colour match option
		$("#fmfont").change(function () {
			if (document.getElementById("fontmatch").amiofffonts &&
				($("#fmfont").attr("value") == "Other")) {
				
				$("#fontmatch").fadeIn("slow");
				document.getElementById("fontmatch").amiofffonts = false;
			}
			else if (!document.getElementById("fontmatch").amiofffonts) { 
				$("#fontmatch").fadeOut("slow");
				document.getElementById("fontmatch").amiofffonts = true;
			}
		});
	}


	if (document.getElementById("howmatch")) {

		// fonts
		$("#howmatch").hide(0);

		// set a flag on the hidden element
		document.getElementById("howmatch").amioffhow = true;

		// set the onchange handler for the colour match option
		$("#fmhow").change(function () {
			if (document.getElementById("howmatch").amioffhow &&
				($("#fmhow").attr("value") == "other")) {
				
				$("#howmatch").fadeIn("slow");
				document.getElementById("howmatch").amioffhow = false;
			}
			else if (!document.getElementById("howmatch").amioffhow) { 
				$("#howmatch").fadeOut("slow");
				document.getElementById("howmatch").amioffhow = true;
			}
		});
	}

	if (document.getElementById("wordingsection")) {

		// set a flag on the hidden element
		document.getElementById("wordingsection").amioffcheck = false;

		// set the onchange handler for the colour match option
		$("#diycheck").change(function () {

			if (!document.getElementById("wordingsection").amioffcheck) {
				$("#wordingsection").fadeOut("slow");
				document.getElementById("wordingsection").amioffcheck = true;
			}
			else if (document.getElementById("wordingsection").amioffcheck) { 
				$("#wordingsection").fadeIn("slow");
				document.getElementById("wordingsection").amioffcheck = false;
			}
		});
	}
}