var wmaUrl = "";
var addUrl = location.href;
var tidTLab = null;
var	ttsStopStas = 0;
var	ttsPauzStat = 0;
var	ttsPlayStat = 0;
var TTSPostSrc = "http://news.idoican.com.cn/audio/TTS/Default.aspx"; //要调用的TTSPalyer的地址
var temptxt = "";
function readTxt()
{
	var txtobj = document.all("ozoom");
	if(typeof(txtobj) == "object")
	{	
		var txt = txtobj.innerText;	
		GetUrl(txt);		
	}
    else
    {
        alert("无法获取文章内容");
    }
}
function getId()
{
	var pos1 = addUrl.indexOf("content_");
	var pos2 = addUrl.indexOf(".htm");
	var id = addUrl.substring(pos1+8, pos2);
	return id;
}	
function getName()
{
	 var pos1 = addUrl.indexOf("/html");
	
	var strurl = addUrl.substring(7,pos1);
	var pos2 = strurl.indexOf("/");
	var name = strurl.substring(pos2+1);
	return name;
}
		
function getDateStr()
{
	var re = /\d{4}-\d{2}[\/\\]\d{2}/i;
	var ret = addUrl.match(re);
	if(ret)
	{
		return ret; 
	}
	else
	{
		alert("no date pattern found");
		return "";
	}
}
function GetUrl(text)
{
	temptxt = text;
	var txtId = getId();
	var txtPath = getName() + "/html211/" + getDateStr(addUrl); 
	var url = TTSPostSrc; 
	//var url = "http://172.24.25.78/TTSWeb/test.asp";
	//var layer = document.getElementById("wait"); //等待层；
	//layer.style.display = "block";
	//layer.style.top = window.event.clientY + "px";
	//layer.style.left = window.event.clientX + "px";
	var postValue = "id="+ txtId+ "&path=" + txtPath + "&content=" + encodeURIComponent(text);
	var myAjax = new Ajax.Request(
							url,
							{
							method: 'post',
							asynchronous: true,
							parameters: postValue,
							onSuccess: callBackSuccess,
							onFailure: callBackFail
							});
}


function callBackSuccess(xmlHttp)
{
	//var layer = document.getElementById("wait"); //等待层；
	//layer.style.display = "none";
	var txtUrl = null;
    txtUrl = xmlHttp.responseText;
	if(txtUrl == "4"|txtUrl == "5"|txtUrl == "6")
	{
		alert("该文章没有文字内容！");
		wmaUrl = "empty";
    }
	else
	{
		wmaUrl = txtUrl;
		evtPlayin();
	}
}

function callBackFail(xmlHttp)
{
	if(xmlHttp.statusText == "proxy error")
	{
		//var layer = document.getElementById("wait"); //等待层
		//layer.innerHTML = "继续等待...";
		GetUrl(temptxt);
	}
	else
	{		
	 	alert("获得声音文件错误:  "+ xmlHttp.statusText);
	}
}

function evtPlayin(){
    if(wmaUrl==""){alert("本篇稿件没有语音素材！");return;}
	ttsStopStas = 0;
	ttsPauzStat = 0;
	ttsPlayStat = 1;
    var wmps = document.Player.playState;
	if(wmps==0)
	{document.getElementById("readPlayBtn").innerHTML = "暂停阅读";}
	if(wmps==2){document.getElementById("readPlayBtn").innerHTML = "暂停阅读";}
	if(wmps==3){evtPausein();document.getElementById("readPlayBtn").innerHTML = "语音阅读";return;}
	if(document.Player.URL!=wmaUrl){document.Player.URL = wmaUrl;}
	document.Player.controls.play();	
}
function evtStopin(){
	ClosePlayer();
	if(wmaUrl==""){
		return;
	}
	ttsStopStas = 0;
	ttsPauzStat = 0;
	ttsPlayStat = 0;
	clearInterval(tidTLab);
	document.Player.controls.stop();
}
function evtPausein(){
	if(wmaUrl==""){
		return;
	}
	if(ttsPauzStat == 1){
		ttsStopStas = 0;
		ttsPauzStat = 0;
		ttsPlayStat = 1;
	}else{
		ttsStopStas = 0;
		ttsPauzStat = 1;
		ttsPlayStat = 0;	
	}
	var wmps = Player.playState;
	var wmpc = Player.controls;
	if(wmps==2){wmpc.play();return;}
	if(wmps==3){wmpc.pause();return;}
}