 var ATCLabel = undefined;
//if(THIS_WEB == undefined)  THIS_WEB = "http://localhost/auktiva/";
//if(LTHIS_WEB == undefined) LTHIS_WEB = THIS_WEB;

   // kontrola cookie a jejich ulozeni do pole _COOKIES_
  // v tomto poli jsou vsechny cookie a je mozno je pouzivat dale ve vsech nactenych strankach


var RecaptchaOptions = {
   custom_translations : { instructions_visual : "Opište 2 slova:"}
};



   var _COOKIES_ = new Array();
   _COOKIES_['login'] = '';
   cookies = document.cookie.split('; ');

   var a;
   i = 0;
   while(cookies[i]){
       prom = cookies[i].split('=');
       if(prom[1] != null){
          prom[1] = prom[1].replace(/%2F/g,'/');
          prom[1] = prom[1].replace(/%3F/g,'?');
          prom[1] = prom[1].replace(/%3D/g,'=');
          prom[1] = prom[1].replace(/%40/g,'@');
       }
       _COOKIES_[prom[0]] = prom[1];
      // document.write(prom[0]+' = '+prom[1]+'<br>');                                                                                                                                    
      i++;
   }


// zobrazuje na hlavni strance hlasku o tom ze uz tu uzivatel byl
function DoYouKnowMe(){
        
        if(_user_name != ''){
           // uzivatel je prihlasen
           
           if(_user_logged==1){
              lbox = document.getElementById('login_box');
              if(lbox){
                 r  = ('<div class="loggeduser">');
                 r += ('<span class="username">'+_user_name+'</span> ');
                 r += ('<form action="'+THIS_WEB+'logout.php" method="post" >');
                 r += ('<input type="submit" class="logout_button" value="Odhlásit">');
                 r += ('<input type="hidden" name="Logout" value="1">');
                 r += ('</form>');
                 r += ('</div>');
                 lbox.innerHTML = r;
              }
           
           // uztivatel neni prihlasen, ale uz tu nekdy byl - zaznam v cookie
           }
        } else {
           if((_COOKIES_['login'] != undefined) && (_COOKIES_['login'] !='')){
              lbox = document.getElementById('login_box');
              if(lbox){
                 lbox.innerHTML +=('Nejste náhodou .. &nbsp;<a href="'+LTHIS_WEB+'myaccount.php">'+_COOKIES_['login']+'</a>?');
              }
           }
        }
}

// upravuje navigacni menu podle toho jestli je uzovatel prihlasen ci nikoliv
function nav_menu(){
   if(_user_logged==0){
      lbook = document.getElementById('loginbookmark');

      if(lbook){
         lbook.innerHTML = "Registrace";
         lbook.href = LTHIS_WEB + 'registrace.php';
      }
   }
}

