﻿var currShowingAgent = -1;
var currListingAgent = -1;
var currMls = -1;
var currAgent = -1;
var showingInstructions = "";
var agentRemarks = "";
var listingsTable;
var agentsTable;
var currDate = new Date();
var mlsSearchPanel;
var agentSearchPanel;
var appointmentPanel;
var showingAgentEditPanel;
var listingAgentEditPanel;
var sellerEditPanel;
var startAppt;
var startMLS;

function pageLoad()
{
    clearShowingAgentInfo();
    clearListingAgentInfo();
    clearSellerInfo();
    clearListingInfo();
    
    if($get("ctl00_LblAccess").innerHTML == "ADMIN"){
	    $get("navAdmin").style.display = "block";    
	}
	
	$get("propertyInfoStatus").value = "Not Active";            
    $get("ctl00_ContentPlaceHolder1_txtApptDate").value = getDateString(currDate);
    
    var searchString = document.location.search;
    searchString = searchString.substring(1);

    var nvPairs = searchString.split("&");

    for (i = 0; i < nvPairs.length; i++)
    {
	    var nvPair = nvPairs[i].split("=");
	    if(nvPair[0] == "appt")
	    {
		    startAppt = nvPair[1];
		    PageMethods.GetApptInfo(startAppt, onGetApptInfo_Complete, onErrorGeneric);
	    }
	    else if(nvPair[0] == "mls")
	    {
	        startMLS = nvPair[1];
	        PageMethods.GetListingInfo(startMLS, onGetListingInfoComplete, onErrorGeneric);
	    }
    }
    
    $("#mlsData").fadeIn(300);
    $("#showAgent-container").fadeIn(300);
    $("#photoBox-container").fadeIn(300);
    $("#schedule-container").fadeIn(300);
    $("#photoContainer").fadeIn(300);
    $("#showAgentInner").fadeIn(300);
    $("#listing_sellerInfo-container").fadeIn(300);
    $("#showingAgent-buttons").fadeIn(300);
    
    logIt("navigation","entered Scheduler.aspx", "9");    
}

function onGetApptInfo_Complete(results)
{
    PageMethods.GetListingInfo(results.MLS, onGetListingInfoComplete, onErrorGeneric);
    
    $get("ctl00_ContentPlaceHolder1_txtApptDate").value = results.ApptDate;  
    onDateChanged();
    
    PageMethods.GetAgentInfo(results.Agent, onFindAgentComplete, onFindAgentError);
    
    appointmentDetails_Click(results.Button);
}

function getDateString(date)
{
    var dateFormatted = date.getMonth() + 1 + "/" + date.getDate() + "/" + date.getFullYear();
    
    return dateFormatted;
}

function onErrorGeneric(error)
{
    $("#divAppointmentFT").fadeIn();
    logIt("Error", "Generic Error: " + error.get_message(), "2"); 
    alert("The following Error occurred:\n\n " + error.get_message() + "\n\nListing Planner site admins notified.  Please try again in a few minutes.");
}


//-------------Showing Agent--------------//
function btnFindAgent_Click()
{
    logIt("navigation", "clicked find showing agent", "9");
    $get("divSearchAgent-container").style.display = "block";
    if(!agentSearchPanel)
    {
        agentSearchPanel = new YAHOO.widget.Panel("divSearchAgent-container", {    
	                                    modal: true, 
                                        fixedcenter: true, 
                                        close: true, 
                                        zindex: 0,
                                        draggable: false, 
                                        visible: false
			    }); 
			    
        agentSearchPanel.render(document.body);
    }
    
    agentSearchPanel.show();
}

function clearShowingAgentInfo()
{
    //btnCancelAgentEdit_Click();
    $get("agentID").value = "";
    $get("agentName").innerHTML = ""; 
    $get("agentOffice").innerHTML = "";
    $get("agentWork").innerHTML = "";
    $get("agentCell").innerHTML = "";
    $get("agentEmail").innerHTML = "";
    $get("agentNameEdit").innerHTML = "";
    $get("agentOfficeEdit").innerHTML = "";
    $get("agentWorkEdit").value = "";
    $get("agentCellEdit").value = "";
    $get("agentEmailEdit").value = "";  
}

function btnAgentSearch_Click()
{
 
    logIt("search","Showing Agent Search id: " + $get("txtSearchAgentId").value 
                 + "agency: " + $get("txtSearchAgency").value + " name: " + $get("txtSearchAgentName").value
                 + "phone: " + $get("txtSearchAgentPhone").value, "9");
                                 
    clearShowingAgentInfo();  
    $get("divAgentSearchParameters").style.display = "none";
    $get("divAgentSearching").style.display = "";
    $get("divAgentSearchResults").style.display = "none";
    $get("divAgentSearchResults").innerHTML = "";

    PageMethods.FindAgents($get("txtSearchAgentId").value,
                           $get("txtSearchAgency").value,
                           $get("txtSearchAgentName").value,
                           $get("txtSearchAgentPhone").value,
                           onFindAgentsComplete,
                           onFindAgentsError);
}

function onFindAgentsError(error)
{
    logIt("Error", "Error Finding Showing Agent: " + error.get_message(), "3");
    $get("divAgentSearchParameters").style.display = "";
    $get("divAgentSearching").style.display = "none";
    
    alert(error.get_message());
}

function onFindAgentsComplete(results)
{    
    $get("divAgentSearching").style.display = "none";
            
    if(results.rows)
    {    
        if(results.rows[1])
        {
            createAgentsTable(results);
            var div = $get("divSearchAgent-container");
            //AjaxControlToolkit.Animation.ResizeAnimation.play(div, .2, 30, 550, 335, "px");
    
            $get("divAgentSearchResults").style.display = "";
            $get("divAgentSearchButtons").style.display = "none";
            $get("divNewAgentSearch").style.display = "";
            $get("divAgentInstructions").style.display = "";
        }
        else
        {
            currAgent = results.rows[0].AgentID;      
    
            PageMethods.GetAgentInfo(currAgent, onFindAgentComplete, onFindAgentError);
        }
    }
    else
    {
        $get("divAgentSearchParameters").style.display = "";
        
        alert("No results found!");
    }
}

