﻿
//    function moveDiv()
//    {
//        var div1 = document.getElementById("menu_div");
//        var tab1 = document.getElementById("table1");
//        var destination = 100;
//        var start = 250;
//        var strStart = start + "px";
//        while (start != destination)
//        {
//            strStart = start + "px";
//            div1.style.top = strStart;
//            wait(1000);
//            start = start - 10;
//        }
//    }

    //future
    function UpdateTicker() {
        var marquee = document.getElementById("marquee1");
        if (marquee != null) {
            //var tickerlink = document.getElementById("hfMarqueeLink");
            var ticker = document.getElementById("hfMarquee");
            //if (tickerlink.value != "") {
                // Add the hyperlink
                //if (ticker.value != "") {
                    //marquee.innerHTML = "<a href='" + tickerlink.value + "'>" + ticker.value + "</a>";
                //}
            //}
            //else {
                // No hyperlink
                if (ticker.value != "") {
                    marquee.innerHTML = ticker.value;
                }
                else {
                    marquee.innerHTML = "empty ticker!";
                }
            //}
            //alert();
        }
    }
    
    function randomnumber(num1, num2) {
        num1 = parseInt(num1);
        num2 = parseInt(num2);
        if (num1 >= num2) {
            return 0; 
        }
        else {
            var generator = Math.random() * (num2 - num1);
            generator = Math.round(num1 + generator);
            return generator;
        }
    }

    
    function pause(iMilliseconds) {
        var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + iMilliseconds + ');';
        window.showModalDialog('javascript:document.writeln ("<script>' + sDialogScript + '<' + '/script>")');
    }
    
    function wait(msecs)
    {
        var start = new Date().getTime();
        var cur = start
        while(cur - start < msecs)
        {
            cur = new Date().getTime();
        }
    }

//    function DisplayFaq(faqnum, e)
//    {
//        var faq = document.getElementById(faqnum);
//        var faq_1 = document.getElementById(faqnum + "_1");
//        var faqquestion1 = document.getElementById("faqquestion");
//        var faqanswer1 = document.getElementById("faqanswer");
//        //var faqdata1 = document.getElementById("faqdata");
//        faqquestion1.innerHTML = faq.value;
//        faqanswer1.innerHTML = faq_1.value;
//        //faqdata1.style.top = mouseY(e)+"px";
//        //faqdata1.style.left = mouseX(e)+"px";
//        setTimeout('document.getElementById("faqdata").style.top = "' + mouseY(e)+ 'px"', 300);
//        setTimeout('document.getElementById("faqdata").style.left = "' + mouseX(e)+ 'px"', 300);
//    }
//    function DisplayFaq2(faqnum, e)
//    {
//        var faq = document.getElementById(faqnum);
//        //var faq_1 = document.getElementById(faqnum + "_1");
//        var faqquestion1 = document.getElementById("faqquestion");
//        var faqanswer1 = document.getElementById("faqanswer");
//        //var faqdata1 = document.getElementById("faqdata");
//        faqquestion1.innerHTML = faq.innerHTML;
//        faqanswer1.innerHTML = faq.value;
//        //faqdata1.style.top = mouseY(e)+"px";
//        //faqdata1.style.left = mouseX(e)+"px";
//        setTimeout('document.getElementById("faqdata").style.top = "' + mouseY(e)+ 'px"', 300);
//        setTimeout('document.getElementById("faqdata").style.left = "' + mouseX(e)+ 'px"', 300);
//    }
//    function DisplayFaq3(question, answer, e)
//    {
//        document.getElementById("faqquestion").innerHTML = question;
//        document.getElementById("faqanswer").innerHTML = answer;
//        setTimeout('document.getElementById("faqdata").style.top = "' + mouseY(e)+ 'px"', 300);
//        setTimeout('document.getElementById("faqdata").style.left = "' + mouseX(e)+ 'px"', 300);
//    }
//    function HideFaq()
//    {
//        //var faqdata1 = document.getElementById("faqdata");
//        setTimeout('document.getElementById("faqdata").style.top = "-200px"', 300);
//        setTimeout('document.getElementById("faqdata").style.left = "-200px"', 300);
//        //faqdata1.style.top = "-200px";
//        //faqdata1.style.left = "-200px";
//    }
//    function mouseX(evt) {
//        if (evt.pageX) return evt.pageX;
//        else if (evt.clientX)
//            return evt.clientX + (document.documentElement.scrollLeft ?
//            document.documentElement.scrollLeft :
//            document.body.scrollLeft);
//        else return null;
//        }
//    function mouseY(evt) {
//        if (evt.pageY) return evt.pageY;
//        else if (evt.clientY)
//            return evt.clientY + (document.documentElement.scrollTop ?
//            document.documentElement.scrollTop :
//            document.body.scrollTop);
//        else return null;
//    }

