/**
 * AS4OCEAN2012JoinUsWidget
 * proves form emailing functionality to the OCEAN2012 jpin us form
 */

jQuery.noConflict();

jQuery(document).ready(function()
{
	
	jQuery("#send_sign_up_form").click(function()
	{
		if(!confirm("Are you sure you wish to send this form to CPD Online?"))
		{
			return false
		}
		
		AS4OCPDSignUpWidget.getInstance().sendForm();
	});
});


var AS4OCPDSignUpWidget = Class.create({
	
		
	emailTo: null,
	
	formData: null,
	
	sendForm: function()
	{
		
		var errFlag = false;
		var strFormData = "";
		
		jQuery("#CPD_sign_up_form input, #CPD_sign_up_form textarea ").each(function(i, ele)
		{
			console.log(ele);
			strFormData += ""+ele.id+"="+ele.value+"|:|";
		});
						
		strFormData = encodeURI(strFormData);					
		
		//because the above doesn't seem to work
		
		strFormData = strFormData.replace(/&/, 'amp;');
		
				
		
		// now send the form 
		
		jQuery.ajax(
		{
			type: "POST",
			url: "/channel/send_cpd_sign_up_form",
			data: "strFormData="+strFormData,
			success: function(msg)
			{
				alert("Thank you for signing up.");						
			}
		});	
	}
});


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Static method to retrieve controller from channel_widgets_id
AS4OCPDSignUpWidget.getInstance = function(channelWidgetsId)
{
	if(!AS4OCPDSignUpWidget.instance)
		AS4OCPDSignUpWidget.instance = new AS4OCPDSignUpWidget();
		
	return AS4OCPDSignUpWidget.instance;
}


