﻿

function IsEnableVCOnline ()
{
    try
    {
        var c = 0;
        c = $$("VCOnline1").RefColor;
        if ( c == null || typeof(c) == 'undefined')
        {
            return false;
        }
        return true;
    }
    catch (e)
    {
        return false;
    }
}
    
function $$(id)
{
    return document.getElementById(id);
}
    
function GetMediaFile(fileName)
{
    if (IsEnableVCOnline() ==  true)
    {
        
        if ( $$("VCOnline1").IsFileExist(fileName) == false)
        {
            return _appClient.strDataUrl + "/" + fileName;
            
        }
        else
        {
            return  $$("VCOnline1").GetLocalPathFileName(fileName);
        }
        
    }
    return fileName;    
    
}

/********
    网页元素圆角函数
********/
function RoundCorner(oContain,idxStyle)
{
    var r = [];
    var oStyleLst = [
    {top:["0 5px","0 3px","0 2px","0 1px","0 1px"],bottom:["0 1px","0 1px","0 2px","0 3px","0 5px"]},
    {top:["0 5px","0 3px","0 2px","0 1px","0 1px"],bottom:["0px","0px","0px","0px","0px"]},
    {top:["0 0 0 5px","0 0 0 3px","0 0 0 2px","0 0 0 1px","0 0 0 1px"],bottom:["0 1 0 0px","0 1 0 0px","0 2 0 0px","0 3 0 0px","0 5 0 0px"]},
    {top:["0 5 0 0px","0 3 0 0px","0 2 0 0px","0 1 0 0px","0 1 0 0px"],bottom:["0 0 0 1px","0 0 0 1px","0 0 0 2px","0 0 0 3px","0 0 0 5px"]}
    ]; //author: longbill.cn
    if (!idxStyle || idxStyle>oStyleLst.length) idxStyle = 1;
    idxStyle--;
    //oContain = document.getElementById(oContain);
    if (!oContain) return;
    for (var key in oStyleLst[idxStyle])
    {
        var topborder = document.createElement("div");
        topborder.style.display = "block";
        topborder.style.backgroundColor = (oContain.parentNode.style.backgroundColor)?oContain.parentNode.style.backgroundColor:"#FFF";
        for (var i=0; i<oStyleLst[idxStyle][key].length; i++)
        {
              var b = document.createElement("div");
              if (oContain.style.backgroundColor)
                    b.style.backgroundColor = oContain.style.backgroundColor;
              else if (oContain.className)
                    b.className = oContain.className;
              b.style.display = "block";
              b.style.margin = oStyleLst[idxStyle][key][i];
              b.style.height = "1px";
              b.style.overflow = "hidden";
              b.style.width = "auto";
              
              topborder.appendChild(b);
        }
        oNode = (key == 'top')?oContain.firstChild:null;
        oContain.insertBefore(topborder, oNode);
    }
} 

Function.prototype.ExtArgus = function() {
  var __method = this;
  var arg = arguments;
  return function() {
    __method.apply(window, arg);
  }
}

function GetAbsoluteLocationEx(element) 
{ 
    if ( arguments.length != 1 || element == null ) 
    { 
        return null; 
    } 
    var elmt = element; 
    var offsetTop = elmt.offsetTop; 
    var offsetLeft = elmt.offsetLeft; 
    var offsetWidth = elmt.offsetWidth; 
    var offsetHeight = elmt.offsetHeight; 
    while( elmt = elmt.offsetParent ) 
    { 
          // add this judge 
        if ( elmt.style.position == 'absolute' || elmt.style.position == 'relative'  
            || ( elmt.style.overflow != 'visible' && elmt.style.overflow != '' ) ) 
        { 
            break; 
        }  
        offsetTop += elmt.offsetTop; 
        offsetLeft += elmt.offsetLeft; 
    } 
    return { absoluteTop: offsetTop, absoluteLeft: offsetLeft, 
        offsetWidth: offsetWidth, offsetHeight: offsetHeight }; 
} 


