var CIBCManageContactUs = {

	dialog: {},
	PORTLET_ID: "cibcwgcontactus_WAR_cibcwgmanage",
	
	popup: function() {
		var instance = this;

		instance.dialog = CIBC.Popup({
			width: 640,
			height: 480,
			message: '<div class="loading-animation" />',
			position: [50,50],
			resizable: false,
			modal: true,
			title: Liferay.Language.get("contact_us")
		});

		instance.render({
			action: "",
			name: "",
			email: "",
			subject: "",
			message: ""
		});
		
		return instance.dialog;
	},
	
	submit: function() {
		var instance = this;
		var form = instance.dialog.find("#contactUsForm");
		instance.render({
			action: form.attr("action"),
			name: form.find("#name").val(),
			email: form.find("#email").val(),
			subject: form.find("#subject").val(),
			message: form.find("#message").val()
		});
	},
	
	render: function(options) {
		var instance = this;
		var plid = themeDisplay.getPlid();
		var ppid = CIBCManageContactUs.PORTLET_ID;
		instance.dialog.html('<div class="loading-animation" />');
		
		jQuery.ajax({
			url: themeDisplay.getPathMain() + '/portal/render_portlet',
			data: {
				p_l_id: plid,
				p_p_id: ppid,
				p_p_state: 'exclusive',
				doAsUserId: themeDisplay.getDoAsUserIdEncoded(),
				action: options.action,
				name: options.name,
				email: options.email,
				subject: options.subject,
				message: options.message
			},
			success: function(message) {
				instance.dialog.html(message);
			}
		});
	},
	
	close: function(message) {
		var instance = this;
		alert(message);
		jQuery(instance.dialog).dialog("close");
	}
	
};


