
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

var modified = false;

/*function makeArray() {
  var args = makeArray.arguments;
  for (var i = 0; i < args.length; i++) {
    this[i] = args[i];
  }
  this.length = args.length;
}
*/
function attach(id)
{ return $(id);
}

/*
function set(id, val)
 { o = attach(id)
   o.value = unescape(val)
   o.defaultValue = o.value
 }
*/  
 function _s(id, val)
 { $(id).set('value',unescape(val));
//   o.defaultValue = o.value
 }
 function set_var(v, val)
 { new kport_ajax({url:'?ajax=1&section=fnc&fnc=set_var&var='+v+'&val='+val,async:false,put_wait:false,update:'msg'}).loadURL();
 }
 
 function set_in_form(frm,id, val)
 { f=document.getElementById(frm)
   for (var t=0; t < f.elements.length; t++)
   { if (f.elements[t].id == id)
     { f.elements[t].value = unescape(val)
     }
   }
 }

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

 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 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)
   hilite_modified_from_ext(s)
   close_calendar()
 }

 function set_event_date(d, m, y, s)
 { d = new Date(y,m,d)
   o = document.getElementById(s)
   o.value = d.toLocaleString()
   o.value = d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate()
 }
 
 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=240, top=128, left=128')
//   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, day, s, func)
 { var ld = new makeArray(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
   var hdate = new makeArray()
   var t, o, k, d, x, act_date

   if ((y%4) == 0) ld[1]++
    
   //if (m == "") m = 1;
   //if (y == "") y = 2005;
   //if (day != "")
   // document.getElementById('get_day_'+s).value=day
   
   //if (act_date = document.getElementById(s).value)
   // hdate = act_date.split("/")
   //else
   // hdate = 
   
   //t = new Date(y, m-1, 1);
   t = new Date()
   if (m)
    t.setMonth(m-1)
   else
    m=parseInt(t.getMonth()+1)
   if (y)
    t.setFullYear(y)
   else
    y=t.getFullYear()
   if (day)
   { document.getElementById('get_day_'+s).value=day
     t.setDate(day)
   }
   else
    day=t.getDate()
   //alert (t.getMonth()+' '+t.getFullYear()+' '+day)
   
   if (act_date = document.getElementById(s).value)
    hdate = act_date.split("/")
   else
   { hdate[0] = y
     hdate[1] = m
     hdate[2] = day
   }
   hdate[0] = parseInt(hdate[0],10)
   hdate[1] = parseInt(hdate[1],10)
   hdate[2] = parseInt(hdate[2],10)
   
   o = attach('get_month_'+s)
   o.selectedIndex=m-1
   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)'
     o=attach(s+'_td'+eval(d+k))
     o.className='cal_td'
     o.onmouseover=''
     o.onmouseout=''
   }
   for (;d <= ld[m-1]; d++)
   { t.setDate(d)
     o=attach(s+'_d'+eval(d+k))
     o.innerHTML=d
     o=attach(s+'_td'+eval(d+k))
     if ((d==hdate[2]) && (m==hdate[1]) && (y==hdate[0]))
      o.className='cal_tdH'
     else
      o.className='cal_td'
     //<a class='cal_link' name='{$s}_a{$d}' id='{$s}_a{$d}' href=''><span class='cal_lab' name='{$s}_d{$d}' id='{$s}_d{$d}'>31</span></a></td>";
     o=attach(s+'_a'+eval(d+k))
     o.href="javascript:"+func+"("+d+","+parseInt(m-1)+","+y+", '"+s+"');set_calendar("+m+","+y+","+d+",'"+s+"','"+func+"')"
   }
   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)'
     o=attach(s+'_td'+eval(d+k))
     o.className='cal_td'
     o.onmouseover=''
     o.onmouseout=''
   }
   //document.getElementById('get_day_'+s).value=day
 }

 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 stripSlashes(str)
 { return str.replace(/\\/g, '');
 }
/*
 function prep_gallery_obj(o)
 { // a[0] = id
   // a[1] = file name
   // a[2] = file size
   // a[3] = dimensions
   // a[4] = icon file name
   // a[5] = desc
   // a[6] = ord
   // a[7] = copyright
   // a[8] = zoom
   // a[9] = mime
   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("|")
//alert(attach('gallery_pos').value)
     _s('gallery_pos', a[0]+"|"+o.id+"|"+a[6])
//alert(attach('gallery_pos').value)
     o_img = attach(o.id+'_img')
     //o1.src = user_img_dir+a[1]
     o_img.src = a[4]
     //alert(o1.src) 
     //alert(a.toString())
     //o1.src = a[4]
     //o1.src = a[1]
     //o1 = attach(o.id+'_fn')
     //o1.innerHTML = a[1]
     o1 = attach(o.id+'_fs')
     o1.innerHTML = a[2]
     o1 = attach(o.id+'_fd')
     o1.innerHTML = a[3]
     o1 = attach(o.id+'_desc')
     o1.value = unescape(a[5])
     o1 = attach(o.id+'_copyright')
     o1.value = unescape(a[7])
     if (a[8].length > 0)
     { //alert (unescape(a[8]))
//       o_img.onmouseover = function(){eval(unescape(a[8]))}
//       o_img.onmouseout = hideddrivetip
     }
     o1 = attach(o.id+'_mime')
     o1.innerHTML = a[9]
     o1 = attach(o.id+'_dir')
     o1.innerHTML = basename(a[1])
   }
 }
*/
 function basename(fullPath)
 { var lastSlash // the position of the last slash in the path
   var fileName  // the name of the file
   var c = "\\"
   var pos
   
   lastSlash = fullPath.lastIndexOf(c)
   if (lastSlash == -1)
    c = "/"
   //fileName = fullPath.substring(lastSlash+1,fullPath.length)
   fileName = fullPath.split(c);
   //alert(fileName[fileName.length-1])
   fileName.pop()
   return fileName.join(c)
 }
