﻿/*var prm = parent.Sys.WebForms.PageRequestManager.getInstance();
if (prm!=null)
{
    prm.add_initializeRquest(initializeRequest);
}


function initialiseRequest(sender, args)
{
    if (prm.get_isInAsyncPostBack())
        args.set_cancel(true);
}

*/

function setCustomFieldDisplay(chkBoxPref, ControlPrefix, CSVFieldName) {

    if (chkBoxPref.checked) {
        //Display the Opitions ComboBox and try select the Matching Value... 
        igcmbo_getComboById(ControlPrefix + '_wbcOptions').Element.disabled=false;
        igcmbo_getComboById(ControlPrefix + '_wbcOptions').Element.style.display='block';
        //we want to now see if we can find a value in the grid that corresponds to our Option
        var combo = igcmbo_getComboById(ControlPrefix+ '_wbcOptions');
        // get grid reference from webcombo
        var grid = combo.getGrid();
        // get all rows in Grid
        var rows = grid.Rows;
        if (CSVFieldName != '')
        {
                //Loop through all the rows and see if we can find a value hat corresponds to the CSVFieldName
                combo.setDataValue(CSVFieldName, false);
        }
        else
        {
             //Loop through all the rows and see if we can find a value hat corresponds to the CSVFieldName
             combo.setDataValue('IGNORE', false);
        }
        if (combo.getSelectedIndex() == -1)
            combo.setDataValue('CREATE', false);       
        // disable the WebCombo Control
        igcmbo_getComboById(ControlPrefix+ '_wbcMapTo').Element.disabled=true;
        igcmbo_getComboById(ControlPrefix+ '_wbcMapTo').Element.style.display='none';
        //check and disable the "Required" Checkbox
        document.getElementById(ControlPrefix +'_chkRequired').checked = true;
        document.getElementById(ControlPrefix +'_chkRequired').disabled = true;
        //Disable the Default Value TextBox & set vale yo "N/A"
        document.getElementById(ControlPrefix +'_txtDefaultText').value = '';
        document.getElementById(ControlPrefix +'_txtDefaultText').disabled = true;
        //Clear the field Tag Label... 
        document.getElementById(ControlPrefix +'_lblTag').style.display = 'none';
        //
    }
    else
    {
         // enable the WebCombo Control
        igcmbo_getComboById(ControlPrefix+ '_wbcMapTo').Element.disabled=false;
        igcmbo_getComboById(ControlPrefix+ '_wbcMapTo').Element.style.display='block';
        //Hide the WebOptions Control - Set its Value back to "IGNORE"
        igcmbo_getComboById(ControlPrefix+ '_wbcOptions').Element.disabled=true;
        igcmbo_getComboById(ControlPrefix+ '_wbcOptions').Element.style.display='none';
        var combo = igcmbo_getComboById(ControlPrefix + '_wbcMapTo');
        // get grid reference from webcombo
        var grid = combo.getGrid();
        // get all rows in Grid
        var rows = grid.Rows;
        if (CSVFieldName != '') {
            //Loop through all the rows and see if we can find a value hat corresponds to the CSVFieldName
            combo.setDataValue(CSVFieldName, false);
        }
        else {
            //Loop through all the rows and see if we can find a value hat corresponds to the CSVFieldName
            combo.setDataValue('IGNORE', false);
        }
        if (combo.getSelectedIndex() == -1)
            combo.setDataValue('IGNORE', false); 
        //check and disable the "Required" Checkbox
        document.getElementById(ControlPrefix +'_chkRequired').checked = false;
        document.getElementById(ControlPrefix +'_chkRequired').disabled = false;
        //Disable the Default Value TextBox & set vale yo "N/A"
        document.getElementById(ControlPrefix +'_txtDefaultText').value = '';
        document.getElementById(ControlPrefix +'_txtDefaultText').disabled = false;
        //populate the Field Tag Label... 
        //Get the "Tag" value from the Combo Box
        document.getElementById(ControlPrefix + '_lblTag').style.display = 'block';
    }
}

function swapReason(FilterName) {
    var img = document.getElementById("img" + FilterName);
    var tbl = document.getElementById("tblReason" + FilterName);
    if (img.src.indexOf('plus.gif') > -1) {
        //Expand the table
        tbl.style.display = 'block';
        img.src = '../../../../../../App_Themes/Reportmail8/res/img/minus.gif';
    }
    else {
        //collapse the table
        tbl.style.display = 'none';
        img.src = '../../../../../../App_Themes/Reportmail8/res/img/plus.gif';
    }
}

function WebCombo_AfterSelectChanged(webComboID)
{
    // get the combo from the passed-in id
    var combo = igcmbo_getComboById(webComboID);
    // get the currently selected row in webcombo
    var index = combo.getSelectedIndex();
    // get grid reference from webcombo
    var grid = combo.getGrid();
    // get selected row in grid
    var row = grid.Rows.getRow(index);
    // get cell values in row
    var Tag = row.getCell(1).getValue();
    var FieldName= row.getCell(0).getValue();
    var ControlPrefix = webComboID.replace('wbcMapTo', '').replace('x', '_').replace('x', '_').replace('x', '_');
    var TagControlID = ControlPrefix + 'lblTag';
    if (FieldName == 'Email Address')
    {
        //Set the required field to True...
        document.getElementById(ControlPrefix + 'chkRequired').disabled = true;
        document.getElementById(ControlPrefix + 'chkRequired').checked = true;
        document.getElementById(ControlPrefix + 'txtDefaultText').disabled = true;
        document.getElementById(ControlPrefix + 'txtDefaultText').value = "N/A";
    }
    else
    {
        document.getElementById(ControlPrefix + 'chkRequired').disabled = false;
        document.getElementById(ControlPrefix + 'chkRequired').checked = false;
        document.getElementById(ControlPrefix + 'txtDefaultText').disabled = false;
        document.getElementById(ControlPrefix + 'txtDefaultText').value = "";
    }
    
    if (Tag != null)
    {
       document.getElementById(TagControlID).innerHTML = Tag;
    }
    else
    {
        if (FieldName != 'CREATE' && FieldName != 'IGNORE' && FieldName !='Email Format')
            document.getElementById(TagControlID).innerHTML = '{'+ FieldName +'}';
        else
        {
            if (FieldName == 'CREATE')
            {
                document.getElementById(TagControlID).innerHTML = '{' + document.getElementById(ControlPrefix + 'lblCSVName').innerHTML.replace(/ /g, '_') + '}';
            }
            else {
                document.getElementById(TagControlID).innerHTML = ' ';
            }
        }
    }
}