function createAgentsTable(data)
{
    var dataSource = new YAHOO.util.DataSource(data.rows);
    dataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
    dataSource.responseSchema = {
        fields: ["AgentID","AgentName","OfficeName"]
    };

    var columnDefs = [
        {key:"AgentID", label:"Agent ID", sortable:"true"},
        {key:"AgentName", label:"Name", sortable:"true"},
        {key:"OfficeName", label:"Office", sortable:"true"}
    ];
	 
    agentsTable = new YAHOO.widget.DataTable("divAgentSearchResults", columnDefs, dataSource);
    
    agentsTable.set("selectionMode","single");
    agentsTable.subscribe("rowClickEvent", agentsTable.onEventSelectRow);
    agentsTable.subscribe("rowClickEvent", getAgentInfo);
}

function getAgentInfo(args)
{
    var record = agentsTable.getSelectedTrEls();    
    currAgent = record[0].childNodes[0].childNodes[0].innerHTML;    
    PageMethods.GetAgentInfo(currAgent, onFindAgentComplete, onFindAgentError);
}

function btnCloseAgent_Click()
{
    btnNewAgentSearch_Click();
    agentSearchPanel.hide();
}
	
function btnNewAgentSearch_Click()
{
    $get("divNewAgentSearch").style.display = "none";
    $get("divAgentSearchParameters").style.display = "";
    $get("divAgentSearchResults").style.display = "none";
    $get("divNewAgentSearch").style.display = "none";
    $get("divAgentInstructions").style.display = "none";
    $get("divSearchAgent-container").style.height = "215px";
    $get("divSearchAgent-container").style.width = "450px";
    $get("divAgentSearchButtons").style.display = "";
}	

function btnAgentSearchClear_Click()
{
    $get("txtSearchAgentId").value = "";
    $get("txtSearchAgency").value = "";
    $get("txtSearchAgentName").value = "";
    $get("txtSearchAgentPhone").value = "";
}


function onFindAgentComplete(results, context, methodName)
{
    btnNewAgentSearch_Click();

    var div = $get("divShowingAgent");
    //AjaxControlToolkit.Animation.ResizeAnimation.play(div, .2, 30, 300, 200, "px");
    
    $get("agentName").innerHTML = results.Name;
    $get("agentOffice").innerHTML = results.Office.substring(0,30);
    $get("agentWork").innerHTML = results.WorkNumber;
    $get("agentCell").innerHTML = results.CellNumber;
    $get("agentEmail").innerHTML = results.EmailAddress;
    $get("agentID").value = results.ID;
    currShowingAgent = results.ID;
    if(agentSearchPanel)
    {
        agentSearchPanel.hide();
    }
    $get("btnEditAgent").style.display = "block";
    $("#showingAgentInfo-container").show();
    checkMissingContactInfo();
}

function checkMissingContactInfo()
{
    var missingInfo = new Array();
    var missingCount = 0;
    
    if($get("agentCell").value == "")
    {
        missingInfo.push("Cell Number");
        missingCount++;        
    }
    
    if($get("agentEmail").value == "")
    {
        missingInfo.push("Email Address");
        missingCount++;
    }
    
    if(missingCount == 1)
    {
        alert("Contact Information Missing!\n\nPlease ask " + $get("agentName").innerHTML + " to provide " + missingInfo[0] + "!");
    }    
    
    if(missingCount == 2)
    {
        alert("Contact Information Missing!\n\nPlease ask " + $get("agentName").innerHTML + " to provide an Email Address and Cell Number!");
    }  
}

function onFindAgentError(error, context, methodName)
{
    logIt("Error", "Error: " + error.get_message(), "3");
    alert(error.get_message());
}

function btnEditAgent_Click()
{
    logIt("edit","editing Showing Agent" + $get("agentName").innerHTML, "9");
    $get("divShowingAgentEdit-container").style.display = "block";
    $get("btnEditAgent").style.display = "none";
    $get("btnCancelAgentEdit").style.display = "";
    $get("btnSaveAgent").style.display = "";
    $get("btnCancelAgentEdit").disabled = false
    $get("btnSaveAgent").disabled = false;
    
    if(!showingAgentEditPanel)
    {
        showingAgentEditPanel = new YAHOO.widget.Panel("divShowingAgentEdit-container", {    
	                                    modal: true, 
                                        fixedcenter: true, 
                                        close: true, 
                                        zindex: 0,
                                        draggable: false, 
                                        visible: false
			    }); 
			    
        showingAgentEditPanel.render(document.body);
    }
    
    $get("agentNameEdit").innerHTML = $get("agentName").innerHTML;
    $get("agentOfficeEdit").innerHTML = $get("agentOffice").innerHTML;
    $get("agentWorkEdit").value = $get("agentWork").innerHTML;
    $get("agentCellEdit").value = $get("agentCell").innerHTML;
    $get("agentEmailEdit").value = $get("agentEmail").innerHTML;  
    
    showingAgentEditPanel.show();
}

function btnCancelAgentEdit_Click()
{
    logIt("edit", "cancel edit of Showing Agent " + $get("agentName").innerHTML, "9");
    $get("btnEditAgent").style.display = "";
    $get("btnFindAgent").style.display = "";
    $get("btnCancelAgentEdit").style.display = "none";
    $get("btnSaveAgent").style.display = "none";
    
    showingAgentEditPanel.hide();
}

function btnSaveAgent_Click()
{
    logIt("edit", "saving changes to showing agent" + $get("agentName").innerHTML, "9");
    $get("imgAgentSaving").style.display = "";
    $get("btnCancelAgentEdit").disabled = true;
    $get("btnSaveAgent").disabled = true;

    var agent = new Agent();
    agent.ID = $get("agentID").value;
    agent.Name = $get("agentNameEdit").innerHTML;
    agent.Office = $get("agentOfficeEdit").innerHTML;
    agent.WorkNumber = $get("agentWorkEdit").value;
    agent.CellNumber = $get("agentCellEdit").value;
    agent.EmailAddress = $get("agentEmailEdit").value;
    
    //TODO: Validate input
    
    PageMethods.SaveAgentInfo(agent, onSaveAgentComplete, onSaveAgentError);    
}

function onSaveAgentComplete()
{
    logIt("edit", "successful save to showing agent" + $get("agentName").innerHTML, "9");
    $get("btnEditAgent").style.display = "";
    $get("btnCancelAgentEdit").style.display = "none";
    $get("btnSaveAgent").style.display = "none";
    
    $get("btnFindAgent").style.display = "";
    $get("btnEditAgent").style.display = "";
    
    $get("agentName").innerHTML = $get("agentNameEdit").innerHTML;
    $get("agentOffice").innerHTML = $get("agentOfficeEdit").innerHTML;
    $get("agentWork").innerHTML = $get("agentWorkEdit").value;
    $get("agentCell").innerHTML = $get("agentCellEdit").value;
    $get("agentEmail").innerHTML = $get("agentEmailEdit").value;
    
    $get("imgAgentSaving").style.display = "none";
    showingAgentEditPanel.hide();
}

