function search(id){
	var query = document.getElementById(id).value
	var queryEncode = encodeQuery(query);
	go(window.location.host + '/' +  queryEncode);

}

function encodeQuery(toEncode) {
	return encodeURIComponent(toEncode);
}

function go(toUrl){
	window.location.href = 'http://' + toUrl;
}

function searchEvent(event,id) {
  if ((event && event.which == 13) || (window.event && window.event.keyCode == 13) ){
    search(id);
    return false;
    }
  else
    return true;
}


/**
 * This class encapsulates all logic for buy tracking.
 * @constructor
 */

function BuyTracker(){};

/**
 * set the user how buyer
  */
BuyTracker.prototype._setBuyer = function() {
	var expireDate = new Date (); 
	expireDate.setTime(expireDate.getTime() + (30 * 24 * 3600 * 1000));
	document.cookie = "__buyer" + "=" + escape("1") + ";path=/; domain=" + new String(location.host).substring(new String(location.host).indexOf(".") ,new String(location.host).length) + ((expireDate == null) ? "" : "; expires=" + expireDate.toGMTString()); 
};




/**
 * User is buyer
 * @return {Boolean} 
  */
BuyTracker.prototype._isBuyer = function() {
	if(document.cookie){
		// Still not sure that "[a-zA-Z0-9.()=|%/]+($|;)" match *all* allowed characters in cookies
		tmp =  document.cookie.match((new RegExp('__buyer' +'=[a-zA-Z0-9.()=|%/]+($|;)','g')));
		if(!tmp || !tmp[0])
			return false;
		else 
			return (unescape(tmp[0].substring('__buyer'.length+1,tmp[0].length).replace(';','')) == '1');
			
	}
};


/**
 * Tracks the buy.
 * @param {Object} arg1 GA tracker created by user
 * @param {Integer} arg2 itemId
 * @return {Boolean} true
  */
BuyTracker.prototype._track = function(tracker,itemId) {
  
	if(!this._isBuyer()){
		
		this._setBuyer();
		
		tracker._trackPageview('/pms/');
	
	}
	
	return true;
	
};
