// JavaScript Document
//ajax load file///

function loadDat(zdrojDat, divID){ 
  var XMLHttpRequestObjekt = false; 
  if (window.XMLHttpRequest) {
     XMLHttpRequestObjekt = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
     XMLHttpRequestObjekt = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if(XMLHttpRequestObjekt) {
     var obj = document.getElementById(divID); 
     XMLHttpRequestObjekt.open("GET", zdrojDat); 
     XMLHttpRequestObjekt.onreadystatechange = function(){ 
        if (XMLHttpRequestObjekt.readyState == 4 && XMLHttpRequestObjekt.status == 200){ 
          obj.innerHTML = XMLHttpRequestObjekt.responseText; 
        } else {
          //alert('Nepodařilo se provést.');
        }
     } 
     XMLHttpRequestObjekt.send(null); 
  }
}

function login(){
  var chyby = '';
  if (document.login_form.nick.value==""){var chyby = chyby + 'Nezadali jste jméno!\n';}
  if (document.login_form.pass.value==""){var chyby = chyby + 'Nezadali jste heslo!\n';}
  if(chyby!= ''){
    window.alert(chyby); return false;
  }
}

function nazev(){
  var chyby = '';
  if (document.sablona.nazev.value==""){var chyby = chyby + 'Zadat nazev!\n';}
  if(chyby!= ''){
    window.alert(chyby); return false;
  }
}

function jeemail(adr){
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
  return adr.search(re) == 0;
}

function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}

function komform(){
    var chyby = '';
    //if (trim(document.kom_form.email.value)==""){var chyby = chyby + 'Zadejte nějaký text.\n';}
    if (trim(document.kom_form.jmeno.value)==""){var chyby = chyby + 'Zadejte jméno.\n';}
    //if (document.kom_form.kod.value!=document.kom_form.kod1.value || trim(document.kom_form.kod.value)==""){var chyby = chyby + 'Špatný kód.\n';}
    if(chyby!= ''){
      window.alert(chyby); return false;
    }
}


function forgotpass() {
  var chyby = '';
  if (!jeemail(document.forgotpass_form.mail.value)){var chyby = chyby + 'Tento e-mail není platný!\n';}
  if(chyby!= ''){
    window.alert(chyby); return false;
  }
}

function intercomsubmit() {
  var chyby = '';
  if (document.intercom_form.text.value==""){var chyby = chyby + 'Zadejte nějaký text.\n';}
  if (document.intercom_form.id_od.value=="" || document.intercom_form.id_od.value==0){var chyby = chyby + 'Neexistuje odesílatel.\n';}
  if (document.intercom_form.id_komu.value=="" || document.intercom_form.id_komu.value==0){var chyby = chyby + 'Neexistuje příjemce.\n';}
  if(chyby!= ''){
    window.alert(chyby); return false;
  }
}

function open_bub(bublina){
  document.getElementById(bublina).style.display='block';
}
function close_bub(bublina){
  document.getElementById(bublina).style.display='none';
}


function okno_img(a){
	var trenink=window.open(a, 'fotka', 'width=500, height=650, resizable=yes, scrollbars=yes'); 
	vyska = screen.height;
	sirka = screen.width;
	var levy = (sirka - 500)/2;
	var horni = (vyska - 570)/2
	trenink.moveTo(levy, horni);
	trenink.focus();
	return false;
}

function oknof(a, widthf, heightf){
	var trenink=window.open(a, '_blank', 'width='+widthf+', height='+heightf+', resizable=yes, scrollbars=yes'); 
	vyska = screen.height;
	sirka = screen.width;
	var levy = (sirka - widthf)/2;
	var horni = (vyska - heightf)/2
	trenink.moveTo(levy, horni);
	trenink.focus();
	return false;
}

function okno(a, widthf, heightf){
	var okno=window.open(a, '_blank', 'width='+widthf+', height='+heightf+', resizable=yes, scrollbars=yes'); 
	return false;
}

function smazat(){
      var opravdu=confirm("Opravdu smazat?");
      if (opravdu)
      return true ;
      else
      return false ;
}
function opravdu(text){
      var opravdu=confirm(text);
      if (opravdu)
      return true ;
      else
      return false ;
}

function drop_user(){
      var opravdu=confirm("Opravdu odstranit Váš účet?");
      if (opravdu)
      return true ;
      else
      return false ;
}

//javascript funkce ekvivalent k PHP str_replace
function str_replace (search, replace, subject)
{
  var result = "";
  var  oldi = 0;
  for (i = subject.indexOf (search)
     ; i > -1
     ; i = subject.indexOf (search, i))
  {
    result += subject.substring (oldi, i);
    result += replace;
    i += search.length;
    oldi = i;
  }
  return result + subject.substring (oldi, subject.length);
}

/*function calc_average(){
      document.day.km_prum.value=Math.round((document.day.km.value/(document.day.delka.value/60))*100)/100;
}*/

function calc_wkg(){
      document.test.ap_wkg.value=Math.round((document.test.ap_w.value/document.test.kg.value)*10)/10;
      document.test.anp_wkg.value=Math.round((document.test.anp_w.value/document.test.kg.value)*10)/10;
}


function color_pick(color){
    document.skin_form.color.value=color;
    document.skin_form.submit();
}

function min_def_box(box){
  if(Get_Cookie(box)){
    document.getElementById(box).style.display=Get_Cookie(box);
  }
}

function minimizebox(box){
  var today = new Date(); 
  //var zero_date = new Date(0,0,0); 
  today.setTime(today.getTime()); 
  var cookie_expire_date = new Date(today.getTime() + (365 * 86400000));

  if(document.getElementById(box).style.display=='none'){
    document.getElementById(box).style.display='block';
    Set_Cookie(box,'block',cookie_expire_date);
  } else {
    document.getElementById(box).style.display='none';
    Set_Cookie(box,'none',cookie_expire_date);
  }
}


function search_blog_set_cookie(val){
  var today = new Date(); 
  //var zero_date = new Date(0,0,0); 
  today.setTime(today.getTime()); 
  var cookie_expire_date = new Date(today.getTime() + (365 * 86400000));
  Set_Cookie('blog_search',val,cookie_expire_date);
}

function search_set_cookie(val){
  var today = new Date(); 
  //var zero_date = new Date(0,0,0); 
  today.setTime(today.getTime()); 
  var cookie_expire_date = new Date(today.getTime() + (365 * 86400000));
  Set_Cookie('s_search',val,cookie_expire_date);
}

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 
function Set_Cookie(name,value,expires,path,domain,secure){ 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
}
function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
}
function odroluj(){
	var objDiv = document.getElementById("thumbnails");
	objDiv.scrollTop = Get_Cookie("rol");
}

function smile_mess(neco) {
 document.intercom_form.text.value = document.intercom_form.text.value + ''+neco+'';
 document.intercom_form.text.focus();
};



   
