function copyAddress(formName) {
	var c = eval('document.' + formName + '.copy_address');

	var ba1 = eval('document.' + formName + '.BILLING_ADDRESS_1');
	var ba2 = eval('document.' + formName + '.BILLING_ADDRESS_2');
	var bc = eval('document.' + formName + '.BILLING_CITY');
	var bz = eval('document.' + formName + '.BILLING_ZIP_CODE');
	var bsi = eval('document.' + formName + '.BILLING_STATE_ID');
	var bp1 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_1');
	var bp2 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_2');
	var bp3 = eval('document.' + formName + '.BILLING_PHONE_NUMBER_PART_3');

	var sa1 = eval('document.' + formName + '.shipping_address_1');
	var sa2 = eval('document.' + formName + '.shipping_address_2');
	var sc = eval('document.' + formName + '.shipping_city');
	var szc = eval('document.' + formName + '.shipping_zip_code');
	var ssi = eval('document.' + formName + '.shipping_state_id');
	var sp1 = eval('document.' + formName + '.shipping_phone_1');
	var sp2 = eval('document.' + formName + '.shipping_phone_2');
	var sp3 = eval('document.' + formName + '.shipping_phone_3');
	
	if (c.checked) {
		ba1.value = sa1.value;
		if (ba2) { ba2.value = sa2.value; }
		bc.value = sc.value;
		bz.value = szc.value;
		bsi.value = ssi.value;
		bp1.value = sp1.value;
		bp2.value = sp2.value;
		bp3.value = sp3.value;
	} else {
		ba1.value = '';
		if (ba2) { ba2.value = ''; }
		bc.value = '';
		bz.value = '';
		bsi.value = 35;
		bp1.value = '';
		bp2.value = '';
		bp3.value = '';
	}
}	

function copyAddress2(formName) {
	var c = eval('document.' + formName + '.copy_address');

	var ba1 = eval('document.' + formName + '.address');
	var ba2 = eval('document.' + formName + '.address2');
	var bc = eval('document.' + formName + '.city');
	var bz = eval('document.' + formName + '.zip_code');
	var bsi = eval('document.' + formName + '.state_id');
	var sp1 = eval('document.' + formName + '.phone_1');
	var sp2 = eval('document.' + formName + '.phone_2');
	var sp3 = eval('document.' + formName + '.phone_3');

	var sa1 = eval('document.' + formName + '.from_address_1');
	var sa2 = eval('document.' + formName + '.from_address_2');
	var sc = eval('document.' + formName + '.from_city');
	var szc = eval('document.' + formName + '.from_zip_code');
	var ssi = eval('document.' + formName + '.from_state_id');
	var sf1 = eval('document.' + formName + '.from_phone_1');
	var sf2 = eval('document.' + formName + '.from_phone_2');
	var sf3 = eval('document.' + formName + '.from_phone_3');
	
	if (c.checked) {
		ba1.value = sa1.value;
		if (ba2) { ba2.value = sa2.value; }
		bc.value = sc.value;
		bz.value = szc.value;
		bsi.value = ssi.value;
		sp1.value = sf1.value;
		sp2.value = sf2.value;
		sp3.value = sf3.value;
	} else {
		ba1.value = '';
		if (ba2) { ba2.value = ''; }
		bc.value = '';
		bz.value = '';
		bsi.value = 35;
		sp1.value = '';
		sp2.value = '';
		sp3.value = '';
	}
}

function disable_submit(button_id) {
	var el = document.getElementById(button_id);
	if (el) { el.disabled = true; }
}

function popupSeniorApplication(url) {
	window.open(url, '', 'height=800,width=870,scrollbars=yes').focus();
}

function fill_loginbox(val, id) {
	var el1 = document.getElementById('loginbox');
	if (el1) {
		if (undefined != val) {
			val = val.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			
			if (val != '') {
				el1.innerHTML = val;
				el1.className = 'loginbox';
				el1.style.display = 'block';
			} else {
				el1.className = '';
				el1.style.display = 'none';
			}
		}
	}
}

/* Function to load the login/logout link on cms_pages */
function load_login_logout_link(page) {
	asyncGet(page, 'copyToElementInnerHtml', eval({'elementId':'loginlink'}));
}

// Need to make sure that the survey is enabled and Agent is not logged in
function survey_popup_callback(resp, context_path) {
	if (resp) {
		var json = eval('(' + resp + ')');
		//alert('survey enabled: ' + json.enabled + ' user logged-in: ' + json.logged_in);
		if (json.enabled == 'true' && json.logged_in == 'false') {
			window.open(context_path + '/survey/index.jsp', '', 'height=800,width=870,scrollbars=yes').focus();
		}
	}
}

// We need to make sure that the survey hasn't already been shown
function survey_popup(context_path) {
	var surveyShown = readCookie('SURVEY');
	if (!surveyShown || surveyShown != 'YES') {
		asyncGet(context_path + '/async/survey_enabled.jsp', 'survey_popup_callback', context_path);
	}
}

// Tab auto move function for register a smartLink card
function moveOnMax(field,nextFieldID){
	  if(field.value.length >= field.maxLength){
	    document.getElementById(nextFieldID).focus();
	  }
}

function reload_captcha_image(context_path) {
	var now = new Date();
	if (document.images) {
		document.images.captcha_image.src = context_path + '/servlet/captcha.jpg?' + now.getTime();
	}
}

function product_image_swap(new_image_src) {
	if (document.images) {
		document.images.product_image.src = new_image_src;
	}
}

// Fills in the leftnav
function fill_leftnav_div(val, id) {
	var el = document.getElementById('sidebar');
	
	if (el) {
		if (undefined != val) {
			el.innerHTML = val;
		}
	}
}

// This is called when a PDF is clicked on
function record_pdf_click(context_path, id) {
	var pic = new Image(1,1);
	pic.src = context_path + '/servlet/conversion?ref=PAGEVIEW&model_name=multimedia_file&model_id=' + id + '&ts=' + new Date().getTime();
}
