function toggle_prods(v){
         //alert('ok')
         if (v=='drp18_val_99' || v=='drp18_val_98' || v=='drp18_val_100' || v=='drp18_val_97'){
            for (var i=1; i<50; i++){
                if (document.getElementById('products'+i)) document.getElementById('products'+i).style.display='none'
            }
         }

         if (v=='drp18_val_103' || v=='drp18_val_102' || v=='drp18_val_104' || v=='drp18_val_105'){
            for (var i=1; i<50; i++){
                if (document.getElementById('products'+i)) document.getElementById('products'+i).style.display=''
            }
         }
}

function cnt_sm(){

         q1=document.getElementById('fd173').value*1
         p1=document.getElementById('fd174').value*1

         q2=document.getElementById('fd176').value*1
         p2=document.getElementById('fd177').value*1

         q3=document.getElementById('fd179').value*1
         p3=document.getElementById('fd180').value*1

         q4=document.getElementById('fd182').value*1
         p4=document.getElementById('fd183').value*1

         q5=document.getElementById('fd185').value*1
         p5=document.getElementById('fd186').value*1

         res=q1*p1+q2*p2+q3*p3+q4*p4+q5*p5

         document.getElementById('fd150').value=res

}

function count_ae(h1_div,m1_div,h2_div,m2_div,res_div){

         h1=document.getElementById(h1_div).value*1
         h2=document.getElementById(h2_div).value*1

         m1=document.getElementById(m1_div).value*1
         m2=document.getElementById(m2_div).value*1

         var res_min=0
         if (h1==h2){
            res_min=m2-m1
         }else{
            var h_dur=h2-h1
            var m_dur=m2-m1
            if (m2<m1){
                h_dur=h_dur-1
                var tmp=60-m1
                m_dur=tmp+m2
            }
            res_min=h_dur*60+m_dur
         }
         res=Math.round(res_min/10)
         //alert(h1+":"+m1+"\n"+h2+":"+m2+"\n"+res)
         if (document.getElementById(res_div)) document.getElementById(res_div).value=res

         return true
         
}

function show_it(self,val){
     if (document.getElementById(val).style.display=="block"){
             document.getElementById(val).style.display="none"
             //self.src="http://localhost:8080/crm/img/help_down.jpg"
             //self.src="http://www.objekt-datenbank.de/dev/img/help_down.jpg"
             self.src="img/down.jpg"
             //self.src="http://208.58.148.104/crm/img/help_down.jpg"

     }else{
             document.getElementById(val).style.display="block"
             //self.src="http://localhost:8080/crm/img/help_up.jpg"
             //self.src="http://www.objekt-datenbank.de/dev/img/help_up.jpg"
             self.src="img/up.jpg"
             //self.src="http://208.58.148.104/crm/img/help_up.jpg"

     }

}

function show_sw(self,val){
     if (document.getElementById("txt"+val+"small").style.display=="block"){
             document.getElementById("txt"+val+"small").style.display="none"
             document.getElementById("txt"+val+"big").style.display="block"
             self.src="img/down.gif"
     }else{
             document.getElementById("txt"+val+"big").style.display="none"
             document.getElementById("txt"+val+"small").style.display="block"
             self.src="img/up.gif"
     }
}

function w_show_hide(val){
         if (val=="Pralaimetas"){
            document.getElementById('winner1').style.display="block"
            document.getElementById('winner2').style.display="block"
         }else{
            document.getElementById('winner1').style.display="none"
            document.getElementById('winner2').style.display="none"
         }
         return true
}

function go_delete(link,main_div){
     var ar = document.getElementById(main_div).getElementsByTagName("div")
     
     var act_div
     for (var i=0; i<ar.length; i++){
         if (ar[i].className=="sub"){
            if (ar[i].style.display == "block") act_div=ar[i].id
         }
     }

     document.location=link+"&act_div="+act_div
}

function show_list(main_div,val){
     var ar = document.getElementById(main_div).getElementsByTagName("div")

     for (var i=0; i<ar.length; i++){
         if (ar[i].className=="sub"){
            ar[i].style.display = "none"
            //alert(ar[i].id)
            if (document.getElementById(ar[i].id+"_menu")) document.getElementById(ar[i].id+"_menu").style.backgroundColor="#E8E7ED"
         }
     }
     if (document.getElementById(val)){
        document.getElementById(val).style.display="block"
        document.getElementById(val+"_menu").style.backgroundColor="#ffffff"
     }
     //alert("<? echo $ar['val']; ?>")
}
function isnumber(string){
     str="0123456789:"
     result=0;
     for (var i=0; i < string.length; i ++){
         for (var j=0; j < str.length; j++){
             if (string.charAt(i) == str.charAt(j)){
                result = result + 1;
             }
         }
     }
     if (result == string.length) return true
     else return false
}
function open_window(width,height,link,type){
       var window_left=(screen.availWidth/2)-(width/2)
       var window_top=(screen.availHeight/2)-(height/2)
       var width1=width+20
       var params="height="+height+",width="+width1+",left="+window_left+",top="+window_top+",scrollbars=yes"
       window.open(link+"?type="+type,'',params)
       return true
}