/*
function Object.prototype.clone(){
	var newObj = new Object();
	for(elements in this){
		newObj[elements] = this[elements];
	}
	return newObj;
}

function Object.prototype.cloneAll(){
	function clonePrototype(){}
	clonePrototype.prototype = this;
	var obj = new clonePrototype();
	for(var ele in obj){
		if(typeof(obj[ele])=="object") obj[ele] = obj[ele].cloneAll();
	}
	return obj;
}
*/

function addEvent(obj, sEvent, func)
{  
    var argu = Array.prototype.slice.call(arguments,3);
    var f = (function(){ func.apply(null,argu); }); 
    obj[sEvent] = f;    

}

function removeEvent(obj, sEvent)
{
    
    delete obj[sEvent];
    obj[sEvent] = null;
    
}


     // JScript File
window.setTimeoutEx = function(fRef, mDelay) {
    if(typeof fRef == 'function')
    {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return  window.setTimeout(f, mDelay);
    }
    return  window.setTimeout(fRef,mDelay);
}
    
    
window.setIntervalEx = function(fRef, mDelay) {
    if(typeof fRef == 'function')
    {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function(){ fRef.apply(null, argu); });
        return  window.setInterval(f, mDelay);
    }
        return  window.setInterval(fRef,mDelay);
    }    


/*
<div id="screenCover" style="position:absolute;width:100%;height:100%">
    <div id="parentCover" style="地位到一个窗口,大小，居中">
        <div> wenzi
        <div>
        <button></button>
        <button></button>
        <button></button>
    </div>
</div>

*/
/*
function   Sleep(numberMillis)   {   
  var   now   =   new   Date();   
  var   exitTime   =   now.getTime()   +   numberMillis;   
  while   (true)   {   
          now   =   new   Date();   
          if   (now.getTime()   >   exitTime)   
                  return;   
  }   
}   
*/

function MSG()
{
    this.message = 0;
    this.wParam = 0;
    this.lParam = 0;
};


function CaptureMSG()
{
    var msg = null;
    try
    {
        var strMSG = $$("VCOnline1").CaptureMSG();
        if (strMSG != "")
        {
            var ss = strMSG.split(",");
            msg = new MSG();
            msg.message = parseInt(ss[0],10);
            msg.wParam  = parseInt(ss[1],10);
            msg.lParam  = parseInt(ss[2],10);
        }
    }
    catch (e)
    {
    
    }
    return msg;
}

function Sleep(ms)
{
    try
    {
        $$("VCOnline1").Sleep(ms);
    }
    catch (e)
    {
    
    }
}

function Point(x,y)
{
    this.x = x;
    this.y = y;
}

function Rect(left,top,right,bottom)
{
    this.left = left;
    this.right = right;
    this.top = top;
    this.bottom = bottom;
    this.Width = function()
    {
        return (this.right - this.left);
    }
    this.Height = function()
    {
        return (this.bottom - this.top);
    }
    
    this.ToCenter = function (rc)
    {
       var left = rc.left + (rc.Width() - this.Width()) / 2;
       var top = rc.top + (rc.Height() - this.Height()) / 2;    
       var nRc = new Rect(left,top,  left + this.Width(), top + this.Height());
       return nRc;    
    }
}

function RectOfVisible()
{
    var left = document.documentElement.scrollLeft;
    var top = document.documentElement.scrollTop;
    var width = document.documentElement.clientWidth;
    var height = document.documentElement.clientHeight;
    return new Rect(left, top , left + width, top + height);
}

function RectOfElement(objEle)
{
    var pos = GetAbsoluteLocationEx(objEle);
    var left = pos.absoluteLeft;
    var top = pos.absoluteTop;
    var width = pos.offsetWidth;
    var height = pos.offsetHeight;
    return new Rect(left, top , left + width, top + height);
}

