
var dom = (document.getElementById)? true : false
var op = (window.opera)?true : false
var op5 = (op && dom)?true : false
var ns = (window.outerWidth && !op)?true : false
var ns6 = (ns && dom)?true : false
var ns4 = (ns && !dom)?true : false
var ie = (document.all && !op)?true : false
var ie5 = (ie && dom)?true : false
var ie4 = (ie && !dom)?true : false

var agt = navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var opera = (agt.indexOf("opera") != -1);
var mac = (agt.indexOf("mac") != -1);
var mac_ie = (ie && mac);
var win_ie = (ie && !mac);
var gecko  = (navigator.product == "Gecko");

var hq_img = new Image()
var zoom_win
var actprj_z, actimg_z, maxprj, cal_win, news_length
var sel1 = null, sel2 = null

function makeArray() {
  var args = makeArray.arguments;
  for (var i = 0; i < args.length; i++) {
    this[i] = args[i];
  }
  this.length = args.length;
}

function MY_getElementById (tag, id) {
	var el, i, objs = document.getElementsByTagName(tag);
	for (i = objs.length; --i >= 0 && (el = objs[i]);)
	{document.write (objs[i]+"<br>")
	if (el.id == id)
			return el;
}
	return null;
}

function attach(id)
{ var obj
  
//  if(ns4) obj = document.layers[id]
//   else if(ie4) obj = document.all[id]
//         else 
//          if(ie5 || ns6) obj = document.getElementById(id)
//           else obj = eval(id)
   //obj = document.getElementById(id)

   if (ie5)
    obj = document.all[id]
   else
    obj = document.getElementById(id)

//obj = MY_getElementById("",id)
return obj
}

 function set(id, val)
 { o = attach(id)
   o.value = val
   o.defaultValue = o.value
 }
  
 function set_to_default(id)
 { o = attach(id)
   o.value = o.defaultValue
 }
                 
 function flush(id)
 { o = attach(id)
   o.value = ""
 }

function hide_obj(id) { temp_Obj = attach(id)
                        if(ns4) temp_Obj.visibility = "hide"
                         else temp_Obj.style.visibility = "hidden"
                      }
function is_hidden(id) { temp_Obj = attach(id)
                         if(ns4) return (temp_Obj.visibility == "hide")
                          else return (temp_Obj.style.visibility == "hidden")
                      }
function show_obj(id) { temp_Obj = attach(id)
                        if(ns4) temp_Obj.visibility = "show"
                         else temp_Obj.style.visibility = "visible"
                      }

function put_on_top(id) { return
                          temp_Obj = attach(id)
                          if(ns4) temp_Obj.zIndex = "100"
                           else temp_Obj.style.zIndex = ""
                        }

function move_left(id) { step = 5
                         temp_Obj = attach(id)
                         if(ns4) temp_Obj.left = parseInt(temp_Obj.left) - step
                          else temp_Obj.style.left = parseInt(temp_Obj.style.left) - step
                       }
function move_top(id) { step = 5
                        temp_Obj = attach(id)
                        if(ns4) temp_Obj.top = parseInt(temp_Obj.top) - step
                         else temp_Obj.style.top = parseInt(temp_Obj.style.top) - step
                      }
 
function doMouseDown() { return true
                       }

function doMouseUp() { return true
                     }

//document.onmousedown = doMouseDown
//document.onmouseup = doMouseUp

function clockon() {
 var m = new makeArray("Gen","Feb","Mar","Apr","Mag","Giu","Lug","Aug","Set","Ott","Nov","Dic")
 var thistime= new Date()
 var hours=thistime.getHours()
 var minutes=thistime.getMinutes()
 var seconds=thistime.getSeconds()
 var day=thistime.getDate()
 var month=thistime.getMonth()
 var year=thistime.getFullYear()

 if (eval(hours) <10) {hours="0"+hours}
 if (eval(minutes) < 10) {minutes="0"+minutes}
 if (seconds < 10) {seconds="0"+seconds}
 thistime = day+"."+m[month]+"."+year+" "+hours+":"+minutes+":"+seconds 
 
// if(document.all) { o=attach("clock")
//                    o.value=thistime
//                  }
 o=attach('clock_span')
 o.innerHTML=thistime
	
 var timer=setTimeout("clockon()",1000)
}