function onSaveAgentError(error)
{
    logIt("Error","Error: " + error.get_message(), "2");
    alert(error.get_message());2
    $get("imgAgentSaving").style.display = "none";
    $get("btnCancelAgentEdit").disabled = false;
    $get("btnSaveAgent").disabled = false;
}

//////////////Showing Agent Ends//////////////////


//------------------Listings---------------------//
//listing agent
function btnEditListingAgent_Click()
{
    logIt("edit", "editing listing agent " + $get("listingAgentName").innerHTML, "8");
    $get("divListingAgentEdit-container").style.display="block";
    $get("btnCancelListingAgentEdit").disabled = false
    $get("btnSaveListingAgent").disabled = false;
    
    $get("listingAgentIDEdit").innerHTML = $get("listingAgentID").innerHTML;
    $get("listingAgentNameEdit").innerHTML = $get("listingAgentName").innerHTML;
    $get("listingAgentWorkEdit").value = $get("listingAgentWork").innerHTML;
    $get("listingAgentCellEdit").value = $get("listingAgentCell").innerHTML;
    $get("listingAgentEmailEdit").value = $get("listingAgentEmail").innerHTML;
    
    if(!listingAgentEditPanel)
    {
        listingAgentEditPanel = new YAHOO.widget.Panel("divListingAgentEdit-container", {    
	                                    modal: true, 
                                        fixedcenter: true, 
                                        close: true, 
                                        zindex: 0,
                                        draggable: false, 
                                        visible: false
			    }); 
			    
        listingAgentEditPanel.render(document.body);
    }
    
    listingAgentEditPanel.show();
}

function btnCancelListingAgentEdit_Click()
{
    logIt("edit", "canceled edit of listing agent " + $get("listingAgentName").innerHTML, "8");
    
    if(listingAgentEditPanel)
    {
        listingAgentEditPanel.hide();
    }
}

function btnSaveListingAgent_Click()
{
    logIt("edit", "saving edit of listing agent " + $get("listingAgentName").innerHTML, "8");
    $get("imgListingAgentSaving").style.display = "";
    $get("btnCancelListingAgentEdit").disabled = true;
    $get("btnSaveListingAgent").disabled = true;

    var agent = new Agent();
    agent.ID = $get("listingAgentID").innerHTML;
    agent.Name = $get("listingAgentName").innerHTML;
    agent.Office = $get("listingAgentOffice").innerHTML;
    
    if($get("listingAgentWorkEdit").value)
    {
        agent.WorkNumber = $get("listingAgentWorkEdit").value;
    }
    else
    {
        agent.WorkNumber = $get("listingAgentWork").innerHTML;
    }
    
    if($get("listingAgentCellEdit").value)
    {
        agent.CellNumber = $get("listingAgentCellEdit").value;
    }
    else
    {
        agent.CellNumber = $get("listingAgentCell").innerHTML;
    }
    
    if($get("listingAgentEmailEdit").value)
    {
        agent.EmailAddress = $get("listingAgentEmailEdit").value;
    }
    else
    {
        agent.EmailAddress = $get("listingAgentEmail").innerHTML;
    }
            
    PageMethods.SaveAgentInfo(agent, onSaveListingAgentComplete, onSaveListingAgentError);    
}

function getListingAgent()
{
    var agent = new Agent();
    agent.ID = $get("listingAgentID").innerHTML;
    agent.Name = $get("listingAgentName").innerHTML;
    agent.Office = $get("listingAgentOffice").innerHTML;
    agent.WorkNumber = $get("listingAgentWork").innerHTML;
    agent.CellNumber = $get("listingAgentCell").innerHTML;
    agent.EmailAddress = $get("listingAgentEmail").innerHTML;
    
    return agent;
}

function onSaveListingAgentComplete()
{
    logIt("edit", "Successful save of changes to listing agent " + $get("listingAgentName").innerHTML, "8");
    
    $get("listingAgentWork").innerHTML = $get("listingAgentWorkEdit").value;
    $get("listingAgentCell").innerHTML = $get("listingAgentCellEdit").value;
    $get("listingAgentEmail").innerHTML = $get("listingAgentEmailEdit").value;
    $get("listingAgentEmail").href = "mailto:" + $get("listingAgentEmailEdit").value;
    
    $get("imgListingAgentSaving").style.display = "none";
    
    listingAgentEditPanel.hide();
}

function onSaveListingAgentError(error)
{
    logIt("error", "error on save of listing agent " + $get("ListingAgentName").innerHTML, "8");
    alert(error.get_message());
    
    $get("imgListingAgentSaving").style.display = "none";
    $get("btnCancelListingAgentEdit").disabled = false;
    $get("btnSaveListingAgent").disabled = false;        
}

//seller
function btnEditSeller_Click()
{
    logIt("edit", "editing seller" + $get("sellerName").innerHTML, "9");
    $get("divSellerEdit-container").style.display="block";
    $get("btnCancelSellerEdit").disabled = false
    $get("btnSaveSeller").disabled = false;
    
    $get("sellerNameEdit").value = $get("sellerName").innerHTML;
    $get("sellerHomeEdit").value = $get("sellerHome").innerHTML;
    $get("sellerWork1Edit").value = $get("sellerWork1").innerHTML;
    $get("sellerCell1Edit").value = $get("sellerCell1").innerHTML;
    $get("sellerName2Edit").value = $get("sellerName2").innerHTML;
    $get("sellerWork2Edit").value = $get("sellerWork2").innerHTML;
    $get("sellerCell2Edit").value = $get("sellerCell2").innerHTML;
    $get("sellerEmailEdit").value = $get("sellerEmail").innerHTML;
    
    if(!sellerEditPanel)
    {
        sellerEditPanel = new YAHOO.widget.Panel("divSellerEdit-container", {    
	                                    modal: true, 
                                        fixedcenter: true, 
                                        close: true, 
                                        zindex: 0,
                                        draggable: false, 
                                        visible: false
			    }); 
			    
        sellerEditPanel.render(document.body);
    }
    
    sellerEditPanel.show();
}