//    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
//    }
//

    //page functions
    function AddressHasChanged() {
        var lat = document.getElementById("tbLatitude");
        var lon = document.getElementById("tbLongitude");
        lat.value = "";
        lon.value = "";
    }
    function EmailAddressHasChanged() {
        document.getElementById("btnSubmit").disabled = "True";
        document.getElementById("btnSubmitEmail").disabled = "";
        alert("Email Address has changed. Please click the Validate Email button!");
    }
    
    function PayPalMessage() {
	    alert("This will redirect you to PayPal to make a secure donation using your credit card or bank account!");
        return true;
    }

    function leftTrim(sString) {
        while (sString.substring(0, 1) == ' ') {
            sString = sString.substring(1, sString.length);
        }
        return sString;
    }
 
    function rightTrim(sString) {
        while (sString.substring(sString.length - 1, sString.length) == ' ') {
            sString = sString.substring(0, sString.length - 1);
        }
        return sString;
    }

    function allTrim(sString) {
        sString = leftTrim(sString);
        sString = rightTrim(sString);
        return sString;
    }
    
    function WhyCaptcha()
    {
        Window1 = window.open('','whycaptcha','left=20,top=20,width=750,height=300,toolbars=no,resizable=1,scrollbars=0');
        Window1.document.open();
        Window1.document.write("<html><head><title>Why Captcha</title>");
        Window1.document.write("<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />");
        Window1.document.write("<link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" />");
        Window1.document.write("</head><body>");
        Window1.document.write("<center><table width='90%'><tr><td>");
        Window1.document.write("<span class='flashwindowtext'><br>CAPTCHA: 'Completely Automated Public Turing test to tell Computers and Humans Apart'</span><br><br>");
        //Window1.document.write("The term 'CAPTCHA' was coined in 2000 by Luis von Ahn, Manuel Blum, Nicholas J. Hopper (all of Carnegie Mellon University), and John Langford (then of IBM). It is a contrived acronym for 'Completely Automated Public Turing test to tell Computers and Humans Apart'.<br><br>");
        Window1.document.write("Excerpt from the <a href='http://en.wikipedia.org/wiki/Captcha' target='_blank'>Wikipedia article</a> on CAPTCHA:<br>");
        Window1.document.write("A CAPTCHA is a type of challenge-response test used in computing to ensure that the response is not generated by a computer. The process usually involves one computer (a server) asking a user to complete a simple test which the computer is able to generate and grade. Because other computers are unable to solve the CAPTCHA, any user entering a correct solution is presumed to be human. Thus, it is sometimes described as a reverse Turing test, because it is administered by a machine and targeted to a human, in contrast to the standard Turing test that is typically administered by a human and targeted to a machine. A common type of CAPTCHA requires that the user type the letters or digits of a distorted image that appears on the screen.<br><br>");
        Window1.document.write("<br>");
        Window1.document.write("</td></tr></table></center>");
        Window1.document.write("</body></html>");
        Window1.document.close();	
        Window1.focus();
        return false;
    }

    function VerifyFields(form_section)
    {
        var cntrls;
        var cntrlnames;
        var invalid = false;
        var empty;
                
        switch(form_section)
        {
            case "contact":
                cntrls = new Array("tbName", "tbAddress1", "tbAddress2", "tbCity", "ddlState", "tbZipCode", "tbPhone", "tbCell", "tbEmail", "tbMessage", "tbCAPTCHA");
                cntrlnames = new Array("Name", "Address Line 1", "Address Line 2", "City", "State", "Zip Code", "Phone", "Cell", "Email", "Message", "Captcha");
                cntrltype = new Array("other", "other", "other", "other", "other", "other", "phone", "phone", "email", "other", "other");
                empty = new Array("yes", "yes", "", "yes", "yes", "yes", "yes", "", "yes", "", "yes");
                break;    
            case "testimonial":
                break;
            case "submitnews":
                break;
            case "newmember_alt":
                cntrls = new Array("tbAltName", "tbEmailAddress2", "tbPassword2");
                cntrlnames = new Array("Alt Contact Name", "Alt Email Address", "Alt Password");
                cntrltype = new Array("other", "email", "password");
                empty = new Array("yes", "yes", "yes");
                break;
            case "newmember":
            case "updatemember":
                cntrls = new Array("tbAgencyName", "ddlUnitType", "tbAddress1", "tbAddress2", "tbCity", "ddlStates", "tbWebsite", "tbOfficeEmail", "tbPOC", "tbFax", "tbPhone", "tbPhone2", "ddlCountry", "tbZipCode", "tbRemarks", "tbCAPTCHA", "tbYourName", "tbEmailAddress", "tbPassword", "tbLatitude", "tbLongitude");
                cntrlnames = new Array("Agency Name", "Agency Type", "Address Line 1", "Address Line 2", "City", "State", "Website", "Office Email", "Primary Contact Name", "Fax", "Office Phone", "Alt Phone", "Country", "Zip Code", "Remarks", "Captcha", "Your Name", "Your Email Address", "Your Password", "Latitude", "Longitude");
                cntrltype = new Array("other", "other", "other", "other", "other", "other", "website", "email", "other", "phone", "phone", "phone", "other", "other", "other", "other", "other", "email", "password", "number", "number");
                empty = new Array("yes", "yes", "yes", "no", "yes", "yes", "no", "yes", "yes", "no", "yes", "no", "yes", "yes", "no", "yes", "yes", "yes", "yes", "no", "no");
                break;
            case "updateagencymanagement":
                cntrls = new Array("tbAgencyName", "ddlUnitType", "tbAddress1", "tbAddress2", "tbCity", "ddlStates", "tbWebsite", "tbOfficeEmail", "tbFax", "tbPhone", "tbPhone2", "ddlCountry", "tbZipCode", "tbRemarks", "tbCAPTCHA", "tbLatitude", "tbLongitude");
                cntrlnames = new Array("Agency Name", "Agency Type", "Address Line 1", "Address Line 2", "City", "State", "Website", "Office Email", "Fax", "Office Phone", "Alt Phone", "Country", "Zip Code", "Remarks", "Captcha", "Latitude", "Longitude");
                cntrltype = new Array("other", "other", "other", "other", "other", "other", "website", "email", "phone", "phone", "phone", "other", "other", "other", "other", "number", "number");
                empty = new Array("yes", "yes", "yes", "no", "yes", "yes", "no", "yes", "no", "yes", "no", "yes", "yes", "no", "yes", "no", "no");
                break;
            case "tickermanagement":
                cntrls = new Array("tbMessage", "tbHyperlink", "tbCAPTCHA");
                cntrlnames = new Array("Ticker Message", "Ticker Hyperlink", "Captcha");
                cntrltype = new Array("allchars", "website", "other");
                empty = new Array("yes", "no", "yes");
                break;
            case "mailmanagement":
                cntrls = new Array("tbMailText", "tbMailDate", "tbCAPTCHA");
                cntrlnames = new Array("Mail Text", "Mail Date", "Captcha");
                cntrltype = new Array("allchars", "date", "other");
                empty = new Array("no", "yes", "yes");
                break;
            case "emailmanagement":
                cntrls = new Array("tbName", "tbEmail", "tbPosition", "tbPhone", "tbCAPTCHA");
                cntrlnames = new Array("Full Name", "Email Address", "Position/Description", "Phone/Future", "Captcha");
                cntrltype = new Array("other", "email", "allchars", "other", "other");
                empty = new Array("yes", "yes", "yes", "no", "yes");
                break;
            case "searchmanagement":
                cntrls = new Array("tbCityState", "tbHyperlink", "tbDiagnosis", "tbRecoveryTime", "tbSearchDate", "tbCAPTCHA");
                cntrlnames = new Array("Search City/State", "Search Hyperlink", "Search Diagnosis", "Search Recovery Time", "Search Date", "Captcha");
                cntrltype = new Array("other", "website", "other", "time", "date", "other");
                empty = new Array("yes", "no", "yes", "yes", "yes", "yes");
                break;
            case "newsmanagement":
            	// textbox does not work with the empty field set. It always reports that the field is empty.
                cntrls = new Array("tbSource", "tbMoreInfo", "tbBlurb", "tbArticle", "tbPictureLink", "tbCAPTCHA");
                cntrlnames = new Array("Article Source", "Article More Info", "Article Blurb", "Article Text", "Picture Link", "Captcha");
                cntrltype = new Array("other", "other", "allchars", "allchars", "website", "other");
                empty = new Array("yes", "no", "no", "no", "no", "yes");
                break;
            case "afteraction":
                cntrls = new Array("tbOtherCount", "tbAutCount", "tbAlzCount", "tbAgencyCount", "ddlCondition", "tbDistanceFromWater", "ddlAreaFound", "tbReportDate", "tbMissionDate", "ddlMission", "tbClientNum", "tbSubjectAge", "ddlSex", "ddlDiagnosis", "tbMissionLocation", "tbMissionSubjects", "tbUnitNotifiedBy", "tbNotified", "tbArrived", "tbRecovered", "tbCleared", "tbMembersInvolved", "tbOthersInvolved", "tbCAPTCHA", "tbNarrative", "tbDistanceFound", "tbDistanceFromRoad", "tbWeather", "tbTemperature");
                cntrlnames = new Array("Other count", "Autism count", "Alzheimer's count", "Agency's Total Client Count", "Subject's overall condition", "Distance from water", "Type of area found", "Today's Date", "Mission Date", "Was This a Lifesaver Mission", "Client Number", "Subject's Age", "Subject's Sex", "Diagnosis", "Mission Location", "Mission Subjects", "Notified By", "Time Notified", "Time Arrived", "Time Recovered", "Time Cleared", "Members Involved", "Others Involved", "Captcha", "Narrative", "Distance Found From Last Seen", "Distance Found From Road", "Weather", "Temperature");
                cntrltype = new Array("number", "number", "number", "number", "other", "other", "other", "date", "date", "other", "other", "number", "other", "other", "other", "other", "other", "time", "time", "time", "time", "other", "other", "other", "other", "other", "other", "other", "other");
                empty = new Array("yes", "yes", "yes", "yes", "yes", "no", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "no", "yes", "yes", "yes", "no", "yes", "yes");
                break;
            case "afteraction_airunit":
                cntrls = new Array("ddlWing", "tbAircraftAgency", "tbACNotified", "tbACArrived", "tbACCleared", "tbAircrew1", "tbAircrew2");
                cntrlnames = new Array("", "Aircraft Agency", "Aircraft Time Notified", "Aircraft Time Arrived", "Aircraft Time Cleared", "Air Crew 1", "Air Crew 2");
                cntrltype = new Array("other", "other", "time", "time", "time", "other", "other");
                empty = new Array("yes", "yes", "yes", "yes", "yes", "yes", "no");
                break;
            case "webreports":
                cntrls = new Array("tbStartDate", "tbEndDate");
                cntrlnames = new Array("Start Date", "End Date");
                cntrltype = new Array("date", "date");
                empty = new Array("yes", "yes");
                break;
        }
        var i=0;
        for (i=0; i<=cntrls.length-1; i++)
            {
                var cntrl1 = document.getElementById(cntrls[i]);
                
                //make sure the developer did not make a mistake
                if (cntrl1 == null)
                {
                    alert(cntrlnames[i] + " field does not exist! Will ignore!!");
                    return true;
                }
                
                //check for blank field first. if found return immediately
                if (empty[i] == "yes" && cntrl1.value == "")
                {
                    Alert3(cntrlnames[i]);
                    return false;
                }
                
                //check for password fields. handle them differently.
                if (cntrltype[i] == "password")
                {
                    if(!Validate_Password(cntrl1.value))
                    {
                        Alert4(cntrlnames[i]);
                        return false;
                    }
                }
                
                //check for invalid characters. if found make a note of it and continue verification
                if (cntrltype[i] == "email")
                {
                    //check email address
                    if(!Validate_Email_Address(cntrl1.value))
                    {
                        if (!invalid)
                        {
                            invalid = true;            
                        }    
                    }
                }
                else
                {
                    if(!Validate_String(cntrltype[i], cntrl1.value, false))
                    {
                        if (!invalid)
                        {
                            Alert2(cntrlnames[i],Validate_String(cntrltype[i], cntrl1.value, true));
                            invalid = true;            
                        }    
                    }
                }
            }
            
        //now check to see if we found any invalid characters above. If so ask them if they want to submit anyway.    
        if (invalid)
        {
            if (confirm('Do you want to include the invalid characters in your post? (Click Ok to continue or Cancel to go back and fix the problem)'))
            {
                return(true);                     
            }
            else
            {
                return(false);                     
            }
        }
        else
        {
            return true;
        }    
    }

//    function unLoadMe() {
//        //not used
//        var rtn = confirm("You changed some of the information on this form. If you continue, these changes will be lost. Do you want to continue?");
//        if (rtn == true) {
//            return true;
//        }
//        if (rtn == false) {
//            return false;
//        }
//    }
//
    function fieldFocus(cntrl) {
        document.getElementById(cntrl).focus();
        document.getElementById(cntrl).select();
    }

    function Thanks()
    {
        if (document.getElementById("hfSubmitted").value == "yes")
        alert("Thanks. The information you submitted has been saved!");
    
        if (document.getElementById("hfSubmitted").value == "update")
        alert("Thanks. The information you submitted has been updated!");

        if (document.getElementById("hfSubmitted").value == "delete")
        alert("Thanks. The selected item was deleted!");
    
        if (document.getElementById("hfSubmitted").value == "new")
        alert("Thanks. The page has been cleared and you can now add a new item!");

        if (document.getElementById("hfSubmitted").value == "updateagency")
        alert("Thanks. Your information has been updated! Your agency's data will be verified before posting!");

        if (document.getElementById("hfSubmitted").value == "updateagencymanagement")
        alert("Thanks. The agency information has been updated!");

        if (document.getElementById("hfSubmitted").value == "deleteagencymanagement")
        alert("Thanks. The agency information has been deleted!");

        if (document.getElementById("hfSubmitted").value == "report")
        alert("Thanks. Your report has been submitted!");

        if (document.getElementById("hfSubmitted").value == "actionreport")
        alert("Thanks. Your report has been submitted! A copy of this report has been emailed to your address.");

    document.getElementById("hfSubmitted").value = "";
    }
    
    function ThanksNewMember()
    {
        if (document.getElementById("hfNewMember").value == "yes")
        alert("Thanks. Your new member account has been created! Please check your email for a validation message.");
    
        if (document.getElementById("hfNewMember").value == "valid")
        alert("Thanks. Your new member account has been validated! You may now login to your account.");
    }
    
    function Alert2(str, invalid)
    {
        alert("Please review the " + str + " field for invalid characters! " + "(" + invalid + ")");
    }
    function Alert3(str)
    {
        alert(str + " field cannot be empty!");
    }
    function Alert4(str)
    {
        alert(str + " field must be at least 4 characters!");
    }
    
    function Validate_String(type, string, return_invalid_chars)
        //used by ValidEmailAddress() and VerifyFields()
         {
         
         switch (type)
         {
            case "email":
                valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                invalid_chars = '';
                break;
            case "phone":
                valid_chars = '1234567890-()+';
                invalid_chars = '';
                break;
            case "date":
                valid_chars = '1234567890/-.';
                invalid_chars = '';
                break;
            case "time":
                valid_chars = '1234567890:APM ';
                invalid_chars = '';
                break;
            case "number":
                valid_chars = '1234567890.-+';
                invalid_chars = '';
                break;
            case "website":
                valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:/\\';
                invalid_chars = '';
                break;
            case "allchars":
                valid_chars = ' ~!@#$%^&*()_+`1234567890-={}|[]\\:";\'<>?,./abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                invalid_chars = '';
                break;
            case "other":
                valid_chars = ' \'1234567890-_.@#$%&*()^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,';
                invalid_chars = '';
                break;    
         }

         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }

    function Validate_Password(password)
        {
            //for now we will just check for length. must be 4 chars or more
            if (password.length < 4)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        
    function Validate_Email_Address(email_address)
         {
             //Assumes that valid email addresses consist of user_name@domain.tld
             at = email_address.indexOf('@');
             dot = email_address.indexOf('.');

             //First.Last causes a problem with this logic.
             //Changed logic to allow for First.Last
//            if (at == -1 ||
//            dot == -1 ||
//            dot <= at + 1 ||
//            dot == 0 ||
//            dot == email_address.length - 1) {
//                alert("Enter a valid email address before continuing!");
//                return (false);
//            }

            if (at == -1 ||
            dot == -1 ||
            dot == 0 ||
            dot == email_address.length - 1) {
                alert("Enter a valid email address before continuing!");
                return (false);
            }
            user_name = email_address.substr(0, at);
            domain_name = email_address.substr(at + 1, email_address.length);                  
         
             if(!Validate_String("email", user_name, false))
             //if(Validate_String("email", user_name, true) === false)
                {
                Alert2("email", Validate_String("email", user_name, true));
                return(false);                     
                }
              
             if(!Validate_String("email", domain_name, false))
             //if (Validate_String("email", domain_name, true) === false)
                {
                Alert2("email", Validate_String("email", domain_name, true));
                return(false);                     
                }
             
             return(true);
             }

    function AreYouSure(str)
    {
        if (str == "")
        {
            str = "item";
        }
        if (confirm('Are you sure you want to delete this ' + str + '? (Click Ok to delete or Cancel to go back)'))
        {
            if (confirm('Again, Are you sure you want to delete this ' + str + '? (Click Ok to delete or Cancel to go back)'))
            {
                return true;    
            }
            else
            {
                alert("Delete Cancelled!");
                return false;
            }
        }
        else
        {
            alert("Delete Cancelled!");
            return false;
        } 
    }
    
    function SaveFlashCookie()
    {
        createCookie("flash_width", document.body.offsetWidth, 365);
        createCookie("flash_height", document.body.offsetHeight, 365);
        alert("Flash Size Saved!");
    }
    
    function DisplayFlash(movie)
    {
        var winwidth = 160; //default
        var winheight = 240; //default
        var fwidth = "100%";
        var fheight = "95%";
        var cookieWidth = readCookie("flash_width");
        if (cookieWidth)
        {
            winwidth = cookieWidth;
        }
        var cookieHeight = readCookie("flash_height");
        if (cookieHeight)
        {
            winheight = cookieHeight;
        }
        flashWindow = window.open('','flash','left=20,top=20,width='+ winwidth + ',height=' + winheight + ',toolbars=no,resizable=1,scrollbars=0');
        flashWindow.document.open();
        flashWindow.document.write("<html><head><title>Flash Player</title>");
        flashWindow.document.write("<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />");
        flashWindow.document.write("<link href=\"default.css\" rel=\"stylesheet\" type=\"text/css\" />");
        //flashWindow.document.write("<script language=\"JavaScript1.2\" src=\"PLS_Functions.js\" type=\"text/javascript\"></script>");
        flashWindow.document.write("<script type=\"text/javascript\">");
        flashWindow.document.write("function SaveFlashCookie2(){");
        flashWindow.document.write("createCookie(\"flash_width\", document.body.offsetWidth, 365);");
        flashWindow.document.write("createCookie(\"flash_height\", document.body.offsetHeight, 365);");
        //flashWindow.document.write("alert(document.body.offsetWidth + \"--\" + document.body.offsetHeight + \" Flash Size Saved!\");}");
        flashWindow.document.write("alert(\"Flash Size Saved!\");}");
        flashWindow.document.write("function createCookie(name,value,days) {");
	    flashWindow.document.write("if (days) {");
		flashWindow.document.write("    var date = new Date();");
		flashWindow.document.write("    date.setTime(date.getTime()+(days*24*60*60*1000));");
		flashWindow.document.write("    var expires = \"; expires=\"+date.toGMTString();");
	    flashWindow.document.write("}");
	    flashWindow.document.write("else var expires = \"\";");
	    flashWindow.document.write("document.cookie = name+\"=\"+value+expires+\"; path=/\";");
        flashWindow.document.write("}");
        flashWindow.document.write("</script>");
        flashWindow.document.write("</head><body>");
        flashWindow.document.write("<center><span class='flashwindowtext'>I am resizable!&nbsp;&nbsp;<input type='button' value='Save' onclick='SaveFlashCookie2();' /></span><br>");
        flashWindow.document.write("<object id='flash1' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='" + fwidth + "' height='" + fheight + "'>");
        flashWindow.document.write("<param name='MOVIE' value='" + movie + "'>");
        flashWindow.document.write("<param name='QUALITY' value='HIGH'>");
        flashWindow.document.write("<param name='BGCOLOR' value='#000000'>");
        flashWindow.document.write("<embed id='flash1' src='" + movie + "' quality='high' type='application/x-shockwave-flash' bgcolor='#000000' width='" + fwidth + "' height='" + fheight + "'>");
        flashWindow.document.write("</object>");
        flashWindow.document.write("</center>");
        flashWindow.document.write("</body></html>");
        flashWindow.document.close();	
        flashWindow.focus();
        return false;
    }
    function DisplayFlash2(movie) {
        var winwidth = 160; //default
        var winheight = 240; //default
        var fwidth = "100%";
        var fheight = "100%";
        var cookieWidth = readCookie("flash_width2");
        if (cookieWidth) {
            winwidth = cookieWidth;
        }
        var cookieHeight = readCookie("flash_height2");
        if (cookieHeight) {
            winheight = cookieHeight;
        }
        flashWindow = window.open("jwvideoplayer/FlashPlayer.aspx?movie=" + movie, "flash", "left=20,top=20,width=" + winwidth + ",height=" + winheight + ",toolbars=no,resizable=1,scrollbars=0");
        flashWindow.focus();
        return false;
    }

    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);
    }


    //page management functions
