/**
 * @author YangChao
 */
var EC_CS_lastScrollY = 0;
var EC_CS_Heightmain = 0;		//主面板位置
var EC_CS_Heightdlg1 = 0;		//对话框1
var EC_CS_Heightdlg2 = 0;		//对话框2
function ec_cs_moveDiv(id, sid,obj){
	if (obj=='dlg2'){
		EC_CS_lastScrollY = EC_CS_Heightdlg2;
	}else if (obj=='dlg1'){
		EC_CS_lastScrollY = EC_CS_Heightdlg1;
	}else{
		EC_CS_lastScrollY = EC_CS_Heightmain;
	}
	
    var diffY;
    if (document.documentElement && document.documentElement.scrollTop) {
        diffY = document.documentElement.scrollTop;
    }
    else 
        if (document.body) {
            diffY = document.body.scrollTop;
        }
        else {
        }
    percent = 0.1 * (diffY - EC_CS_lastScrollY);
    if (percent > 0) {
        percent = Math.ceil(percent);
    }
    else {
        percent = Math.floor(percent);
    }
    if (EC_CS_TYPE == 2) {// 上下悬浮
        if (EC_CS_STYLE == 1) {
            document.getElementById(id).style.top = parseInt(document.getElementById(id).style.top) + percent + "px";
        }
        else {
            document.getElementById(id).style.bottom = parseInt(document.getElementById(id).style.bottom) - percent + "px";
            if (navigator.Actual_Version == "6.0") {
                document.getElementById(id).style.bottom = 0;
            }
        }
    }
    else {
        document.getElementById(id).style.top = parseInt(document.getElementById(id).style.top) + percent + "px";
        if (EC_CS_PANEL_POS) {
            EC_CS_PANEL_POS.top = parseInt(document.getElementById(id).style.top) + percent;
        }
    }
    /*
     * 
     
    if (document.getElementById(sid)) {
        document.getElementById(sid).style.top = parseInt(document.getElementById(sid).style.top) + percent + "px";
    }
    */
    EC_CS_lastScrollY = EC_CS_lastScrollY + percent;
	if (obj=='dlg2'){
		EC_CS_Heightdlg2 = EC_CS_lastScrollY;
	}else if (obj=='dlg1'){
		EC_CS_Heightdlg1 = EC_CS_lastScrollY;
	}else{
		EC_CS_Heightmain = EC_CS_lastScrollY
	}
}

function ec_cs_fnOpenSms(id){
    var url = EC_CS_SERVER + "sms?id=" + id + "&corpid=" + EC_CS_ID + "&scheme=" +EC_CS_SCHEME;
    var w = window.open(url,'ECCSTalk', 'height=400,width=447,status=no,toolbar=no,menubar=no,location=no');
}

function ec_cs_fnOpenTalk(id, status, smsonline){
    if (status == '0' && smsonline == '1') {
        ec_cs_fnOpenSms(id);
        return;
    }
    var url = EC_CS_SERVER + "talk?id=" + id + "&corpid=" + EC_CS_ID + "&scheme=" +EC_CS_SCHEME;
    var w = window.open(url, 'ECCSTalk', 'height=400,width=447,status=no,toolbar=no,menubar=no,location=no');
}

function ec_cs_fnOpenTalk2(id, action){
    var url = EC_CS_SERVER + "cs/?id=" + id + "&scheme=" +EC_CS_SCHEME +"&handle="+action;
    var w = window.open(url,'ECCSTalk', 'height=480,width=705,status=no,toolbar=no,menubar=no,location=no');
    ec_cs_fnDialogCancle();
}

function ec_cs_fnDialogOK(){
	//随即找在线
	var len = EC_CS_ONLINES.length;
	if (len > 0) {
		var index = Math.floor(Math.random() * (len - 1));
		ec_cs_fnOpenTalk2(EC_CS_ONLINES[index],'talk');
	}else if(EC_CS_SMSLINES.length > 0){
		len = EC_CS_SMSLINES.length;
		var index = Math.floor(Math.random() * (len - 1));
		ec_cs_fnOpenTalk2(EC_CS_SMSLINES[index],'sms');	
	}else{
		len = EC_CS_OFFLINES.length;
		if (len > 0) {
			var index = Math.floor(Math.random() * (len - 1));
			ec_cs_fnOpenTalk2(EC_CS_OFFLINES[index],'msg');		
		}
	}
	ec_cs_fnDialogCancle();
	/*
	if (EC_CS_TIMER) {
		window.clearTimeout(EC_CS_TIMER);
	}*/
}

function ec_cs_fnCallOK(){
    var url = EC_CS_SERVER + "cs/callrand?id=" + EC_CS_ID + "&scheme=" +EC_CS_SCHEME;
    var w = window.open(url,'ECCSTalk', 'height=480,width=705,status=no,toolbar=no,menubar=no,location=no');
}

function ec_cs_fnDialogCancle(){
    var obj = document.getElementById('ec_cs_showdlg');
    obj.style.display = "none";
    EC_CS_ISBUZY = false;
    if (document.getElementById('ec_cs_showdlg2')){
    	document.getElementById('ec_cs_showdlg2').style.display = "none";
        EC_CS_ISBUZY = false;   	
    }  
}

