var act_el
var new_win
var pics=new Array()

function put_pic(vl,id,lg,w,can,ttl){
         //pic=new Image();
         //pic.src=vl;
         if (lg==1 && can=='1' && pics[id]=='0'){
            document.getElementById("pic_id").innerHTML="<div id='vote_photo_"+id+"_cnt'>"+
             "<table id='vote_photo_"+id+"' class='vote'>"+
                         "<tr>"+
                           "<td id='vote_photo_"+id+"_1' class='vote_star' onMouseOver='higlight_vote("+id+", 1, 1);' onMouseOut='higlight_vote("+id+", 1, 0);' onClick='makeVote("+id+", 1);'></td>"+
                           "<td id='vote_photo_"+id+"_2' class='vote_star' onMouseOver='higlight_vote("+id+", 2, 1);' onMouseOut='higlight_vote("+id+", 2, 0);' onClick='makeVote("+id+", 2);'></td>"+
                           "<td id='vote_photo_"+id+"_3' class='vote_star' onMouseOver='higlight_vote("+id+", 3, 1);' onMouseOut='higlight_vote("+id+", 3, 0);' onClick='makeVote("+id+", 3);'></td>"+
                           "<td id='vote_photo_"+id+"_4' class='vote_star' onMouseOver='higlight_vote("+id+", 4, 1);' onMouseOut='higlight_vote("+id+", 4, 0);' onClick='makeVote("+id+", 4);'></td>"+
                           "<td id='vote_photo_"+id+"_5' class='vote_star' onMouseOver='higlight_vote("+id+", 5, 1);' onMouseOut='higlight_vote("+id+", 5, 0);' onClick='makeVote("+id+", 5);'></td>"+
                           "<td id='vote_comment_"+id+"' class='vote_comment'></td>"+
                         "</tr>"+
             "</table>"+ttl+
             "</div><br /><img src='"+vl+"' alt='' />";
         }else{
            document.getElementById("pic_id").innerHTML=ttl+"<br /><img src='"+vl+"' alt='' />";
         }

}

function set_pr(val,id){
         //alert(val+"|"+id)
         //alert(document.getElementById("g_price"+id))
         document.getElementById("g_price"+id).value=prices[val]
}

function add_pr_row(){
         if (row<=10) document.getElementById("row"+row).style.display='block'
         //document.getElementById("row"+row).style.visibility='visible'
         row++
}

function drop_row(nr){
         document.getElementById("row"+nr).style.display='none'
         if (document.getElementById("g_id"+nr)) document.getElementById("g_id"+nr).options[0].selected=true
         if (document.getElementById("g_name"+nr)) document.getElementById("g_name"+nr).value=""
         //alert(document.getElementById("g_name"+nr))
}

function add_sr_row(){
         if (srow<=10) document.getElementById("srow"+srow).style.display='block'
         //document.getElementById("row"+row).style.visibility='visible'
         srow++
}

function drop_srow(nr){
         document.getElementById("srow"+nr).style.display='none'
         if (document.getElementById("g_service"+nr)) document.getElementById("g_service"+nr).value=""
         //document.getElementById("row"+nr).style.visibility='hidden'
}

function popupWindow(url){
         var width=800
         var height=600
         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+""

         window.open(url,'','toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=no,resizable=no,copyhistory=no,screenX=0,screenY=0,'+params)
}


function show_m(id){
         //alert('ok');

         var ar = document.getElementById("menu").getElementsByTagName("div")

         for (var i=0; i<ar.length; i++){
             if (ar[i].className=="sub") ar[i].style.visibility = "hidden"
         }

         if (id.length>0){
            if (document.getElementById(id)){
               document.getElementById(id).style.visibility="visible"
            }
         }
}


function get_mouse_x(current_event) {
    if (its_ie4plus) {
        return event.clientX
    }else if (its_ns4plus) {
        return current_event.pageX
    }else if (its_opera) {
        return current_event.pageX
    }else{
        event.clientX
    }
}

function get_mouse_y(current_event) {
    if (its_ie4plus) {
        return event.clientY
    }else if (its_ns4plus) {
        return current_event.pageY
    }else if (its_opera) {
        return current_event.pageY
    }else{
        event.clientY
    }
}

function check_email(self,val){
     if (val.length>0){    
         var ok=0
         for(var ii=0;ii<val.length;ii++){
                 if (val.charAt(ii)=="@") ok=1
         }
         if (ok==1 && val.length>=7) return true
         else{
             alert("Neteisingai įvedėte el.paštą!")
             return false
         }
     }else return true
}


function eqq(val1,val2){
         var ok1=0
         for(var ii=0;ii<val1.length;ii++){
                 if (val1.charAt(ii)==val2.charAt(ii)) ok1++
         }
         if (ok1==val1.length && val1.length==val2.length) return true
         else return false
}

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 params="height="+height+",width="+width+",left="+window_left+",top="+window_top+",scrollbars=no"
       new_win=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){
     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 count_years(b,el){
     var birth=document.getElementById(b).value
     var b_year=birth.substr(6,4)
     var date_val=new Date()
     var n_year=date_val.getYear()
     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 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
}

