/*
#
# $Id: general.js,v 1.2 2006/08/29 00:00:42 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the PROM/SE Virtual Professional Development (VPD
# system.
#
# VPD is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# VPD is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with VPD; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# 

*/

function onloadFunctions(section,page){
    //Highlight the current section in the persistent menu
    // document.getElementById('nav'+ section).className='active'
    //    document.getElementById("interiorContent").style.zIndex = 100;
    if (typeof(buildingCourse) != "undefined") {
        buildCourseInitialize();
    }
    loginName = document.getElementById("username");
    if (loginName) {
        loginName.focus();
    }
    
    if (page!='NULL') {
    //Highlight the current page in interior menu
        liPage=document.getElementById(page);
        liPage.firstChild.className= "active"
    

    //Highlight menu items that have submenus with down arrow
    var ULs = document.getElementsByTagName('UL');

    for (var i=0;i<ULs.length;i++) {
        if (ULs[i].id.indexOf('subMenu')!=-1) {
            ULs[i].parentNode.firstChild.className="expandActive"
        }
    }

//Display nested ULs if parent or member li is active and highlight parent with down arrow

    for (i=0; i<liPage.childNodes.length; i++) {
      var node=liPage.childNodes[i];

        if (node.nodeName=="UL"){
        liPage.firstChild.className="subMenuActive"
        //node.style.display="block"
		node.className="show"
        }
    }

    if (liPage.parentNode.parentNode.nodeName=="LI") {
        //liPage.parentNode.style.display="block"
		liPage.parentNode.className="show"
        liPageGrandParent=liPage.parentNode.parentNode
        liPageGrandParent.firstChild.className= "subMenuActive"
    }


}

login = document.getElementById('username');
if (login) {
    login.focus();
}
// set minumum height for IE.

 //     var wrapperColumnHeight=document.getElementById('wrapperColumn').offsetHeight;

   //     if (document.all && wrapperColumnHeight<347) {
     //          document.getElementById('wrapperColumn').style.height=37.5 + 'em';
       //     }


/*This script is a fix for IE not recognizing the css hover for elements other than links
        See http://www.alistapart.com/articles/dropdowns/ for reference */
/*
    //First check to see if browser is IE
     if (document.all&&document.getElementById) {
        //loop through each li in the parent ul
        navRoot = document.getElementById("navPersistent");
            for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
                if (node.nodeName=="LI") {
            //change name of class for li depending on mouseover state
                    node.onmouseover=function() {
                        this.className+="over";
                    }
                    node.onmouseout=function() {
                        this.className=this.className.replace("over", "");
                    }
                }
            }
      }
*/
}
function infoReveal(segmentId, segmentNum) {
   var arrowTest = /BannerRightArrow/;
   var arrowImage = document.getElementById(segmentId + 'Image' + segmentNum);
   var divCollapse = document.getElementById(segmentId + 'Collapser' + segmentNum);
   var divControl = document.getElementById(segmentId + 'Controller' + segmentNum);
   var divContainer = document.getElementById(segmentId + 'Container' + segmentNum);
    if (arrowTest.test(arrowImage.src)) {
        arrowImage.src = '../_images/BannerDnArrow.gif';
        divControl.style.borderBottom = '0px';
        divContainer.style.borderBottom = '1px black solid';
        divCollapse.style.display = 'block';
    } else {
        divControl.style.borderBottom = '1px black solid';
        divContainer.style.borderBottom = '0px';
        arrowImage.src = '../_images/BannerRightArrow.gif';
        divCollapse.style.display = 'none';
    }
}
function get_xmlHttp() {
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    return(xmlHttp);    
}
function saveUnit(token, district_id, curriculum_id) {
    var grade = document.getElementById('grade');
    var unitDescription = document.getElementById('newunitdescription');
    var unitTitle = document.getElementById('title');
    xmlHttp = get_xmlHttp();
    xmlHttp.onreadystatechange = function() {
        var output;
        if(xmlHttp.readyState==4) {
            // Get the data from the server's response
            //var text_out;
            alert(xmlHttp.responseText);
            var xmlDoc = xmlHttp.responseXML.documentElement;
            alert(xmlDoc.nodeName);
            var allUnits = xmlDoc.childNodes;
            var loopEnd = xmlDoc.childNodes.length;
            for (i=0;i<loopEnd;i++) {
            output += '<div id="unitContainer' + $unit_counter + '">';
            output += '<div id="unitController' + $unit_counter + '">';
            output += '<div class="arrowSpacer" onclick="infoReveal(\'unit\',' + "$unit_counter" + ');">';
            output += '<img id="unitImage' + $unit_counter + '" src="../_images/BannerRightArrow.gif" width="7" height="4" alt="" />';
            output += '</div>';
            output += '</div>';
            output += '<div id="unitCollapser' + $unit_counter + '">';
            output += 'develop curriculum here';
            output += '</div>';
            output += '</div>';





                output += '<div>';
                output += allUnits[i].getElementsByTagName('title')[0].childNodes[0].nodeValue;
                output += '</div>';
            }
            document.getElementById('replaceThis').innerHTML = output;
            // timedMsg();     
        }
    }
    xmlHttp.open("GET","/promse/flash?token="+token+"&amp;seqorder=1&amp;grade="+grade.value+"&amp;action=saveunit&amp;curriculumid="+curriculum_id+"&amp;districtid="+district_id+"&amp;title="+unitTitle.value+"&amp;description="+unitDescription.value,true);
    xmlHttp.send(null);
    
}
function linker(material_id, district_id, token) {
    document.getElementById("statusMessage").innerHTML="Saving Change";
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState==4) {
            // Get the data from the server's response
            //var text_out;
            var xmlDoc = xmlHttp.responseXML.documentElement;
            var linkMessage = xmlDoc.getElementsByTagName('linkmessage')[0].childNodes[0].nodeValue;
            if (linkMessage == "linked") {
                document.getElementById("linkMessage" + material_id).innerHTML = "In District";
            } else if (linkMessage == "unlinked") {
                document.getElementById("linkMessage" + material_id).innerHTML = "Not in District";
            } else {
                document.getElementById("linkMessage" + material_id).innerHTML = "Server Problem";
            }
            document.getElementById("statusMessage").innerHTML="Saved";
            // timedMsg();     
        }
    }
    xmlHttp.open("GET","/promse/flash?token="+token+"&amp;action=linkmaterialdistrict&amp;materialid="+material_id+"&amp;districtid="+district_id,true);
    xmlHttp.send(null);
}
function toggleHomeIntro(showID,hideID,hideID2){
    document.getElementById('dd'+ showID).style.left=0
    if (hideID) {
        document.getElementById('dd'+ hideID).style.left='-9999px'
    }
    if (hideID2) {
        document.getElementById('dd'+ hideID2).style.left='-9999px'
    }

    dlRoot = document.getElementById("homeIntroSectionMenu");
    for (i=0; i<dlRoot.childNodes.length; i++) {
       node = dlRoot.childNodes[i];
		if (node.id=='dt'+ showID) {
			node.firstChild.className="active"
		}
		if (node.id=='dt'+ hideID || node.id=='dt'+ hideID2){
			node.firstChild.className=""
		}
	}
}




