
function Evt() {
	this.url		= 'http://events.walla.co.il/events.asp?un={nick}&l={app}&event_type=1&DivName={desc}&page_location=5&url={url}';
	//this.url		= 'http://10.0.1.41/events.php?un={nick}&l={app}&event_type=1&DivName={desc}&page_location=5&url={url}';
	this.nick		= '';
	this.app		= '';
	this.source		= '';	// button or link..
	this.etype		= ''; 	// search engine
	this.vertical	= '';	// vertical
	this.target		= '';
};
Evt.prototype.send = function(url) {
	var desc = 'search_' + this.source + '_' + this.etype;
	if ('' != this.vertical) {
		desc += '.' + this.vertical;
	}

	var src = this.url.replace('{nick}', this.nick).replace('{app}', this.app).replace('{desc}', desc).replace('{url}', encodeURIComponent(url));
	var img	= document.createElement('img');
	
	img.src = src;
	document.body.appendChild(img);
};

// global event object
wevt = new Evt();

/**
 * @param elementId		input-text dom node id
 * @param suggestId		block-element dom node id
 * @param callback		function
 * @returns {Autocomplete}
 */
function Autocomplete(elementId, suggestId, callback) {
	
	this.enabled		= true;
	
	// initial form elements:
	this.textElement	= document.getElementById(elementId);

	// initial suggest vars:
	this.suggestElement	= document.getElementById(suggestId);
	this.suggestIndex	= -1;
	this.suggestList	= new Array();

	// callback for autocomplete:
	var self		= this;
	this.callback	= callback;
	this.ioCallback	= 'autocomplete_' + elementId;

	// attach keyup event to text element
	this.textElement.onkeyup = function() { self.handleOnkeyup.apply(self, arguments); };
	// attach a function to the global scope
	window[this.ioCallback] = function() { self.populateSuggest.apply(self, arguments); };
}

Autocomplete.prototype.submit = function() {
	this.cancel();
	this.onSubmit();
};

Autocomplete.prototype.onSubmit = function() {
	// event
};

/**
 * Call cancel when you want to stop any current process
 */
Autocomplete.prototype.cancel = function() {
	var ch = this.suggestElement.firstChild;
	if (ch) {
		this.suggestElement.removeChild(ch);
	}
	this.suggestElement.style.display = 'none';
};

// Define to activate/deactivate autocomplete mechanism
Autocomplete.prototype.setEnabled = function(flag) {
	this.cancel();
	this.enabled = flag;
};


// keyboard actions controller
Autocomplete.prototype.handleOnkeyup = function(/*Event*/ e) {
	if (this.enabled) {
		e = e || window.event;
		switch(e.keyCode) {
			case 13:	this.submit();	break;	// submit form
			case 27:	this.cancel();	break;	// esc key
			case 38:	this.up();		break;	// up-arrow key
			case 40:	this.down();	break;	// down-arrow key
			default:	this.io();		break;	// do autocomple
		}
	}
};

// IO action
Autocomplete.prototype.io = function() {
	var value = this.textElement.value;
	if ('' == value) {
		return this.cancel();
	}
	if (this.callback instanceof Function) {
		this.callback(value, this.ioCallback);
	}
	else {
		window[this.callback](value, this.ioCallback);
	}
	return null;
};


// Navigate up action
Autocomplete.prototype.up = function() {
	if (0 == this.suggestIndex) return;
	this._mark(-1);
};

// Navigate down action
Autocomplete.prototype.down = function() {
	if ((this.suggestList.length - 1) == this.suggestIndex) return;
	this._mark(1);
};

Autocomplete.prototype.populateSuggest = function(/*Array*/ list) {
	if ((undefined == list) || !(list instanceof Array)) {
		// do not server call without proper value
		return;
	}
	this._populate(list);
};

// private methods
Autocomplete.prototype._mark = function(dir, isElement) {
	// remove "selected" class from current element (if element exists)
	if (0 <= this.suggestIndex) {
		this.suggestList[this.suggestIndex].setAttribute('class', '');
	}
	// increase/secrease/set suggest index
	if (isElement) {
		this.suggestIndex = parseInt(dir.getAttribute('index'));
	} else {
		this.suggestIndex += dir;
	}
	// add "seleted" class to the new selected element
	this.suggestList[this.suggestIndex].setAttribute('class', 'selected');
	// update the input search value
	this.textElement.value = this.suggestList[this.suggestIndex].innerHTML.replace('<strong>', '').replace('</strong>', '').replace('<STRONG>', '').replace('</STRONG>', '');
	this.textElement.focus();
};

