/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/* check page number */
function checkpages(obj, max_st) {

			if(obj.value < 1) {alert('Nedá sa skočiť na stránku  '+obj.value);return false;}
			if(obj.value > max_st) {alert('Nedá sa skočiť na stránku  '+obj.value);return false;}

			return true;
		}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function searchEmpty(formElement) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = true;
	if (formElement.value == '') {
		_isEmpty = false;
	}
	
	return _isEmpty;
}

/** Standards Compliant "_blank" Windows learnt from **/

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}

/** Standards Compliant "_blank" Windows for ePayments (without toolbars)  **/

function externalEpay(adress) {
  window.open(adress,null,"scrollbars=1,resizable=1,location=0,menubar=0,status=1,toolbar=0",true);
}

// PRELOAD IMAGE

function preloadImage(im) {
if (document.images) {
img1 = new Image();
img1.src = "../images/"+im;
}
}



window.onload = function() {

preloadImage("arrow-right.gif");
preloadImage("arrow-right-hover.gif");
preloadImage("arrow-down.gif");
preloadImage("arrow-down-hover.gif");
preloadImage("add_to_cart.gif");
preloadImage("add_to_cart_hover.gif");

externalLinks();

// focus search form
document.getElementById('search').focus();


}

