//弹出窗口

// time in seconds the popup is shown

timePopup=4;
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
adCount=0;
function initPopup(){
  if(!ns && !ie && !w3) return;
  if(ie)      adDiv=eval('document.all.layer1.style');
  else if(ns) adDiv=eval('document.layers["layer1"]');
  else if(w3) adDiv=eval('document.getElementById("layer1").style');
  if (ie||w3) adDiv.visibility="visible";
  else        adDiv.visibility ="show";
  showPopup();
}
function showPopup(){
if(adCount<timePopup*10){
  adCount+=1;
  if (ie){
     documentWidth  =document.body.offsetWidth/2+document.body.scrollLeft-20;
     documentHeight =document.body.offsetHeight/2+document.body.scrollTop-20;
     }  
  else if (ns){
     documentWidth=window.innerWidth/2+window.pageXOffset-20;
     documentHeight=window.innerHeight/2+window.pageYOffset-20;
    } 
  else if (w3){
     documentWidth=self.innerWidth/2+window.pageXOffset-20;
     documentHeight=self.innerHeight/2+window.pageYOffset-20;
   } 
//  adDiv.left=documentWidth-50;
  adDiv.left=50;
//  adDiv.top =documentHeight-50;
  adDiv.top =50;
  setTimeout("showPopup()",100);
}
  else 
   closePopup();
}
function closePopup(){
if (ie||w3)
adDiv.display="none";
else
adDiv.visibility ="hide";
}
//***********************************************************
// 定义浏览器检查变量
var navigator_ok=false;
//取得游览器的版本号第一个字母并转换为数字。
var version_No=parseInt(navigator.appVersion.substring(0,1));
//取得浏览器的名称。
var aname=navigator.appName;
//检查浏览器是否为IE 4.0 以上的版本。
function check_navigate() {
  if(aname.indexOf("Internet Explorer")!=-1) {
    if(version_No>=4)
       navigator_ok=navigator.javaEnabled();
  }
}

//定义移动增量的最小值。
var delta_min=2;
//定义移动增量的最大值。
var delta_max=5;
//定义产生X、Y增量随机调整大小幅度的变量。
var delta_direction=2;
//定义一个记录浮动图像的对象。
function floater_obj(origin_x,origin_y,my_width,my_height) {
  this.delta_x=0;
  this.delta_y=0;
  this.width=my_width;
  this.height=my_height;
  this.x=origin_x;
  this.y=origin_y;
}
//定义使图像产生浮动效果的执行函数。
function floater_move() {
  if(navigator_ok) {
    //取得文档在窗口内的X和Y方向的偏移量。
    pageX=window.document.body.scrollLeft;
    pageY=window.document.body.scrollTop;
    //取得当前窗口的宽度和高度的数值。
    pageW=window.document.body.offsetWidth;
    pageH=window.document.body.offsetHeight;
    //累计X、Y的增量值。
    floater.x +=floater.delta_x;
    floater.y +=floater.delta_y;
    //使X、Y的增量值随机的增加或减少。
    floater.delta_x+=delta_direction*(Math.random()-0.5);
    floater.delta_y+=delta_direction*(Math.random()-0.5);
    //限制X、Y的下正负增量值不超过最大限制。
    if(floater.delta_x>(delta_max+delta_min)) 
        floater.delta_x=(delta_max+delta_min)*2- floater.delta_x;
    if(floater.delta_x<(-delta_max-delta_min)) 
        floater.delta_x=(-delta_max-delta_min)*2- floater.delta_x;
    if(floater.delta_y>(delta_max+delta_min))  
        floater.delta_y=(delta_max+delta_min)*2-floater.delta_y;
    if(floater.delta_y<(-delta_max-delta_min)) 
        floater.delta_y=(-delta_max-delta_min)*2-floater.delta_y;
    //如果移动到窗口的左边界，则产生一个正的增量值，使其向右移动。    
    if(floater.x<=pageX) {
        floater.x=pageX;
        floater.delta_x=delta_min+delta_max*Math.random();
        }
    //如果移动到窗口的右边界，则产生一个负的增量值，使其向左移动。   
    if(floater.x>=pageX+pageW-floater.width) {
        floater.x=pageX+pageW-floater.width;
        floater.delta_x=-delta_min-delta_max*Math.random();
        }
     //如果移动到窗口的上边界，则产生一个正的增量值，使其向下移动。        
    if(floater.y<=pageY) {
        floater.y=pageY;
        floater.delta_y=delta_min+delta_max*Math.random();
        }
    //如果移动到窗口的下边界，则产生一个负的增量值，使其向上移动。    
    if(floater.y>=pageY+pageH-floater.height) {
        floater.y=pageY+pageH-floater.height;
        floater.delta_y=-delta_min-delta_max*Math.random();
        }
    //使用计算完成的X、Y座标值给定图像的移动位置。
    document.all.my_picture.style.pixelLeft=floater.x;
    document.all.my_picture.style.pixelTop=floater.y;
  }
}

