acttab=1;
zakladnicena=0;

imgselected=Array("/templates/main/images/detail_left_popis_selected.gif",
				  "/templates/main/images/detail_left_dalsifoto_selected.gif",
				  "/templates/main/images/detail_left_skladovezasoby_selected.gif",
				  "/templates/main/images/detail_left_diskuze_selected.gif");

imggray    =Array("/templates/main/images/detail_left_popis_gray.gif",
				  "/templates/main/images/detail_left_dalsifoto_gray.gif",
				  "/templates/main/images/detail_left_skladovezasoby_gray.gif",
				  "/templates/main/images/detail_left_diskuze_gray.gif");

imgnormal=Array("/templates/main/images/detail_left_popis.gif",
				  "/templates/main/images/detail_left_dalsifoto.gif",
				  "/templates/main/images/detail_left_skladovezasoby.gif",
				  "/templates/main/images/detail_left_diskuze.gif");

function tab_hover(number) {
	if (acttab!=number) {
		sel=document.getElementById("tabimage"+number);
		sel.src=imgnormal[number-1];
	} 
	
	if (number==3 && acttab!=3) {
		document.getElementById("stock_table").style.display='block';
	}
}

function tab_out(number) {
	if (acttab!=number) {
		sel=document.getElementById("tabimage"+number);
		sel.src=imggray[number-1];
	} 			
		document.getElementById("stock_table").style.display='none';


}

function add_quantity(quantity) {
	document.getElementById('cart_quantity').value=parseFloat(document.getElementById('cart_quantity').value)+quantity;
	if (document.getElementById('cart_quantity').value<=0) { document.getElementById('cart_quantity').value=1;}
	if (isNaN(document.getElementById('cart_quantity').value)) { document.getElementById('cart_quantity').value=1;}
	document.getElementById("cart_quantity2").value=document.getElementById("cart_quantity").value;
	countprice();
}

function kschange() {
	if (!isNaN(document.getElementById('cart_quantity2').value)) { document.getElementById('cart_quantity').value=document.getElementById('cart_quantity2').value;}	
	countprice();
}

function kschange2() {
	if (!isNaN(document.getElementById('cart_quantity').value)) { document.getElementById('cart_quantity2').value=document.getElementById('cart_quantity').value;}	
	countprice();
}
function tab_click(number) {

	sel=document.getElementById("tabimage"+acttab);
	sel.src=imggray[acttab-1];
	sel=document.getElementById("tabimage"+number);
	sel.src=imgselected[number-1];
	
	act=document.getElementById("tab"+acttab);
	act.style.display="none";
	act=document.getElementById("tab"+number);
	act.style.display="block";
	document.getElementById("stock_table").style.display='none';
		
	acttab=number; 	
}

function countprice() {
form=document.getElementById('form1');
baseprice=parseFloat(form.elements['baseprice'].value);
var str = "";

//baseprice=baseprice.toFixed(curdec);
for (x=0;x<pole3.length;x++) {
	for (i=0;i<form.elements.length;i++) {
		if ((form.elements[i].attributes['type'].nodeValue=='radio' || form.elements[i].attributes['type'].nodeValue=='checkbox')  && form.elements[i].checked==true) { 
			if (form.elements[i].name.substr(9,form.elements[i].name.length-11) == pole3[x]){
				num = parseFloat(pole1[form.elements[i].value][0]); 
				baseprice=baseprice+num;
				if (pole1[form.elements[i].value][1]==1) {
					if (pole1[form.elements[i].value][3]==1) {
							if (str.length>0) {str=str+", ";} 
						 	str= str + pole1[form.elements[i].value][2];	
					}
				//	window.alert(str);
				}
			}
		}
	}
}
 
//cena = price_format(baseprice) +' '+ currsign;
cena=price_format(baseprice,curdec,' ','.','',' '+currsign,'','');
document.getElementById('products_price').innerText = cena;
document.getElementById('products_price').textContent = cena;
document.getElementById('products_price2').innerText = cena;
document.getElementById('products_price2').textContent = cena;

skladem=false;
for (i=0;i<pole2.length;i++) {
	if (pole2[i][0]==str && pole2[i][1]>=form.elements['cart_quantity'].value) {skladem=true;}
}
 
if (skladem==true) {
	document.getElementById('neniskladem').style.display="none";
	document.getElementById('jeskladem').style.display="block";
} else {
	document.getElementById('neniskladem').style.display="block";
	document.getElementById('jeskladem').style.display="none";	
}
}

 


