var
	cCount=0;
function form_updateDisplay(inSource){
	target = document.getElementById(inSource.id + '_dynamic');
	if (inSource.type!='checkbox'){
		target.innerHTML = inSource.value;
	}else{
		if(inSource.checked){
			switch(cCount){
			case 0:
				target.style.color = '#666666';
				break;
			case 1:
				break;
			default:
				break;
			}
		}else{
			target.style.color = '#CCCCCC';
		}
	}
}

function form_init(){
	_comm_form = document.getElementById('comm_form');
	_comm_company_name = document.getElementById('comm_company_name');
	_comm_form.reset();
	_comm_company_name.focus();
}

var
	firstName = null;

function form_submit(_inForm){
	var
		inForm = document.forms[_inForm];

	switch(inForm.name){
		case 'communicate':
			var
				params = null,
				xForm = new xhttp(),
				loc = 'http://www.webframeworks.com/talk-with-us',
				func = 'processResults',
				errMsg = 'Something Broke!!!';
			
			firstName = escape(document.getElementById('comm_first_name').value);

			coName = 'coName='+escape(document.getElementById('comm_company_name').value);
			cTitle = '&cTitle='+escape(document.getElementById('comm_title').value);
			fName = '&fName='+escape(document.getElementById('comm_first_name').value);
			lName = '&lName='+escape(document.getElementById('comm_last_name').value);
			emailAddr = '&emailAddr='+escape(document.getElementById('comm_email').value);
			phoneNumber = '&phoneNumber='+escape(document.getElementById('comm_phone').value);
			infoManaged = '&infoManaged='+escape(document.getElementById('comm_info_managed').value);
			infoCustom = '&infoCustom='+escape(document.getElementById('comm_info_custom').value);
			infoAnalysis = '&infoAnalysis='+escape(document.getElementById('comm_info_analysis').value);
			infoConsult = '&infoConsult='+escape(document.getElementById('comm_info_consult').value);
			infoContent = '&infoContent='+escape(document.getElementById('comm_info_content').value);
			infoComment = '&infoComment='+escape(document.getElementById('comm_info_comment').value);
			params = '?'+coName+cTitle+fName+lName+emailAddr+phoneNumber+infoManaged+infoCustom+infoAnalysis+infoConsult+infoContent+infoComment;
			
			if(passValidation(inForm)){
				xForm.fetch(loc+params, func, {errorString:errMsg});
				inForm.reset();
			}
		break;
	}
}

function passValidation(theForm){
	var
		fieldCount = theForm.length,
		isValid = null;
		
	for(var i=0;i<fieldCount;++i){
		if(theForm[i].type!='textarea' & theForm[i].type!='submit'){
			if(theForm[i].alt.indexOf('required')>-1){
				if(theForm[i].value=='' | theForm[i].value==null){
					theForm[i].style.backgroundColor = '#FF6600';
					isValid = false;
				}else{
					isValid = true;
				}
			}
		}
	}
	return isValid;
}

function processResults(response){
	var
		comm_response = document.getElementById('comm_response');
	
	comm_response.innerHTML = "Thank you, "+firstName+".<br />We've received your message, and we look forward to speaking with you.";
}

window.onload=form_init;