function clearform(which,text){

	var $txt = text
	if (which.value==$txt) {
		which.value='';
	} else if (which.value=="") {
		which.value=$txt;
	}

}

function ShowElem(Elem,hide1,hide2,hide3){

  var FormElem = document.getElementById( Elem )
  var hideElem1 = document.getElementById( hide1 )
  var hideElem2 = document.getElementById( hide2 )
  var hideElem3 = document.getElementById( hide3 )
  if(FormElem)
   if((FormElem.style.display == "none") || (FormElem.style.display == "")) {
    FormElem.style.display = "block";
	if (hideElem1)
	hideElem1.style.display = "none";
	if (hideElem2)
	hideElem2.style.display = "none";
	if (hideElem3)
	hideElem3.style.display = "none";	
   }

}

//-------------------------------------------------------

function setClass( hEl, sClass )
  {
    hEl.className = sClass
 }

function AddToCard(prodID,lg)
{
    
     $.post("/l_"+lg+"/addproduct",{"AddItem":1,"ProdID":prodID,"Quantity":1},function(data){ 
     res=data.split("|");
     if(res[0]==1) 
     {
        $(".buyBoxClear").fadeIn();
        $(".buyBoxIcon").attr("style",'background: url("/include/im/buy_icons/cart.png") no-repeat scroll 0 0 transparent;');
        $("#basket-count").html(res[1]);//alert("OK");
        $("#basket-price").html(res[2]);
        location.href="#basket";
        options = { };       
        $( ".buyBox" ).effect( 'bounce', options, 500, basketTimeOut );      
        
     }     
     });
}
function EmptyCart(lg)
{
    $.post("/l_"+lg+"/emptycart",{},function(data){ 
     res=data.split("|");
     if(res[0]==1) 
     {
        $(".buyBoxClear").fadeOut();
        $(".buyBoxIcon").attr("style",'background: url("/include/im/buy_icons/cart-grey.png") no-repeat scroll 0 0 transparent;');
        $("#basket-count").html(res[1]);//alert("OK");
        $("#basket-price").html(res[2]);        
        options = { };       
        $( ".buyBox" ).effect( 'bounce', options, 500, basketTimeOut );      
        
     }     
     });
}
function refuseOrder(id,lg,checkText)
{
     var reply = confirm(checkText);
    if(reply!='' && reply != null)
	{
         $.post("/l_"+lg+"/refuseorder",{"id":id},function(data){ 
         res=data.split("|");
         if(res[0]==1) 
         {
            $("#productTableStatus_"+id+"").html('<p>'+res[1]+'</p>');
            $("#refusalOrder_"+id).remove();            
         }     
         });
    }
}

function ShowPaymentInfo()
{
    current=$("#Payment").val();
    $("#descriptions div").fadeOut("fast",function()
    {
       $(".desc_"+current).fadeIn("fast");
    });
}
function HideShowCompany()
{
    invtype=$("#Invoice").val();
    if(invtype==1)
    {
        $(".personName").hide();
        $(".personEGN").hide();
        $(".personAddress").hide();
        $(".companyName").show();
        $(".companyMol").show();
        $(".companyAddress").show();
        $(".companyITN").show();
        $(".companyDDS").show();
    }
    else
    {
        $(".companyName").hide();
        $(".companyMol").hide();
        $(".companyAddress").hide();
        $(".companyITN").hide();
        $(".companyDDS").hide();
        $(".personName").show();
        $(".personEGN").show();
        $(".personAddress").show();
    }
    
}
function basketTimeOut() {     
	 setTimeout(function() {
				$( ".buyBox" ).removeAttr( "style" ).hide().fadeIn();
			}, 1000 );
		};

