// JavaScript Document
$(document).ready(function(){
	$('.sect').each(function(){
		var height = $(this).height();
		$(this).attr('rel',height);
		setTimeout(function(){
			$('.sect-2').addClass('closed');
			$('.sect-3').addClass('closed');
		},500);
	});
	
	$('#quote-step-1').live('click',function(){
		var traditional_modular = $('.sect-1 input:checked').attr('value');
		var height = $('.sect-2').attr('rel');
		$('.sect-1').css('borderBottom','1px dotted #726f6f');
		$('.sect-2').animate({height:height},1500,function(){
			$('.sect-2').removeClass('closed');
		})
		$('.sect-2 h4').html(traditional_modular.toUpperCase()+' <span>Stand Selected</span>');
		$('.sect-3 h4').html(traditional_modular.toUpperCase()+'  Stand <span>- <span id="location"></span> - <span id="m2"></span>m<sup>2</sup></span>');
		$('.sect-1 input').attr('disabled','disabled');
		return false;
	});
	
	$('#quote-step-2').click(function(){
		$('#quote-step-1').fadeOut();
		$('#quote-step-2').fadeOut();
		
		var step2fail = false;
		var width = $('.sect-2 input[name|="width"]');
		var height = $('.sect-2 input[name|="height"]');
		
		if(!is_numeric(width.val())||!is_numeric(height.val())){
			if(!is_numeric(width.val())){
				width.css('border','1px solid #ff9c9c');
			}else{ 
				width.css('border','1px solid #a8a7a7'); 
			}
			
			if(!is_numeric(height.val())){
				height.css('border','1px solid #ff9c9c');
			}else{
				height.css('border','1px solid #a8a7a7'); 
			}
			step2fail=true;
		}else{
			step2fail=false;	
		}
		
		if(!step2fail){
			var location = $('.sect-2 select').val();
			$('h4 span#location').html(location.toUpperCase());
			
			var width = $('.sect-2 input[name|="width"]');
			var height = $('.sect-2 input[name|="height"]');
			
			width.css('border','1px solid #a8a7a7'); 
			height.css('border','1px solid #a8a7a7'); 
			
			var m2 = (width.val()*1)*(height.val()*1);
			$('h4 span#m2').html(m2);
			
			var boxheight = $('.sect-3').attr('rel');
			$('.sect-2').css('borderBottom','1px dotted #726f6f');
			$('.sect-3').animate({height:boxheight},1500,function(){
				$('.sect-3').removeClass('closed');
			});
			$('.sect-2 input').attr('disabled','disabled');
			$('.sect-2 select').attr('disabled','disabled');
		}
		return false;
	});
	
	$('#quote-final').click(function(){
		var finalfail = false;
		
		var company = $('.sect-3 input[name|="company"]');
		var phone = $('.sect-3 input[name|="phone"]');
		var name = $('.sect-3 input[name|="name"]');
		var email = $('.sect-3 input[name|="email"]');
		var attending = $('.sect-3 input[name|="attending"]');	
		
		if(company.val()=='' || company.val()=='Company Name'){ finalfail = true; company.css('border','1px solid #ff9c9c'); }else{ company.css('border','1px solid #A8A7A7'); }
		if(!is_numeric(phone.val()) || phone.val()==''){ finalfail = true; phone.css('border','1px solid #ff9c9c'); }else{ phone.css('border','1px solid #A8A7A7'); }
		if(name.val()=='' || name.val()=='Your Name'){ finalfail = true; name.css('border','1px solid #ff9c9c'); }else{ name.css('border','1px solid #A8A7A7'); }
		if(!validate_email(email.val())){ finalfail = true; email.css('border','1px solid #ff9c9c'); }else{ email.css('border','1px solid #A8A7A7'); }
		if(attending.val()=='' || attending.val()=='Exhibition Attending'){ finalfail = true; attending.css('border','1px solid #ff9c9c'); }else{ attending.css('border','1px solid #A8A7A7'); }
		
		if(!finalfail){
			$('.sect-1 input').removeAttr('disabled');
			$('.sect-2 input').removeAttr('disabled');
			$('.sect-2 select').removeAttr('disabled');
			document.forms["quote_form"].submit();	
		}
		
		return false;
	});
});

function is_numeric (mixed_var) {
    return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}
function validate_email(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		return false;
	}else{
		return true;   
	}
}
