/* Spruceland JavaScript */

window.addEvent('domready', function() {
		
	// Smooth Scroll page links
	var mySmoothScroll = new SmoothScroll();
	
	
	// if employmentForm
	if ($('employmentForm')) {
		
		// hide the referred by
		var referredByContainer = new Fx.Slide('referredByContainer').hide();
		if($('referred').get('value') == "Yes"){
			referredByContainer.slideIn();
		}
		
		// Toggle the referredBy container
		$('referred').addEvent('change', function() {
			if ($('referred').value =="No"){
				referredByContainer.slideOut();
			}
			if ($('referred').value =="Yes"){
				referredByContainer.slideIn();
			}
		});
		
		employmentCheck = function (){
		
			if($('firstName').get('value') == ""){ 
				alert("Please provide your first name.");
				$('firstName').focus();
				return false;
			}
			
			if($('lastName').get('value') == ""){ 
				alert("Please provide your last name.");
				$('lastName').focus();
				return false;
			}
			
			if($('phone').get('value') == ""){
				alert("Please provide your phone number.");
				$('phone').focus();
				return false;
			}
			
			var phoneValue = $('phone').get('value');
			var phoneFilter  = /^\(\d{3}\) ?\d{3}( |-)?\d{4}|^\d{3}( |-)?\d{3}( |-)?\d{4}/;
			if(phoneValue != ""){
				if (!phoneFilter.test(phoneValue)) {
					alert('Incorrect phone format. Enter your 10 digit phone number.');
					$('phone').focus();
					return false;
				}
			}
			
			if($('address').get('value') == ""){
				alert("Please provide your home address.");
				$('address').focus();
				return false;
			}
		
			if($('city').get('value') == ""){
				alert("Please provide your city.");
				$('city').focus();
				return false;
			}
					
			if($('province').get('value') == ""){
				alert("Please provide your province.");
				$('province').focus();
				return false;
			}
		
			if($('postalCode').get('value') == ""){
				alert("Please provide your postal code.");
				$('postalCode').focus();
				return false;
			}
			
			var pcValue = $('postalCode').get('value');
			var pcFilter  = /^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}(\-| |){1}[0-9]{1}[a-zA-Z]{1}[0-9]{1}$/;
				if(pcValue != ""){
					if (!pcFilter.test(pcValue)) {
						alert("Incorrect postal code format. H0H 0H0");
						$('postalCode').focus();
						return false;
					}
				}
				
			if($('position').get('value') == ""){
				alert("Please tell us which position you are applying for.");
				$('position').focus();
				return false;
			}
			
			if($('referred').get('value') == "Yes"){
				if($('referredBy').get('value') == ""){
					alert("Please tell us who referred you to this job opening.");
					$('referredBy').focus();
					return false;
				}
			}
			
			if($('agree').checked == false){
				alert("You must agree to the drug testing terms.");
				$('agree').focus();
				return false;
			}		
			
			if($('wsp_code').get('value') == ""){
				alert('Enter the Anti Spam code. 5 lowercase letters');
				$('wsp_code').focus();
				return false;
			}
			
			return true;
			
		} // end employmentCheck function
		
	} // end if employmentForm
	
	
	
	
	
	
	// if requestForm
	if ($('requestForm')) {
		
		// If All Information is checked... then deselect the rest of them
		$('allInfo').addEvent('change', function() {
			if ($('allInfo').checked == true){
				$('productDetails').checked = false;
				$('pricingInfo').checked = false;
				$('packagingAndShippingInfo').checked = false;
			}
		});
		
		
		infoRequestCheck = function (){
		
			if($('fullName').get('value') == ""){ 
				alert("Please provide your name.");
				$('fullName').focus();
				return false;
			}
			
			if($('company').get('value') == ""){ 
				alert("Please provide your company name.");
				$('company').focus();
				return false;
			}
			
			if($('phoneNumber').get('value') == ""){
				alert("Please provide your phone number.");
				$('phoneNumber').focus();
				return false;
			}
			
			if($('email').get('value') == ""){
				alert("Please provide your email address.");
				$('email').focus();
				return false;
			}
			
			var emailValue = $('email').get('value');
			var emailFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(emailValue != ""){
				if (!emailFilter.test(emailValue)) {
					alert("It appears your email address is formatted incorrectly.");
					$('email').focus();
					return false;
				}
			}
			

			var productListCheckBoxTotal = 0; // checkbox counter
		
			// tagName is referenced as a CAPITALIZED value
			var obj = $('productList').getElementsByTagName('INPUT');
		
			for (i=0; i<obj.length; i++) {
				// type is referenced as a lowercase value
				if (obj[i].type == 'checkbox') {
					if (obj[i].checked == true) {
						productListCheckBoxTotal++;
		  			}
		  		}
			}
			
			if(productListCheckBoxTotal == 0) {
				alert("You must choose at least one product to request information for.");
				$('fjStudsAndStrips').focus();
				return false;
			}
			
			
			var infoTypeCheckBoxTotal = 0; // checkbox counter
		
			// tagName is referenced as a CAPITALIZED value
			var obj = $('infoType').getElementsByTagName('INPUT');
		
			for (i=0; i<obj.length; i++) {
				// type is referenced as a lowercase value
				if (obj[i].type == 'checkbox') {
					if (obj[i].checked == true) {
						infoTypeCheckBoxTotal++;
		  			}
		  		}
			}
			
			if(infoTypeCheckBoxTotal == 0) {
				alert("Please tell us what type of information you are looking for.");
				$('productDetails').focus();
				return false;
			}
			
			
			if($('purchasedBeforeNo').checked == false && $('purchasedBeforeYes').checked == false) {
				alert("Please tell us if you have purchased from us in the past.");
				$('purchasedBeforeNo').focus();
				return false;
			}
			
		
			if($('wsp_code').get('value') == ""){
				alert('Enter the Anti Spam code. 5 lowercase letters');
				$('wsp_code').focus();
				return false;
			}
			
			return true;
			
		} // end infoRequestCheck function
		
	} // end if requestForm
	
	
	
	
}); // Close DomReady function




	
	