//    function InsertFlash(imageflag)
//    {
//        flashWindow = window.open('insertflash.aspx','flash','left=20,top=20,width=500,height=500,toolbars=no,resizable=1,scrollbars=1');
//        //flashWindow.document.open();
//        //flashWindow.document.write("");
//        //flashWindow.document.close();	
//        flashWindow.focus();
//    }
    function SaveFlash(html)
    {
        FTB_API["ftb1"].InsertHtml(html);
    }
    function AddEvent1()
    {
    FTB_AddEvent(ftb1, 'change', ftb_KeyDown, true);
    }
    function addEvent(obj, evType, fn)
    { 
        if (obj.addEventListener){ 
            obj.addEventListener(evType, fn, false); 
            return true; 
        }
        else if (obj.attachEvent){ 
            var r = obj.attachEvent("on"+evType, fn); 
            return r; 
        }
        else { 
            return false; 
        } 
    }
    function ftb_MouseOver()
    {
        //alert("MouseOver");
    }
    function ftb_TextChanged2()
    {
        alert("TextChanged");
    }
    function ftb_ProcessText()
    {
        alert("ProcessText");
    }
    function ftb_KeyDown()
    {
        alert("KeyDown");
    }
    function ftbPreviewNow2()
    {
       //ftbControl.ftb.Preview();
       	var ftb1 = document.getElementById("ftb1");
       	var tb1 = document.getElementById("tbHeaderText");
       	
       	//ftb1.CopyDesignToHtml();
        printWindow = window.open('','preview','left=20,top=20,width=748,height=600,toolbars=no,resizable=0,scrollbars=1');
        printWindow.document.open();
        //printWindow.document.write("<html><head><link rel='stylesheet' href='" + ftbControl.designModeCss + "' type='text/css' />" + ((ftbControl.baseUrl != '') ? "<base href='" + ftbControl.baseUrl + "' />" : "") + "</head><body>" + ftbControl.htmlEditor.value + "</body></html>");
        printWindow.document.write("<html><head><link rel=stylesheet href=" + ftb1.designModeCss + " type=text/css />");
        printWindow.document.write(((ftb1.baseUrl != '') ? "<base href=" + ftb1.baseUrl + " />" : "") + "</head>");
        printWindow.document.write("<body>");
        printWindow.document.write("<strong><span style=font-size: 14pt><font color=#006400>" + tb1.value + "</font></span></strong><br>");
        printWindow.document.write(ftb1.value + "</body></html>");
        printWindow.document.close();	
        printWindow.focus();
        //var myRef;
        //myRef = window.open('', 'mywin', 'left=20,top=20,width=525,height=550,status=0,toolbar=0,menubar=0,location=0,directories=0,resizable=1,scrollbars=1');
        //myRef.focus();            
    }
    function ftbPreviewNow(tbName)
    {
        var ftb1 = document.getElementById("ftb1");
       	var tb1 = document.getElementById(tbName);
       	
       	//ftb1.CopyDesignToHtml();
        printWindow = window.open('','preview','left=20,top=20,width=748,height=600,toolbars=no,resizable=0,scrollbars=1');
        printWindow.document.open();
        //printWindow.document.write("<html><head><link rel='stylesheet' href='" + ftbControl.designModeCss + "' type='text/css' />" + ((ftbControl.baseUrl != '') ? "<base href='" + ftbControl.baseUrl + "' />" : "") + "</head><body>" + ftbControl.htmlEditor.value + "</body></html>");
        printWindow.document.write("<html><head><link rel=stylesheet href=" + ftb1.designModeCss + " type=text/css />");
        printWindow.document.write(((ftb1.baseUrl != '') ? "<base href=" + ftb1.baseUrl + " />" : "") + "</head>");
        printWindow.document.write("<body>");
        //printWindow.document.write("<strong><span style=font-size: 14pt><font color=#006400>" + tb1.value + "</font></span></strong><br>");
        printWindow.document.write(tb1.value + "</body></html>");
        printWindow.document.close();	
        printWindow.focus();
        
        return false;
    }
    function noFocus()
    {
       FTB_API['ftb1'].Focus();
       alert("You cannot enter text directly into the sections. Use the main control!!!");
    }
    function OpenWin(winloc)
    {
        var myRef;
        myRef = window.open(winloc, 'mywin', 'left=20,top=20,width=525,height=550,status=0,toolbar=0,menubar=0,location=0,directories=0,resizable=1,scrollbars=1');
        myRef.focus();            
    }
    function OpenWin2(winloc, name, width, height)
    {
        var myRef;
        myRef = window.open(winloc, name, 'left=20,top=20,width=' + width + ',height=' + height + ',status=0,toolbar=0,menubar=0,location=0,directories=0,resizable=1,scrollbars=1');
        myRef.focus();            
    }
    function DeleteConfirm(myID)
    {
        var val1 = document.getElementById(myID).options[document.getElementById(myID).selectedIndex].text
        var answer = window.confirm("Are you sure you want to delete the page named: " + val1 + "?");
        if (answer == true)
            {
                answer = window.confirm("Again... Are you sure you want to delete the page named: " + val1 + "?");
                if (answer == true)
                    {
                    return true;
                    }
                else
                    {
                    alert("Delete Cancelled!");
                    return false;
                    }    
            }
        else
            {
                alert("Delete Cancelled!");
                return false;
            }
    }
    function CopyToTB(myID)
    {
        var ftb1 = document.getElementById("ftb1");
        var tb = document.getElementById(myID);
        if (tb.disabled)
        {
            alert("This section not available with this page type!");
        }
        else
        {
            if (confirm("This will overwrite all data in the section! Is this OK?"))
            {
                tb.value = ftb1.value;
                alert("Copy Complete!");
            }
            else
            {
                alert("Copy Cancelled!");
            }    
        }
    }
    function CopyToTB_tiny(myID) {
        var tb = document.getElementById(myID);
        if (tb == null) {
            return
        }
        if (tb.disabled) {
            alert("This section not available with this page type!");
        }
        else {
            if (confirm("This will overwrite all data in the section! Is this OK?")) {
                //tb.value = tinyMCE.get('elm1').getContent();
                tb.value = tinyMCE.activeEditor.getContent();
                alert("Copy Complete!");
            }
            else {
                alert("Copy Cancelled!");
            }
        }
    }
    
    function CopyFromTB(myID) //not used
    {
        var ftb1 = document.getElementById("ftb1");
        var tb = document.getElementById(myID);
        if (tb.disabled)
        {
            alert("This section not available with this page type!");
        }
        else
        {
            ftb1.value = tb.value;
            alert("Copy Complete!");
        } 
    }
    function CopyFromTB2(myID, ftbControl)
    {
        var tb = document.getElementById(myID);
        if (tb.disabled)
        {
            alert("This section not available with this page type!");
        }
        else
        {
            //ftbControl.ftb.DeleteContents();
            if (confirm('Would you like to clear the editor before pasting? (Click Ok to clear or Cancel to paste at current cursor location)'))
            {	
    	        ftbControl.ftb.designEditor.document.body.innerHTML = '';
	            ftbControl.ftb.htmlEditor.value='';
	            ftbControl.ftb.GoToDesignMode();
            }
            else
            {
            
            }
            //ftbControl.ftb.InsertHtml(tb.value); either work!!!
            FTB_API[ftbControl.ftb.id].InsertHtml(tb.value);
            alert("Copy Complete!");
        } 
    }
    function CopyFromTB2_tiny(myID) {
        var tb = document.getElementById(myID);
        if (tb == null) {
            return
        }
        if (tb.disabled) {
            alert("This section not available with this page type!");
        }
        else {
            if (confirm('Would you like to clear the editor before pasting? (Click Ok to clear or Cancel to paste at current cursor location)')) {
                //ftbControl.ftb.designEditor.document.body.innerHTML = '';
                //ftbControl.ftb.htmlEditor.value = '';
                //ftbControl.ftb.GoToDesignMode();
                //tinyMCE.get('elm1').execCommand('mceClearContents');
                tinyMCE.activeEditor.setContent('');
                //tinyMCE.get('elm1').setContent('');
            }
            else {

            }
            //ftbControl.ftb.InsertHtml(tb.value); either work!!!
            //FTB_API[ftbControl.ftb.id].InsertHtml(tb.value);
            tinyMCE.activeEditor.execCommand('mceInsertContent', false, tb.value);
            //tinyMCE.get('elm1').execCommand('mceInsertContent', false, tb.value);
            alert("Copy Complete!");
        }
    }

    function mvMenuDiv() {

        // Set the top div to a positive height if we are using the horizontal menu. Set to 0 if not.
        //var headerdiv = document.getElementById("headerdiv"); //table row at top of screen where menu2 ends up
        if (document.body.offsetWidth < 985) //allow for scroll bars
        {
            var headerdiv = document.getElementById("headerdiv");
            //headerdiv.style.height = "30px";
            headerdiv.style.height = "115px";
        }
        else {
            var headerdiv = document.getElementById("headerdiv");
            //headerdiv.style.height = "0px";
            headerdiv.style.height = "85px";
        }
        
        //Comment out the next two lines to shutoff the menu animation without changing any other pages
        //This function is in jsmovingdiv.js (moved to bottom of this function)
        //mvMenuDivAnimate();
        //return;

        //Displays the correct menu based on the width of the screen
        var menudiv = document.getElementById("menudiv"); //vertical menu
        var menudiv2 = document.getElementById("menudiv2"); //horizontal menu
        var table1 = document.getElementById("table1");
        if (document.body.offsetWidth < 985) //allow for scroll bars
        {
            menudiv.style.top = -200 + "px";
            menudiv.style.left = -200 + "px";
            menudiv2.style.top = "85px";
            if (document.body.offsetWidth < menudiv2.offsetWidth) {
                menudiv2.style.left = "0px";
            }
            else {
                //menudiv2.style.left = "115px";
                menudiv2.style.left = "0px"; 
                //((document.body.offsetWidth - menudiv2.offsetWidth) / 2) + "px";
            }
        }
        else {
            menudiv2.style.top = -200 + "px";
            menudiv2.style.left = -200 + "px";
            menudiv.style.top = "180px";
            menudiv.style.left = ((document.body.offsetWidth - 748) / 2) - menudiv.offsetWidth - 20 + "px";
        }
    }

    //Include the jsmovingdiv.js file into this file
    //var head = document.getElementsByTagName('head');  //[0];
    //script = document.createElement('script');
    //script.src = "jsmovingdiv.js";
    //script.type = 'text/javascript';
    //head.appendChild(script);

    //Contents of jsmovingdiv.js file
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    // Setup the vars for establishing the base location
    // The first section can be changed in code to control usage
    var baseLeft = 20;
    var baseTop = 5;
    var baseHeight = 30; // should be a little larger than the div height
    var pStr = "px";
    var baseZindex = 30;
    var movingZindex = 1000;
    var movingLeft = 40; //jog to the right while moving should be more than baseLeft
    var movingBackColor = "#006AD5"; //background color while moving
    var completedBackColor = ""; //background color after moving (can be blank. blank would use the default page background)
    var anispeed1 = "25"; //speed of animation up
    var anispeed2 = "25"; // speed of animation for all others down
    var numDivs = 30;  //number of divs in the collection
    var cntrlprefix = "img-"; //prefix used for the control that controls the moving
    var moveAlertMsg = "Move to Top complete!"; //set to anything if you want an alert when the move is complete
    var steplength = "1"; //length of movement upwards while moving
    var destControl = "hfSortedResults"; //destination control we will write the resulting ordered list
    //////////////////////////////////////////////////////////////////////////////////////////////////////

    // Setup the global control arrays
    var cntrls = new Array(); //names
    var cntrls_top = new Array(); //top values
    var cntrls_loc = new Array(); //ordered list

    // Setup the global vars for controlling the timer
    var stopFlag = false;
    var animateProcessID = "";
    var processdiv = "";
    var processdivIndex;
    var otherdivIndex;
    var processStart;
    var processFinish;
    var processLeft;

    // Setup the div name arrayand the initial ordered list
    for (var i = 0; i <= numDivs - 1; i++) {
        cntrls[i] = "div_" + i;
        cntrls_loc[i] = "div_" + i;
    }

    // Setup the div top values
    cntrls_top[0] = baseTop;
    for (var i = 1; i <= numDivs - 1; i++) {
        cntrls_top[i] = cntrls_top[i - 1] + baseHeight;
    }

    // Place the divs based on the default locations (page init)
    function initDivs() {
        for (var i = 0; i <= numDivs - 1; i++) {
            if (i == 0) {
                var controller = document.getElementById(cntrlprefix + cntrls[i]);
                if (controller) {
                    controller.disabled = "true";
                }
            }
            var cntrl = document.getElementById(cntrls[i]);
            if (cntrl) {
                cntrl.style.top = cntrls_top[i] + pStr;
                cntrl.style.left = baseLeft + pStr;
                cntrl.style.zindex = baseZindex;
                showVals(cntrl);
            }
        }
    }

    function moveDivToTop(cntrl) {

        //Only one move allowed at a time.
        if (animateProcessID != "") {
            return;
        }

        // cntrl is the image or button clicked to activate the move
        cntrl.disabled = "true";
        // its parent contains the name of the div to move to the top
        var divtomove = document.getElementById(cntrl.parentNode.id);
        // First off is the div already at the top?
        if (divtomove.style.top != baseTop + pStr) {
            // ok we can move this one
            // Figure out which one this is.
            var divIndex = -1;
            for (var i = 0; i <= numDivs - 1; i++) {
                if (divtomove.id == cntrls_loc[i]) {
                    divIndex = i;
                }
            }
            divtomove.style.backgroundColor = movingBackColor;

            // Move it to the top
            processStart = cntrls_top[divIndex];
            processFinish = baseTop;
            processdiv = divtomove;
            processdivIndex = divIndex;
            processLeft = baseLeft;
            if (animateProcessID == "") {
                animateProcessID = setInterval('animateDiv()', anispeed1);
            }
            cntrls_top[divIndex] = baseTop;
        }
        else {
            alert("this div is already at the top");
            return;
        }
    }

    function animateDiv() {
        processdiv.style.zIndex = movingZindex;

        //Jog to the right and down first.
        if (processLeft < movingLeft) {
            processLeft = processLeft + 1;
            processdiv.style.left = processLeft + pStr;
            processdiv.style.top = (processStart + processLeft - baseLeft) + pStr;
            if (processLeft == movingLeft) {
                processStart = processStart + processLeft - baseLeft + 5;
            }
            return;
        }

        //Ok now move up.
        processStart = processStart - steplength;
        processdiv.style.top = processStart + pStr;
        processdiv.style.left = movingLeft + pStr;
        showVals(processdiv);

        if (processStart <= processFinish) {
            stopFlag = true;
            clearInterval(animateProcessID);
            animateProcessID = "";
            processdiv.style.top = baseTop + pStr;
            processdiv.style.left = baseLeft + pStr;
            processdiv.style.zIndex = baseZindex;
            processdiv.style.backgroundColor = completedBackColor;
            showVals(processdiv);
            otherdivIndex = 0;
            animateProcessID = setInterval('animateOthers()', anispeed2);
        }
    }
    function animateOthers() {
        // Now move all the ones that were above it down.
        // The divs that were below it do not need to move.
        var cntrl2 = document.getElementById(cntrls_loc[otherdivIndex]);
        cntrls_top[otherdivIndex] = cntrls_top[otherdivIndex] + baseHeight;
        cntrl2.style.top = cntrls_top[otherdivIndex] + pStr;
        cntrl2.style.left = baseLeft;
        // Set the image/button enabled
        var cntrl_activator = document.getElementById(cntrlprefix + cntrls_loc[otherdivIndex]);
        if (cntrl_activator) {
            cntrl_activator.disabled = "";
        }
        showVals(cntrl2);

        otherdivIndex = otherdivIndex + 1;
        if (otherdivIndex == processdivIndex) {
            clearInterval(animateProcessID);
            animateProcessID = "";
            cleanUp();
        }

    }
    function cleanUp() {
        // Now reorder the list of locations
        // The moved control needs to be moved to the 0 index
        for (var i = processdivIndex; i > 0; i--) {
            cntrls_loc[i] = cntrls_loc[i - 1];
            cntrls_top[i] = cntrls_top[i - 1];
        }
        cntrls_loc[0] = processdiv.id;
        cntrls_top[0] = baseTop;

        //Update the destination control with the sorted list
        var destCntrl = document.getElementById(destControl);
        if (destCntrl) {
            destCntrl.value = "";
            for (var i = 0; i <= numDivs - 1; i++) {
                destCntrl.value = destCntrl.value + cntrls_loc[i] + ";";
            }
        }

        if (moveAlertMsg != "") {
            alert(moveAlertMsg);
        }
    }

    function showVals(cntrl) {
        // For testing only!!!
        // update the values for the top and left of each div moved.
        // create controls named: tbTop-div_0 & tbLeft-div_0 & tbZIndex-div_0
        //    var tbtop = document.getElementById("tbTop-" + cntrl.id);
        //    var tbLeft = document.getElementById("tbLeft-" + cntrl.id);
        //    var tbZIndex = document.getElementById("tbZIndex-" + cntrl.id);
        //    tbtop.value = cntrl.style.top;
        //    tbLeft.value = cntrl.style.left;
        //    tbZIndex.value = cntrl.style.zIndex;
    }

    /////////////////////////////////////////////////////////////////////////////////////
    var singledivtopstart;
    var singledivtopend;
    var singledivleftstart;
    var singledivleftend;
    var singleprocessdiv = "";
    var singleanimateProcessID = "";

    function mvMenuDivAnimate() {
        //Only one at a time
        if (singleanimateProcessID == "") {

            //alert("start animation");
            anispeed1 = "5";
            //Displays the correct menu based on the width of the screen
            var menudiv = document.getElementById("menudiv"); //vertical menu
            var menudiv2 = document.getElementById("menudiv2"); //horizontal menu
            var table1 = document.getElementById("table1");
            if (document.body.offsetWidth < 985) //allow for scroll bars
            {
                //Check to see if the menu is already there
                if (menudiv2.style.top != "0px") {
                    //alert(menudiv2.style.top);
                    menudiv.style.top = -200 + "px";
                    menudiv.style.left = -200 + "px";
                    singledivtopstart = 100;
                    singledivtopend = 0;
                    singledivleftstart = 10;
                    singleprocessdiv = "menudiv2";
                    

                    if (document.body.offsetWidth < menudiv2.offsetWidth) {
                        singledivleftend = 0;
                        singleanimateProcessID = setInterval('animateSingleDiv()', anispeed1);
                    }
                    else {
                        singledivleftend = (document.body.offsetWidth - menudiv2.offsetWidth) / 2;
                        singleanimateProcessID = setInterval('animateSingleDiv()', anispeed1);
                    }
                }
            }
            else {
                if (menudiv.style.top != "180px") {
                    menudiv2.style.top = -200 + "px";
                    menudiv2.style.left = -200 + "px";
                    singledivtopstart = 80;
                    singledivtopend = 180;
                    singledivleftstart = 0;
                    singledivleftend = Math.round((document.body.offsetWidth - 748) / 2) - menudiv.offsetWidth - 5;
                    singleprocessdiv = "menudiv";
                    singleanimateProcessID = setInterval('animateSingleDiv()', anispeed1);
                }
            }
        }
    }

    function moveSingleDiv(divname) {
        //Move only one div at a time 
        if (singleanimateProcessID == "") {
            singleprocessdiv = divname;
            singleanimateProcessID = setInterval('animateSingleDiv()', anispeed1);
        }
    }

    function animateSingleDiv() {
        //vars we can set before or during the move
        //pStr = "px";
        //baseZindex = 30;
        //movingZindex = 1000;
        //movingBackColor = "#006AD5"; //background color while moving
        //completedBackColor = ""; //background color after moving (can be blank. blank would use the default page background)
        //anispeed1 = "25"; //speed of animation
        //moveAlertMsg = "Move to Top complete!"; //set to anything if you want an alert when the move is complete
        //steplength = "1"; //length of movement upwards while moving

        var movetop = singledivtopend - singledivtopstart;
        if (movetop == 0) {
            //We are not moving up or down
            singledivtopstart = singledivtopstart;
        }
        if (movetop > 0) {
            //We are moving down
            singledivtopstart = singledivtopstart + 1;
        }
        if (movetop < 0) {
            //We are moving up
            singledivtopstart = singledivtopstart - 1;
        }
        
//        if (movetop < 0) {
//            //We are moving up
//            singledivtopstart = singledivtopstart - 1;
//        }
//        else {
//            //We are moving down
//            singledivtopstart = singledivtopstart + 1;
//        }

        var moveleft = singledivleftend - singledivleftstart;
        if (moveleft == 0) {
            //We are not moving left or right
            singledivleftstart = singledivleftstart;
        }
        if (moveleft > 0) {
            //We are moving right
            singledivleftstart = singledivleftstart + 1;
        }
        if (moveleft < 0) {
            //We are moving left
            singledivleftstart = singledivleftstart - 1;
        }

//        if (moveleft < 0) {
//            //We are moving left
//            singledivleftstart = singledivleftstart - 1;
//        }
//        else {
//            //We are moving right
//            singledivleftstart = singledivleftstart + 1;
//        }

        //Ok move the div
        divtomove = document.getElementById(singleprocessdiv);
        if (divtomove) {
            divtomove.style.top = singledivtopstart + pStr;
            divtomove.style.left = singledivleftstart + pStr;
            divtomove.style.zIndex = movingZindex;
            divtomove.style.backgroundColor = movingBackColor;
        }

        //Check to see if we should cancel the animation (we are there)
        //if (singledivtopstart == singledivtopend || singledivleftstart == singledivleftend) {
        if (singledivtopstart == singledivtopend && singledivleftstart == singledivleftend) {
            clearInterval(singleanimateProcessID);
            //alert("we are there (" + singleanimateProcessID + " " + singledivtopstart + "=" + singledivtopend + " " + singledivleftstart + "=" + singledivleftend + ")");
            singleanimateProcessID = 0;
            if (divtomove) {
                divtomove.style.top = singledivtopend + pStr;
                divtomove.style.left = singledivleftend + pStr;
                divtomove.style.zIndex = baseZindex;
                divtomove.style.backgroundColor = completedBackColor;
            }
        }
    }
    /////////////////////////////////////////////////////////////////////////////////////


    /////////////////////////////////////////////////////////////////////////////////////
    // Header Image Animation Section --------------------------------------------
    function PlaceHeaderDivs() {
        // if this is the first time loading the page, populate the images
        if (document.getElementById("image1").style.posTop < 0) {
            document.getElementById("header_img1").src = document.getElementById("hfPic1").value;
            document.getElementById("header_img2").src = document.getElementById("hfPic2").value;
            document.getElementById("header_img3").src = document.getElementById("hfPic3").value;
            document.getElementById("header_img4").src = document.getElementById("hfPic4").value;
            document.getElementById("header_img5").src = document.getElementById("hfPic5").value;
            //At this point can we slide the divs down onto the page as one big group?
            
        }
        var div_image1 = document.getElementById("image1");
        var div_image2 = document.getElementById("image2");
        var div_image3 = document.getElementById("image3");
        var div_image4 = document.getElementById("image4");
        var div_image5 = document.getElementById("image5");
        var startleft = Math.round((document.body.offsetWidth - 750) / 2);
        div_image1.style.left = startleft + "px";
        div_image2.style.left = startleft + 150 + "px";
        div_image3.style.left = startleft + 300 + "px";
        div_image4.style.left = startleft + 450 + "px";
        div_image5.style.left = startleft + 600 + "px";

        var starttop = 0;
        div_image1.style.top = starttop + "px";
        div_image2.style.top = starttop + "px";
        div_image3.style.top = starttop + "px";
        div_image4.style.top = starttop + "px";
        div_image5.style.top = starttop + "px";
    }
    /////////////////////////////////////////////////////////////////////////////////////
    // Header Image Animation Section --------------------------------------------
    function PlaceHeaderDivs2() {
        // if this is the first time loading the page, populate the images
        if (document.getElementById("image1").style.posTop < 0) {
            document.getElementById("header_img1").src = document.getElementById("ucHeader1_hfPic1").value;
            document.getElementById("header_img2").src = document.getElementById("ucHeader1_hfPic2").value;
            document.getElementById("header_img3").src = document.getElementById("ucHeader1_hfPic3").value;
            document.getElementById("header_img4").src = document.getElementById("ucHeader1_hfPic4").value;
            document.getElementById("header_img5").src = document.getElementById("ucHeader1_hfPic5").value;
            //At this point can we slide the divs down onto the page as one big group?

        }
        var div_image1 = document.getElementById("image1");
        var div_image2 = document.getElementById("image2");
        var div_image3 = document.getElementById("image3");
        var div_image4 = document.getElementById("image4");
        var div_image5 = document.getElementById("image5");
        var startleft = Math.round((document.body.offsetWidth - 750) / 2);
        div_image1.style.left = startleft + "px";
        div_image2.style.left = startleft + 150 + "px";
        div_image3.style.left = startleft + 300 + "px";
        div_image4.style.left = startleft + 450 + "px";
        div_image5.style.left = startleft + 600 + "px";

        var starttop = 0;
        div_image1.style.top = starttop + "px";
        div_image2.style.top = starttop + "px";
        div_image3.style.top = starttop + "px";
        div_image4.style.top = starttop + "px";
        div_image5.style.top = starttop + "px";
    }
    // This can be moved to the general JS file that is included on the page.
    // This is fired after an ajax call to the server for a new file name.
    function OnEndRequest(sender, args) {
        //alert("EndRequest!");

        // This function should not run unless the calling element is the header timer.
        //alert(sender._postBackSettings.sourceElement.id);
        if (singleanimateProcessID == "" && sender._postBackSettings.sourceElement.id == "header_Timer") {

            //alert(sender._postBackSettings.sourceElement.id);
            var timer1 = $find("header_Timer");
            timer1._stopTimer();

            // Cache the new picture just returned from the ajax call.
            var new_image = new Image();
            var hfPic5 = document.getElementById("hfPic5");
            new_image.src = hfPic5.value;

            singledivtopstart = -255;
            singledivtopend = 0;
            singledivleftstart = 0;
            singledivleftend = 0;
            singleprocessdiv = "div_movering";
            singleanimateProcessID = 0;
            movingBackColor = "";
            anispeed1 = "25"; //speed of animation
            //document.getElementById("header_mover").src = document.getElementById("header_img2").src;
            // Start the process of moving all the divs.
            // This process will fire every second to see if we need to move on to the next div.
            // If the previous div is not finished moving then the process will just abort.
            imageanimateProcessID = setInterval('startmoveSingleDiv()', 1000);
        }
    }
    function OnBeginRequest(sender, args) {
        //alert("BeginRequest!");
        
//        if (sender._postBackSettings.sourceElement.id != "header_Timer") {
//            alert(sender._postBackSettings.sourceElement.id);

//            // Clear the animation process
//            clearInterval(singleanimateProcessID);
//            singleanimateProcessID = 0;

//            //Stop the timer
//            var timer1 = $find("header_Timer");
//            timer1._stopTimer();
//        }
    }
    function OnInitializeRequest(sender, args) {
        //alert("InitializeRequest!");
    }
    function OnPageLoaded(sender, args) {
        //alert("PageLoaded!");
    }
    function OnPageLoading(sender, args) {
        //alert("PageLoading!");
    }

    function startmoveSingleDiv() {
        // Start the process of moving all the divs.
        // This process will fire every second to see if we need to move on to the next div.
        // If the previous div is not finished moving then the process will just abort.
        if (singleanimateProcessID == "") {
            var divtomove = "div_movering";
            var cntrl = document.getElementById("image1");
            var starttop = cntrl.offsetTop;
            var startleft = cntrl.offsetLeft;
            var startleftoffset = startleft + 150;
            var widthmultiplier = 150;
            switch (imagemoving) {
                case 0:
                    singledivtopstart = starttop;
                    singledivtopend = 0;
                    singledivleftstart = 0 + startleftoffset;
                    singledivleftend = startleft;
                    document.getElementById("header_mover").src = document.getElementById("hfPic1").value;
                    moveSingleDiv(divtomove);
                    imagemoving = imagemoving + 1;
                    break;
                case 1:
                case 2:
                case 3:
                    document.getElementById("header_img" + imagemoving).src = document.getElementById("hfPic" + imagemoving).value;
                    singledivtopstart = starttop;
                    singledivtopend = 0;
                    singledivleftstart = (widthmultiplier * imagemoving) + startleftoffset;
                    singledivleftend = (widthmultiplier * imagemoving) + startleft;
                    document.getElementById(divtomove).style.top = "-255px";
                    document.getElementById(divtomove).style.left = "-255px";
                    document.getElementById("header_mover").src = document.getElementById("hfPic" + (imagemoving + 1)).value;
                    moveSingleDiv(divtomove);
                    imagemoving = imagemoving + 1;
                    break;
                case 4:
                    document.getElementById("header_img4").src = document.getElementById("hfPic4").value;
                    singledivtopstart = -100;
                    singledivtopend = 0;
                    singledivleftstart = (widthmultiplier * 4) + startleft;
                    singledivleftend = (widthmultiplier * 4) + startleft;
                    document.getElementById(divtomove).style.top = "-255px";
                    document.getElementById(divtomove).style.left = "-255px";
                    document.getElementById("header_mover").src = document.getElementById("hfPic5").value;
                    moveSingleDiv(divtomove);
                    imagemoving = 5;
                    break;
                case 5:
                    document.getElementById("header_img5").src = document.getElementById("hfPic5").value;
                    clearInterval(imageanimateProcessID);
                    imageanimateProcessID = 0;
                    imagemoving = 0;
                    var timer1 = $find("header_Timer");
                    timer1._startTimer();
                    document.getElementById(divtomove).style.top = "-255px";
                    break;
            }
        }
    }
    // End Header Image Animation Section --------------------------------------------
    /////////////////////////////////////////////////////////////////////////////////////
