var speakstate;
var isie = (navigator.appName == "Microsoft Internet Explorer");
function Speakarticle(fileurl,id) {
    $.ajax({
        type: "GET",
		async:false,
        url: fileurl,
        dataType: "text",
        data: { "id": "" + id + "" },
        success: function (data) {
            var articlewav = "article_" + id + ".wav";
            if (data == articlewav) {
                $("#textspeak .m").html("等待处理…");
                speakstate = window.setInterval("getstate(" + id + ")",500);     	
            }
            else {
                $("#textspeak .m").html("等待处理…");
                if (data == "no right!")
				{
                    alert("系统已禁用语音朗读功能！");
				}
                else {
                    alert("服务器配置或权限错误!");
                }
            }
        },error: function (err) { alert("声音输出错误!"); }
    });
}
 function cfm_ifm(html) {
        var newElem = document.getElementById("player");
        newElem.innerHTML = "";
        var frm = document.createElement("iframe");
        frm.setAttribute("name", "ifr_wav");
        frm.setAttribute("id", "ifr_wav");
        frm.setAttribute("src", "");
        frm.setAttribute("marginwidth", "0");
        frm.setAttribute("marginheight", "0");
        frm.setAttribute("width", "50");
        frm.setAttribute("height", "30");
        frm.setAttribute("scrolling", "no");
        frm.setAttribute("border", "0");
        frm.setAttribute("frameborder", "0");
        newElem.appendChild(frm);
        var ifr_wav = window.frames['ifr_wav'];
        createcfm(ifr_wav,html);
}
function createcfm(ifr,html) {
        ifr.document.open();
        ifr.document.write(html);
        ifr.document.close();		
}
function player(id)
{
	if (navigator.userAgent.toUpperCase().indexOf("MOBILE") > 0) {
		var fileurl_wav=paperweburl + "jquery/tts_html5/" + id;
			$.ajax({
			 type: "GET",
			 async:false,
			 url: fileurl_wav,
			 dataType: "html",
			 data: { "id": "" + id + "","temp": "" + (new Date()).getTime() + "" },
			 success: function(data){
				 if (data !=""){
					 cfm_ifm(data)
					 $("#textspeak .m").html("");	
					 var myAudio = window.frames['ifr_wav'].document.getElementById("speakaudio");
		             myAudio.play();				  
				 }	
			 }
			, error: function (err) { alert("状态错误!"); }
		 });
	}
    else if (isie) {
        $("#player").load(paperweburl + "jquery/tts/" + id, function () { $("#textspeak .m").html("正在朗读…"); });
    }
    else if (navigator.userAgent.toUpperCase().indexOf("SAFARI") > 0) {
        $("#player").load(paperweburl + "jquery/tts_w3c/" + id, function () { $("#textspeak .m").html("正在朗读…"); });
    }
    else if (navigator.userAgent.toUpperCase().indexOf("FIREFOX") > 0) {
        $("#player").load(paperweburl + "jquery/tts/" + id, function () { $("#textspeak .m").html("正在朗读…"); });
    }
    else {
        $("#player").load(paperweburl + "jquery/tts/" + id, function () { $("#textspeak .m").html("正在朗读…"); });
    }
}
function getstate(id) {
	 var fileurl2=paperweburl+"jquery/getstate";
	 $.ajax({
	     type: "GET",
		 async:false,
	     url: fileurl2,
	     dataType: "text",
	     data: { "id": "" + id + "","temp": "" + (new Date()).getTime() + "" },
	     success: function(data){
	         if (data ==""){
	             clearInterval(speakstate); //stop 
	             $("#textspeak .m").html("正在缓冲…");  
	             player(id);
	         }	
	     }
        , error: function (err) { alert("状态错误!"); }
	 });
}
function Speakstop() {
    clearInterval(speakstate);
    $("#player").html("");
    $("#textspeak .m").html("朗读");
}