﻿
//    var m_sLocSelectAdr = '<%=ClientAPI.GetSafeJSString(Localization.GetString("SelectAdress.Text", LocalResourceFile))%>';
//    var m_sLocSelectSE = '<%=ClientAPI.GetSafeJSString(Localization.GetString("SelectSE.Text", LocalResourceFile))%>';
//    var m_sLocAskForGroup = '<%=ClientAPI.GetSafeJSString(Localization.GetString("AskForGroup.Text", LocalResourceFile))%>';
//    var m_sLocAskForNewOrg = '<%=ClientAPI.GetSafeJSString(Localization.GetString("AskForNewOrg.Text", LocalResourceFile))%>';
//    var m_sLocAskForTitle = '<%=ClientAPI.GetSafeJSString(Localization.GetString("AskForTitle.Text", LocalResourceFile))%>';
//    var m_sLocChooseEl = '<%=ClientAPI.GetSafeJSString(Localization.GetString("ChooseElement.Text", LocalResourceFile))%>';

var m_sUCPrefixID;
var m_sUCPrefixName;

var _tb=null;
var _grid=null;
var _tree=null;
var _tab=null;
var _combo=null;

    document.write("<div id=\"ttip\" class=\"Tooltip\" style=\"display:none;position:absolute;\"><\/div>");


xBump=yBump=10;
MSIE=document.all;
NS6=document.getElementById&&!document.all;

if(MSIE||NS6)
{
	ttipObj=document.all?document.all["ttip"]:document.getElementById?document.getElementById("ttip"):"";
}

