var _cfscriptLocation = '/ajax/ehmc/outpatientregistration.cfm';
var registrationid = null;
var policiestosubmit = 0;

/*
function my_error_handler() {
	alert('error');	
}

DWREngine.setErrorHandler(my_error_handler);
*/

function isEmail(s) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(s)){ return true; }
	return false;
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e, nextfield) {
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
	$(nextfield).focus();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;
    while(!found && index < arr.length)
    if(arr[index] == ele)
    found = true;
    else
    index++;
    return found;
  }
  return true;
}

function confirmphsiciansorder(elm) {
	if( elm.value == 'No') {
		$('f0-message').innerHTML = 'Please wait until you have your physician\'s order before submitting your registration.';
		$('f0-message').style.display = 'block';
	}
	else if ( elm.value == 'Yes') {
		$('f0-message').style.display = 'none';
		$('screen-confirmpysicianorder').style.display = 'none';
		$('registrationscreens').style.display = 'block';
	}
}

function startScanUploadCallback() {
	// make something useful before submit (onStart)
	$('scanstatus').innerHTML = 'Order scan upload in progress...';
	return true;
}

function completeScanUploadCallback(filename) {
	$('orderscan').value = filename;
	$('scanstatus').innerHTML = 'Order scan uploaded successfully.';
}

function toggleSecondaryPolicy() {	
	if( $('secondarypolicy').style.display=='' ) {
		$('secondarypolicy').style.display='none';
		$('secondarypolicybutton').value = 'Add Secondary Policy';
	}
	else {
		$('secondarypolicy').style.display='';
		$('secondarypolicybutton').value = 'Remove Secondary Policy';
	}
	return false;
}

function toggleSchedulePreferences() {	
	var val = $RF('f3', 'f3-schedulingpreference');
	if( val == 'First Available' ) {
		$('scheduling-firstchoicerow').style.display='none';
		$('scheduling-secondchoicerow').style.display='none';
		$('scheduling-thirdchoicerow').style.display='none';
	}
	else {
		$('scheduling-firstchoicerow').style.display='';
		$('scheduling-secondchoicerow').style.display='';
		$('scheduling-thirdchoicerow').style.display='';
	}
}

function toggleAccidentClaim() {	
	var val = $RF('f5', 'f5-accidentclaim');
	if( val == 'No' ) {
		$('accidentclaimtable').style.display='none';
	}
	else {
		$('accidentclaimtable').style.display='';
	}
}

function toggletestinfo(testid) {
	if( $('f2-info'+testid) ) {
		if( $('f2-tests'+testid).checked ) {
			$('f2-infodiv'+testid).style.display = 'block';
		}
		else {
			$('f2-infodiv'+testid).style.display = 'none';			
		}
	}
}

function displayscreen(screenid) {
	hidescreens();
	$(screenid).style.display = 'block';
	$(screenid).scrollTo();
}

function hidescreens() {
	$('screen1').style.display = 'none';
	$('screen2').style.display = 'none';
	$('screen3').style.display = 'none';
	$('screen4').style.display = 'none';
	$('screen5').style.display = 'none';
}

function addmapsteplink(stepnum) {
	if( stepnum == 5) {
		str = '<area shape="rect"  coords="337,-2,389,24" href="javascript:displayscreen(\'screen5\');" />';
	}
	else if( stepnum == 4) {
		str = '<area shape="rect"  coords="225,-4,277,22" href="javascript:displayscreen(\'screen4\');" />';
	}
	else if( stepnum == 3) {
		str = '<area shape="rect"  coords="150,-5,202,21" href="javascript:displayscreen(\'screen3\');" />';
	}
	else if( stepnum == 2) {
		str = '<area shape="rect"  coords="72,1,135,27" href="javascript:displayscreen(\'screen2\');" />';
	}
	$('Map').insert(str);
}

function toggletestcategory(i) {
	var listelm = $('testcatlist'+i);
	if(listelm.style.display == 'none') {
		listelm.style.display = 'block';
		$('testcat'+i).addClassName('open');
	}
	else {
		listelm.style.display = 'none';
		$('testcat'+i).removeClassName('open');
	}
}

