﻿function Quote_Make_Changed() {

    var sAjaxRequest = "";
    bShowLoadingScreen = true;
    sAJAXOutputDivName = "divModel";
    sAjaxRequest += "PageAction=ChangeMake";
    sAjaxRequest += "&MakeId=" + document.getElementById("Master_Quote_Make").value;
    runRemoteScriptPost("/Common/Ajax/Master_Generics.ashx", sAjaxRequest);

}

function Quote_Search() {
    quote_createPopUp();
}

function Quote_CloseWindow() {
    if (document.getElementById("ajaxHighlight")) {
        document.getElementById("ajaxHighlight").removeChild(document.getElementById("ajaxHighlight_Header"));
        document.getElementById("ajaxHighlight").removeChild(document.getElementById("ajaxHighlight_Content"));
        document.getElementsByTagName("body").item(0).removeChild(document.getElementById("ajaxHighlight"));
        document.getElementsByTagName("body").item(0).removeChild(document.getElementById("ajaxHighlight_FullScreenWashout"));

    }
}

function quote_createPopUp() {

    //Validate Entry
    if (!document.getElementById("Master_Quote_Make")) {
        alert("You must enter a Make");
        return false;
    }
    if (!document.getElementById("Master_Quote_Model")) {
        alert("You must enter a model");
        return false;
    }

    if (!ValidateNotNull("Master_Quote_Make", "Make")) return;
    if (!ValidateNotNull("Master_Quote_Model", "Model")) return;
    if (!ValidateNotNull("Master_Quote_BudgetFrom", "Budget - From")) return;
    if (!ValidateNotNull("Master_Quote_BudgetTo", "Budget - To")) return;

    if (parseInt(document.getElementById("Master_Quote_BudgetFrom").value) > parseInt(document.getElementById("Master_Quote_BudgetTo").value)) {
        alert("You must enter a Budget To which is greater than Budget From");
        return false;
    }

    if (!document.getElementById("ajaxHighlight")) {
        var iWidth = 700;
        var iHeight = 500;
        var oDialog = document.createElement("div");
        var oWashout = document.createElement("div");

        oDialog.setAttribute("id", "ajaxHighlight");
        oDialog.setAttribute("name", "ajaxHighlight");
        oWashout.setAttribute("id", "ajaxHighlight_FullScreenWashout");
        oDialog.setAttribute("align", "center");

        document.getElementsByTagName("body").item(0).appendChild(oDialog);
        document.getElementsByTagName("body").item(0).appendChild(oWashout);

        document.getElementById("ajaxHighlight_FullScreenWashout").style.height = document.body.scrollHeight + "px";

        document.getElementById("ajaxHighlight").style.width = iWidth + "px";
        document.getElementById("ajaxHighlight").style.height = iHeight + "px";
        document.getElementById("ajaxHighlight").style.marginLeft = (0 - (iWidth / 2)) + "px";
        document.getElementById("ajaxHighlight").style.marginTop = (0 - (iHeight / 2)) + "px";
        document.getElementById("ajaxHighlight").style.overflowY = 'hidden';
        document.getElementById("ajaxHighlight").style.overflowX = 'hidden';

        var oHeader = document.createElement("div");
        oHeader.setAttribute("id", "ajaxHighlight_Header");
        oHeader.setAttribute("align", "center");
        document.getElementById("ajaxHighlight").appendChild(oHeader);
        document.getElementById("ajaxHighlight_Header").innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:100%; height:30px;\"><tr><td style=\"vertical-align:middle; color:#ffffff; padding-left:5px; text-align:left;\"><strong>CJ Tafft:</strong> Car Finder</td><td style=\"vertical-align:middle; color:#ffffff; padding-right:10px; text-align:right;\"><div class=\"Layout-Generics-FakeLink\" onclick=\"Javascript: Quote_CloseWindow();\">(Close)</div></td></tr></table>";

        var oContent = document.createElement("div");
        oContent.setAttribute("id", "ajaxHighlight_Content");
        oContent.setAttribute("align", "center");
        document.getElementById("ajaxHighlight").appendChild(oContent);
        //Run Ajax Query

        var sAjaxRequest = "";
        bShowLoadingScreen = true;
        sAJAXOutputDivName = "ajaxHighlight_Content";
        sAjaxRequest += "PageAction=SearchResult";
        sAjaxRequest += "&MakeId=" + document.getElementById("Master_Quote_Make").value;
        sAjaxRequest += "&ModelId=" + document.getElementById("Master_Quote_Model").value;
        sAjaxRequest += "&BudgetFrom=" + document.getElementById("Master_Quote_BudgetFrom").value;
        sAjaxRequest += "&BudgetTo=" + document.getElementById("Master_Quote_BudgetTo").value;
        runRemoteScriptPost("/Common/Ajax/Master_Generics.ashx", sAjaxRequest);

    }
}
