// JavaScript Document

// This function substitutes carriage returns for html <br />.
function escapeVal(textarea){ 
	replaceWith = '<br />';
	// textarea is reference to that object, replaceWith is string that will replace the encoded return
	textarea.value = escape(textarea.value); // encode textarea string's carriage returns
	
	for(i=0; i<textarea.value.length; i++)
	{ 
		// loop through string, replacing carriage return encoding with HTML break tag
		
		if(textarea.value.indexOf("%0D%0A") > -1)
		{ 
			// Windows encodes returns as \r\n hex
			textarea.value=textarea.value.replace("%0D%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0A") > -1)
		{ 
			// Unix encodes returns as \n hex
			textarea.value=textarea.value.replace("%0A",replaceWith);
		}
		else if(textarea.value.indexOf("%0D") > -1)
		{ 
			// Macintosh encodes returns as \r hex
			textarea.value=textarea.value.replace("%0D",replaceWith);
		}
		
	}
	// alert('Do I get called here.');
	textarea.value=unescape(textarea.value);  // unescape all other encoded characters
}

function send_callback_request()
{
	document.forms.f.type.value = 'request_callback';
	document.forms.f.submit();
}

// This function is used to send submit the form which submits the email.
function send_email()
{
	document.forms.f.type.value = 'message';
	document.forms.f.submit();
}

// This function is called to check the status on any functions that were called
// on the last submit.
function check_status(status)
{
	switch(status)
	{
		case 'email_success':
		alert('Email Sent OK, please check your inbox for receipt confirmation.\nNote: Not all email clients will receive confirmation straight away,\n however,please be assured that Susan will receive your message.\n\nAlso check your junk/spam mail box as some clients such as Hotmail\n have strict email rules which can treat legitimate mail as spam.');
		break;
		case 'email_fail':
		alert('Email Not Sent, there was a problem, please try again later.');
		break;
		case 'callback_email_success':
		alert('Callback Request Email Sent OK, Susan will receive your request soon.\n\nThank you...');
		break;
		case 'callback_email_fail':
		alert('Callback Request Email Not Sent, there was a problem, please try again later.');
		break;
	}
}