function verify_f1() {
	var errors = new Array();
	
	if( $('f1-contactperson').value.length < 1 ) {
    	addError(errors, 'f1-label-contactperson', null);
    }
	if( $('f1-contactphoneareacode').value.length < 3 || $('f1-contactphoneprefix').value.length < 3 || $('f1-contactphonesuffix').value.length < 4 ) {
    	addError(errors, 'f1-label-contactphone', null);
    }
	if( $('f1-relationshiptopatient').value.length < 1 ) {
    	addError(errors, 'f1-label-relationshiptopatient', null);
    }
	if( $('f1-firstname').value.length < 1 ) {
    	addError(errors, 'f1-label-firstname', null);
    }
	if( $('f1-lastname').value.length < 1 ) {
    	addError(errors, 'f1-label-lastname', null);
    }
	if( $('f1-birthdate').value.length < 1 ) {
    	addError(errors, 'f1-label-birthdate', null);
    }
	else {
		try {
			var d = parseDateString($('f1-birthdate').value);
		} 
		catch (e) {
			addError(errors, 'f1-label-birthdate', 'invalid date');
		}
	}
	if( $('f1-gender').value.length < 1 ) {
    	addError(errors, 'f1-label-gender', null);
    }
	if( $('f1-address').value.length < 1 ) {
    	addError(errors, 'f1-label-address', null);
    }
	if( $('f1-city').value.length < 1 ) {
    	addError(errors, 'f1-label-city', null);
    }
	if( $('f1-state').value.length < 1 ) {
    	addError(errors, 'f1-label-state', null);
    }
	if( $('f1-zipcode').value.length < 1 ) {
    	addError(errors, 'f1-label-zipcode', null);
    }
	if( $('f1-dayphoneareacode').value.length < 3 || $('f1-dayphoneprefix').value.length < 3 || $('f1-dayphonesuffix').value.length < 4 ) {
    	addError(errors, 'f1-label-dayphone', null);
    }
	var tempphone = $('f1-eveningphoneareacode').value + $('f1-eveningphoneprefix').value + $('f1-eveningphonesuffix').value;
	if( tempphone.length > 1 && tempphone.length < 10 ) {
    	addError(errors, 'f1-label-eveningphone', null);
    }
	if( $('f1-email').value.length < 1 || !isEmail($('f1-email').value) ) {
    	addError(errors, 'f1-label-email', null);
    }
	if( $('f1-verifyemail').value != $('f1-email').value ) {
    	addError(errors, 'f1-label-verifyemail', 'Does not match email address');
    }
	if( $('f1-emergencycontact').value.length < 1 ) {
    	addError(errors, 'f1-label-emergencycontact', null);
    }
	if( $('f1-emergencyphoneareacode').value.length < 3 || $('f1-emergencyphoneprefix').value.length < 3 || $('f1-emergencyphonesuffix').value.length < 4 ) {
    	addError(errors, 'f1-label-emergencyphone', null);
    }
	if( $('f1-emergencycontactrelationship').value.length < 1 ) {
    	addError(errors, 'f1-label-emergencycontactrelationship', null);
    }

	if( errors.length ) {
		displayErrors('f1-message', errors);
		return false;
	}
	else {
		displayscreen('screen2');
		return true;
	}
}


function verify_f2() {
	var errors = new Array();
	
	if( $('f2-havephysicianorder').value.length < 1 ) {
    	addError(errors, 'f2-label-havephysicianorder', null);
    }
	if( $('f2-physicianlastname').value.length < 1 ) {
    	addError(errors, 'f2-label-physicianlastname', null);
    }
	if( $('f2-physicianfirstname').value.length < 1 ) {
    	addError(errors, 'f2-label-physicianfirstname', null);
    }
	if( $('f2-physicianphoneareacode').value.length < 3 || $('f2-physicianphoneprefix').value.length < 3 || $('f2-physicianphonesuffix').value.length < 4 ) {
    	addError(errors, 'f2-label-physicianphone', null);
    }
	/* change this to validate correct if entered but not a required field */
	var tempphone = $('f2-physicianphoneareacode').value + $('f2-physicianphoneprefix').value + $('f2-physicianphonesuffix').value;
	if( tempphone.length > 1 && tempphone.length < 10 ) {
    	addError(errors, 'f2-label-physicianfax', null);
    }
	/*if( $('f2-physicianfaxareacode').value.length < 3 || $('f2-physicianfaxprefix').value.length < 3 || $('f2-physicianfaxsuffix').value.length < 4 ) {
    	addError(errors, 'f2-label-physicianfax', null);
    }*/
	if( $('f2-physicianaddress').value.length < 1 ) {
    	addError(errors, 'f2-label-physicianaddress', null);
    }
	if( $('f2-physiciancity').value.length < 1 ) {
    	addError(errors, 'f2-label-physiciancity', null);
    }
	if( $('f2-physicianstate').value.length < 1 ) {
    	addError(errors, 'f2-label-physicianstate', null);
    }
	if( $('f2-physicianzipcode').value.length < 1 ) {
    	addError(errors, 'f2-label-physicianzipcode', null);
    }

	var testids = $CF('f2','f2-tests');
	if( testids.length == 0 ) {
    	addError(errors, 'f2-label-tests', null);	
	}
	
	for( var i=0; i<testids.length; i++ ) {
		if( $('f2-info'+testids[i]) && $('f2-info'+testids[i]).value.length < 1 ) {
    		addError(errors, 'f2-label-info'+testids[i], null);			
		}
	}
	
	if( errors.length ) {
		displayErrors('f2-message', errors);
		return false;
	}
	else {
		displayscreen('screen3');
		addmapsteplink(2);
		return true;
	}
}

