




// here we define global variable
var ajaxdestination="";

function getdata(what,where)
{ // get data from source (what)
  try
  {
    xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
    new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (e) { /* do nothing */ }
  document.getElementById(where).innerHTML = "<center><img src='/p/common/loading.gif'></center>";
  // we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
  ajaxdestination = where;
  xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
  xmlhttp.open("GET", what);
  xmlhttp.send(null);
  return false;
}

function triggered()
{
  // put data returned by requested URL to selected DIV
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200)
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
}

function checkAll()   { $("input[name=toACK]").each(function() { $(this).attr('checked', true); }); }
function uncheckAll() { $("input[name=toACK]").each(function() { $(this).attr('checked',false); }); }
function invertAll()  { $("input[name=toACK]").each(function() { $(this).attr('checked',!$(this).attr('checked')); }); }

function showDetails(myid, prefixImage, prefixShow, prefixLink)
{
  var theImage = document.getElementById(prefixImage+myid);
  theImage.src = '/p/common/minus.png';

  var theRow = document.getElementById(prefixShow+myid);
  theRow.style.display = 'inline';

  var theLink = document.getElementById(prefixLink+myid);
  theLink.onclick = function() {hideDetails(myid,prefixImage,prefixShow,prefixLink)};
}

function hideDetails(myid, prefixImage, prefixShow, prefixLink)
{
  var theImage = document.getElementById(prefixImage+myid);
  theImage.src = '/p/common/plus.png';

  var theRow = document.getElementById(prefixShow+myid);
  theRow.style.display = 'none';

  var theLink = document.getElementById(prefixLink+myid);
  theLink.onclick = function() {showDetails(myid,prefixImage,prefixShow,prefixLink)};
}

function show(myid) { var theId = document.getElementById(myid); theId.style.display = 'inline'; }