//定义一个用于产生对象实例的全局变量。
var floater;
//初始化函数（在<body onload="init()">中调用）。
function initdiv() {
    //调用检查浏览器函数。
    check_navigate(); 
    //如果浏览器符合要求，则执行图像的移动功能。
    if(navigator_ok) {
        //----------------------------------------------------------------
        //生成一个记录移动位置的“对象实例”。
        //对象参数顺序为：对象在页面上出现的初始X座标、Y座标，对象的宽度、高度。
        //----X、Y座标定义方法如下：-------
        //左上角定义为：0，0
        //右上角定义为：800，0
        //左下角定义为：0，600
        //右下角定义为：800，600
        //---------------------------------------
        //如果被显示的图像为80X80的尺寸。
        //定义对象宽度为：80+20=100 （考虑窗口水平滚动条宽度）
        //定义对象高度为：80+20=100 （考虑窗口垂直滚动条宽度）
        //------------------------------------------------------------------
        floater=new floater_obj(800,0,100,100); 
        //定时执行图像移动函数（现为：100毫秒）。
        window.setInterval("floater_move()",100);
    }
}

/***********************************
*读取屏幕信息
*
*/
function ReadScreenMes(){
  var correctwidth=800;
  var correctheight=600;
  if(!(screen.width !=correctwidth)||(screen.height !=correctheight))
  {
     document.write ("<p>你现在的分辩率为:"+screen.width +"*"+screen.height);
     document.write ("<p>注意:打开此网页的最佳分辨率为:"+correctwidth+"*"+correctheight);
     document.write ("<p>请重新设置屏幕分辩率!");
   }
   else
   document.write ("OK!");
  }

function ShowTime(){
	var today =new Date();
	document.write (today);
	document.write ("<p>现在的时间是:"+today.getHours()+"点"+today.getMinutes()+"分");
	document.write ("<P>现在的日期是:"+today.getYear()+"年"+today.getMonth()+"月"+today.getDay()+"日");
}

/************************************************************
*在主页上弹出一个独立窗口
*参数：
*    theURL:要弹出窗口的内容网址
*   winName:要弹出窗口的名字
*    wwidth:要弹出窗口的宽度
*   wheight:要弹出窗口的高度
* positionX:窗口所在位置（x坐标）
* positionY:窗口所在位置(y坐标）
************************************************************/

function  OpenWindow(theURL,winName,wwidth,wheight,positionX,positionY)
{
param="screenX="+positionX+",screenY="+positionY+",directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,status=0,toolbar=0,width="+wwidth+",height="+wheight
//alert(param);
 window.open (theURL,winName,param);
}
function OpenNotify(url,winName,winWidth,winHeight){
	positionX=(screen.width-winWidth)/2;
	positionY=(screen.height-winHeight)/2;
	param='screenX='+positionX+',screenY='+positionY+',directories=0,fullscreen=0,width='+winWidth+',height='+winHeight+',location=0,menubar=0,scrollbars=1,status=0,toolbar=0';
	//alert(param);
	window.open(url,winName,param);
}

/**********************************************
*初始化所有脚本
***********************************************/

function init()
{
//initdiv();
//initPopup();
wwidth=605;
wheight=275;

screenWidth=screen.width;
positionX=screenWidth-wwidth;
positionY=0;
//OpenWindow("popup.htm","欢迎",wwidth,wheight,positionX,positionY);

}


