// GLOBAL VARIABLES

var OnMenu = false;
var OnMenuTimeout = false;
var TimeoutID;

// search results
var SearchResult_Limit = 25;
var SearchResult_PageName = new Array(SearchResult_Limit);
var SearchResult_PageText = new Array(SearchResult_Limit); 

// search timing
var SearchComplete = true;
var ElapsedTime = 0;
var WaitBeforeSearch = 2;      
var TimerID;

// security edit boxes
var SecurityBox = "";  

// ajax
http_request = false; 
  
// active directory same account name and display name (used for security boxes)
var AD_sAMAccountName = new Array();
var AD_displayName = new Array();

  
/* ------------------
   Initialize TinyMCE
   ------------------ */
  
  tinyMCE.init({ 
// General options 
mode : "textareas", 
theme : "advanced", 
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager,advfile",
textarea_trigger : "htmleditor", 
 
// Theme options 
theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", 
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,advfile,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", 
theme_advanced_toolbar_location : "top", 
theme_advanced_toolbar_align : "left", 
theme_advanced_statusbar_location : "bottom", 
theme_advanced_resizing : true,    
 
// Example content CSS (should be your site CSS) 
content_css : "css/dcsdweb.css", 
 
// Drop lists for link/image/media/template dialogs 
template_external_list_url : "tinymce/template_list.js", 
external_link_list_url : "js/link_list.js", 
external_image_list_url : "js/image_list.js", 
media_external_list_url : "js/media_list.js", 
 
// Replace values for the template plugin 
template_replace_values : { 
username : "Some User", 
staffid : "991234" 
} 
});            
  
      
function Init()
{       

                     
    /* ------------------------------
    Hide the marquee after a delay
    ------------------------------ */

    setTimeout("HideMarquee()",60000);                                                        


    /* -------------------------------
    Set focus on the correct fields
    ------------------------------- */


    // try catch block because safari does not like the focus function
    try
    {
        if(document.getElementById("StreetNumber")!= undefined)
        {
            document.getElementById("StreetNumber").focus();                                            // focus on StreetNumber (school zone finder)
        }
        else if(document.getElementById("Username") != undefined)
        {
            document.getElementById("Username").focus();                                                // focus on Username (login form)
        }
        else
        {
            document.getElementById("searchfield").focus();                                             // focus on SearchField (search field on page header bar)
        }
    }
    catch(e){}        
    
    
    // Hide the Live HTML (LiveHTML is used in Draft mode so the author can see the HTML that is currently displayed live to end users on the website)
    document.getElementById("LiveHTML").style.display = "none";   
    
    
    // If Anchorname variable is set then take the user to where the anchor is located
    if(AnchorName!="")
    {
      document.location = "#" + AnchorName;
      
      try
      {
      document.getElementById(AnchorName + "c1").style.backgroundColor = "Yellow";
      document.getElementById(AnchorName + "c2").style.backgroundColor = "Yellow";
      document.getElementById(AnchorName + "c3").style.backgroundColor = "Yellow";
      document.getElementById(AnchorName + "c4").style.backgroundColor = "Yellow";
      }
      catch(e)
      {
      }
    }
    
    
    
    if(document.getElementById("bg_message")!= undefined)
    {
      
      if(readCookie("message") == null)
      {
        ShowMessage();
      }
    }
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function HideMessage()
{
    HideElement("bg_message",null);
    HideElement("text_message",null);
    
    if(readCookie("message")==null)
    {        
        createCookie("message","no",90);
    }        
    
    return false;
}
      
function HideMarquee()
{
    if(document.getElementById("MarqueeTable")!=undefined)
    {
        document.getElementById("MarqueeTable").style.left = "-4000px";
    }
}

function EditPage()
{         

    var PageName;
    var splittext;
    var txtDisplay;

    // Hide draft/live controls if they are present
    HideElement("DraftLiveControl_row","relative");   

    // Show horizontal rule, save page and cancel
    ShowElement("pageedit1","relative","0");
    ShowElement("pageedit2","relative","0");
    ShowElement("pageedit3","relative","0");   

    // Set all Page Option Fields    
    document.getElementById("PageName").value = txtPageName;                                                         
    document.getElementById("SearchKeywords").value = txtSearchKeywords;                            
    document.getElementById("Private").value = txtPrivate;    
    document.getElementById("MarqueeOn").value = txtMarqueeOn;
    document.getElementById("MarqueeText").value = txtMarqueeText;
    document.getElementById("PageOwner").value = txtPageOwner;
    document.getElementById("PageAuthor").value = txtPageAuthor;
    document.getElementById("PageViewer").value = txtPageViewer;
    
        
    document.getElementById("PageOwnerText").innerHTML = "";
    splittext = txtPageOwner.split(";",4);
        
    for(var i=0; i<=splittext.length - 1; i++)
    {
        if(splittext[i].length > 15)
        {
            txtDisplay = splittext[i].substring(0,15) + "...";
        }
        else
        {
            txtDisplay = splittext[i];
        }
    
        document.getElementById("PageOwnerText").innerHTML  += "<span title=\"" + splittext[i] + "\">" + txtDisplay + "</span><BR>";    
    }
    
    document.getElementById("PageAuthorText").innerHTML = "";
    splittext = txtPageAuthor.split(";",4);
        
    for(var i=0; i<=splittext.length - 1; i++)
    {
        if(splittext[i].length > 15)
        {
            txtDisplay = splittext[i].substring(0,15) + "...";
        }
        else
        {
            txtDisplay = splittext[i];
        }
    
        document.getElementById("PageAuthorText").innerHTML  += "<span title=\"" + splittext[i] + "\">" + txtDisplay + "</span><BR>";    
    }
  
  
    document.getElementById("PageViewerText").innerHTML = "";
    splittext = txtPageViewer.split(";",4);
        
    for(var i=0; i<=splittext.length - 1; i++)
    {
        if(splittext[i].length > 15)
        {
            txtDisplay = splittext[i].substring(0,15) + "...";
        }
        else
        {
            txtDisplay = splittext[i];
        }
    
        document.getElementById("PageViewerText").innerHTML  += "<span title=\"" + splittext[i] + "\">" + txtDisplay + "</span><BR>";    
    }
                        
      
    // Clear ParentPage options if some exist
    var NumOptions = document.getElementById("ParentPageID").options.length;
    
    if(NumOptions > 0)
    {
        for(var i=0; i<= NumOptions; i++)
        {
            document.getElementById("ParentPageID").options.remove(0);
        }
    }          
           
    // If logged in user is not an admin or owner of page then disable some options     
    if(txtPageOwner.indexOf(Username) == -1 && Username != "admin" && !ContainsUserGroups(txtPageOwner))
    {
        // Add the Current ParentPage to the option list            
        var Option = document.createElement("OPTION");
        
        Option.value = txtParentPageID;        
        Option.text = txtParentPageName;            
        document.getElementById("ParentPageID").options.add(Option);        
        
        // Disable the appropriate options                  
        document.getElementById("PageName").readOnly = "true";   
        document.getElementById("PageName").style.color = "#999999";                   
    }
    else
    {        
        // Add the Current ParentPage to the option list            
        var Option = document.createElement("OPTION");
        
        Option.value = txtParentPageID;
        
        Option.text = txtParentPageName; 
           
        document.getElementById("ParentPageID").options.add(Option);
    
        // Add the Pages of which the current user is an owner of
        for(var i=0; i<= OwnedPages_ID.length - 1; i++)
        {
        
            if(OwnedPages_Name[i].length > 25)
            {
                PageName = OwnedPages_Name[i].substring(0,25) + "...";
            }
            else
            {
                PageName = OwnedPages_Name[i];
            }
            
                    
            // Dont add the current page to the list or the the page that was already added above
            if(OwnedPages_ID[i] != txtParentPageID && OwnedPages_ID[i] != txtPageID)
            {
                var Option = document.createElement("OPTION");
                Option.value = OwnedPages_ID[i];
                Option.text = PageName;
    
                document.getElementById("ParentPageID").options.add(Option);
            }                        
        }
        
        document.getElementById("ParentPageID").value = txtParentPageID;
        
        // Enable the appropriate fields        
        document.getElementById("PageName").readOnly = "";        
    }            
                          
    document.getElementById("PageHTML").style.display = "none";
    document.getElementById("LiveHTML").style.display = "none";                                     // hide the page html
    
    
    
    ShowElement("PageOptions","absolute","0");            
    
    try
    {
        document.getElementById("CreateBox").style.left = "-4000px";
    }
    catch(e){}        
                                       
    // hide the html editor box (for creating pages)       
    document.getElementById("EditBox").style.left = "0px";                                          // show the html editor box (for editing pages)

 

    //ShowElement("DraftWaterMark");

    try
    {
        document.getElementById("DraftWaterMark").style.display = "";
    }
    catch(e){}

    return false;                                                                                   // return false so the (edit page) link doesn't go anywhere                                      
}

function ContainsUserGroups(AuthorizedUsersOrGroups)
{   
    var arrUserGroups = new Array();    
    var FoundOne = false;                        
    
    arrUserGroups = UserGroups.split(";");       
    
    for(var i=0; i<=arrUserGroups.length - 1; i++)
    {
        if(arrUserGroups[i]!="")
        {
            if(AuthorizedUsersOrGroups.toLowerCase().indexOf(arrUserGroups[i].toLowerCase()) != -1)
            {                
                FoundOne = true;
            }
        }
    }
    
    return FoundOne;    
}

function CreatePage()
{   

    // Show horizontal rule, save page and cancel
    ShowElement("pageedit1","relative","0");
    ShowElement("pageedit2","relative","0");
    ShowElement("pageedit3","relative","0");

    var PageName;
                
    HideElement("DraftLiveControl_row","relative");   
    
    // Enable fields if previously disabled                
    document.getElementById("PageName").readOnly = "";      
    document.getElementById("PageName").style.color = "#000000";       

    // Clear ParentPage options if some exist
    var NumOptions = document.getElementById("ParentPageID").options.length;
    
    if(NumOptions > 0)
    {
        for(var i=0; i<= NumOptions; i++)
        {
            document.getElementById("ParentPageID").options.remove(0);
        }
    }
          
    // Add the Pages of which the current user is an owner of
    for(var i=0; i<= OwnedPages_ID.length - 1; i++)
    {       
    
     if(OwnedPages_Name[i].length > 25)
            {
                PageName = OwnedPages_Name[i].substring(0,25);
            }
            else
            {
                PageName = OwnedPages_Name[i];
            }
    
        var Option = document.createElement("OPTION");
        
        Option.value = OwnedPages_ID[i];
        
        Option.text = PageName;
        document.getElementById("ParentPageID").options.add(Option);
            
        document.getElementById("ParentPageID").value = txtPageID;                        
    }
    
    // Set all page options to blank or default values
    document.getElementById("PageName").value = "";                                                 
    document.getElementById("SearchKeywords").value = "";
    document.getElementById("Private").value = "false";
    document.getElementById("MarqueeOn").value = "false";
    document.getElementById("MarqueeText").value = "";

    document.getElementById("PageHTML").style.display = "none";                                     
    document.getElementById("LiveHTML").style.display = "none";       
    
    ShowElement("PageOptions","relative","0");                                          
        
    document.getElementById("CreateBox").style.left = "0px";                                        
    document.getElementById("EditBox").style.left = "-3000px";                                      

    document.getElementById("PageOwnerText").innerHTML = Username + "<br>Sec - DCSD Webmasters";
    document.getElementById("PageOwner").value = Username + ";Sec - DCSD Webmasters;";
    
    document.getElementById("PageAuthorText").innerHTML = "";
    document.getElementById("PageAuthor").value = "";

    document.getElementById("PageViewerText").innerHTML = "everyone";
    document.getElementById("PageViewer").value = "everyone;";

    document.getElementById("PageName").focus();

    return false;                                                                                                                         
}

function QuickNav()
{    
    try
    {
        document.location = "#" + document.getElementById("select").value;
        
        document.getElementById(document.getElementById("select").value + "c1").style.backgroundColor = "yellow";
        document.getElementById(document.getElementById("select").value + "c2").style.backgroundColor = "yellow";
        document.getElementById(document.getElementById("select").value + "c3").style.backgroundColor = "yellow";
        document.getElementById(document.getElementById("select").value + "c4").style.backgroundColor = "yellow";
        document.getElementById(document.getElementById("select").value + "c5").style.backgroundColor = "yellow";
    }
    catch(e)
    {
    }
}

function ToggleHide(id)
{
    if(document.getElementById(id).style.position != "absolute")
    {
        document.getElementById(id).style.position = "absolute";
        document.getElementById(id).style.left = "-4000px";
    }
    else
    {
        document.getElementById(id).style.position = "relative";
        document.getElementById(id).style.left = "0px";
    }
    
    return false;
}

function ShowMessage()
{
    document.getElementById("bg_message").style.display = "";
    document.getElementById("text_message").style.display = "";
}

function ShowElement(id,mode,leftpos)
{
    try
    {
        if(document.getElementById(id) != undefined)
        {
            if(mode == "relative")
            {
                document.getElementById(id).style.position = "relative";
            }
                       
            document.getElementById(id).style.left = leftpos + "px";                              
            document.getElementById(id).style.display = "";
        }
    }
    catch(e){}
}

function HideElement(id,mode)
{
    try
    {
        if(document.getElementById(id) != undefined)
        {
            if(mode == "relative")
            {
                document.getElementById(id).style.position = "absolute";
            }
            
            document.getElementById(id).style.left = "-4000px";        
            document.getElementById(id).style.display = "none";            
        }
    }
    catch(e){}
}

function ShowQuickLinks(type)
{
    switch(type)
    {
        case "students":
            ShowElement("quicklinks_students1","absolute","0");                        
            ShowElement("quicklinks_students2","absolute","10");                        
            ShowElement("quicklinks_students3","absolute","10");            
        break;
        
        case "parents":
            ShowElement("quicklinks_parents1","absolute","200");
            ShowElement("quicklinks_parents2","absolute","210");
            ShowElement("quicklinks_parents3","absolute","210");                   
        break;
        
        case "employees":
            ShowElement("quicklinks_employees1","absolute","400");
            ShowElement("quicklinks_employees2","absolute","410");
            ShowElement("quicklinks_employees3","absolute","410");                       
        break;
        
        case "mostvisited":
            ShowElement("quicklinks_mostvisited1","absolute","600");
            ShowElement("quicklinks_mostvisited2","absolute","610");
            ShowElement("quicklinks_mostvisited3","absolute","610");                        
        break;
    }
}

function HideQuickLinks(type)
{
    switch(type)
    {
        case "students":
            HideElement("quicklinks_students1","absolute");
            HideElement("quicklinks_students2","absolute");
            HideElement("quicklinks_students3","absolute");
        break;
        
        case "parents":
            HideElement("quicklinks_parents1","absolute");
            HideElement("quicklinks_parents2","absolute");
            HideElement("quicklinks_parents3","absolute");
        break;
        
        case "employees":
            HideElement("quicklinks_employees1","absolute");
            HideElement("quicklinks_employees2","absolute");
            HideElement("quicklinks_employees3","absolute");
        break;
        
        case "mostvisited":
            HideElement("quicklinks_mostvisited1","absolute");
            HideElement("quicklinks_mostvisited2","absolute");
            HideElement("quicklinks_mostvisited3","absolute");
        break;
        
        case "all":
            HideElement("quicklinks_students1","absolute");
            HideElement("quicklinks_students2","absolute");
            HideElement("quicklinks_students3","absolute");
        
            HideElement("quicklinks_parents1","absolute");
            HideElement("quicklinks_parents2","absolute");
            HideElement("quicklinks_parents3","absolute");
                    
            HideElement("quicklinks_employees1","absolute");
            HideElement("quicklinks_employees2","absolute");
            HideElement("quicklinks_employees3","absolute");
      
            HideElement("quicklinks_mostvisited1","absolute");
            HideElement("quicklinks_mostvisited2","absolute");
            HideElement("quicklinks_mostvisited3","absolute");
        break;
    }
}

function ApproveDraft()
{    
    document.getElementById("Action").value = "approve";  
    document.getElementById("PageName").value = txtPageName;
               
    document.getElementById("HTMLForm").submit(); 
    
    return false; 
}

function DenyDraft()
{ 
    document.getElementById("Action").value = "deny";
    document.getElementById("HTMLForm").submit(); 
    
    return false; 
}

function ClearDraft()
{     
    var con = confirm("Are you sure you want to clear the draft?");    
        
    if(con)
    {
        document.getElementById("Action").value = "cleardraft";
        document.getElementById("HTMLForm").submit(); 
    }
        
    return false; 
}

function DeletePage()
{        
    var con = confirm("Are you sure you want to delete this page?");    
        
    if(con)
    {
        document.getElementById("Action").value = "delete";
        document.getElementById("HTMLForm").submit(); 
    }
        
    return false; 
                                                             
}   

function ViewOtherInfo()
{
    if(document.getElementById("OtherInfoLink").innerHTML == "other info")
    {
        document.getElementById("OtherInfoLink").innerHTML = "security info";
    }
    else
    {
        document.getElementById("OtherInfoLink").innerHTML = "other info";
    }
       
    ToggleHide("colPageOwner");
    ToggleHide("colPageAuthor");
    ToggleHide("colPageViewer");
    
    ToggleHide("PageOwnerText");
    ToggleHide("PageAuthorText");
    ToggleHide("PageViewerText");
    
    ToggleHide("colPageApproved");
    ToggleHide("colApprovedBy");
    ToggleHide("colLastEditedBy");
    
    ToggleHide("PageApprovedText");
    ToggleHide("ApprovedByText");
    ToggleHide("LastEditedByText");              
    
    return false;
}

function UpdateMarqueeText()
{
    document.getElementById("PageMarquee").innerHTML = document.getElementById("MarqueeText").value;
}
     
function SavePage()
{      
    
    if(document.getElementById("CreateBox").style.left == "0px")                                    // if create box is visible then action is create
    {           
        document.getElementById("Action").value = "create";
    }
    else                                                                                            // if create box is not visible then action is edit
    {
        document.getElementById("Action").value = "edit";
    }                

    document.getElementById("HTMLForm").submit();                                                   // submit the form that processes creating new page or editing current page
    
    return false;                                                                                   // return false so the (save page) link doesn't go anywhere        
}

function ToggleDraftLiveHTML()
{         
    if(document.getElementById("PageHTML").style.display == "")                                    
    {           
        document.getElementById("DraftWaterMark").style.display = "none";
        document.getElementById("PageHTML").style.display = "none";
        document.getElementById("LiveHTML").style.display = ""; 
        document.getElementById("DraftLiveControl").innerText = "view draft page";       
    }
    else                                                                                          
    {
        document.getElementById("DraftWaterMark").style.display = "";
        document.getElementById("PageHTML").style.display = "";
        document.getElementById("LiveHTML").style.display = "none";        
        document.getElementById("DraftLiveControl").innerText = "view live page";
    }                
        
    return false;                                                                                  
}

function Cancel()
{          

    // Hide page edit options from page edit panel
    HideElement("pageedit1","relative");
    HideElement("pageedit2","relative");
    HideElement("pageedit3","relative");

    document.getElementById("PageHTML").style.display = "";
    
    HideElement("PageOptions","absolute");
    
    //document.getElementById("PageOptions").style.left = "-4000px";                                  // hide the page options
    document.getElementById("CreateBox").style.left = "-4000px";                                    // hide the create box                                                
    document.getElementById("EditBox").style.left = "-4000px";                                      // hide the edit box 

    try{document.getElementById("PageMarquee").innerHTML = txtMarqueeText;}
    catch(e){}

    if(document.getElementById("DraftLiveControl_row") != undefined)
    {
    
        ShowElement("DraftLiveControl_row","relative","0");
        
        document.getElementById("LiveHTML").style.display = "none";
        document.getElementById("DraftWaterMark").style.display = "";
        document.getElementById("DraftLiveControl").innerText = "view live page";           
    }

    return false;                                                                                   // return false so the cancel link doesn't go anywhere           
}           

function CloseSearchResults()
{
    document.getElementById("SearchField").value = "";                                      // clear the search field

    document.getElementById("SearchHTMLPanel").style.left = "-4000px";                      // hide the search result panel
    document.getElementById("PageHTML").style.display = "";                                 // show the page html

    document.getElementById("SearchField").focus();                                         // focus on the search field

    return false;                                                                           // return false so the close results link doesn't go anywhere
}                   

function ActivateImage(id)
{
    var curimage = document.getElementById(id).src; 
    var newimage = curimage.replace(".png","_active.png");
    document.getElementById(id).src = newimage;
}

function DeActivateImage(id)
{
    var curimage = document.getElementById(id).src; 
    var newimage = curimage.replace("_active.png",".png");
    document.getElementById(id).src = newimage;
}         

function ActivateNavPanelCell(id)
{
    document.getElementById(id).style.backgroundImage = "url('images/main/bg_navpanelcell_active.png')";
}

function DeActivateNavPanelCell(id)
{
    document.getElementById(id).style.backgroundImage = "url('images/main/bg_navpanelcell.png')";
}           

function GotoPage(e)
{
    document.location="main.aspx?pageid=" + e;        
}                  

function BackToSearchResults(SearchString)
{
    document.getElementById("SearchField").value = SearchString;
    
    StartSearching();
}


/* --------------------
   Search Engine Functions
   ----------------------- */

function StartSearching()
{           
    if(SearchComplete)
    {          
        TimerID = setInterval("IncrementSearchTimer()",500);
        SearchComplete = false;
    }
    else
    {
        ElapsedTime = 0;
    } 
}

function IncrementSearchTimer()
{
    if(ElapsedTime == WaitBeforeSearch)
    {         
        clearInterval(TimerID);
        SearchComplete = true;
        ElapsedTime = 0;
        
        try
        {                       
            GetSearchResults(document.getElementById("SearchField").value,UserGroups,Username);            
        }    
        catch(e)
        {        
            GetSearchResults(document.getElementById("SearchField").value,"","");
        }
    }
    else
    {
        ElapsedTime += 1;
    }
}           

function GetSearchResults(SearchString,UserGroups,Username)
{           

    url = "ajaxhandler.aspx?searchstring=" + SearchString + "&usergroups=" + UserGroups + "&username=" + Username + "&action=search";  
    http_request = false;              

    // If window.XMLHttpRequest returns true then were on a Mozilla Safari browser
    if (window.XMLHttpRequest)
    { // Mozilla, Safari,...
        this.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            // set type accordingly to anticipated content type           
            http_request.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject) // If window.ActiveXObject return true then were on a IE Browser
    { // IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");  // First try Msxml2.XMLHTTP (newer browsers)
        }
        catch (e)
        {
            try
            {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");  // If not Msxml2.XMLHTTP then try Microsoft.XMLHTTP (most browsers)
            }
            catch (e) {}
        }
    }
    if (!http_request)
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }

    http_request.onreadystatechange = ProcessSearchResults;
    http_request.open('GET', url, true);     
    http_request.send(null);
}

