// display decision alert box

function decision(message, url){
    if(confirm(message)) location.href = url;
}
// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {
           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
           win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) {
                  win.window.focus();
           }
}
function sw_m(sub){
  try {
    oDiv = document.getElementById(sub);
    if(oDiv.style.display == 'block')oDiv.style.display = 'none';
    else oDiv.style.display = 'block';
  } catch(e){ }
}
function jumpMenu(target,object,restore){
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}
function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function getImage(imageName)
{
        findObj('img').src = imageName;
}
function getImagePopUp(imageName, width, height, realwidth, realheight)
{                      
        width = width || 0;
        height = height || 0;
        width = parseInt(width);
        height = parseInt(height);  
        
        $("#imgpopup").fadeOut(400,function(){
        if(width > 0 && height >0)             
           $("#imgpopup").attr("src",imageName).attr("width",width).attr("height",height);           
        else
           $("#imgpopup").attr("src",imageName); 
         $("#imgpopup").fadeIn(400);  
        });  
        
        CheckLoupe(imageName,realwidth,realheight);  
        
           
               
}   

function CheckLoupe(imageName,realwidth,realheight)
{
       if(realwidth > 420 || realheight > 420) 
       {
            $(".loupe").removeClass("disabled").addClass("enabled").children("img").css("display","block"); 
            $('.loupe').children('img').attr('src',imageName).attr("width",realwidth).attr("height",realheight);
       }     
        else
            $(".loupe").removeClass("enabled").addClass("disabled").children("img").css("display","none");     
}

function submitDoc(formName) {
  var obj;
      
    if (obj=findObj(formName)!=null)
    {         
        findObj(formName).submit();
    }
    else
    {
        alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
    }
}
 
 $(document).ready(function(){ 
 
       
 if(!navigator.cookieEnabled)
   // $("#no_cookies").html("Cookies ir izslēgti. Lai interneta veikals pilnvertīgi strādātu ieslēdziet cookies uz Jūsu brauzera.Cookies выключены. Для того полноценной работы сайте включите cookies в Вашем браузере.Your browser's cookie functionality is disabled. Please enable them in order to use full website functionality.");
               alert("Cookies ir izslēgti. Lai interneta veikals pilnvērtīgi strādātu ieslēdziet Cookies Jūsu brauzerī. Varat turpināt veikt pasūtījumu arī ar izslēgtiem Cookies, bet tādā gadījumā mēs negarantējam internetveikala pilnvērtīgu darbību.\n\nCookies выключены. Для полноценной работы интернет-магазина включите cookies в Вашем браузере. Вы можете продолжать оформлять заказ с выключенными cookies, но в этом случае мы не гарантируем полноценной работы интернет магазина.\n\nYour browser's cookie functionality is disabled. Please enable them in order to use full online store functionality. You can continue checkout process, however in this case we can not guarantee online store full functionality.");     
  ShowContentTable();  
  $("#tab_descr, #tab_connected").click(function(){          
           
       if($(this).hasClass("tab"))
       {
           id = $(".tab_selected").attr("id");
           $(".tab_selected").removeClass("tab_selected");
           $("#"+id).addClass("tab");             
           $(this).removeClass("tab");
           $(this).addClass("tab_selected");           
       }
       
       ShowContentTable();
     
  });
  
  function ShowContentTable()
  {        
     if($("#tab_descr").hasClass("tab_selected"))
     {         
        $("#content_descr").css("display","block");
        $("#content_con").css("display","none");
     }   
     if($("#tab_connected").hasClass("tab_selected"))
     {
        $("#content_con").css("display","block");
        $("#content_descr").css("display","none"); 
     }        
  }
  
 });
 function nav_noliktava() {
     //alert ('Iespējams prece šobrīd nav pieejama. Informāciju par preču piegādi noliktavā var saņemt rakstot uz e-pastu semicom@semicom.lv vai zvanot pa tālr. 67543310');
     alert ('Prece nav noliktavā. Piegāde iespējama 1-4 nedāļu laikā. Informāciju par preču piegādi saņemsiet pēc pasūtījuma veikšanas, vai jautājiet rakstot uz e-mail  semicom@semicom.lv\n\n\nТовара нет на складе. Доставка возможна в течении 1-4х недель. Информацию о доставке товара получите после осуществления заказа или же написав на e-mail semicom@semicom.lv\n\n\nGoods are not in stock. Delivery is possible during 1-4 weeks. Information about the delivery of goods will be sent after the booking, or by contacting us at semicom@semicom.lv');
 }
 function many_goods(a) {
       document.getElementById('quan').value=a.value;
 }
 function getXmlHttp(){
  var xmlhttp;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}
 function submenu(obj,ss) {
     //alert(obj+' '+ss);
    var xmlhttp = getXmlHttp();
    xmlhttp.open("GET", "/getsubmenu.php?s="+encodeURIComponent(obj)+"&ss="+encodeURIComponent(ss)+"&l="+Math.random(), true);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
     //alert(xmlhttp.responseText);
     //++++++++++++++++++++++++++++++++++++++
       document.getElementById('sub'+obj).innerHTML=xmlhttp.responseText;
     //++++++++++++++++++++++++++++++++++++
         }
    }
  };
  xmlhttp.send(null);
}
  function clickMenu1(obj1) {
       // alert(obj1);
     if (document.getElementById(obj1).style.display=='') {
     document.getElementById(obj1).style.display='block';
     return(0);
     }
     if (document.getElementById(obj1).style.display=='none') {
     document.getElementById(obj1).style.display='block';
     return(0);
     }
     if (document.getElementById(obj1).style.display=='block') {
     document.getElementById(obj1).style.display='none';
     return(0);
     }
     }
