currentX = currentY = 0;   
whichIt = null;            
lastScrollX = 0; lastScrollY = 0; 
volumeWidth=32
var expand=0    
var timeStart
var MS=navigator.appVersion.indexOf("MSIE")
var MSVER=parseInt(navigator.appVersion.substring(MS+5,MS+6))

function showstatus(text){
document.all.Status.innerHTML='<marquee style="font-family: 宋体; font-size: 9pt; color: rgb(0,164,0)" align="bottom" border="0" scrolldelay="90" scrollamount="2" width="135">' + text +'</marquee>'
//document.all.Status.style.visibility="visible"
}

function GetProxySetting(){
	if (GetCookie("ProxyType") == null)
		document.all.ProxyType.value=2
	else
		document.all.ProxyType.value=GetCookie("ProxyType")
		
	if (GetCookie("ProxyIP") == null)
		document.all.ProxyAddress.value=""
	else
    	document.all.ProxyAddress.value=GetCookie("ProxyIP")
 		
 	if (GetCookie("ProxyPort") == null)
 		document.all.ProxyPort.value=""
 	else    
    	document.all.ProxyPort.value=GetCookie("ProxyPort")
    
    if (GetCookie("ProxyUserName")== null)
    	document.all.UserName.value=""
    else
    	document.all.UserName.value=GetCookie("ProxyUserName")
    if (GetCookie("ProxyPasswd") == null )
    	document.all.UserPassword.value=""
    else
    	document.all.UserPassword.value=GetCookie("ProxyPasswd")
}

function SaveProxySetting(){
	var now = new Date()
//	alert(now.toLocaleString())
	var expdate = new Date()
	expdate.setTime(now.getTime()+1000*60*60*24*360)

	SetCookie("ProxyType",document.all.ProxyType.value,expdate)
		
    SetCookie("ProxyIP",document.all.ProxyAddress.value, expdate)
 		    
    SetCookie("ProxyPort",document.all.ProxyPort.value,expdate)

    SetCookie("ProxyUserName",document.all.UserName.value,expdate)

    SetCookie("ProxyPasswd",document.all.UserPassword.value,expdate)	
    return true
}

function getMicVol()
{
	return Math.round(volumeWidth*(AccessAgent.GetVolume(1)/100))
}
function getSpkVol()
{	
	return Math.round(volumeWidth*(AccessAgent.GetVolume(0)/100))
}

function Keypad_MouseDown(key)
{
	var obj=eval("document.images.key"+key);
	obj.src = "WebPhonePic/keypad"+key+"_down.gif";
}

function keyPress() {
/*
	if (event.keyCode == 13)
	{
		CallPhone();
		return true;
	}
*/
	if (AccessAgent.IsCalling()!=0)
		AccessAgent.UserInput(event.keyCode);
}

function UserInput(ch)
{
	if (AccessAgent.IsCalling()!=0)
		AccessAgent.UserInput(ch.charCodeAt(0))
}

function Keypad_MouseUp(key)
{
	var obj=eval("document.images.key"+key);
	obj.src = "WebPhonePic/keypad"+key+"_up.gif";
	if (key=='a') key='*';
	if (key=='b') key='#';
	numberstr=document.all.DialNum.value;
	numberstr=numberstr+key;
	document.all.DialNum.value=numberstr;
	UserInput(key);
}

function CallPhone()
{
		var result
	
		var AccessServer = GetCookie("AccessServer")
		var AccessServerPort = parseInt(GetCookie("AccessServerPort"))
		var ID = GetCookie("ID")
		var Password = GetCookie("Password")
		var phone=GetCookie("PhoneNumber")
		if (AccessServer==null)
		    AccessServer=""
		if (AccessServerPort==null)
		    AccessServerPort=80
		if (phone==null)
		    phone=""
		if (ID==null)
		    ID=""
		if (Password==null)
		    Password=""
		//result = AccessAgent.Init(AccessServer,AccessServerPort)
result = AccessAgent.Init('211.157.219.33','80')
		
		if( result==1)
		{	
			clearTimeout(timeID)  

	       document.images.a.src="WebPhonePic/cb.gif" 
    	   document.images.b.src="WebPhonePic/cb.gif" 
	       document.images.d.src="WebPhonePic/cb.gif" 
    	   document.images.e.src="WebPhonePic/cb.gif" 
       	   document.images.g.src="WebPhonePic/cb.gif" 
       	   document.images.h.src="WebPhonePic/cb.gif" 
       		
       	   var proxyip=GetCookie("ProxyIP")
           if (proxyip==null)
       	   		proxyip = ""
    	   var proxytype=GetCookie("ProxyType")
       	   if (proxytype==null || proxytype==2)
       	   {
       			proxyip=""
       			proxytype=2
       		}
	       var proxyport=GetCookie("ProxyPort")
           if (proxyport==null)
	            proxyport = 0	
           var proxyusername=GetCookie("ProxyUserName")
           var proxypasswd=GetCookie("ProxyPasswd")
           if (proxyusername ==null)
      	        proxyusername = ""
           if (proxypasswd == null)
      	        proxypasswd = ""
      
           AccessAgent.SetProxyInfo(proxytype,proxyip,proxyport, proxyusername,proxypasswd)
 
          // AccessAgent.CallTo(phone,ID,Password)
AccessAgent.CallTo('2700',ID,Password)
        } 
}