// zobrazi hlasku o nacitani
function pleas_wait(param){
  
  if(param == 'hide'){
     //alert('Hide');
     pw = document.getElementById('pleas_wait');
  
     //alert(pw.className);
     if(pw){
        pw.className = "displaynone";
    }
    return true;
  }
  
  
    var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  

  wh = document.documentElement.clientHeight;
  

  scl=scrOfY+(wh/2)-50+"px";
  //scl = 0;
  
  pw = document.getElementById('pleas_wait');
  if(pw==null){
     
     body = document.getElementsByTagName("body");

     a  = ('<div id="pleas_wait" class="displaynone">');
     a += ('<img src="'+THIS_WEB+'ikony/spinner.gif" alt="Prosím počkejte">');
     a += ('<br>Načítám');
     a += ('</div>');
  
     $(body).append(a);
  
  }
  
  pw = document.getElementById('pleas_wait');
  
  //alert(pw.className);
  if(pw){
     if(pw.className == "displaynone"){
        //alert('ahoj');
        pw.style.top = scl;
        pw.className = "displayblock";
     } else {
        //alert('nazdar');
        pw.className = "displaynone";
     }
  }
}

    
// vytvari hlavicku okna
     function CreateWait(img){
           var cont = document.createElement('div');
              cont.className = 'waitClock';
           var pic = document.createElement('img');
              pic.src = THIS_WEB + 'ikony/spinner.gif';
              
              $(cont).append(pic);
              return(cont);
           
    }    


    function pictureResize(img,maxw,maxh){
    
                  height = img.height;
                  width = img.width;
                 
                  var h = height / maxh;
                  var w = width / maxw;                  
                  if((height > maxh) && (width > maxw)){
                    
                     if(w >h){
                       img.width = maxw;
                       img.height = height / w;
                       img.style.left = '-'+((width - maxw) / 2) +'px';
                     } else {
                       img.height = maxh; 
                       img.width = width / h;
                       img.style.left = '-'+((width - maxw) / 2) +'px';                    
                     }
                  } else if((height > maxh)){
                     img.height = maxh; 
                     img.width = width / h;
                     img.style.left = '-'+((width - maxw) / 2) +'px';
                  } else if((width > maxw) ){
                       img.width = maxw;
                       img.height = height / w;
                       img.style.left = '-'+((width - maxw) / 2) +'px';                     
                  }    
    }

    function mainPictureResize(img,maxw,maxh){
    
                  height = img.height;
                  width = img.width;
                 
                  var h = height / maxh;
                  var w = width / maxw;
                  
                                    
                  if((height > maxh) && (width > maxw)){
                    
                     if(w >h){
                       img.height = maxh; 
                       img.width = width / h;   
                     } else {
                       img.width = maxw;
                       img.height = height / w;
                     }
                  } else if((height > maxh)){
                       img.width = maxw;
                       img.height = height / w;  
                  } else if((width > maxw) ){
                     img.height = maxh; 
                     img.width = width / h;                   
                  }    
    }

		function showBigAuctionPictures(maxWidthOfBigPicture,maxHeightOfBigPicture){
    
       var pictures = document.getElementById('smallauctionpictures');
       var bigpictures = document.getElementById('bigauctionpictures');
        
       var img;
        
       var TheAuctionVisiblePicture = null; 
        
       var aNodes = pictures.childNodes;
       var pic = new Array();
       var first = 1;
       //alert(aNodes.length);
       for(var i=0;i < aNodes.length; i++){
       //alert(i);
         if(aNodes[i].tagName == 'A'){
            var sNodes = aNodes[i].childNodes;
            //alert(sNodes.length);
            
            for(var j=0;j < sNodes.length; j++){
               if(sNodes[j].className == 'picture displaynone'){
                  
                  img = document.createElement('img');
                  img.src = sNodes[j].innerHTML;
                  img.alt = 'obrazek';
                  if(first == 1) {
                     img.className=''; 
                     TheAuctionVisiblePicture = img;
                     img.onload = function() { pictureResize(this,maxWidthOfBigPicture,maxHeightOfBigPicture); };
                     first = 0;
                  } else img.className = 'displaynone';
                  

                  
                  aNodes[i].picture = img;
                  aNodes[i].picturesrc = sNodes[j].innerHTML;
                  aNodes[i].onmouseover = function() {
                         if(TheAuctionVisiblePicture != null) TheAuctionVisiblePicture.className = 'displaynone';
                         this.picture.className ='';
                         pictureResize(this.picture,maxWidthOfBigPicture,maxHeightOfBigPicture)
                         TheAuctionVisiblePicture = this.picture;
                       }
                  //aNodes[i].style.border = '1px solid red';
                  $(bigpictures).append(img);   
               }
            }
         }
         
         //aNodes[i].onmouseover = function() { MWNahled(this); }
         //aNodes[i].onmouseout  = function() { $('#MWNahled').css('display','none'); }          
       }
       //alert(TheAuctionVisiblePicture.width);
       
    }

    function pictureResize(img,maxw,maxh){
    
                  height = img.height;
                  width = img.width;
                 
                  var h = height / maxh;
                  var w = width / maxw;                  
                  if((height > maxh) && (width > maxw)){
                    
                     if(w >h){
                       img.width = maxw;
                       img.height = height / w;
                       img.style.left = '-'+((width - maxw) / 2) +'px';
                     } else {
                       img.height = maxh; 
                       img.width = width / h;
                       img.style.left = '-'+((width - maxw) / 2) +'px';                    
                     }
                  } else if((height > maxh)){
                     img.height = maxh; 
                     img.width = width / h;
                     img.style.left = '-'+((width - maxw) / 2) +'px';
                  } else if((width > maxw) ){
                       img.width = maxw;
                       img.height = height / w;
                       img.style.left = '-'+((width - maxw) / 2) +'px';                     
                  }    
    }

    function mainPictureResize(img,maxw,maxh){
    
                  height = img.height;
                  width = img.width;
                 
                  var h = height / maxh;
                  var w = width / maxw;
                  
                                    
                  if((height > maxh) && (width > maxw)){
                    
                     if(w >h){
                       img.height = maxh; 
                       img.width = width / h;   
                     } else {
                       img.width = maxw;
                       img.height = height / w;
                     }
                  } else if((height > maxh)){
                       img.width = maxw;
                       img.height = height / w;  
                  } else if((width > maxw) ){
                     img.height = maxh; 
                     img.width = width / h;                   
                  }    
    }
       
  // vraci pocet znaku, ktery zbyva 
  function  CharCount(obj,printarea,max){
     
     c = obj.value.length;
     if(c>max) obj.value = obj.value.substr(0,max);
     c = max-c;
     if(c<0) c=0;
     $(printarea).empty();
     $(printarea).append("Zbývá: "+c);
  
  }
  
  function BeforeTextareaSubmit(form){
      
     ta = document.getElementsByTagName('textarea');
     ok = 1;
     for( i=0; i<ta.length;i++){
        if(ta[i].value.length <= 0){
           ok = 0;
        }   
     }
     if(ok > 0){
       document.forms[form].submit();
     } else alert('Nejdřív prosím vyplňte formulář.');
  
  }
  
    function BeforeInputBoxSubmit(boxes,form){
     

     ib = document.forms[form][boxes];

     ok = 0;

     if((ib != undefined) || (ib != null)){
        for( i=0; i<ib.length;i++){
          if(ib[i].checked == true){
          ok = 1;
           }
        }
     }
            
     if(ok > 0){
       document.forms[form].submit();
     } else alert('Vyberte prosím nějaké položky.');
  
  }
  
  function InputBoxesSelectAll(boxes,form){
  
     ib = document.forms[form][boxes];
  
     if((ib != undefined) || (ib != null)){
  
        for( i=0; i<ib.length;i++){
           if(ib[i].disabled != true) ib[i].checked = true;
        }    
     }
  }
  
  function InputBoxesUnselectAll(boxes,form){
  
     ib = document.forms[form][boxes];
  
     if((ib != undefined) || (ib != null)){
  
        for( i=0; i<ib.length;i++){
              ib[i].checked = false;
        }    
     }
  }  
  
  function InputBoxesInverse(boxes,form){
  
     ib = document.forms[form][boxes];
  
     if((ib != undefined) || (ib != null)){
  
        for( i=0; i<ib.length;i++){
           if(ib[i].disabled != true){
              if(ib[i].checked == true) ib[i].checked = false;
              else ib[i].checked = true;
           }
        }    
     }
  } 
  
  function isdefined( variable)
  {
     return (typeof(window[variable]) == "undefined")?  false: true;
  }  


