﻿var noCache = new Date().getTime();

function quoteForm() {

    $.get("quote_form.asp", { timestamp: noCache }, 
    function(data) {
        $('#quote_form').html(data);
    });
        
}

function sendCallback() {

    var thisname = document.getElementById('name').value;
    var thistel = document.getElementById('tel').value;
    var thistime = document.getElementById('time').value;

    if (thisname && thistel) {

        $.post("send_callback.asp", { name: thisname, tel: thistel, time: thistime },
        function(data) {
            alert(data);
        });

    } else {

        alert("Please complete all fields in the callback form.");

    }


}

function selectAnswer(questionID,answerID) {

    clearQuestionOptions(questionID);
    $('#S' + answerID).show();

}

function clearQuestionOptions(questionID) {

    anwers = $('#G' + questionID).val();
    var anwersArray = anwers.split(',');
    for (var i in anwersArray) {
        thisAnswer = anwersArray[i];
        $('#S' + thisAnswer).hide();
        $('#T' + thisAnswer).val("");
    }
    
} 

function startSurvey() {

    $.post("run_survey.asp",
    function(data) {
        $('#boxPopup').html(data);
        centerPopup();
    });

}

function openSurvey() {
    
    openPop();

    $.post("survey.asp", 
    function(data) {
    $('#boxPopup').html(data);
    centerPopup();
    });

}

function blockSurvey() {

    $.post("survey_close.asp",
    function(data) {
        // do nothing
    });

}

function openPop() {

    //centering with css
    centerPopup();
    //load popup
    loadPopup();

    $("#boxPopupClose").click(function() {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
    
}
