﻿addLoadListener(stretch);
addLoadListener(foldall);
addLoadListener(setlinks);

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}


    
      function stretch() 
      {
        var left= document.getElementById("ctl00_float_left").offsetHeight;
        if (left!=null)
        {
            var right= document.getElementById("ctl00_float_right").offsetHeight;

            if (right!=null)
            {
                var tallest;
                if (left > right)
                     tallest= left
                else tallest= right;
                document.getElementById("ctl00_float_left").style.height = tallest+"px";
                document.getElementById("ctl00_float_right").style.height = tallest+"px";
            }
        }
      }
      
      function foldall()
      {
        var tds= document.getElementsByTagName("td");
        for (var i=0;i<tds.length; i++)
        {
            var s= tds[i].className;
            if (s=="unfold")
               tds[i].className= "fold";
            else if (s=="presenterexp")
               tds[i].className= "presenterreg";
            else if (s=="sponsorexp")
               tds[i].className= "sponsorreg";
            else if (s=="titleexp")
               tds[i].className= "titlereg";
            else if (s=="venueexp")
               tds[i].className= "venuereg";
        }
      }
    
     
    function setlinks()
    {
        var links= document.getElementsByTagName("a");
        
        for (var i=0; i<links.length; i++)
        {
            var jsattr= links[i].getAttribute("jslink");
            if ((jsattr!=null) && (jsattr!=""))
            {
            links[i].href = "javascript:UpdateContent('" + jsattr + "','')";
            links[i].setAttribute("jslink","");
            links[i].target= "";
            }        
        }
    }

    

    function JavaScriptOn()
    {
     //   $get('JSTest').value = "true";
    
    }
 
    function ReceiveServerData(rValue)
    {    

        var commandstr= rValue.toString();
        var commands= commandstr.split('^');
        for (var i in commands)
        {
        if (commands[i].length>1)
            {

            var argstr= commands[i];
            var args= argstr.split('|');
         
            switch (args[0])
                {
                case "ShowEvent": ShowExpanded(args[1], args[2], args[3], "titleexp"); break;
                case "ShowPresenter": ShowExpanded(args[1], args[2], args[3], "presenterexp"); break;
                case "ShowSponsor": ShowExpanded(args[1], args[2], args[3], "sponsorexp"); break;
                case "ShowVenue": ShowExpanded(args[1], args[2], args[3], "venueexp"); break;
                default: break;
                }
            }
        }
 
    }
    
    function ShowExpanded(sender, receiver, text, sendstyle)
    {
        foldall();
        var r= document.getElementById(receiver);
        r.innerHTML = text;
        r.className= "unfold";
        
        var s= document.getElementById(sender);
        s.className= sendstyle;
        restretch();
        MoveToTop(sender);
    }
    
      function restretch() 
      {
        var left= document.getElementById("sidebar_left").offsetHeight+50;
        if (left!=null)
        {
            var right= document.getElementById("ctl00_GeneratedContent").offsetHeight + document.getElementById("ctl00_PageIntroPanel").offsetHeight +40;
            if (right!=null)
            {
                var tallest;
                if (left > right)
                     tallest= left
                else tallest= right;
                document.getElementById("ctl00_float_left").style.height = tallest+"px";
                document.getElementById("ctl00_float_right").style.height = tallest+"px";
            }
        }
   }
   
       function MoveToTop(objName)
    {
        var posx= 0;
        var posy= 0;
       element= document.getElementById(objName);
       
       while(element !=null)
       {
            posx+= element.offsetLeft;
            posy+= element.offsetTop;
            element= element.offsetParent;
       }
       
       if (typeof window.pageYOffset != 'undefined')
        {
            window.pageXOffset= posx;
            window.pageYOffset= posy;
        }

        else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0)
        {
            document.documentElement.scrollLeft= posx;
            document.documentElement.scrollTop= posy;
        }

        else if (typeof document.body.scrollTop != 'undefined')
        {
            document.body.scrollLeft=posx;
            document.body.scrollTop=posy;
        }

    }
    
    function Initialize()
    {
        dw = document.getElementById("ctl00_DetailWrapper");
        if (dw != null)
            dw.className= "hidden";
            
        ciw = document.getElementById("ctl00_CategoryItemsWrapper");
        if (ciw != null)
            ciw.className= "hidden";       
            
        clw = document.getElementById("ctl00_CategoryListWrapper");
        if (clw != null)
            clw.className= "hidden";               
    }
    
    function Preload(argstr)
    {
        var args= argstr.split('##');
        if (args[0]=="Images")
            PreloadImages(args[1]);
    }
    
    function PreloadImages(argstr)
    {
    
        var args= argstr.split('#');
        var imgs= [];
        for (var i in args)
        {
            imgs[i]= new Image();
            imgs[i].src= args[i];
        }

    }
    
    function ShowCategoryList(text)
    {
        document.getElementById("ctl00_CategoryList").innerHTML = text;
        document.getElementById("ctl00_GroupMenuPanel").innerHTML = "";
        document.getElementById("ctl00_CategoryListWrapper").className= "sub_center";
        MoveToTop("ctl00_CategoryListWrapper");
    }
    
    function ShowCategoryListTitle(text)
    {
        document.getElementById("CategoryListTitle").innerHTML = text;
    }
    
    function ShowCategoryItems(text)
    {
        document.getElementById("ctl00_CategoryItems").innerHTML = text;
        document.getElementById("ctl00_ItemMenuPanel").innerHTML = "";
        document.getElementById("ctl00_CategoryItemsWrapper").className= "sub_center";
        ClearItem();
        MoveToTop("ctl00_CategoryItemsWrapper");
    }
    
    function SetCategoryItemsTitle(text)
    {
        document.getElementById("CategoryItemsTitle").innerHTML = text;
    }
    
    function ShowItem(text)
    {
        document.getElementById("ctl00_ItemDetail").innerHTML = text;
        document.getElementById("ctl00_ContentPanel").innerHTML = "";
        document.getElementById("ctl00_DetailWrapper").className= "sub_center";
        MoveToTop("DetailWrapper");
    }
    
    function ShowItemTitle(text)
    {
        document.getElementById("ItemDetailTitle").innerHTML = text;
    }
    
    function ClearItem()
    {
        document.getElementById("ItemDetailTitle").innerHTML = "";
        document.getElementById("ctl00_ItemDetail").innerHTML = "";  
        document.getElementById("ctl00_ContentPanel").innerHTML = "";  
        document.getElementById("ctl00_DetailWrapper").className= "hidden";    
    }
    
    
    function SetPreviewImage(path, width, height, caption, group, item, page, selection)
    {

        var preview= document.getElementById("GalleryPreviewImage");
        if (preview==null)
            preview= document.getElementById("ctl00_GalleryPreviewImage");        
            
        var divParent= preview.parentNode;

        var imgNew = document.createElement('img');
        imgNew.src = path;
        imgNew.width= Number(width);
        imgNew.height= Number(height);
        
        imgNew.id = 'GalleryPreviewImage';
//alert("path= " + imgNew.src + "\nwidth= " + imgNew.width + " height= " + imgNew.height + "\nID= " + imgNew.id);     
        divParent.replaceChild(imgNew, preview);
        
        var link= document.getElementById("GalleryPreviewLink");
        if (link==null)
            link= document.getElementById("ctl00_GalleryPreviewLink");

        var dest= "javascript:UpdateContent('ShowImage:" + group + ":" + item + ":" + page + ":" + selection + "','')";
       
        link.setAttribute("href", dest);
        
        
        var captent= document.getElementById("PreviewCaption");
        if (captent==null)
            captent= document.getElementById("ctl00_PreviewCaption");
          

        while (captent.firstChild!=null)
            {
            var child= captent.firstChild;
//            alert("Removed child");
            captent.removeChild(child);
            }
        var newcap= document.createTextNode(caption);

        captent.innerHTML= caption;

        MoveToTop("GalleryPreviewImage");
    }
    
    function SetThumbStyle(name,style)
    {   
        var thumb= document.getElementById(name)
        if (thumb==null)
            thumb= document.getElementById("ctl00_"+ name);
        if (thumb!=null)
//            alert(name + " was not found");
//        else 
            thumb.className= style;
    }
    
    function ShowImage(url,width,height)
    {
        var argstr= 'width=' + width + ',height=' + height + ',scrollbars=yes,resizable=yes,status=yes,toolbar=no,menubar=no,location=no';
        var win = window.open(url, '', argstr);
    }
    

