//======================================================================================                  
//======================================================================================
//for display of products
var manuf=new Array();
var page=1;
var order;
var desc=false;

var str_id;


function gopage(i){
      page=i;
      reload_display();
      return false;
      }
function reset_page(){
      page=1;
}     
function goorder(d){
      desc=d;
      reload_display();
	  return false;
}      

function reload_display(){
      var only_actions=0;
      var only_stock=0;
      
      document.getElementById('processing_call').style.display='block';
	  str_id=document.getElementById('str_id').value;
	  try{
		  str_speciall=document.getElementById('str_special').value;
		  }catch(e){
		  	str_speciall=0;
		  }
      only_actions=false;
      only_stock=false;
      order=document.getElementById('order_select').value;
      param='str_id='+str_id+'&sort='+order+'&special='+str_speciall+'&only_stock='+only_stock+"&only_actions="+only_actions+"&page="+page+"&desc="+desc;

      url=rootdir+'inc/4ajax/prod_list.php?'+param;  
      xmlHttp=GetXmlHttpObject(displayStateChanged,true);
      xmlHttp.open("GET", url , true);
      xmlHttp.send(null);
      return false;      
        } 
        
//function for change of state
function displayStateChanged() 
        { 
        if (xmlHttp.readyState==2){ 
        //document.getElementById('basket_window').style.display='block';
        //document.getElementById('content').innerHTML=saving_call; 
                } 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
        out=xmlHttp.responseText.split('|||');
        document.getElementById('display_complet').innerHTML=out[0];
        //document.getElementById('display_complet').xmlHttp.responseText;
        //document.getElementById('total_prod_call').innerHTML=out[2];        
        document.getElementById('pages_top').innerHTML=out[1];
        //document.getElementById('pages_bottom').innerHTML=out[1];
        //document.getElementById('order_jump_a').innerHTML=out[3];
        document.getElementById('processing_call').style.display='none';
                } 
        }
		
function jump(which){
    url=urlroot+'produkt/'+which.value;
    location=url;
}

//menu hover function

 function emptyInput(id){
 				id.value='';
 				}
				
 function emptyLoginCallArea(){
 				document.getElementById('login_callarea').innerHTML='';
 				}
				

 function hover(id,dir){
 				if(dir)document.getElementById(id).style.backgroundPosition='bottom';
 				else document.getElementById(id).style.backgroundPosition='top';
 				}

 function menuHover(nr,selected){
        		if(selected){
        					document.getElementById('menuItem_'+nr).className='menuItemHover';
        					document.getElementById('menuItemIn_'+nr).className='menuItemInHover';
        					}
        		else 		{
        					document.getElementById('menuItem_'+nr).className='menuItem';
        					document.getElementById('menuItemIn_'+nr).className='menuItemIn';
        					}
        		}
 function top_up(level,id){
 							document.getElementById('leftMenu_'+id).className='leftMenu_'+level+'_hover';
 				}
 function top_down(level,id){
 							document.getElementById('leftMenu_'+id).className='leftMenu_'+level;
 				} 		
 function showMenu(id,small){
 				if(!small)add='';
 				else add='_small'; 				
 				if(document.getElementById('subMenuBag_'+id).className=='subMenuBagHidden'){
 						document.getElementById('subMenuBag_'+id).className='subMenuBag';		
 						document.getElementById('leftMenu_plus_'+id).src=rootdir+'img/sipka-down'+add+'.gif';
 							 
 						}
 						else{
 						document.getElementById('subMenuBag_'+id).className='subMenuBagHidden';
 						document.getElementById('leftMenu_plus_'+id).src=rootdir+'img/sipka-right'+add+'.gif';
 						}
 						
 				}	