function MessageBox()
{
    
	this.oScreenDiv = document.createElement("div");
	
	this.oParentTable = document.createElement("table");
	this.oParentTableTr = this.oParentTable.insertRow(0);
	this.oParentTableTd = this.oParentTableTr.insertCell(0);
	
	
	this.oMsgTable = document.createElement("table");
	this.oMsgTableTr = this.oMsgTable.insertRow(0);
	this.oMsgTableTd = this.oMsgTableTr.insertCell(0);
	
	this.oMsgDiv = document.createElement("div");
	this.oCaptionDiv = document.createElement("div");
	this.oInfoDiv = document.createElement("div");
	this.oButtonDiv = document.createElement("div");
	this.oButtonYesInput = document.createElement("input");
	this.oButtonNoInput = document.createElement("input");
	this.oButtonOkInput = document.createElement("input");
	
	this.oButtonYesInput.type="button";
	this.oButtonNoInput.type="button";
	this.oButtonOkInput.type="button";
	
	this.oButtonYesInput.value="是";
	this.oButtonNoInput.value="否";
	this.oButtonOkInput.value="确定";
	
	
	this.oScreenDiv.className = "MessageBox_ScreenDiv";
	this.oParentTable.className = "MessageBox_ParentTable";
	this.oMsgTable.className = "MessageBox_MsgTable";
	this.oMsgDiv.className = "MessageBox_MsgDiv";
	this.oCaptionDiv.className = "MessageBox_CaptionDiv";
	this.oInfoDiv.className = "MessageBox_InfoDiv";
	this.oButtonDiv.className = "MessageBox_ButtonDiv";
	
	this.oButtonYesInput.className = "MessageBox_Button";
	this.oButtonNoInput.className = "MessageBox_Button";
	this.oButtonOkInput.className = "MessageBox_Button";
	
	this.oParentTableTd.appendChild(this.oMsgTable);
	this.oMsgTableTd.appendChild(this.oMsgDiv);
	this.oMsgDiv.appendChild(this.oCaptionDiv);
	this.oMsgDiv.appendChild(this.oInfoDiv);
	this.oMsgDiv.appendChild(this.oButtonDiv);
	
	this.oButtonDiv.appendChild(this.oButtonYesInput);
	this.oButtonDiv.appendChild(this.oButtonOkInput);
	this.oButtonDiv.appendChild(this.oButtonNoInput);
	
	
	this.offsetPositionBeginDrag = null;
	this.OnMouseMove = function(oThis)
	{
	    if (event.button  == 1)
	    {
	        if (oThis.offsetPositionBeginDrag == null)
	        {
	            var offsetX = event.x - oThis.oParentTable.offsetLeft;
	            var offsetY = event.y - oThis.oParentTable.offsetTop;
	            oThis.offsetPositionBeginDrag = new Point( offsetX , offsetY );
	        }
	        else
	        {
	            var offsetX = event.x - oThis.oParentTable.offsetLeft;
	            var offsetY = event.y - oThis.oParentTable.offsetTop;
	            
	            var moveX = offsetX -  oThis.offsetPositionBeginDrag.x;
	            var moveY = offsetY -  oThis.offsetPositionBeginDrag.y;

                oThis.oParentTable.style.left = oThis.oParentTable.offsetLeft + moveX;
                oThis.oParentTable.style.top  = oThis.oParentTable.offsetTop +  moveY;
                
	        }
	        
	    }
	    else
	    {
	        oThis.offsetPositionBeginDrag = null;
	    }
	}
	
	
	addEvent(this.oCaptionDiv,"onmousemove",this.OnMouseMove,this);
	
	
	this.onselectstart = function()
	{
        try
        {
             document.selection.empty ();
        }
        catch(e)
        {

        }
	}
	addEvent(this.oParentTable,"onselectstart",this.onselectstart,this);
	
	
	this.strReturn = null;
	
	
	this.OnYes = function(oThis)
	{
	     oThis.strReturn = "yes";
	     oThis.oScreenDiv.style.display = "none";
	     oThis.oParentTable.style.display = "none";
	}
	this.OnNo = function(oThis)
	{
	     oThis.strReturn = "no";
	     oThis.oScreenDiv.style.display = "none";
	     oThis.oParentTable.style.display = "none";
	}
	
	this.OnOk = function(oThis)
	{
	     oThis.strReturn = "ok";
	     oThis.oScreenDiv.style.display = "none";
	     oThis.oParentTable.style.display = "none";
	}
	
	addEvent(this.oButtonYesInput,"onclick",this.OnYes, this);
	addEvent(this.oButtonNoInput,"onclick",this.OnNo, this);
	addEvent(this.oButtonOkInput,"onclick",this.OnOk, this);
	
	this.oScreenDiv.style.display = "none";
	this.oParentTable.style.display = "none";
	
	
	this.Information = function(rcDisp, strCaption, strInfoText)
	{
	    this.oButtonYesInput.style.visibility = "hidden";
	    this.oButtonNoInput.style.visibility = "hidden";
	    this.oButtonOkInput.style.visibility = "";
	    this.Show(rcDisp, strCaption, strInfoText);
	}
	
	this.Show = function(rcDisp, strCaption, strInfoText)
	{
	   
	    document.body.appendChild(this.oScreenDiv); 
	    document.body.appendChild(this.oParentTable);
	    
	    this.oScreenDiv.style.display = "";
	    this.oParentTable.style.display = "";
	    
	    var rcOfVisilbe = RectOfVisible();
	    
	    
	    this.oScreenDiv.style.left = rcOfVisilbe.left;
	    this.oScreenDiv.style.top = rcOfVisilbe.top;
	    this.oScreenDiv.style.width = rcOfVisilbe.Width();
	    this.oScreenDiv.style.height = rcOfVisilbe.Height();
	   
	    
	    
	    
	    this.oParentTable.style.left = rcDisp.left; 
	    this.oParentTable.style.top = rcDisp.top;
	    this.oParentTable.width = rcDisp.Width(); 
	    this.oParentTable.height = rcDisp.Height();
	    //debugger;
		this.oCaptionDiv.innerText = strCaption;
		this.oInfoDiv.innerHTML = strInfoText;
		
	    while (this.oScreenDiv.style.display != "none")
	    {
	        var msg = CaptureMSG();
	        if (msg != null && msg.message == parseInt("0x0101",16))
	        {
	            if (msg.wParam == 13)
	            {
	                if (this.oButtonYesInput.style.visibility == "")
	                {
	                    this.OnYes(this);
	                }
	                else if (this.oButtonOkInput.style.visibility == "")
	                {
	                    this.OnOk(this);    
	                }
	            }
	            else if (msg.wParam == 27)
	            {
	                if (this.oButtonNoInput.style.visibility == "")
	                {
	                    this.OnNo(this);
	                }
	                else if (this.oButtonOkInput.style.visibility == "")
	                {
	                    this.OnOk(this);    
	                }
	            }
	        }
	        else
	        {
	            Sleep(10);
	        }
	    }
	}
	
	this.Confirm = function(rcDisp, strCaption, strInfoText)
	{
	    this.oButtonYesInput.style.visibility = "";
	    this.oButtonNoInput.style.visibility = "";
	    this.oButtonOkInput.style.visibility = "hidden";
	    this.Show(rcDisp, strCaption, strInfoText);
	    return this.strReturn;
	}
	
	
}