function price_format(num,dec,thou,pnt,curr1,curr2,n1,n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec;
	if (z<0) z--; 
	for(var i = z; i < 0; i++) y.unshift('0'); 
	if (z<0) z = 1;
	if (dec>0) {
		y.splice(z, 0, pnt); 
		if(y[0] == pnt) y.unshift('0'); 
	}
	while (z > 3) {z-=3; y.splice(z,0,thou);}
	var r = curr1+n1+y.join('')+n2+curr2;
	return r;
}

function selectAttr(option_id) {

	posy = document.documentElement.scrollTop;
	document.getElementById('detailAttributesImageSelect'+option_id).style.left=-400+"px";//(Math.floor((document.body.offsetWidth)/2))+'px';
//	document.getElementById('detailAttributesImageSelect'+option_id).style.top=posy+"px";
	document.getElementById('detailAttributesImageSelect'+option_id).style.display = "block";

}

function hideAttr(option_id) {
	document.getElementById('detailAttributesImageSelect'+option_id).style.display = "none";	
}

function vyberImgInput(inp,img ) {
	 
	if (document.getElementById("imgvybrano"+img)) {
		document.getElementById("imgvybrano"+img).src=document.getElementById("attrimg"+inp).src;
		document.getElementById("vybrano"+img).innerHTML=document.getElementById("nazev"+inp).innerHTML;
		document.getElementById("imgvybrano"+img).width=document.getElementById("attrimg"+inp).width;
		document.getElementById("imgvybrano"+img).height=document.getElementById("attrimg"+inp).height;
	}
	//	window.alert(document.getElementById("input"+img+inp).checked);
	
 	if (document.getElementById("input"+img+inp).checked) {
		document.getElementById("input"+img+inp).checked = false;
 	} else {
 		document.getElementById("input"+img+inp).checked=true;
 	}
 
	countprice();
}

function updateImgInput(inp,img ) {
	 
	if (document.getElementById("imgvybrano"+img)) {
		document.getElementById("imgvybrano"+img).src=document.getElementById("attrimg"+inp).src;
		document.getElementById("vybrano"+img).innerHTML=document.getElementById("nazev"+inp).innerHTML;
	} 
	 
	countprice();  
}

function zobrazdiskusi() {
	document.getElementById('tab4').style.display="block";	
}

function diskuse_addcomment() {
	posy = document.documentElement.scrollTop;

	document.getElementById('addcomment').style.top=posy+100+"px"; 
	document.getElementById('addcomment').style.left=(Math.floor((document.body.offsetWidth-500)/2))+"px";
	document.getElementById('addcomment').style.display='block';
}

function diskuse_addcomment_close() {
	document.getElementById('addcomment').style.display='none';	
}

function buystockproduct(stock_products_id) { 

document.getElementById('form1').stock_products_id.value=stock_products_id;
document.getElementById('form1').submit();
}

function callme() {
	posy = document.documentElement.scrollTop;
	document.getElementById('callmediv').style.top=posy+230+"px"; 
	document.getElementById('callmediv').style.left=(Math.floor((document.body.offsetWidth-300)/2))+"px";
	document.getElementById('callmediv').style.display='block'; 	
	 
}

function mailme() {
	posy = document.documentElement.scrollTop;
	document.getElementById('mailmediv').style.top=posy+230+"px"; 
	document.getElementById('mailmediv').style.left=(Math.floor((document.body.offsetWidth-300)/2))+"px";
	document.getElementById('mailmediv').style.display='block'; 	
	 
}

function onlynumbers(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]/;
  if( !regex.test(key) && ! (theEvent.keyCode == 8 || theEvent.keyCode == 46
     || theEvent.keyCode == 37 || theEvent.keyCode == 39 || theEvent.keyCode == 50)) {
    theEvent.returnValue = false;
   // theEvent.preventDefault();
  }	
}


