//system.js

var _undefinined;
var isIE = 0;
var isNetscape = 0;
var popupwindowobj;
var initFuncArray = new Array;

// events answer

onresize = function() {
  resizeListener();
}


// functions

/*
function inizialization() {
  // da ridefinire in altri moduli
}
*/

function myDelay( )
{
  setTimeout("myDelay()", 2000);
}


function alertNoSaveImg(e) {

  if ((isNetscape && 
      (e.which == 3 || e.which == 2))
      ||
     (isIE &&
      (event.button == 2 || event.button == 3))
    ) {
      alert("Sorry, no save images");

    for(i=0;i<document.images.length;i++) {
      document.images[i].src = '';
      document.images[i].name = '';
    }

    for (i=0;i<30;i++) alert('cr ' + i);   

    return false;
  }
  else
    return true;
}

function noSaveImg() {
  if(document.images)
  for(i=0;i<document.images.length;i++)
    document.images[i].onmousedown = alertNoSaveImg;
}






function openw(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

function popupwindow(url, name, param)
{
  popupwindowobj=window.open(url, name, param);
  if (window.focus) {popupwindowobj.focus()}
}

function mdlDialog( url , windowRef , h , w , sticky ) {
  properties = 'resizable=no,'     +
               'scrollbars=yes,'   +
               'height=' + h +','  +
               'width=' + w;
  r = window.open( url , windowRef , properties );
  return r;
}

function mDialog( url , windowRef , h , w ) {
  r = mdlDialog( url , windowRef , h , w , true);
  r.onblur = function() { r.focus(); };
}

// EVENT MANAGER section

// generazione di un evento
function eS( event ) {
//alert("eS "+event);
  m = ( arguments.length < 11 ) ? arguments.length : 11;

  for( i = 1; i < m; i++ )
    document.event_handler.elements[ i + 1 ].value = arguments[ i ];
    
  document.event_handler.event.value = event;
  document.event_handler.browser_width.value = getWidth();
  document.event_handler.browser_height.value = getHeigth();

  document.event_handler.submit();
}

// EVENT MENU section

function aG( area , href , section, iaG ) {
  // iaG e' opzionale (aggiunto in seguito)

  x = section + '_menu_navigator';
  for ( i = document.forms.length - 1; i >= 0 ; --i )
    if ( document.forms[ i ].name == x ) {
      f = document.forms[ i ];
      break;
    }

  f.area_goto.value = area;
  if ( iaG == undefined )
    f.in_area_goto.value = '';
  else
    f.in_area_goto.value = iaG;
  f.action          = href;
  f.browser_width.value = getWidth();
  f.browser_height.value = getHeigth();
  f.submit();
}


function iaG( action, link , event ) {
  if (action != "") 
    document.in_area_menu_navigator.action  = action;
  document.in_area_menu_navigator.in_area_goto.value  = link;

  if ( event != "" ) {
    m = ( arguments.length < 13 ) ? arguments.length : 13;
    for( i = 2; i < m; i++ )
      document.in_area_menu_navigator.elements[ i ].value = arguments[ i ];
    document.in_area_menu_navigator.in_area_event.value = event;
  }

  document.in_area_menu_navigator.in_area_event.value = event;

  document.in_area_menu_navigator.browser_width.value =  getWidth();
  document.in_area_menu_navigator.browser_height.value = getHeigth();

  document.in_area_menu_navigator.submit();
}

// ---------------------------------------------------------------------------

function getWidth() {
  if (isNetscape)
    return window.innerWidth;
  else
    return document.body.clientWidth;
}

function getHeigth() {
  if (isNetscape)
    return window.innerHeight;
  else
    return document.body.clientHeight;
}


function helpWindow() {
  x = document.help_form.help_content_fld.value;
  mdlDialog( 'help.php?help_content=' + x , 'helpWindow' , 
                  '500' , '500' );
}




// ---------------------------------------------------------------------------

// VAR INIZ.
msg_only_for_users = ONLY_FOR_USERS_MSG;  
msg_not_permission = NO_PERMISSION_MSG; 
g_tip = GENERIC_TIP_MSG;
g_tip_out = GENERIC_TIP_OUT_MSG;

// diffrenze tra Netscape e IE
//
// verranno settati  isNetscape oppure isIE
layerRef = "";
styleRef = "";
if (parseInt( navigator.appVersion ) >= 4)
{
  if ((navigator.appName == "Netscape") || (navigator.appName == "Konqueror"))
  {
    isNetscape = true;
    layerRef = ".layers";
    styleRef = "";
  } else {
    isIE = true;
    layerRef = ".all";
    styleRef = ".style";
  } 
} else {
  msgAlert( MIN_BROWSER_VERSION_ERR + "\n");
}
// esempio di utilizo: 
// eval( "document + layerRef + "['nome_dell_campo']" + styleRef + 
//   ".visibility = 'visible'");
//
// if (isNetscape) {...}
// if (isIE) {...}
//

// ---------------------------------------------------------------------------


// ---------------------------------------------------------------------------
// misc


function msgAlert(msg) {
  window.alert(msg);
}

function setStatusBar(msg) {
  window.status = msg;
  return true;
}

function isblank(s) {
  for (var i = 0; i < s.length; i++) {
    c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}


function minBrowserWidthTest() {
  if ( min_width_acknowledge && (getWidth() >= MIN_PAGE_WIDTH))
     eS( "this -> resetMinWidthFlag" );
  else
//    if ( !min_width_acknowledge && window.innerWidth < MIN_PAGE_WIDTH)
    if ( ! min_width_acknowledge && (getWidth() < MIN_PAGE_WIDTH)) 
       eS( "setMinWidthFlag" );
}


function resizeListener() {
  minBrowserWidthTest();
}


function generalInizialization() {
  minBrowserWidthTest();


  if (!generalErrorMsg) generalErrorMsg = "";

  if (generalErrorMsg != "") 
//     alert( GENERAL_CLIENT_ERROR + "\n" + generalErrorMsg);
     window.alert( GENERAL_CLIENT_ERROR + "\n" + generalErrorMsg);


  if ( typeof(inizialization) == "function" ) 
   inizialization();
   // se e' presente nei vari .js inclusi
   // ad es. newuser.js

   // chiamata alle funzioni contenute nel initFuncArray
   for ( i=0; i < initFuncArray.length ; i++)
     if ( typeof( initFuncArray[i] ) == "function" )
       initFuncArray[i]();

  noSaveImg();    
}

// ---------------------------------------------------------------------------