function show(obj) {
 if (document.getElementById(obj)!=null) {
    if (document.getElementById(obj).style.display == 'none') {
       document.getElementById(obj).style.display = 'block';
    }else {
       document.getElementById(obj).style.display = 'none';
    }
  }
}
function raschot()
{    
      
    
    var summa = document.getElementById("summa").value;
    
    var pirma_iemaksa = document.getElementById("iemaksa").value / 100;
    //alert(pirma_iemaksa);
    //return;
    //alert(11);
    //return;
    if (
        //document.calculator.summa.value > 4000
        document.getElementById("summa").value > 4000
        )  
    {
        window.alert("Pirkuma maksa nevar pārsniegt 4000 Ls");
    }
    else if (
        //document.calculator.summa.value < 35
        document.getElementById("summa").value < 35
        )
    {
        window.alert("Pirkuma maksa nevar būt mazākā par 35 Ls");
    }
    if (summa - summa * pirma_iemaksa > 2000) 
    {
        window.alert("Minimālais pirma_iemaksas " + Math.ceil((summa - 2000)/summa*100) + "%");
    } 
    else
    {
        
    var month; var kontrol; var stavka; var apkp;
        if (
            //document.calculator.tarif.value == "1"
            document.getElementById("tarif").value == "1"
            )
        {
            if (
                //document.calculator.summa.value < 500
                document.getElementById("summa").value < 500
                )
              {
                if (    //(document.calculator.month.value >= 1) && (document.calculator.month.value <= 18)
                        (document.getElementById("month").value >= 1) && (document.getElementById("month").value <= 18)
                    )
                {
                    //month=document.calculator.month.value;
                    month=document.getElementById("month").value;
                    kontrol = 0.03;
                    stavka = 0.189;
                    apkp = 0.004;
                }
          
                if (
                    //(document.calculator.month.value >= 19) && (document.calculator.month.value <= 36)
                    (document.getElementById("month").value >= 19) && (document.getElementById("month").value <= 36)
                    )
                {
                    //month=document.calculator.month.value;
                    month=document.getElementById("month").value;
                    kontrol = 0.03;
                    stavka = 0.194;
                    apkp = 0.004;
                }
            }
        
            if (
                //document.calculator.summa.value >= 500
                document.getElementById("summa").value >= 500
                )
            {
                if (
                    //(document.calculator.month.value >= 1) && (document.calculator.month.value <= 18)
                    (document.getElementById("month").value >= 1) && (document.getElementById("month").value <= 18)
                    )
                {
                    //month=document.calculator.month.value;
                    month=document.getElementById("month").value;
                    
                    kontrol = 0.04;
                    stavka = 0.151;
                    apkp = 0.005;
                }
          
                if (
                    //(document.calculator.month.value >= 19) && (document.calculator.month.value <= 36)
                    (document.getElementById("month").value >= 19) && (document.getElementById("month").value <= 36)
                    )
                {
                    //month=document.calculator.month.value;
                    month=document.getElementById("month").value;
                    
                    kontrol = 0.04;
                    stavka = 0.166;
                    apkp = 0.005;
                }
            }
        }
        
        
        if (
            //document.calculator.tarif.value == "2"
            document.getElementById("tarif").value == "2"
            
            )
        {
            //month=document.calculator.month.value;
            month=document.getElementById("month").value;
            
            kontrol = 0;
            stavka = 0.149;
            apkp = 0.005;
        }
        
        
        if (
            //document.calculator.tarif.value == "3"
            document.getElementById("tarif").value == "3"
            )
        {
            if (
                //(document.calculator.month.value >= 1) && (document.calculator.month.value <= 36)
                (document.getElementById("month").value >= 1) && (document.getElementById("month").value <= 36)
                )
            {
                //month=document.calculator.month.value;
                month=document.getElementById("month").value;
                kontrol = 0;
                stavka = 0.23;
                apkp = 0.005;
            }
        }
        
        if (
            //document.calculator.tarif.value == "4"
            document.getElementById("tarif").value == "4"
            )
        {
            if (
                //(document.calculator.month.value >= 1) && (document.calculator.month.value <= 36)
                (document.getElementById("month").value >= 1) && (document.getElementById("month").value <= 36)
                )
            {
                //month=document.calculator.month.value;
                month=document.getElementById("month").value;
                kontrol = 0;
                stavka = 0;
                apkp = 0;
            }
        }
      
        var kontrolls = summa * kontrol;
        var pirma_iemaksaz = summa * pirma_iemaksa;
        var apkpz= summa * apkp;
        var vznos = kontrolls + pirma_iemaksaz;
        var ostatok = summa - pirma_iemaksaz;
        
        if (stavka == 0) 
        {
            jezemesja4no = ostatok / month; 
        }
        else
        { 
            jezemesja4no = (ostatok * stavka / 12) / (1 - Math.pow((1 + (stavka / 12)),-month)); 
        }
        
        samajasumma = jezemesja4no + apkpz;
        itogo = vznos + samajasumma*month;
        vznos = Math.round(vznos*100)/100;
        samajasumma = Math.round(samajasumma*100)/100;
        vsego = samajasumma * month;          
       
               console.log(pirma_iemaksa);
       // document.getElementById("kontrol").innerHTML = IntToStr(kontrol * 100);
        document.getElementById("pirma_iemaksa").innerHTML = IntToStr(pirma_iemaksa * 100);
       // document.getElementById("stavka").innerHTML = IntToStr(stavka * 100);
       // document.getElementById("usluga").innerHTML = IntToStr(apkp * 100);
        //document.getElementById("vznos").innerHTML = IntToStr(vznos);
        document.getElementById("men_maks").innerHTML = IntToStr(samajasumma);
        
    }
}
//-->
function rekinat () {   if(document.getElementById('kompanija').value==1 || parseInt(document.getElementById('kompanija').value.replace("'",""))==10) {
               if (document.getElementById('summa').value >0)
       {
           
         // raschot(); 
        
          var Objvert = document.getElementById('summa').value;
          var Piem =  document.getElementById('iemaksa').value;
          var men =   document.getElementById('termins').value;
          var proc = 24;
          pirm_iem=0;
          if (Piem>0) pirm_iem =  Piem * Objvert / 100;
          aizd_sum=Objvert-pirm_iem;
          proc2 = proc /12 / 100;
          Ikm_Maks = aizd_sum * proc2* (1-1/(1-Math.pow(1+proc2,men)));
          document.getElementById('men_maks').innerHTML= Ikm_Maks.toFixed(2);
          document.getElementById('pirma_iemaksa').innerHTML= pirm_iem.toFixed(2);
         
       }  
   }
   if(document.getElementById('kompanija').value==2) {          //alert('GE Money');
       if (document.getElementById('summa').value >0)
       {
          var Objvert = document.getElementById('summa').value;
          var Piem =  document.getElementById('iemaksa').value;
          var men =   document.getElementById('termins').value;
           var proc = 26;
          if  (document.getElementById('pirkums').value==0)   var proc = 26;
          if  (document.getElementById('pirkums').value==1)   var proc = 24;
          if  (document.getElementById('pirkums').value==2)   var proc = 22;
          pirm_iem=0;
          if (Piem>0) pirm_iem =  Piem * Objvert / 100;
          aizd_sum=Objvert-pirm_iem;
          proc2 = proc /12 / 100;
          Ikm_Maks = aizd_sum * proc2* (1-1/(1-Math.pow(1+proc2,men)));
          document.getElementById('men_maks').innerHTML= Ikm_Maks.toFixed(2);
          document.getElementById('pirma_iemaksa').innerHTML= pirm_iem.toFixed(2);
       }
   }
   if(document.getElementById('kompanija').value==3) {
         // alert('Parex');
       if (document.getElementById('summa').value >0)
       {          var Objvert = document.getElementById('summa').value;
          var Piem =  document.getElementById('iemaksa').value;
          var men =   document.getElementById('termins').value;
          var proc = 26;
          pirm_iem=0;
          if (Piem>0) pirm_iem =  Piem * Objvert / 100;
          aizd_sum=Objvert-pirm_iem;
          proc2 = proc /12 / 100;
          Ikm_Maks = aizd_sum * proc2* (1-1/(1-Math.pow(1+proc2,men)));
          document.getElementById('men_maks').innerHTML= Ikm_Maks.toFixed(2);
          document.getElementById('pirma_iemaksa').innerHTML= pirm_iem.toFixed(2);
       }
   }
   if(document.getElementById('kompanija').value==4) {
       if (document.getElementById('summa').value >0)
       {
          var Objvert = document.getElementById('summa').value;
          var Piem =  document.getElementById('iemaksa').value;
          var men =   document.getElementById('termins').value;
          var proc = 27;
          pirm_iem=0;
          if (Piem>0) pirm_iem =  Piem * Objvert / 100;
          aizd_sum=Objvert-pirm_iem;
          proc2 = proc /12 / 100;
          Ikm_Maks = aizd_sum * proc2* (1-1/(1-Math.pow(1+proc2,men)));
          document.getElementById('men_maks').innerHTML= Ikm_Maks.toFixed(2);
          document.getElementById('pirma_iemaksa').innerHTML= pirm_iem.toFixed(2);
       }
   }
}
 function close_calc() {
 document.getElementById('lizinga_kalkulators').style.display='none';
 }
  function open_calc() {
 document.getElementById('lizinga_kalkulators').style.display='block';
 }
 function addsalidzin(x) {
  //alert(x.name);
  url=window.location.href+'&sal='+x.name;
///  alert(url);
  window.location = url;
 }
