﻿
	/**
	 * Display an error message for the checker
	 *
	 * @param		String		Text message to display
	 *
	 */

	function	displayError( txt )	{
		if( debugbba ) 	{
			alert( "Error : " + txt);
		}
	}

	/**
	 * Callback - called when the samknows call has started
	 *
	 * @param		Object		Currently unused - may change
	 *
	 */

	function	ml_start_callback()	{}

	function	ml_submit( formname, start_callback, end_callback, error_callback )	{
		dataquerystring	=	"";
		email	=	email1	=	email2	=	email3	=	email4	=	yemail	=	message	=	"";
		
		target		=	document.getElementById('ml_email_address1');
		if( target )	{	email1	=	target.value;	}
		target		=	document.getElementById('ml_email_address2');
		if( target )	{	email2	=	target.value;	}
		target		=	document.getElementById('ml_email_address3');
		if( target )	{	email3	=	target.value;	}
		target		=	document.getElementById('ml_email_address4');
		if( target )	{	email4	=	target.value;	}
		
		target		=	document.getElementById('ml_yemail_address');
		if( target )	{
			yemail	=	target.value;
		}

		target		=	document.getElementById('ml_message');
		if( target )	{	message	=	target.value;	}

		dataquerystring	+=	"&email1=" + email1 + "&email2=" + email2 + "&email3=" + email3 + "&email4=" + email4 + "&yemail=" + yemail + "&message=" + urlencode( message );
		return	ajax_submit( dataquerystring, start_callback, end_callback, error_callback );
	}

	/**
	 * @param		String		JSON Data
	 *
	 * @return		Boolean		false on error
	 *							Should forward the HTML page on suceess
	 *							depending on the data returned
	 */

	function	ml_end_callback( data )	{

		jsonContent = eval("(" + data + ")");

		xcomm	=	document.getElementById('maillist_container');
		if( xcomm )	{

			if(done == 1)	{
				newcdata	=	'<p>Your invitation has been sent, let\'s hope they have as much musical taste as you!</p><p><a href="javascript:;" onclick="hidediv(\'maillist\');">Close</a>';	
			}
			else if(done == -1 )	{
				newcdata	=	'<p>Your invitation has not been sent. There was a problem with your email address. Please refresh this page and try again.</p><p><a href="javascript:;" onclick="hidediv(\'maillist\');">Close</a>';	
			}
			else if(done == -2 )	{
				newcdata	=	'<p>Your invitation has not been sent. There was a problem with one of your friends email address. Please refresh this page and try again.</p><p><a href="javascript:;" onclick="hidediv(\'maillist\');">Close</a>';	
			}
			
			xcomm.innerHTML	=	newcdata;
		}
	}


	/**
	 * @param		Number		error_code
	 *							-2 = no postcode and/or phone number
	 *							All other codes - assume can't connect to samknows
	 */

	function	ml_error_callback( error_code )	{

		if( error_code == -2 )	{
			displayError("Please enter data");
		}
		else	{
			displayError("Sorry. Big error.");
		}
	}