function verify_f3() {
	var errors = new Array();
	
	var schedpref = $RF('f3', 'f3-schedulingpreference');	
	if( schedpref == null ) {
    	addError(errors, 'f3-label-schedulingpreference', null);
	}
	else if( schedpref == 'Preferred Day/Time') {
		if( $('f3-firstchoicedow').value.length < 1 || $('f3-firstchoicetod').value.length < 1 ) {
			addError(errors, 'f3-label-firstchoice', null);
		}
		if( $('f3-secondchoicedow').value.length < 1 || $('f3-secondchoicetod').value.length < 1 ) {
			addError(errors, 'f3-label-secondchoice', null);
		}
		if( $('f3-thirdchoicedow').value.length < 1 || $('f3-thirdchoicetod').value.length < 1 ) {
			addError(errors, 'f3-label-thirdchoice', null);
		}
    }
	
	if( $('f3-locationid').value.length < 1 ) {
    	addError(errors, 'f3-label-locationid', null);
    }

	if( errors.length ) {
		displayErrors('f3-message', errors);
		return false;
	}
	else {
		addmapsteplink(3);
		return true;
	}
}


function verify_insurancepolicy() {
	var errors = new Array();
		
	if( $('f4-policytype').value.length > 0 || $('f4-subscribername').value.length > 0 || $('f4-subscriberbirthdate').value.length > 0 || $('f4-policynumber').value.length > 0 || $('f4-groupnumber').value.length > 0 ) {
		if( $('f4-policytype').value.length < 1 ) {
			addError(errors, 'f4-label-policytype', null);
		}
		if( $('f4-insurancecompany').value.length < 1 ) {
			addError(errors, 'f4-label-insurancecompany', null);
		}
		if( $('f4-subscribername').value.length < 1 ) {
			addError(errors, 'f4-label-subscribername', null);
		}
		if( $('f4-subscriberbirthdate').value.length < 10 ) {
			addError(errors, 'f4-label-subscriberbirthdate', null);
		}
		if( $('f4-policynumber').value.length < 1 ) {
			addError(errors, 'f4-label-policynumber', null);
		}
		if( $('f4-groupnumber').value.length < 1 ) {
			addError(errors, 'f4-label-groupnumber', null);
		}
		if( $('f4-benefitsphoneareacode').value.length < 3 || $('f4-benefitsphoneprefix').value.length < 3 || $('f4-benefitsphonesuffix').value.length < 4 ) {
			addError(errors, 'f4-label-benefitsphone', null);
		}
		if( $('f4-precertificationphoneareacode').value.length < 3 || $('f4-precertificationphoneprefix').value.length < 3 || $('f4-precertificationphonesuffix').value.length < 4 ) {
			addError(errors, 'f4-label-precertificationphone', null);
		}
	
		if( $('f4-billingaddress').value.length < 1 ) {
			addError(errors, 'f4-label-billingaddress', null);
		}
		if( $('f4-billingcity').value.length < 1 ) {
			addError(errors, 'f4-label-billingcity', null);
		}
		if( $('f4-billingstate').value.length < 1 ) {
			addError(errors, 'f4-label-billingstate', null);
		}
		if( $('f4-billingzipcode').value.length < 1 ) {
			addError(errors, 'f4-label-billingzipcode', null);
		}
	}
	
	if( $('f4-policytype2').value.length > 0 || $('f4-subscribername2').value.length > 0 || $('f4-subscriberbirthdate2').value.length > 0 || $('f4-policynumber2').value.length > 0 || $('f4-groupnumber2').value.length > 0 || $('f4-insurancecompany2').value.length > 0 ) {
		if( $('f4-policytype2').value.length < 1 ) {
			addError(errors, 'f4-label-policytype2', null);
		}
		if( $('f4-insurancecompany2').value.length < 1 ) {
			addError(errors, 'f4-label-insurancecompany2', null);
		}
		if( $('f4-subscribername2').value.length < 1 ) {
			addError(errors, 'f4-label-subscribername2', null);
		}
		if( $('f4-subscriberbirthdate2').value.length < 10 ) {
			addError(errors, 'f4-label-subscriberbirthdate2', null);
		}
		if( $('f4-policynumber2').value.length < 1 ) {
			addError(errors, 'f4-label-policynumber2', null);
		}
		if( $('f4-groupnumber2').value.length < 1 ) {
			addError(errors, 'f4-label-groupnumber2', null);
		}
		if( $('f4-benefitsphoneareacode2').value.length < 3 || $('f4-benefitsphoneprefix2').value.length < 3 || $('f4-benefitsphonesuffix2').value.length < 4 ) {
			addError(errors, 'f4-label-benefitsphone2', null);
		}
		if( $('f4-precertificationphoneareacode2').value.length < 3 || $('f4-precertificationphoneprefix2').value.length < 3 || $('f4-precertificationphonesuffix2').value.length < 4 ) {
			addError(errors, 'f4-label-precertificationphone2', null);
		}
	
		if( $('f4-billingaddress21').value.length < 1 ) {
			addError(errors, 'f4-label-billingaddress21', null);
		}
		if( $('f4-billingcity2').value.length < 1 ) {
			addError(errors, 'f4-label-billingcity2', null);
		}
		if( $('f4-billingstate2').value.length < 1 ) {
			addError(errors, 'f4-label-billingstate2', null);
		}
		if( $('f4-billingzipcode2').value.length < 1 ) {
			addError(errors, 'f4-label-billingzipcode2', null);
		}
	}

	if( errors.length ) {
		displayErrors('f4-message', errors);
		return false;
	}
	else {
		displayscreen('screen5');
		addmapsteplink(4);
		return true;
	}
}

