﻿function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
  
  addResizeEvent(func);
}

function addResizeEvent(func) {
    var oldonresize = window.onresize;
    if (typeof window.onresize != 'function') {
        window.onresize = func;
    } else {
        window.onresize = function() {
            if (oldonresize) {
                oldonresize();
            }
            func();
        }
    }
}

function resizeRightNav()
{
    var cb;
    var cbm;
    var rh = document.getElementById('rightNav').offsetHeight;
    

    
    if (getElementsByClass('SWContentBODYMinusLeftNavigation').length)  
    {
        cb = getElementsByClass('SWContentBODYMinusLeftNavigation')[0].offsetHeight + 30;
    }
    else if (getElementsByClass('SWCONTENTBODYMINUSLEFTNAVIGATION').length)
    {
        cb = getElementsByClass('SWCONTENTBODYMINUSLEFTNAVIGATION')[0].offsetHeight + 30;
    }
    else if (document.getElementById('lyrBody'))
    {
        cb = document.getElementById('lyrBody').offsetHeight + 30;
    }
    else if (document.getElementById('leftNav'))
    {
         cb = document.getElementById('leftNav').offsetHeight + 20;
    }
    if (getElementsByClass('SWContentBODY').length) cbm = getElementsByClass('SWContentBODY')[0].offsetHeight + 30;
    
    
    if (cb < rh)
    {
        document.getElementById('leftNavBkg').style.height = rh + 'px'; 
        document.getElementById('rightNavBkg').style.height = rh + 'px';
        rh = rh - 45;
        if (getElementsByClass('SWContentBODY').length) getElementsByClass('SWContentBODY')[0].style.height = rh + 'px';
        if (getElementsByClass('SWContentBODYMinusLeftNavigation').length) getElementsByClass('SWContentBODYMinusLeftNavigation')[0].style.height = rh + 'px';

    }
    else
    {
        if (cbm > cb) cb = cbm;
        document.getElementById('leftNavBkg').style.height = cb + 'px'; 
        document.getElementById('rightNavBkg').style.height = cb + 'px';
    }
    
    
}


function resizeHome()
{
    var contentheight = document.getElementById('homeRightNav').offsetHeight;

    var backgroundheight = document.getElementById('homeRightGrad').offsetHeight;

    if (contentheight > backgroundheight)
    {
        document.getElementById('homeRightGrad').style.height = contentheight + 'px';
        contentheight = contentheight + 158;

        document.getElementById('homeLeftNav').style.height = contentheight + 'px';
    }
    
}

function resizeSWHead()
{
    var tablelist = document.getElementsByTagName('table')
    
    tablelist[0].width = 944;
}

function resizeSWFoot()
{
    if (document.getElementById('sw-footer')) {
        document.getElementById('sw-footer').style.width = '944px';
        document.getElementById('sw-footer').innerHTML = '<div style="width: 100%; background-color: #6a6b6c; "><span style="line-height: 2; color: #000000; text-decoration: none;"><center><a href="mailto:info@pvsd.k12.ca.us"><span style="color: #FFFFFF; text-decoration: none;">Questions or Feedback?</span></a> <span style="color: #FFFFFF; text-decoration: none;">|</span> <a href="http://www.schoolwires.com/policies"><span style="color: #FFFFFF; text-decoration: none;">TRUSTe Approved Privacy Policy</span></a></center></span></div><table width="100%"><tr><td><p>Copyright 2002-2009 Schoolwires, Inc. All rights reserved.</p></td><td align="right"><p>All Content Copyright 2009 Pleasant Valley School District</p></td></tr></table></div>';
    }
}



function formatCalendar()
{
    if (getElementsByClass('SmallCalendarOuter').length)
    {
        var contentdiv = getElementsByClass('SWContentBODYMinusLeftNavigation')[0];
        var alltd = contentdiv.getElementsByTagName('td');

  
        for (i = 0; i < alltd.length; i++)
        {
            if (alltd[i].width = '10%')
            {
                if (alltd[i].parentNode.className != 'ViewHeader') {
                alltd[i].width = '';
                var calHelp = "<div class=navHeader>Calendar Tips</div><ul style='margin-left: 0; padding-left: 14;'><li>For <strong>event details</strong>, click on the event name.</li>";
                var calHelp = calHelp + "<li>To <strong>filter events</strong>, click 'Filter Options', select the sites or categories you want to view, then press the Filter button.</li>";
                var calHelp = calHelp + "<li>To <strong>add events to your personal calendar</strong>, click 'Export', enter a date range, and then open the downloaded file in a calendar program such as Outlook or iCal. (Note: Times may not show up correctly in Outlook 2007)</li>";
                var calHelp = calHelp + "<li>To <strong>receive automatic e-mail updates</strong> when this calendar is updated, follow the instructions in <a href='http://pvsd.schoolwires.net/16411058121613277/blank/browse.asp?A=383&BMDRN=2000&BCOB=0&C=55533'><span style='color: #FFFFFF; text-decoration: underline'>this video</span></a> and select 'homepage'.</li></ul>";
                document.getElementById('leftText').innerHTML = calHelp;
}
            } 
        }

  }
}

   function fixLinks()
   {
       var images = document.getElementsByTagName('IMG');

       for(var i=0; i<images.length; i++)
       {
           var sLink = images[i].src
           if(sLink.indexOf('_template') != -1)
           {
               images[i].src =
'http://pvsd.schoolwires.net/pvsd/LIB/pvsd/' +
sLink.slice(sLink.indexOf('_template'),sLink.length);
           }
       }
   }

function formatHierarchy()
{
    if (document.getElementById('leftNav')) {
    var leftNav = document.getElementById('leftNav');
    var allImg = leftNav.getElementsByTagName('img');
    var isHierarchy = 0;
    
    for (i = 0; i < allImg.length; i++)
    {
        if (allImg[i].src.indexOf('bullet') == -1) 
        {
            isHierarchy = 1;
        }
    }
    
    if (isHierarchy == 1) 
    {
        for (i = 0; i < allImg.length; i++)
        {
            allImg[i].style.display = 'inline';
        }
    } }
}


function subpagefunctions()
{
    addLoadEvent(resizeSWFoot);
    addLoadEvent (resizeSWHead);
    addLoadEvent(resizeRightNav);
    addLoadEvent (fixLinks);
    addLoadEvent(formatCalendar);
    addLoadEvent (formatHierarchy);
}

function footerfunctions()
{
    resizeSWHead();
    resizeRightNav();
    formatHierarchy();
}


function homepagefunctions()
{
    addLoadEvent(resizeHome);
    addLoadEvent(resizeSWFoot);
    addLoadEvent (resizeSWHead);
}