//product details
 var timer = new Array();
 
 var packageCode = new Array();
 var selectedPackage = new Array();
 
 
 function updatePrice(opt,id,typeOfDisplay){
 		
 		//opt = document.getElementById('sel_'+id).value;
 		
 		packageId = opt.value;
 		if(typeOfDisplay==2){
		 		document.getElementById('price_'+id).innerHTML=package[packageId];
		 		}else{
		 		document.getElementById('detailCodeVal').innerHTML=packageCode[packageId];
		 		document.getElementById('detailPriceVal').innerHTML=package[packageId]+',-'+currency;
		 		}
		 		
 		selectedPackage[id] = packageId;

 }
 
/*----------------------------------*/
//********************************************************************************
//buy item
var id;
var otherArea=false;
var addFromDetail="";
var pointEl;


function addItem(id_r,point)
        {   
            id=id_r;
			pointEl=point;
			
			pointEl.innerHTML='ukládám';
			
			document.getElementById('processing_call').style.display='block';
            var url=rootdir+"inc/flow/basket_add.php?asdasd=234&id="+id;
            
            
            xmlHttp=GetXmlHttpObject(stateChanged,true);
            xmlHttp.open("GET", url , true);
            xmlHttp.send(null);
            return false;
        }       
//function for change of state
function stateChanged() 
        { 
        if (xmlHttp.readyState==2){ 
         
 				 
                } 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                if (xmlHttp.status == 200){
                              var call_get="";
                            if (1==1){       
									document.getElementById('processing_call').style.display='none';                                                                
                                    document.getElementById('basket_call_area').innerHTML=xmlHttp.responseText;
                                    pointEl.innerHTML='zakoupeno';								
									pointEl.onclick='';
									
									
                            }
                      //not sucessfull, using alternative
                      } 
                } 
        }
       
/*----------------------------------*/
var counter = new Array();
var countOfCounters;
function loadBasketAnim(id){
	countOfCounters++;
	loadBasketAnimPart(id,1);
}




/*------------------------BASKET--------------------------------------------*/
/*------------------------BASKET--------------------------------------------*/
//for basket
  var items = new Array();
  var prize = new Array();
  var deleted = new Array();
  var prodParamsID = new Array();  

  var prodParamsPrice = new Array();      
  
  //warning-max 100 products
  for(i=0;i<100;i++){
  		prodParamsID[i] = new Array();
  		prodParamsPrice[i] = new Array();
  				  //warning - max 50 options
  				  for(j=0;j<50;j++)prodParamsPrice[i][j] = new Array();
  		}
  



  var count=1;
  var changed=false;
  
  function format_it(a){
		//a = Math.round(a*10)/10;
		a = Math.round(a);
		var a = a.toString();
		var b = a.indexOf("\.");
		if (b == "-1"){
			s='';
			if(a.length>6)s+=a.substring(0,a.length-6)+'&nbsp;'			
			if(a.length>3)s+=a.substring(a.length-6,a.length-3)+'&nbsp;'						
			s+=a.substring(a.length-3,a.length);
			return s;
		}else{
			var s1 = a.substring(0,b);
			var lg = a.length;
			var s2 = a.substring((b+1),lg);
			s1 = s1.substring(0,s1.length-3) +' '+s1.substring(s1.length-7,s1.length-3) +'&nbsp;'+ s1.substring(s1.length-3,s1.length);
			var s = s1+","+s2;
			return s;
		}  
  }
  
function deleteThem(){
        //alert("ff");
        var empty=true;
        
        for(var i=0;i<items.length;i++){
            //alert(document.getElementById('check_'+items[i]).checked);
            if(document.getElementById('check_'+items[i]).checked){
                    document.getElementById('row_'+items[i]).style.display='none';
                    document.getElementById('row3_'+items[i]).style.display='none';					
                    document.getElementById('row2_'+items[i]).style.display='none';					
                    
                    deleted[items[i]]=true;
                    document.getElementById('basket_count_'+items[i]).value=0;
                    
                    }
            else empty=false;
        }
        
        if(empty){
        reload();
        document.getElementById('all_basket').style.display='none';

        document.getElementById('processing_call').display='block';
        document.getElementById('processing_call').innerHTML=empty_call+"<br/><br/><br/><br/>";
         
        
        }else reload();                  
  }  
