﻿
//if(location.href.indexOf("/html/article")>0)
//{
//    document.oncontextmenu=function(){return false};
//    document.ondragstart=function(){return false};
//    document.onselectstart =function(){return false};
//    document.onselect=function(){document.selection.empty();};
//    document.oncopy=function(){document.selection.empty();};
//    document.onbeforecopy=function(){return false};
//    //document.onmouseup=function(){document.selection.empty();}
//    
//    if(location.href.indexOf("univs")<0)
//    {
//        if (top.location != location) top.location.href = location.href;
//    }
//}


//fix firefox has no innerText

window.onerror=function(){return true;}
if(window.HTMLElement){
    HTMLElement.prototype.__defineGetter__ 
   ( 
     "innerText", 
      function (){ 
      var anyString = ""; 

      var childS = this.childNodes; 
      for(var i=0; i<childS.length;i++){ 
        if(childS[i].nodeType==1) 
           anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText; 
        else if(childS[i].nodeType==3) 
           anyString += childS[i].nodeValue; 
      } 
      return anyString; 
     } 
   ); 
}
String.prototype.realLength = function()
{
  return this.replace(/[\u4e00-\u9fa5]/g,"**").length;
}

function $(elem)
{
   return document.getElementById(elem);
}

function show(ids)
{
   var idarr=ids.split("|");
   for(var i=0;i<idarr.length;i++)
   {
      if($(idarr[i])!=null)
         $(idarr[i]).style.display="";
   }
}

function hide(ids)
{
   var idarr=ids.split("|");
   for(var i=0;i<idarr.length;i++)
   {
      if($(idarr[i])!=null)
         $(idarr[i]).style.display="none";
   }
}

function alertError(msg)
{
   var _msg="对不起，发生错误，请重新尝试！";
   if(msg!=null&&msg!="")
      _msg=msg;
   alert(_msg);
}

function alertOK(msg)
{
   var _msg="操作成功！";
   if(msg!=null&&msg!="")
      _msg=msg;
   alert(_msg);
}

function checkAll(str)
{
 var a = document.getElementsByName(str);
 var n = a.length;
 for (var i=0; i<n; i++)
 a[i].checked = window.event.srcElement.checked;
}

//获得当前时间
function getDatetimeNow()
{
   var d = new Date();
   var vYear = d.getFullYear();
   var vMon = d.getMonth() + 1;
   var vDay = d.getDate();
   var vHour = d.getHours();
   var vMin = d.getMinutes();
   var vSec = d.getSeconds();
   var _strNow=vYear+'-'+vMon+'-'+vDay+' ';
   _strNow=_strNow+(vHour<10 ? "0" + vHour : vHour)+':'+(vMin<10 ? "0" + vMin : vMin)+':'+(vSec<10 ?  "0"+ vSec : vSec);
   return _strNow; 
}

function toggleTab(ids)
{
   var idarr=ids.split("|");
   for(var i=0;i<idarr.length;i++)
   {
      if($(idarr[i])!=null)
         $(idarr[i]).className="hit";
   }
}

function popUp(elem)
{
    var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientWidth;
    if (window.innerWidth) {
        clientWidth = (window.__safari ? window.innerWidth : Math.min(window.innerWidth, document.documentElement.clientWidth));
    } else {
        clientWidth = document.documentElement.clientWidth;
    }
    var clientHeight;
    if (window.innerHeight) {
        clientHeight = (window.__safari ? window.innerHeight : Math.min(window.innerHeight, document.documentElement.clientHeight));
    } else {
        clientHeight = document.documentElement.clientHeight;
    }
    var dis=0;//get rid of the player
    if($("defplayer")!=null)
        dis=130;
    //if(elem.style.left=="")
        elem.style.left = scrollLeft+((clientWidth-elem.offsetWidth)/2)-dis+'px';//"200px";//modify 2008-11-07 lihuiming elem.style.left
    //if(elem.style.top=="")
        elem.style.top = scrollTop+((clientHeight-elem.offsetHeight)/2)+'px';//"200px";//
}

document.onkeydown=function()
{
   if(event.keyCode==13)
   {
      if(event.srcElement==$("tbEmail")||event.srcElement==$("tbPwd")||event.srcElement==$("tbCode"))
      {
         $("btnOK").click();
         return false;
      }
      else if(event.srcElement==$("tbDict"))
      {
         $("btnDict").click();
         return false;
      }
      else if(event.srcElement==$("tbSearch"))
      {
         $("btnSearch").click();
         return false;
      }
      else if(event.srcElement==$("tbSiteSearch"))
      {
         $("btnSiteSearch").click();
         return false;
      }
      else if(event.srcElement==$("tbS"))
      {
         $("btnS").click();
         return false;
      }
      else if(event.srcElement==$("dictbartb"))
      {
         $("dictbarbtn").click();
         return false;
      }
   }
}