function HangupPhone()
{
	AccessAgent.Hangup()
}

function CallMouseDown()  {                                                                                                                
    if (document.images.call.src.search("WebPhonePic/call_up.gif") != -1)
        document.images.call.src = "WebPhonePic/call_down.gif"                                                                                                             
}                  

function CallMouseUp()    {
    if (document.images.call.src.search("WebPhonePic/call_down.gif") != -1) {                                                                                                              
        document.images.call.src = "WebPhonePic/call_up.gif"                                                                                                             
		if (AccessAgent.IsCalling()!=0)
		{
			alert("您正在通话中，请挂断后再拨")
			return 1;
		}
		showstatus("正在呼叫...")
		CallPhone()
   }
} 

function ConfigClick()
{
	if(document.all.floater1.style.display=="block")  {
		if (MSVER>=6)                                                                                                                                                                                                                                                                                                                                                          
        	top.window.resizeTo(169,179);
		else
			top.window.resizeTo(167,154);
    	document.all.floater1.style.display="none";
	}	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
	else {
		if (MSVER>=6)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
        	top.window.resizeTo(169,322);
        else
        	top.window.resizeTo(167,296);
        document.all.floater1.style.display="block";
		if(document.all.floater2.style.display=="block")
		{
			DialpadMouseDown();
	    	document.all.floater2.style.display="none";
	    }
   }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
}

function ConfigMouseDown()
{
   if (document.images.config.src.search("WebPhonePic/config_up.gif") != -1) { 
       document.images.config.src = "WebPhonePic/config_down.gif" 
   } 
   else
       document.images.config.src = "WebPhonePic/config_up.gif" 
}

function DialpadMouseDown()
{
   if (document.images.dialpad.src.search("WebPhonePic/dialpad_up.gif") != -1) { 
       document.images.dialpad.src = "WebPhonePic/dialpad_down.gif" 
   } 
   else
       document.images.dialpad.src = "WebPhonePic/dialpad_up.gif" 
}

function DialpadClick()
{
	if(document.all.floater2.style.display=="block")  {
		if (MSVER>=6)
			top.window.resizeTo(169,179);
		else
        	top.window.resizeTo(167,154);
    	document.all.floater2.style.display="none";
	}	                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
	else {                     
		if (MSVER>=6)
			top.window.resizeTo(169,322);
		else
			top.window.resizeTo(167,296);
        document.all.floater2.style.display="block";
		if(document.all.floater1.style.display=="block")
		{
			ConfigMouseDown();
	    	document.all.floater1.style.display="none";
	    }
   }                                
}

function ClickMin(){ 
    document.all.floater.style.display="none";                                                                                                                                                                                                    
    document.all.floater1.style.display="none";               
    document.all.floater2.style.display="block"; 
    top.window.resizeTo(160,23);
} 
function ClickMax(){ 
    document.all.floater2.style.display="none"; 
    document.all.floater.style.display="block";                                                                                                                                                                                                    
    if (expand == 1)
    {
 	   document.all.floater1.style.display="block";  
 	   top.window.resizeTo(160,253);
 	}
 	else
 	   top.window.resizeTo(160,125);
}
function ClickClose()
{
	top.window.close();
} 

function BeenHangUp() { 
	clearTimeout(timeID)  
	showstatus("点击呼叫按钮开始通话...")
} 

function HangUpMouseUp(){ 
    if (document.images.hangup.src.search("WebPhonePic/hangup_down.gif") != -1)
       document.images.hangup.src = "WebPhonePic/hangup_up.gif"                                                                                                                                                                                                                                                                                                                                              
    if (AccessAgent.IsCalling()!=0)
    {
		showstatus("呼叫挂断中...")
		HangupPhone()
	}
	else
		showstatus("点击呼叫按钮开始通话...")
} 

