/* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */
// {{{ http user agent detection

var pc = 0;
var mac = 0;
var ie = 0;
var ns = 0;
var safari = 0;

/// operating system

if (navigator.userAgent.indexOf('Win') != -1) {
  pc = 1;
}

if (navigator.userAgent.indexOf('Mac') != -1) {
  mac = 1;
}

/// browser

if (navigator.userAgent.indexOf('MSIE') != -1) {
  ie = 1;
}

if (navigator.userAgent.indexOf('Netscape') != -1) {
  ns = 1;
}

if (navigator.userAgent.indexOf('Safari') != -1) {
  safari = 1;
}

// }}}
// {{{ function NB_popup(url, title, width, height)

function NB_popup(url, title, width, height)
{
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
  props = 'width='+width+',height='+height+',resizable=no,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no';
  if (safari == 1) {
    props = props + ',screenX='+x+',screenY='+y;
  } else {
    props = props + ',left='+x+',top='+y;
  }
  w = window.open(url, title, props);
}

// }}}
// {{{ function NB_popup_s(url, title, width, height)

function NB_popup_s(url, title, width, height)
{
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
  props = 'width='+width+',height='+height+',resizable=no,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no';
  if (safari == 1) {
    props = props + ',screenX='+x+',screenY='+y;
  } else {
    props = props + ',left='+x+',top='+y;
  }
  w = window.open(url, title, props);
}

// }}}
// {{{ function NB_popup_sr(url, title, width, height)

function NB_popup_sr(url, title, width, height)
{
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
  props = 'width='+width+',height='+height+',resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no';
	if (safari == 1) {
		props = props + ',screenX='+x+',screenY='+y;
	} else {
		props = props + ',left='+x+',top='+y;
	}
	w = window.open(url, title, props);
}

// }}}
// {{{ function NB_popup_r(url, title, width, height)

function NB_popup_r(url, title, width, height)
{
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
	props = 'width='+width+',height='+height+',resizable=yes,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no';
	if (safari == 1) {
		props = props + ',screenX='+x+',screenY='+y;
	} else {
		props = props + ',left='+x+',top='+y;
	}
	w = window.open(url, title, props);
}

// }}}
// {{{ function NB_popup_sra(url, title, width, height, warning)

function NB_popup_sra(url, title, width, height, warning)
{
  if ((screen.availWidth == 640) || (screen.availHeight == 480)) {
    width = 628;
    height = 442;
  } else if ((screen.availWidth == 800) || (screen.availHeight == 600)) {
    width = 788;
    height = 562;
  } else if ((screen.availWidth == 1024) || (screen.availHeight == 768)) {
    width = 1012;
    height = 730;
  }
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
	props = 'width='+width+',height='+height+',resizable=yes,scrollbars=yes,menubar=no,toolbar=no,directories=no,location=no,status=no';
	if (safari == 1) {
		props = props + ',screenX='+x+',screenY='+y;
	} else {
		props = props + ',left='+x+',top='+y;
	}
	w = window.open(url, title, props);
  //w.moveTo(0,0);
  //w.resizeTo(screen.width, screen.height);
  if (warning && ((screen.availWidth <= 800) || (screen.availHeight <= 600))) {
    alert('Per la migliore visualizzazione si consiglia di impostare la risoluzione ad almeno 1024x768 pixels.');
  }
  w.focus();
}

// }}}
// {{{ function NB_popup_ra(url, width, height, title, warning)

function NB_popup_ra(url, width, height, title, warning)
{
  if ((screen.availWidth == 640) || (screen.availHeight == 480)) {
    width = 628;
    height = 442;
  } else if ((screen.availWidth == 800) || (screen.availHeight == 600)) {
    width = 788;
    height = 562;
  } else if ((screen.availWidth == 1024) || (screen.availHeight == 768)) {
    width = 1012;
    height = 730;
  }
	x = parseInt(Math.round((screen.availWidth - width) / 2.0));
	y = parseInt(Math.round((screen.availHeight - height) / 2.0));
  if (pc && ie) {
    x -= 6;
    y -= 20;
  }
	x = parseInt(Math.max(x, 0));
	y = parseInt(Math.max(y, 0));
	props = 'width='+width+',height='+height+',resizable=yes,scrollbars=no,menubar=no,toolbar=no,directories=no,location=no,status=no';
	if (safari == 1) {
		props = props + ',screenX='+x+',screenY='+y;
	} else {
		props = props + ',left='+x+',top='+y;
	}
	w = window.open(url, title, props);
  //w.moveTo(0,0);
  //w.resizeTo(screen.width, screen.height);
  if (warning && ((screen.availWidth <= 800) || (screen.availHeight <= 600))) {
    alert('Per la migliore visualizzazione si consiglia di impostare la risoluzione ad almeno 1024x768 pixels.');
  }
  w.focus();
}