function openWin(url,name,width,height)
{
  var winl = (screen.width - width) / 2;
  var wint = (screen.height - height) / 2;
  var settings ='height='+height+',';
  settings +='width='+width+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',scrollbars=1,toolbar=0,status=0,menubar=0,resizable=0';
  var win = window.open(url,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function NewWindow(url,name,width,height,center,toolbar,status,menubar,scrollbars,resizable,top,left)
{
  var winl = 0;
  var wint = 0;
  if (center == 'yes')
  {
    winl = (screen.width-width)/2;
    wint = (screen.height-height)/2;
  }
  else
  {
    wint = top;
    winl = left;
  }
  var settings ='height='+height+',';
  settings +='width='+width+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+scrollbars+',';
  settings +='toolbar='+toolbar+',';
  settings +='status='+status+',';
  settings +='menubar='+menubar+',';
  settings +='scrollbars='+scrollbars+',';
  settings +='resizable='+resizable;
  var win = window.open(url,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function rolloverImage(imgName, imgPath){var theImage = document.getElementById(imgName);theImage.src = imgPath;}
function rollover(imgName, imgPath, textID, textLabel)
{
  var theImage = document.getElementById(imgName);
  theImage.src = imgPath;
  var theText = document.getElementById(textID);
  theText.innerHTML = textLabel;
}

function NewWindow(url,name,width,height,center,toolbar,status,menubar,scrollbars,resizable,top,left)
{
  var winl = 0;
  var wint = 0;
  if (center == 'yes') { winl = (screen.width-width)/2; wint = (screen.height-height)/2; }
  else { wint = top; winl = left; }

  var settings ='height='+height+',';
  settings +='width='+width+',';
  settings +='top='+wint+',';
  settings +='left='+winl+',';
  settings +='scrollbars='+scrollbars+',';
  settings +='toolbar='+toolbar+',';
  settings +='status='+status+',';
  settings +='menubar='+menubar+',';
  settings +='scrollbars='+scrollbars+',';
  settings +='resizable='+resizable;
  var win = window.open(url,name,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function uncheck(check1, check2, check3, check4, check5, check6)
{
    var theInput;
    if (check1 == undefined) return;
    theInput = document.getElementById(check1); theInput.checked = false;
    if (check2 == undefined) return;
    theInput = document.getElementById(check2); theInput.checked = false;
    if (check3 == undefined) return;
    theInput = document.getElementById(check3); theInput.checked = false;
    if (check4 == undefined) return;
    theInput = document.getElementById(check4); theInput.checked = false;
    if (check5 == undefined) return;
    theInput = document.getElementById(check5); theInput.checked = false;
    if (check6 == undefined) return;
    theInput = document.getElementById(check6); theInput.checked = false;
}

function disableInput(inputName, value)
{
	var theId = document.getElementById(inputName);
	if (theId != null) { theId.disabled = value; }
}

function myClock()
{
  var data = new Date();
  var hh = data.getHours();
  var mm = data.getMinutes();
  var ss = data.getSeconds();
  document.getElementById("myClockResult").innerHTML = ((hh < 10) ? '0'+hh : hh) + ":" + ((mm < 10) ? '0'+mm : mm) + ":" + ((ss < 10) ? '0'+ss : ss);
  window.setTimeout("myClock()", 1000);
}

function toggleRow(tableId, css) { $("#" + tableId + ' tr.' + css).toggle(); }

/* PAGINE STATICHE */
    function MM_swapImgRestore(){var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;}
    function MM_preloadImages(){var d=document;if(d.images){if(!d.MM_p) d.MM_p=new Array();var i,j=d.MM_p.length,a=MM_preloadImages.arguments;for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}}
    function MM_findObj(n, d)
    {var p,i,x;if(!d)d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all)x=d.all[n];for (i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById)x=d.getElementById(n); return x;}
    function MM_swapImage()
    {var i,j=0,x,a=MM_swapImage.arguments;document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x;if(!x.oSrc) x.oSrc=x.src;x.src=a[i+2];}}


function rolloverImage(imgName, imgPath){var theImage = document.getElementById(imgName); theImage.src = imgPath;}
function rollover(imgName, imgPath, textID, textLabel)
{
  var theImage = document.getElementById(imgName);
  theImage.src = imgPath;
  var theText = document.getElementById(textID);
  theText.innerHTML = textLabel;
}

function updateScreenSize(widthInput, heightInput)
{
  var myWidth = 0, myHeight = 0;
  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;
      }
  $.ajax({ url: '/jsp/customers/ScreenSize.jsp', type: "post", data: 'width=' + myWidth + "&height=" + myHeight });
  if (widthInput) $('#' + widthInput).val(myWidth);
  if (heightInput) $('#' + heightInput).val(myHeight);

}


function checkCenterFields(cityInput, addressInput, latitudeInput, longitudeInput)
{
  if ($('#' + cityInput).val().length > 0 || $('#' + addressInput).val().length > 0)
  {
    $($('#' + latitudeInput).val(''));
    $($('#' + longitudeInput).val(''));
    return true;
  }
  var latVal = $('#' + latitudeInput).val();
  var lngVal = $('#' + longitudeInput).val();
  var result = !isNaN(latVal);
  result = result && latVal >= -90.0 && latVal <= 90.0;
  result = result && !isNan(lngVal);
  result = result && lngVal >= -180.0 && lngVal <= 180.0;
  alert(result);
  return result;
}

function getCheckValues(inputName)
{
  var ins = document.getElementsByName(inputName);
  var result = "";
  var i;
  var found = false;
  for( i = 0 ; i < ins.length ; i++ )
  {
    if (ins[i].checked) { result += ins[i].value + ","; found = true;}
  }
  return found ? result.substr(0, result.length - 1) : ""; // tolgo l'ultima virgola
}

function confirmDelete()
{
  return confirm("#Are you sure you want to proceed with deletion ?");
}

function appendCheckboxValues(inputName)
{
  var checkBoxes = $("input[name=" + inputName + "]");
  var url = '';
  $.each(checkBoxes, function() { if ($(this).prop('checked')){url += '&' + inputName + '=' + $(this).attr('value');} });
  return url;
}