function ShowHide(Owner, Target){

    if(Owner.value == 0){
     Target.style.display = "none";
     Target.value = "";
    }
    else
     Target.style.display = "inline";

 }

 
 $(document).ready(function(){  
    $(".menu > li").click(function(e){  
        switch(e.target.id){  
            case "news":  
                //change status &amp;amp;amp; style menu  
                $("#news").addClass("active");  
                $("#newsletters").removeClass("active");  
                $("#userManuals").removeClass("active");  
				$("#links").removeClass("active");  
                //display selected division, hide others  
                $("div.news").fadeIn('fast',function()
                {
                    $(".change-url a").attr("href","/l_"+lang+"/?s=7");
                    $(".change-url a").html(archivenews);
                    $(".change-url").css("display","block");
                });  
                $("div.newsletters").css("display", "none");  
                $("div.userManuals").css("display", "none");  
				$("div.links").css("display", "none"); 
				
            break;  
            case "newsletters":  
                //change status &amp;amp;amp; style menu  
                $("#news").removeClass("active");  
                $("#newsletters").addClass("active");  
                $("#userManuals").removeClass("active");  
				$("#links").removeClass("active"); 
                //display selected division, hide others  
                $("div.newsletters").fadeIn('fast',function()
                {
                    $(".change-url a").attr("href","/l_"+lang+"/?s=11");
                    $(".change-url a").html(archivbuletin);
                    $(".change-url").css("display","block");
                });  
                $("div.news").css("display", "none");  
                $("div.userManuals").css("display", "none");  
				$("div.links").css("display", "none"); 
            break;  
            case "userManuals":  
                //change status &amp;amp;amp; style menu  
                $("#news").removeClass("active");  
                $("#newsletters").removeClass("active");  
                $("#userManuals").addClass("active"); 
				$("#links").removeClass("active"); 
                //display selected division, hide others  
                $("div.userManuals").fadeIn('fast',function()
                {
                     $(".change-url").css("display","none");
                    
                });  
                $("div.news").css("display", "none");  
                $("div.newsletters").css("display", "none");
				$("div.links").css("display", "none"); 
            break; 
			 case "links":  
                //change status &amp;amp;amp; style menu 
				$("#links").addClass("active");
				$("#userManuals").removeClass("active"); 
                $("#news").removeClass("active");  
                $("#newsletters").removeClass("active");  
                //display selected division, hide others  
				$("div.links").fadeIn('fast',function()
				{
                    content=$("div.links  h3").html();
                   
                    if(content)
                    { 
                        //$(".change-url").css("display","none");
                        $(".change-url a").attr("href","/l_"+lang+"/?s=14");
                        $(".change-url a").html(leksinfo);
                        $(".change-url").css("display","block");
                    }
                    else  $(".change-url").css("display","none");
				});   
                $("div.news").css("display", "none");  
                $("div.newsletters").css("display", "none");  
                $("div.userManuals").css("display", "none");  
            break;  
        }  
        //alert(e.target.id);  
        return false;  
    });  
    
    $(".zoomimg").fancybox();
    $(".fancyiframe").fancybox(
    {'type'				: 'iframe'}
);
    
    /*------load product list--------------------------*/ 
     loadCheckbox();      
     if($("#priduct-list").length)
     { 
             $(".loader").fadeIn('fast',function()
             {  
                $(".loader").fadeIn('fast');
               getP=location.hash.replace(/^#p=/, '');
               if(getP) offset='&p='+getP; 
               else offset='';                          
                ajaxSubmitForm(offset);    
             });
     }
     $(".filter-form input").click(    
     function()
     {  
         submitFilter();
     });
     var defaultMin=parseInt($(".minprice_value").html());
     var defaultMax=parseInt($(".maxprice_value").html());
     var valuta=$(".currency").html();
     var priceStep=parseInt($(".price_step").html());
     $("#price_slider").slider( 
     {      	
      	range:true,
      	min:defaultMin,
      	max:defaultMax,
      	values:[$("#price_min").val(),$("#price_max").val()],
      	step:priceStep,
      	slide:function(event,ui)      	
      	{
      		$("#price_min").val(ui.values[0]);
      		$("#price_max").val(ui.values[1]);
      		$(".range").html(ui.values[0]+valuta+" - "+ui.values[1]+valuta);
      		submitFilter();
      	}
      } );
      
      $("#clear-form").click(function()
      {
        clear_form_elements(".filter-form"); 
      });
    /*---------end load list---------------------------*/
    


});

function submitFilter()
{
     var url=location.href;
         urltmp=url.split("s=");
         if(urltmp[1]) urltmp2=urltmp[1].split("&");
         if(urltmp2[0]) param=urltmp2[0];
         else param=urltmp[1];         
         if(param==3)  
         {
            offset='';
            ajaxSubmitForm(offset);
            //location.href="#";
         }         
         else $(".filter-form").submit(); 
}

function loadCheckbox()
{    
    $(".filter-form input.props").each( function() {
        if(this.checked)
        {
            labelID=$(this).attr("id").replace(/^props_/, 'propc_');            
            $("#"+labelID).attr("class","checked");
        }
    });
    $(".filter-form input.model").each( function() {
        if(this.checked)
        {
            labelID=$(this).attr("id").replace(/^model_/, 'modelc_');
            $("#"+labelID).attr("class","checked");
        }
    });
    $(".filter-form input.brand").each( function() {
        if(this.checked)
        {
            labelID=$(this).attr("id").replace(/^brand_/, 'brandc_');
            $("#"+labelID).attr("class","checked");
        }
    });
}

function ajaxSubmitForm(offset) 
{      
   
   var options = 
   { 
        url: "/l_"+lang+"/showproducts.html?nd="+new Date().getTime()+offset,
        beforeSubmit: function()
        {    
             $(".loader").fadeIn('fast');
        },
        success: function(data) 
        {
             //$("#priduct-list").html('<div class="loader" style="margin:100px 300px;display:none;"><img src="/include/im/ajax-loader.gif" alt=""/></div>');
             $(".loader").fadeIn('fast',function()             
             {
                $("#priduct-list").html(data);  
                $(".loader").fadeOut('fast');
             });             
        },
        dataType: 'html'      
    }; 
    $(".filter-form").ajaxSubmit(options);  
}
function pager(lang,pager,url)
{        
       
       //$("#priduct-list").html('<div class="loader" style="margin:100px 300px;display:none;"><img src="/include/im/ajax-loader.gif" alt=""/></div>'); 
       $(".loader").fadeIn('fast',function()
       {
            catid=$(".catid").val();
            $("#priduct-list").load("/l_"+lang+"/showproducts.html?nd="+new Date().getTime()+"&p="+pager+"&catid="+catid+url,{}
            //{"model":model,"brand":brand,"props":props,"catid":catid}
            ,function(){$(".loader").fadeOut('fast');});
            location.href="#p="+pager;
           
       });   
       
}
function setCheck(id,prefix,oldprefix)
{ 
    newid=prefix+'_'+id; 
    if($("#"+oldprefix+'_'+id).is(":checked"))
    {        
        $("#"+newid).attr("class","checked");        
    }
    else $("#"+newid).removeAttr("class"); 
}
function clear_form_elements(ele) 
{
      $(ele).find(':input').each(function() {
      switch(this.type) {    
        case 'checkbox':
        case 'radio':
        this.checked = false;
        }
      });
      defalt_min=$(".minprice_value").html();
      defalt_max=$(".maxprice_value").html();
      var valuta=$(".currency").html();
      $("#price_min").val(defalt_min);
      $("#price_max").val(defalt_max);
      $(".range").html(defalt_min+valuta+" - "+defalt_max+valuta); 
      $("#price_slider").slider( "values" , 0 , defalt_min );	
      $("#price_slider").slider( "values" , 1 , defalt_max );
      $(ele+" li").removeAttr("class");
      submitFilter();
}

function submitOrderForm()
 {
    $("#prev").val("1");
    $('#orderform').submit();
 }
 
function loadSelectComp()
{
    var id=$('#comparecat').val();     
   
    if(id)
    {
        $("#comparewith").removeOption(/./);
        $("#comparewith").ajaxAddOption("/include/scripts/script_form_products.php",{"id":id},false,function()
	{        	
        
	});
    }   
}