function getCookieVal (offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name)
{
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i=0;i<arrCookie.length;i++)
    {
    	var index=arrCookie[i].indexOf("=");
    	var l=arrCookie[i].length;
    	var n=arrCookie[i].substring(0,index);
    	var v="";
    	if(l>index+1)
    	  v=arrCookie[i].substring(index+1,l);
	    if (n==name) 
	    {
		    return unescape(v);
	    }
    }
    return "";
}

function SetCookie (name, value)
{
    var today = new Date();
    var expires = new Date();
    expires.setTime(today.getTime() + 1000*60*60*365);
    document.cookie = name + "=" + value +"; domain=.veduchina.com; path=/; expires=" + expires.toGMTString();
}

function User(id,name,pic)
{
   this.ID=id;
   this.Name=name;
   this.Pic=pic;
}
function getCurrentUser()
{
   var cookie=GetCookie("UserProfile");
   if(cookie=="")
      return null;
   else
   {
      var profile=cookie.split("&");
      var id=parseInt(profile[0].split("=")[1]);
      var name=unescape(profile[1].split("=")[1]);
      var pic=profile[2].split("=")[1];
      return new User(id,name,pic);
   }
}
function login()
{
    alert("请先登录");
    location.href="http://www.veduchina.com/login.aspx?returnurl="+location.href;
}

function writeUserProfile()
{
   var user=getCurrentUser();
   if(user==null)
   {
       document.write("<a href='http://www.veduchina.com/login.aspx?returnurl="+location.href+"'>登录</a>&nbsp; | &nbsp;<a href='http://www.veduchina.com/reg.aspx'>注册</a>");
   }
   else
   {
      document.write("<a href='http://www.veduchina.com/user/default.aspx'>"+user.Name+"的设置</a>&nbsp; | &nbsp;<a href='http://www.veduchina.com/user/default.aspx?url=http://www.veduchina.com/user/subject/list.aspx'>课程</a>&nbsp; | &nbsp;<a id='ausermsg' href='http://www.veduchina.com/user/default.aspx?url=%2fuser%2fmessage%2flist.aspx%3fInboxOrOut%3d1%26type%3d2'>邮件<span id='msgcount' style='color:red;'></span></a>&nbsp; | &nbsp;<a href='http://www.veduchina.com/logout.aspx'>退出</a>");
   }
}



function convertToHtml(str)
{
   var pattern=new RegExp("(\r\n|\n)( |　){0,}","ig");
   return "　　"+str.replace(pattern,"<br/>　　");
}

function convertToText(str)
{
   var pattern=new RegExp("(<br/>)|(<br>)","ig");
   return str.replace(pattern,"\r\n");
}

function checkInput(reg)
{
	var srcElem = event.srcElement
	var oSel = document.selection.createRange()
	var srcRange = srcElem.createTextRange()
	oSel.setEndPoint("StartToStart", srcRange)
	var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
	event.returnValue = reg.test(num);
}

function launchChat(targetuserid)
{
    var user=getCurrentUser();
    if(user==null)
    {
        alertError("请先登录");
        return;
    }
    up_launchWM( user.ID, targetuserid );
}

function siteSearch(engine)
{
    var type=$("selSiteSearchType").selectedIndex;
    var q=$("tbSiteSearch").value;
    var cx=["011739841680837636807%3abyjoqztqieu","011739841680837636807%3aoirixqlf4bq","011739841680837636807%3ay60gvdxiore","011739841680837636807%3azqkh90pepo8","011739841680837636807%3ad0zy3b4ckzw"];
    location.href="http://s.veduchina.com/default.aspx?cx="+cx[type]+"&ie=UTF-8&sa=%E6%90%9C%E7%B4%A2&cof=FORID%3A9&q="+EncodeUtf8(q);
}

