//<![CDATA[
function recordingReply(html){
	log('recordingReply html: ' + html);
	if (html == ""){
		alert("The recording could not be saved. Please check your microphone to ensure it is working properly");
		
		return;
	}
	
	var recording_ID_field = document.getElementById("recording_ID");
	recording_ID_field.value = html;
	
	var formName = getCommentFormName();
	
	var comment_form = document.forms[formName];

	var holder = comment_form.comment.value;
	comment_form.comment.value = '[audio_comment id="' + recording_ID_field.value + '" recording_title="Comment Recording"]\n' + holder;
	
	if(comment_form.author.value == ''){
		alert('Please check your name');
		return;
	}
	if(comment_form.email.value == ''){
		alert('Please check your email address');
		return;
	}
	
	submitButton = document.getElementById('new-submit');
	log('submitButton: ' + submitButton);
		
		if(submitButton === null){
			var inputs = document.forms[formName].elements;
			for(var i = 0; i < inputs.length; i++){
				if(inputs[i].type == 'submit'){
					submitButton = inputs[i];
				}
			}
		}
	
	submitButton.click();
}

function trace(str){
	log(str);
	document.getElementById("trace").innerHTML += (str + "<br />");
}

function log(str) {
	//console.log(str);
}

function getCommentFormName() {
	var formName = 'commentform';
	
	if(!document.forms[formName]) {
		formName = 'cf';
	}
	
	return formName;
}

function thisMovie(movieName) {
	if (window.document[movieName]){
		return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1) {
		if (document.embeds && document.embeds[movieName]) {
			return document.embeds[movieName]; 
		}
	}
	else { 
		return document.getElementById(movieName);
	}
}

function recordingSave(){
	// if our hidden recording_id field is empty, send the flash player its save cmd and wait for a sound id to be returned.
	// populate the recording_id field and resend the form.
	var recording_ID_field = document.getElementById("recording_ID");

	if (recording_ID_field.value == ""){
		var recorderName = "recorderPRD"; 
		
		var recorder = thisMovie(recorderName);
		
		var comment_field = document.getElementById("comment");
		var email_field = document.getElementById("email");
		recorder.addCommentFields(email_field.value, comment_field.value, window.location.href);
		
		if(audio_only && recorder.getState() != 'initialized'){
			recorder.saveRecording();
		}else if(!audio_only && recorder.getState() == 'initialized'){
			var formName = getCommentFormName();
			
			document.forms[formName].submit();
		}else{
			recorder.saveRecording();
		}
		

		return false;
	}
	else {
		return true;
	}
}
//]]>

function init() {
	var wrapper = "flashRecorder";
	var so = new SWFObject("http://www.evoca.com/evocaRecorder/BGRecorder.swf","recorderPRD2", "480", "140", "10");
	so.addParam("allowScriptAccess", "always");
	so.addParam("allowFullScreen", "false");
	so.addParam("movie", "http://www.evoca.com/evocaRecorder/BGRecorder.swf");
	so.addVariable("save_url", "rtmp://www.evoca.com/liveCast");
	so.addVariable("site_url", "http://www.evoca.com");
	so.addVariable("owner_id", owner_id);
	
	//so.write("flashRecorder");
}

//window.onLoad = init();