function btnCancelSellerEdit_Click()
{
    logIt("edit", "cancel edit of seller" + $get("sellerName").innerHTML, "9");
    
    if(sellerEditPanel)
    {
        sellerEditPanel.hide();
    }
}

function btnSaveSeller_Click()
{
    logIt("edit", "saving seller" + $get("sellerName").innerHTML, "9");
    $get("imgSellerSaving").style.display = "";
    $get("btnCancelSellerEdit").disabled = true;
    $get("btnSaveSeller").disabled = true;

    var seller = getSeller();
    
    var listingAgent = getListingAgent();
            
    PageMethods.SaveSellerInfo(seller, listingAgent, onSaveSellerComplete, onSaveSellerError);    
}

function getSeller()
{
    var seller = new Seller();
    seller.MlsNumber = $get("propertyInfoMls").innerHTML;
    seller.Name = $get("sellerNameEdit").value;
    seller.HomePhoneNumber = $get("sellerHomeEdit").value;
    seller.WorkNumber1 = $get("sellerWork1Edit").value;
    seller.CellNumber1 = $get("sellerCell1Edit").value;
    seller.Name2 = $get("sellerName2Edit").value;
    seller.WorkNumber2 = $get("sellerWork2Edit").value;
    seller.CellNumber2 = $get("sellerCell2Edit").value;
    seller.EmailAddress = $get("sellerEmailEdit").value;
    
    return seller;
}

function onSaveSellerComplete()
{
    logIt("edit", "successful save of seller" + $get("sellerName").innerHTML, "9");
    
    $get("sellerName").innerHTML = $get("sellerNameEdit").value;
    $get("sellerHome").innerHTML = $get("sellerHomeEdit").value;
    $get("sellerWork1").innerHTML = $get("sellerWork1Edit").value;
    $get("sellerCell1").innerHTML = $get("sellerCell1Edit").value;
    $get("sellerName2").innerHTML = $get("sellerName2Edit").value;
    $get("sellerWork2").innerHTML = $get("sellerWork2Edit").value;
    $get("sellerCell2").innerHTML = $get("sellerCell2Edit").value;
    $get("sellerEmail").innerHTML = $get("sellerEmailEdit").value;
    $get("sellerEmail").href = "mailto:" + $get("sellerEmailEdit").value;
    
    $get("imgSellerSaving").style.display = "none";
    sellerEditPanel.hide();
}

function onSaveSellerError(error)
{
    logIt("error", "error saving seller" + $get("sellerName").innerHTML, "9");
    alert(error.get_message());
    
    $get("imgSellerSaving").style.display = "none";
    $get("btnCancelSellerEdit").disabled = false;
    $get("btnSaveSeller").disabled = false;        
}

//listing

function btnSearchMLS_Click()
{
    logIt("navigation", "searching listings intitiated" + $get("propertyInfoMls").innerHTML, "8");
    
    $get("divSearchMLS-container").style.display = "block";
    $get("divSearchButtons").style.display = "block";
    
    if(!mlsSearchPanel)
    {
        mlsSearchPanel = new YAHOO.widget.Panel("divSearchMLS-container", 
                                    {   
                                        modal: true, 
                                        fixedcenter: true, 
                                        close: true, 
                                        zindex: 0,
                                        draggable: false, 
                                        visible: false
                                    });  
                                    
        mlsSearchPanel.render(document.body);
    }
    
    mlsSearchPanel.show();
}

function checkEnter(area, event)
{
    if(event.keyCode == 13)
    {
        if(area == "searchMLS")
        {
            btnSearch_Click();
        }
        
        if(area == "searchShowingAgent")
        {
            btnAgentSearch_Click();
        }
    }
}

function btnClear_Click()
{
    $get("txtMLS").value = "";
    $get("txtStreetNbr").value = "";
    $get("txtStreetName").value = "";
    $get("txtCity").value = "";
    $get("txtZip").value = "";
    $get("txtArea").value = "";
}

function btnSearch_Click()
{
    logIt("navigation", "searching listings with criteria MLS: " + $get("txtMLS").value +
                      + " street nbr: " + $get("txtStreetNbr").value + " street: " + $get("txtStreetName").value
                      + " city: " + $get("txtCity").value + " zip: " + $get("txtZip").value
                      + " area: " + $get("txtArea").value, "9");
                      
    $get("divSearchParameters").style.display = "none";
    $get("divSearching").style.display = "";
    $get("divSearchResults").style.display = "none";
    $get("divSearchResults").innerHTML = "";
    $get("divSearchButtons").style.display = "none";
    
    //var div = $get("divSearch");
    //AjaxControlToolkit.Animation.ResizeAnimation.play(div, .2, 30, 550, 80, "px");
    
    PageMethods.FindListings($get("txtMLS").value,
                             $get("txtStreetNbr").value,
                             $get("txtStreetName").value,
                             $get("txtCity").value,
                             $get("txtZip").value,
                             $get("txtArea").value,
                             onFindListingsComplete,
                             onFindListingsError);
}

function onFindListingsError(error)
{
    logIt("error", "error searching listings", "3");
    $get("divSearchParameters").style.display = "";
    $get("divSearching").style.display = "none";
    $get("divSearchButtons").style.display = "";
        
    if(error.get_message().match("Maximum"))
    {
        alert("Too many values returned, please narrow down your search!");
    }
    else 
    {
        alert(error.get_message());
    }
}

function onFindListingsComplete(results)
{
    clearSchedule();
    clearListingAgentInfo();
    clearSellerInfo();
    clearListingInfo();
    
    btnCancelListingAgentEdit_Click();
    btnCancelSellerEdit_Click();
    
    //$get("divListingAgent").style.display = "none";
    //$get("divSellerInfo").style.display = "none";
    
    if(results.rows)
    {           
        if(results.rows[1])
        {
            createListingsTable(results);
        
            var div = $get("divSearchMLS-container");
            //AjaxControlToolkit.Animation.ResizeAnimation.play(div, .2, 30, 550, 300, "px");
        
            $get("divSearchResults").style.display = "";
            $get("divNewSearch").style.display = "";
            $get("divInstructions").style.display = "";
            
            $get("divSearching").style.display = "none";
        }
        else
        {
            currListing = results.rows[0].ListingID;            
            PageMethods.GetListingInfo(currListing, onGetListingInfoComplete, onErrorGeneric);                
        }
    }
    else
    {
        $get("divSearchParameters").style.display = "";
        $get("divSearching").style.display = "none";
        $get("divSearchButtons").style.display = "";
        alert("No results found!");
    }
}

