//===================================================
// "What If" pane manager object.
//===================================================
function WIPaneMgr() {
    this.mod_method      = '';
    this.mod_processed   = false;
    this.mod_reset       = '';
    this.header_text     = '';
    this.headers         = {
        'closed'    : '',
        'open'      : '',
        'open_mod'  : ''
    }
    this.valuation_hi    = '';
    this.valuation_low   = '';
    this.ico_src_open    = '';
    this.ico_src_close   = '';
    this.div_elts        = {
        'header'                : 'hval_whatif_pane_header',
        'button_toggle'         : 'hval_whatif_pane_btn',
        'content'               : 'hval_whatif_pane_content',
        'form'                  : 'frmHValWhatIf',
        'form_reset'            : 'frmReset',
        'field_livingarea'      : 'mod_livingarea',
        'field_msg_livingarea'  : 'mod_livingarea_err_msg'
    }
}
//===================================================
//  Methods
//===================================================
WIPaneMgr.prototype.setup = function() {
    this.headers['open']        = this.headers['open'] + this.header_text;
    this.headers['open_mod']    = this.header_text + this.headers['open_mod'];
    this.icon_open       = '<a href="javascript: oWIPaneMgr.toggleWhatIf(true);">' + this.ico_src_open + '</a>';
    this.icon_closed     = '<a href="javascript: oWIPaneMgr.toggleWhatIf(false);">' + this.ico_src_close + '</a>';
    this.mod_processed   = ( this.mod_method.toLowerCase() == 'post' || this.mod_method.toLowerCase() == 'get' ? true : false );
    // Initial display.
    this.toggleWhatIf(this.mod_processed);
}
//===================================================
WIPaneMgr.prototype.toggleWhatIf = function (show) {
    //debugger;
    var bShow = ( show || this.mod_reset == 'true' );
    // Reset mod_reset so subsequent toggles do not consider the initial reset.
    this.mod_reset = 'false';
    // Display appropriate content...where appropriate.
    document.getElementById(this.div_elts['header']).innerHTML = ( bShow ? ( this.mod_processed ? this.headers['open_mod'] : this.headers['open']) : this.headers['closed'] );
    document.getElementById(this.div_elts['button_toggle']).innerHTML = ( bShow ? this.icon_closed : this.icon_open );
    this.toggleDisplay(bShow);
}
//===================================================
WIPaneMgr.prototype.toggleDisplay = function(show) {
    if ( document.getElementById(this.div_elts['content']) != null )
    {
        document.getElementById(this.div_elts['content']).style.display = ( show ? 'block' : 'none' );
    }
}
//===================================================
WIPaneMgr.prototype.submitModifiedValuation = function() {
    var oForm = document.getElementById(this.div_elts['form']);
    var strLivingArea = oForm[this.div_elts['field_livingarea']].value;
    if ( this.isNumericFieldValid(strLivingArea) ) {
        // Remove any querystring data that might be present (ex: STF email link).
        oForm.action = document.location.href.replace(document.location.search, '');
        //debugger;
        DCSext=new Object();
        dcsMultiTrack('DCSext.tag_hval_aid', tracking_obj.aid , 'DCSext.tag_hval_zip', tracking_obj.zip , 'WT.cg_n', 'AgentView' , 'WT.cg_s', 'HomeValuesRecalc;HomeValuesTab' );
        oForm.submit();
    } else {
        document.getElementById('mod_livingarea_err_msg').innerHTML = "Please enter an integer.";
        setTimeout("document.getElementById('mod_livingarea_err_msg').innerHTML = ''", 4000);
        return false;
    }   
}
//===================================================
WIPaneMgr.prototype.isNumericFieldValid = function(field_val) {
    // Return false if there are non-numeric characters.
    intNonNumPos = field_val.search(/[^\d]+/ig)
    return ( intNonNumPos == -1 );
}
//===================================================
WIPaneMgr.prototype.resetValuation = function() {
    var oForm = document.getElementById(this.div_elts['form_reset']);
    // Remove any querystring data that might be present (ex: STF email link).
    oForm.action = document.location.href.replace(document.location.search, '');
    oForm.submit();
}
//===================================================
