//validation for the newsletter module
//newsletter and contact validation functions must be seperated due to both forms existing on the page at the same time.
function verifyRequired() {
  if (document.icpsignup["fields_email"].value == "email" || document.icpsignup["fields_email"].value == "") {
	document.icpsignup["fields_email"].focus();
	alert("The Email field is required.");
	return false;
  }
  if (document.icpsignup["fields_fname"].value == "first name" || document.icpsignup["fields_fname"].value == "") {
	document.icpsignup["fields_fname"].focus();
	alert("The First Name field is required.");
	return false;
  }
  if (document.icpsignup["fields_lname"].value == "last name" || document.icpsignup["fields_lname"].value == "") {
	document.icpsignup["fields_lname"].focus();
	alert("The Last Name field is required.");
	return false;
  }
return true;
}

//validation for the contact forms
function contactValidation() {
	
		  if (document.getElementById('Salutation').value == "") {
			document.getElementById('Salutation').focus();
			alert("Salutation is required.");
			return false;
		  }
		  
		  if (document.getElementById('FirstName').value == "") {
			document.getElementById('FirstName').focus();
			alert("First Name is required.");
			return false;
		  }
		  
		  if (document.getElementById('LastName').value == "") {
			document.getElementById('LastName').focus();
			alert("Last Name is required.");
			return false;
		  }
		  
		  if (document.getElementById('Phone').value != "") { //if the field is not empty check for valid email format
				var phoneFilter = /((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}/; //matches (123) 456-7890 or 123-456-7890
				var str = document.getElementById('Phone').value;
					if (phoneFilter.test(str)) {//if it is a match
					
						//do nothing and proceed to the next rule or submit form
						
					} else { //if not a match
						document.getElementById('Phone').focus();
						alert("Phone Number format not accepted. Hint: (123) 456-7890 or 123-456-7890");
						return false;
					}
			
		  } else { //if the field is empty
			document.getElementById('Phone').focus();
			alert("Phone Number is required.");
			return false;
		  } //end phone field not empty
		  
		  		  
		  if (document.getElementById('Email').value != "") { //if the field is not empty check for valid email format
				var emailFilter = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/; //joe@aol.com | joe@wrox.co.uk | joe@domain.info
				var str = document.getElementById('Email').value;
					if (emailFilter.test(str)) {//if it is a match
					
						//do nothing and proceed to the next rule or submit form
						
					} else { //if not a match
						document.getElementById('Email').focus();
						alert("Email format not accepted. Hint: yourname@domain.com");
						return false;
					}
			
		  } else { //if the field is empty
			document.getElementById('Email').focus();
			alert("Email is required.");
			return false;
		  } //end email field not empty
		  
		  if (document.getElementById('BestTimeToCall').value == "") {
			document.getElementById('BestTimeToCall').focus();
			alert("Best Time to Call is required.");
			return false;
		  }
		  
		  if (document.getElementById('Company').value == "") {
			document.getElementById('Company').focus();
			alert("Company Name is required.");
			return false;
		  }

return true; //if everything is ok submit the form
}

// initialise jquery plugins
	$(document).ready(function(){
	
	//Capitalize Input Field Values
	$('#fields_fname').capitalize();
							   
	
	//superfish menu
	$("ul.sf-menu").supersubs({ 
	minWidth:    12,      // minimum width of sub-menus in em units 
	maxWidth:    27,     // maximum width of sub-menus in em units 
	extraWidth:  1      // extra width can ensure lines don't sometimes turn over 
					   // due to slight rounding differences and font-family 
	}).superfish();   // call supersubs first, then superfish, so that subs are 
					 // not display:none when measuring. Call before initialising 
					// containing tabs for same reason.
					 
	//clearing inputs
	$('form#login #username').clearingInput({text: 'username'}, {blurClass: 'blur'});
	$('form#login #password').clearingInput({text: 'password'}, {blurClass: 'blur'});
	$('form#newsletterFrm #fields_fname').clearingInput({text: 'first name'}, {blurClass: 'blur'});
	$('form#newsletterFrm #fields_lname').clearingInput({text: 'last name'}, {blurClass: 'blur'});
	$('form#newsletterFrm #fields_email').clearingInput({text: 'email'}, {blurClass: 'blur'});
		
	//easy slider enewsletterblog
	if($("#enewsletterblog").length < 0) { //if the element id does not exist then execute code
			$("#masthead").easySlider({
			auto: true
			});
		}
			
	//cufon config
	//Please note. Line height properties don't work in ie.
	Cufon.replace('h1', { fontFamily: 'Sansation' });
	Cufon.replace('h2', { fontFamily: 'Sansation' });
	Cufon.replace('h3', { fontFamily: 'Sansation' });
	Cufon.replace('ul.sf-menu li a.topLevel', { fontFamily: 'Sansation' });
	Cufon.replace('.smallType', { fontFamily: 'Redensek' });
	
	
	
	
	//image border hover
	$("img.imgBorder").hover(
	  function () {
		$(this).addClass("imgBorderOvr");
	  },
	  function () {
		$(this).removeClass("imgBorderOvr");
	  }
	);
	
	
		//play sound with only one player visable
		$("#sound01").click(function(){
			var url = "assets/song-samples/Angels We Have Heard On High.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Angels We Have heard On High</span>");
		});
		
		$("#sound02").click(function(){
			var url = "assets/song-samples/Auld Lang Syne.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Auld Lang Syne</span>");
		});
		
		$("#sound03").click(function(){
			var url = "assets/song-samples/Away In A Manger.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Away In A Manger</span>");
		});
		
		$("#sound04").click(function(){
			var url = "assets/song-samples/Deck The Halls.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Deck The Halls</span>");
		});
		
		$("#sound05").click(function(){
			var url = "assets/song-samples/Good King Wenceslas.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Good King Wencesias</span>");
		});
		
		$("#sound06").click(function(){
			var url = "assets/song-samples/Greensleeves.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Greensleeves</span>");
		});
		
		$("#sound07").click(function(){
			var url = "assets/song-samples/Hanukkah Oh Hanukkah.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\"width=\"200\"> <span class=\"small\">Hanukka Oh Hanukkah</span>");
		});
		
		$("#sound08").click(function(){
			var url = "assets/song-samples/Hark The Herald Angels.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Hark The Herald Angels Sing</span>");
		});
		
		$("#sound09").click(function(){
			var url = "assets/song-samples/It Came Upon A Midnight Clear.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">It Came Upon A Midnight Clear</span>");
		});
		
		$("#sound10").click(function(){
			var url = "assets/song-samples/Jingle Bells.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Jingle Bells</span>");
		});
		
		$("#sound11").click(function(){
			var url = "assets/song-samples/Joy To The World.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Joy To The World</span>");
		});
		
		$("#sound12").click(function(){
			var url = "assets/song-samples/Little Town Of Bethlehem.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Little Town of Bethlehem</span>");
		});
		
		$("#sound13").click(function(){
			var url = "assets/song-samples/O Come All Ye Faithful.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">O Come All Ye Faithful</span>");
		});
		
		$("#sound14").click(function(){
			var url = "assets/song-samples/Oh Christmas Tree.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Oh Christmas Tree</span>");
		});
		
		$("#sound15").click(function(){
			var url = "assets/song-samples/Oh Holy Night.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Oh Holy Night</span>");
		});
		
		$("#sound16").click(function(){
			var url = "assets/song-samples/Silent Night.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Silent Night</span>");
		});
		
		$("#sound17").click(function(){
			var url = "assets/song-samples/Three Sisters Suite.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">Three Sisters Suite</span>");
		});
		
		$("#sound18").click(function(){
			var url = "assets/song-samples/We Wish You A Merry Christmas.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">We Wish You A Merry Christmas</span>");
		});
		
		$("#sound19").click(function(){
			var url = "assets/song-samples/What Child Is This.mp3";
			$("#player").html("<embed src='"+url+"' type=\"audio/mpeg\" height=\"18\" width=\"200\"> <span class=\"small\">What Child Is This</span>");
		});
		
		
		
		//Scroll To - affects all anchor tags
		if($(".localScroll").length > 0) { //if the element class exist then execute code
			$.localScroll({
			duration: 2000
			});
		}
		
		
		//form controls for contact-request-quote.asp
		$("input#whenToStart").hide();
		$("input#lookingForService").hide();
		$("div#additionalInfo").hide();
		
		$("input:radio[name=11. Looking for Service]").change(function(){
			switch ($(this).val()) {
				case 'Other':
				$("input#lookingForService").fadeIn(500);
				break;
				
				default:
				$("input#lookingForService").fadeOut(250).val("");
			}
		});
		
		$("input:radio[name=12. When to Start]").change(function(){
			switch ($(this).val()) {
				case 'Other':
				$("input#whenToStart").fadeIn(500);
				break;
				
				default:
				$("input#whenToStart").fadeOut(250).val("");
			}
		});
		
		
		//Form Controls for contact-request-call.asp
		$("input#supplyAdditionalInfo").click(function(event) {
				event.preventDefault();
				$("div#additionalInfo").fadeIn(500);
		})
		
		
		//Form Controls for right-col-ecard.asp
		$("input#removeMusic").change(function(){
			window.location = "ecard-confirmation.asp?removeMusic=true";
		 });
		
		$("input#removeStationery").change(function(){
			window.location = "ecard-confirmation.asp?removeStationery=true";
		 });
		
		
		
		
		//ecard estimate form
		
		if ($("#numberOfSignaturesDiv").length > 0) { //if the element exists
			$("#numberOfSignaturesDiv").hide(); // hide it
			$("input#logoSignature").click(function() {
				if($(this).is(":checked")) {
				$("#numberOfSignaturesDiv").fadeIn("slow").css({"margin-top" : "18px", "margin-bottom" : "18px"}); //show if checked
				} else {
				$("#numberOfSignaturesDiv").fadeOut("fast").css({"margin-top" : "18px", "margin-bottom" : "18px"}); //hide if not checked
				}
			});
		}
		
		
		
		if ($("#numberOfRecipientsDiv").length > 0) { //if the element exists
			$("#numberOfRecipientsDiv").hide(); // hide it
			$("input#emailRecipients").click(function() {
				if($(this).is(":checked")) {
				$("#numberOfRecipientsDiv").fadeIn("slow").css({"margin-top" : "18px"}); //show if checked
				} else {
				$("#numberOfRecipientsDiv").fadeOut("fast").css({"margin-top" : "18px"}); //hide if not checked
				}
			});
		}
		
		



			
	
	
	}); //end document ready function