function setSelectionRange(input,selectionStart,selectionEnd) {
	if(input.setSelectionRange) {
		input.focus();
		input.setSelectionRange(selectionStart,selectionEnd);
	}
	else if(input.createTextRange) {
		var range=input.createTextRange();
		range.collapse(true);
		range.moveEnd('character',selectionEnd);
		range.moveStart('character',selectionStart);
		range.select();
	}
}
function uprava(textpre,textpost,pole) { 
	var ele;
	if(ele=document.getElementById(pole)) {
		if(ele.setSelectionRange) {
			var start=ele.selectionStart;
			var end=ele.selectionEnd; 
			ele.value=ele.value.substring(0,start)+textpre+ele.value.substring(start,end)+textpost+ele.value.substring(end);
			//var pos=start+textpre.length+textpost.length+(end-start)+1;
			setSelectionRange(ele,start,end+textpre.length+textpost.length);
		}
		else if(document.selection) {
			ele.focus();
			document.selection.createRange().text=textpre+document.selection.createRange().text+textpost;
		}
	}
}
function formatovani(obj) {
  var smajly='<br><a onClick="uprava(\'\', \':-)\', \''+obj+'\')"><img src="/img/sm/20.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-D\', \''+obj+'\')"><img src="/img/sm/2.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-(\', \''+obj+'\')"><img src="/img/sm/9.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':\\\'(\', \''+obj+'\')"><img src="/img/sm/1.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-|\', \''+obj+'\')"><img src="/img/sm/3.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \';-)\', \''+obj+'\')"><img src="/img/sm/23.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-[\', \''+obj+'\')"><img src="/img/sm/17.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':lol:\', \''+obj+'\')"><img src="/img/sm/11.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-!\', \''+obj+'\')"><img src="/img/sm/12.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \'3-(\', \''+obj+'\')"><img src="/img/sm/18.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-P\', \''+obj+'\')"><img src="/img/sm/16.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \'8-)\', \''+obj+'\')"><img src="/img/sm/4.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':-O\', \''+obj+'\')"><img src="/img/sm/6.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':evil:\', \''+obj+'\')"><img src="/img/sm/7.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a><a onClick="uprava(\'\', \':twisted:\', \''+obj+'\')"><img src="/img/sm/22.gif" width="15" height="15" alt="smajlĂ­k" class="sm"></a>';
  document.getElementById(obj+'-formatovani').style.display='block';
  document.getElementById(obj+'-formatovani').innerHTML=smajly;
}
var ajax_obj=new Array();
function ajax_otevrit(obj,skript,typ,msg,akce) {
  var mozno=1;
  if (window.XMLHttpRequest) {
	 ajax_obj[obj]=new XMLHttpRequest();
  }else if(window.ActiveXObject) {
	 try {
	   ajax_obj[obj]=new ActiveXObject('Microsoft.XMLHTTP');
	 }catch(e) {
	   ajax_obj[obj]=new ActiveXObject('Msxml2.XMLHTTP');
	 }
  }else mozno=0;
  if (mozno) {
    var url=skript+'?'+new Date().getTime();
    ajax_obj[obj].open("POST", url, true);
    ajax_obj[obj].setRequestHeader('x-mj-js-akce', akce);
    ajax_obj[obj].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax_obj[obj].onreadystatechange=function() {ajax_otevrit_req(obj, typ);};
    ajax_obj[obj].send(msg);
  }
}
function ajax_otevrit_req(obj, typ) {
  if (ajax_obj[obj].readyState==4) {
    if(ajax_obj[obj].status==200) {
      if (ajax_obj[obj].responseText=='<prava>') {
        alert('K tĂ©to akci nemĂˇte dostateÄŤnĂˇ oprĂˇvnÄ›nĂ­.');
      }else if (ajax_obj[obj].responseText=='<exist>') {
        alert('VolanĂ˝ cĂ­l neexistuje.');
      }else if (ajax_obj[obj].responseText=='<voted>') {
        alert('V tomto hlasovĂˇnĂ­ jste jiĹľ hlasoval/a.');
      }else if (ajax_obj[obj].responseText.substring(0,7)=='<alert>') {
        var tmp=ajax_obj[obj].responseText;
        tmp=tmp.replace('<alert>', '');
        alert(tmp);
      }else if (ajax_obj[obj].responseText.substring(0,7)=='<cfirm>') {
        var tmp=ajax_obj[obj].responseText;
        tmp=tmp.replace('<cfirm>', '');        
        var c=confirm(tmp);
      }else if (ajax_obj[obj].responseText=='<tocart>') {
        document.location.href='/obchod/kosik';
      }else{
        misto=document.getElementById(obj);
        if (typ=='innerHTML') {
          misto.innerHTML=ajax_obj[obj].responseText;
        }else if (typ=='value') {
          misto.value=ajax_obj[obj].responseText;
        }else if (typ=='iframe') {
          window.frames[0].document.getElementById(obj).innerHTML=ajax_obj[obj].responseText;
        }
      }
    }
  }
}
function ajax_odeslat(obj,skript,msg,akce) {
  var mozno=1;
  if (window.XMLHttpRequest) {
	 ajax_obj[obj]=new XMLHttpRequest();
  }else if(window.ActiveXObject) {
	 try {
	   ajax_obj[obj]=new ActiveXObject('Microsoft.XMLHTTP');
	 }catch(e) {
	   ajax_obj[obj]=new ActiveXObject('Msxml2.XMLHTTP');
	 }
  }else mozno=0;
  if (mozno) {
    var url=skript;
    ajax_obj[obj].open("POST", url, true);
    ajax_obj[obj].setRequestHeader('x-mj-js-akce', akce);
    ajax_obj[obj].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    ajax_obj[obj].send(msg);
  }
}
// pridani produktu do kosiku