function ProcessSearchResults()
{  

    // initialize the search result vars
    for(i=0; i<=SearchResult_Limit - 1; i++)
    {
    SearchResult_PageName[i] = "";
    SearchResult_PageText[i] = "";
    }

    var recordstring = "";

    var pagenamestring = "";
    var pagetextstring = "";  

    var numrecords = 0;

    if (http_request.readyState == 4)
    {  
        if (http_request.status == 200)
        {         
            result = http_request.responseText;          

            for(i=0; i<=result.length - 1; i++)
            {
                if(result.substring(i,i+2)!=";;")
                {
                    recordstring += result.substring(i,i+1); 
                }
                else
                { 
                    if(recordstring.substring(0,1)==";")
                    {
                    recordstring = recordstring.substring(1,recordstring.length);
                    }

                    for(i2=0; i2<=recordstring.length - 1; i2++)
                    {
                        if(recordstring.substring(i2,i2+2)!=",,")
                        {
                            if(i2<recordstring.indexOf(",,"))
                            {
                            pagenamestring += recordstring.substring(i2,i2+1); 
                            }
                            else
                            {
                            pagetextstring += recordstring.substring(i2,i2+1);
                            }
                        }            

                    }

                    if(pagetextstring.substring(0,1)==",")
                    {
                        pagetextstring = pagetextstring.substring(1,pagetextstring.length);
                    }

                    SearchResult_PageName[numrecords] = pagenamestring.replace("pagename::","");          
                    SearchResult_PageText[numrecords] = pagetextstring.replace("pagetext::","");                   

                    numrecords++;

                    recordstring = "";
                    pagenamestring = "";
                    pagetextstring = "";
                }
            }

            UpdateSearchResultsTable();
                                                                
        }       
        else 
        { 
            alert("There was a problem with the function 'ProcessSearchResults'.");
        }   
    }
}

