function getID(sId) {
	return document.getElementById(sId);
}

function getT(sId) {
	return document.getElementsByTagName(sId);
}

function AddShopLink() {
	if(getID('howtoadd')) {
		getID('howtoadd').style.display = 'none';
	}
}

function onAddShow(){AddShow();}
function AddShow() {
	var h = getID('howtoadd');
	h.style.display = (h.style.display=='none' ? 'block' : 'none');
}

function FilterNonNumeric(field) {
	var result  = new String();
	var numbers = "0123456789";
	var chars   = field.value.split("");
	for (i = 0; i < chars.length; i++) {
		if (numbers.indexOf(chars[i]) != -1) {
			result += chars[i];
		}
	}
	if (field.value != result) {
		field.value = result;
	}
}

function FinderUrl() {
	var action, q, type, adresa;
	
	type = new Array(3);
	type[0] = 'zbozi';
	type[1] = 'e-shopy';
	type[2] = 'akcni-zbozi';
	type[3] = 'inzerce';
	
    action 	= getID('finder').getAttribute('action');
    q = encodeURIComponent(getID('q').value);
	adresa 	= type[getID('type').value]+'/'+encodeURI(q)+'/';
	var e = getID('finder').elements['lang'];
	var lang = "";
	for(var i = 0; i < e.length; i++){
		if(e[i].checked && (e[i].value == 'all')){
			lang = 'all/';
		}
	}
	
	window.location.href = action+lang+adresa;
	return false;
	
}

function inpQText() {
	if(getID('q').value != '') {
		getID('q').value = decodeURI(getID('q').value);
	}
}

function explode(delimiter,string) {
    var emptyArray = { 0: '' };

    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }

    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }

    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }

    if ( delimiter === true ) {
        delimiter = '1';
    }
    return string.toString().split ( delimiter.toString() );
}

function clk(obj, searchType, position, clickOn) {
	var refPage = 'scripts/click.php?';
	var refURL = encodeURI(obj.href);
	var refText = '';
	var q = encodeURI(getID('q').value);
	var docRoot = getT('H1')[0].firstChild.href;		

	if(clickOn == 1){
		refText = obj.firstChild.getAttributeNode('alt').nodeValue;
	}else {
		refText = obj.firstChild.data;
	}
	
	refText = encodeURI(refText);
	
	window.location.href = docRoot + refPage + 'url=' + refURL + '&title=' + refText + '&pos=' + position + '&cimg=' + clickOn + '&type=' + searchType + '&q=' + q;
	return false;
}

window.onload = Init;
function Init() {
	AddShopLink();
	if(getID('q')) {
        inpQText();
		getID('q').focus();
		getID('q').select();
	}
}

function addSearchEngine() {
  if ((typeof window.sidebar == "object") &&
  (typeof window.sidebar.addSearchEngine == "function")) {
  
  	window.sidebar.addSearchEngine(
		"http://www.items.cz/addons/searching/items.src", 
		"http://www.items.cz/addons/searching/items.png", 
		"Items.cz - Hledání v internetových obchodech Easy-shop",
		"Web"
	);
  	
  }else {
  	alert("Tuto funkci podporuje pouze Firefox a Mozzila.");
  }
  
  return false;
}