(function() {
	var u = document.location.href.replace(/http:\/\//, ''); // 'gallur.sedelectronica.es'; // use to test
	var sb = document.getElementById('searchbox');
	var charset = document.charset || document.characterSet;
	if (charset != undefined) {
		if (sb.ie != undefined) {
			sb.ie.value = charset;
		} else {
			var ie_field = sb.cref.cloneNode(true);
			ie_field.name = "ie"
			ie_field.value = charset;
			sb.insertBefore(ie_field, sb.cref);
		}
	}
	sb.cref.value = 'http://www.google.com/cse/tools/makecse?url=' + encodeURIComponent(u);
})();

(function() {
	var f = document.getElementById('searchbox');
	if (!f) {
		f = document.getElementById('searchbox');
	}
	if (f && f.q) {
		var q = f.q;
		var n = navigator;
		var l = location;
		var su = function () {
			var u = document.createElement('input');
			var v = document.location.toString();
			var existingSiteurl = /(?:[?&]siteurl=)([^&#]*)/.exec(v);
			if (existingSiteurl) {
				v = decodeURI(existingSiteurl[1]);
			}
			var delimIndex = v.indexOf('://');
			if (delimIndex >= 0) {
				v = v.substring(delimIndex + '://'.length, v.length);
			}
			u.name = 'siteurl';
			u.value = v;
			u.type = 'hidden';
			f.appendChild(u);
		};
		if (n.appName == 'Microsoft Internet Explorer') {
			var s = f.parentNode.childNodes;
			for (var i = 0; i < s.length; i++) {
				if (s[i].nodeName == 'SCRIPT' && s[i].attributes['src'] && s[i].attributes['src'].nodeValue == unescape('http:\x2F\x2Fwww.google.com\x2Fcse\x2Ftools\x2Fonthefly?form=searchbox_demo\x26lang=')) {
					su();
					break;
				}
			}
		} else {
			su();
		}
			
		if (n.platform == 'Win32') {
			q.style.cssText = 'border: 1px solid #7e9db9; padding: 2px;';
		}
			
		if (window.history.navigationMode) {
			window.history.navigationMode = 'compatible';
		}
	
		var b = function() {
			if (q.value == '') {
				q.style.background = '#FFFFFF none left no-repeat';
			}
		};
		
		var f = function() {
			q.style.background = '#ffffff';
		};
		
		q.onfocus = f;
		q.onblur = b;
		
		if (!/[&?]q=[^&]/.test(l.search)) {
			b();
		}
	}
})();