function UpdateSearchResultsTable()
{    
    
    var ColorToggle = 1;
                      
    if(document.getElementById("SearchField").value.length>1)
    {
        var numRows = 3;
        var numCols = 3;                                     

        var oPageHTML = document.getElementById("PageHTML");
        var oSearchHTML = document.getElementById("SearchHTML");
        var oSearchHTMLPanel = document.getElementById("SearchHTMLPanel");

        // Launch cancel in case editing is in progress 
        try
        {
            Cancel();
        }
        catch(e){}
        
        oPageHTML.style.display = "none";
        
       
        
        oSearchHTMLPanel.style.left = "0px";

        var oTable = document.createElement("Table");
       

        oTable.setAttribute("width","100%");
        oTable.setAttribute("id","SearchTable");                                      
        oTable.setAttribute("cellpadding","0");
        oTable.setAttribute("cellspacing","0");

        for(var i=0; i<=SearchResult_PageName.length - 1; i++)
        {
            if(SearchResult_PageName[i]!="")
            {
                                                                  
                var oTR = oTable.insertRow(i);                                                                                                                                                                       

                if(ColorToggle==1){oTR.style.backgroundColor = "#cccccc";}
                else{oTR.style.backgroundColor = "#eeeeee";}

                var oTD = oTR.insertCell(0);
                
                oTD.style.paddingLeft = "10px";
                            
                //oTD.innerHTML = "<span style=\"padding-left: 5px;\">" + SearchResult_PageName[i] + "</span>";                                

                oTD.innerHTML = SearchResult_PageName[i];

                var oTD = oTR.insertCell(1);
                oTD.innerHTML = SearchResult_PageText[i];

                ColorToggle = ColorToggle * -1; 
            }         
        }
        
       
               
        try
        {
            var SearchTable = document.getElementById("SearchTable"); 
            oSearchHTML.removeChild(SearchTable);         
        }
        catch(e){}         

        

        oSearchHTML.appendChild(oTable);
    }
    else
    {            
        CloseSearchResults();
    }           
                      
}