function verify_f5() {
	var errors = new Array();
		
	if( $('f5-employmentstatus').value.length < 1 ) {
    	addError(errors, 'f5-label-employmentstatus', null);
    }
	
	var accidentclaimval = $RF('f5', 'f5-accidentclaim');
	if( acidentclaimval == 'Yes' ) {
		if( $('f5-accidentinsurancecompany').value.length < 1 ) {
			addError(errors, 'f5-label-accidentinsurancecompany', null);
		}
		if( $('f5-accidentclaimnumber').value.length < 1 ) {
			addError(errors, 'f5-label-accidentclaimnumber', null);
		}
	}
	
	if( errors.length ) {
		displayErrors('f5-message', errors);
		return false;
	}
	else return true;
}

function clearErrors() {
	espans = $$('span.errorcallout');
	for( var i=0; i<espans.length; i++ ) {
		espans[i].removeClassName('errorcallout');
	}
	
	eboxes = $$('div.errorbox');
	for( var i=0; i<eboxes.length; i++ ) {
		eboxes[i].style.display = 'none';
	}
}

function displayErrors(msgbox_id, errors) {
	for( var i=0; i < errors.length; i++ ) {
		$(errors[i].labelid).addClassName('errorcallout');
	}
	
	$(msgbox_id).innerHTML = 'Your form submission contains one or more incomplete fields. Please review the items displayed in red below.';
	$(msgbox_id).style.display = 'block';
	$(msgbox_id).scrollTo();
}

function addError(errors, labelid, msg) {
	errors[errors.length] = new error( labelid, msg);
}

function error( labelid, msg) {
	this.labelid = labelid;
	this.msg = msg;
}