// }}}
// {{{ function NB_resize(width, height)

function NB_resize(width, height)
{
  x = (screen.availWidth - width) / 2;
  y = (screen.availHeight - height) / 2;
  if (pc && ie) {
    width += 10;
    height += 50;
  }
  self.resizeTo(width, height);
  self.moveTo(x, y);
}

// }}}
// {{{ function NB_spreadsheet_clearrow(form, row)

function NB_spreadsheet_clearrow(form, row)
{
  for (i = 0; i < 8; i++) {
    form['riga_colonna_0'+i+'['+row+']'].value = '';
  }
  form['riga_commento['+row+']'].value = '';
}

// }}}
// {{{ function NB_spreadsheet_clearallrows(form, numrows)

function NB_spreadsheet_clearallrows(form, numrows)
{
  for (row = 0; row < numrows; row++) {
    NB_spreadsheet_clearrow(form, row)
  }
}

// }}}
// {{{ function NB_spreadsheet_clearall(form, numrows)

function NB_spreadsheet_clearall(form, numrows)
{
  NB_spreadsheet_clearallrows(form, numrows);
  form['lst_titolo'].value = '';
  form['lst_titolo_dx'].value = '';
  //form['lst_sottotitolo_01'].value = '';
  //form['lst_sottotitolo_02'].value = '';
  //form['lst_sottotitolo_03'].value = '';
}

// }}}
// {{{ function NB_input_checkbox_hash_checkall(hash)

function NB_input_checkbox_hash_checkall(hash)
{
  for (var key in hash) {
    hash[key].checked = true;
  }
}

// }}}
// {{{ function NB_specialoffers_handle_ofe_utente_checkall(checkbox, form)

function NB_specialoffers_handle_ofe_utente_checkall(checkbox, form)
{
  pattern = /^ofe_utente\[.+\]\[checked\]$/;
  if (checkbox.checked) {
    for (var i = 0; i < form.elements.length; i++) {
      if (pattern.test(form.elements[i].name))
        form.elements[i].checked = true;
    }
  }
}

// }}}
// {{{ function NB_specialoffers_handle_ofe_utente_checked(checkbox, checkbox_to_uncheck, form)

function NB_specialoffers_handle_ofe_utente_checked(checkbox, checkbox_to_uncheck, form)
{
  pattern = /^ofe_utente\[.+\]\[checked\]$/;
  found_not_checked = false;
  
  if (!checkbox.checked) {
    checkbox_to_uncheck.checked = false;
  } else {
    for (var i = 0; i < form.elements.length; i++) {
      if (pattern.test(form.elements[i].name)) {
        if (!form.elements[i].checked) {
          found_not_checked = true;
          break;
        }
      }
    }
    if (!found_not_checked)
      checkbox_to_uncheck.checked = true;
  }
}

// }}}
// {{{ function NB_specialoffers_selectall(form)

function NB_specialoffers_selectall(form)
{
  pattern = /^ofe_utente\[.+\]\[checked\]$/;
  for (var i = 0; i < form.elements.length; i++) {
    if (pattern.test(form.elements[i].name)) {
      form.elements[i].checked = true;
    }
  }
}

// }}}
// {{{ function NB_specialoffers_deselectall(form, another_checkbox_to_deselect)

function NB_specialoffers_deselectall(form, another_checkbox_to_deselect)
{
  another_checkbox_to_deselect.checked = false;
  pattern = /^ofe_utente\[.+\]\[checked\]$/;
  
  for (var i = 0; i < form.elements.length; i++) {
    if (pattern.test(form.elements[i].name)) {
      form.elements[i].checked = false;
    }
  }
}

// }}}
// {{{ function NB_print_document() {

function NB_print_document() {
  var NS = (navigator.appName == "Netscape");
  if (NS) {
    window.print() ;  
  } else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
    document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);
    WebBrowser1.outerHTML = "";  
  }
}

// }}}

