﻿/// <changes>
/// 2008-07-04  IC      Added function ProcessError for handled ajax error
/// 2008-07-21  SS      Added logic for get form text for breadcrumb.
/// 2008-08-12  SS      Added valores[0].Value to get the text value of input
/// 2008-08-13  SS      Prevent bad data
/// 2008-10-06  SS      Increment index of search string added area geof
/// 2008-10-14	EF		Remove the "searchTextValues" and related parameters.
/// 2009-03-19	EF		Remember selected advertisements.
/// </changes>
// JScript File

function BusquedaInterna(save)
{
    if(typeof(save)=="undefined")
        save = false;
    if(validateFormFields())
    {
        var valores = getFormValues();
//        var sBusqueda = valores[0].Valor + sSss + valores[1].Valor + sSss + valores[2].Valor + sSss + valores[3].Valor + sSss + valores[4].Valor + sSss + valores[5].Valor;
        var sBusqueda = sSss + escapeSearchString(valores[0].Valor.substring(2,valores[0].Valor.length)) + sSss + valores[1].Valor + sSss + valores[2].Valor + sSss + valores[3].Valor + sSss + valores[4].Valor + sSss + valores[5].Valor + sSss + valores[6].Valor;
        // 2008-10-06   SS      Increment index of search string added area geof
        for(var i = 7; i < valores.length; i++)
//        for(var i = 6; i < valores.length; i++)
        {
            if(valores[i].Valor!=null)
            {
                if(typeof(valores[i].Valor)!='string')
                    for(var j = 0; j < valores[i].Valor.length; j++)
                        sBusqueda += sSss + valores[i].idCampo + sSss + valores[i].Operacion + sSss + valores[i].Valor[j];
                else if(valores[i].Valor!='')
                    sBusqueda += sSss + valores[i].idCampo + sSss + valores[i].Operacion + sSss + valores[i].Valor;
            }
        }
        
//        var selectedAndUnselectedItems = CargarSeleccionadosYDeseleccionados(idsAvisos, nStep);

        //2008-07-21    SS      Added logic for get form text for breadcrumb sBusquedaTextValues.
        Controls_Form_BusquedaInterna.Buscar(arraySelecciones.length!=0 ? arraySelecciones[arraySelecciones.length-1] : idCategoriaInicialEnc, 
            sBusqueda, 
            '', //selectedAndUnselectedItems[0],  // Selected items
            '', //selectedAndUnselectedItems[1],  // Unselected items
            true, //false,                          // Do not clear selection
            Redirect_callback);
    }
}
function Redirect_callback(res){    
      
    if (res.error != null)
        ProcessError(res);
    else
        document.location.href = res.value;   
}
function Error_callback(res){            
    if (res.error != null)
        ProcessError(res);
        //a=1;//alert(res.error.Message);;
}


