function openPopBox(html) {
	$('pop_box').innerHTML = html;
	Effect.Appear('pop_box_wrapper',{duration:0.5});
	dragger = new Draggable('pop_box',{});  
}

function closePopBox() {   
	Effect.Fade('pop_box_wrapper', {duration:0.5, from:1.0,to:0.0});
	dragger.destroy();
}

function loadPopBoxByPageName(pageName){
	loadPopBox('/global/containers/ajax_pop_box/ajax-pop-box.dot?name=' + pageName);
}

function loadPopBox(url) {
	
	new Ajax.Request(url, {
		method:'get',
		onSuccess: function(transport){
			openPopBox(transport.responseText);	
		}
	});  	
}

function loadPlan(marketChannel) { 
	
	new Ajax.Request('/global/containers/ajax_pop_box/ajax-pop-box.dot?name=' + marketChannel + '_plan', {
		method:'get',
		onSuccess: function(transport){
			var planPage = transport.responseText;	
		
			if (marketChannel == 'AKC' || marketChannel == 'CFA') {
				planPage = planPage.replace(/;;ap_quote;;/, getPlanQuote(marketChannel, 'Accident Plus (accident / injury only)'));
				planPage = planPage.replace(/;;e_quote;;/, getPlanQuote(marketChannel, 'Essential'));
				planPage = planPage.replace(/;;ep_quote;;/, getPlanQuote(marketChannel, 'Essential Plus'));
				planPage = planPage.replace(/;;w_quote;;/, getPlanQuote(marketChannel, 'Wellness'));
				planPage = planPage.replace(/;;wp_quote;;/, getPlanQuote(marketChannel, 'Wellness Plus'));
				planPage = planPage.replace(/;;disclaimer;;/, quote.disclaimer);
			}			
			openPopBox(planPage);
		}
	});  	
}

function openNewsletterSubscriptionBox(emailObj, marketChannel, ipAddress) {
	
	new Ajax.Request('/global/containers/ajax_pop_box/ajax-pop-box.dot?name=newsletter_signup', {
		method:'get',
		onSuccess: function(transport){
			var page = transport.responseText;	
		
			page = page.replace(/email address/, emailObj.value);
			page = page.replace(/;;marketChannel;;/, marketChannel);
			page = page.replace(/;;ipAddress;;/, ipAddress);
			
			openPopBox(page);
		}
	});  	
}

function sendNewsletterSubscription(emailObject, firstNameObject, lastNameObject, marketChannel, ipAddress) {	

	loadPopBoxByPageName('wait_page');
	new Ajax.Request('/PPIServices/NewsletterSubscribeServlet', {
		method:'get',
		parameters: {
			email: emailObject.value, 
			lastName:lastNameObject.value, 
			firstName:firstNameObject.value, 
			ipAddress: ipAddress, 
			marketChannel: marketChannel
		},
		onSuccess: function(transport){
			var retVal = transport.responseText.evalJSON();
			alert(retVal.message);
			closePopBox();
		}
	});
}