﻿// MARKETING -> Physical Tour Request Submission - Progress Bar - Clear Form Fields //
function updatePTProgressBar() {
    document.getElementById("PTProgressBar").style.display = "block";

    var progress;
    progress = $("#PTProgressBar").progressbar("option", "value");

    if (progress < 100) {
        $("#PTProgressBar").progressbar("option", "value", progress + 15);
        setTimeout(updatePTProgressBar, 500);
    }
    else if (progress >= 100) {
        alert("Your submission has been sent.  Thank you!");
        // greybox request check //
        if (document.getElementById("hidPTRequestType")) {
            parent.GB_hide();
        }
        else {
            clearPTFields();
        }
        
    }
}

function clearPTFields() {
    document.getElementById("ctl00_ContentPH_txtPTAgentName").value = "";
    document.getElementById("ctl00_ContentPH_txtPTMLS").value = "";
    document.getElementById("ctl00_ContentPH_txtPTAddress").value = "";
    document.getElementById("ctl00_ContentPH_txtPTPrice").value = "";
    document.getElementById("ctl00_ContentPH_txtPTSqFtUpper").value = "";
    document.getElementById("ctl00_ContentPH_txtPTSqFtBasement").value = "";
    document.getElementById("ctl00_ContentPH_txtPTDirections").value = "";
    document.getElementById("ctl00_ContentPH_chkPTEmailReceipt").checked = false;
    document.getElementById("ctl00_ContentPH_selPTArea").selectedIndex = 0;
    document.getElementById("ctl00_ContentPH_selPTOccupancy").selectedIndex = 0;
    document.getElementById("PTProgressBar").style.display = 'none';
}

// MARKETING -> Postcard Request Submission - Progress Bar - Clear Form Fields //
function updatePCProgressBar() {
    document.getElementById("PCProgressBar").style.display = "block";

    var progress;
    progress = $("#PCProgressBar").progressbar("option", "value");

    if (progress < 100) {
        $("#PCProgressBar").progressbar("option", "value", progress + 15);
        setTimeout(updatePCProgressBar, 500);
    }
    else if (progress >= 100) {
        alert("Your submission has been sent.  Thank you!");
        clearPCFields();
    }
}

function clearPCFields() {
    document.getElementById("ctl00_ContentPH_txtPCAgentName").value = "";
    document.getElementById("ctl00_ContentPH_txtPCMLS").value = "";
    document.getElementById("ctl00_ContentPH_txtPCAddress").value = "";
    document.getElementById("ctl00_ContentPH_txtPCPrice").value = "";
    document.getElementById("ctl00_ContentPH_selPCOffice").selectedIndex = 0;
    document.getElementById("ctl00_ContentPH_txtPCQuantity").value = "20";
    document.getElementById("ctl00_ContentPH_txtPCSpecial").value = "";
    document.getElementById("ctl00_ContentPH_txtPCWebsite").value = "";
    document.getElementById("PCProgressBar").style.display = 'none';
    document.getElementById("ctl00_ContentPH_chkPCEmailReceipt").checked = false;

    var i = 0;
    var chkOptions;

    while (i < 5)
    {
        chkOptions = document.getElementById("ctl00_ContentPH_chkPCOptions" + "_" + i);
        chkOptions.checked = false;
        i++;
    }
}

// MARKETING -> TV Show Request Submission - Progress Bar - Clear Form Fields //
function updateTVProgressBar() {
    document.getElementById("TVProgressBar").style.display = "block";

    var progress;
    progress = $("#TVProgressBar").progressbar("option", "value");

    if (progress < 100) {
        $("#TVProgressBar").progressbar("option", "value", progress + 15);
        setTimeout(updateTVProgressBar, 500);
    }
    else if (progress >= 100) {
        alert("Your submission has been sent.  Thank you!");
        clearTVFields();
    }
}

