/*************************************************
This script relies on functions within popup-dialog.js.  
That file need also be included for this to work.
************************************************/
//Preload
var icon = new Image();
icon.src = '/images/icon_warning_triangle.gif';            
var okOver = new Image();
okOver.src = '/images/btn_OK_hover.gif';            
var cancelOver = new Image();
cancelOver.src = '/images/btn_cancel_hover.gif';

//Save Parameters
var okButton = new Array('/images/btn_OK.gif','/images/btn_OK_hover.gif', 'confirmSave');
var cancelButton = new Array('/images/btn_cancel.gif','/images/btn_cancel_hover.gif', 'cancel');
var buttons = new Array(okButton, cancelButton);

//Cancel Parameters
var deleteOkButton = new Array('/images/btn_OK.gif','/images/btn_OK_hover.gif', 'confirmDelete');
var deleteCancelButton = new Array('/images/btn_cancel.gif','/images/btn_cancel_hover.gif', 'cancel');
var deleteButtons = new Array(deleteOkButton, deleteCancelButton);

//Called to confirm a save, using a popup when necessary
function selectSubmitButton(){
    //notLoggedInButton
    //hasSavedSearchButton
    //noSavedSearchButton
    
    var notLoggedInButton = document.getElementById("listingForm:notLoggedInButton");
    var hasSavedSearchButton = document.getElementById("listingForm:hasSavedSearchButton");
    var noSavedSearchButton = document.getElementById("listingForm:noSavedSearchButton");
    
    var button = null;
    if(notLoggedInButton){
        //Not logged in.  Send to login screen
        notLoggedInButton.click();
    }else if(hasSavedSearchButton){
        //Logged in and has saved search.  See if they want to overwrite it.
        createPopup('Overwrite Saved Search?','', 380, 240, true, true, true, false, getSavedSearchBody());
    }else if(noSavedSearchButton){
        //Logged in, no saved search.  Save the search
        noSavedSearchButton.click();
    }
}

//Called to confirm a deletion, using a popup
function showConfirmDeletePopUp(){
    createPopup('Delete Saved Search?','', 380, 240, true, true, true, false, getDeleteSearchBody());                
}

//Callback method to close the popup and submit the form, for a delete
function confirmDelete(){
    closePopup();
    var deleteSearchButton = document.getElementById("listingForm:deleteSavedSearchButton");
    deleteSearchButton.click();
}     
//Callback method to close the popup and submit the form, for a save
function confirmSave(){
    closePopup();
    var hasSavedSearchButton = document.getElementById("listingForm:hasSavedSearchButton");
    var noSavedSearchButton = document.getElementById("listingForm:noSavedSearchButton");
    var button = null;
    if(hasSavedSearchButton){
        button = hasSavedSearchButton;
    }else if(noSavedSearchButton){
        button = noSavedSearchButton;
    }
    button.click();
}
//Callback method to close the popup and cancel the form
function cancel(){
    closePopup();
}