//--------BEGIN---把中文字符转换成Utf8编码------------------------//
function EncodeUtf8(s1)
{
  var s = escape(s1);
  var sa = s.split("%");
  var retV ="";
  if(sa[0] != "")
  {
     retV = sa[0];
  }
  for(var i = 1; i < sa.length; i ++)
  {
       if(sa[i].substring(0,1) == "u")
       {
           retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5)));
           
       }
       else retV += "%" + sa[i];
  }
  
  return retV;
}
function Str2Hex(s)
{
  var c = "";
  var n;
  var ss = "0123456789ABCDEF";
  var digS = "";
  for(var i = 0; i < s.length; i ++)
  {
     c = s.charAt(i);
     n = ss.indexOf(c);
     digS += Dec2Dig(eval(n));
       
  }
  //return value;
  return digS;
}
function Dec2Dig(n1)
{
  var s = "";
  var n2 = 0;
  for(var i = 0; i < 4; i++)
  {
     n2 = Math.pow(2,3 - i);
     if(n1 >= n2)
     {
        s += '1';
        n1 = n1 - n2;
      }
     else
      s += '0';
      
  }
  return s;
  
}
function Dig2Dec(s)
{
  var retV = 0;
  if(s.length == 4)
  {
      for(var i = 0; i < 4; i ++)
      {
          retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
      }
      return retV;
  }
  return -1;
} 
function Hex2Utf8(s)
{
 var retS = "";
 var tempS = "";
 var ss = "";
 if(s.length == 16)
 {
     tempS = "1110" + s.substring(0, 4);
     tempS += "10" +  s.substring(4, 10); 
     tempS += "10" + s.substring(10,16); 
     var sss = "0123456789ABCDEF";
     for(var i = 0; i < 3; i ++)
     {
        retS += "%";
        ss = tempS.substring(i * 8, (eval(i)+1)*8);
        
        
        
        retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
        retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
     }
     return retS;
 }
 return "";
}
//--------END---把中文字符转换成Utf8编码------------------------//


function dictbarSearch(dict)
{
    var word=document.getElementById("dictbartb").value;
    if(word=="")
    {
        window.open("http://dict.veduchina.com/"+dict);return;
    }
    window.open("http://dict.veduchina.com/"+dict+"/w/"+word);
}

function showAttachment(filepath,fileext,server)
{
    var vsid=GetCookie("virtualwall");
    if(vsid.length>0)
    {
        var arr1=vsid.split("=");
        vsid=arr1[1];
    }
    
    var height=20;
    var width=400;
    if(server==null)
    {
        server=GetCookie("FileServer");
        if(server=="")
            server=1;
    }
    else
    {
        SetCookie("FileServer",server);
    }
    
    var style1="";
    var style2="";
    if(parseInt(server)==1)
        style1="font-weight:bold;";
    else
        style2="font-weight:bold;";
        
    var isFs3=false;
    if(filepath.indexOf("fs3")>0)
        isFs3=true;
    if(isFs3)
        server="";
    else
        server="http://fs"+server+".veduchina.com/vsid"+vsid+"/";
    switch(fileext)
    {
        case ".flv":
            height=410;
            width=520;
            break;
        case ".mp3":
            height=20;
            width=400;
            break;
        default:
            return;
            break;
    }
    
    var filefullurl=new String();
    filefullurl=server+filepath;
    //filefullurl=filefullurl.replace(".veduchina.com/",".veduchina.com/vsid"+vsid+"/");
    
    var html='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+width+'" height="'+height+'">'
                        +'<param name="movie" value="http://www.veduchina.com/flash/mediaplayer.swf" />'
	                    +'<param name="quality" value="high" />'
                        +'<param name="FlashVars" value="skin=http://www.veduchina.com/flash/skins/skin5.swf&autostart=true&width='+width+'&height='+height+'&file='+filefullurl+'" />'
                        +'<param name="allowScriptAccess" value="always" />'
                        +'<param name="allowfullscreen" value="true" />'
                        +'<embed src="http://www.veduchina.com/flash/mediaplayer.swf" quality="high" flashvars="skin=http://www.veduchina.com/flash/skins/skin5.swf&autostart=true&width='+width+'&height='+height+'&file='+filefullurl+'" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" allowscriptaccess="always"  allowfullscreen="true"></embed>'
                    +'</object>';
    
    if(!isFs3)
        html+="<br/>(播放速度慢？切换服务器吧)<a href='javascript:;' style='"+style2+"' onclick='showAttachment(\""+filepath+"\",\""+fileext+"\",2);'>北方网通</a> | <a href='javascript:;' style='"+style1+"' onclick='showAttachment(\""+filepath+"\",\""+fileext+"\",1);'>南方电信</a><br/><br/>"
                    
   $("divAttachment").innerHTML=html;
}