function FloatEle(oDisplayRelativeEle)
{
    this.m_oSrcEle = null;
    this.m_oDisplayRelativeEle = oDisplayRelativeEle;
    
    
    
    
    this.OnMouseEnter = function(oThis)
    {
        //oThis.m_oSrcEle.style.width = oThis.m_oToEle.offsetWidth;
    }
    
    this.OnMouseLeave = function(oThis)
    {
        //oThis.m_oSrcEle.style.width = 10;
    }
   // addEvent(this.m_oSrcEle,"onmouseenter",this.OnMouseEnter,this);
   // addEvent(this.m_oSrcEle,"onmouseleave",this.OnMouseLeave,this);
    
    this.SetFloatEle = function(oSrcEle)
    {
        if (this.m_oSrcEle != null)
        {
            this.m_oSrcEle.style.display = "none";
        }
        this.m_oSrcEle = oSrcEle;
        this.m_oSrcEle.style.width = "100%";
        this.m_oSrcEle.style.height = 32;
        this.m_oSrcEle.style.backgroundColor = "#96C6FA";
        this.m_oSrcEle.style.textAlign = "right";
        this.m_oSrcEle.style.overFollow ="hidden";
        //this.m_oSrcEle.style.lineHeight = 32;
    
    
    }
    
    this.Update = function()
    {
        if (this.m_oSrcEle != null)
        {
            this.m_oSrcEle.style.display = "";
            var rcVisible = RectOfVisible();
            this.m_oSrcEle.style.position = "absolute";
            this.m_oSrcEle.style.left = rcVisible.left;
            this.m_oSrcEle.style.top = rcVisible.bottom - this.m_oSrcEle.offsetHeight;
           
        }
    
    }
    
    this.CheckPosition = function(oThis)
    {
        
        if (oThis.m_oDisplayRelativeEle.style.display == "none")
        {
            if (oThis.m_oSrcEle != null)
            {
                oThis.m_oSrcEle.style.display = "none";
            }
        }
        else
        {
            oThis.Update();
        }
        setTimeoutEx( oThis.CheckPosition, 100 , oThis);
    }
    setTimeoutEx( this.CheckPosition, 100, this);
    
}

