﻿/******************************************************************
 制 作 人：杨彬
 用于环境：IE6.0
 技术支持：www.myweb.name
*******************************************************************/

//屏蔽页面错误的代码
function killErrors()
{
    return true;
}
//window.onerror = killErrors;
//if (top.location != self.location) top.location=self.location;

function GetRadioValue(obj)
{
    for(i=0;i<obj.length;i++)
    {
        if(obj[i].checked)
        {
            return obj[i].value;
        }
    }
    return null;
}

/// <summary>
/// 全选，根据obj选中状态，选中其它所有同名控件
/// </summary>
/// <param name="obj">
/// 触发全选按钮的复选框控件
/// </param>
function CheckedAll(obj)
{
    // 其中obj的value是其它控件的name
    var checks = document.getElementsByName(obj.value);
    for (i=0; i<checks.length; i++)
    {
        checks[i].checked = obj.checked; 
    }
}

/// <summary>
/// 调用日历
/// </summary>
/// <param name="objInput">打开窗口的的文件名称</param>
function ShowCalendar(objInput){
	var vReturnValue = showModalDialog("../Public/DateSelect.aspx","","dialogWidth:330px;dialogHeight:220px;status:no;center:true");
	if (vReturnValue!="" && vReturnValue!=null){
		objInput.value = vReturnValue;
	}
}

function SendValue(val) 
{
    window.returnValue = val;
    // window.close();//firefox不支持
    top.close();//IE和FireFox都支持
}

/// <summary>
/// 打开一个模式窗体
/// </summary>
/// <param name="srcFile">打开窗口的的文件名称</param>
/// <param name="control">回传控件的名称</param>
function GetDialogForm(srcFile, control)    
{      
    var winFeatures = "dialogHeight:400px; dialogWidth:300px;";        
    winFeatures +="status:no;scrollbars:no; resizable:yes;center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口
    // var val = window.showModalDialog(srcFile, obj, winFeatures);
    var val;
    if (window.showModalDialog!=null)//IE判断 
    {
       val = window.showModalDialog(srcFile, obj, winFeatures);
    }
    else 
    {
        winFeatures += "modal=yes";
         val = window.open(srcFile, obj, winFeatures);    
    }   

    if (control == '') 
        return false;
    if (val!=null && val!='undefined') 
    {
        control.value = val;
    }  
} 

/// <summary>
/// 上传附件专用，打开一个模式窗体
/// </summary>
/// <param name="srcFile">打开窗口的的文件名称</param>
/// <param name="control">回传控件的名称</param>
function GetAttach(srcFile, control)    
{      
    var winFeatures = "dialogHeight:600px; dialogWidth:800px;";        
    winFeatures +="status:no;scrollbars:no; resizable:yes;center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口
    var val;

    if (window.showModalDialog!=null)//IE判断 
    {
        val = window.showModalDialog(srcFile, obj, winFeatures);
    }
    else 
    {
        winFeatures += "modal=yes";
        val = window.open(srcFile,obj, winFeatures);    
    }   

    if (control == '') 
        return false;
    if (val!=null && val!='undefined') 
    {
        control.value = val;
    }  
} 
/// <summary>
/// 打开一个模式窗体
/// </summary>
/// <param name="srcFile">打开窗口的的文件名称</param>
/// <param name="winFeatures">窗体的特性</param>
function GetPersonForm(srcFile, control)    
{      
    var winFeatures = "dialogHeight:480px; dialogWidth:720px;";        
    winFeatures +="status:no;center:true;location=no;resizable:yes;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口
    var val = window.showModalDialog(srcFile, obj, winFeatures);
    
    if (val!=null && val!='') 
    {
        control.value=val;
        window.location.href='UserRegisterOperate.aspx?OID='+val;
    } 
    
    winFeatures +="status:no;scrollbars:no;  center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口 
    if (window.showModalDialog!=null)//IE判断 
    {
        window.showModalDialog(srcFile, obj, winFeatures);
    }
    else 
    {
        winFeatures += "modal=yes";
        window.open(srcFile,obj, winFeatures);    
    }   
} 
/// <summary>
/// 打开一个模式窗体
/// </summary>
/// <param name="srcFile">打开窗口的的文件名称</param>
/// <param name="winFeatures">窗体的特性</param>
function OpenDialogForm(srcFile, winFeatures)    
{      
    if (winFeatures == null || winFeatures == '')
    {
        winFeatures = "dialogHeight:400px; dialogWidth:600px;";        
    }
    winFeatures +="status:no;scrollbars:no; location=no; resizable:yes;center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口 
    if (window.showModalDialog!=null)//IE判断 
    {
        window.showModalDialog(srcFile, obj, winFeatures);
    }
    else 
    {
        winFeatures += "modal=yes";
        window.open(srcFile, obj, winFeatures);    
    }   
} 