function clearListingAgentInfo()
{
    //Listing agent spans
    $get("listingAgentID").innerHTML = "&nbsp;";
    $get("listingAgentName").innerHTML = "&nbsp;";
    $get("listingAgentOffice").innerHTML = "&nbsp;";
    $get("listingAgentWork").innerHTML = "&nbsp;";
    $get("listingAgentCell").innerHTML = "&nbsp;";
    $get("listingAgentEmail").innerHTML = "&nbsp;";
            
    //Listing agent textboxes
    $get("listingAgentIDEdit").innerHTML = "";
    $get("listingAgentNameEdit").innerHTML = "";
    $get("listingAgentWorkEdit").value = "";
    $get("listingAgentCellEdit").value = "";
    $get("listingAgentEmailEdit").value = "";
}

function clearSellerInfo()
{
    //Seller spans
    $get("sellerName").innerHTML = "&nbsp;";
    $get("sellerHome").innerHTML = "&nbsp;";
    $get("sellerWork1").innerHTML = "&nbsp;";
    $get("sellerCell1").innerHTML = "&nbsp;";
    $get("sellerName2").innerHTML = "&nbsp;";
    $get("sellerWork2").innerHTML = "&nbsp;";
    $get("sellerCell2").innerHTML = "&nbsp;";
    $get("sellerEmail").innerHTML = "&nbsp;";
    
    //Seller Textboxes
    $get("sellerNameEdit").value = "";
    $get("sellerHomeEdit").value = "";
    $get("sellerWork1Edit").value = "";
    $get("sellerCell1Edit").value = "";
    $get("sellerName2Edit").value = "";
    $get("sellerWork2Edit").value = "";
    $get("sellerCell2Edit").value = "";
    $get("sellerEmailEdit").value = "";
}

function clearListingInfo()
{
    $get("propertyInfoMls").innerHTML = "&nbsp;";
    $get("propertyInfoAddress").innerHTML = "&nbsp;";
    $get("propertyInfoArea").innerHTML = "&nbsp;";
    $get("propertyInfoStatus").innerHTML = "&nbsp;";
    //$get("lastStatus").innerHTML = "Not Active";
    $get("propertyInfoSaleRent").innerHTML = "&nbsp;";
    $get("propertyInfoType").innerHTML = "&nbsp;";
    $get("propertyInfoClass").innerHTML = "&nbsp;";
    $get("propertyInfoCityState").innerHTML = "&nbsp;";
    $get("propertyInfoListOrig").innerHTML = "&nbsp;";
    $get("propertyInfoListCurr").innerHTML = "&nbsp;";
    $get("propertyInfoCounty").innerHTML = "&nbsp;";
    $get("propertyInfoSqft").innerHTML = "&nbsp;";
    $get("propertyInfoPPSqft").innerHTML = "&nbsp;";
    $get("propertyInfoMarket").innerHTML = "&nbsp;";  
    $get("propertyInfoBeds").innerHTML = "&nbsp;";
    $get("propertyInfoYear").innerHTML = "&nbsp;";
    $get("propertyInfoFullBaths").innerHTML = "&nbsp;";
    $get("propertyInfoHalfBaths").innerHTML = "&nbsp;";
    $get("propertyInfoZip").innerHTML = "&nbsp;";
    $get("txtShowingInstructions").value = "";
    $get("txtAgentRemarks").value = "";
}

function createListingsTable(data)
{
    var dataSource = new YAHOO.util.DataSource(data.rows);
    dataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
    dataSource.responseSchema = {
        fields: ["ListingID","Address","City", "ListingStatus"]
    };

    var columnDefs = [
        {key:"ListingID", label:"Listing ID", sortable:"true"},
        {key:"Address", label:"Address", sortable:"true"},
        {key:"City", label:"City", sortable:"true"},
        {key:"ListingStatus", label:"Status", sortable:"true"}
    ];
    
    listingsTable = new YAHOO.widget.DataTable("divSearchResults", columnDefs, dataSource);
    
    listingsTable.set("selectionMode","single");
    listingsTable.subscribe("rowClickEvent", listingsTable.onEventSelectRow);
    listingsTable.subscribe("rowClickEvent", getListingInfo);
}

function getListingInfo(args)
{
    var record = listingsTable.getSelectedTrEls();
    
    currMls = record[0].childNodes[0].childNodes[0].innerHTML;      
    
    PageMethods.GetListingInfo(currMls, onGetListingInfoComplete, onErrorGeneric);
    
    //TODO: Add "Loading..." message
}

function onGetListingInfoComplete(results)
{
    $get("divSearching").style.display = "block";
    logIt("navigation", "successfully retrieved listing info for MLS " + results.Property.MlsNumber, "9");
    loadPropertyInfo(results.Property);
    loadListingAgentInfo(results.ListingAgent);
    loadSellerInfo(results.Seller);
    onDateChanged();
    
    $get("mlsPhoto1").src = "photos/carmls" + results.Property.MlsNumber + ".jpg";
    
    $get("txtShowingInstructions").value = results.ShowingInstructions;
    $get("txtAgentRemarks").value = results.AgentRemarks;
    
    $get("divSearchParameters").style.display = "";
    $get("divSearchResults").style.display = "none";
    $get("divNewSearch").style.display = "none";
    $get("divInstructions").style.display = "none";
    $get("divSearch").style.height = "150px";
    
    $get("btnEditSeller").style.display = "block";
    $get("btnEditListingAgent").style.display = "block";
    $get("divSchedule").style.display = "inline";
    
    $get("divSearching").style.display = "none";
    $get("schedule-container").style.display = "block";
    $get("schedule-containerInfo").style.display = "block";
    
    if(mlsSearchPanel)
    {
        mlsSearchPanel.hide();
    }
}

