   var errorIds = [];

	function validate(){

		var errors = {'general':[], 'cover':[], 'bolt':[], 'weld':[], 'other':[]};
		for(var i=0; i < errorIds.length; i++){
			getById( errorIds[i]+"-label" ).style.color = "";
		}
		errorIds.clear();

		//-- check general
		var temp = trim(getById('firstName').value);
		if( !temp || !temp.length ){
			errors['general'].push('Please enter a first name');
			errorIds.push('firstName');
		}

		temp = trim( getById('lastName').value );
		if( !temp || !temp.length ){
			errors['general'].push('Please enter a last name');
			errorIds.push('lastName');
		}

		if( !validateEmail( getById('email').value) ){
			errors['general'].push('Please enter a valid email address');
			errorIds.push('email');
		}
		
		temp = trim (getById('phone').value );
		if( !temp || !temp.length ){
			errors['general'].push('Please enter your phone number');
			errorIds.push('phone');
		}
		
		temp = getById("leadsource").options[ getById("leadsource").selectedIndex ].value;
		if( temp == -1 ){
			errors['general'].push("Please select your referral source");
			errorIds.push("leadsource");
		}
		
		//-- check for quote
		var type = getById('inquiryType').value;
		if( type == 'quote' ){
			//-- check cover section

			if( !isNum( getById("flangediameter").value )
				&& !isNum(getById('flangecircumference').value) ){
				errors['cover'].push("Please enter a decimal number for the flange diameter or circumference");
				errorIds.push('flangediameter');
			}

			if( !isInt( getById('numbolts').value ) ){
				errors['cover'].push('Please enter the number of bolts for the cover');
				errorIds.push('numbolts');
			}

			if( !isNum(getById('coverthickness').value) ){
				errors['cover'].push("Please enter a decimal number for the cover thickness");
				errorIds.push('coverthickness');
			}

			if( getSelVal('covershape') == "-1" ){
				errors['cover'].push("Please select the appropriate cover shape");
				errorIds.push('covershape');
			}

			if( !isNum(getById('flangethickness').value) ){
				errors['cover'].push("Please enter a decimal number for the flange thickness");
				errorIds.push('flangethickness');
			}

			if( getSelVal('fastenertype') == "-1") {
				errors['cover'].push("Please select the approproate cover fastener");
				errorIds.push('fastenertype');
			}
		}

		var hasError = false;
		var text = "<h4 class='error heading'>Please correct the following errors before continuing.</h4><ul class='error'>";
		for(var name in errors){
			if( errors[name].length ){
				hasError = true;
				text += "<li>" + errors[name].join("</li><li>")+"</li>";
			}
		}

		if( hasError )
			getById('errors').innerHTML = text+"</ul>";

		for(var i=0; i < errorIds.length; i++){
			getById( errorIds[i]+"-label" ).style.color = "#C00";
		}

		scroll(0,0);
		return !hasError;
	}

	function getById(id){ return document.getElementById(id); }

	function getSelVal(id){
		var index = getById(id).selectedIndex;
		return getById(id).options[index].value;
	}

	function trim(str){
		return str ? str.replace(/(^\s+)|(\s+$)/g,'') : null;
	}

	function isEmpty(str){
		str = trim(str);
		return str == null || str == "";
	}

	function isNum(val){
		return !isEmpty(val) && !isNaN(val) && val.indexOf("-") == "-1";
	}

	function isInt(val){ return isNum(val) && val.indexOf(".") == "-1"; }


	function validateEmail(address){
		return address &&  (/^[0-9A-z_-]+(\.?[0-9A-z_-]+)*@([0-9A-z_-]+\.)+[A-z]{2,}$/).test(address);
	}

	var tabs = {
		'general':['generalHeader', 'personalSection', 'inqSubmitBtn'],
		'quote':['quoteHeader','personalSection','coverSection', 'inqSubmitBtn'],
		'order':['orderHeader']};
	var sections = ['generalHeader', 'personalSection', 'quoteHeader', 'orderHeader', 'coverSection', 'inqSubmitBtn'];

	function activateTab(id){

		for(var name in tabs){
			getById(name+"Tab").className = name == id ? "tab active" : "tab";
		}

		getById('inquiryType').value = id;

		var targetSections = tabs[id];
		if( !targetSections ) return;

		for(var i=0; i < sections.length; i++){
			var found = false;
			for(var j=0; j < targetSections.length; j++){
				if( sections[i] == targetSections[j]){
					found = true;
					break;
				}
			}
			getById(sections[i]).style.display = found ? "" : "none";
		}
	}

	function showHelp(name, show){
		if( show == undefined ) show = true;

		var n = getById(name+"-help");
		if( n ) { n.style.display = show ? "" : "none"; }
	}

	function slideHelp(id, show){
		if( show == undefined ) show = true;

		var n = getById(id+"-help");
		if( !n || (n.style.display == "none" && !show || n.style.display != "none" && show )) return;
		if( show )  new Effect.SlideDown(n, {duration:1});
		else new Effect.SlideUp(n, {duration:1});
   }

	function init(){
   	activateTab('general');
  }