//reloads actual counts in detail 
function reloadDetail(){
			i=0;
	        total_for_one=prize[i];
	            for(j=0;j<prodParamsID[i].length;j++){
	            		el_name = 'basket_param_'+i+'_'+j;
	            		val = document.getElementById(el_name).value;	            		
	            		total_for_one+=1*prodParamsPrice[i][j][val];
	            }
	            
            prize_out_one = format_it(total_for_one);
            document.getElementById('totalPrice').innerHTML=prize_out_one+" ,-KÄŤ";
}
 
  
//reloads actual counts in basket
function reload(){  
    
    var total=0;
    if(count>1)
        changed=true;
    else count++;
        
    
        for(var i=0;i<items.length;i++){
            if(!deleted[items[i]]){
            	
	            total_for_one=prize[i];
	            for(j=0;j<prodParamsID[i].length;j++){
	            		el_name = 'basket_param_'+i+'_'+j;
	            		val = document.getElementById(el_name).value;	            		
	            		total_for_one+=1*prodParamsPrice[i][j][val];
	            }
	            
			total	
            prize_out= document.getElementById('basket_count_'+items[i]).value*Math.round(total_for_one*1.19);
            prize_out_one = format_it(total_for_one);
            total += prize_out;
            //document.getElementById('basket_item_one_'+items[i]).innerHTML=prize_out_one;
            document.getElementById('basket_item_'+items[i]).innerHTML=format_it(prize_out)+',-';            
            }
        }
         document.getElementById('basket_total_w').innerHTML="<br /><b>celkem: <u>"+format_it(total)+",-"+currency+"</u> &nbsp;&nbsp;s DPH</b><br /><br />";
//         													" <u>"+format_it(total*1.05)+",-"+currency+"</u> &nbsp;&nbsp;5% DPH<br/>"+
//         													" <u>"+format_it(total*1.09)+",-"+currency+"</u> 19% DPH<br/>";
  }
  
  function update_basket(){
          document.getElementById('call_area_basket').style.display='none';           
          document.getElementById('call_area_basket').innerHTML = "";
          if(changed){
                return changeCount();
                }
          }
          
          
var xmlHttp;

function changeCount()
        {   
         var add="";
         var error=false;
        for(var i=0;i<items.length;i++){
                        val=document.getElementById('basket_count_'+items[i]).value;
                        add+="&id[]="+items[i]+"&count["+items[i]+"]="+val;
                        if(!isNumeric(val))error=true;


			            for(j=0;j<prodParamsID[i].length;j++){
			            		el_name = 'basket_param_'+i+'_'+j;
			            		valPrice = document.getElementById(el_name).value;  		
			            		valId = prodParamsID[i][j];  		
			            		add+="&param["+items[i]+"][]="+valId+"&paramVal["+items[i]+"]["+valId+"]="+valPrice;
	            		}                        
                    }
          if(error){
          //no numbers were added
          document.getElementById('call_area_basket').style.display='block';
          document.getElementById('call_area_basket').innerHTML = number_call;
          }
          else{

            var url = rootdir+'inc/flow/basket_update.php?'+add;
            //alert(url);
        document.getElementById('call_area_basket').style.display='block';
        document.getElementById('call_area_basket').innerHTML=saving_call; 
        //document.getElementById('processing_call').innerHTML=url; 
        //return;
            xmlHttp=GetXmlHttpObject(basketStateChanged,true);
            xmlHttp.open("GET", url , true);
            xmlHttp.send(null);
            }
        } 
        
//function for change of state
function basketStateChanged() 
        { 
        if (xmlHttp.readyState==2){ 
                } 
        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
        //alert('saved');
          document.getElementById('call_area_basket').style.display='block';
         document.getElementById('call_area_basket').innerHTML=done_call; 
        document.getElementById('basket_call_area').innerHTML=xmlHttp.responseText;
        changed=false;
                } 
        } 