function getCookie(c_name){  
   if (document.cookie.length>0){
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1){
         c_start=c_start + c_name.length+1;
         c_end=document.cookie.indexOf(";",c_start);
         if (c_end==-1) c_end=document.cookie.length;
         return unescape(document.cookie.substring(c_start,c_end));
      }
   }
   return "";
}

function setCookie(c_name,value,expiredays,path){
   var exdate=new Date();
   exdate.setDate(exdate.getDate()+expiredays);
   var cookie_string = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
   
   if ( path )
        cookie_string += "; path=" + escape ( path );
   
   document.cookie = cookie_string;
}
  



function formFillIn(params,fname){
// Foreach 

   for ( var i in params )
   {
      //alert('ahoj: '+i);
      
      if(!fname || (fname == undefined) ) fname = 'main_form';
      var obj = document.forms[fname].elements[i];
      
      if((obj != null)){
        
         //document.write(i+" = "+obj.type+'<br>');
         switch(obj.type)
         {
           case 'text':
             //alert(i+" = "+obj.type+" "+params[i][1]);
             if(params[i][0] !='') obj.value = params[i][0];
             if(params[i][1]==2) obj.className = obj.className + " wrong";
             if(params[i][1]==1) obj.className = obj.className + " missing";             
             break;
           case 'hidden':
             if(params[i][0] !='') obj.value = params[i][0];         
             break;             
           case 'password': // nyvyplnuje hodnotu
             if(params[i][1]==2) obj.className = obj.className + " wrong";
             if(params[i][1]==1) obj.className = obj.className + " missing";             
             break;                  
           case 'checkbox':
             if(((params[i][0]==1)||(params[i][0] == 'on')) && !obj.checked) { obj.click(); }
             if(params[i][1]==2) $(obj).wrap('<div class="wrong_c"></div>');
             if(params[i][1]==1) $(obj).wrap('<div class="missing_c"></div>');
             break;
           case 'textarea':
             if(params[i][0] !='') obj.value = params[i][0];
             if(params[i][1]==2) obj.className = obj.className + " wrong";
             if(params[i][1]==1) obj.className = obj.className + " missing";             
             break;            
           case undefined:    // to nejspise bude radio
             r_obj = obj[0];
             if((r_obj != null)&&(r_obj.type ='radio')){
                formSelectRadiotWithValue(obj,params[i][0]);;
             }
             break;
           case 'select-one':
             //alert(i+" = "+obj.type+" "+params[i][0]);
             formSelectSelectWithValue(obj,params[i][0]);
             if(obj.onchange != undefined) obj.onchange();
 
             if(params[i][1]){
                var d = document.getElementById(i);
                if(d != null) {
                   d.style.border = '2px solid #ffcc00';
                   d.style.background = '#f9e378';
                } else obj.className = obj.className + " wrong_s";             
             }
             break;
           default:
             //alert('default: '+i);
             break;
          
         }
      }
   }
}

