//zjisteni IE
var IE= null;
var ua = navigator.appName.toLowerCase();
if(ua.indexOf('explorer')>-1 && document.getElementById && document.childNodes) {IE=true;}

//-----------------------------------------
function mouse_position() {
	var pozice = new Array();

   if (document.all) {
		pozice[0] = window.event.screenX;
		pozice[1] = window.event.screenY;
	 } else {
		pozice[0] = 200;
		pozice[1] = 200;
	 }

	return pozice;
}

	function select_color(id_zbozi,typ) {
		page = "barva.php?id="+id_zbozi+"&typ="+typ;

		kde = mouse_position();
		if (kde[0]>720) x_posun = -360;
		else x_posun = 20;
		if (kde[1]>490) y_posun = -200;
		else y_posun = 20;
		window_left = kde[0]+x_posun;
    window_top = kde[1]+y_posun;
		detailWin=window.open(page,'kosik','resizable=yes,scrollbars=yes,top='+window_top+',left='+window_left+',width=180,height=230');
		detailWin.focus();
	}

	function select_width(id_zbozi,typ) {
		barva = document.getElementById('zbozi'+id_zbozi).vla0.value;
		//barva = eval("document.all.zbozi"+id_zbozi+".vla0.value");
		if (barva=='') {
		select_color(id_zbozi,typ)
		} else {
		kde= mouse_position();
		if (kde[0]>720) x_posun = -360;
		else x_posun = 20;
		if (kde[1]>490) y_posun = -200;
		else y_posun = 20;
		window_left = kde[0]+x_posun;
    window_top = kde[1]+y_posun;

		page = "sirka.php?id="+id_zbozi+"&color="+barva+"&typ="+typ;
		detailWin=window.open(page,'kosik','resizable=yes,scrollbars=yes,top='+window_top+',left='+window_left+',width=180,height=230');
		detailWin.focus();
		}
	}

	function show_detail(id_zbozi) {
		formular = document.getElementById('zbozi'+id_zbozi);
    //formular = eval("document.all.zbozi"+id_zbozi);
		barva = formular.vla0.value;
		sirka = formular.vla1.value;
		if (barva=='' || sirka=='') {
		//alert ('Musíte mít vybrané vlastnosti zboží!\r(např.Barva,Šíře,Velikost apod.)');
		alert (message_sel_color);
		} else {
			formular.akce.value = 'zbozi_detail';
			formular.superakce.value = '';
			formular.target = '_self';
			winwidth = 680;
			winheight = 550;
			window_left = 50;
	    window_top = 50;

			//if (typeof detailWin != "undefined") detailWin.close();
	    //detailWin=window.open('','kosik','resizable=yes,scrollbars=yes,width='+winwidth+',height='+winheight+',top='+window_top+',left='+window_left+'');

			formular.submit();
		}
	}

function check_formular(id_zbozi,typ) {
  	formular = document.getElementById('zbozi'+id_zbozi);
		barva = formular.vla0.value;
		sirka = formular.vla1.value;
		winwidth = 180;
		winheight = 230;
		kde= mouse_position();
		if (kde[0]>720) x_posun = -360;
		else x_posun = 1;
		if (kde[1]>490) y_posun = -200;
		else y_posun = 20;
		window_left = kde[0]+x_posun;
    window_top = kde[1]-winheight+y_posun;

		if (typeof detailWin != "undefined") detailWin.close();
		if (barva=='') {
			document.vysledek = false;
      detailWin=window.open('','kosik','width='+winwidth+',height='+winheight+',resizable=yes,scrollbars=yes,top='+window_top+',left='+window_left+'');
			select_color(id_zbozi,typ);
		} else if (sirka=='') {
			document.vysledek = false;
      detailWin=window.open('','kosik','width='+winwidth+',height='+winheight+',resizable=yes,scrollbars=yes,top='+window_top+',left='+window_left+'');
			select_width(id_zbozi,typ);
		} else {
			formular.akce.value = 'kosik_pocet';
      detailWin=window.open('','kosik','width='+winwidth+',height='+winheight+',resizable=yes,scrollbars=yes,top='+window_top+',left='+window_left+'');
			formular.submit();
		}
	}

function open_img(id_zbozi,zbozi_name,imgsource,zbozi_name,menushow) {
		if (imgsource) obrazek = imgsource;
		else obrazek = document.getElementById('zbozi'+id_zbozi).nahled.src;
		//obrazek = eval("document.zbozi"+id_zbozi+".nahled.src");
		delka = obrazek.length;
		obrazek2 = obrazek.substr(0,delka-5)+'v.jpg';

		showmenu = (menushow!=undefined) ? 'menubar=1,':'';
		zbozi_name = (zbozi_name!=undefined) ? zbozi_name:' ';
		adresa = 'index.php?superakce=view&img='+obrazek2+'&name='+zbozi_name;
		ImgWindow = window.open(adresa,'imgdetail',showmenu+'height=450,width=600,top=50,left=50');
    ImgWindow.focus();
	}

function enable_cart(id_zbozi) {
		barva = document.getElementById('zbozi'+id_zbozi).vla0.value;
		sirka = document.getElementById('zbozi'+id_zbozi).vla1.value;
		//barva = eval("document.zbozi"+id_zbozi+"");
		//sirka = eval("document.zbozi"+id_zbozi+"");

		if (!isNaN(barva) && !isNaN(sirka) && barva!='' && sirka!='') {
			eval("document.all.kos"+id_zbozi+".src='static/design/kos.gif'");
		} else {
			eval("document.all.kos"+id_zbozi+".src='static/design/kos2.gif'");
		}
	}

function vis_switch(dir_id,znamenko) {
	klas = document.getElementById('submenu'+dir_id);
	//klas2 = 'document.getElementById("submenu'+dir_id+'")';
	if (klas.style.display == 'none') {
	klas.style.display = 'block';
	znamenko.src = 'img/minus.gif';
	} else {
	klas.style.display = 'none';
	znamenko.src = 'img/plus.gif';
	}
}

function winsize(width,height,top,left) {
	window.resizeTo(width,height);
	if (top && left) window.moveTo(top,left);
}

function show_hide(layer_id) {
	if (document.getElementById(layer_id)) {
		layer=document.getElementById(layer_id);
		if (layer.style.display=='block') {
      layer.style.display='none';
		} else {
      layer.style.display='block';
		}
	}
}

function zobraz_cenu(cena, mena, predCenou) {
	cena = Math.round(cena*100)/100;
	cenashow = cena.toString();
	cenashow = cenashow.replace('.',',');
	if (typeof(mena)!='undefined') {
    if (predCenou) cenashow = mena + ' ' + cenashow;
		else cenashow = cenashow + ' ' + mena;
	}
	
	return cenashow;
}

function getStockInfo(id) {
	var num = parseInt($('#kosikpocet_'+id).val());
	$.ajax({
	    url: 'stockInfo.php',
	    data: "id=" + id + "&n=" + num,
	    type: 'GET',
	    dataType: 'html',
	    timeout: 30000,
	    beforeSend: function(){
	        loading(true);
	    },
	    error: function(){
	        loading(false);
	        alert('Error loading stock info');
	    },
	    success: function(html){
	        loading(false);
					alert(html);
					// else alert('Error loading stock info');
	    }
	});
}

function loading(active) {
	if (active) {
		$('body').css("cursor","wait");
	}	else {
		$('body').css("cursor","auto");
	}
}

function validateEmail(elementValue) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(elementValue);
}