/* Mouse */
var mouseX = 0;
var mouseY = 0;
document.onmousemove = mouseMove;
function mouseMove(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	mouseX = posx;
	mouseY = posy;
}
function clearFormValue( array )
{
	for( i = 0; i < array.length; i++ )
	{
    	elem = document.getElementById( array[i] );
    	if ( null != elem )
    	{
    		elem.value = "";
		}
	}
}
function switchElement(e)
{
	elem = document.getElementById(e);
	if ( null != elem )
	{
		if ( elem.style.display != 'none' )
			elem.style.display='none';
		else
			elem.style.display='block';
	}
}
function hideElement(e)
{
	elem = document.getElementById(e);
	if ( null != elem )
		elem.style.display='none';
}
function showElement(e)
{
	elem = document.getElementById(e);
	if ( null != elem )
		elem.style.display='block';
}
/* hint */
function showHint( hint )
{
	var hintElement = document.createElement('div');
	hintElement.innerHTML = hint;
	var container = document.getElementById('jsInfoWindow');
	if ( container.hasChildNodes() )
		container.replaceChild(hintElement,container.childNodes[0]);
	else
		container.appendChild(hintElement);
	container.style.left = (mouseX+10) + 'px';
	container.style.top = (mouseY+10) + 'px';
	showElement('jsInfoWindow');
	/* upravime umisteni hintu pokud je moc vpravo */
	if ((0 + mouseX + container.offsetWidth) > (0 + document.documentElement.clientWidth))
		container.style.left = Math.max(0, ((document.documentElement.clientWidth) - container.offsetWidth)) + 'px';
}
function hideHint(){
	
	hideElement('jsInfoWindow');	
}
//doplnime funkci trim
function trim(string_to_trim)
{
	return string_to_trim.replace(/^\s+|\s+$/g,"");
}
//kopirovani adres v registraci
//kopie kontaktni adresy do dodaci
function copyContactAddressToDelivery( checkbox, isChecked )
{
	if ( isChecked == true)
	{
		with (window.document.registrationForm) {
			person2.value = trim(name.value + " " + surname.value);
			street2.value = trim(street1.value);
			city2.value = trim(city1.value);
			zip2.value = trim(zip1.value);
			country2.value = trim(country1.value);
			checkbox.checked = false;
		}
	}	
}
//kopie kontaktni adresy do fakturacni
function copyContactAddressToInvoice( checkbox, isChecked )
{
	if ( isChecked == true)
	{
		with (window.document.registrationForm) {
			firmName.value = trim(name.value + " " + surname.value);
			person3.value = trim(name.value + " " + surname.value);
			street3.value = trim(street1.value);
			city3.value = trim(city1.value);
			zip3.value = trim(zip1.value);
			country3.value = trim(country1.value);
			checkbox.checked = false;
		}
	}	
}
//kopie fakturacni adresy do dodaci
function copyInvoiceAddressToDelivery( checkbox, isChecked )
{
	if ( isChecked == true)
	{
		with (window.document.registrationForm) {
			person2.value = trim(person3.value);
			firmname2.value = trim(firmName.value);
			street2.value = trim(street3.value);
			city2.value = trim(city3.value);
			zip2.value = trim(zip3.value);
			country2.value = trim(country3.value);
			checkbox.checked = false;
		}
	}	
}
//fce na otevreni noveho okna s danym url a na dane pozici
function windowOpenURL(content,title,w, h){
	newWindow = window.open(content,title,'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h);
	newWindow.moveTo(0 + (screen.width - w)/2 , 0 + (screen.height - h)/2);
}
//zmena kategorie
function changeCategory( url, cidselectid )
{
	element = document.getElementById(cidselectid);
	window.location = url + element.options[element.selectedIndex].value;	
}
//vymazani vstupniho pole
function clearValue(elem, txt) {    
	if (elem.value.indexOf(txt, 0) == 0) elem.value = '';
}