// funkce se pokusi najit v danem selectboxu prvek s
// danou hodnotou a priradi ho jako SELECT
function formSelectSelectWithValue(s,val){

   if((s != null)&&((s.type == 'select-one')||(s.type == 'select-multiple'))){
    //document.write('-------------- '+val+' ---------------');
    for(var i=0;i<s.length;i++){
    
       //document.write('- '+s[i].value);
       if(s[i].value == val){
          s.selectedIndex = i;
         // document.write('- Select<br>');
          return(1);
       } // else document.write('<br>');
    }
 
 }
}

// funkce se pokusi najit v danem selectboxu prvek s
// danou hodnotou a priradi ho jako SELECT
function formSelectRadiotWithValue(s,val){

   if(s != null){
    
    l = s.length;
    
    //document.write('-------------- '+l+' __ '+val+' ---------------<br>');
    if(l>1){  // prvku je vic, mucim je projit a zjistit ktery odpovida hodnote

    for(var i=0;i<l;i++){
    
       //document.write('- '+s[i].value);
       if(s[i].value == val){
          //s.selectedIndex = i;
          s[i].click();
         // document.write('- Select<br>');
          //return(1);
       }  //else document.write('<br>');
    }
    
    
    } else {  // je to jedinej prvek typu radio, oznacim tedy jej

    }
 }
}  

// Prida danemu selectboxu dalsi option
function addSelectOption(selectbox,value,name,selected){
   if(selectbox && (selectbox != undefined)){
      var o = document.createElement('option');
      o.appendChild(document.createTextNode(name));
      o.value = value;
      if(selected) selectbox.selectedIndex = value;
      selectbox.appendChild(o); 
   }
}

  // vymaze dany selectbox
  function clearSelectbox(sb){
     var l = sb.length;
     for(i=l-1;i>=0;i--){
        sb.remove(i);
     }  
  }


// zkopiruje dane promenne z jednoho formulare do druheho
// fo - zdrojovy formular [string/object]
// so - cilovy formular  [string/object]
// elementy ke zkopirovani [array]
function formsInputCopy(fo,so,par){

   if(typeof(fo) == 'object') f = fo; else f = document.forms[fo];
   if(typeof(so) == 'object') s = so; else s = document.forms[so];
   val = 0;
  
   for(i in par){
      //alert(i+' / '+par[i]);
      if(f.elements[par[i]]){
         if(f.elements[par[i]].type == 'checkbox') {
            if(f.elements[par[i]].checked == true) val = 1; else val = 0;
         } else val = f.elements[par[i]].value;
         
         
         if(s.elements[par[i]] == undefined) formAddInputByName(so,par[i],val);
         else s.elements[par[i]].value = f[par[i]].value;
         //alert(par[i]+' > '+f.elements[par[i]].type+' = '+val);
      }
      
   }
}

function smallFormRequest(req,prom,val){
  var f = document.createElement('form');
  var r = document.createElement('input');  f.appendChild(r);
  var p = document.createElement('input');  f.appendChild(p);
  
  f.method = 'post';
  
  r.name  = 'request';
  r.value = req;
  
  p.name  = prom;
  p.value = val;
  
  
  document.body.appendChild(f);
  f.submit();
}

function formAddRequest(form,request){
   f = document.getElementById(form);   
   formAddInput(form,'request',request)
}

