﻿

var const_ItemSelectionCheckBox_Prefix = "spItemSelectionCheckBox_" ; 

function $(id)
{
    return document.getElementById(id);
}

function sjjw_ListItemSelect( imgObj , listId )
{
    var checkboxName = "spItemSelectionCheckBox_" + listId;
    var imageFile = sjjw_GetUrlFileName( imgObj.src ) ;
     if( imageFile == "unchecka.gif" ){
        imgObj.src = "/_layouts/images/checkall.gif";
        sjjw_SetCheckboxState( checkboxName , true ) ;
    }
    else
    {
        imgObj.src = "/_layouts/images/unchecka.gif";
        sjjw_SetCheckboxState( checkboxName , false ) ;
    }
    
}

function sjjw_SetCheckboxState( name , c )
{
    var checkboxList = document.getElementsByName(name);
 	for (var i = 0; i < checkboxList.length; i++)
	{
		var chkBox = checkboxList[i];
		chkBox.checked = c  ;			 
    }
}	  

function sjjw_GetUrlFileName( url )
{
    var arr = url.split('/');
    return arr[arr.length-1];
}   

function WebPart_ChangeDisplay(id){
   var obj = $("Div_"+id);
    var imgObj = $("Img_"+id);
    if( obj.style.display == 'none' ){
        obj.style.display = '';
        imgObj.src='/_layouts/images/minus.gif';
    }
    else {
        obj.style.display = 'none';
        imgObj.src='/_layouts/images/plus.gif';
    }
}


function sjjw_TableToExcel( id )
{
        var tab = document.getElementById(id);
        var colsNum = tab.cells.length/tab.rows.length; 
        var ExcelSheet;        
    
        var  ExcelApp = new ActiveXObject("Excel.Application");
        
        ExcelSheet = ExcelApp.Workbooks.Add()
        //ExcelSheet = new ActiveXObject("Excel.Sheet");
        // 使 Excel 通过 Application 对象可见。
        ExcelSheet.Application.Visible = true;
        // 将table中内容放置到表格的中。
        var cellsNum = 0;
        for(var i = 0; i < tab.rows.length; i++)
        {
                for(var j = 0; j < colsNum; j++)
                {
                        //ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = tab.cells(cellsNum++).innerText;
                        ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = tab.rows[i].cells[j].innerText;
                }
        }

        // 保存表格。
        //ExcelSheet.SaveAs("D:\\TEST.XLS");
        // 用 Application 对象用 Quit 方法关闭 Excel。
        //ExcelSheet.Application.Quit();
        window.opener = "" ;
        window.close() ;
}

function sjjw_PageToExcel() 
{ 
 
    var oRangeRef = document.body.createTextRange(); 
    //oRangeRef.moveToElementText( elTable ); 

    oRangeRef.execCommand( "Copy" ); 
     
    try{ 
        var appExcel = new ActiveXObject( "Excel.Application" ); 
        appExcel.Visible = true; 
        appExcel.Workbooks.Add().Worksheets.Item(1).Paste(); 
    //appExcel = null; 
    }catch(e){ 
        alert("使用此功能必须在浏览器中设置:Internet选项->安全->将本站加入“受信任的站点”。"); 
    } 


function sjjw_PageToWord()
{	
	    document.execCommand ("selectall");
		document.execCommand ("copy");	
	
	   try{
			var wApp = new ActiveXObject("Word.Application");
			wApp.visible = true ;
			wApp.Documents.add();
			wApp.Selection.PasteSpecial();
	    }
	   catch(e)
	   {
		alert ("请正确安装Word或设置IE的安全选项！");
		return false;
	   }
	   
}

	function sjjw_HtmlToWord(str)
	{
		var printWindow=window.open("","PrintWindow","width=10,height=10,left=10000,top=10000");
		
		printWindow.document.write (str);
		printWindow.document.execCommand ("selectall");
		printWindow.document.execCommand ("copy");	
		printWindow.close();
		Paste2Word();
	}
	
 function SJJW_EditInputValue( hiddenElementId )
{
var obj = document.getElementById(hiddenElementId);
var url = "/_layouts/zoombldr.aspx";

var args =new Object();
args.value= obj.value ;

var retVal=window.showModalDialog(url, args , 'dialogHeight:500px;dialogWidth:620px;resizable:yes;status:no;help:no;');
obj.value = retVal ;

}

function sjjw_Link(linkUrl)
{
    var url = linkUrl.split(",")[0];
    window.location = url;
}