/// <summary>
/// 从模式窗体中回送父窗体值
/// </summary>
/// <param name="obj">父窗体的控件名称</param>
/// <param name="val">值</param>
function SendDialogValue(obj, val)    
{        
    //取得父窗口传过来的对象        
    var myObj = window.dialogArguments;        
    //赋值 
    myObj[obj].value = val; 
    obj.value = val; 
    //关闭窗口        
    // window.close();//firefox不支持
    top.close();//IE和FireFox都支持
} 

/// <summary>
/// 从模式窗体中回送父窗体2个值
/// </summary>
/// <param name="obj1">父窗体的控件名称</param>
/// <param name="val1">值</param>
/// <param name="obj2">父窗体的控件名称</param>
/// <param name="val2">值</param>
function SendDialogValue2(obj1,val1,obj2,val2)    
{        
    //取得父窗口传过来的对象        
    var myObj = window.dialogArguments;        
    //赋值 
    myObj[obj1].value = val1; 
    myObj[obj2].value = val2; 
    //关闭窗口        
    // window.close();//firefox不支持
    top.close();//IE和FireFox都支持
} 
/// <summary>
/// 从模式窗体中回送父窗体2个值
/// </summary>
/// <param name="obj1">父窗体的控件名称</param>
/// <param name="val1">值</param>
/// <param name="obj2">父窗体的控件名称</param>
/// <param name="val2">值</param>
/// <param name="obj3">父窗体的控件名称</param>
/// <param name="val3">值</param>
function SendDialogValue3(obj1,val1,obj2,val2,obj3,val3)    
{        
    //取得父窗口传过来的对象        
    var myObj = window.dialogArguments;        
    //赋值 
    myObj[obj1].value = val1; 
    myObj[obj2].value = val2; 
    myObj[obj3].value = val3; 
    //关闭窗口        
    // window.close();//firefox不支持
    top.close();//IE和FireFox都支持
} 
 
var HKEY_Root,HKEY_Path,HKEY_Key; 
HKEY_Root="HKEY_CURRENT_USER"; 
HKEY_Path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; 
//设置网页打印的页眉页脚为空 
function PageSetup_Null() 
{ 
    try 
    { 
        var Wsh=new ActiveXObject("WScript.Shell"); 
        HKEY_Key="header"; 
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
        HKEY_Key="footer"; 
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,""); 
    } 
    catch(e)
    {
        alert("需要手工设置页眉和页脚：\n\n建议先点击'打印设置'，那里可以去掉页眉和页脚!");
    } 
} 
//设置网页打印的页眉页脚为默认值 
function  PageSetup_Default() 
{   
    try 
    { 
        var Wsh=new ActiveXObject("WScript.Shell"); 
        HKEY_Key="header"; 
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); 
        HKEY_Key="footer"; 
        Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d"); 
    } 
    catch(e)
    {
        alert(e);
    } 
} 
function CheckFormClose()
{
    //if (document.getElementById('ctl00_ContentPlaceHolderMain_ChineseName').value!='')
    //{
        //alert('您将关闭本页');
        window.event.returnValue='您将关闭本页么？';
    //}
    //return true;
}

function Resize(frame)
{
    parent.document.all("frame").style.height=document.body.scrollHeight;
}

function setMenu01(i){
    for(var ti=1;ti<5;ti++)
    {
     if (ti == i)
     {
      document.getElementById("menu1_"+ti).style.display='block';
      document.getElementById("menu0"+ti).className='news';
      
     }
     else
     {
      document.getElementById("menu1_"+ti).style.display='none';
      document.getElementById("menu0"+ti).className='news1';
      
     }
    } 
} 

