﻿//<!--
    dojo.require("dojo.parser");

//    dojo.connect("tblSurveyContainer", "onMouseOver", survey_over());
//    dojo.connect("tblSurveyContainer", "onMouseOut", survey_over());
//    dojo.connect("divSurveyClose", "onclick", survey_out)

    var lock_survey_over = false; 
    var survey_submitted = false;   
    var lockInterval;
    var survey_is_open = false;

    function survey_over()
    {
        if(!w3c_dom) return;
        if((lock_survey_over)||(survey_submitted)) return;
        if(survey_is_open) return;
        survey_is_open = true;
        dojo.animateProperty({
        node: dojo.byId("tblSurveyContainer"),
        duration: 400,
        rate: 10,
        properties: 
        {
            //height: {start: "150", end: "300"}
            height: {end: "300"}
        },
        onEnd: function()
        {
            document.getElementById("divSurveyContent").innerHTML = "<br />Survey stuff here...<br />\n" +
                "\tmultiple lines<br />\n" +
                "\tblah blah blah....<br />\n";
            document.getElementById("divSurveyContent").innerHTML = "<br />How did you arrive at this page?<br />\n" +
                "<select id=\"selQuest1\" onchange=\"is_other_selection('selQuest1','txtQuest1Other');\">\n"+
                "\t<option value=\"\">select</option>\n" +
                "\t<option value=\"Bookmarked\">Bookmarked</option>\n" +
                "\t<option value=\"TV media website\">TV media website</option>\n" +
                "\t<option value=\"Newspaper website\">Newspaper website</option>\n" +
                "\t<option value=\"AirNow\">AirNow</option>\n" +
                "\t<option value=\"RAQC.org or OzoneAware.org\">RAQC.org or OzoneAware.org</option>\n" +
                "\t<option value=\"Local government website\">Local government website</option>\n" +
                "\t<option value=\"State government website\">State government website</option>\n" +
                "\t<option value=\"Federal government website\">Federal government website</option>\n" +
                "\t<option value=\"Search Engine\">Search engine</option>\n" +
                "\t<option value=\"No comment\">No comment</option>\n" +
                "\t<option value=\"Other\">Other...</option>\n" +
                "</select><br />\n" +
                "<input type=\"text\" id=\"txtQuest1Other\" style=\"visibility:hidden;\" onblur=\"is_complete();\" /><br />\n" +
                "What are you most interested in seeing?<br />\n" +
                "<select id=\"selQuest2\" onchange=\"is_other_selection('selQuest2','txtQuest2Other');\">\n" +
                "\t<option value=\"\">select</option>\n" +
                "\t<option value=\"Air Quality Index\">Air Quality Index</option>\n" +
                "\t<option value=\"Can I burn?\">Can I burn?</option>\n" +
                "\t<option value=\"Should I avoid exercise?\">Should I avoid exercise?</option>\n" +
                "\t<option value=\"Should I avoid driving, mowing... ?\">Should I avoid driving, mowing... ?</option>\n" +
                "\t<option value=\"Pollutant concentrations\">Pollutant concentrations</option>\n" +
                "\t<option value=\"No comment\">No comment</option>\n" +
                "\t<option value=\"Other\">Other...</option>\n" +
                "</select><br />\n" +
                "<input type=\"text\" id=\"txtQuest2Other\" style=\"visibility:hidden;\" onblur=\"is_complete();\" /><br />\n" +
                "How familiar are you with the Air Quality Index?<br />\n" +
                "<select id=\"selQuest3\" onchange=\"is_other_selection('selQuest3','txtQuest3Other');\">\n" +
                "\t<option value=\"\">select</option>\n" +
                "\t<option value=\"Very\">Very</option>\n" +
                "\t<option value=\"Somewhat\">Somewhat</option>\n" +
                "\t<option value=\"Not at all\">Not at all</option>\n" +
                "\t<option value=\"No comment\">No comment</option>\n" +
                "\t<option value=\"Other\">Other...</option>\n" +
                "</select><br />\n" +
                "<input type=\"text\" id=\"txtQuest3Other\" style=\"visibility:hidden;\" onblur=\"is_complete();\" /><br />\n" +
                "Zip code (outside of USA, enter country)<br />" +
                "<input type=\"text\" id=\"txtZipCode\" onblur=\"is_complete();\" /><br />\n&nbsp;<br />" +
                "<input type=\"button\" id=\"btnSurvey\" value=\"Submit\" onclick=\"survey_submit();\" style=\"vertical-align:middle;\" disabled=\"disabled\" />" +
                "<span class=\"smallFont\">(Does not leave page)</span>";

            //document.getElementById("divSurveyClose").innerHTML = "<a href=\"javascript:return survey_out();\" style=\"cursor:pointer;\"><b>Close X</b></a>";
            document.getElementById("divSurveyClose2").innerHTML = "Close X";
            document.getElementById("divSurveyClose2").onclick = function(){survey_out()};
        }
        }).play();
    }
    function survey_out()
    {
        if(!w3c_dom) return;
        lock_survey_over=true;
        survey_is_open=false;
        lockInterval = setTimeout("lock_survey_over=false;", 1500);

        dojo.animateProperty({
        node: dojo.byId("tblSurveyContainer"),
        duration: 400,
        rate: 10,
        properties: 
        {
            //height: {start: "300", end: "150"}
            height: {end: "30"}
        }
        }).play();
        document.getElementById("divSurveyContent").innerHTML = "";
        document.getElementById("divSurveyClose2").innerHTML = "";
        return false;
    }
    function fadey_thing()
    {
        if(!w3c_dom) return;
        dojo.animateProperty({
            node: dojo.byId("divSurveyEntice"),
            duration: 1500,
            rate: 5,
            properties: 
            {
                color: {end: "#aaaaaa"}
            },
            onEnd: function()
            {
                dojo.animateProperty({
                    node: dojo.byId("divSurveyEntice"),
                    duration: 1500,
                    rate: 5,
                    properties: 
                    {
                        color: {end: "#eeeeee"}
                    },
                    onEnd: function()
                    {
                        fadey_thing();
                    }
                }).play();
            }
        }).play();
    }
    function is_other_selection(select_name,text_name)
    {
        if(!w3c_dom) return;
        var select_value = document.getElementById(select_name).value;
        select_value = select_value.toLowerCase();
        if(select_value=="other")
        {
            document.getElementById(text_name).style.visibility = "visible";
        }
        else document.getElementById(text_name).style.visibility = "hidden";
        is_complete();
    }
    function is_complete()
    {
        if((document.getElementById("selQuest1").value=="") ||
            (document.getElementById("selQuest2").value=="") ||
            (document.getElementById("selQuest3").value=="")) return;
        if(((document.getElementById("selQuest1").value=="Other") &&
            (document.getElementById("txtQuest1Other").value=="")) ||
            ((document.getElementById("selQuest2").value=="Other") &&
            (document.getElementById("txtQuest2Other").value=="")) ||
            ((document.getElementById("selQuest3").value=="Other") &&
            (document.getElementById("txtQuest3Other").value==""))) return;
        document.getElementById("btnSurvey").disabled=false;
    }
    function init_survey()
    {    
        if(!w3c_dom) return;
        document.getElementById("tblSurveyContainer").style.visibility = "visible";
        fadey_thing();
    }
    function survey_submit()
    {
        submit_survey_ajax();
        survey_submitted = true;
        survey_out();
        document.getElementById("divTitle").innerHTML = "Survey submitting";
        document.getElementById("divSurveyEntice").innerHTML = "...";
    }
    function survey_submit_success()
    {
        document.getElementById("divTitle").innerHTML = "Survey submitted";
        document.getElementById("divSurveyEntice").innerHTML = " - Thank you";
    }
    //AJAX
    function submit_survey_ajax() 
    {
        var targetURL = "air_quality_survey.aspx";
        var queryString = "";
        var httpRequest;
      
        queryString = "?quest1=" + escape(document.getElementById("selQuest1").value) +
                    "&quest1other=" + escape(document.getElementById("txtQuest1Other").value) +
                    "&quest2=" + escape(document.getElementById("selQuest2").value) +
                    "&quest2other=" + escape(document.getElementById("txtQuest2Other").value) +
                    "&quest3=" + escape(document.getElementById("selQuest3").value) +
                    "&quest3other=" + escape(document.getElementById("txtQuest3Other").value) +
                    "&zipcode=" + escape(document.getElementById("txtZipCode").value) +
                    "&referer=" + escape(document.getElementById("hdnReferer").value);

        if (window.XMLHttpRequest) 
        { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) 
            {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
		    }
        } 
        else if (window.ActiveXObject) 
        { // IE
            try 
            {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) 
            {
			    try 
			    {
				    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
		    }
	    }

        if (!httpRequest) 
        {
            //alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        httpRequest.onreadystatechange = function() 
        { 
            //survey_submit_success(); 
            change_content_sur(httpRequest);
        };
        httpRequest.open('GET', targetURL + queryString, true);
        httpRequest.send(null);
    }

    function change_content_sur(httpRequest) 
    {
        if (httpRequest.readyState == 4) 
        {
            if (httpRequest.status == 200) 
            {
                document.getElementById("divTitle").innerHTML = "Survey submitted";
                document.getElementById("divSurveyEntice").innerHTML = " - " + httpRequest.responseText;
            } 
            else 
            {
                document.getElementById("divDebug").innerHTML = 'There was a problem with the request.';
            }
        }
    }
//-->    