function Login()
{                                  
    GetLoginResults(document.getElementById("Username").value,document.getElementById("Password").value);                        
    return false;      
}


/* ----------------------------
School Zone Finder Functions
---------------------------- */

function FindSchoolZone()
{ 
    //document.getElementById("SearchError").innerText = "School Zone Finder is down for maintenance.  Please try again later.";
    //return false;
    if(document.getElementById("StreetName").value == "" || document.getElementById("StreetNumber").value == "")
    {
        document.getElementById("SearchError").innerText = "Please fill in both fields before clicking Search.";          
        return false;
    } 

    if(document.getElementById("StreetNumber").value/1 != document.getElementById("StreetNumber").value)
    {          
        document.getElementById("SearchError").innerText = "Please enter a number into the Street Number field.";
        return false;
    }

    document.getElementById("SearchError").innerText = "";

    GetSchoolZoneInfo(document.getElementById("StreetName").value,document.getElementById("StreetNumber").value) 

    return false;    
}

function GetSchoolZoneInfo(StreetName,StreetNumber)
{        
    url = "ajaxhandler.aspx?streetname=" + StreetName + "&streetnumber=" + StreetNumber + "&action=findschoolzone";   
    http_request = false;

    // Combine the parameters into the URL
    //url = url + "?" + parameters;            

    // If window.XMLHttpRequest returns true then were on a Mozilla Safari browser
    if (window.XMLHttpRequest)
    { // Mozilla, Safari,...
        this.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            // set type accordingly to anticipated content type           
            http_request.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject) // If window.ActiveXObject return true then were on a IE Browser
    { // IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");  // First try Msxml2.XMLHTTP (newer browsers)
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");  // If not Msxml2.XMLHTTP then try Microsoft.XMLHTTP (most browsers)
            }
            catch (e) {}
        }
    }
    
    if (!http_request)
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }

    http_request.onreadystatechange = ProcessSchoolZoneInfoResults;  
    http_request.open('GET', url, true);     
    http_request.send(null);
}