/*
 function prep_resources_obj(o)
 { // a[0] = id
   // a[1] = file name
   // a[2] = file size
   // a[3] = dimensions
   // a[4] = icon file name
   // a[5] = desc
   // a[6] = ord
   // a[7] = copyright
   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("|")
     _s('gallery_pos', a[0]+"|"+o.id+"|"+a[6])
     o1 = attach(o.id+'_img')
     //o1.src = user_img_dir+a[1]
     o1.src = a[4]
     //alert(o1.src) 
     //alert(a.toString())
     //o1.src = a[4]
     //o1.src = a[1]
     //o1 = attach(o.id+'_fn')
     //o1.innerHTML = a[1]
     o1 = attach(o.id+'_fs')
     o1.innerHTML = a[2]
     o1 = attach(o.id+'_fd')
     o1.innerHTML = a[3]
     o1 = attach(o.id+'_desc')
     o1.value = a[5]
     o1 = attach(o.id+'_copyright')
     o1.value = a[7]
     o1 = attach(o.id+'_dir')
     o1.innerHTML = basename(a[1])
   }
 }
 function download(id)
 { // a[0] = id
   // a[1] = file name
   // a[2] = file size
   // a[3] = dimensions
   // a[4] = icon file name
   // a[5] = desc
   // a[6] = ord
   // a[7] = copyright
   a = new Array()
   
   o=attach(id)
   if (o.options.length != 0)
   { if (o.selectedIndex != -1)
     { a=o.value.split("|")
	   top.location.href='index.php?section=download&file='+a[1]
	 }
   }
 }
*/
/* function get_sel_date(s)
 { o=document.getElementById(s)
   return o.value
 }
 
 function get_sel_event_date(s)
 { o=document.getElementById(s)
   if (o.options.length != 0)
   { if (o.selectedIndex != -1)
     { return o.options[o.selectedIndex].value
     }
   }
   return false
 }

 function get_sel_event_progr(s)
 { o=parent.document.getElementById(s)
   if (o.options.length != 0)
   { if (o.selectedIndex != -1)
     { return o.options[o.selectedIndex].value
     }
   }
   return false
 }
 
 function prep_events_obj(o, fc, lc)
 { //events_dates_id|events_dates_event_id|first_date|last_date|lang_id
   ename = o.id.split("|")
   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("|")
	 document.getElementById(fc).value=a[2]
     document.getElementById(lc).value=a[3]
     d1=a[2].split("/")
     set_calendar(d1[1],d1[0],d1[2],fc,'set_event_date')
     d2=a[3].split("/")
     set_calendar(d2[1],d2[0],d2[2],lc,'set_event_date')
	 document.getElementById('event_progr|'+ename[1]).src='index.php?section=put_progr&edid='+a[0]+'&progr_id='+ename[1]+'&lang_id='+a[4]
     //document.getElementById('event_progr_zoom').src='?section=put_progr&edid='+a[0]
     
     //o=document.getElementById('event_progr_zoom')
     //prep_events_zoom_obj(o)
   }
 }
 
 function prep_events_zoom_obj(o)
 { //events_dates_id|events_dates_event_id|first_date|last_date|lang_id
   a = new Array()
   var extra_link
   
   extra_link = ""
   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("|")
     //document.getElementById(fc).value=a[2]
     //document.getElementById(lc).value=a[3]
     //d1=a[2].split("/")
     //set_calendar(d1[1],d1[0],d1[2],fc,'set_event_date')
     //d2=a[3].split("/")
     //set_calendar(d2[1],d2[0],d2[2],lc,'set_event_date')
     //document.getElementById('event_progr_zoom').src='?section=put_progr&edid='+a[0]//+'&epid'+a[1]
     extra_link = '&edid='+a[0]+'&lang_id='+a[4]
     //document.getElementById('event_progr_zoom').src='?section=put_progr&edid='+a[0]
   }
   document.getElementById('event_progr_zoom').src='?section=put_progr'+extra_link
 }
 
 function prep_progr_obj(o)
 { //events_progr_id|events_dates_id|first_time|last_time|lang_id
   a = new Array()
   
   ename = o.id.split("|")
   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("|")
     // alert(a[0]+' '+a[1])
     //document.getElementById(fc).value=a[2]
     //document.getElementById(lc).value=a[3]
     //d1=a[2].split("/")
     //set_calendar(d1[1],d1[0],d1[2],fc,'set_event_date')
     //d2=a[3].split("/")
     //set_calendar(d2[1],d2[0],d2[2],lc,'set_event_date')
	 document.getElementById('event_progr_zoom|'+ename[1]).src='index.php?section=put_progr&act=event_progr_zoom&edid='+a[1]+'&epid='+a[0]+'&progr_id='+ename[1]+'&lang_id='+a[4]
   }
   else
   { o=attach('edid')
     document.getElementById('event_progr_zoom|'+ename[1]).src='index.php?section=put_progr&act=event_progr_zoom&edid='+o.value+'&epid=&progr_id='+ename[1]+'&lang_id='
   }
 }

 function prep_event_date_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.src = 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)
 { var el=$(o);
   if (el.hasClass("global_selectable"))
    return el.hasClass("global_selected");
   else
   { var t, d
     t = ((o.className == 'tableline_sel') || (o.className == 'tableline_selover') || (o.className == 'tableline_lastsel') || (o.className == 'tableline_lastselover') || (o.className == 'tablelineHilite_sel') || (o.className == 'tablelineHilite_selover'))
     d = ((o.className == 'diapo_sel') || (o.className == 'diapo_selHover') || (o.className == 'diapo_lastsel') || (o.className == 'diapo_lastselHover'))
     return (t || d || a);
   }
 }

 function select_it(o)
 { var el=$(o);
   if (el.hasClass("global_selectable"))
    el.toggleClass("global_selected");
   else
   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 'tablelineHilite':
     case 'tablelineHiliteHover':
      if ((o == sel1) || (o == sel2))
       o.className = 'tablelineHilite_lastsel'
      else
       o.className = 'tablelineHilite_sel'
     break;
	 
     case 'tablelineHilite_sel':
     case 'tablelineHilite_selover':
     case 'tablelineHilite_lastsel':
     case 'tablelineHilite_lastselover':
     o.className = 'tablelineHilite'
     break;
	 
     case 'diapo':
     case 'diapoHover':
      if ((o == sel1) || (o == sel2))
       o.className = 'diapo_lastsel'
      else
       o.className = 'diapo_sel'
     break;
     
     case 'diapo_sel':
     case 'diapo_selover':
     case 'diapo_lastsel':
     case 'diapo_lastselHover':
     o.className = 'diapo'
     break;
   }
   return true
 }
 
 function force_select_it(o,f)
 { var el=$(o);
   if (el.hasClass("global_selectable"))
   { if (f)
      el.addClass("global_selected");
     else
      el.removeClass("global_selected");
   }
   else
   if (f)
   { 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 'tablelineHilite':
       case 'tablelineHiliteHover':
        if ((o == sel1) || (o == sel2))
         o.className = 'tablelineHilite_lastsel'
        else
         o.className = 'tablelineHilite_sel'
        break;
        
       case 'tablelineHilite_sel':
       case 'tablelineHilite_selover':
       case 'tablelineHilite_lastsel':
       case 'tablelineHilite_lastselover':
        //o.className = 'tableline'
        break;
	   
	   case 'diapo':
       case 'diapoHover':
        if ((o == sel1) || (o == sel2))
         o.className = 'diapo_lastsel'
        else
         o.className = 'diapo_sel'
        break;
        
       case 'diapo_sel':
       case 'diapo_selover':
       case 'diapo_lastsel':
       case 'diapo_lastselHover':
        //o.className = 'diapo'
       break;
     }
   }
   else
   { 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 'tablelineHilite':
       case 'tablelineHiliteHover':
        //if ((o == sel1) || (o == sel2))
        // o.className = 'tableline_lastsel'
        //else
        // o.className = 'tableline_sel'
        break;
        
       case 'tablelineHilite_sel':
       case 'tablelineHilite_selover':
       case 'tablelineHilite_lastsel':
       case 'tablelineHilite_lastselover':
        o.className = 'tablelineHilite'
        break;
        
	   case 'diapo':
       case 'diapoHover':
        //if ((o == sel1) || (o == sel2))
        // o.className = 'diapo_lastsel'
        //else
        // o.className = 'diapo_sel'
        break;
        
       case 'diapo_sel':
       case 'diapo_selover':
       case 'diapo_lastsel':
       case 'diapo_lastselHover':
        o.className = 'diapo'
       break;
     }
   }
   return true
 }

 function last_two_selection(o)
 { if ((o != sel1) && (o != sel2) && ((is_selected(o))))
   { if (sel2)
      if (is_selected(sel2))
      { if (sel2.className.search('tableline') != -1)
         sel2.className='tableline_sel'
        else
         if (sel2.className.search('diapo') != -1)
          sel2.className='diapo_sel'
      }
     if (o.className.search('tableline') != -1)
      o.className='tableline_lastsel'
     else
      if (o.className.search('diapo') != -1)
       o.className='diapo_lastsel'
     sel2 = sel1
     sel1 = o
   }
 }

 function hilite_it(o)
 { var el=$(o);
   if (el.hasClass("global_selectable"))
   { el.addClass("global_hilite");
   }
   else
   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;
     
     case 'tablelineHilite':
     o.className = 'tablelineHiliteHover'
     break;
     
     case 'tablelineHilite_sel':
     o.className = 'tablelineHilite_selover'
     break;
     
     case 'diapo':
     o.className = 'diapoHover'
     break;
     
     case 'diapo_sel':
     o.className = 'diapo_selHover'
     break;
     
     case 'diapo_lastsel':
     o.className = 'diapo_lastselHover'
     break;
   }
   return true
 }

 function dehilite_it(o)
 { var el=$(o);
   if (el.hasClass("global_selectable"))
   { el.removeClass("global_hilite");
   }
   else
   switch(o.className)
   { case 'tableline':
     case 'tablelineover':
     o.className = 'tableline'
     break;
     
     case 'tablelineHilite':
     case 'tablelineHiliteHover':
     o.className = 'tablelineHilite'
     break;
     
     case 'tablelineHilite_sel':
     case 'tablelineHilite_selover':
     o.className = 'tablelineHilite_sel'
     break;
     
     case 'tableline_sel':
     case 'tableline_selover':
     o.className = 'tableline_sel'
     break;
     
     case 'tableline_lastsel':
     case 'tableline_lastselover':
     o.className = 'tableline_lastsel'
     break;
     
     case 'diapo':
     case 'diapoHover':
     o.className = 'diapo'
     break;
     
     case 'diapo_sel':
     case 'diapo_selHover':
     o.className = 'diapo_sel'
     break;
     
     case 'diapo_lastsel':
     case 'diapo_lastselHover':
     o.className = 'diapo_lastsel'
     break;
   }
   return true
 }
 
 function select_all(f)
 { var a = $$(".global_selectable");
   a.each(function(item,index){
		force_select_it(item,f)
	});
   all_files=document.getElementsByTagName("tr")
   for (t = 0; t < all_files.length; t++)
   { n = all_files[t].id
	 a = n.split("|")
     if ((a[0] == "tr") || (a[0] == "file"))
	 { //if (f)
	   { /*
	     if ((all_files[t] == sel1) || (all_files[t] == sel2))
         { all_files[t].className = 'tableline_lastsel'
		 }
		 else
          all_files[t].className = 'tableline_sel'
         //select_it(all_files[t])
	     last_two_selection(all_files[t])*/
		 //select_it(all_files[t]);
	   }
	   //else
	   { /*
	     all_files[t].className = 'tableline'
         //select_it(all_files[t])
	     last_two_selection(all_files[t])
		 */
		 //select_it(all_files[t]);
	   }
       force_select_it(all_files[t],f)
	   last_two_selection(all_files[t])
	 }
   }
   all_files=document.getElementsByTagName("div")
   for (t = 0; t < all_files.length; t++)
   { n = all_files[t].id
	 a = n.split("|")
     if ((a[0] == "tr") || (a[0] == "file"))
	 { force_select_it(all_files[t],f)
	   last_two_selection(all_files[t])
	 }
   }
 }
 
 function get_all_selected()
 { var s="", f = false
   var el = $$(".global_selected");
   var a = false;
   el.each(function(item,index){
		a = item.get("id").split("|");
		if (f)
		 s = s + "|";
		f = true;
		s = s + a[1];
	});
   all_files=document.getElementsByTagName("tr")
   for (t = 0; t < all_files.length; t++)
   { n = all_files[t].id
	 a = n.split("|")
     if ((a[0] == "tr") && (is_selected(all_files[t])))
     { if (f)
        s = s + "|"
       f = true
       s = s + a[1]
     }
   }
   //alert (s)
   all_files=document.getElementsByTagName("div")
   for (t = 0; t < all_files.length; t++)
   { n = all_files[t].id
	 a = n.split("|")
     if ((a[0] == "tr") && (is_selected(all_files[t])))
     { if (f)
        s = s + "|"
       f = true
       s = s + a[1]
     }
   }
   return s
 }
 
 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 prep_to_delete(form_name,tab,sub_tab,sub_tab_type)
 { id=get_all_selected();
   if(id)
   { ids=id.split('|');
     if (confirm('Sicuro di voler eliminare '+ids.length+' elementi?'))
	 { /*_s('act','del')
	   _s('id',id)
	   o=attach(form_name)
	   o.onSubmit=''
	   o.submit()*/
	   ajaxManager('load_page','index.php?section=services&func=del_sub_cat&id='+id+'&vfunc=update_cat_div&cat=&act_id=&tab='+tab+'&sub_tab='+sub_tab+'&sub_tab_type='+sub_tab_type+'&lev=&service_act=clear_all','msgs','GET','no_wait_msg');
     }
   }
 }
 
 function prep_to_delete_elems(form_name, tab, table_id, pages_id, lang_id)
 { var id=get_all_selected();
   if(id)
   { var ids=id.split('|');
     if (confirm('Sicuro di voler eliminare '+ids.length+' elementi?'))
	 { ajaxManager('load_page','index.php?section=services&func=del_elem&vfunc=del_table_line&id='+id+'&tab='+tab+'&table_id='+table_id+'&pages_id='+pages_id+'&lang_id='+lang_id+'&main_form_name='+form_name+'&service_act=clear_all','tr_'+tab+'_'+lang_id+'|'+ids[0],'GET','no_wait_msg');
     }
   }
   else
    alert("ATTENZIONE! Non č stato selezionato alcun elemento");
 }
 
 function prep_to_delete_cat(form_name)
 { id=get_all_selected()
   if(id)
   { ids=id.split('|')
     if (confirm('Sicuro di voler eliminare '+ids.length+' elementi?'))
	 { _s('act','del')
	   _s('key',id)
	   o=attach(form_name)
	   o.onSubmit=''
	   o.submit()
     }
   }
 }
 
 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 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
 }
 
 function go_to(form_name, url)
 { o = document.getElementById(form_name)
   o.action = url
   o.submit()
 }

 function pack_perms_bits(fn)
 { var s
 
   s = (document.getElementById('px_'+fn).checked?'1':'0')
   s = s + (document.getElementById('pw_'+fn).checked?'1':'0')
   s = s + (document.getElementById('pr_'+fn).checked?'1':'0')
   s = s + (document.getElementById('gx_'+fn).checked?'1':'0')
   s = s + (document.getElementById('gw_'+fn).checked?'1':'0')
   s = s + (document.getElementById('gr_'+fn).checked?'1':'0')
   s = s + (document.getElementById('ox_'+fn).checked?'1':'0')
   s = s + (document.getElementById('ow_'+fn).checked?'1':'0')
   s = s + (document.getElementById('or_'+fn).checked?'1':'0')
   return s
 }
 
 function pack_perms_bits2(fn)
 { var s
 
   s = (document.getElementById(fn+'px').checked?'1':'0')
   s = s + (document.getElementById(fn+'pw').checked?'1':'0')
   s = s + (document.getElementById(fn+'pr').checked?'1':'0')
   s = s + (document.getElementById(fn+'gx').checked?'1':'0')
   s = s + (document.getElementById(fn+'gw').checked?'1':'0')
   s = s + (document.getElementById(fn+'gr').checked?'1':'0')
   s = s + (document.getElementById(fn+'ox').checked?'1':'0')
   s = s + (document.getElementById(fn+'ow').checked?'1':'0')
   s = s + (document.getElementById(fn+'or').checked?'1':'0')
   return s
 }

 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 fix_pagesize(ps_var_name)
{ o1 = attach(ps_var_name)
  o2 = attach('get_pagesize_'+ps_var_name)
  o1.value = o2.value
  return true
}

 function get_xmlHttpReq()
 { var xmlHttpReq = false;
        
   // Mozilla/Safari
   if (window.XMLHttpRequest)
   { xmlHttpReq = new XMLHttpRequest();
    if (xmlHttpReq.overrideMimeType)
     xmlHttpReq.overrideMimeType('text/xml')
   }
   // IE
   else
    if (window.ActiveXObject)
    { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
   return xmlHttpReq;
 }

//0 uninitialized Object is not initialized with data.
//1 Loading Object is loading its data.
//2 loaded Object has finished loading its data.
//3 interactive User can interact with the object even though it is not fully loaded.
//4 complete Object is completely initialized.

//The following table lists common XMLHttpRequest object methods: 
//Method		 					Description
// 
//abort() 		 					Stops the current request 
//getAllResponseHeaders() 			Returns complete set of headers (labels and values) as a string 
//getResponseHeader("headerLabel")  Returns the string value of a single header label 
//open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) 
//									 Assigns destination URL, method, and otheroptional attributes of a pending request 
//send(content) 					 Transmits the request, optionally with postable string or DOM object data 
//setRequestHeader("label", "value") Assigns a label/value pair to the header to be sent with a request 

function wait_msg()
{ //return "<div style='padding:8px;background-color:#ffffff;border:1px solid #d0d0d0'><img src='new_gfx/wa.gif' align='absmiddle' />&nbsp;Attendere, operazione in corso...</div>";
  return "<img src='new_gfx/ajax-loader.gif' style=\"vertical-align:middle\" alt=\"\" />&nbsp;Attendere...";
}

function eval_js(elementId)
{ var scripts = $(elementId).getElementsByTagName('script');
  var code;
  for (var i = 0; i < scripts.length; i++) {
		code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
			scripts[i].text ? scripts[i].text : 
			scripts[i].textContent;
		try {
			//alert(code);
			eval(code);
		} catch(e) {
			alert(e);
		}
	}
}

function ajaxManager()
// tipo_interr, url, dest_tag, metodo, no_wait_msg_flag, next_js
// 05-08-2008: da oggi usa Mootools :o)
{ var args = ajaxManager.arguments;
  
  //alert(args[2]);
  el = $(args[2]);//document.getElementById(args[2]);
  if (args[4] != "no_wait_msg")
  { el.set("html", wait_msg());//el.innerHTML = wait_msg();
  }
  switch (args[0])
  { case "load_page":
     var x = get_xmlHttpReq();
     if (x)
     { x.onreadystatechange = function()
       { try {
		 if ((x.readyState == 4) && (x.status == 200))
         { if (result = parser_xml(x.responseText))
           { result_msg = result.getElementsByTagName("result_msg");
			 if (result_msg[0].childNodes[0])
              $("msgs").set("html",unescape(result_msg[0].childNodes[0].nodeValue));//document.getElementById("msgs").innerHTML = unescape(result_msg[0].childNodes[0].nodeValue);
             el = $(args[2]);//document.getElementById(args[2]);
             result_body = result.getElementsByTagName("result_body");
             if (result_body[0].childNodes[0])
             { //alert(args[2]);
			   el.set("html",result_body[0].childNodes[0].nodeValue);//el.innerHTML = result_body[0].childNodes[0].nodeValue;
			   eval_js(args[2]);
			   //alert(el.innerHTML);
             }
			 if (args[5])
			 { //alert(args[5]);
			 //alert("dentro alla valutazione della prossima funzione: "+args[5]);
			   eval(args[5]/*+"(result_body);"*/);
			 }
             var page_reload_flg = result.getElementsByTagName("page_reload_flg");
             if (page_reload_flg[0].childNodes[0].nodeValue  == "true")
		     { frm = document.getElementsByTagName("form");
		       //for (var t = 0; t < frm.length; t++)
			   // alert(frm[t].id);
			   if (frm[0])
			    frm[0].submit();
			   //top.history.go(0);
			 }
           }
           else
            alert("ERROR\n"+x.responseText);           
           //else
           // el.innerHTML = x.responseText;
         }
	     }
		 catch(e)
		 { alert(e)
		 }
       }
	   var met = 'GET';
	   if (typeof args[3] != 'undefined')
	    met = args[3];
	   if (met == 'GET')
	   { x.open(met, args[1].replace(/&amp;/g, "&"), true);
         x.send(null);
	   }
	   else
	   { //alert("Metodo POST");
	     params = args[1].split('?');
	     params[1] = params[1].replace(/&amp;/g, "&");
	     x.open('POST', params[0], true);
	     x.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
         x.setRequestHeader("Content-length", params.length-1);
         x.setRequestHeader("Connection", "close");
         x.send(params[1]);
	   }
     }
     break;
    case "start_up":
     ajaxManager('load_page', 'basic.xml', 'contentLYR');
     break;
  }
}

function parser_xml(str)
{ //alert(str);
  // code for IE
  if (window.ActiveXObject)
  { var doc=new ActiveXObject("Microsoft.XMLDOM");
    doc.async="false";
    doc.loadXML(str);
  }
  // code for Mozilla, Firefox, Opera, etc.
  else
  { var parser=new DOMParser();
    var doc=parser.parseFromString(str,"text/xml");
  }
  var x = doc.documentElement;
//  alert (x.getElementsByTagName("div")[0].childNodes[0].nodeValue);
  return x;
//  alert (x.getElementsByTagName("to")[0].childNodes[0].nodeValue);
/*
for (i=0;i<x.childNodes.length;i++)
  {
  document.write(x.childNodes[i].nodeName);
  document.write("=");
  document.write(x.childNodes[i].childNodes[0].nodeValue);
  document.write("<br />");
  }
*/
}
 function get_fileupload()
 { var all_files=top.document.getElementsByTagName("input")
   for (var t = 0; t < all_files.length; t++)
   { //alert(all_files[t].type+" - "+all_files[t].id);
if (all_files[t].type == "file")
      if (all_files[t].value != "")
      { uploadFile(all_files[t])
        break;
      }
   }
 }
function uploadFile(obj) {
	var uploadDir = obj.value;
	var uploaderId = 'uploader'+obj.name;
	var uploader = obj.name;
    var o=top.document.getElementById('formName'+obj.name)
    o.submit()
	//traceUpload(uploadDir, obj.name);	
    //ajaxManager('load_page','index.php?section=browse_files&act=upload_new','uploader'+obj.name)
    o=top.document.getElementById('uploader'+obj.name).innerHTML = wait_msg()
}
 function clear_fields(fld, fld1)
 { _s(fld,'')
   if (fld1)
    _s(fld1,'')
//   var o=document.getElementById(fld)
//   if (o.className.indexOf('_h') == -1)
//   { o.className = o.className+'_h'
//   }
   hilite_modified(fld)
}

  function DivSetVisible(div_id, iframe_id, state)
  {
   var DivRef = document.getElementById(div_id);
   var IfrRef = document.getElementById(iframe_id);
   if(state)
   {
    DivRef.style.display = "block";
    IfrRef.style.width = DivRef.offsetWidth;
    IfrRef.style.height = DivRef.offsetHeight;
    IfrRef.style.top = DivRef.style.top;
    IfrRef.style.left = DivRef.style.left;
    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    IfrRef.style.display = "block";
   }
   else
   {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
   }
  }

 function hilite_modified(obj_name)
 { return true;
   //document.getElementById(obj_name+'_hilite_div').className='hilite_modified_on';
   o = document.getElementById(obj_name+'_trans_hilite_div')
   if (o)
    o.className='hilite_modified_on';
   modified = true;
 }
 function hilite_modified_from_ext(obj_name)
 { //document.getElementById(obj_name+'_hilite_div').className='hilite_modified_on';
   o = window.opener.document.getElementById(obj_name+'_trans_hilite_div')
   if (o)
    o.className='hilite_modified_on';
   modified = true;
 }


 function hilite_selected(obj_name)
 { o = document.getElementById(obj_name)
   for(var t = 0; t < o.options.length; t++)
    o.options[t].className = 'hilite_selected_off'
   o.options[o.selectedIndex].className = 'hilite_selected_on'
 }

 function post_vars(v)
 { f = document.createElement("form")
   document.body.appendChild(f)
   //f.action = "?section=ps&cat="+id
   f.method = "POST"
   for (t = 0; t < v.length; t++)
   { e = document.createElement("input")
     e.type = "hidden"
     ev = v[t].split("=")
     e.id = ev[0]
     e.name = ev[0]
     e.value = ev[1]
     f.appendChild(e)
   }
   for (t=0; t < tree.length; t++)
   { e = document.createElement("input")
     e.type = "hidden"
     e.id = "pcat_is_opened|"+tree[t].cat			//Al Submit viene inviato il 'name', non 'id'
     e.name = "pcat_is_opened|"+tree[t].cat
     e.value = tree[t].isopened
     f.appendChild(e)
   }
   f.action = "index.php"
   f.submit()
 }

 function display_new_req(n)
 { var o=document.getElementById(n)
   if(o.style.display == 'none')
    o.style.display = 'block'
   else
    o.style.display = 'none'
 }

 function get_all_posted_fields(frm_name)
//non pių usata
 { f = document.getElementById(frm_name)
   for (var t=0; t < f.elements.length; t++)
   { alert(f.elements[t].id+" = "+f.elements[t].value)
   }
 }

 function form2GET(inputs_pre)
 { f = document.getElementsByTagName("form")
   if (f[0])
    for (t=0, first=false, s=""; t < f[0].elements.length; t++)
    { if (f[0].elements[t].name.indexOf(inputs_pre) == 0)
      { //alert(f[0].elements[t].name+" = "+f[0].elements[t].type)
        switch(f[0].elements[t].type)
        { case 'hidden':
		  case 'textarea':
          case 'text':
           s = s + (first?"&":"") + f[0].elements[t].name+"="+escape(f[0].elements[t].value)
           first=true
           break;
          case 'select':
          case 'select-one':
           s = s + (first?"&":"") + f[0].elements[t].name+"="+escape(f[0].elements[t].options[f[0].elements[t].selectedIndex].value)
           first=true
           break;
          case 'checkbox':
           s = s + (first?"&":"") + f[0].elements[t].name+"="+(f[0].elements[t].checked?"1":"0")
           first=true
           break;
        }
      }
    }
    //alert(s)
    return s
 }
 
/* function window_popup(div_name)
 { var windowModel = new DHTMLSuite.windowModel();
   windowModel.createWindowModelFromMarkUp(div_name);
   var myWindow = new DHTMLSuite.windowWidget();
   myWindow.addWindowModel(windowModel);
   myWindow.init();
   myWindow.setStatusBarText('This is some text');
 }
 */
 function set_permalink(title, obj)
 { //alert(typeof obj);
 }
 
 function conf_cat_del()
 { return confirm('ATTENZIONE! Stai per eliminare un segmento. Procedo?');
 }
 
 function conf_file_del(n)
 { var files = n.split("|")
   return confirm('ATTENZIONE! Stai per eliminare il file "'+files.toString()+'". Procedo?');
 }
 
 function conf_elem_del(n)
 { return confirm("ATTENZIONE! Stai per eliminare l'elemento cod. "+n+". Procedo?");
 }

function ocmd(n)
 { ta=attach(n);
   o=attach(n+'_o');
   if (ta.style.visibility == 'hidden')
   { ta.style.visibility='visible';
     o.src='new_gfx/bullet_toggle_minus.png';
	 ta.style.position='static';
   }
   else
   { ta.style.visibility='hidden';
     o.src='new_gfx/bullet_toggle_plus.png';
	 ta.style.position='absolute';
   }
 }
 
 function post_form(qs)
 { var form=false;
   var v = qs.split('&');
   for (var t = 0; t < v.length; t++)
   { var val = v[t].split('=');
	 if (val[0] == 'ajax_dest')
	 { ajaxManager('load_page','?'+qs,val[1]);
	   return;
	 }
	 else
	  if (val[0] == 'form')
	   form = attach(val[1]);
	  else
       _s(val[0],val[1]);
   }
   if(form)
	form.submit();
 }
 
 function add_qs_to_form(form_name,qs)
 { var form=document.getElementById(form_name);
   var v = qs.split('&');
   var val;
   for (var t = 0; t < v.length; t++)
   { val = v[t].split('=');
     e = document.createElement("input");
     e.type = "hidden";
     e.id = val[0];
     e.name = e.id
     e.value = val[1];
     form.appendChild(e);
   }
 }
 
 function check_copy_to_lang(id, lang)
 { cnf_flg=true;
   o=attach(id);
   if(o.options[o.selectedIndex].value != '0')
    cnf_flg=confirm('ATTENZIONE! Stai per copiare il segmento attuale dalla lingua "'+lang+'" alla lingua "'+o.options[o.selectedIndex].value+'". Sei sicuro?');
   return cnf_flg;
 }
 
 var calendarObjForForm = new Array();
 
 function pickDate(calobj, buttonObj, inputObject)
 { var inputObjectv = document.getElementById(inputObject.id+'v');
   calobj.setCalendarPositionByHTMLElement(inputObjectv,0,inputObjectv.offsetHeight+2);	// Position the calendar right below the form input
   calobj.setInitialDateFromInput(inputObject,'yyyy-mm-dd hh:ii');// Specify that the calendar should set it's initial date from the value of the input field.
   calobj.addHtmlElementReference('myDate',inputObject);// Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
   if(calobj.isVisible())
   { calobj.hide();
   }
   else
   { calobj.resetViewDisplayedMonth();	// This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
	 calobj.display();
   }
 }
 
 function getDateFromCalendar(el, cal)
 { var d = new Date(cal.val.getFullYear(), cal.val.getMonth(), cal.val.getDate());
   $(el.getProperty("id")+"v").value = d.toLocaleString();
   return;
 }
 
 function put_cal(n, val, img, dest)
 { var dp = val.split(/\//);
   //alert(JSON.encode(dp)+" - "+val);
   var loc_str="";
   //if (val)
   { var d = new Date();
     d.setDate(dp[0]);
	 d.setMonth(parseInt(dp[1])-1);
	 d.setFullYear(dp[2]);
     loc_str = d.toLocaleString();
	 //loc_str = val;
   }
   var cal_hin = new Element('input', {
    'type': 'text',
//    'type': 'hidden',
    'class': 'input',
    'value': val,
    'name': n,
    'id': n,
	'size': 30
});
   var cal_in = new Element('input', {
    'type': 'hidden',
//    'type': 'text',
    'class': 'label',
    'value': loc_str,
    'name': n+'v',
    'id': n+'v',
	'readonly': true,
	'size': 30
});
   var cal_picker = new Element('img', {
    'id': n+'picker',
	'class': 'pickerImg',
	'src': "js/vlaCalendar.v2.1.1/images/calendar.gif"
});
   $(dest).adopt(cal_hin,cal_in,cal_picker);
   //eval("var i = calendarObjForForm.push(new Calendar({'"+n+"': 'Y/m/d'}, {callback: getDateFromCalendar, linkobj:'"+n+"v', classes: ['dashboard'], direction: 0, navigation:2 }));");
   eval("var i = calendarObjForForm.push(new vlaDatePicker('"+n+"',{openWith:'"+n+"picker',format:'d/m/Y',style: 'apple_widget',prefillDate:{day:"+d.getDate()+",month:"+parseInt(d.getMonth()+1)+",year:"+d.getFullYear()+"}}));");
   return;
 }
 
 function go_to_dir(d, aux_qs)
 { ajaxManager('load_page','index.php?section=services&func=put_files&service_act=execute'+(aux_qs?'&'+aux_qs:'')+'&d='+d,'tool_div_name_cont');
 }
 
 function choose_img(dest, img, src)
 { document.getElementById(dest+"_img").src='img.php?src='+user_img_dir+img+'&sx=128&sy=0&cut=0&cutsx=128&cutsy=0&bck=f2f2f2&save=0';
   document.getElementById(dest+"_file").value=img;
   ajaxManager('load_page','?section=services&func=put_img_info&service_act=execute&d='+user_img_dir+img,dest+'_info');
 }
 function choose_file(dest, img, src)
 { document.getElementById(dest+"_img").src='img.php?src='+src+'&sx=80&sy=&cut=0&cutsx=&cutsy=&bck=f2f2f2&save=0';
   document.getElementById(dest+"_file").value=img;
   ajaxManager('load_page','?section=services&func=put_file_info&service_act=execute&d='+user_img_dir+img,dest+'_info');
 }
 function DEBUG_search_k(dest)
 { var g = top.document.getElementsByTagName('div');
   var k = 0;
   var k_tmp;
   for(var t=0;t < g.length;t++)
   { if(g[t].id.indexOf('imageBox') != -1)
     { //k_tmp = g[t].id.split("|");
	   //if (k_tmp[1] > k)
	   // k = k_tmp[1];
	   alert(g[t].id);
	 }
   }
   //return k++;
 }
 function get_next_k(dest)
 { var g = top.document.getElementsByTagName('div');
   var k = 0;
   var k_tmp;
   var new_k = 0;
   for(var t=0;t < g.length;t++)
   { if(g[t].id.indexOf('imageBox'+dest) != -1)
     { //alert("nel calcolo del prossimo k ho trovato "+g[t].id);
	   k_tmp = g[t].id.split("|");
	   new_k = parseInt(k_tmp[1]);
	   if (new_k > k)
	    k = new_k;
	 }
   }
   //alert("ultim ID di galleria per "+dest+" = "+new_k);
   return ++new_k;
 }
 function choose_img_gallery(dest, img, src)
 { //document.getElementById(dest+"_img").src='img.php?src='+user_img_dir+img+'&sx=128&sy=0&cut=0&cutsx=128&cutsy=0&bck=f2f2f2&save=0';
   //document.getElementById(dest+"_file").value=img;
   //ajaxManager('load_page','?section=services&func=put_img_info&service_act=execute&d='+user_img_dir+img,dest+'_info');
   var file='img.php?src='+escape(user_img_dir+img)+'&sx=96&sy=96&cut=1&cutsx=96&cutsy=96&bck=ffffff&save=0';
   //					$tmp_name, $imgs[$w*3], $ptf, $fn, htmlentities($imgs[$w*3+1], ENT_QUOTES)
   create_gallery_image(dest, "|"+get_next_k(dest)+"|", img, file, "", "");
//                     (nid,    k, file,                v, desc, copyright)
   initGallery();
   //alert(top.document.getElementById(dest+'_gallery').innerHTML);
   //DEBUG_search_k(dest);
}
 function choose_img_resource(dest, img, src)
 { //var file='img.php?src='+escape(user_img_dir+img)+'&sx=96&sy=96&cut=1&cutsx=96&cutsy=96&bck=ffffff&save=0';
   //alert(img+" - "+src);
//   create_resource_image(dest, img, img, src, "desc", "copyright");
   create_resource_image(dest, "|"+get_next_k(dest)+"|", img, src, "", "");
   initGallery();
 }
/**/

function get_window_width()
{ if( typeof( window.innerWidth ) == 'number' )
 { //Non-IE
   myWidth = window.innerWidth;
   myHeight = window.innerHeight;
 }
 else
  if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  { //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  else
   if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
   { //IE 4 compatible
     myWidth = document.body.clientWidth;
     myHeight = document.body.clientHeight;
   }
  return myWidth;
}
function get_window_height()
{ if( typeof( window.innerWidth ) == 'number' )
 { //Non-IE
   myWidth = window.innerWidth;
   myHeight = window.innerHeight;
 }
 else
  if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
  { //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  }
  else
   if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
   { //IE 4 compatible
     myWidth = document.body.clientWidth;
     myHeight = document.body.clientHeight;
   }
  return myHeight;
}

function center_window(w)
{ //w.divElement.style.left=((document.width-w.windowModel.__getWidth())/2+window.pageXOffset)+'px';
  //w.divElement.style.top=((document.height-w.windowModel.__getHeight())/2+window.pageYOffset)+'px';
  //alert(document.scrollX);
  var pxo = (typeof(window.pageXOffset) != 'undefined'?window.pageXOffset:0);
  var pyo = (typeof(window.pageYOffset) != 'undefined'?window.pageYOffset:0);
  w.divElement.style.left=((get_window_width()-w.windowModel.__getWidth())/2+pxo)+'px';
  w.divElement.style.top=((get_window_height()-w.windowModel.__getHeight())/2+pyo)+'px';
}
function new_center_window(w,h)
{ //w.divElement.style.left=((document.width-w.windowModel.__getWidth())/2+window.pageXOffset)+'px';
  //w.divElement.style.top=((document.height-w.windowModel.__getHeight())/2+window.pageYOffset)+'px';
  //alert(document.scrollX);
  var pxo = (typeof(window.pageXOffset) != 'undefined'?window.pageXOffset:0);
  var pyo = (typeof(window.pageYOffset) != 'undefined'?window.pageYOffset:0);
  var x =((get_window_width()-w)/2+pxo);//+'px';
  var y =((get_window_height()-h)/2+pyo);//+'px';
  if (Browser.Platform.mac && Browser.Engine.gecko) y=0;
  return {'x': x, 'y': y};
  return {'x': x, 'y': y};
}
function redraw_table_on_change(tab, table_flag, pages_flag, table_extra_qs, pages_extra_qs,table_id,pages_id, lang_id)
{ //if (table_flag)
  // ajaxManager('load_page','index.php?section=services&func=draw_table&tab='+tab+'&service_act=execute&'+table_extra_qs,tab+'_table');
  //if (pages_flag)
  // ajaxManager('load_page','index.php?section=services&func=draw_pages_table&tab='+tab+'&service_act=execute&'+pages_extra_qs,tab+'_pages');
  if (table_flag)
   new kport_ajax({url:"?ajax=1&section=services&func=draw_table&tab="+tab+"&table_id="+table_id+"&pages_id="+pages_id+"&lang_id="+lang_id+"&service_act=execute&"+table_extra_qs,update:table_id,put_wait:false}).loadURL();
  if (pages_flag)
   new kport_ajax({url:"?ajax=1&section=services&func=draw_pages_table&tab="+tab+"&table_id="+table_id+"&pages_id="+pages_id+"&lang_id="+lang_id+"&service_act=execute&"+pages_extra_qs,update:pages_id,put_wait:false/*,next_js:"$('"+tab+"_pages2').set('html',$('"+tab+"_pages').get('html'))"*/}).loadURL();
}

function sync_all_reqs()
{ var s, ss, kt, t;
  for (t=0;t<all_galleries.length;t++)
   document.getElementById(all_galleries[t]+"_file").value=unescape(saveImageOrder(all_galleries[t]));
  for (t=0;t<all_resources.length;t++)
   document.getElementById(all_resources[t]+"_file").value=unescape(saveImageOrder(all_resources[t]));
  for (t=0;t<all_keywords.length;t++)
  { //ak = all_keywords[t].split("|");
    //kt = document.getElementById("kt|"+ak[1]);
    kt = document.getElementById("kt|"+all_keywords[t]);
	if (typeof kt != undefined)
	 s = kt.value;
	ss = unescape(multipleSelectOnSubmit("ka|"+all_keywords[t]));
	if (ss)
	 s = s+"|";
    document.getElementById(all_keywords[t]+"_file").value=s+ss;
  }
}

function setFormFieldValue(value,nameOfSlider)
{ //document.forms[0].elements[nameOfSlider].value = value;
  document.getElementById(nameOfSlider).value = value;
}

function setSliderValue(whichEl,newValue)
{ whichEl.setSliderValue(newValue);
}

function create_editable_filename(files_tab, form_name)
{ $$('.editable').each(function(el)
  {	if(!el.hasClass('EDITABLE_SELECT'))
    { el.addClass('EDITABLE_SELECT');
	el.addEvent('dblclick',function()
	{ //store "before" message
	  var before = el.get('html').trim();
	  //erase current
	  el.set('html','');
	  //replace current text/content with input or textarea element
	  if(el.hasClass('textarea'))
	  {	var input = new Element('textarea', { 'class':'box', 'text':before });
	  }
	  else
	  {	var input = new Element('input', { 'class':'input', 'value':before });
		//blur input when they press "Enter"
		input.addEvent('keydown', function(e) { if(e.key == 'enter') { this.fireEvent('blur'); } });
	  }
	  input.inject(el).select();
	  //add blur event to input
	  input.addEvent('blur', function() {
	    //get value, place it in original element
	    val = input.get('value').trim();
	    el.set('text',val).addClass(val != '' ? '' : 'editable-empty');
	    //save respective record
	    var url = 'mootools-editable-content.php?id=' + el.get('rel') + '&content=' + el.get('text');
	    var request = new Request({
	 	  url:url,
		  method:'post',
		  onRequest: function() {
			//alert('making ajax call :: ' + url);
	   //ajaxManager('load_page','?section=fnc&fnc=change_filename&files_tab='+files_tab+'&form_name='+form_name+'&qs=','msg');
		    ajFetch('index.php?ajax=1&section=fnc&fnc=change_filename&files_tab='+files_tab+'&form_name='+form_name+'&file='+el.get('rel')+'&newname='+escape(el.get('text'))+'&qs=', 'msg', false, 0, false);
		  }
	    }).send();
	  });
    });
	}
  });
};

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 16;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function change_tab(tab_index,tab,tab_id)
{ //'name':"{$n}",'lang_id':"{$lang_id}",'tab':"{$data->valtab}"}
  var t;
  for(t=0; t < all_datagrids.length; t++)
  { //alert(all_datagrids[t].tab+" - "+tab);
    if(all_datagrids[t].tab_id == tab_id)
    { //alert(all_datagrids[t].tab);
	  redraw_table_on_change(all_datagrids[t].tab, true, true, "main_form_name=", "main_form_name=",all_datagrids[t].name+"_table",all_datagrids[t].name+"_pages", all_datagrids[t].lang_id);
	}
  }
  //alert(id+" - "+JSON.encode(all_datagrids[0]));
}