function submitRegistration() {
	var contactphone = $('f1-contactphoneareacode').value + $('f1-contactphoneprefix').value + $('f1-contactphonesuffix').value;
	var dayphone = $('f1-dayphoneareacode').value + $('f1-dayphoneprefix').value + $('f1-dayphonesuffix').value;
	var eveningphone = $('f1-eveningphoneareacode').value + $('f1-eveningphoneprefix').value + $('f1-eveningphonesuffix').value;
	var emergencyphone = $('f1-emergencyphoneareacode').value + $('f1-emergencyphoneprefix').value + $('f1-emergencyphonesuffix').value;
	var employerphone = $('f5-employerphoneareacode').value + $('f5-employerphoneprefix').value + $('f5-employerphonesuffix').value;
	var physicianphone = $('f2-physicianphoneareacode').value + $('f2-physicianphoneprefix').value + $('f2-physicianphonesuffix').value;
	var physicianfax = $('f2-physicianfaxareacode').value + $('f2-physicianfaxprefix').value + $('f2-physicianfaxsuffix').value;

	var ssn = $('f1-ssn1').value + $('f1-ssn2').value + $('f1-ssn3').value;
	var schedpref = $RF('f3', 'f3-schedulingpreference');	
	var accidentclaimval = $RF('f5', 'f5-accidentclaim') == null ? '' : $RF('f5', 'f5-accidentclaim');
	
	var testids = $CF('f2','f2-tests');	
	var testsstr = '';
	for( var i=0; i<testids.length; i++ ) {
		if( i > 0) { testsstr += '|'; }
		testsstr += testids[i];
		if( $('f2-info'+testids[i]) ) {
    		testsstr += '@' + $('f2-info'+testids[i]).value;	
		}
	}

	DWREngine._execute(_cfscriptLocation, null, 'submitOutpatientRegistration', 
						$('f1-contactperson').value, 
						contactphone, 
						$('f1-contactphoneext').value,
						$('f1-relationshiptopatient').value, 
						$('f1-firstname').value, 
						$('f1-lastname').value, 
						$('f1-middleinitial').value, 
						ssn, 
						$('f1-birthdate').value, 
						$('f1-gender').value, 
						$('f5-ethnicity').value, 
						$('f5-maritalstatus').value, 
						$('f1-address').value, 
						$('f1-address2').value, 
						$('f1-city').value, 
						$('f1-state').value, 
						$('f1-zipcode').value,
						dayphone,
						eveningphone, 
						$('f1-email').value, 
						$('f1-emergencycontact').value, 
						emergencyphone,
						$('f1-emergencycontactrelationship').value,
						$('f5-employmentstatus').value, 
						$('f5-retirementdate').value, 
						$('f5-employer').value,
						employerphone, 
						$('f5-employeraddress').value, 
						$('f5-employeraddress2').value, 
						$('f5-employercity').value, 
						$('f5-employerstate').value, 
						$('f5-employerzipcode').value, 
						$('f2-physicianfirstname').value, 
						$('f2-physicianlastname').value, 
						$('f2-physicianmiddleinitial').value, 
						physicianphone,
						$('f2-physicianphoneext').value, 
						physicianfax,
						$('f2-physicianaddress').value, 
						$('f2-physicianaddress2').value, 
						$('f2-physiciancity').value, 
						$('f2-physicianstate').value, 
						$('f2-physicianzipcode').value, 
						$('f2-havephysicianorder').value, 
						$('orderscan').value, 
						$('f2-diagnosis').value, 
						schedpref,
						$('f3-firstchoicedow').value, 
						$('f3-firstchoicetod').value, 
						$('f3-secondchoicedow').value, 
						$('f3-secondchoicetod').value, 
						$('f3-thirdchoicedow').value, 
						$('f3-thirdchoicetod').value, 
						$('f3-schedulingcomments').value, 
						$('f3-locationid').value, 
						accidentclaimval,
						testsstr,
						registrationCallback);
}

function registrationCallback(val) {
	registrationid = val;

	var accidentclaimval = $RF('f5', 'f5-accidentclaim') == null ? '' : $RF('f5', 'f5-accidentclaim');
	
	if( accidentclaimval == 'Yes' ) {
		submitAccidentClaim();
	}
	else {
		submitInsurancePolicies();
	}
}

function submitAccidentClaim() {

	var adjusterphone = $('f5-accidentadjusterphoneareacode').value + $('f5-accidentadjusterphoneprefix').value + $('f5-accidentadjusterphonesuffix').value;

	DWREngine._execute(_cfscriptLocation, null, 'submitAccidentClaim',
					   registrationid,
					   $('f5-accidentinsurancecompany').value,
					   $('f5-accidentclaimnumber').value,
					   $('f5-accidentdate').value,
					   $('f5-accidenttime').value,
					   $('f5-accidentlocation').value,
					   $('f5-accidentemployer').value,
					   $('f5-accidentadjuster').value,
					   adjusterphone,
					   $('f5-adjusteraddress').value,
					   $('f5-adjusteraddress2').value,
					   $('f5-adjustercity').value,
					   $('f5-adjusterstate').value,
					   $('f5-adjusterzipcode').value,
					   accidentClaimCallback);	 
}

