
var MAX_DESC_CHARS = 525;

onload = LimitDescription;

function $(OBJ) {
	return document.getElementById(OBJ);
}

function LimitDescription() {


	if($('00N70000001cyBi').value.length >= MAX_DESC_CHARS ) {
		$('00N70000001cyBi').value = $('00N70000001cyBi').value.substr(0,MAX_DESC_CHARS);
	}

	$('lblCharsLeft').innerHTML = "(" + parseInt(MAX_DESC_CHARS - $('00N70000001cyBi').value.length) + ") characters left";

}

function MoveNextField(OBJ, MAX_LEN, NEXT_OBJ) {

	if( OBJ.value.length >= MAX_LEN ) {
		$(NEXT_OBJ).focus();
		return;
	}

}

function ValidateForm()  {

	if(!CheckObject($('first_name').value,"[a-zA-Z]{2,25}")) { alert('Please enter your first name'); $('first_name').focus(); return; }
	if(!CheckObject($('last_name').value,"[a-zA-Z]{2,25}")) { alert('Please enter your last name'); $('last_name').focus(); return; }
	if(!CheckObject($('DP1').value,"[0-9]{3,3}")) { alert('Please enter your area code'); $('DP1').focus(); return; }
	if(!CheckObject($('DP2').value,"[0-9]{3,3}")) { alert('Please enter your full phone number'); $('DP2').focus(); return; }
	if(!CheckObject($('DP3').value,"[0-9]{4,4}")) { alert('Please enter your full phone number'); $('DP3').focus(); return; }
	if(!CheckObject($('email').value,"([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})")) { alert('Please enter a valid email address'); $('email').focus(); return; }

	if( $('00N70000001cxFj').selectedIndex == 0 ) { alert('Please select the state where you currently live'); $('00N70000001cxFj').focus(); return;}
	if( $('00N70000001yFNz').selectedIndex == 0 ) { alert('Please select the state where the problem is'); $('00N70000001yFNz').focus(); return;}
	if( $('00N70000001cyEm').selectedIndex == 0 ) { alert('Please tell us what the problem is'); $('00N70000001cyEm').focus(); return;}

	//SET PHNOE DATA
	$('phone').value = $('DP1').value + '-' + $('DP2').value + '-' + $('DP3').value;
	//SET MOBILE DATA
	$('mobile').value = $('MP1').value + '-' + $('MP2').value + '-' + $('MP3').value;
	//SET EVENGINE DATA
	$('00N70000001cyE5').value = $('EP1').value + '-' + $('EP2').value + '-' + $('EP3').value;


	//alert('Right here is when the form would submit');
	document.frmOnlineForm.submit();

}

function CheckObject(VALUE, REGEX) {

	r = new RegExp(REGEX);

	return r.test(VALUE);

}