function basket_double(zid,zvelikost,zkusu) {
  ajax_otevrit('abc', '/ajax/ajax.php', 'innerHTML', 'id='+zid+'&velikost='+zvelikost+'&kusu='+zkusu, 'double');
}
function size_stock(zid,zvelikost,ztop) {
  var cil;
  if (ztop=='t') cil='tbtnplace';else cil='btnplace';
  ajax_otevrit(cil+zid, '/ajax/ajax.php', 'innerHTML', 'id='+zid+'&velikost='+zvelikost, 'stock');
  ajax_otevrit("sinf"+zid, '/ajax/ajax.php', 'innerHTML', 'id='+zid+'&velikost='+zvelikost+'&msg=1', 'stock');
}
function vypln() {
  var jmeno, prijmeni, email, email2, telefon, ulice, mesto, psc;
  var jmeno2, prijmeni2, emailx2, email22, telefon2, ulice2, mesto2, psc2;
  jmeno=document.getElementById("ajmeno");
  prijmeni=document.getElementById("aprijmeni");
  email=document.getElementById("aemail");
  email2=document.getElementById("aemail2");
  telefon=document.getElementById("atelefon");
  ulice=document.getElementById("aulice");
  mesto=document.getElementById("amesto");
  psc=document.getElementById("apsc");
  
  jmeno2=document.getElementById("ajmeno2");
  prijmeni2=document.getElementById("aprijmeni2");
  emailx2=document.getElementById("aemailx2");
  email22=document.getElementById("aemail22");
  telefon2=document.getElementById("atelefon2");
  ulice2=document.getElementById("aulice2");
  mesto2=document.getElementById("amesto2");
  psc2=document.getElementById("apsc2");
  
  jmeno2.value=jmeno.value;
  prijmeni2.value=prijmeni.value;
  emailx2.value=email.value;
  email22.value=email2.value;
  telefon2.value=telefon.value;
  mesto2.value=mesto.value;
  ulice2.value=ulice.value;
  psc2.value=psc.value;
  if (document.getElementById("astejne").checked==false) {
    jmeno2.value='';
    prijmeni2.value='';
    emailx2.value='';
    email22.value='';
    telefon2.value='';
    mesto2.value='';
    ulice2.value='';
    psc2.value='';
  }
}
function objform(zeme) {
  var btn=document.getElementById("objbtn");
  btn.disabled=true;
  btn.className='tl dis';
  ajax_otevrit('objform', '/ajax/ajax.php', 'innerHTML', 'zeme='+zeme, 'objform');
  btn.style.display='none';
}
function shtab(tabid) {
  document.getElementById("st1").className='';
  document.getElementById("st2").className='';
  document.getElementById("sb1").style.display='none';
  document.getElementById("sb2").style.display='none';
  document.getElementById("st"+tabid).className='akt';
  document.getElementById("sb"+tabid).style.display='block';
}
function schvalit(gid) {
  ajax_odeslat('ptd'+gid, '/ajax/ajax.php', 'id='+gid, 'schvalit');
  document.getElementById("ptd"+gid).style.background='#88cc88';
  document.getElementById("gsch"+gid).style.display='none';
}
function gsmazat(gid) {
  if (confirm('Opravdu chcete odstranit tuto položku?')) {
    ajax_odeslat('ptd'+gid, '/ajax/ajax.php', 'id='+gid, 'gsmazat');
    document.getElementById("ptd"+gid).style.display='none';
  }
}
