﻿// JScript 文件
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


function loadPage(sId,wid,skinId,c,isRecord,gId){
var referrer = document.referrer; 
if (!referrer) { 
    try { 
        if (window.opener) { 
            // IE下如果跨域则抛出权限异常 
            // Safari和Chrome下window.opener.location没有任何属性 
            referrer = window.opener.location.href; 
        } 
    } catch (e) {} 
}


    var cId = readCookie('cId');
	document.write(unescape("%3Cscript src='http://cw.sqsina.com/C.ashx?cId="+cId+"&skinId="+skinId+"&sId="+sId+"&c="+c+"&wid="+wid+"&gId="+gId+"&isRecord="+isRecord+"&rurl="+encodeURI(escape(referrer))+"&cUrl="+window.location.href+"' type='text/javascript'%3E%3C/script%3E"));
}
 
//alert("window.location.host="+window.location.href);
function querystring(){
    this.params = new Object();
    this.initialize = function(){
        var param=this.paramstring();
        if(param.length == 0) return;
        if(param.substring(0,1)=='?'){
            param=param.substring(1);
        }
        param = param.replace(/\+/g, ' ');
        var args = param.split('&');
        for (var i=0;i<args.length;i++){
            var value;
            var pair = args[i].split('=');
            var name = unescape(pair[0]);
            if (pair.length == 2)
                value = unescape(pair[1]);
            else
                value = name;
            this.params[name] = value; 
        }
    };
    this.get = function(key, defvalue){
        return this.params[key]==null?defvalue:this.params[key];
    };
    this.paramstring = function(){
        var col=document.getElementsByTagName("script");
        var jsrc=col.item(col.length-1).src;
        var i=jsrc.indexOf("?");
        var words=jsrc.substr(i+1,jsrc.length);
        return(words);
    };
    this.initialize();
}
var lastScrollYChat=0;
var timeout
function moveR() {

    var diffY;
    var diffX;
    if (document.documentElement)
    {
        diffY = document.documentElement.scrollTop+(document.documentElement.clientHeight-msn.offsetHeight)/2;
        diffX = document.documentElement.scrollLeft+document.documentElement.clientWidth-msn.offsetWidth;
    }
    else if (document.body)
    {
        diffY = document.body.scrollTop+(document.body.clientHeight-msn.offsetHeight)/2;
        diffX = document.body.scrollLeft+document.body.clientWidth-msn.offsetWidth;
    }
    else{/*Netscape stuff*/}

    percent=.1*(parseInt(diffY)-lastScrollYChat);
    if(percent>0)
        percent=Math.ceil(percent);
    else 
        percent=Math.floor(percent);
    msn.style.top=parseInt(msn.style.top)+percent+"px";
    msn.style.left=diffX+"px";
    lastScrollYChat=lastScrollYChat+percent;
    if(percent == 0)
        setTimeout("moveR();",200)
    else
        setTimeout("moveR();",1)    
}
function closeDiv(){
	msn.style.visibility='hidden';
}
loadPage(new querystring().get('sId','0'),new querystring().get('wid','0'),new querystring().get('skinId','0'),new querystring().get('c','1'),new querystring().get('isRecord','0'),new querystring().get('gId','-1'));


function openCallWo(sId,gId,wId,cUrl,cId)
	{
	 
	if(cId-0<=0){
	    cId=readCookie("cId");
	    if(cId==null){
	        cId=Math.random() * 999999999 + 99999;
	    }
	}
		 
        var s_left=screen.availWidth;
        var s_top=screen.availHeight;
        s_left = (s_left - 700)/2;
        s_top = (s_top - 500)/2-100;
        objWin__ = window.open( "http://cw.sqsina.com/Client.htm?cId="+cId+"&gId="+gId+"&sId=" + sId + "&wId="+wId+"&cUrl=" + cUrl,"woocall", 

"scrollbars=no,status=yes,resizable=no,top="+s_top+",left="+s_left+",width=700,height=500, toolbar=no, menubar=no, scrollbars=no, resizable=yes, status=no");
	    objWin__ .focus();
	    window.opener=null; 
        window.open('','_self');
        return true;
         
	}
	
//function openCallWo(sId,gId,wId,cUrl,cId)
//	{
//        openCallWo(sId,-1,wId,cUrl,cId)
//         
//	}
	
	
//	
//	
//	    function __clear(timer){  
//        clearTimeout(timer);  
//        clearInterval(timer);  
//        return null;  
//    };  
//      
//    function __attach_event(evt, callback) {  
//        if (window.addEventListener) {  
//            window.addEventListener(evt, callback, false);  
//       } else if (window.attachEvent) {  
//           window.attachEvent("on" + evt, callback);  
//       }  
//   }  
//     
//   function __domReady(f) {  
//       // 假如 DOM 已经加载，马上执行函数  
//       if (__domReady.done) return f();  
//       // 假如我们已经增加了一个函数  
//       if (__domReady.timer) {  
//           // 把它加入待执行函数清单中  
//           __domReady.ready.push(f);  
//       } else {  
//           // 为页面加载完毕绑定一个事件，  
//           // 以防它最先完成。使用addEvent(该函数见下一章)。  
//           __attach_event("load", __isDOMReady);  
//           // 初始化待执行函数的数组  
//           __domReady.ready = [f];  
//           // 尽可能快地检查DOM是否已可用  
//           __domReady.timer = setInterval(__isDOMReady, 100);  
//       }  
//   }  
//   function __isDOMReady() {  
//       // 如果我们能判断出DOM已可用，忽略  
//       if (__domReady.done) return false;  
//       // 检查若干函数和元素是否可用  
//       if (document && document.getElementsByTagName && document.getElementById && document.body) {  
//           // 如果可用，我们可以停止检查  
//           __clear(__domReady.timer);  
//           __domReady.timer = null;  
//           // 执行所有正等待的函数  
//         
//           if(__domReady.ready!=null){
//               for ( var i = 0; i < __domReady.ready.length; i++ ) {  
//                   __domReady.ready[i]();  
//               }
//           }
//           // 记录我们在此已经完成  
//           __domReady.ready = null;  
//           __domReady.done = true;  
//       }  
//   }  
//   
//   
//   
//   
//    __domReady(function() {    
//        alert("The dom is loaded!");    
//});  
