﻿var vscms_pages =null;
function showDialog(dim,titul,move)
{
    try
    {
        var titul=titul ||'Dialog';
        var overlay=Builder.node('DIV',{className:'dialogOverlay'});
        var iframe=Builder.node('IFRAME');
        iframe.style.height=0;
        iframe.style.width=0;
        iframe.style.visibilty='hidden';
        var div=Builder.node('DIV');
        var dialog=Builder.node('DIV');
        var table=Builder.node('TABLE',{className:'dialogBackground'});
        var tbody=Builder.node('TBODY');
        var header=Builder.node('TR');
        var title=Builder.node('TD',{className:'dialogTitle'});
        title.innerHTML=titul;
        var closebut=Builder.node('TD',{className:'dialogCloseButton',innerHTML:'&nbsp'});
        closebut.onclick=function(){overlay.remove();dialog.remove()};
        var titletable=Builder.node('TABLE',{style:'width:100%'});
        var titlerow=Builder.node('TR');
        var titlebody=Builder.node('TBODY');
        titlerow.appendChild(title);
        titlerow.appendChild(closebut);
        titlebody.appendChild(titlerow);
        titletable.appendChild(titlebody);
        var headercol=Builder.node('TD');
        headercol.appendChild(titletable);
        header.appendChild(headercol);
        var bodyrow=Builder.node('TR');
        var body=Builder.node('TD');
        Element.extend(table);
        Element.extend(div);
        Element.extend(dialog);
        Element.extend(overlay);
        Element.extend(iframe);
        body.appendChild(div);
        bodyrow.appendChild(body);
        tbody.appendChild(header);
        tbody.appendChild(bodyrow);
        table.appendChild(tbody); 
        dialog.appendChild(table);       
        dialog.style.zIndex=10001;
        document.body.appendChild(overlay);
        document.body.appendChild(dialog);
        dialog.absolutize();
        overlay.setOpacity(0.5);
        div.style.zIndex=10002;
        div.setOpacity(1);
        overlay.absolutize();
        overlay.appendChild(iframe);
        overlay.style.zIndex=10000;
        overlay.style.backgroundColor='#000000';
        Element.extend(document.body);
        var offset=document.viewport.getScrollOffsets();
        overlay.style.left=offset.left+'px';
        overlay.style.top=offset.top+'px';
        overlay.style.height=document.viewport.getHeight()+'px';
        overlay.style.width=document.viewport.getWidth()+'px';
        Event.observe(window, 'scroll', 
            function()
            {
                
                var offset=document.viewport.getScrollOffsets();
                    overlay.style.left=offset.left+'px';
                    dialog.style.left=offset.left+280+'px';
                overlay.style.top=offset.top+'px';
                dialog.style.top=(offset.top+100)+'px';

                return true;
            }
        );
        if(dim)
        {
            dialog.style.top=dim.top+'px';
            dialog.style.left=dim.left+'px';
            dialog.style.height=dim.height+'px';
            dialog.style.width=dim.width+'px';
        }
        
        else
        {
            dialog.style.top=(offset.top+100)+'px';
            dialog.style.left=(offset.left+280)+'px';
            //dialog.style.height=500+'px';
            //dialog.style.width=500+'px';
        }
        return div;
    }
    catch(e)
    {
        alert(e);
    }
}