function formAddInput(form,name,value){
   if(typeof(form) == 'object') f = form;
   else f = document.forms[form];
   
   myinp = document.createElement('input');
   myinp.name = name;
   myinp.type = 'hidden';
   myinp.value = value; 
   f.appendChild(myinp);
} 

function formAddInputByName(form,name,value){
   f = document.forms[form];

   var ra = document.createElement('input');
   ra.name = name;
   ra.type = 'hidden';
   ra.value = value; 
   f.appendChild(ra);
}

// vytori formular a elementy
function createForm(name,par,elem){

   // defaultni parametry
   def = {'action':'','enctype':'multipart/form-data','method':'post','onsubmit':'this.submit()'};
   myform = document.createElement('form');
   
   // doplneni parametru
   if(par == undefined) par = def;
   else for(i in def) if(par[i] == undefined) myform[i]=def[i];  else myform[i] = par[i];   
   
   // skryjeme
   myform.style.display = 'none';
   //myform.style.border = '10px solid red';
   
   // elementy formulare
   for(i in elem){
      formAddInput(myform,i,elem[i])   
   }
    
   document.body.appendChild(myform);
   return myform;
}

 function newCharCounter(textbox,tmax){

   if(!tmax) tmax = 1000;

   ttext = textbox.value.length;
   if(ttext > tmax) textbox.value = textbox.value.substr(0,tmax);
   ttext = tmax-ttext;
   if(ttext<0) ttext=0;

   ttext = 'Zbývá: '+ttext;

   if(textbox.charcounter){
      textbox.charcounter.innerHTML = ttext;
   } else {
   
      var charbox = document.createElement('div');
      charbox.innerHTML = ttext;
      charbox.style.position = 'relative';

      textbox.parentNode.insertBefore(charbox, textbox.nextSibling);

      charbox.className = 'charCounter';
      textbox.charcounter = charbox;
      
   }
}

 
function helpCreate(){
   var Help   = document.createElement('div');
   //var Head   = document.createElement('div');  Head.className = "head";
   var Main   = document.createElement('div');  Main.className = "main";
   var LeftS  = document.createElement('div');  LeftS.className = "left_shad";
   var RightS = document.createElement('div');  RightS.className = "right.shad";
   var HT     = document.createElement('div');  HT.className = "helptext";
   var Bottom = document.createElement('div');  Bottom.className = "arrow";
   
   HT.innerHTML   = "Nápovědu se nepodařilo nalézt";
   //Head.innerHTML = "Nápověda";
   
   //Main.appendChild(Head);
   Main.appendChild(HT);
   
   LeftS.appendChild(Main);

   Help.appendChild(LeftS);
   Help.appendChild(RightS);
   Help.appendChild(Bottom);
   
   Help.id = "help2";
   Help.visibility = 'hidden';
   
   document.body.appendChild(Help);
   return Help;
} 
  
function helpHide(){
    $("#help2").hide();
}


function helpShow(e,hid,nohelp){

   H = document.getElementById('help2');
  
   if(H == undefined){  H = helpCreate(); } 

 //opera Netscape 6 Netscape 4x Mozilla 
   if (window.innerWidth || window.innerHeight){ 
      docwidth = window.innerWidth; 
      docheight = window.innerHeight; 
   } 
 
 //IE Mozilla 
   if (document.body.clientWidth || document.body.clientHeight){ 
      docwidth = document.body.clientWidth; 
      docheight = document.body.clientHeight; 
   } 


    //help width
    $("#help2 .helptext").remove();
    if(HELP[hid] != null){ hlp = HELP[hid] } else if(nohelp == undefined) hlp = 'Nápovědu pro toto téma se nepodařilo nalézt.'; else hlp = hid;
    $("#help2 .main").append('<div class="helptext">'+hlp+'</div>');

    var right = docwidth - $(e).position().left;
 
    H.style.top = $(e).position().top-$("#help2").height()-9+'px';
    if($(e).position().left>(docwidth/2)) { H.style.left = 'auto'; H.style.right = right-25+'px'; $("#help2 .arrow").css('left','auto'); $("#help2 .arrow").css('right','10px'); } 
                                 else  { H.style.left  = $(e).position().left-10+'px'; H.style.right = 'auto'; $("#help2 .arrow").css('left','10px'); $("#help2 .arrow").css('right','auto');}

    $("#help2").show(); 
}    		