function MSIEBodyReturn()
{
	return(document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;
}

function ShowTip(ttipText)
{
	ttipObj.innerHTML=ttipText;
	ttipObj.style.display="block";
	return false;
}

function MoveTip(e)
{
	xPos=(NS6)?e.pageX:event.x+MSIEBodyReturn().scrollLeft;
	yPos=(NS6)?e.pageY:event.y+MSIEBodyReturn().scrollTop;
	lEdge=(xBump<0)?xBump*(-1):-1000;
	rEdge=MSIE&&!window.opera?MSIEBodyReturn().clientWidth-event.clientX-xBump:window.innerWidth-e.clientX-xBump-20;
	bEdge=MSIE&&!window.opera?MSIEBodyReturn().clientHeight-event.clientY-yBump:window.innerHeight-e.clientY-yBump-20;
	if(rEdge<ttipObj.offsetWidth)
	{
		ttipObj.style.left=MSIE?MSIEBodyReturn().scrollLeft+event.clientX-ttipObj.offsetWidth+"px":window.pageXOffset+e.clientX-ttipObj.offsetWidth+"px";
	}
	else if(xPos<lEdge)
	{
		ttipObj.style.left=xBump+"px";
	}
	else
	{
		ttipObj.style.left=xPos+xBump+"px";
	}
	if(bEdge<ttipObj.offsetHeight)
	{
		ttipObj.style.top=MSIE?MSIEBodyReturn().scrollTop+event.clientY-ttipObj.offsetHeight-yBump+"px":window.pageYOffset+e.clientY-ttipObj.offsetHeight-yBump+"px";
	}
	else
	{
		ttipObj.style.top=yPos+yBump+"px";
	}
}

function HideTip(){
	if(MSIE||NS6)
	{
		ttipObj.style.display="none";
		ttipObj.innerText="";
	}
}

document.onmousemove=MoveTip;

    function initModul1()
    {
        alert('sd');
            var Check = confirm('dfgfd');
            if(Check == true) 
            {
        		return true;
            }
            else 
            {
                return false;
            }
    
    }

    function trim (str) 
    {
        if(str == null) { return ''}
        return str.replace(/ +/g, ' ').replace(/^\s+/g, '').replace(/\s+$/g, '');
    }

    function initModul()
    {
    	m_sUCPrefixID = dnn.getVar('UCPrefixID');
//    	try
//    	{
//    	    //alert(dnn.getVar('jsVisible'));
//            var tr1 = document.getElementById(dnn.getVar('jsModulPath') + '_wpFolder_trModFolder');
//            var tr2 = document.getElementById(dnn.getVar('jsModulPath') + '_wpFolder_trShowType');
//            if(dnn.getVar('jsVisible')>=2)
//            {
//                tr1.style.visibility='visible';
//                tr2.style.visibility='visible';
//            }
//            else
//            {
//                tr1.style.visibility='hidden';
//                tr2.style.visibility='hidden';
//            }
//        }
//    	catch(ex)
//       	{}
	    //m_sUCPrefixName = dnn.getVar('UCPrefixName');
	    //alert(m_sUCPrefixID);
    }


	/******* <TAB EVENTS> **********/				

    function tab_InitializeTabs(oWebTab)
    {
        this._tab = igtab_getTabById(oWebTab.ID);
        if(this._tab == null){alert("this._tab not found"); return;}
		this._tab.getProgressIndicator().setTemplate(ig.getElementById("progressIndicatorTemplate2").innerHTML);
    }
        
//  Prüfen ob ein Eintrag selektiert
    function tab_BeforeSelectedTabChange(oWebTab, oTab, oEvent) 
    {
		if(this._tab.getSelectedTab().getIndex()==0)
		{
    		var selRow=null;
	    	for(var rowId in this._grid.SelectedRows) 
		    {
    			selRow=igtbl_getRowById(rowId);
	    	}
		    if(selRow==null)
    		{
	    		alert(m_sLocSelectRecord);
		    	oEvent.cancel=true;
		    	return false;
    		}
//		else
//		{
//		    dnn.setVar('jsGridUpdate', '10');
//			return false;
		}
    }

//  Abbruch falls keine Einträge
    function tab_BeforeSelectedTabChange1(oWebTab, oTab, oEvent) 
    {
		if(this._tab.getSelectedTab().getIndex()==0)
		{
	    	if(this._grid.Rows.length==0)
		    {
			    alert(m_sLocNoEl);
			    oEvent.cancel=true;
			    return false;
    		}
	    	else
		    {
    		}
	    	return false;
        }
    	return false;
    }

    function tab_AfterSelectedTabChange(oWebTab, oTab, oEvent)
    {
   	    if(this._tab.getSelectedTab().getIndex()>=1)
   	    {
            __doPostBack('tab' + String(this._tab.getSelectedTab().getIndex()));
        }
        else
        {
    		oEvent.cancel=true;
    	}
		return false;
//	    if(this._tab.getSelectedTab().getIndex()==0)
//	    {
//            __doPostBack('tab0');
//			return false;
//        }
    }
    

		
	/******* <GRID EVENTS> **********/				

	//This function serves 2 purposes.  Grab a reference to the grid, and tell the grid not to track
	//any changes made on the client side.  Since we will be dynamically adding and removing rows
	//if the grid were to track all of those changes it would hurt performance.  We really don't need
	//the grid to track the data, since we aren't expecting any events to fire on the server.
    function uwgEl1_InitializeLayoutHandler(gridName) 
    {
		this._grid=igtbl_getGridById(gridName);
        if(this._grid == null){alert("this._grid not found"); return;}
        this._grid.getProgressIndicator().setTemplate(ig.getElementById("progressIndicatorTemplate").innerHTML);

		UpdateGridRecordChange();
//			_grid=igtbl_getGridById(gridID);
//			_grid.xmlHttpRequestEX=_grid.xmlHttpRequest;
//			_grid.xmlHttpRequest=function(type){
				/* added \x01 as separator in front of additional param, otherwise we'll interfere with the grid. */
//				this.QueryString=this.QueryString+"\x01&NodePath="+this._nodePath;
//				this.xmlHttpRequestEX(type);
//			}
    }


    function uwgEl1_AfterRowActivateHandler(gridName, rowId)
    {
//		this._grid=igtbl_getGridById(gridName);
//        if(this._grid == null){alert("this._grid22 not found"); return;}
//        var row = _grid.Rows.getRowById(rowId); 
        var row = igtbl_getRowById(rowId); 
        if(row!=null)
        {
            var cell = row.getCellFromKey('Id'); 
            if(cell == null)
            {
                dnn.setVar('jsId', 0);
            } 
            else
            {
                dnn.setVar('jsId', cell.getValue());
            }
            //alert(cell.getValue());
        }
    }

    //Simple Utility function to delete all grid rows.
    function ClearGridRows(_grid)
    {
	    if(_grid!=null)
	    {
		    var count=_grid.Rows.length;
		    for(var i=0;i<count;i++)
		    {
			    _grid.Rows.remove(0);
    		}
	    }
    }


    //Flag we can set after we modify the Grid prototype, so that we only do it once.
    var _updatedRecordChange=false;
    //Change the _recordChange prototype to point to our new function, which can then call
    //the original _recordChange, only if the type is not "ChangedCells".  This way, we don't
    //keep these changes in memory - we don't need them.
    function UpdateGridRecordChange()
    {
	    if(_updatedRecordChange)return;
	    _updatedRecordChange=true;
	    //Keep track of the old function, we're just changing its name.
	    igtbl_Grid.prototype._recordChangeEX=igtbl_Grid.prototype._recordChange;
	    //Now we can poing _recordChange to a new function
	    igtbl_Grid.prototype._recordChange=function(type, obj, value){
		    //We want to record all changes except for ChangedCells updates, there is no need to track them.
		    if(type!="ChangedCells" &&type!="AddedRows" && type!="DeletedRows"){
			    this._recordChangeEX(type,obj,value);
		    }
	    }
    }

    function uwgEl1_AfterCellUpdateHandler(gridName, cellId)
    {
        if(this._grid == null && gridName!=""){this._grid=igtbl_getGridById(gridName);}
        //var grid = igtbl_getGridById(dnn.getVar('jsModulPath') + '_tabUsers__ctl0_uwgEl1');
        if(this._grid == null){alert("uwgEl1 111 not found! " + gridName); return;}

        var kk = 0;    
        var oRows = this._grid.Rows;
        dnn.setVar('jsSelected', '');
        for(var i=0; i < oRows.length; i++) 
        {
            //oRow = oRows.getRow(i);
            var cell = oRows.getRow(i).getCell(0); 
            if(cell.getValue()=='true' || cell.getValue()==true || cell.getValue()==1) 
            {
                kk = kk + 1;
                dnn.setVar('jsSelected', dnn.getVar('jsSelected') + oRows.getRow(i).getCellFromKey('Id').getValue() + ';');
            }
        }
        document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_txtNoSelected').value = kk;
        var wd = document.getElementById('txtNoSelected');
        wd.value = kk;
    }
    
    function uwgEl1_AfterXmlHttpResponseProcessed(gridName)
    {
        this._grid=igtbl_getGridById(gridName);
        if(this._grid.Rows.length == 0) 
        {
            document.getElementById('cmdSelectAll').style.visibility='hidden';
            document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_cmdUnselectAll').style.visibility='hidden';
        }
        else
        {
            document.getElementById('cmdSelectAll').style.visibility='visible';
            document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_cmdUnselectAll').style.visibility='visible';
        }
    }

    
	/******* <TREE EVENTS> **********/				
	//Setup the tree.. Mainly, we just want to find the nodes that will need demand loading, and give them a temporary child.
	//This ensures that the nodes will have expansion indicators, only when they actually have children.
    function uwtr1_InitializeTree(treeId)
    {	 
		_tree=igtree_getTreeById(treeId);
	}
		
    function uwtr1_NodeClick(treeId, nodeId, button)
    {
        dnn.setVar('jsTreeId', ''); 
        dnn.setVar('jsTreeName', ''); 
        var node = igtree_getNodeById(nodeId);
        if(node == null) {alert(m_sLocSelectSE); return false;}
        dnn.setVar('jsTreeId', node.getTag()); 
        dnn.setVar('jsTreeName', node.getText());
        if(dnn.getVar('jsShowBtnSearch')=='0')
            {cmd_OnClientClick('1');}
    }

	//This function is responsible for filling the "details" pane with the file list.
	function getNodeSpecificContent(node)
	{
		var nodeId=getNodePath(node);
        //alert(nodeId);
		goToPage(1,nodeId);
	}
		
	function goToPage(page,nodePath)
	{
		//don't use the grid's goToPage function directly, since we need to add additional parameters.
        if(this._grid == null)
        {
            __doPostBack(nodePath, '');
        }
        else
        {
            if(this._grid.Rows.length==0) 
            {
            __doPostBack(nodePath, '');
            }
            else
            {
        	this._grid._pageToGo=page;
	    	this._grid._nodePath=nodePath;
		    this._grid.invokeXmlHttpRequest(this._grid.eReqType.Page,this._grid,page);
		    }
		}
	}	


    //Simple utility function to piece together an XPath expression based on the given node.
    function getNodePath(node)
    {
	    var nodePath="";
	    while (node!=null)
	    {
		    nodePath="/*[@name='"+node.getText()+"']"+nodePath;
		    node=node.getParent();
	    }
	    nodePath="/"+nodePath;
	    return escape(nodePath);
    }

    
	/******* <WebTextEdit EVENTS> **********/				

    function wte_Focus(oEdit, text, oEvent)
    {
    	oEdit.className = "highlight";
    }

    
	/******* <Toolbar EVENTS> **********/				


    function uwtb1_InitializeToolbar(oToolbar, oEvent)
    {
        this._tb = oToolbar;
        var it = this._tb.Items.fromKey("TBmessage");
        if(it!=null)
        {
           if(dnn.getVar('jsRights')!='1')
           {
              it.setEnabled(false);
           }
           else 
           {
              it.setEnabled(true);
           }
        }
    }


	/******* <COMBO EVENTS> **********/				

    function wcEl1_InitializeCombo(webComboId){
        this._combo = igcmbo_getComboById(webComboId);
        if(_combo == null){alert("wcMesslist1a not found"); return;}
    }
    
    function wcEl1_AfterSelectChange(webComboId)
    {
        if(this._combo == null) { this._combo = igcmbo_getComboById(webComboId); }
        if(this._combo == null) { return false; }
        if(this._combo.getSelectedIndex()!=-1)
        {
            //alert(_combo.getDataValue());
            dnn.setVar('jsId', this._combo.getDataValue());
    	    __doPostBack('tab1');
        } 
        return false;
        //if(_combo.getSelectedIndex()!=-1){
        //    _grid.setActiveRow(null);
        //    _grid.clearSelectionAll();
        //}
    }


	/******* <Furthur functions> **********/				

    var mod = null;
    function ModFolder(mod) {
        //dnn.setVar('jsAddFolderVisible', '0');
        if(this._tree == null){alert("this._tree not found"); return false;}
        var node = this._tree.getSelectedNode();
        if(node == null)
        {
            alert(m_sLocSelectFolder); 
            return false;
        }
        var nodeTag=node.getTag();
        if(mod=='add') 
        {
            if (nodeTag=='1' || nodeTag=='2' || nodeTag=='3')
            {
                alert(m_sLocAddFolderNotPoss); 
                return false;
            }
            else 
            {
        		return true;
            }
        }

        if(mod=='typ') 
        {
            if (nodeTag=='0' || nodeTag=='1' || nodeTag=='2' || nodeTag=='3')
            {
                alert(m_sLocModFolderNotPoss); 
                return false;
            }
            else 
            {
        		return true;
            }
        }

        if(mod=='show') 
        {
        	loopNodes(this._tree.getNodes(),"");
       		return false;
        }

        if(mod=='del')
        {
            if (nodeTag=='0' || nodeTag=='1' || nodeTag=='2' || nodeTag=='3')
            {
                alert(m_sLocDelFolderNotPoss); 
                return false;
            }
            if(node.hasChildren() == true) 
            {
                alert(m_sLocDelFolderDelSub);
                return false;
            } 
            var Check = confirm(m_sLocDelFolderDef);
            if(Check == true) 
            {
        		return true;
            }
            else 
            {
                return false;
            }
        }
            
        if(mod=='ren')
        {
            if (nodeTag=='0' || nodeTag=='1' || nodeTag=='2' || nodeTag=='3')
            {
                alert(m_sLocRenFolderNotPoss); 
                return false;
            }
            else 
            {
        		return true;
            }
        }
    }


    function loopNodes(nodes, nodeText) {
    	for(var i=0;i<nodes.length;i++) {
	    	nodes[i].setText(nodes[i].getTag() + " - " + nodes[i].getText());
		    if(nodes[i].hasChildren())
			    loopNodes(nodes[i].getChildNodes(),nodeText);                           
    	}
    }

    function SyncFolder()
    {
        var Check = confirm(m_sLocSyncFolder);
        if(Check == true) 
        {
    	    alert('Diese Funktion ist noch nicht implementiert');
		    __doPostBack('syncFolder', '');
		}
    }
    

    function fnGetObj(objName) {
        if(document.getElementById) return document.getElementById(objName);
        if(document.all) return document.all[objName];
    }


    function uwtSettings_DragStart(oTree, oNode, oDataTransfer, oEvent){
	    if(oNode.getLevel()!=2) {oEvent.cancel=true; return false;}
    	oDataTransfer.dataTransfer.setData("Text", oNode.getText());
	    oDataTransfer.dataTransfer.effectAllowed = "move";
    }

    function uwtSettings_Drop(oTree, oNode, oDataTransfer, oEvent){
	    if(oNode.getLevel()!=1) {oEvent.cancel=true; return false;}
    	else {
	    var sourceNode = oDataTransfer.sourceObject;
	    if(!oNode.isChildOf(sourceNode)) {
	        oNode.addChild(oDataTransfer.dataTransfer.getData("Text"));
	        oNode.setExpanded(true);
    	    if(sourceNode)
	            sourceNode.remove();}
	        return false; }
    }

    function rbContr() { 
        dnn.setVar('jsContr', "1");
	    __doPostBack('rbContribute');
    }

    function rbAll() { 
        dnn.setVar('jsContr', "0");
	    __doPostBack('rbContribute');
    }

    function rbIncl() { 
        dnn.setVar('jsInclExcl', "I");
	    __doPostBack('tab0');
    }

    function rbExcl() { 
        dnn.setVar('jsInclExcl', "E");
	    __doPostBack('tab0');
    }

    function rbBoth() { 
        dnn.setVar('jsTo', " ");
	    __doPostBack('tab0');
    }

    function rbToMe() { 
        dnn.setVar('jsTo', "T");
	    __doPostBack('tab0');
    }

    function rbFromMe() { 
        dnn.setVar('jsTo', "F");
	    __doPostBack('tab0');
    }

    function rbAll() { 
        dnn.setVar('jsRead', " ");
	    __doPostBack('tab0');
    }

    function rbRead() { 
        dnn.setVar('jsRead', "R");
	    __doPostBack('tab0');
    }

    function rbUnread() { 
        dnn.setVar('jsRead', "U");
	    __doPostBack('tab0');
    }

    function ddlFolder() { 
        var ddl = document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlFolder');
        if(ddl == null){alert(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlFolder not found'); return false;}
        for(i=0;i<ddl.length;++i) {
            if(ddl.options[i].selected==true) {
                //alert(ddl.options[i].value);
                dnn.setVar('jsFolderId', ddl.options[i].value);
            }
        }
    }

    function ddlConf() { 
        var ddl = document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlConf');
        if(ddl == null){alert(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlConf not found'); return false;}
        for(i=0;i<ddl.length;++i) {
            if(ddl.options[i].selected==true) {
                //alert(ddl.options[i].value);
                dnn.setVar('jsConf', ddl.options[i].value);
            }
        }
    }

    function ddlFromUId() { 
        var ddl = document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlFromUId');
        if(ddl == null){alert(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlFromUId not found'); return false;}
        for(i=0;i<ddl.length;++i) {
            if(ddl.options[i].selected==true) {
                //alert(ddl.options[i].value);
                dnn.setVar('jsFromUId', ddl.options[i].value);
            }
        }
    }

    function ddlToUId() { 
        var ddl = document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlToUId');
        if(ddl == null){alert(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlToUId not found'); return false;}
        for(i=0;i<ddl.length;++i) {
            if(ddl.options[i].selected==true) {
                //alert(ddl.options[i].value);
                dnn.setVar('jsToUId', ddl.options[i].value);
            }
        }
    }

    function ddlCategorie() { 
        var ddl = document.getElementById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlCategorie');
        if(ddl == null){alert(dnn.getVar('jsModulPath') + '_uwt1__ctl0_wpFilter_ddlCategorie not found'); return false;}
        for(i=0;i<ddl.length;++i) {
            if(ddl.options[i].selected==true) {
                //alert(ddl.options[i].value);
                dnn.setVar('jsCategorie', ddl.options[i].value);
            }
        }
    }


    function wdcFrom_ValueChanged(oDateChooser, newValue, oEvent){
        dnn.setVar('jsFrom', newValue.toLocaleString());
        //alert(newValue.toLocaleString());
    }

    function wdcUntil_ValueChanged(oDateChooser, newValue, oEvent){
        dnn.setVar('jsUntil', newValue.toLocaleString());
    }

    function txtSearchText_TextChanged(oEdit, newText, oEvent){
        dnn.setVar('jsSearchText', newText);
        //alert(newText);
    }

    function cmdSelectOne_onclick() 
    {
        if(this._grid == null)
        {
            this._grid = igtbl_getGridById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_uwgEl1');
            if(this._grid == null){alert("this._grid not found"); return false;}
        }

    	var selRow=null;
    	for(var rowId in _grid.SelectedRows) 
       	{
    		selRow=igtbl_getRowById(rowId);
    	}
   	    if(selRow==null)
       	{
       		alert(m_sLocChooseEl);
    	}
	
        else
       	{
            var cell = selRow.getCell(0); 
            cell.setValue(true);
        } 
        return false;
    }


    function cmdSelectAll_onclick() 
    {
        if(this._grid == null)
        {
//            this._grid = igtbl_getGridById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_uwgEl1');
            if(this._grid == null){alert("this._grid not found"); return;}
        }

        //var k = 0;    
        var oRows = this._grid.Rows;
        for(var ii=0; ii < oRows.length; ii++) {
            //oRow = oRows.getRow(ii);
            var cell = this._grid.Rows.getRow(ii).getCell(0); 
            cell.setValue(true);
            //k = k + 1;
        }
        return false;
    }


    function cmdUnselectAll_onclick() 
    {
        if(this._grid == null)
        {
//            this._grid = igtbl_getGridById(dnn.getVar('jsModulPath') + '_uwt1__ctl0_uwgEl1');
            if(this._grid == null){alert("this._grid not found"); return;}
        }

        var oRows = this._grid.Rows;
        for(var ij=0; ij < oRows.length; ij++) {
            //oRow = oRows.getRow(i);
            var cell = this._grid.Rows.getRow(ij).getCell(0); 
            cell.setValue(false);
        }
        return false;
    }