function loadPropertyInfo(property)
{
    $get("propertyInfoMls").innerHTML = property.MlsNumber;
    $get("propertyInfoAddress").innerHTML = property.Address;
    $get("propertyInfoArea").innerHTML = property.Area;
    $get("propertyInfoStatus").innerHTML = property.Status;
    //$get("lastStatus").innerHTML = property.Status;
    $get("propertyInfoSaleRent").innerHTML = property.SaleOrRent;
    $get("propertyInfoType").innerHTML = property.Type;
    $get("propertyInfoClass").innerHTML = property.Class;
    $get("propertyInfoCityState").innerHTML = property.City + ", " + property.State;
    $get("propertyInfoListOrig").innerHTML = property.OriginalListingPrice;
    $get("propertyInfoListCurr").innerHTML = property.ListingPrice
    $get("propertyInfoCounty").innerHTML = property.County;
    if(property.SquareFootage)
    {
        $get("propertyInfoSqft").innerHTML = property.SquareFootage;
    }
    $get("propertyInfoPPSqft").innerHTML = property.ppSquareFootage;
    $get("propertyInfoMarket").innerHTML = property.Market;    
    
    if(property.NumberOfBeds !== 0)
    {
        $get("propertyInfoBeds").innerHTML = property.NumberOfBeds;
    }
    
    if(property.YearBuilt !== 0)
    {
        $get("propertyInfoYear").innerHTML = property.YearBuilt;
    }
    
    if(property.NumberOfFullBaths !== 0)
    {
        $get("propertyInfoFullBaths").innerHTML = property.NumberOfFullBaths;
    }
    
    if(property.NumberOfHalfBaths !== 0)
    {
        $get("propertyInfoHalfBaths").innerHTML = property.NumberOfHalfBaths;
    }
    
    if(property.Zip !== 0)
    {
        $get("propertyInfoZip").innerHTML = property.Zip;
    }
}

function loadListingAgentInfo(listingAgent)
{
    $get("listingAgentID").innerHTML = listingAgent.ID;
    $get("listingAgentName").innerHTML = listingAgent.Name;
    $get("listingAgentOffice").innerHTML = listingAgent.Office;
    $get("listingAgentWork").innerHTML = listingAgent.WorkNumber;
    $get("listingAgentCell").innerHTML = listingAgent.CellNumber;
    $get("listingAgentEmail").innerHTML = listingAgent.EmailAddress;
    $get("listingAgentEmail").href = "mailto:" + listingAgent.EmailAddress;
}

function loadSellerInfo(seller)
{
    $get("sellerName").innerHTML = seller.Name;
    $get("sellerHome").innerHTML = seller.HomePhoneNumber;
    $get("sellerWork1").innerHTML = seller.WorkNumber1;
    $get("sellerCell1").innerHTML = seller.CellNumber1;
    $get("sellerName2").innerHTML = seller.Name2;
    $get("sellerWork2").innerHTML = seller.WorkNumber2;
    $get("sellerCell2").innerHTML = seller.CellNumber2;
    $get("sellerEmail").innerHTML = seller.EmailAddress;
    $get("sellerEmail").href = "mailto:" + seller.EmailAddress;
}

function btnCloseMLS_Click()
{
    btnNewSearch_Click();
    $get("divSearchMLS").style.display = "none";
}
function btnNewSearch_Click()
{
    logIt("navigagtion", "new listing search clicked", "9");
    $get("divNewSearch").style.display = "none";    
    $get("divSearchButtons").style.display = "block";
    $get("divSearchParameters").style.display = "";
    $get("divSearchResults").style.display = "none";
    $get("divNewSearch").style.display = "none";
    $get("divInstructions").style.display = "none";
    $get("divSearch").style.height = "150px";
}

