﻿// JScript 文件

var currentDialog = null;

function $(id) {
	if(typeof(id)=="object")return id;
    return document.getElementById(id);
}

  //显示具体广播信息
  function showShowBroadCast(id)
  {
      $("showbroadcast_wait").style.display="";
      $("showbroadcast_content").style.display="none";
  
      displayDivModelDialog("ia","showbroadcast");   
      
      getBroadCast(id);
  }
  
  function getBroadCast(id)
  {
      makeRequest('/live/gb.aspx?act=showgb&id='+id+'&rand=' + Math.random(),"getBroadCastCallBack","GET","");
  }
  
  function getBroadCastCallBack()
  {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
		   var al = http_request.responseText.split("|");
		   $('showbroadcast_content_broadcast').innerHTML = al[0];
		   $('showbroadcast_content_username').innerHTML = al[1];
		   $('showbroadcast_content').style.display = "";
		   $("showbroadcast_wait").style.display    ="none";
		}
	}

  }
  
  //显示摸态
  function displayDivModelDialog(backgroupDiv,dialogDiv)
  {
       if(navigator.appName=="Microsoft Internet Explorer"){
           var pageOption=document.getElementsByTagName("select");
			for(var i=0;i<pageOption.length;i++){
				pageOption[i].style.visibility = "hidden";
			}
		}
      
      var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body; 
      
      $(backgroupDiv).style.display = 'block';
      $(dialogDiv).style.display = 'block';
      //document.getElementsByTagName('html')[0].style.overflow="hidden"
  
      var bodyClientWidth  = $(bdy).clientWidth;
      var bodyClientHeight = $(bdy).clientHeight;
      $(backgroupDiv).style.height = ((bdy.scrollHeight>bodyClientHeight)?bdy.scrollHeight:bodyClientHeight)+"px";
      $(backgroupDiv).style.width  = ((bdy.scrollWidth>bodyClientWidth)?bdy.scrollWidth:bodyClientWidth)+"px";
      var bodyScrollTop     =  bdy.scrollTop
      var dialogTop    =  (bodyClientHeight - $(dialogDiv).offsetHeight)/2;  
      var dialogLeft   =  (bodyClientWidth - $(dialogDiv).offsetWidth)/2;
      //var dialogScrollTopAndTop = bodyScrollTop + dialogTop
      //(新)加入滚动相对定部的做标
      $(dialogDiv).dialogTop = dialogTop
      dialogTop = bodyScrollTop + dialogTop
      if( dialogLeft < bdy.scrollLeft)
      {
          dialogLeft = bdy.scrollLeft
      }
      if( dialogTop < bdy.scrollTop )
      {
          dialogTop = bdy.scrollTop
      }
      var computedialogLeft = bdy.clientWidth - $(dialogDiv).offsetWidth  +  bdy.scrollLeft
      var computedialogTop  = bdy.clientHeight - $(dialogDiv).offsetHeight +  bdy.scrollTop 
      if(dialogLeft>computedialogLeft)dialogLeft = computedialogLeft;
      if(dialogTop>computedialogTop)dialogTop = computedialogTop;
      $(dialogDiv).style.left = dialogLeft + "px";
      $(dialogDiv).style.top  = dialogTop  + "px";
  
      //设置当前对话框
      currentDialog = $(dialogDiv);
  }
 
  //关闭模态  function closeDivModelDialog(backgroupDiv,dialogDiv)
  {
         currentDialog = null;
        
         if(navigator.appName=="Microsoft Internet Explorer")
          {
            var pageOption=document.getElementsByTagName("select");
			for(var i=0;i<pageOption.length;i++){
				pageOption[i].style.visibility = "visible";
			}
		}
        
        $(backgroupDiv).style.display = 'none';
        $(dialogDiv).style.display = 'none'; 
       
        //document.getElementsByTagName('html')[0].style.overflow="auto"
  }
  
  
 //错误提示
 function writeInfo(id, info,color)
 {
    if($(id) == null)
      return;
   
    if($(id).nextSibling != null && $(id).nextSibling.infoType == 'info')
    {
       $(id).nextSibling.innerHTML = info
    }
    else
    { 
       errorElement = document.createElement('span');
       
       errorElement.style.backgroundColor =  'orange'   //color;
       
       errorElement.innerHTML = info;
    
       errorElement.infoType = 'info' 
       
       if($(id).nextSibling != null)
       {
         if($(id).parentNode == null)return; 
          $(id).parentNode.insertBefore(errorElement,$(id).nextSibling)
       }
       else
       {
          if($(id).parentNode == null)return;
          $(id).parentNode.appendChild(errorElement);
       }
    }
 }

function clearInfo(id)
{
  if( !($(id).nextSibling == null || $(id).nextSibling.infoType == 'undefined')  )
  {
     if($(id).nextSibling.infoType == 'info')
     {
         if($(id).parentNode == null)return;
         $(id).parentNode.removeChild($(id).nextSibling)
     }
  }
}

//设置滚动
window.onscroll = function(){

   if(currentDialog == null)return;

   var bdy = (document.documentElement && document.documentElement.clientWidth)?document.documentElement:document.body; 
    
   currentDialog.style.top  = ( bdy.scrollTop +  currentDialog.dialogTop)+'px'; 

}

