﻿// JScript 文件

function cls(){ 
//捕获触发事件的对象，并设置为以下语句的默认对象 
with(event.srcElement) 
    //如果当前值为默认值，则清空 
if(value==defaultValue) value="" 
} 

function res(){ 
//捕获触发事件的对象，并设置为以下语句的默认对象 
with(event.srcElement) 
//如果当前值为空，则重置为默认值 
if(value=="") value=defaultValue 
} 

//弹出HTML编辑器
function eWebEditorPopUp(form, field, width, height) {
	window.open("/Tools/WebEditor/popup.htm?style=popup&form="+form+"&field="+field, "", "width="+width+",height="+height+",toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}

//在屏幕中间打开指定大小的窗口
function openwin(turl,wd,hd) {
   tt=(screen.height-hd)/2;
   ll=(screen.width-wd)/2;
   winn=window.open(turl,"","scrollbars=yes,resizable=yes,status=no,width="+wd+",height="+hd+",top="+tt+",left="+ll);
   winn.focus();
}

//插入Flash
function insertFlash(elm, url, w, h) 
{
if (!document.getElementById(elm)) return;
var str = '';
str += '<object width="'+ w +'" height="'+ h +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
str += '<param name="movie" value="'+ url +'">';
str += '<param name="wmode" value="opaque">';
str += '<param name="quality" value="autohigh">';
str += '<embed width="'+ w +'" height="'+ h +'" src="'+ url +'" quality="autohigh" wmode="transparent" type="application/x-shockwave-flash" plugspace="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
str += '</object>';
document.getElementById(elm).innerHTML = str;
}

//选择全部复选框
function CheckAll(oCheckBox,form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != oCheckBox.name)       e.checked = oCheckBox.checked; 
   }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//屏蔽回车键
function event_down()
{
if(event.keyCode==13)event.returnValue =false;
}

//在屏幕中间打开一个网页窗口
function OpenWindow(URL,winwidth,winheight){
   wintop=(screen.height-winheight)/2;
   winleft=(screen.width-winwidth)/2;
   winn=window.open(URL,"","scrollbars=yes,resizable=yes,status=no,width="+winwidth+",height="+winheight+",top="+wintop+",left="+winleft);
   winn.focus();
}

function myBrowser(){
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    document.write(userAgent);
    var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera ; //判断是否IE浏览器 
    var isFF = userAgent.indexOf("Firefox") > -1 ; //判断是否Firefox浏览器
    var isSafari = userAgent.indexOf("Safari") > -1 ; //判断是否Safari浏览器

    if(isIE){ 
       var IE5 = IE55 = IE6 = IE7 = IE8 = false;
       var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
       reIE.test(userAgent);
       var fIEVersion = parseFloat(RegExp["$1"]);

       IE55 = fIEVersion == 5.5 ;
       IE6 = fIEVersion == 6.0 ;
       IE7 = fIEVersion == 7.0 ;
       IE8 = fIEVersion == 8.0 ;
      
       if(IE55){ return "IE55"; }
       if(IE6){ return "IE6"; }
       if(IE7){ return "IE7"; }
       if(IE8){ return "IE8"; }
     }
    if(isFF){ return "FF"; }
    if(isOpera){ return "Opera"; }
}

//在屏幕中间打开指定大小的窗口
function showModalWin(url,wd,hd) {
    var tt=(screen.height-hd)/2;
    var ll=(screen.width-wd)/2;
    var rnd=Math.random();
    var paraRnd="rnd=" + rnd;
    if(url.indexOf('?')>-1)
      paraRnd = "&" + paraRnd
    else
      paraRnd = "?" + paraRnd
    if(navigator.userAgent.indexOf("MSIE")>0)
    {
        if(window.XMLHttpRequest)
        {
            hd -= 21+3+3;
            wd -= 6;
        }
       winn=window.showModalDialog(url + paraRnd,window,"scrollbars=yes;resizable=no;help=no;status=no;dialogHeight=" + hd +"px;dialogWidth=" + wd + "px");
    }
    else
       winn=window.open(url,"","scrollbars=yes,resizable=yes,status=no,width="+wd+",height="+hd+",top="+tt+",left="+ll);
    return winn;
}

//往新窗口中写入自适应窗口宽度的图片
function ShowImgInWin(imgurl)
{
   var strHtml = "<html><title>照片---中小学辅导网</title><body>";
   strHtml += "<table width=\"100%\" height=\"100%\"><tr><td style=\"text-align:center; vertical-align:middle;\"><img src=\"" + imgurl + "\" onload=\"if(this.width>document.body.clientWidth){this.width=document.body.clientWidth-10};\"></td></tr></table>";
   strHtml += "<style>body{margin:5px;text-align:center;}</style>";
   //strHtml += "<style>div img {width:expression(document.body.clientWidth>window.screen.availWidth?\"600\":\"auto\"); overflow:hidden;}</style>";
   strHtml += "</body></html>";
   var imgWin = window.open("","newWindow","scrollbars=yes,toolbar=no,status=no,resizeable=no");
   imgWin.document.write(strHtml);  //   写html文本   
}

function closeWindow()
{
    window.opener=null;window.open('','_self');window.close();
}