function showingInstructions_Click()
{
    logIt("edit", "editing showing instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    showingInstructions = $get("txtShowingInstructions").innerHTML;

    $get("btnCancelShowingInstructions").style.display = "";
    $get("btnSaveShowingInstructions").style.display = "";
    
    $get("txtShowingInstructions").focus();
}

function btnCancelShowingInstructions_Click()
{
    logIt("edit", "canceled edit of showing instructions for MLS " + $get("propertyInfoMls").innerHTML, "9");
    
    $get("btnCancelShowingInstructions").style.display = "none";
    $get("btnSaveShowingInstructions").style.display = "none";
    
    $get("txtShowingInstructions").innerHTML = showingInstructions;
}

function btnSaveShowingInstructions_Click()
{
    logIt("edit", "saving edit of showing instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");

    var showingInstructions = $get("txtShowingInstructions").value;
    var listingAgent = getListingAgent();
    
    PageMethods.SaveShowingInstructions(showingInstructions, $get("propertyInfoMls").innerHTML, listingAgent, 
        onSaveShowingInstructionsComplete, onErrorGeneric);
}

function onSaveShowingInstructionsComplete(results)
{
    logIt("edit", "successful save of showing instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    showingInstructions = "";
    
    $get("btnCancelShowingInstructions").style.display = "none";
    $get("btnSaveShowingInstructions").style.display = "none";
}

function agentRemarks_Click()
{
    logIt("edit", "editing agent instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    
    agentRemarks = $get("txtAgentRemarks").innerHTML;
    
    $get("btnCancelAgentRemarks").style.display = "";
    $get("btnSaveAgentRemarks").style.display = "";
    
    $get("txtAgentRemarks").focus();
}

function btnCancelAgentRemarks_Click()
{
    logIt("edit", "canceled edit of agent instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    
    $get("btnCancelAgentRemarks").style.display = "none";
    $get("btnSaveAgentRemarks").style.display = "none";
    
    $get("txtAgentRemarks").innerHTML = agentRemarks;
}

function btnSaveAgentRemarks_Click()
{
    logIt("edit", "saving edit of agent instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    
    var agentRemarks = $get("txtAgentRemarks").value;
    var listingAgent = getListingAgent();
    
    PageMethods.SaveAgentRemarks(agentRemarks, $get("propertyInfoMls").innerHTML, listingAgent, 
        onSaveAgentRemarksComplete, onErrorGeneric);
}

function onSaveAgentRemarksComplete(results)
{
    logIt("edit", "successful edit of agent instructions for MLS " + $get("propertyInfoMls").innerHTML, "8");
    
    agentRemarks = "";

    $get("btnCancelAgentRemarks").style.display = "none";
    $get("btnSaveAgentRemarks").style.display = "none";
}

function statusChanged(newValue)
{
    if($get("propertyInfoMls").innerHTML != "&nbsp;")
    {
        if(confirm("Change Status for MLS " + $get("propertyInfoMls").innerHTML + "?"))
        {
            logIt("edit","status changed from " + $get("lastStatus").innerHTML + " to " + newValue + " for MLS " + $get("propertyInfoMls").innerHTML, "8");    
            PageMethods.SaveStatus(newValue, $get("propertyInfoMls").innerHTML, $get("listingAgentName").innerHTML, $get("listingAgentOffice").innerHTML, onStatusChangeComplete, onErrorGeneric);
        }
        else 
        {
            $get("propertyInfoStatus").value = $get("lastStatus").innerHTML;
        }
    }
}

function onStatusChangeComplete(results)
{
    $get("lastStatus").innerHTML = get("propertyInfoStatus").value;
    logIt("edit","status successfully changed to " + newValue + " for MLS " + $get("propertyInfoMls").innerHTML, "8");
    
}
////////////////// Listings Complete //////////////////////

//--------------------Schedule---------------------------//
function getPreviousAppointments()
{
    var oneMinute = 60 * 1000  // milliseconds in a minute
    var oneHour = oneMinute * 60
    var oneDay = oneHour * 24

    var dateInMS = currDate.getTime() - oneDay //??needs to subtract from value provided
    currDate = new Date(dateInMS)

    $get("ctl00_ContentPlaceHolder1_txtApptDate").value = getDateString(currDate);
    
    onDateChanged();
}

function getNextAppointments()
{
    var oneMinute = 60 * 1000  // milliseconds in a minute
    var oneHour = oneMinute * 60
    var oneDay = oneHour * 24

    var dateInMS = currDate.getTime() + oneDay
    currDate = new Date(dateInMS)

    $get("ctl00_ContentPlaceHolder1_txtApptDate").value = getDateString(currDate);
    
    onDateChanged();
}

function btnCalToday_Click()
{
    currDate = new Date();
    $get("ctl00_ContentPlaceHolder1_txtApptDate").value = getDateString(currDate);  
    
    onDateChanged();
}

function clearSchedule()
{
    var i=0;
    while($get("divAppointmentButtons").childNodes[i])
    {
        var button = $get("divAppointmentButtons").childNodes[i];
        if(button.style)
        {
            var appt = new Date($get("ctl00_ContentPlaceHolder1_txtApptDate").value);
            var today = new Date();
            var todayDate = (today.getFullYear() * 100 + today.getMonth() + 1) * 100 + today.getDate();
            var apptDate = (appt.getFullYear() * 100 + appt.getMonth() + 1) * 100 + appt.getDate();
            
            var hour = today.getHours();
            var apptTime = button.id.replace(/BtnSched/,"").replace(/_/,":");
            var apptHour = apptTime.split(':')[0];
            var apptPM = new RegExp("pm$");
            
            if(apptPM.test(apptTime) && apptHour != 12)
            {
                apptHour = (parseInt(apptHour) + 12);
            }            
            
            //alert("apptDate=" + apptDate + "\ntodayDate=" + todayDate + "\nhour=" + hour + "\napptHour=" + apptHour);
             
            if(apptDate < todayDate || (apptDate == todayDate && hour > parseInt(apptHour) + 2))
            {
                button.style.backgroundColor = "Gainsboro";
            }
            else
            {
                button.style.backgroundColor = "Green";
            }
        }
        button.title = "";
        i++;   
    }
}

function onDateChanged()
{    
    //TODO: disable Appointments if time has passed
    clearSchedule();
    PageMethods.decorateSchedule($get("ctl00_ContentPlaceHolder1_txtApptDate").value, $get("propertyInfoMls").innerHTML, onScheduleDecoSuccess, onErrorGeneric);
}

function onScheduleDecoSuccess(results)     
{   
    if(results[0])
    {
        if(results[0].substring(0,28) == "The following error occurred")
        {
            alert("results");
        }
        else
        { 
            var i=0;
            
            while(results[i])
            {
                var data = results[i].split(",");
                $get(data[0]).style.backgroundColor = data[2];
                $get(data[0]).title = data[1];
                i++;
            }
        }
    }
}

function btnCloseAppt_Click()
{
    logIt("navigation", "closed appointment window", "9");
    btnNewAppt_Click();
    if(appointmentPanel)
    {
        appointmentPanel.hide();
    }
}

function btnCancelAppt_Click()
{
    $("#divAppointmentFT").fadeOut();
    logIt("edit", "cancelling appointment " + $get("lblApptNumber").innerHTML + " for MLS " + $get("lblPropertyMLS").innerHTML, "4");
    if($get("lblApptNumber").innerHTML > 0)
    {
        var confirmed = confirm("Are you sure you want to cancel this appointment?");
        if(confirmed)
        {
            PageMethods.CancelAppointment($get("lblApptNumber").innerHTML, $get("ddlApptStatus").options[$get("ddlApptStatus").selectedIndex].text, 
                                          $get("lblPropertyMLS").innerHTML, $get("ctl00_LblAgentName").innerHTML,
                                          onCancelApptSuccess, onErrorGeneric);
        }
    }
    else
    {
        btnCloseAppt_Click();
    }
}

function onCancelApptSuccess(results)
{
    logIt("edit", "successful cancel of appointment " + $get("lblApptNumber").innerHTML + " for MLS " + $get("lblPropertyMLS").innerHTML, "4");
    
    if(results)
    {
        alert(results);
    }
    
    onDateChanged();
    btnCloseAppt_Click();
}

function appointmentDetails_Click(id)
{   
    $("#divAppointmentFT").fadeIn();
    logIt("navigation", "clicked find show appointment button" + id, "9");
    
    btnCloseAppt_Click();
    colorApptPanel(id);
    fillApptDetails(id);  
    
    $get("divAppointment-container").style.display = "block";
   
    appointmentPanel = new YAHOO.widget.Panel("divAppointment-container", {    
                                    modal: true, 
                                    fixedcenter: true, 
                                    close: true, 
                                    zindex: 0,
                                    draggable: false, 
                                    visible: false      }); 
		    
    appointmentPanel.render(document.body);   
    
    appointmentPanel.show();  
    
}

function colorApptPanel(id)
{

}

function colorApptPanel_old(id)
{
    if($get(id).style.backgroundColor.toLowerCase() == "old")
    {
        $get("divAppointment-container").className = "popupGold-container";
        $get("divAppointmentHD").className = "popupGold-container-hd";
        $get("divAppointmentBD").className = "popupGold-container-bd";
        $get("divAppointmentFT").className = "popupGold-container-ft";
        $get("divAppointment-container").style.backgroundColor = "#ffffd9";
    }    
    else if($get(id).style.backgroundColor.toLowerCase() == "rangered")
    {
        $get("divAppointment-container").className = "popupRed-container";
        $get("divAppointmentHD").className = "popupRed-container-hd";
        $get("divAppointmentBD").className = "popupRed-container-bd";
        $get("divAppointmentFT").className = "popupRed-container-ft";
        $get("divAppointment-container").style.backgroundColor = "#fba2a2";
    }
    else if($get(id).style.backgroundColor.toLowerCase() == "ainsboro")
    {
        $get("divAppointment-container").className = "popupGrey-container";
        $get("divAppointmentHD").className = "popupGrey-container-hd";
        $get("divAppointmentBD").className = "popupGrey-container-bd";
        $get("divAppointmentFT").className = "popupGrey-container-ft";
        $get("divAppointment-container").style.backgroundColor = "#dddddd";
    }
    else
    {
        $get("divAppointment-container").className = "popupGreen-container";
        $get("divAppointmentHD").className = "popupGreen-container-hd";
        $get("divAppointmentBD").className = "popupGreen-container-bd";
        $get("divAppointmentFT").className = "popupGreen-container-ft";
        $get("divAppointment-container").style.backgroundColor = "#badcbb";
    }
    
}

function fillApptDetails(id)
{
    
    $get("lblApptTime").innerHTML = id.toString().replace("BtnSched","").replace("_",":");    
    
    logIt("navigation", "requesting to open appointment for mls " + $get("propertyInfoMls").innerHTML + " on " 
          + $get("ctl00_ContentPlaceHolder1_txtApptDate").value + " at " + $get("lblApptTime").innerHTML, "9");
          
    PageMethods.GetAppointmentDetails(id, $get("propertyInfoMls").innerHTML, $get("ctl00_ContentPlaceHolder1_txtApptDate").value, 
                                             onGetApptDetailsSuccess, onErrorGeneric);
}

function onGetApptDetailsSuccess(results)
{
    if(results)
    {
        logIt("edit", "successfully opened existing appointment " + results.ApptNumber, "9");
        //ApptNumber, StartTime, OwnerContact, Description, Duration, ShowingAgent
        $get("lblPropertyMLS").innerHTML = $get("propertyInfoMls").innerHTML;
        $get("lblApptDate").innerHTML = $get("ctl00_ContentPlaceHolder1_txtApptDate").value;
        $get("lblApptTime").innerHTML = results.StartTime;
        $get("lblShowingAgentName").innerHTML = results.ShowingAgentName;
        $get("lblShowingAgentID").innerHTML = results.ShowingAgentID;
        $get("lblShowingAgentAgency").innerHTML = results.OfficeName;
        $get("lblShowingAgentCell").innerHTML = results.AgentCell;
        $get("lblShowingAgentEmail").innerHTML = results.AgentEmail;
        $get("lblApptNumber").innerHTML = results.ApptNumber;
        
        for(var a=0;a<$get("ddlDuration").options.length;a++)
        {
            if($get("ddlDuration").options[a].text == results.Duration)
            {
                $get("ddlDuration").selectedIndex = a;
            }
        }
        
        for(var b=0;b<$get("ddlApptStatus").options.length;b++)
        {
            if($get("ddlApptStatus").options[b].text == results.OwnerContact)
            {
                $get("ddlApptStatus").selectedIndex = b;
            }
        }
        
        $get("txtApptDesc").value = results.Description;
    }
    else
    {
        logIt("edit", "opening new appointment for" + $get("ctl00_ContentPlaceHolder1_txtApptDate").value + " at " + $get("lblApptTime").innerHTML, "9");
        $get("lblPropertyMLS").innerHTML = $get("propertyInfoMls").innerHTML;
        $get("lblApptDate").innerHTML = $get("ctl00_ContentPlaceHolder1_txtApptDate").value;
        $get("lblShowingAgentName").innerHTML = $get("agentName").innerHTML;
        $get("lblShowingAgentID").innerHTML = $get("agentID").value;
        $get("lblShowingAgentCell").innerHTML = $get("agentCell").innerHTML;
        $get("lblShowingAgentAgency").innerHTML = $get("agentOffice").innerHTML;
        $get("lblShowingAgentEmail").innerHTML = $get("agentEmail").innerHTML;
    }
}

function btnNewAppt_Click()
{
    $get("lblApptNumber").innerHTML = "";
    $get("lblPropertyMLS").innerHTML = "";
    $get("lblApptDate").innerHTML = "";
    $get("lblApptTime").innerHTML = "";
    $get("lblShowingAgentName").innerHTML = "";
    $get("lblShowingAgentID").innerHTML = "";
    $get("lblShowingAgentCell").innerHTML = "";
    $get("lblShowingAgentAgency").innerHTML = "";
    $get("lblShowingAgentEmail").innerHTML = "";
    $get("txtApptDesc").value = "";
    $get("ddlDuration").selectedIndex = 0;
    $get("ddlApptStatus").selectedIndex = 0;
	$get("agentEmail").innerHTML = "";
}

function btnApptSave_Click()
{
    $("#divAppointmentFT").fadeOut();
    logIt("edit", "attempting to save appointment at " + $get("ctl00_ContentPlaceHolder1_txtApptDate").value + " at " + $get("lblApptTime").innerHTML, "9");
    
    if($get("lblShowingAgentName").innerHTML)
    {
        PageMethods.SaveAppointment($get("ddlDuration").options[$get("ddlDuration").selectedIndex].text, 
                                    $get("lblApptTime").innerHTML, 
                                    $get("ddlApptStatus").options[$get("ddlApptStatus").selectedIndex].text, 
                                    $get("lblPropertyMLS").innerHTML, $get("lblApptDate").innerHTML, 
                                    $get("lblShowingAgentID").innerHTML, $get("txtApptDesc").value, $get("ctl00_LblAgentName").innerHTML, 
                                    $get("lblApptNumber").innerHTML, $get("listingAgentEmail").innerHTML, $get("agentEmail").innerHTML, 
                                    $get("agentCell").innerHTML, $get("agentWork").innerHTML, onApptSaveSuccess, onErrorGeneric);
    }
    else
    {
        logIt("user error", "attempted to save appointment without showing agent", "4");
        alert("Can't create appointment without Showing Agent selected!");
    }
}


function onApptSaveSuccess(results)
{
    logIt("edit", "appointment successfully saved", "9");
    onDateChanged();   
    btnCloseAppt_Click();
    alert("Save Successful");
    clearShowingAgentInfo();
}

////////////////// Scheduled Ends ///////////////////////////

function logIt(type, desc, sev)
{
    PageMethods.Logger(type, desc, sev, null, null);
}