function open_window1(width,height,link){
       var window_left=(screen.availWidth/2)-(width/2)
       var window_top=(screen.availHeight/2)-(height/2)
       //var width1=width+20
       var params="height="+height+",width="+width+",left="+window_left+",top="+window_top+",scrollbars=yes"
       window.open(link,'',params)
       return true
}

function open_win(width,height,link){
       var window_left=(screen.availWidth/2)-(width/2)
       var window_top=(screen.availHeight/2)-(height/2)
       var params="height="+height+",width="+width+",left="+window_left+",top="+window_top+",scrollbars=yes"
       window.open(link,'',params)
       return true
}

function select_item(val,type){
     for(var kk=0;kk<opener.document.getElementById(type).options.length;kk++){
             if (opener.document.getElementById(type).options[kk].value==val){
                opener.document.getElementById(type).options[kk].selected=true
             }
     }
     self.close()
     return true
}

function input_item(val,type){
     if (opener.document.getElementById(type)){
        opener.document.getElementById(type).value=val
        self.close()
     }
     return true
}

function rep(self,id){
         if (self.length>0){
            var val=""
            for(var ii=0;ii<self.length;ii++){
                    if (self.charAt(ii)=="-") val+="."
                    else val+=self.charAt(ii)
            }
            //var val=self.replace("-",".")
            document.getElementById(id).value=val
            return true
         }else return true
}

function no_points(val){
         var out=""
         for(var ii=0;ii<val.length;ii++){
                 if (val.charAt(ii)!=".") out+=val.charAt(ii)
         }
         return out
}

function count_sum(id){
     var count=document.getElementById('count_'+id).value
     var price=document.getElementById('price_'+id).value

     count=no_points(count)
     count=count.replace(",",".")
     price=no_points(price)
     price=price.replace(",",".")
     var res=count*price
     res=res+""
     res=res.replace(".",",")
     document.getElementById('sum_'+id).value=res
     
     count=count.replace(".",",")
     document.getElementById('count_'+id).value=count
     
     price=price.replace(".",",")
     document.getElementById('price_'+id).value=price

     return true
}

function format_sum(id){
     var v=document.getElementById(id).value

     v=no_points(v)
     //v=v.replace(",",".")
     //s=res.replace(".",",")
     document.getElementById(id).value=res
     
     return true
}

function count_years(b,el){
     var birth=document.getElementById(b).value

     if (birth.length>0){

        var b_year=birth.substr(6,4)
        b_year*=1

        var b_mon=birth.substr(3,2)
        if (b_mon.substr(0,1)=="0") b_mon=b_mon.substr(1,1)
        b_mon*=1

        var b_day=birth.substr(0,2)
        if (b_day.substr(0,1)=="0") b_day=b_day.substr(1,1)
        b_day*=1

        var zd
        if (b=="birthdate"){
           if ( ((b_mon==1) && (b_day>=21)) || ((b_mon==2) && (b_day<=19)) ) zd="aquarius"
           if ( ((b_mon==2) && (b_day>=20)) || ((b_mon==3) && (b_day<=20)) ) zd="pisces"
           if ( ((b_mon==3) && (b_day>=21)) || ((b_mon==4) && (b_day<=20)) ) zd="aries"
           if ( ((b_mon==4) && (b_day>=21)) || ((b_mon==5) && (b_day<=20)) ) zd="taurus"
           if ( ((b_mon==5) && (b_day>=21)) || ((b_mon==6) && (b_day<=21)) ) zd="gemini"
           if ( ((b_mon==6) && (b_day>=22)) || ((b_mon==7) && (b_day<=22)) ) zd="cancer"
           if ( ((b_mon==7) && (b_day>=23)) || ((b_mon==8) && (b_day<=23)) ) zd="leo"
           if ( ((b_mon==8) && (b_day>=24)) || ((b_mon==9) && (b_day<=23)) ) zd="virgo"
           if ( ((b_mon==9) && (b_day>=24)) || ((b_mon==10) && (b_day<=23)) ) zd="libra"
           if ( ((b_mon==10) && (b_day>=24)) || ((b_mon==11) && (b_day<=22)) ) zd="scorpio"
           if ( ((b_mon==11) && (b_day>=23)) || ((b_mon==12) && (b_day<=21)) ) zd="sagittarius"
           if ( ((b_mon==12) && (b_day>=22)) || ((b_mon==1) && (b_day<=20)) ) zd="capricorn"

           if (document.getElementById('zodiac')){
              sar=document.getElementById('zodiac')
              for (i_ = 0; i_ < sar.length; i_++)
              if (sar.options[i_].value == zd) sar.options[i_].selected=true
           }
        }
        //alert(b_year+"|"+b_mon+"|"+b_day)

        var date_val=new Date()

        var n_year=date_val.getFullYear()
        n_year*=1

        var n_mon=date_val.getMonth()
        n_mon+=1
        n_mon+=''
        if (n_mon.substr(0,1)=="0") n_mon=n_mon.substr(1,1)
        n_mon*=1

        var n_day=date_val.getDate()
        n_day*=1

        //alert(n_year+"|"+n_mon+"|"+n_day)

        var res=0
        if (b_year==n_year){
           res=0
        }else if (b_year<n_year){
           if (b_mon<n_mon){
              res=n_year-b_year
           }else if (b_mon>n_mon){
              res=n_year-b_year-1
           }else{
              res=n_year-b_year 
              if (b_day>n_day) res--
           }
        }

        //alert(b_year+"|"+n_year)

        //var res=1*n_year-1*b_year
        document.getElementById(el).value=res
     }
     return true
}

