$(document).ready(function(){

	$('#form').submit(function(){
		return validateForm();
		
	});
	$('#other').change(function(){
		showOther();
	});
	
	$('#certificationFloat').scrollFollow();

});

function validateForm(){
	// reset background colors back to normal
	
	var objects = $(".validated");
    objects.each(function(){
    	$(this).css({'background':'#fff','color':'#000'});
    });
    $('input[name=certificationother]').css({'background':'#fff','color':'#000'});
    objects = ""; // clear objects array
    var num = 0; // set num to 0
    
    // validate
    var objects = $(".validated").filter(function(){
    	var ele = $(this);
    	return ele.val() == '';
    });
	
    objects.each(function(){
    	$(this).css({'background':'#ff0000','color':'#fff'});
    	num = 1;
    });
	
    if($('#certificationOtherBox').hasClass("shown")){
    	if($('input[name=Other Certification]').val()==""){
    		num = 1;
    		$('input[name=Other Certification]').css({'background':'#ff0000','color':'#fff'});
    	}
    }
    if($('input[name=ISO 9001 Quality Standard]').attr("checked")==false && $('input[name=ISO 14001 Environmental Standard]').attr("checked")==false && $('input[name=OHSAS 18001 Health & Safety]').attr("checked")==false && $('#other').attr("checked")==false){
    	alert('Please choose a type of certificate.');
    }
    
    if($('#companyemailconfirm').val()!=$('input[name=Company Email]').val()){
    	$('#companyemailconfirm').css({'background':'#ff0000','color':'#fff'});
    }
    
    if(num==1){
//    	$('html, body').animate({scrollTop:0}, 'slow');
    	return false;
	}
}

function showOther(){
	
	var other = $('#other');
	if(other.attr("checked")==true){
		$('#certificationOtherBox').show().addClass("shown");
		$('input[name="Other Certification"]').focus();
	}
	else {
		$('#certificationOtherBox').hide().removeClass("shown");
		$('input[name=Other Certification]').blur();
	}
	
}