// JavaScript Document

Search = function()
{

	this.maxPage = null;
	this.site_url = null;
	this.php_self = null;
	this.totalItems = null;
	this.search_val = null;

	
	//erase left blank spaces in a string
	this.ltrim = function(s) 
	{ 
		return s.replace(/^\s+/, ""); 
	};
	//erase rigth blank spaces in a string
	this.rtrim = function(s) 
	{ 
		return s.replace(/\s+$/, ""); 
	}; 
	//erase left and right blank spaces in a string
	this.trim = function(s) 
	{ 
		return this.rtrim(this.ltrim(s)); 
	};
	
	/*blank input box*/
	this.blankInputText = function(e, obj)
	{
		this.value = "";
	}
	
	/*only write numbers in to input type text*/
	this.onlyNumbers = function (e, obj)
	{
		key = (document.all) ? e.keyCode : e.which;
		
		if (key == 8 || key == 0 || (key >= 48 && key <= 57))
			return true;
		else
			YAHOO.util.Event.stopEvent(e);
	}
	
	/*goTo_top_btn_click*/	
	this.goTo_top_btn_click = function(e, obj)
	{
		if(this.trim(this.goTo_top.value) != "" && isNaN(this.goTo_top.value) == false && (this.goTo_top.value > 0 && parseInt(this.goTo_top.value) <= parseInt(this.maxPage.value) ))
		{
			//alert(this.wname.value+" - "+this.wseason.value+" - "+this.wflowert.value);
			document.location.href = this.php_self+"?cur_page="+this.goTo_top.value+"&search_val="+this.search_val;
		}
		else
		{
			this.goTo_top.value = "#";
		}
	}

	/*goTo_bottom_btn_click*/
	this.goTo_bottom_btn_click = function(e, obj)
	{
		if(this.trim(this.goTo_bottom.value) != "" && isNaN(this.goTo_bottom.value) == false && (this.goTo_bottom.value > 0 && parseInt(this.goTo_bottom.value) <= parseInt(this.maxPage.value) ))
		{
			//alert(this.wname.value+" - "+this.wseason.value+" - "+this.wflowert.value);
			document.location.href = this.php_self+"?cur_page="+this.goTo_bottom.value+"&search_val="+this.search_val;
		}
		else
		{
			this.goTo_bottom.value = "#";
		}
	}

	
	//Function init
	this.init = function(site_url, php_self, search_val)
	{
		//Initializations
		this.site_url = site_url;
		this.php_self = php_self;
		this.search_val = search_val;
		
		this.maxPage = YAHOO.util.Dom.get("maxPage_top_txt");
		
		//alert(this.maxPage.value+" - "+this.search_val);

		this.goTo_top = YAHOO.util.Dom.get("goTo_top_txt");
		this.goTo_bottom = YAHOO.util.Dom.get("goTo_bottom_txt");
		
		
		//Listeners
		YAHOO.util.Event.addListener("goTo_top_txt", "focus", this.blankInputText, this.goTo_top, true);
		YAHOO.util.Event.addListener("goTo_bottom_txt", "focus", this.blankInputText, this.goTo_bottom, true);
		
		YAHOO.util.Event.addListener("goTo_top_txt", "keypress", this.onlyNumbers, this.goTo_top, true);
		YAHOO.util.Event.addListener("goTo_bottom_txt", "keypress", this.onlyNumbers, this.goTo_bottom, true);
		
		YAHOO.util.Event.addListener("goTo_top_btn", "click", this.goTo_top_btn_click, this, true);
		YAHOO.util.Event.addListener("goTo_bottom_btn", "click", this.goTo_bottom_btn_click, this, true);
	}

}