function unselect(list){
  for (i = 0; i < list.length; i++)
    if (list.options[i].selected)
      list.options[i].selected = false
  return true
}

function select_all(){
  if (document.getElementById('inform_d')){
     list=document.getElementById('inform_d')
     for (i = 0; i < list.length; i++)
       list.options[i].selected = true
  }
  return true
}


function in_list(id,name,l_name){
    sar=document.getElementById(l_name)
    for (i_ = 0; i_ < sar.length; i_++)
        if (sar.options[i_].value == id) return true
    return false
}


function add_to_list(){
  //sarasas1 = document.main_form.elements['inform_old[]'];
  //sarasas2 = document.main_form.elements['inform[]'];
  sarasas1 = document.getElementById('inform_s')
  sarasas2 = document.getElementById('inform_d')
  for (i = 0; i < sarasas1.length; i++) {
    if (sarasas1.options[i].selected) {
      id = sarasas1.options[i].value
      pav = sarasas1.options[i].text
      if (!in_list(id,pav,'inform_d')){
        sarasas2.options[sarasas2.length] = new Option(pav, id, false, false)
      }
    }
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function add_all(){
  sarasas1 = document.getElementById('inform_s')
  sarasas2 = document.getElementById('inform_d')
  for (i = 0; i < sarasas1.length; i++) {
      id = sarasas1.options[i].value
      pav = sarasas1.options[i].text
      if (!in_list(id,pav,'inform_d')){
        sarasas2.options[sarasas2.length] = new Option(pav, id, false, false)
      }
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function rem_from_list(){
  sarasas1 = document.getElementById('inform_s')
  sarasas2 = document.getElementById('inform_d')
  //sarasas1 = document.main_form.elements['inform_old[]'];
  //sarasas2 = document.main_form.elements['inform[]'];
  for (i = sarasas2.length-1; i >= 0; i--){
    if (sarasas2.options[i].selected) sarasas2.options[i] = null
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function rem_all(){
  sarasas1 = document.getElementById('inform_s')
  sarasas2 = document.getElementById('inform_d')
  for (i = sarasas2.length-1; i >= 0; i--){
    sarasas2.options[i] = null
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

///////////////////////////////////////////////////

function select_all_res(){
  if (document.getElementById('inform_d_res')){
     list=document.getElementById('inform_d_res')
     for (i = 0; i < list.length; i++)
       list.options[i].selected = true
  }
  return true
}

function add_to_list_res(){
  //sarasas1 = document.main_form.elements['inform_old[]'];
  //sarasas2 = document.main_form.elements['inform[]'];
  sarasas1 = document.getElementById('inform_s_res')
  sarasas2 = document.getElementById('inform_d_res')
  for (i = 0; i < sarasas1.length; i++) {
    if (sarasas1.options[i].selected) {
      id = sarasas1.options[i].value
      pav = sarasas1.options[i].text
      if (!in_list(id,pav,'inform_d_res')){
        sarasas2.options[sarasas2.length] = new Option(pav, id, false, false)
      }
    }
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function add_all_res(){
  sarasas1 = document.getElementById('inform_s_res')
  sarasas2 = document.getElementById('inform_d_res')
  for (i = 0; i < sarasas1.length; i++) {
      id = sarasas1.options[i].value
      pav = sarasas1.options[i].text
      if (!in_list(id,pav,'inform_d_res')){
        sarasas2.options[sarasas2.length] = new Option(pav, id, false, false)
      }
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function rem_from_list_res(){
  sarasas1 = document.getElementById('inform_s_res')
  sarasas2 = document.getElementById('inform_d_res')
  //sarasas1 = document.main_form.elements['inform_old[]'];
  //sarasas2 = document.main_form.elements['inform[]'];
  for (i = sarasas2.length-1; i >= 0; i--){
    if (sarasas2.options[i].selected) sarasas2.options[i] = null
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}

function rem_all_res(){
  sarasas1 = document.getElementById('inform_s_res')
  sarasas2 = document.getElementById('inform_d_res')
  for (i = sarasas2.length-1; i >= 0; i--){
    sarasas2.options[i] = null
  }
  unselect(sarasas1)
  unselect(sarasas2)
  return true
}