function accidentClaimCallback(val) {
	submitInsurancePolicies();
}

function submitInsurancePolicies() {
	policiestosubmit = 0;
	
	if( $('f4-policytype').value.length > 0 || $('f4-subscribername').value.length > 0 || $('f4-subscriberbirthdate').value.length > 0 || $('f4-policynumber').value.length > 0 || $('f4-groupnumber').value.length > 0 || $('f4-insurancecompany').value.length > 0) {
		policiestosubmit = policiestosubmit + 1;
	}

	if( $('f4-policytype2').value.length > 0 || $('f4-subscribername2').value.length > 0 || $('f4-subscriberbirthdate2').value.length > 0 || $('f4-policynumber2').value.length > 0 || $('f4-groupnumber2').value.length > 0 || $('f4-insurancecompany2').value.length > 0) {
		policiestosubmit = policiestosubmit + 1;	
	}

	if( policiestosubmit == 0 ) {
		registrationCompleted();
	}
	else{
		if( $('f4-policytype').value.length > 0 || $('f4-subscribername').value.length > 0 || $('f4-subscriberbirthdate').value.length > 0 || $('f4-policynumber').value.length > 0 || $('f4-groupnumber').value.length > 0 || $('f4-insurancecompany').value.length > 0) {
			
			var benefitsphone = $('f4-benefitsphoneareacode').value + $('f4-benefitsphoneprefix').value + $('f4-benefitsphonesuffix').value;
			var precertificationphone = $('f4-precertificationphoneareacode').value + $('f4-precertificationphoneprefix').value + $('f4-precertificationphonesuffix').value;
			
			DWREngine._execute(_cfscriptLocation, null, 'submitInsurancePolicy',
							   registrationid,
							   $('f4-insurancecompany').value,
							   $('f4-policytype').value,
							   $('f4-subscribername').value,
							   $('f4-subscriberbirthdate').value,
							   $('f4-policynumber').value,
							   $('f4-groupnumber').value,
							   benefitsphone,
							   precertificationphone,
							   $('f4-billingaddress').value,
							   $('f4-billingaddress2').value,
							   $('f4-billingcity').value,
							   $('f4-billingstate').value,
							   $('f4-billingzipcode').value,
							   1,
							   insurancePolicyCallback);	 
		}
	
		if( $('f4-policytype2').value.length > 0 || $('f4-subscribername2').value.length > 0 || $('f4-subscriberbirthdate2').value.length > 0 || $('f4-policynumber2').value.length > 0 || $('f4-groupnumber2').value.length > 0 || $('f4-insurancecompany2').value.length > 0) {
			var benefitsphone2 = $('f4-benefitsphoneareacode2').value + $('f4-benefitsphoneprefix2').value + $('f4-benefitsphonesuffix2').value;
			var precertificationphone2 = $('f4-precertificationphoneareacode2').value + $('f4-precertificationphoneprefix2').value + $('f4-precertificationphonesuffix2').value;
			
			DWREngine._execute(_cfscriptLocation, null, 'submitInsurancePolicy',
							   registrationid,
							   $('f4-insurancecompany2').value,
							   $('f4-policytype2').value,
							   $('f4-subscribername2').value,
							   $('f4-subscriberbirthdate2').value,
							   $('f4-policynumber2').value,
							   $('f4-groupnumber2').value,
							   benefitsphone2,
							   precertificationphone2,
							   $('f4-billingaddress21').value,
							   $('f4-billingaddress22').value,
							   $('f4-billingcity2').value,
							   $('f4-billingstate2').value,
							   $('f4-billingzipcode2').value,
							   2,
							   insurancePolicyCallback);	 
		}
	}
}

function insurancePolicyCallback(val) {
	policiestosubmit = policiestosubmit - 1;
	
	if( policiestosubmit == 0) {
		registrationCompleted();
	}
}

function registrationCompleted() {	
	$('screen1').style.display = 'none';
	$('screen2').style.display = 'none';
	$('screen3').style.display = 'none';
	$('screen4').style.display = 'none';
	$('screen5').style.display = 'none';
	$('screen-thankyou').style.display = 'block';
}