function clearTVFields() {
    document.getElementById("ctl00_ContentPH_txtTVAgentName").value = "";
    document.getElementById("ctl00_ContentPH_txtTVMLS").value = "";
    document.getElementById("ctl00_ContentPH_txtTVAddress").value = "";
    document.getElementById("ctl00_ContentPH_txtTVPrice").value = "";
    document.getElementById("ctl00_ContentPH_selTVTimeFrame").selectedIndex = 0;
    document.getElementById("TVProgressBar").style.display = 'none';
    document.getElementById("ctl00_ContentPH_chkTVEmailReceipt").checked = false;
}

// SEND FEEDBACK -> Feedback Submission - Progress Bar //
function updateSFBProgressBar() {
    document.getElementById("SFBProgressBar").style.display = "block";

    var progress;
    progress = $("#SFBProgressBar").progressbar("option", "value");

    if (progress < 100) {
        $("#SFBProgressBar").progressbar("option", "value", progress + 15);
        setTimeout(updateSFBProgressBar, 500);
    }
    else if (progress >= 100) {
        alert("Your submission has been sent.  Thank you!");
        parent.GB_hide();
    }
}

function GB_hide() {
    $("#GB_window,#GB_overlay").hide();
}

// BLOG ENGINE - Print This Post //
var gAutoPrint = true; 

function printSpecial()
{
    if (document.getElementById != null)
    {
        var html = '<HTML>\n<HEAD>\n';

        if (document.getElementsByTagName != null)
        {
            var headTags = document.getElementsByTagName("head");
            if (headTags.length > 0)
                html += headTags[0].innerHTML;
        }

        html += '\n</HE>\n<BODY>\n';

        var printReadyElem = document.getElementById("printReady");

        if (printReadyElem != null)
        {
            html += printReadyElem.innerHTML;
        }
        else
        {
            alert("Could not find the printReady function");
            return;
        }

        html += '\n</BO>\n</HT>';

        var printWin = window.open("","printSpecial");
            
        printWin.document.open();
        printWin.document.write(html);
        printWin.document.close();
            
        if (gAutoPrint)
            printWin.print();
    }
    else
    {
        alert("The print ready feature is only available if you are using an browser. Please update your browswer.");
    }
}

// RESOURCES -> Documents & Restrictions Search Options Toggle //
function btnToggleSearchOptions() {
    var togglearea = document.getElementById("ctl00_ContentPH_toggleSearchOptions");

    var toggle = document.getElementById("ctl00_ContentPH_toggle").value;

    if (toggle == "0") {
        togglearea.style.display = 'block';
        document.getElementById("ctl00_ContentPH_toggle").value = "1";
    }
    else {
        togglearea.style.display = 'none';
        document.getElementById("ctl00_ContentPH_toggle").value = "0";
    }
}

// KeyPress Event Handler for Restriction Search Textbox //
function clickButton(e, buttonid) {

    var evt = e ? e : window.event;

    var bt = document.getElementById(buttonid);

    if (bt) {

        if (evt.keyCode == 13) {

            bt.click();

            return false;

        }

    }

}

// Directory Print GridView Contents //
function PrintGridView(htmlOutput) {
        var new_window = window.open('print.html'); // dummy html 
        new_window.document.write(htmlOutput); // gridview contents
        new_window.document.close();
        new_window.focus();
        new_window.print();
    }

// Blog Paging Control - Button Click Events //
function NewerPosts_Click() {
    __doPostBack('', 'NewerPosts_Click');
}

function OlderPosts_Click() {
    __doPostBack('', 'OlderPosts_Click');
}

function pageClick(position) {
    __doPostBack('', position);
}

// Master Page - Search Code
function clearSearch() {
    document.getElementById("ctl00_txtSearchSite").value = "";
}

function checkKeywords() {
    if (document.getElementById("ctl00_txtSearchSite").value == "") 
    {
        document.getElementById("ctl00_txtSearchSite").value = "Click here to search...";
    }
}
