﻿/******************************************************************
 制 作 人：杨彬
 用于环境：IE6.0
 技术支持：www.myweb.name
*******************************************************************/

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();
}

/// <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);
    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:480px; dialogWidth:600px;";        
    winFeatures +="status:no;scrollbars:no; resizable:yes;center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口
    var val = window.showModalDialog(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";
    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;
        //document.aspnetForm.ctl00_ContentPlaceHolderMain_HiddenFieldName.value=val;
        //document.aspnetForm.submit();
        //alert(control.value);
    }  
} 
/// <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; resizable:yes;center:true;";
    var obj = aspnetForm;  //将form1作为默认对象传递给新窗口               
    window.showModalDialog(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();    
} 

/// <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();    
} 
/// <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();    
} 
 
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 Scroll(rolllink,rolllink1,rolllink2)
{
   var rollspeed=40
   rolllink2.innerHTML=rolllink1.innerHTML //克隆rolllink1为rolllink2
   function Marquee(){
   if(rolllink2.offsetTop-rolllink.scrollTop<=0) //当滚动至rolllink1与rolllink2交界时
   rolllink.scrollTop-=rolllink1.offsetHeight  //rolllink跳到最顶端
   else{
   rolllink.scrollTop++
   }
   }
   var MyMar=setInterval(Marquee,rollspeed) //设置定时器
   rolllink.onmouseover=function() {clearInterval(MyMar)}//鼠标移上时清除定时器达到滚动停止的目的
   rolllink.onmouseout=function() {MyMar=setInterval(Marquee,rollspeed)}//鼠标移开时重设定时器
}

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);
    }
}


