
var m_strIP= "";
var m_nRow=0;				//当前表格的行，播放的行
var m_nTotalRow=0;			//总记录数
var m_DisplayPlayTimeID;	//定时器ID
var m_PlayTimeCount= 0;		//当前已播放的时长
var m_MvoeLen= 0;			//当前已移动的滑块长度
var m_TotalLength;			//文件录音长度

var m_MaxCount=200;			//滑块长度

window.onload = function()
{
    var b = document.getElementById("btn"),
        l = document.getElementById("line"),
        s = document.getElementById("show"),
        bl = false;
	var bx_len= 0;
    function exe(e)
	{
        var e = e||event,
                bx = e.clientX-l.offsetLeft-2;  //据说测试有2像素的误差，所以去掉2像素。
                if(bx<0)
				{
                   bx = 0;
                }
				else if(bx>m_MaxCount)
				{
                   bx = m_MaxCount;
                }
                b.style.left = bx + "px";
                //pr = Math.round(bx/l.clientWidth*100);
                //s.innerHTML = pr + "%" + " | " + (Math.round(pr/200*20)+5) + "分钟";
				
				bx_len= bx;
				s.innerHTML = Get_SecToTimeStr(bx_len);
				
    	}
    	l.onclick = function(e)
		{
        	if(!bl){exe(e)
		}
    }
    b.onmousedown = function(){
         bl = true;
    }
	
    document.onmousemove = function(e)
	//l.onmousemove = function(e)
	{
        if(bl){exe(e)}
    }
	
    document.onmouseup = function()
	//l.onmouseup = function()
	{
        bl = false;
		if(bx_len <= 0 || bx_len > m_MaxCount)
			return;
		StartPlayFile_mvoe(bx_len);			
		bx_len= 0;
    }

	PlayForm_login();	
}

window.onerror = function(e)
{
    alert(e);
}


function exec_changepos(){	
	var npos= document.getElementById("txtpos").value;
	ChangePos(npos);
}
function ChangePos(pos){	
	var b = document.getElementById("btn");
	b.style.left = pos + "px";
}

function exec_addpos(){
	var npos= document.getElementById("txtpos").value;
	AddPos(npos);
}

function AddPos(pos){	
	var b = document.getElementById("btn");
	var x= b.style.left;
	if( x != ""){
		x = x.substr(0,x.lastIndexOf("px"));
		x = parseInt(x,10)+ parseInt(pos,10);
	}else{
		x= pos;
	}
	alert(x);
	b.style.left = x + "px";
}