function setMenu(i,max)
{
    for(var ti=1;ti<=max;ti++)
    {
        if (ti == i)
        {
            document.getElementById("menu1_"+ti).style.display='block';
            document.getElementById("menu0"+ti).className='zq';
            document.getElementById("menua"+ti).className='fq';
        }
        else
        {
            document.getElementById("menu1_"+ti).style.display='none';
            document.getElementById("menu0"+ti).className='zq1';
            document.getElementById("menua"+ti).className='fq1';
        }
    } 
}
function addFav()
{ 
    window.external.AddFavorite(document.location.href,document.title);
}

function addHome()
{
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage('http://www.myweb.name/');
}

function ScrollText(content,btnPrevious,btnNext,autoStart)
{
    this.Delay = 10;
    this.LineHeight = 20;
	this.Amount = 1;//注意:LineHeight一定要能整除Amount.
	this.Direction = "up";
    this.Timeout = 1500;
    this.ScrollContent = this.$(content);
    this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
    //this.ScrollContent.scrollTop = 0;
    if(btnNext)
    {
        this.NextButton = this.$(btnNext);
        this.NextButton.onclick = this.GetFunction(this,"Next");
        this.NextButton.onmouseover = this.GetFunction(this,"Stop");
        this.NextButton.onmouseout = this.GetFunction(this,"Start");
    }
    if(btnPrevious)
    {
        this.PreviousButton = this.$(btnPrevious);
        this.PreviousButton.onclick = this.GetFunction(this,"Previous");
        this.PreviousButton.onmouseover = this.GetFunction(this,"Stop");
        this.PreviousButton.onmouseout = this.GetFunction(this,"Start");
    }
    this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
    this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
    if(autoStart)
    {
        this.Start();
    }
}

ScrollText.prototype.$ = function(element)
{
    return document.getElementById(element);
}

ScrollText.prototype.Previous = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("up");
}

ScrollText.prototype.Next = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("down");
}

ScrollText.prototype.Start = function()
{
    clearTimeout(this.AutoScrollTimer);
    this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
}

ScrollText.prototype.Stop = function()
{
    clearTimeout(this.ScrollTimer);
    clearTimeout(this.AutoScrollTimer);
}

ScrollText.prototype.AutoScroll = function()
{
    if(this.Direction == "up")
    {
        if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
        this.ScrollContent.scrollTop += this.Amount;
    }
    else
    {
        if(parseInt(this.ScrollContent.scrollTop) <= 0)
        {
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Delay);
    }
    else
    {
        this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
    }
}

ScrollText.prototype.Scroll = function(direction)
{
    if(direction=="up")
    {
        if(this.ScrollContent.scrollTop == 0)
        {
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }
    else
    {
        this.ScrollContent.scrollTop += this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Delay);
    }
}

ScrollText.prototype.GetFunction = function(variable,method,param)
{
    return function()
    {
        variable[method](param);
    }
}
// 文本字数限制，一旦超过将给出截断，且给出提示；
// 下方有SpanMsg提示字数标签。
function textLimitCheck(thisArea, maxLength) 
{
    var length = thisArea.value.length; 
    if (length > maxLength) 
    { 
        alert('最多只能输入' + maxLength + '个字限制。 \r超出的将自动去除。'); 
        thisArea.value = thisArea.value.substring(0, maxLength);
        thisArea.focus(); 
    }
    else 
    {
        document.getElementById('SpanMsg').innerText='您还可以输入的剩余字数为：' + (maxLength-length);
    }
} 


//上下翻滚，可以控制速度
//调用方式：<script>startmarquee(27,60,2000)</script>
function startmarquee(lh,speed,delay) 
{
    var p=false;
    var t;
    var o=document.getElementById("marqueebox");
    o.innerHTML+=o.innerHTML;
    o.style.marginTop=0;
    o.onmouseover=function(){p=true;}
    o.onmouseout=function(){p=false;}
    function start()
    {
        t=setInterval(scrolling,speed);
        if(!p) o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
    }
    function scrolling()
    {
        if(parseInt(o.style.marginTop)%lh!=0)
        {
            o.style.marginTop=parseInt(o.style.marginTop)-1+"px";
            if(Math.abs(parseInt(o.style.marginTop))>=o.scrollHeight/2) o.style.marginTop=0;
        }
        else
        {
            clearInterval(t);
            setTimeout(start,delay);
        }
    }
    setTimeout(start,delay);
}


