﻿Buscar= function (callbackID,
					clientID,
                    id,
                    url
                    ) {
    this._callbackID = callbackID;
    this._clientID = clientID;
    this._id = id;
    this._url = url;
    this._clickHandler = Function.createDelegate(this, this._onClick);
    this._enterHandler = Function.createDelegate(this, this._onEnter);
    this.initialize();
}

Buscar.prototype = {
    initialize: function () {

        var elt = $('#' + this._clientID + '_button');        
        elt.bind('click', this._clickHandler);
        
        var elt1 = $('#' + this._clientID + '_textfield');        
        elt1.bind('keypress', this._enterHandler);
        
        //this._update();

    },

    dispose: function () {
        var elt = $('#' + this._clientID + '_button');
        elt.unbind('click', this._clickHandler);
    },

    _onError: function (message, context) {
       // alert(message);
    },

    _receiveServerData: function (arg, context) {

    },

    _update: function () {

    },
	_irBuscador: function () {
		if($('#' + this._clientID + '_textfield').val().length >= 3){
		
	    	if($('#' + this._clientID + '_textfield').val() != "" && $('#' + this._clientID + '_textfield').val() != "Buscar..."){
				//alert($('#id_opcion_buscador').val(this._value));
				if($('#id_opcion_buscador').val(this._value) == "interna"){
					$(".BUS_CONTE_search").find("input:first").val($('#' + this._clientID + '_textfield').val());
					window.location = this._url + "Simple.aspx?k=" + $('#' + this._clientID + '_textfield').val();
				}
				else if($('#id_opcion_buscador').val(this._value) == "google"){
					window.location = this._url + "Simple.aspx?k=" + $('#' + this._clientID + '_textfield').val();

					$('#cse-search-box').attr("action", this._url + "Google.aspx")
					$('#cse-search-box').find('#q').val($('#' + this._clientID + '_textfield').val());
				 	$('#cse-search-box').submit();
				}
				else{
					alert("Seleccione donde desea realizar la busqueda.");
				}	
			}
			else{
				alert("Ingrese las palabras que desea buscar.");
			}
		}
		else{
			alert("Ingrese una texto que tenga como mínimo 3 caractares.")
		}
	},
	_onClick: function (e) {		
		this._irBuscador();

    },
    _onEnter: function (event) {
    	if (event.keyCode == '13') {
	    	this._irBuscador();

		}
    }

}