function ProcessSchoolZoneInfoResults()
{    
    // initialize the search result vars
    for(i=0; i<=SearchResult_Limit - 1; i++)
    {
        SearchResult_PageName[i] = "";
        SearchResult_PageText[i] = "";
    }

    var recordstring = "";

    var pagenamestring = "";
    var pagetextstring = "";  

    var numrecords = 0;

    if (http_request.readyState == 4)
    {  

        if (http_request.status == 200)
        {         
            result = http_request.responseText;         

            //alert(result);

            for(i=0; i<=result.length - 1; i++)
            {
                if(result.substring(i,i+2)!=";;")
                {
                    recordstring += result.substring(i,i+1); 
                }
                else
                { 
                    if(recordstring.substring(0,1)==";")
                    {
                        recordstring = recordstring.substring(1,recordstring.length);
                    }

                    for(i2=0; i2<=recordstring.length - 1; i2++)
                    {
                        if(recordstring.substring(i2,i2+2)!=",,")
                        {
                            if(i2<recordstring.indexOf(",,"))
                            {
                                pagenamestring += recordstring.substring(i2,i2+1); 
                            }
                            else
                            {
                                pagetextstring += recordstring.substring(i2,i2+1);
                            }
                        }            
                    }

                    if(pagetextstring.substring(0,1)==",")
                    {
                        pagetextstring = pagetextstring.substring(1,pagetextstring.length);
                    }

                    SearchResult_PageName[numrecords] = pagenamestring.replace("pagename::","");          
                    SearchResult_PageText[numrecords] = pagetextstring.replace("pagetext::","");                   

                    numrecords++;

                    recordstring = "";
                    pagenamestring = "";
                    pagetextstring = "";
                }
            }

            UpdateSchoolResultsTable();
                                                                
        }       
        else 
        { 
            //alert("There was a problem with the function 'ProcessSearchResults'.");
alert(result);
        }   
    }
}