function loadPage(page,container,cache,status)
{
    if(page.startsWith('http'))
    {
        type='http';
        
    }
    else if(page.endsWith('.xml'))
    {
        type='XML';
    }
    else if(page.endsWith('.htm'))
    {
        type='html';
    }
    var url="engine.aspx?"; 
    try
    {
                type="&datatype="+(type||'html');
        container=container || $('_VSCMScontent');
        status=status || $('_VSCMSstatus');
        var timeoutid=window.setTimeout(function(){if(status)status.show()},2000);
        new Ajax.Request(url+"page="+page+type,
          {
            method:'get',
            onSuccess: function(transport){
                
              var response = transport.responseText || "no response text";
              window.clearTimeout(timeoutid);
              if(status)status.hide();
              container.update(response);
              new Effect.Appear(container);
              trackPage(url+"page="+page+type);
            },
            onFailure: function(){  }
          });
          return false;
    }
    catch(e)
    {
        alert(e.message);
    }
}
function trackPage(url) {
    try {
        // google-analytics.com
        if (typeof(window.pageTracker)=='undefined') window.pageTracker = _gat._getTracker("UA-11618675-2");
        window.pageTracker._trackPageview(url);
    }
    catch (err) { }        
}
function vstreeviewSelect(event,item,options)
{
//    try
//    {
//      
//       window._vs_selectednode;
//       window._vs_selectednodestyle;
//       window._vs_selectednodeonmouseout;
//        window._vs_selectednodeonmouseover;
        if(Event.isLeftClick(event))
        {
            
            for(i=0;i<$('_VSCMSsubmenu').childNodes.length;i++)
            {
               if(item.id.substr(item.id.indexOf('_'))!=$('_VSCMSsubmenu').childNodes[i].id.substr($('_VSCMSsubmenu').childNodes[i].id.indexOf('_')))
                {
                    $('_VSCMSsubmenu').childNodes[i].hide();
                }
            }
            if(options.url && options.url!='')
            {
                if(item)
                {
                    /* Menu selected state behavior */
                    if(window._vs_selectednode)
                    {
                        if(window._vs_selectednode.id!=item.id)
                        {
                            window._vs_selectednode.className=window._vs_selectednodestyle;
                            window._vs_selectednode.onmouseout=window._vs_selectednodeonmouseout;
                            window._vs_selectednode.onmouseover=window._vs_selectednodeonmouseover;
                        }
                    }
                    var index=item.className.indexOf(' ');
                    if(index>0)
                    {
                        window._vs_selectednodestyle=item.className.substring(0,item.className.indexOf(' '));
                    }
                    else
                    {
                        window._vs_selectednodestyle=item.className;
                    }   
                    item.className=window._vs_selectednodestyle+' '+options.selectedStyle;
                    window._vs_selectednodeonmouseout=item.onmouseout;
                    window._vs_selectednodeonmouseover=item.onmouseover;
                    item.onmouseover=function(){};
                    item.onmouseout=function(){};
                    window._vs_selectednode=item;
                            
                    /* End of Menu selected state behavior*/
                    child=Element.next(item);
                    if(child)
                    {
                        if($('submenu'+item.id))
                        {
                           $('submenu'+item.id).show();
                        }
                        else
                        {
                            var table=document.createElement('table');
                            table.id='submenu'+item.id;
                            var tbody=document.createElement('tbody');
                            var row=document.createElement('tr');
                            var len=child.childNodes.length;
                            for(i=0;i<len;i++)
                            {
                                var td=document.createElement('td');
                                for(j=0;j<child.firstChild.childNodes.length;j++)
                                {
                                    var anchor=child.firstChild.childNodes[j].firstChild;
                                    anchor.id='submenuitem'+i+j+item.id;
//                                    if(options.submenuStyle)anchor.className=options.submenuStyle;
//                                   if(options.submenuStyleOver)
//                                   {
//                                        anchor.onmouseover='this.className+=\' \'+\'' + options.submenuStyleOver + '\'';
//                                   }
//                                   if(options.submenuStyleOut)
//                                      {
//                                        anchor.onmouseout='this.className=\'' + options.submenuStyleOver+'\'';
//                                        
//                                   }
                             }
                                td.appendChild(Element.remove(child.firstChild));
                                row.appendChild(td);
                            }
                            tbody.appendChild(row);
                            table.appendChild(tbody);
                            Element.extend(table);
                            Element.setStyle(table,{width:'100%'});
                            $('_VSCMSsubmenu').appendChild(table);
                        }
                    }
                }    
                loadPage(options.url);
            }
            else
            {
                if(item)
                {
                    child=Element.next(item);
                    if(child)
                    {
                        //child.toggle();
                        Effect.toggle(child,'blind');

                    }
                }
            }
        }
    //}
//    catch(e)
//    {
//        alert(e.message);
//    }
}
function validateField(field,status,msg)
{
    try
    {
        if(field.value.length>0)
        {
            return true;
        }
        else
        {
            if(status)status.update(msg);
            field.focus();
            return false;
        }
    }
    catch(e)
    {
        alert(e.message);
    }
}

