﻿
window.onload = initialize;

var currentOpenDiv = "leadForm";

var txtFirstName = null;
var txtLastName = null;
var txtEmailAddress = null;
var txtTitle = null;
var txtPhone = null;
var txtSchoolName = null;
var txtFriendsName = null;
var txtFriendsEmail = null;
var chkInterestedIn = null;
var checkedStatus = null;
var txtTravelDates = null;
var txtBudget = null;

function openGetQuoteBox(divToTarget, clickedOption) {


    var divTarget = "formTarget_" + divToTarget;

    
    if (divTarget != currentOpenDiv)
    {

        // get the current values of the form
        // we do this since Firefox seems to lose them 
        // when we move the form

        txtFirstName = $('#ctl00_ContentPlaceHolder1_txtFirstName').val();

        txtLastName = $('#ctl00_ContentPlaceHolder1_txtLastName').val();
        txtEmailAddress = $('#ctl00_ContentPlaceHolder1_txtEmailAddress').val();
        txtTitle = $('#ctl00_ContentPlaceHolder1_txtTitle').val();
        txtPhone = $('#ctl00_ContentPlaceHolder1_txtPhone').val();    
        txtSchoolName = $('#ctl00_ContentPlaceHolder1_txtSchoolName').val();
        txtTravelDates = $('#ctl00_ContentPlaceHolder1_dtTravelStart').val();
        txtBudget = $('#ctl00_ContentPlaceHolder1_lstEstimateBudget').val();
        
        // get the current checkbox status into an array
        var chkStatus = new Array();

        $("#debug1").val("");
        $("#debug2").val("");        

        $("#ctl00_ContentPlaceHolder1_chkInterestedIn").find("td").each(

            function (intIndex) {
            
                var thisValue = $(this).find("label").text();
                var thisCheckbox = $(this).find("input");
                
                if (thisValue.length != 0)
                {
                
                    if (thisValue == clickedOption)
                    {
                    
                        $("#debug1").val($("#debug1").val() + "true,");
                        chkStatus[intIndex] = true;
                        
                    }
                    else
                    {

                        $("#debug1").val($("#debug1").val() + $(thisCheckbox).attr("checked") + ",");
                        chkStatus[intIndex] = $(thisCheckbox).attr("checked");                
                    }
                
                }

            }
            
        );

        var cloneCopy = $("#" + currentOpenDiv).clone(true);
        
        
        var newDivID = "form_" + divToTarget + "";
        
        $(cloneCopy).attr("id", newDivID);
        $("#" + divTarget).append( cloneCopy );
        $("#" + currentOpenDiv).remove();      
        $("#" + divTarget).show();
        
        // rebuild the form fields
        $('#ctl00_ContentPlaceHolder1_txtFirstName').val(txtFirstName);
        
        
        $('#ctl00_ContentPlaceHolder1_txtLastName').val(txtLastName);
        $('#ctl00_ContentPlaceHolder1_txtEmailAddress').val(txtEmailAddress);
        $('#ctl00_ContentPlaceHolder1_txtTitle').val(txtTitle);
        $('#ctl00_ContentPlaceHolder1_txtPhone').val(txtPhone);
        $('#ctl00_ContentPlaceHolder1_txtSchoolName').val(txtSchoolName);
        $('#ctl00_ContentPlaceHolder1_dtTravelStart').val(txtTravelDates);
        $('#ctl00_ContentPlaceHolder1_lstEstimateBudget').selectOptions(txtBudget, true);

        
        // rebuild the checkbox array status
        for (i=0;i < chkStatus.length;i++) {
        
            $("#debug2").val($("#debug2").val() + chkStatus[i] + ",");        
            $("#ctl00_ContentPlaceHolder1_chkInterestedIn_" + i).attr("checked", chkStatus[i]);
            
        }    
        
        currentOpenDiv = newDivID;
        
        $("#ctl00_ContentPlaceHolder1_hdnActiveForm").val(divToTarget);
    
    }
    
}


function initialize() {

    if ($("#ctl00_ContentPlaceHolder1_hdnActiveForm").val() != "") {
        
        openGetQuoteBox("" + $("#ctl00_ContentPlaceHolder1_hdnActiveForm").val() + "", "");
        var toScrollTo = "#result_" + $("#ctl00_ContentPlaceHolder1_hdnActiveForm").val();
        $.scrollTo(toScrollTo);        
    
    }

}

function destinationChanged(lstDest) {

    if ($(lstDest).val() != "-1") {
    
        $("#divSpecific").show();

        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").removeOption(/./);
        
        var destSwitch = $(lstDest).val();
        var newOptions = $("#hdnEvents_" + destSwitch).val();
        var newPieces = newOptions.split("|");

        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").addOption("-99", " ");            
        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").addOption("-1", "Show All");    
        
        for (var thisPiece=0; thisPiece<newPieces.length; thisPiece++)
        {
            var piece = newPieces[thisPiece].split('~');
            $("#ctl00_ContentPlaceHolder1_lstSpecificCity").addOption(piece[1], piece[1]);        
            
        }
        
        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").selectOptions("-99", true)        


        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").attr("disabled", false);        
    
    }
    else
    {
        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").removeOption(/./);    
        $("#ctl00_ContentPlaceHolder1_lstSpecificCity").addOption("-1", "");                
        $("#divSpecific").hide();
    }
    

}