function mediaFilePath(node, type)
{
	if (node.constructor == String)
		return _appClient.strDataUrl+"/"+node;
	if (!node || !node.ownerDocument)
		return "";
	var path = node.ownerDocument.selectSingleNode("//@path");
	if (path)
		path = path.text;
	else
		return "";
	var name;
	if (type)
	{
		name = node.selectSingleNode("@"+type);
		if (name)
			name = name.text;
	}
	else
		name = node.text;
	if (!name)
		return "";
	return _appClient.strDataUrl+"/"+path+"/"+name;
	//return GetMediaFile(_appClient.strDataRelative+"/"+path+"/"+name);
}

function MediaStop()
{
    $$("wmp1").controls.stop();
    $$("VCOnline1").RecordStop();
    
    while (1)
    {
        if ( ($$("wmp1").playState == 0  || $$("wmp1").playState == 1  || $$("wmp1").playState == 10) && $$("VCOnline1").IsRecording() == false)
            break;
        $$("VCOnline1").Sleep(10);
    }
    $$("wmp1").URL = "";
    $$("VCOnline1").Sleep(50);
}


function SetButton(oButton, rawValue, keyCode)
{
    oButton.rawValue = rawValue;
    oButton.keyCode = keyCode;
    RefreshButton(oButton);
    
}
function RefreshButton(oButton)
{
    var nKeyCode = parseInt(oButton.keyCode,10);
    switch (nKeyCode)
    {
        case 13:
            oButton.value = oButton.rawValue + "(Enter)";
            break;
        case 27:
            oButton.value = oButton.rawValue + "(Esc)";
            break;    
        case 48:
            oButton.value = oButton.rawValue + "(0)";
            break;
        case 49:
            oButton.value = oButton.rawValue + "(1)";
            break;
        case 50:
            oButton.value = oButton.rawValue + "(2)";
            break;
        default:
            oButton.value = oButton.rawValue;
            break;      
        
    }
}
function PlayMp3File(strFileName)
{
    try
    {
		if ( strFileName.indexOf("\\_") < 0)//不是录音数据才变速		{
			if ( $$("RadioButton1").checked == true)
			{
				$$("wmp1").settings.rate = 0.7;
			}
			else if ( $$("RadioButton3").checked)
			{
				$$("wmp1").settings.rate = 1.5;
			}
			else 
			{
				$$("wmp1").settings.rate = 1.0;
			}
		}   
    }
    catch(e)
    {
    
    }
    $$("wmp1").URL = strFileName;
}

function GetLocalMp3TimeLength(strMp3FileName)
{
    var strWavFileName = strMp3FileName.replace(/.mp3$/gi,".wav");
    
    if ( $$("VCOnline1").IsFileExist(strWavFileName) == false)
    {
        $$("VCOnline1").ToWAV(strMp3FileName);
    }
    
    return $$("VCOnline1").GetLocalWaveTimeLength(strWavFileName);
}