function hidecontent(){
       document.getElementById('basket_window').style.display='none';
}
function hidecontent_2(id){
       // alert(id);
       document.getElementById(id).style.display='none';
}
function showcontent_2(id){
       // alert(id);

       document.getElementById(id).style.display='block';
}

//function for confirm message
  function confirm_it(text,loc){
  if(confirm(text)){
      //document.getElementById('menu_basket').style.display='none';//inline
      location.href=loc;
      }
  }    
        
//alternative function for non AJAX
function alter_func(){
   // alert("NO AJAX");
}

//======================================================================================                  
//======================================================================================
//for AJAX login


function do_login()
        {   
            login = document.getElementById('login_name').value;
            pass = document.getElementById('login_pass').value;   
            var url = rootdir+'inc/flow/login_ajax.php?login='+login+"&password="+pass;
            xmlHttp=GetXmlHttpObject(loginStateChanged,true);
            xmlHttp.open("POST", url , true);
            xmlHttp.send(null);
            return false;
        } 
        
//function for change of state
function loginStateChanged() 
        { 
                  if (xmlHttp.readyState==2){ 
                  //document.getElementById('disk_loginbag').style.display='none';
                  document.getElementById('login_callarea').innerHTML='...moment'; 
                } 
                  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                  //document.getElementById('basket_window').style.display='block'; 
                  //document.getElementById('content').innerHTML=done_call; 
                  res = xmlHttp.responseText;
                  
                  if(res!='badpass'){
                        out=xmlHttp.responseText.split('|||');
                        document.getElementById('top_login_logged').innerHTML=out[0];
                        //document.getElementById('login_menu').innerHTML=out[1];                                               
                        if(goLocation!=false){
                          if(goLocation=='/')goLocation='';                          
                        	window.location = urlroot + goLocation;                                               	
                        	}
                        }
                  else{
                        document.getElementById('login_callarea').innerHTML=calls['badinfo'];    
                    
                  }
                } 
        }
function do_logout()
        {   
            var url = rootdir+'inc/flow/login_ajax.php?action=logout';
            xmlHttp=GetXmlHttpObject(logoutStateChanged,true);
            xmlHttp.open("POST", url , true);
            xmlHttp.send(null);
            return false;
        } 
        
//function for change of state
function logoutStateChanged() 
        { 
                  if (xmlHttp.readyState==2){ 
                  document.getElementById('login_callarea').innerHTML=calls['checking']; 
                } 
                  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                  res = xmlHttp.responseText;                 
                        document.getElementById('top_login_logged').innerHTML=res;

                } 
        }

/*================myorders===================*/
function show_detail(id){
				name = 'detail_'+id;
				document.getElementById(name).style.display='block'; 
}
function hide_detail(id){
				name = 'detail_'+id;
				document.getElementById(name).style.display='none'; 

}
/*===============lostpass============================*/
function do_lostpass()
        {   
        	email = document.getElementById('lostPassSubmitText').value;        	
        	login = document.getElementById('lostPassSubmitLogin').value;        	
            var url = rootdir+'inc/flow/lostpass.php?email='+email+'&login='+login;
            xmlHttp=GetXmlHttpObject(lostPassStateChanged,true);
            xmlHttp.open("POST", url , true);
            xmlHttp.send(null);
            return false;
        } 
        
//function for change of state
function lostPassStateChanged() 
        { 
                  if (xmlHttp.readyState==2){ 
                  document.getElementById('lostPassSubmitText').value=calls['checking']+'...';
                  document.getElementById('lostPassSubmitLogin').value=calls['checking']+'...';
                } 
                  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                  res = xmlHttp.responseText; 
                  		if(res!='ok'){
                  			alert(calls['passnotfound']);
                  			//alert(res);							
                  		}else{
                  			
                  			document.getElementById('lostPassword').innerHTML='<br /><br /><b>'+calls['mailsent']+'</b><br /><br />';
                  		}          
                        //document.getElementById('lostPassCall').innerHTML=res;
                        //document.getElementById('lostPassSubmitText').value='';
                        //document.getElementById('lostPassSubmitLogin').value='';

                } 
        }