function scroll_news() {
 step = 1
 o=attach('news_div')
 o.style.top = parseInt(o.style.top) - step
 if (parseInt(o.style.top) < parseInt(-news_length))
  o.style.top = 80
 var timer=setTimeout("scroll_news()",100)
}

 function set_day_href(d, m, y, s)
 { d = new Date(y,m,d)
//   o = attach(s)
   //o=document.getElementById(s)
   //o.value = d.toUTCString()
//   o = attach(s+"v")
   o=window.opener.document.getElementById(s+'v')
   o.value = d.toLocaleString()
   o=window.opener.document.getElementById(s)
//   alert ('|'+d.getTimezoneOffset()/60+'|')
//   d.setHours(d.getHours() + (d.getTimezoneOffset()/60))
//   o.value = d.toUTCString()
   o.value = d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate()
//   hide_obj ('div_cal_'+s)
   close_calendar()
 }

 function open_calendar(s)
 { cal_win = window.open('calendar.php?cal='+s, 'Calendar', 'toolbar=no, location=no, directories=no, titlebar=no, menubar=no, scrollbars=yes, resizable=yes, status=no, width=208, height=272, top='+(screen.height-232)/2+', left='+(screen.width-208)/2+'')
//   zoomhq()
//   alert (cal_win.name+" "+zoom_win.name)
 }
   
 function close_calendar()
 {//    alert (cal_win.name+" "+zoom_win.name)
if (cal_win)
    cal_win.close()
   cal_win=null
window.close()
//adjust_zoom_hq()
//alert (zoom_win.name)
 }

 function set_calendar(m, y, s)
 { var ld = new makeArray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
   var t, o, k, d, x

   if ((y%4) == 0) ld[1]++
    
   if (m == "") m = 1;
   if (y == "") y = 2000;
   
   t = new Date(y, m-1, 1);
   o = attach('get_month_'+s)
   o.value = m
   o = attach('get_year_'+s)
   o.value=y

   for (k = 0; k <= 13; k++)
   { o = attach(s+'_d'+eval(k+29))
     o.innerHTML=''
     o = attach(s+'_a'+eval(k+29))
     o.href='javascript:void(0)'
   }
   d = 1
   for (k = 0, t.setDate(d); k < t.getDay(); k++)
   { o=attach(s+'_d'+eval(d+k))
     o.innerHTML='-'
     o=attach(s+'_a'+eval(d+k))
     o.href='javascript:void(0)'
   }
   for (;d <= ld[m-1]; d++)
   { t.setDate(d)
     o=attach(s+'_d'+eval(d+k))
     o.innerHTML=d
     o=attach(s+'_a'+eval(d+k))
     o.href="javascript:set_day_href("+d+","+parseInt(m-1)+","+y+", '"+s+"')"
   }
   for (t.setDate(d), x = 6-t.getDay(); x >=0 ; x--)
   { o=attach(s+'_d'+eval(d+k+x))
     o.innerHTML='-'
     o=attach(s+'_a'+eval(d+k+x))
     o.href='javascript:void(0)'
   }
 }

 function set_cal(m, y, s)
 { var ld = new makeArray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
   var t, o, k, d, x

   if ((y%4) == 0) ld[1]++
    
   if (m == "") m = 1;
   if (y == "") y = 2000;

   t = new Date(y, m-1, 1);
   o = attach('get_month_'+s)
   o.value = m
   o = attach('get_year_'+s)
   o.value=y

   for (k = 0; k <= 13; k++)
   { o = attach(s+'_d'+eval(k+29))
     o.innerHTML=''
     o = attach(s+'_a'+eval(k+29))
     o.href='javascript:void(0)'
   }
   d = 1
   for (k = 0, t.setDate(d); k < t.getDay(); k++)
   { o=attach(s+'_d'+eval(d+k))
     o.innerHTML='-'
     o=attach(s+'_a'+eval(d+k))
     o.href='javascript:void(0)'
   }
   for (;d <= ld[m-1]; d++)
   { t.setDate(d)
     o=attach(s+'_d'+eval(d+k))
     o.innerHTML=d
     o=attach(s+'_a'+eval(d+k))
     o.href="javascript:set_day_href("+d+","+parseInt(m-1)+","+y+", '"+s+"')"
   }
   for (t.setDate(d), x = 6-t.getDay(); x >=0 ; x--)
   { o=attach(s+'_d'+eval(d+k+x))
     o.innerHTML='-'
     o=attach(s+'_a'+eval(d+k+x))
     o.href='javascript:void(0)'
   }
 }

 function cal_pos (c)
 { o=attach(c)
   o.style.left = event.x + document.body.scrollLeft
   o.style.top = event.y + document.body.scrollTop
   if (is_hidden(c))
    show_obj(c)
   else
    hide_obj(c)
   return true
 }

 function prep_gallery_obj(o)
 { // a[0] = position
   // a[1] = file name
   // a[2] = file size
   // a[3] = dimensions
   a = new Array()
   
   if (o.options.length != 0)
   { if (o.selectedIndex == -1)
     { o.options[0].selected=true
       a=o.options[0].value.split("|")
     }
     else
      a=o.value.split("|")
     set('gallery_pos', a[0]+"|"+o.id)
     o1 = attach(o.id+'_img')
     o1.src = user_img_dir+a[1]
     o1 = attach(o.id+'_fs')
     o1.innerHTML = a[2]
     o1 = attach(o.id+'_fd')
     o1.innerHTML = a[3]
   }
 }

 function prep_chars_obj(o, qs)
 { // a[0] = this_name
   // a[1] = obj_id
   // a[2] = char_elem_id
   // a[3] = lang
   // a[4] = return address
   a = new Array()
   
   if (o.options.length != 0)
   { if (o.selectedIndex == -1)
     { o.options[0].selected=true
       a=o.options[0].value.split("|")
     }
     else
      a=o.value.split("|")
      o1=attach('if|'+a[1]+'|'+a[3])
//      o2=attach('main_qs')
//      o1.src="index.php?section=put_chars&char="+a[2]+"&tab=char&lang="+a[3]+"&ra="+a[4]+"&main_qs="+o2.value
      //o1.src="index.php?section=put_chars&char="+a[2]+"&t=char&l="+a[3]+"&main_qs="+o2.value
      o1.src="index.php?section=put_chars&char="+a[2]+"&t=char&l="+a[3]
//      o1.innerHTML="index.php?section=put_chars&char="+a[2]+"&tab=char&lang="+a[3]+""
//     set('char_sel|'+a[1]+'|'+a[3], a[0]+"|"+o.id)
//     o1 = attach(o.id+'_img')
//     o1.src = user_img_dir+a[1]
//     o1 = attach(o.id+'_fs')
//     o1.innerHTML = a[2]
//     o1 = attach(o.id+'_fd')
//     o1.innerHTML = a[3]
   }
 }

 function zoomhq(img)
 { var aw = screen.availWidth
   var ah = screen.availHeight
   var sx = 256
   var sy = 64
   var x = (aw < sx)?0:(aw-sx)/2
   var y = (ah < sy)?0:(ah-sy)/2
   var dx = (aw < sx)?aw:sx
   var dy = (ah < sy)?ah:sy
   if (zoom_win)
   { zoom_win.close()
     zoom_win = null
   }
   zoom_win = window.open("", "zoom", 'toolbar=no, location=no, directories=no, menubar=no, scrollbars=no, resizable=yes, status=no, width='+dx+', height='+dy+', top='+y+', left='+x)
   hq_img.src = img
   //hq_img.width=100
   //hq_img.height=100
   zoom_win.document.write("<DIV ID='D_loading' STYLE='position: absolute; top: 28; left: 48; visibility: visible; z-index: -1000'>loading...</DIV>")
   hq_img.onload = adjust_zoom_hq
}

 function adjust_zoom_hq()
 {  if ((window.screen) && (zoom_win) && !zoom_win.closed)
   { var aw = screen.availWidth
     var ah = screen.availHeight
     var sx = parseInt(hq_img.width) + 12
     var sy = parseInt(hq_img.height) + 38
     var x = (aw < sx)?0:(aw-sx)/2
     var y = (ah < sy)?0:(ah-sy)/2
     var dx = (aw < sx)?aw:sx
     var dy = (ah < sy)?ah:sy
//alert (hq_img.availWidth)
     zoom_win.moveTo(x, y)
     zoom_win.resizeTo(dx, dy)
     zoom_win.document.write("<DIV ID='D_i' STYLE='position: absolute; top: 0; left: 0; z-index: 1000'><img id='zoom_img' name='zoom_img' src='"+hq_img.src+"' width='"+hq_img.width+"' height='"+hq_img.height+"'></div>")
   }
   return true
 }
 //hq_img.onload = adjust_zoom_hq

 function is_selected(o)
 { return ((o.className == 'tableline_sel') || (o.className == 'tableline_selover') || (o.className == 'tableline_lastsel') || (o.className == 'tableline_lastselover'))
 }

 function select_it(o)
 { switch(o.className)
   { case 'tableline':
     case 'tablelineover':
      if ((o == sel1) || (o == sel2))
       o.className = 'tableline_lastsel'
      else
       o.className = 'tableline_sel'
     break;
     
     case 'tableline_sel':
     case 'tableline_selover':
     case 'tableline_lastsel':
     case 'tableline_lastselover':
     o.className = 'tableline'
     break;
     
//     case 'tableline_lastsel':
//     case 'tableline_lastselover':
//     o.className = 'tableline_lastselover'
//     break;
   }

//if ((o.className == 'tableline') || (o.className == 'tablelineover'))
//   { if ((o == sel1) || (o == sel2))
//      o.className = 'tableline_lastsel'
//     else
//      o.className = 'tableline_sel'
//   }
//   else
//    o.className = 'tableline'
   return true
 }

 function last_two_selection(o)
 { if ((o != sel1) && (o != sel2) && ((is_selected(o))))
   { if (sel2)
    if (is_selected(sel2))
     sel2.className='tableline_sel'
o.className='tableline_lastsel'
   sel2 = sel1
   sel1 = o
   }
 }

 function hilite_it(o)
 { switch(o.className)
   { case 'tableline':
     o.className = 'tablelineover'
     break;
     
     case 'tableline_sel':
     o.className = 'tableline_selover'
     break;
     
     case 'tableline_lastsel':
     o.className = 'tableline_lastselover'
     break;
   }
//   if (o.className == 'tableline')
//    o.className = 'tablelineover'
//   else
 //   o.className = 'tableline_selover'
   return true
 }

 function dehilite_it(o)
 { switch(o.className)
   { case 'tableline':
     case 'tablelineover':
     o.className = 'tableline'
     break;
     
     case 'tableline_sel':
     case 'tableline_selover':
     o.className = 'tableline_sel'
     break;
     
     case 'tableline_lastsel':
     case 'tableline_lastselover':
     o.className = 'tableline_lastsel'
     break;
   }

//if ((o.className == 'tableline') || (o.className == 'tablelineover'))
//    o.className = 'tableline'
//   else
//    o.className = 'tableline_sel'
   return true
 }

 function selected_files(tag)
 { var s="", f = false

   all_files=document.getElementsByTagName(tag)
   for (t = 0; t < all_files.length; t++)
   { n = all_files[t].id
     a = n.split("|")
     if ((a[0] == "file") && (is_selected(all_files[t])))
     { if (f)
        s = s + "|"
       f = true
       s = s + a[1]
     }
   }
   alert (s)
   return s
}

 function extract_file_name(o)
 { if (o)
   { a = o.id.split("|")
     if (a[0] == 'file')
      return a[1]
   }  
   return false
 }

 function get_new_name(o)
 { var nn
   
   if (o)
   { if (nn = extract_file_name(o))
      return prompt('Rinomina',nn)
   }  
   return false
 }

 function prep_keywords_sel(o)
 { var s, f
   
   s = ""
   f = false
   for (t = 0; t < o.options.length; t++)
   { if (o.options[t].selected)
     { if (f)
        s = s + "|"
       else
        f = true
       s = s + o.options[t].value
     }
   }
   return s
 }

 function select_option(sel_obj, sel_opt_value)
 { for (t = 0; t < sel_obj.options.length; t++)
   { if (sel_obj.options[t].value == sel_opt_value)
      return t
   }
   return false
 }