function UpdateSchoolResultsTable()
{       

    var ColorToggle = 1;
                              
    var numRows = 3;
    var numCols = 3;                                     
     
    var oSearchHTML = document.getElementById("SchoolResults");
                  
    var oTable = document.createElement("Table");

    oTable.setAttribute("width","100%");
    oTable.setAttribute("id","SchoolResultsTable");                                      
    oTable.setAttribute("cellpadding","0");
    oTable.setAttribute("cellspacing","0");

    for(var i=0; i<=SearchResult_PageName.length - 1; i++)
    {
        if(SearchResult_PageName[i]!="")
        {                              

            var oTR = oTable.insertRow(i);                                                                                                                                                                                     

            var oTD = oTR.insertCell(0);
                    
            oTD.innerHTML = SearchResult_PageName[i];  

            oTD.style.textAlign = "right";
            oTD.style.verticalAlign = "middle";
                                  

            var oTD = oTR.insertCell(1);
            oTD.innerHTML = SearchResult_PageText[i];

            ColorToggle = ColorToggle * -1; 
        }         
    }                                       

    try
    {
        var SearchTable = document.getElementById("SchoolResultsTable"); 
        oSearchHTML.removeChild(SearchTable);         
    }
    catch(e){}

    oSearchHTML.appendChild(oTable);                            

}

