var qckSrch = new Class(
{
    Implements : Options,
    options :
    {
		errorMessage : "",
        atleast : "At least one (1) search criterion is required.",
		required : " is required.",
		invalid : " is invalid.",
		greater : " cannot be greater than ",
        fieldFxError : {"background-color" : "#ff0000"},
        y_height : "",
        x_width : ""
    },

	toTimestamp : function(strDate)
	{
		var datum = Date.parse(strDate);
		return datum/1000;
	},

    chkMulti : function(obj)
    {
        var ctr = 0;
        var valid = false;

        $$(obj).each(function(el)
        {
            if (el.checked)
            {
                ctr++;
            }
        });

        if (ctr > 0)
        {
            valid = true;
        }
        return valid;
    },

    chkSingle : function(obj)
    {
        var ctr = 0;
        var valid = false;

        if ($(obj).value != "")
        {
            ctr++;
        }

        if (ctr > 0)
        {
            valid = true;
        }
        return valid;
    },

    onSubmit : function()
    {
        var ctr = 0;
		if ($("btn_qck_search") != null) {
			$("btn_qck_search").addEvents({
				"click" : function()
				{
					ctr = 0;

					if ((this.chkSingle("txt_keywords") == false) && (this.chkSingle("ddlb_industry_sector") == false) &&
					(this.chkSingle("ddlb_city") == false))
					{
						ctr++;
						this.options.errorMessage = this.options.atleast;
					}


					if (ctr == 0)
					{
					   return true;
					}
					else
					{
						this.openPopup();
						return false;
					}
				}.bind(this)
			});
		}
    },

    notifier : function()
    {
        var setHtml = "<table cellpadding='0' cellspacing='0' border='0' class='errorHeading'>";
        setHtml = setHtml + "<tr><td>" + this.options.errorMessage + "</td></tr>";
        setHtml = setHtml + "</table>";
		$("popup_content_error").set("html",setHtml);
    },

    openPopup : function()
    {
        var scroller = new Fx.Scroll(document.body);
        var size = getSize();
        var pos_left = ((size.x / 2)) - (this.options.x_width / 2);
        var pos_top = ((size.y / 2)) - (this.options.y_height / 2);

        this.notifier();
        scroller.toTop();
        $("popup_dropshadow_error").setStyles(
        {
			left : 8,
			top : 8,
			height : this.options.y_height,
			width : this.options.x_width
        });
        $("popup_shadow_error").setStyles(
        {
			display : "block",
			left : 0,
			top : 0,
			height : document.body.offsetHeight, //document.body.offsetHeight,
			width : document.body.offsetWidth
        });
        $("popup_error").setStyles(
        {
			display : "block",
			left : pos_left,
			top : pos_top
        });
        $("popup_container_error").setStyles(
        {
			height : this.options.y_height,
			width : this.options.x_width
        });
        $("popup_content_error").setStyle("font-weight","bold");
    },

    closePopup : function()
    {
		if ($("btn_close") != null) {
			$("btn_close").addEvents(
			{
				"click" : function()
				{
						$("popup_error").setStyle("display","none");
						$("popup_shadow_error").setStyle("display","none");
						$("popup_content_error").set("html","");
				}
			})
		}
    },

    

    initialize : function(options)
    {
        this.setOptions(options);
        
        this.onSubmit();
        this.closePopup();
    }
});