function HangUpMouseDown(){ 
    if (document.images.hangup.src.search("WebPhonePic/hangup_up.gif") != -1) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
       document.images.hangup.src = "WebPhonePic/hangup_down.gif"                                                                                                                                                                                                                                                                                                                                              
    } 
} 

function GetCookie (name) {  
    var arg = name + "=";  
    var alen = arg.length;  
    var clen = document.cookie.length;  
    var i = 0;  
    while (i < clen) {  
       var j = i + alen;  
       if (document.cookie.substring(i, j) == arg) { 
           return getCookieVal (j);  
       } 
       i = document.cookie.indexOf(" ", i) + 1;  
       if (i == 0)  
           break;  
    }  
    return null;  
} 
function getCookieVal (offset) {   
	var endstr = document.cookie.indexOf (";", offset);   
	if (endstr == -1)     
		endstr = document.cookie.length;   
	return document.cookie.substring(offset, endstr); 
} 

function SetCookie (name, value) {   
	var argv = SetCookie.arguments;   
	var argc = SetCookie.arguments.length;   
	var expires = (argc > 2) ? argv[2] : null;   
//	alert("expires="+ expires.toGMTString())
	var path = (argc > 3) ? argv[3] : null;   
	var domain = (argc > 4) ? argv[4] : null;   
	var secure = (argc > 5) ? argv[5] : false;   
	document.cookie = name + "=" + escape (value) +  
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +  
	((path == null) ? "" : ("; path=" + path)) +   
	((domain == null) ? "" : ("; domain=" + domain)) +     
	((secure == true) ? "; secure" : ""); 
}
function ShowNM() { 
	if (AccessAgent.style.visibility != "hidden") { 
   	    AccessAgent.style.visibility = "hidden";  
	} 
} 
var IE=null 
var NS=null 
//detect system information  
NS = (document.layers) ? 1 : 0; 
IE = (document.all) ? 1: 0; 
var dn   
var timeID=null   
c1=new Image(); c1.src="WebPhonePic/c1.gif"   
c2=new Image(); c2.src="WebPhonePic/c2.gif"   
c3=new Image(); c3.src="WebPhonePic/c3.gif"   
c4=new Image(); c4.src="WebPhonePic/c4.gif"   
c5=new Image(); c5.src="WebPhonePic/c5.gif"   
c6=new Image(); c6.src="WebPhonePic/c6.gif"   
c7=new Image(); c7.src="WebPhonePic/c7.gif"   
c8=new Image(); c8.src="WebPhonePic/c8.gif"   
c9=new Image(); c9.src="WebPhonePic/c9.gif"   
c0=new Image(); c0.src="WebPhonePic/c0.gif"   
cb=new Image(); cb.src="WebPhonePic/cb.gif"   
cam=new Image(); cam.src="WebPhonePic/cam.gif"   
cpm=new Image(); cpm.src="WebPhonePic/cpm.gif"   
function extract(h,m,s,type) {   
    if (!document.images)   
        return   
    if (h<=9){   
        document.images.a.src=cb.src   
        document.images.b.src=eval("c"+h+".src")   
    }   
    else {   
        document.images.a.src=eval("c"+Math.floor(h/10)+".src")   
        document.images.b.src=eval("c"+(h%10)+".src")   
    }   
    if (m<=9){   
        document.images.d.src=c0.src   
        document.images.e.src=eval("c"+m+".src")   
    }   
    else {   
        document.images.d.src=eval("c"+Math.floor(m/10)+".src")   
        document.images.e.src=eval("c"+(m%10)+".src")   
    }   
    if (s<=9){   
        document.g.src=c0.src   
        document.images.h.src=eval("c"+s+".src")   
    }   
    else {   
        document.images.g.src=eval("c"+Math.floor(s/10)+".src")   
        document.images.h.src=eval("c"+(s%10)+".src")   
    }   
}   
function showTime(seed){   
    if (!document.images) 
    {
        return   
    }
    if (seed == 0)
    {
    	timeStart = new Date()
    }
    seed++
//    var       mod=seed%3600;     
//    var       hours=(seed-mod)/3600     
//    var       seconds=mod%60    
//    var       minutes=(seed-3600*hours-seconds)/60;    
	var timeNow = new Date()
    var hours=Math.floor((timeNow.getTime()-timeStart.getTime())/(3600*1000))
    var minutes=Math.floor((timeNow.getTime()-timeStart.getTime())/(60*1000))%60
    var seconds=Math.floor((timeNow.getTime()-timeStart.getTime())/1000)%60

    dn="AM"    
    
//    if ((hours>=12)&&(minutes>=1)||(hours>=13)){   
//      dn="PM"   
//        hours=hours-12   
//    }   
    extract(hours,minutes,seconds,dn)   
    var cmd="showTime("+seed+")";
    timeID=setTimeout(cmd,1000);    
}
function makevisible(cur,which){   
    if (which==0) {   
        if(IE) {   
            document.all.floater.filters.alpha.opacity=100;   
            if(expand==1)   
                document.all.floater1.filters.alpha.opacity=100; 
        }   
        if(NS) {   
            document.floater.filters.alpha.opacity=100;   
            if(expand==1)   
                document.floater1.filters.alpha.opacity=100; 
        }   
    }   
    else  {   
        if(IE) {   
            document.all.floater.filters.alpha.opacity=20;   
            if(expand==1)   
                document.all.floater1.filters.alpha.opacity=20;   
        }   
        if(NS) {   
            document.floater.filters.alpha.opacity=20;   
            if(expand==1)   
                document.floater.filters1.alpha.opacity=20; 
        }   
    }   
}     
function checkFocus(x,y) {  
    stalkerx = document.floater.pageX; 
    stalkery = document.floater.pageY; 
    stalkerx = document.floater1.pageX; 
    stalkery = document.floater1.pageY; 
    stalkerwidth = document.floater.clip.width; 
    stalkerheight = document.floater.clip.height; 
    stalkerwidth = document.floater1.clip.width; 
    stalkerheight = document.floater1.clip.height; 
    if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight)))  
    	return true; 
    else  
    	return false; 
} 
function grabIt(e) { 
	var IsVolume;
	IsVolume=true;
        whichIt = event.srcElement;
        while (whichIt.id.indexOf("spkblock") == -1 && whichIt.id.indexOf("micblock") == -1) { 
	        whichIt = whichIt.parentElement; 
            if (whichIt == null)  
            {
            	IsVolume=false; 
            	break;
            }
    	}
    	if (IsVolume==false && MSVER<6)
    	{
    	whichIt = event.srcElement; 
        while (whichIt.id.indexOf("floater") == -1 && whichIt.id.indexOf("floater1") == -1 && whichIt.id.indexOf("floater2") == -1) { 
	        whichIt = whichIt.parentElement; 
            if (whichIt == null)  
            	return true; 
    	} 
    	}
    	currentX = window.event.screenX; 
    	currentY = window.event.screenY;
  //     	whichIt.setCapture();  
    return false; 
} 
function moveIt() { 
    if (whichIt == null)  
    	return false;  
    if (whichIt.id.indexOf("spkblock") != -1 || whichIt.id.indexOf("micblock") != -1 ){
    	moveVolume();
    	return false;
    }
    newX = 2*window.event.screenX - window.event.x - currentX; 
    newY = 2*window.event.screenY - window.event.y - currentY;
    currentX= window.event.screenX;
    currentY= window.event.screenY; 
//    top.window.moveTo(newX,newY);
    return true;
}

function moveVolume() {
	if (whichIt == null) {return false; }
        newX = window.event.screenX; 
        newY = window.event.screenY; 
        distanceX = (newX - currentX);    distanceY = (newY - currentY); 
        currentX = newX;    currentY = newY; 
        if (whichIt.style.pixelLeft+distanceX<0)
        	whichIt.style.pixelLeft = 0;
        else if (whichIt.style.pixelLeft+distanceX>volumeWidth)
        	whichIt.style.pixelLeft = volumeWidth;
        else 
        	whichIt.style.pixelLeft = whichIt.style.pixelLeft+distanceX;
        event.returnValue=false;
	    if(whichIt.id=="micblock")
			AccessAgent.SetVolume(1,Math.round(100*(whichIt.style.pixelLeft/volumeWidth)))
		if(whichIt.id=="spkblock")
			AccessAgent.SetVolume(0,Math.round(100*(whichIt.style.pixelLeft/volumeWidth)))
        return true;
} 
function dropIt() { 
	if (whichIt == null)
		return false;
//    whichIt.releaseCapture();
    whichIt = null;
    return true; 
} 
document.onmousedown = grabIt; 
document.onmousemove = moveIt; 
document.onmouseup = dropIt; 