function GetSchoolInfo(school)
{
    url = "ajaxhandler.aspx?action=getschoolinfo&school=" + school;
    http_request = false;              

    // If window.XMLHttpRequest returns true then were on a Mozilla Safari browser
    if (window.XMLHttpRequest)
    { // Mozilla, Safari,...
        this.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            // set type accordingly to anticipated content type           
            http_request.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject) // If window.ActiveXObject return true then were on a IE Browser
    { // IE
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");  // First try Msxml2.XMLHTTP (newer browsers)
        }
        catch (e)
        {
            try
            {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");  // If not Msxml2.XMLHTTP then try Microsoft.XMLHTTP (most browsers)
            }
            catch (e) {}
        }
    }
    if (!http_request)
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }

    http_request.onreadystatechange = ProcessSchoolResults;
    http_request.open('GET', url, true);     
    http_request.send(null);
    
    return false;

}

function ProcessSchoolResults()
{
    if (http_request.readyState == 4)
    {  

        if (http_request.status == 200)
        {         
            result = http_request.responseText;         
            

            if(result != "")
            {
                document.getElementById("SchoolInfo").innerHTML = result;
                document.getElementById("SchoolInfo").style.left = "40px";
            }
                                                                
        }       
        else 
        { 
            alert("There was a problem with the function 'ProcessSearchResults'.");
        }   
    }
}

function CloseSchoolInfo()
{
    document.getElementById("SchoolInfo").style.left = "-4000px";
    
    return false;    
}

function EditPageSecurity(Type)
{
    var WinLeft = (screen.width / 2)-150;
    var WinTop = (screen.height / 2)-150;
    
    switch(Type)
    {    
      case "PageOwner":      
        SecurityBox = "PageOwner";
        window.open("editpagesecurity.aspx","pageowners","width=750,height=390,top=" + WinTop + ",left=" + WinLeft + ",status=0");
        break;
        
      case "PageAuthor":      
        SecurityBox = "PageAuthor";
        window.open("editpagesecurity.aspx","pageauthors","width=750,height=390,top=" + WinTop + ",left=" + WinLeft + ",status=0");
        break;
        
      case "PageViewer":      
        SecurityBox = "PageViewer";
        window.open("editpagesecurity.aspx","pageviewers","width=750,height=390,top=" + WinTop + ",left=" + WinLeft + ",status=0");
        break;
            
      default:
        break;            
    }
    
    return false;            
}