//随着播放来显示滑块的位置
function DisplayPlayTime(){
	//m_PlayTimeCount++;
	//document.getElementById("show").innerHTML = Get_SecToTimeStr(m_PlayTimeCount);
	
	var step = m_MaxCount / m_TotalLength;		
	m_MvoeLen += step;	
	if(m_MvoeLen > m_MaxCount){
		m_MvoeLen= m_MaxCount;		
	}
	m_PlayTimeCount= m_MvoeLen / step;
	if(m_PlayTimeCount < 0)
		m_PlayTimeCount= 0;
	document.getElementById("show").innerHTML = Get_SecToTimeStr(m_PlayTimeCount);
	ChangePos(m_MvoeLen);
	if(m_MvoeLen >= m_MaxCount){
		m_MvoeLen= -1;	//滑块回到原置
		m_PlayTimeCount= 0;
		ChangePos(m_MvoeLen);
		clearTimeout(m_DisplayPlayTimeID);
	}
}

	function PlayForm_login(){		
	    m_strIP= GetCookie("ServerIP");
		m_nRow= GetCookie("PlayFileNo");
		m_nTotalRow= GetCookie("TotalRecord");
		StartPlayFile(0);
	}	
	

	function StartPlayFile(n){
		StopPlayFile();		
		if(n== 1){ 		//n= 0是播放当前的,1是播放前一条的,2是播放后一条的	
			m_nRow--;
			if(m_nRow < 1)
				m_nRow= 1;
		}
		else if(n== 2){
			m_nRow++;
			if(m_nRow > m_nTotalRow)
				m_nRow= m_nTotalRow;
		}
		m_strPlayFilePath= window.opener.document.all.QueryTable.rows[m_nRow].cells[11].innerText;
		var len= m_strPlayFilePath.length;
		var strFromPath= "";
		for(var i=0; i<len; i++){
			if(m_strPlayFilePath.charAt(i) == "/")
				strFromPath += "\\";
			else
			  	strFromPath += m_strPlayFilePath.charAt(i);
		}
		document.getElementById("filepath").innerText= strFromPath;
		m_strPlayFilePath= strFromPath;
			
		var temp = window.opener.document.all.QueryTable.rows[m_nRow].cells[9].innerText; 
		m_TotalLength = parseInt(temp.substr(0,2),10)* 3600 + parseInt(temp.substr(3,2),10)* 60 + parseInt(temp.substr(6,2),10); //如：11:55:55
		m_TotalLength++;
		
		var nRet= opener.document.getElementById("GxSocketOcx").GX_StartPlaySound2(m_strIP,m_strPlayFilePath,0,0xffffffff);
		//alert(nRet);
		if(nRet < 0){
			alert("Play failed: "+ nRet);
			return;
		}
		m_DisplayPlayTimeID = setInterval("DisplayPlayTime()",1000);
	}
	
	function StopPlayFile(){
		m_MvoeLen= -1;	//回到原置
		m_PlayTimeCount= 0;
		ChangePos(m_MvoeLen);
		clearTimeout(m_DisplayPlayTimeID);
		opener.document.getElementById("GxSocketOcx").GX_StopPlaySound2(m_strIP);
	}
	
	//拖动滑块播放
	function StartPlayFile_mvoe(pos){
		opener.document.getElementById("GxSocketOcx").GX_StopPlaySound2(m_strIP);	
		clearTimeout(m_DisplayPlayTimeID);		
		var step = m_MaxCount / m_TotalLength;
		var t= parseInt(pos / step,10) * 1000;
		var nRet= opener.document.getElementById("GxSocketOcx").GX_StartPlaySound2(m_strIP,m_strPlayFilePath,t,0xffffffff);
		if(nRet < 0){
			alert("Play failed: "+ nRet);
			return;
		}
		m_MvoeLen= pos;
		m_DisplayPlayTimeID = setInterval("DisplayPlayTime()",1000);		
	}
		
	//快进/快退播放
	function StartPlayFile_KJ_KT(pos){
		if((m_PlayTimeCount + pos)<= 0)//m_PlayTimeCount < 10) && (pos < 0)	//当为快退时,播放的长度还没有快退的长度长时.
			return;
		if((m_PlayTimeCount + pos)>= m_TotalLength)//m_PlayTimeCount < 10) && (pos < 0)	//当为快进时,播放的长度还没有快进的长度长时.
			return;
		opener.document.getElementById("GxSocketOcx").GX_StopPlaySound2(m_strIP);	
		clearTimeout(m_DisplayPlayTimeID);		
		var t= parseInt(m_PlayTimeCount + pos,10) * 1000;
		var nRet= opener.document.getElementById("GxSocketOcx").GX_StartPlaySound2(m_strIP,m_strPlayFilePath,t,0xffffffff);
		if(nRet < 0){
			alert("Play failed: "+ nRet);
			return;
		}
		var step = m_MaxCount / m_TotalLength;		
		m_MvoeLen= parseInt(m_PlayTimeCount + pos,10) * step;
		if(m_MvoeLen < 0)
			m_MvoeLen= 0;
		if(m_MvoeLen > m_MaxCount)
			m_MvoeLen= m_MaxCount;
		m_DisplayPlayTimeID = setInterval("DisplayPlayTime()",1000);		
	}
	
	
	
	
	
	
	
	
	
	
	
	