window.onload = function() {
	var table = e('striped');
	if (table) {
		stripeTable(table);
	}
}

function stripeTable(t) {
	var i, odd = true;
	for (i=0; i<t.rows.length; i++) {
		t.rows[i].className += odd ? ' odd' : ' even';
		odd = !odd;
	}
}

function e(id) {
	return document.getElementById(id);
}

function debug(str) {
	var el = e('dbox');
	if (el) {
		el.innerHTML = str + '<br />' + el.innerHTML;
	} else {
		el = document.createElement('div');
		el.setAttribute('id', 'dbox');
		e('main').appendChild(el);
	}
}

function animate(id, maxHeight) {
	var el = e(id);
	var height = parseInt(el.style.height) * 1;
	if (height >= maxHeight) {
		el.style.height = maxHeight + 'px';
	} else {
		if (height) {
			el.style.height = (height + Math.ceil((maxHeight - height) / 10)) + 'px';
		} else {
			el.style.height = '5px';
		}
		setTimeout('animate(\''+id+'\', '+maxHeight+')', 30);
	}
	// debug(el.style.height);
}

function showFullSearch() {
	var el = e('full_search');
	if (el) {
		el.style.display = 'block';
		el.style.overflow = 'hidden';
		animate('full_search', el.offsetHeight); 
		// alert(el.offsetHeight);
	}
}

function checkSearchForm() {
	if (e('fulltext').value == 'Hľadaj') {
		e('fulltext').value = '';
	}

	if ((e('price_from').value != '') && !IsNumeric(e('price_from').value)) {
		alert('Cena môže byť iba číslo.');
		e('price_from').focus();
		return false;
	}

	if ((e('price_to').value != '') && !IsNumeric(e('price_to').value)) {
		alert('Cena môže byť iba číslo.');
		e('price_to').focus();
		return false;
	}

	if (!e('mobiles').checked && !e('accessories').checked && !e('cameras').checked) {
		alert('Je potrebné zvoliť aspoň jednu kategóru.');
		return false;
	}

	return true;
}
		
function IsNumeric(sText) {
	var ValidChars = '0123456789.,';
	var IsNumber = true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++){ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function changeForm(type) {
	e('form_big').style.display = type ? '' : 'none';
}

function checkQuatro(count) {
	if (count <= 5) {
		return true;
	} else {
		alert('Podmienky spoločnosti Quatro dovoľujú maximálne 5 kusov tovaru na jednu zmluvu.');
		return false;
	}
}
