function listen(id, url) {
		$("#listen-td").html('<embed src= "http://dev.christiantapeministry.com/mp3player.swf" '+
		'height="40" width="500"'+
		'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"'+
		'flashvars="&javascriptid=audio&enablejs=true&file='+url+'&displayheight=0&autostart=true&height=40shownavigation=true&largecontrols=true");'+
		'></embed>');
	
	}
	
function validEmail(email) {
    invalidChars = " /:,;"
    
    if (email == "") {
        return false
    }
    for(i=0;i<invalidChars.length;i++) {
        if (email.indexOf(invalidChars.charAt(i), 0) > -1) {
            return false
        }
    }
    atPos = email.indexOf("@", 1)
    if (atPos == -1) {
        return false
    }
    if (email.indexOf("@", atPos+1) > -1) {
        return false
    }
    periodPos = email.indexOf(".", atPos)
    if (periodPos == -1) {
        return false
    }
    if (periodPos+3 > email.length) {
        return false
    }
    return true
}

function validateForm() {
    if ($("#humanName").val() == "" ) {
        alert("Please enter your name is the Real Name field")
        $("#humanName").focus();
        return false
    }
    if (!validEmail($("#cemail").val())) {
        alert("Please enter a valid email address in the From Email field")
        
        return false
    }
    
    if (!validEmail($("#toEmail").val())) {
        alert("Please enter a valid email address in the To Email field")
        
        return false
    }
    
    return true;
}


function sendEmail() {
	
	if (!validateForm()) {
		return false;
	};

	$.ajax({
		type: "POST",
		url : "send-email.php",
		async: false,
		dataType : "html",
		data: {id: $("#id").val(), 
			humanName: $("#humanName").val(), 
			email: $("#cemail").val(), 
			toEmail: $("#toEmail").val(), 
			subject: $("#subject").val(),
			note: $("#note").val()
			},
		success: function(html){
    		$.facebox.close();
  		}
	});
}
function validateTestimony() {
	if ($('#username').val() == '') {
		$('#testifyError').html('Please Enter A Name');
		return false;
	}
	if ($('#testimony').val() == '') {
		$('#testifyError').html('Please enter something in the testimony field.');
		return false;
	}
	return true;
}
function submitTestimony() {
	
	if (!validateTestimony()) {
		return false;
	};
	var id = $("#id").val();
	$.ajax({
		type: "POST",
		url : "addTestimony.php",
		async: false,
		dataType : "html",
		data: {id: $("#id").val(), 
			username: $("#username").val(), 
			locale: $('#locale').val(),
			testimony: $("#testimony").val()
			},
		success: function(html){
    		$.facebox.close();
    		showTape(id);
    	}
	});
}

var MM_contentVersion = 6;

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
		}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

function playVideo() {

	if ((!Modernizr.video.h264) || ($("#video-object").length == 0)) {
		
		$("#video-object").remove();
		$("#mediaspace").show();
  	} else {
  		
  		$("#video-object").show();
  		$("#mediaspace").remove();
  	
  	}
}

function showTape(id) {
	$("#tape").show();
	$("#tape-title").addClass("box-header-featured");
	$("#tape-content").html('<img class="centered-image" src="/images/loading.gif" border="0"></img>').show();
	
	$.ajax({
		type: "GET",
		url : "ajax-get-tape.php",
		dataType : "html",
		data: "id="+id,
		async: false,
		success: function(html){
    		$("#tape-content").html(html);
    		$('a[rel*=facebox]').facebox();
    		playVideo();
			document.title="CTM - "+$("#tapetitle").text();
  		}
	});
}