/* ------------
Login Functions
--------------- */

function GetLoginResults(Username,Password)
{       
    url = "ajaxhandler.aspx?username=" + Username + "&password=" + Password + "&action=login";  
    http_request = false;

    // Combine the parameters into the URL
    //url = url + "?" + parameters;            

    // If window.XMLHttpRequest returns true then were on a Mozilla Safari browser
    if (window.XMLHttpRequest)
    { // Mozilla, Safari,...
        this.http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType)
        {
            // set type accordingly to anticipated content type           
            http_request.overrideMimeType('text/html');
        }                                
    }
    else if (window.ActiveXObject) // If window.ActiveXObject return true then were on a IE Browser
    { // IE         
    
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");  // First try Msxml2.XMLHTTP (newer browsers)
        }
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");  // If not Msxml2.XMLHTTP then try Microsoft.XMLHTTP (most browsers)
            }
            catch (e) {alert('error');}
        }
    }
    if (!http_request)
    {
        alert('Cannot create XMLHTTP instance');
        return false;
    }

    http_request.onreadystatechange = ProcessLoginResults;
    http_request.open('GET', url, true);     
    http_request.send(null);          
}

function ProcessLoginResults()
{              
    if (http_request.readyState == 4)
    {  
        if (http_request.status == 200)
        {         
            result = http_request.responseText;            

            if(result!="")
            {                  
                document.getElementById("MemberOf").value = result;    
                document.getElementById("Password").value = "";                       
                document.getElementById("PageID").value = "2";                         
                document.getElementById("HTMLForm").submit();        
            }
            else
            {
                document.getElementById("LoginError").style.display = "";
                document.getElementById("Password").value = "";
            }                                                                                                                     
        }       
        else 
        { 
            alert("There was a problem with the function 'ProcessLoginResults'.  Please report this error to Computer Services");
        }   
    }
}

function SetOnMenu()
{ 
  //clearTimeout(TimeoutID);

  OnMenu = true;
}

function StartHideMenuTimout()
{                               
    if(!OnMenuTimeout)
    {  
      OnMenuTimeout = true;                                               
      
      TimeoutID = setTimeout("HideMenuHandler()",2000);
    }
    else
    {
        OnMenu = false;
    }                   
}

function HideMenuHandler()
{            
   if(OnMenu == false)
   {
     HideMenus('all');
   }
   
   OnMenuTimeout = false;            
} 

function MenuHandler(pageid,yoffset,parentid)
{                    

    var current_menu_depth = 0;
    var current_menu_numitems = 0;
    
    var parent_menu_ypos = 0;
    
    if(parentid != null)
    {                    
        parent_menu_ypos = parseInt(document.getElementById("menu" + parentid).style.top.replace("px","")) - 10;
    }        
    
    var FoundOne = false;

    for(var i=0; i<=menus.length - 1; i++)
    {                  
        if(menus[i] == "menu" + pageid)
        {                                               
            current_menu_depth = menus_depth[i];
            current_menu_numitems = menus_numitems[i];            
                       
            FoundOne = true;
                       
            break;
        }
    }           
            
    if(FoundOne)
    {
        for(var i=0; i<=menus.length - 1; i++)
        {
            if(menus_depth[i]>=current_menu_depth)                
            {                              
                HideMenus(menus[i]);
            }
        }
    }                     

    if(pageid!=null&&yoffset!=null)
    {               
        var start_offset = 10;
        //var navlink_height = 18;
        var navlink_height = 18;
        var menu_height = current_menu_numitems * navlink_height;
        
        var hovermenu_ypos = (yoffset * navlink_height) + parent_menu_ypos;
        
        // if the menu doesn't exist enclose the "Show Menu" code in try / catch block
        try
        {        
            document.getElementById("menu" + pageid).style.display = "";         	        	    
    	    
    	    if((hovermenu_ypos + menu_height) > 250)
    	    {
    	      hovermenu_ypos = hovermenu_ypos - menu_height + navlink_height;
    	    }
    	    	    	    	   
    	    //hovermenu_ypos = hovermenu_ypos - menu_height + navlink_height;    	        	       	
    	
	        document.getElementById("menu" + pageid).style.top = start_offset + hovermenu_ypos + "px";
	    }
	    catch(e)
	    {
	    }
	    	    	     	    	        
    }    
}

function HideMenus(menuid)
{       
    if(menuid == "all")
    {
        for(var i=0; i<=menus.length - 1; i++)
        {
            document.getElementById(menus[i]).style.display = "none";           
        }
    }
    else
    {
        document.getElementById(menuid).style.display = "none";
    }
}

function doSomething(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
		
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}