Autocomplete.prototype._populate = function(/*Array*/ list) {
	var ul		= document.createElement('ul');
	var ch		= this.suggestElement.firstChild;
	var len		= list.length;
	var self	= this;
	var value	= this.textElement.value;
	
	this.suggestList = new Array();
	
	for (var i=0 ; i<len ; ++i) {
		var li = document.createElement('li');
		li.setAttribute('index', i);
		
		li.onmousemove	= function() { self._mark.call(self, this, true); };
		li.onclick		= function() { self.submit.call(self); };
		
		li.innerHTML = list[i].replace(value, '<strong>' + value + '</strong>');
		ul.appendChild(li);
		this.suggestList.push(li);
	}
	
	if (ch) {
		this.suggestElement.replaceChild(ul, ch);
	} else {
		this.suggestElement.appendChild(ul);
	}
	this.suggestLength	= len;
	this.suggestElement.style.display = 'block';
};

/**
 * Cross-Site request (jsonp implementation)
 * @param string url
 * @returns {XDscript}
 */
function XDscript(url) {
	this.src = url || null;
};

XDscript.prototype.setUrl = function(url) {
	this.src = url;
};

XDscript.prototype.send = function() {
	var s = document.createElement('script');
	s.type	= 'text/javascript';
	s.src	= this.src;
	document.getElementsByTagName('head')[0].appendChild(s);
};

/**
 * Ajax handler
 * @returns Object
 */
function AjaxHandler() {
	this.XMLHttpFactories = [
	     function () {return new XMLHttpRequest()},
	     function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	     function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	     function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	 ];
};
AjaxHandler.prototype.request = function(url, callback) {
	var r = this._getHandle();
	r.open('GET', url, true);
	r.onreadystatechange = function() {
		if (4 != r.readyState) {
			return;
		}
		if (200 != r.status && 304 != r.status) {
			return;
		}
		callback(r);
	}
	if (4 == r.readyState) {
		return;
	}
	r.send();
};

AjaxHandler.prototype._getHandle = function() {
	var xmlhttp = false;
	for (var i=0;i<this.XMLHttpFactories.length;i++) {
		try {
			xmlhttp = this.XMLHttpFactories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
};










var google_adnum = 0;
function google_ad_request_done(google_ads) {
	var template = '';

	if (google_ads && google_ads.length == 0) {
		return;
	}
	template += '<div class="gads">';
	template += '	<div class="gtitle">';
	template += '		<a href="' + google_info.feedback_url + '">מודעות Google</a>';
	template += '	</div>';
	template += '	<div class="clrc">';
	for(var i = 0; i < google_ads.length; ++i) {
		template += '	<div class="gad">';
		template += '		<div class="adtitle">';
		template += '			<a href="' + google_ads[i].url + '">';
		template += '				<span>' + google_ads[i].line1 + '</span>';
		template += '			</a>';
		template += '		</div>';
		template += '		<div class="adcontent">';
		template += '			<span>' + google_ads[i].line2 + '</span>';
		template += '			<span>' + google_ads[i].line1 + '</span>';
		template += '		</div>';
		template += '		<div class="adurl">';
		template += '			<a href="' + google_ads[i].url + '">';
		template += '				<span>' + google_ads[i].visible_url + '</span>';
		template += '			</a>';
		template += '		</div>';
		template += '	</div>';
	}
	template += '	</div>';
	template += '</div>';
	
	if (google_ads[0].bidtype == "CPC") {
		google_adnum = google_adnum + google_ads.length;
	}
    document.write(template);
    return;
}

google_ad_client		= 'pub-7627650086895590';
google_ad_channel		= '';
google_ad_output		= 'js';
google_max_num_ads		= '2';
google_ad_type			= 'text';
google_image_size		= '300x250';
google_feedback			= 'on';
google_language			= 'iw';
google_adtest			= 'off';
google_ski				= google_adnum;
google_encoding			= '';
